diff options
| author | 2026-10-14 05:55:19 +0000 | |
|---|---|---|
| committer | 2026-10-14 05:55:19 +0000 | |
| commit | 05f7b7e09ad503e4eac4f757de0d7329174f6437 (patch) | |
| tree | 768931192a69eff878d8f149c418fff55b0fdf8e /tests/programs | |
| parent | docs: archive the frozen stage code as one compressed tarball (diff) | |
analyzer: close the ownership gaps that stopped the compiler compiling itself
an owned local can now move into a released owner declared in the same or an
outer block, and g = m*x lends a local owner to a global until the global is
assigned again in the same block. leaving that block, giving the local away, or
returning while the lend is open is an error. recasting a plain local now names
it and says it has no ownership to recast.
methdef and syntax_resident use the supported spellings, so make genome reaches
its fixpoint from a clean checkout. runerr.sh reads the first // expect: line,
since the include headers moved it off line 1.
Diffstat (limited to 'tests/programs')
| -rw-r--r-- | tests/programs/ownmove.zc | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/programs/ownmove.zc b/tests/programs/ownmove.zc new file mode 100644 index 0000000..76a2a17 --- /dev/null +++ b/tests/programs/ownmove.zc @@ -0,0 +1,39 @@ +namespace; +include rt; + +// moves between owned locals and bounded lends of a local to a global. +word sink; +// the scratch buffer is lent to sink while helper reads it through the global. +int helper() { return sink[0] + sink[1]; } +int lend(int a, int b) { + word buf = rt.new(4); + buf[0] = a; buf[1] = b; + word saved = sink; + sink = m*buf; + int s = helper(); + buf[0] = s; + sink = saved; + return buf[0]; +} +// a replacement built in an inner block becomes the outer owner once the old one is released. +int grow(int n) { + word r = rt.new(2); + r[0] = n; + if (n > 0) { + word bigger = rt.new(8); + bigger[0] = r[0] * 10; + rt.free(r); + r = bigger; + } + return r[0]; +} +fn main() { + rt.put_n(lend(3, 4)); rt.put_c(32); + rt.put_n(grow(5)); rt.put_c(32); + rt.put_n(grow(0)); rt.put_c(32); + int i = 0; + while (i < 100) { grow(i); i++; } + rt.gc(); + rt.put_n(sink == 0); rt.put_c(10); + return 0; +} |
