From ce920b6ff47f32bc06dd27124e1b882f82f3d6ae Mon Sep 17 00:00:00 2001 From: zinc Date: Wed, 14 Oct 2026 10:05:40 +0000 Subject: split compiler.zc into files by phase src/compiler/compiler.zc is now twelve files under src/compiler/, listed in order in src/compiler/parts. cat of the parts in order is byte-identical to the old file, so every compiler and image except the language server's is unchanged. no function was edited. consumers read the list: the makefile, bootstrap-check, genmap (which still writes one compiler.zc into a generated map directory), tinyvm.bat, test.sh, test_win.ps1 and the lsp drivers. the language server embeds each part and serves them joined as the one document tinyvm:/compiler.zc. --- tests/drivers/core_lsp_test.js | 4 +++- tests/drivers/hover_surface_test.js | 3 ++- tests/drivers/nav_test.js | 5 ++++- 3 files changed, 9 insertions(+), 3 deletions(-) (limited to 'tests/drivers') diff --git a/tests/drivers/core_lsp_test.js b/tests/drivers/core_lsp_test.js index c3c01aa..5123537 100644 --- a/tests/drivers/core_lsp_test.js +++ b/tests/drivers/core_lsp_test.js @@ -6,6 +6,8 @@ const fs = require('fs'); const cp = require('child_process'); const path = require('path'); const target = process.argv[2]; +// the compiler is the files listed in src/compiler/parts; the server checks them as the one document they make +const compilerSource = () => fs.readFileSync('src/compiler/parts', 'utf8').split(/\r?\n/).filter(Boolean).map(n => fs.readFileSync(path.join('src/compiler', n), 'utf8')).join(''); const files = ['src/core/core.zc', 'src/runtime/rt.zc', 'src/compiler/compiler.zc', 'src/runtime/run.zc', 'src/lib/std.zc', 'src/lib/icon.zc', 'src/lsp/server.zc', 'src/tools/build.zc']; const frame = message => { const body = Buffer.from(JSON.stringify(message)); @@ -13,7 +15,7 @@ const frame = message => { }; for (const file of files) { const uri = 'file://' + path.resolve(file); - const text = fs.readFileSync(file, 'utf8'); + const text = file === 'src/compiler/compiler.zc' ? compilerSource() : fs.readFileSync(file, 'utf8'); const messages = [ { jsonrpc: '2.0', id: 1, method: 'initialize', params: {} }, { jsonrpc: '2.0', method: 'initialized', params: {} }, diff --git a/tests/drivers/hover_surface_test.js b/tests/drivers/hover_surface_test.js index 688aca6..47056f6 100644 --- a/tests/drivers/hover_surface_test.js +++ b/tests/drivers/hover_surface_test.js @@ -17,7 +17,8 @@ function doc(uri, text) { return rid; }; } -const compiler = fs.readFileSync('src/compiler/compiler.zc', 'utf8'); +// the compiler is the files listed in src/compiler/parts, joined: the one document the server embeds +const compiler = fs.readFileSync('src/compiler/parts', 'utf8').split(/\r?\n/).filter(Boolean).map(n => fs.readFileSync('src/compiler/' + n, 'utf8')).join(''); 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/]); diff --git a/tests/drivers/nav_test.js b/tests/drivers/nav_test.js index 8f0d8fd..deff6f3 100644 --- a/tests/drivers/nav_test.js +++ b/tests/drivers/nav_test.js @@ -68,7 +68,10 @@ assert.strictEqual(slice(source('/std.zc'), loc[0]), 'atoi', 'a method goes to i loc = bdef('now('); assert.strictEqual(slice(source('/std.zc'), loc[0]), 'now'); assert.strictEqual(source('/std.zc'), fs.readFileSync(path.join(root, 'src', 'lib', 'std.zc'), 'utf8'), 'the embedded std is the file'); -assert.strictEqual(source('/compiler.zc'), fs.readFileSync(path.join(root, 'src', 'compiler', 'compiler.zc'), 'utf8'), 'the embedded compiler is the file'); +const parts = fs.readFileSync(path.join(root, 'src', 'compiler', 'parts'), 'utf8').split(/\r?\n/).filter(Boolean); +assert.strictEqual(source('/compiler.zc'), parts.map(n => fs.readFileSync(path.join(root, 'src', 'compiler', n), 'utf8')).join(''), 'the embedded compiler is its parts, joined in order'); +const embedded = [...fs.readFileSync(path.join(root, 'src', 'lsp', 'server.zc'), 'utf8').matchAll(/^embed "src\/compiler\/([^"]+)" as bstr/gm)].map(m => m[1]); +assert.deepStrictEqual(embedded, parts, 'src/lsp/server.zc embeds the files of src/compiler/parts, in order'); assert.strictEqual(source('/server.zc'), fs.readFileSync(path.join(root, 'src', 'lsp', 'server.zc'), 'utf8'), 'the embedded server is the file'); loc = bdef('s_to_n('); assert.ok(loc && loc.length === 1 && loc[0].uri === 'tinyvm:/rt.zc', 's_to_n opens the runtime source: ' + JSON.stringify(loc)); -- cgit v1.2.3