aboutsummaryrefslogtreecommitdiff
path: root/src/js/extract_lsp.js
diff options
context:
space:
mode:
authorGravatar Moon Flower <moonflower@elhenney.local> 2026-10-14 08:45:35 +0330
committerGravatar Moon Flower <moonflower@elhenney.local> 2026-10-14 08:45:35 +0330
commitd981870038c3ffa531f5c1d07e4aec855e061491 (patch)
tree9b88cc64668a54a7b240bd180a12c5f2779bd081 /src/js/extract_lsp.js
parentfeat: grow memory limits, add icon/actor libraries, overhaul LSP diagnostics (diff)
build: generate everything into build/, keep src/ free of generated files
src/ carried 8.4 MB of build output: the genome header, the javascript vm and its layout, and the language-server image, plus a second copy of the extension server under editors/vscode/server/. none of it is source. - move the genome from src/core/genome.h to build/core/genome.h and compile with -Ibuild/core; `make all` bootstraps one when it is missing - write genome.json, layout.ts, layout.js and lsp.json to build/js/ - compile tinyvm.ts to build/js/, typed by a tracked src/js/layout.d.ts so the vm needs no generated file beside its source - build the wasm server into build/editors/vscode/server/ and stage the whole server into editors/vscode/server/ only while mkvsix.sh packages it - redirect the test suite, image_run.js, tinyvm.sh, tinyvm.bat, test_win.ps1 and the baremetal build at the new paths, and add make lspimage and make vsix - stop tracking every generated file also fix a build blocker: lookup_raw compared skind against K_VAR, which was never declared, so `make genome` could not run at all. the guard is about emitted program globals, which are K_GVAR and K_GARR. tests/test.sh -q reports 159 passed and 21 failed both before and after this change; every failure is pre-existing and comes from the checked-in genome being stale relative to src/, plus the bootstrap above.
Diffstat (limited to 'src/js/extract_lsp.js')
-rw-r--r--src/js/extract_lsp.js55
1 files changed, 41 insertions, 14 deletions
diff --git a/src/js/extract_lsp.js b/src/js/extract_lsp.js
index 358d404..14ee279 100644
--- a/src/js/extract_lsp.js
+++ b/src/js/extract_lsp.js
@@ -1,22 +1,47 @@
-// writes src/js/lsp.json: the language server's image (build/lsp/genome.h, made by
-// src/tools/mklsp.sh) and the map it was built for, read from build/lsp/map/memmap.h.
-// the vm needs the layout, because the server's map is not the compiler's.
+// writes the language server's javascript image: the genome build/lsp/genome.h,
+// made by src/tools/mklsp.sh, and the map it was built for, read from
+// build/lsp/map/memmap.h. the vm needs the layout, because the server's map is
+// not the compiler's. the image is generated, so it goes to build/js/ and
+// nothing is left in the tree.
+//
+// node src/js/extract_lsp.js [--out PATH]
+//
+// build the lsp first (`make lsp`, or src/tools/mklsp.sh); it needs
+// build/lsp/genome.h.
const fs = require('fs');
const path = require('path');
-if (process.argv.length > 2) {
- if (process.argv.length === 3 && ['--help', '-h'].includes(process.argv[2])) {
- console.log('usage: node src/js/extract_lsp.js [--help|-h]\nconverts build/lsp/genome.h and its memory map into src/js/lsp.json; build the lsp first.');
- process.exit(0);
+const root = path.join(__dirname, '..', '..');
+
+const args = process.argv.slice(2);
+if (args.includes('--help') || args.includes('-h')) {
+ console.log([
+ 'usage: node src/js/extract_lsp.js [--out PATH]',
+ 'converts the language server genome and its memory map into a javascript image.',
+ 'options:',
+ ' --out PATH where to write; defaults to build/js/lsp.json',
+ ' --help, -h show this help and exit',
+ ].join('\n'));
+ process.exit(0);
+}
+let out = path.join(root, 'build', 'js', 'lsp.json');
+for (let i = 0; i < args.length; i++) {
+ if (args[i] === '--out' && args[i + 1]) out = args[i + 1];
+ else {
+ console.error('extract_lsp: unexpected arguments; use --help for usage');
+ process.exit(2);
}
- console.error('extract_lsp: unexpected arguments; use --help for usage');
- process.exit(2);
}
-const root = path.join(__dirname, '..', '..');
-const genome = fs.readFileSync(path.join(root, 'build', 'lsp', 'genome.h'), 'utf8');
+const genomePath = path.join(root, 'build', 'lsp', 'genome.h');
+const mapPath = path.join(root, 'build', 'lsp', 'map', 'memmap.h');
+if (!fs.existsSync(genomePath)) {
+ console.error('extract_lsp: no language server image at ' + genomePath + '; run `make lsp` first');
+ process.exit(1);
+}
+const genome = fs.readFileSync(genomePath, 'utf8');
const { mapValues } = require('./mapvalues.js');
-const layout = mapValues(path.join(root, 'build', 'lsp', 'map', 'memmap.h'), ['GORG', 'DS0', 'DSLIM', 'RS0', 'RSLIM', 'SYSGATE', 'ZFP', 'HEAP_LO', 'HEAP_HI']);
+const layout = mapValues(mapPath, ['GORG', 'DS0', 'DSLIM', 'RS0', 'RSLIM', 'SYSGATE', 'ZFP', 'HEAP_LO', 'HEAP_HI']);
const gorg = parseInt(genome.match(/#define\s+GORG\s+(\d+)/)[1], 10);
const glen = parseInt(genome.match(/#define\s+GLEN\s+(\d+)/)[1], 10);
@@ -25,5 +50,7 @@ const words = arr[1].split(',').map(s => s.trim()).filter(s => s.length > 0);
if (words.length !== glen) throw new Error('genome has ' + words.length + ' words, GLEN says ' + glen);
if (gorg !== layout.GORG) throw new Error('genome GORG ' + gorg + ' is not the map GORG ' + layout.GORG);
-fs.writeFileSync(path.join(__dirname, 'lsp.json'), JSON.stringify({ gorg, glen, layout, words }));
-console.log('wrote src/js/lsp.json: genome ' + glen + ' words at ' + gorg + ', heap ' + layout.HEAP_LO + '..' + layout.HEAP_HI);
+fs.mkdirSync(path.dirname(out), { recursive: true });
+fs.writeFileSync(out, JSON.stringify({ gorg, glen, layout, words }));
+console.log('wrote ' + path.relative(root, out) + ': genome ' + glen + ' words at ' + gorg +
+ ', heap ' + layout.HEAP_LO + '..' + layout.HEAP_HI); \ No newline at end of file