diff options
| author | 2026-10-14 08:29:46 +0330 | |
|---|---|---|
| committer | 2026-10-14 08:29:46 +0330 | |
| commit | 1c53304d03414890af0da7432d1aea87e754a14a (patch) | |
| tree | 97190d86cf548c9bc63f68c86a4d2a4f09809713 /tests/drivers/hover_values_test.js | |
| parent | a (diff) | |
feat: grow memory limits, add icon/actor libraries, overhaul LSP diagnostics
Compiler and VM
- make every memory map limit dynamic and adjustable at both build time and
runtime, including compiler tables, stacks, and every execution region
- reserve and grow tables, operand and return stacks, frame segments, and
image-building output without relocating live code or globals
- rename i/o and string helpers consistently (puts -> put_s, putn -> put_n,
scat -> cat_s) across compiler, runtime, examples, tests, and docs
- recast and consume values assigned to globals from inside functions
- allow fixed and const together, add typed closure returns (fn:t(...)),
multi-include syntax (include rt, run, core;), and recurse type inference
- never infer string literals as word, anywhere, as argument, variable, or
return type
- draft docs/BORROW.md: a borrow checker less intrusive than Rust's but more
intelligent
LSP and editor integration
- require explicit includes and give every toolchain area its own namespace
(rt, lsp, run, core)
- hover for built-in types, inferred types, values known at hover time, array
and pointer lifetime/size, library names in include statements, and inferred
lifetimes with explanations
- honor /* */ comments as documentation for variables and arguments, and stop
misattributing section headers or trailing comments as variable hints
- stream diagnostics and cancel stale requests on change
- jump to definition and references, including cross-file
- quick fixes with automatic library import, and namespace completion
Hints and diagnostics
- render hints as blue squigglies by default, with hints on/small/off per file
- suppress magic-number hints via a preceding /* */ comment, and say so
- warn on unused arguments; allow multiple _ discards in parameters, pattern
matching, and tagged enums, warning if a _ is actually used
- rewrite hint and comment prose in professional compiler-doc register
Libraries
- add icon.zc: run-time self-modification, find/replace syntax, type and block
edits, and step-through inspection of locals and globals
- add actor.zc: async actors with Actor<I,O>, implicit this, spawn/recv/send,
injected into the compiler machinery at include time rather than built in
Tooling and docs
- reorganize sources, tests, and designs into subdirectories
- unify windows entry points in tinyvm.bat and add a matching tinyvm.sh
- add --help across the toolchain
- polish the learning guide, stdlib docs, and design notes
Tests
- add accept, reject, and regression coverage across the compiler, LSP,
- runtime, icon, actors, threads, formatting, and the toolchain contracts,
plus fuzzers and property tests
Diffstat (limited to 'tests/drivers/hover_values_test.js')
| -rw-r--r-- | tests/drivers/hover_values_test.js | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/tests/drivers/hover_values_test.js b/tests/drivers/hover_values_test.js new file mode 100644 index 0000000..badc2ed --- /dev/null +++ b/tests/drivers/hover_values_test.js @@ -0,0 +1,68 @@ +// value previews follow the compiler's bindings and the position of each use. +const assert = require('assert'); +const cp = require('child_process'); +const server = process.argv[2]; +function hover(text, needle, nth = 0) { + let at = -1; + for (let n = 0; n <= nth; n++) at = text.indexOf(needle, at + 1); + assert.ok(at >= 0, needle); + const before = text.slice(0, at), uri = 'file:///hover-values.zc'; + const messages = [ + { jsonrpc: '2.0', id: 1, method: 'initialize', params: {} }, + { jsonrpc: '2.0', method: 'textDocument/didOpen', params: { textDocument: { uri, version: 1, text } } }, + { jsonrpc: '2.0', id: 2, method: 'textDocument/hover', params: { textDocument: { uri }, position: { line: before.split('\n').length - 1, character: before.length - before.lastIndexOf('\n') - 1 } } }, + { jsonrpc: '2.0', method: 'exit' } + ]; + const input = Buffer.concat(messages.map(m => { + const body = Buffer.from(JSON.stringify(m)); + return Buffer.concat([Buffer.from('Content-Length: ' + body.length + '\r\n\r\n'), body]); + })); + const result = cp.spawnSync(server, process.argv.slice(3), { input, timeout: 20000, maxBuffer: 8 << 20 }); + assert.strictEqual(result.status, 0, String(result.stderr)); + let data = result.stdout; + while (data.length) { + const end = data.indexOf('\r\n\r\n'); + const n = Number(/Content-Length:\s*(\d+)/i.exec(data.subarray(0, end).toString())[1]); + const reply = JSON.parse(data.subarray(end + 4, end + 4 + n)); + data = data.subarray(end + 4 + n); + if (reply.id === 2) return reply.result?.contents?.value || ''; + } + assert.fail('missing hover response'); +} +function value(text, needle, expected, nth = 0) { + const md = hover(text, needle, nth); + if (expected === null) assert.ok(!md.includes('value at this position:'), md); + else assert.ok(md.includes('value at this position:\n```zc\n' + expected + '\n```'), md); +} +const flow = 'fn unknown() { return 9; }\nfn main() { let n = 42; put_n(n); n = 7; put_n(n); n = unknown(); return n; }'; +value(flow, 'n = 42', '42'); +value(flow, 'n);', '42'); +value(flow, 'n);', '7', 1); +value(flow, 'n;', null); +value('const answer = 6 * 7; fn main() { return answer; }', 'answer;', '42'); +value('const answer = 42; fn main() { return answer; }', 'answer =', '42'); +value('enum color { red, green = 5 }; fn main() { color shade = green; return shade; }', 'shade;', '5'); +value('fn main() { let n = -9223372036854775808; return n; }', 'n;', '-9223372036854775808'); +value('fn main() { u8 n = 300; return n; }', 'n;', '44'); +value('fn main() { i8 n = 255; return n; }', 'n;', '-1'); +value('fn main() { let n = 3.25; return n; }', 'n;', '3.25'); +value('fn main() { float n = 2; return n; }', 'n;', '2'); +value('fn main() { int n = 3.75; return n; }', 'n;', '3'); +value('fn main() { f32 n = 0.1; return n; }', 'n;', '0.10000000149011612'); +value('fn main() { let n = -0.0; return n; }', 'n;', '0'); +value('fn main() { let text = "hello\\nworld"; return text; }', 'text;', '"hello\\nworld"'); +value('fn main() { let text = b"hello"; return text; }', 'text;', 'b"hello"'); +value('fn main() { let n = 7; let copy = n; n = 8; return copy; }', 'copy;', '7'); +value('fn main() { let n = 1; { let n = 2; put_n(n); } return n; }', 'n);', '2'); +value('fn main() { let n = 1; { let n = 2; put_n(n); } return n; }', 'n;', '1'); +value('fn change(int* p) { p[0] = 9; } fn main() { int n = 7; let p = &n; n = 8; change(p); return n; }', 'n;', null, 1); +value('fn main() { int n = 7; let p = &n; n = 8; p[0] = 9; return n; }', 'n;', null, 1); +value('fn main() { let text = "hey"; text[0] = 120; return text; }', 'text;', null); +value('fn main() { let n = 1; if (1) n = 2; return n; }', 'n;', null); +value('fn main() { let n = 1; while (0) n = 2; return n; }', 'n;', null); +value('fn main() { let n = 1; let ignored = 0 && (n = 2); return n; }', 'n;', null); +value('fn main() { let p = new(int, 3); return p; }', 'p;', null); +value('fn main() { let n = clz(0); return n; }', 'n;', null); +value('let global = 7; fn main() { return global; }', 'global;', null); +value('let global = 7; fn main() { global = 8; return global; }', 'global;', '8'); +console.log('ok position-aware integer, float, string, constant, and alias values; unknown effects invalidate previews'); |
