lang: for-loop by-ref element capture (for xs: (*x))
(*x) binds x to a pointer into the collection (index_gep) instead of a per-element value copy: passing it on (e.g. to a *T param) is zero-copy and mutations write back. In a value position x auto-derefs — a binary-op operand loads the element, a pointer-typed slot keeps the pointer, and an 'if x == {...}' match derefs the pointee for its tag/payload. Arrays GEP through their storage so writes hit the original. Regression test: examples/for-by-ref-capture.sx.
This commit is contained in:
1
tests/expected/for-by-ref-capture.exit
Normal file
1
tests/expected/for-by-ref-capture.exit
Normal file
@@ -0,0 +1 @@
|
||||
0
|
||||
3
tests/expected/for-by-ref-capture.txt
Normal file
3
tests/expected/for-by-ref-capture.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
101 102 103
|
||||
circle 2.000000
|
||||
none
|
||||
Reference in New Issue
Block a user