1
0
forked from alex-eg/sex

walk the values of a brace literal

The walk stopped at a vector, so whatever a literal held reached the
writer as written: #(v : (.get a)) was (v){.get(a)}, and a path through
a pointer inside one read it as a value.
This commit is contained in:
2026-10-14 17:07:20 +03:00
parent 224ef8fb6b
commit 9af9113bf5
2 changed files with 16 additions and 0 deletions

View File

@@ -556,6 +556,7 @@
(define (walk-statement form env)
(cond
((vector? form) (walk-literal form env))
((not (list? form)) form)
((null? form) form)
;; expanded here rather than before the walk, so the macro body can
@@ -674,6 +675,15 @@
(unresolve-closure-types (expression-type queried env)))))
(macroexpand form (list))))
;;; `#(v : (.get a))' is `(v){vːget(&a)}': the values are expressions
;;; like any other, and the type before `:' is not one
(define (walk-literal form env)
(let* ((parts (vector->list form))
(elements (or (and (memq ': parts) (cdr (memq ': parts))) parts)))
(list->vector
(append (drop-right parts (length elements))
(map (lambda (element) (walk-operand element env)) elements)))))
;;; `(var n _ (strlen s))' becomes `(var n size-t (strlen s))'.
(define (resolve-wildcard form env)
(if (and (>= (length form) 3) (wildcard-type? (third form)))

View File

@@ -160,6 +160,12 @@
"(ops meters (fn half ((self meters)) meters (return self)))"
"(fn f () void (var x km 1.0) (var y km (.half x)))")
"metersːhalf(x)"))
(test-assert "a method call inside a literal is still a call"
(emits? (ops-src "(var w vec2 #(vec2 : (.length v) 1.0))")
"(vec2){vec2ːlength(&v), 1.0}"))
(test-assert "however deep"
(emits? (ops-src "(var ws [vec2 1] #(#(vec2 : (.length p) 1.0)))")
"{(vec2){vec2ːlength(p), 1.0}}"))
(test-assert "an address cannot be taken of a call"
(reports? (ops-src "(.length (mk))") "receiver is not an lvalue"))
;; the inner call has to be typed to find the outer one's receiver