From ecc350ca5c2eb50be8309c5f14f8bf0d87db9a02 Mon Sep 17 00:00:00 2001 From: Moon Flower Date: Mon, 12 Oct 2026 08:46:23 +0330 Subject: a --- src/js/extract_lsp.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/js/extract_lsp.js (limited to 'src/js/extract_lsp.js') diff --git a/src/js/extract_lsp.js b/src/js/extract_lsp.js new file mode 100644 index 0000000..6f53ebc --- /dev/null +++ b/src/js/extract_lsp.js @@ -0,0 +1,21 @@ +// 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. +const fs = require('fs'); +const path = require('path'); + +const root = path.join(__dirname, '..', '..'); +const genome = fs.readFileSync(path.join(root, 'build', 'lsp', 'genome.h'), '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 gorg = parseInt(genome.match(/#define\s+GORG\s+(\d+)/)[1], 10); +const glen = parseInt(genome.match(/#define\s+GLEN\s+(\d+)/)[1], 10); +const arr = genome.match(/genome\[\]\s*=\s*\{([\s\S]*?)\};/); +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); -- cgit v1.2.3