diff options
| author | 2026-10-14 10:38:17 +0000 | |
|---|---|---|
| committer | 2026-10-14 10:38:17 +0000 | |
| commit | 93340f97dce404a008f489729df144ace53528ab (patch) | |
| tree | cbada309f3a4683d083d84484f11952418c8dd2b /tests/programs/struct_static_call.zc | |
| parent | todo: handoff section with state, conventions, in-flight work and architectur... (diff) | |
fix std hover, full capture terminator, bare static calls, void main in run-only images
- hover: a symbol from an embedded library source (tinyvm:std.zc, tinyvm:icon.zc) was
looked up only in the document; look it up by its qualified name in the library source
(hover_embedded_sym), and render a method found that way by its line (bs_hover).
- std.capture: allocate one word more than the 256 it holds, so end() terminates inside the buffer.
- a bare call to a static function of the enclosing struct resolves like a bare struct constant
(mstruct is set for every non-generic struct's methods); the struct's own wins over a global.
- run.zc declares main untyped (fn main();), so a run-only image accepts int, void or untyped main
with both compilers.
Diffstat (limited to 'tests/programs/struct_static_call.zc')
| -rw-r--r-- | tests/programs/struct_static_call.zc | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/programs/struct_static_call.zc b/tests/programs/struct_static_call.zc new file mode 100644 index 0000000..73fc0fc --- /dev/null +++ b/tests/programs/struct_static_call.zc @@ -0,0 +1,31 @@ +namespace; +include rt; + +// a static function of a struct can be called by its bare name inside the struct's +// methods and static functions, as a struct constant can. the struct's own function +// wins over a top-level one of the same name; outside the struct only S.name reaches it. +int lim() { return 100; } +int base() { return 7; } + +struct S { + int v; + static int lim() { return 3; } + static int twice(int x) { return x * 2; } + static int both() { return lim() + twice(4); } + int get() { return lim() + this.v; } + int scaled() { return twice(this.v) + later(); } + int top() { return base(); } + static int later() { return 1000; } +} + +int main() { + S s; + s.v = 5; + rt.put_n(S.lim()); rt.put_c(32); // 3 + rt.put_n(lim()); rt.put_c(32); // 100, the global one + rt.put_n(S.both()); rt.put_c(32); // 3 + 8 + rt.put_n(s.get()); rt.put_c(32); // 3 + 5 + rt.put_n(s.scaled()); rt.put_c(32); // 10 + 1000, a static function declared later + rt.put_n(s.top()); rt.put_c(10); // 7, a global that the struct has no member of + return 0; +} |
