From 1c53304d03414890af0da7432d1aea87e754a14a Mon Sep 17 00:00:00 2001 From: Moon Flower Date: Wed, 14 Oct 2026 08:29:46 +0330 Subject: 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, 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 --- tests/drivers/hover_surface_test.js | 65 +++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 tests/drivers/hover_surface_test.js (limited to 'tests/drivers/hover_surface_test.js') diff --git a/tests/drivers/hover_surface_test.js b/tests/drivers/hover_surface_test.js new file mode 100644 index 0000000..13a9a3f --- /dev/null +++ b/tests/drivers/hover_surface_test.js @@ -0,0 +1,65 @@ +// hover declarations and instructions in the source-only documents opened by f12. +const assert = require('assert'); +const fs = require('fs'); +const cp = require('child_process'); +const path = require('path'); +const frame = m => { const b = Buffer.from(JSON.stringify(m)); return Buffer.concat([Buffer.from(`Content-Length: ${b.length}\r\n\r\n`), b]); }; +const messages = [{ id: 1, method: 'initialize', params: {} }], checks = []; +let id = 2; +function doc(uri, text) { + messages.push({ method: 'textDocument/didOpen', params: { textDocument: { uri, version: 1, text } } }); + return (needle, offset = 0) => { + const at = text.indexOf(needle) + offset; assert.ok(at >= 0, needle); + const before = text.slice(0, at), rid = id++; + messages.push({ id: rid, method: 'textDocument/hover', params: { textDocument: { uri }, position: { line: before.split('\n').length - 1, character: before.length - before.lastIndexOf('\n') - 1 } } }); + return rid; + }; +} +const compiler = fs.readFileSync('src/compiler/compiler.zc', 'utf8'); +const ask = doc('tinyvm:/compiler.zc', compiler); +checks.push([ask('ifrcap = NIF', 9), /const int NIF = 431/, /431/]); +checks.push([ask('capture_width = NCAP', 16), /const int NCAP = 32/, /initial capture capacity/, /32/]); +checks.push([ask('closure_cap = NCLO', 14), /const int NCLO = 8/, /initial closure nesting capacity/]); +checks.push([ask('clo_n = clo_n_initial', 8), /word\[NCLO\] clo_n_initial/]); +checks.push([ask('int nclo, closure_cap', 10), /\(int\) let closure_cap/, /value at this position:[\s\S]*\n8\n/]); +const rt = doc('tinyvm:/rt.zc', fs.readFileSync('src/runtime/rt.zc', 'utf8')); +checks.push([rt('SYS_CLOSE = 2'), /const int SYS_CLOSE = 2/]); +const fixture = doc('tinyvm:/fixture.zc', 'const int FIRST = 1, SECOND = 2;\nword[4] backing; word active = backing;\nint x = SECOND;\n'); +checks.push([fixture('x = SECOND', 4), /const int SECOND = 2/]); +checks.push([fixture('active = backing', 9), /word\[4\] backing/]); +const mnemonic = 'q@!$_~cjzr,?.+-*&|^><%'; +for (const op of mnemonic) { + const get = doc('tinyvm:/asm-' + op.charCodeAt(0) + '.zc', `fn f() { asm { ${op} } return 0; }`); + checks.push([get(`{ ${op}`, 2), /opcode \d+/, /(stack:|return stack|data stack)/]); +} +const special = doc('tinyvm:/special.zc', 'fn f() { asm { #1224 } }\ninclude std;\n'); +checks.push([special('#1224'), /load byte/, /byte address/]); +checks.push([special('1224'), /load byte/]); +checks.push([special('std;'), /include std;/, /embedded standard library/, /nothing imports it automatically/]); +const normal = doc('file:///ordinary.zc', 'fn main() { int std = 7; int c = 2; return std + c; }'); +checks.push([normal('std +'), /\(int\) let std/, /value at this position/]); +checks.push([normal('c;'), /\(int\) let c/]); +messages.push({ method: 'exit' }); +let out; +if (process.argv[2] === '--wasm' || process.argv[2] === '--vm') { + const wasm = process.argv[2] === '--wasm', host = require(path.resolve('editors/vscode/client', wasm ? 'wasmproc.js' : 'vmproc.js')); + const p = (wasm ? host.wasmProcess : host.vmProcess)(path.resolve(process.argv[3]), { log: () => {} }); + const chunks = []; p.stdout.on('data', d => chunks.push(d)); + for (const m of messages) p.stdin.write(frame({ jsonrpc: '2.0', ...m })); + out = Buffer.concat(chunks); +} else { + const r = cp.spawnSync(process.argv[2], process.argv.slice(3), { input: Buffer.concat(messages.map(m => frame({ jsonrpc: '2.0', ...m }))), timeout: 60000, maxBuffer: 32 << 20 }); + assert.strictEqual(r.status, 0, String(r.stderr)); out = r.stdout; +} +const replies = new Map(); +while (out.length) { + const e = out.indexOf('\r\n\r\n'), n = Number(/Content-Length:\s*(\d+)/i.exec(out.subarray(0, e).toString())[1]); + const m = JSON.parse(out.subarray(e + 4, e + 4 + n)); replies.set(m.id, m); out = out.subarray(e + 4 + n); +} +for (const [rid, ...patterns] of checks) { + const value = replies.get(rid)?.result?.contents?.value || ''; + for (const pattern of patterns) assert.match(value, pattern, `hover #${rid}: ${value}`); +} +assert.ok(!replies.get(checks[2][0]).result.contents.value.includes('closures being compiled'), 'the section overview is not NCLO documentation'); +assert.ok(!replies.get(checks[checks.length - 1][0]).result.contents.value.includes('opcode'), 'ordinary c is a variable'); +console.log('ok embedded declaration hovers, constant values, asm instructions and explicit std'); -- cgit v1.2.3