aboutsummaryrefslogtreecommitdiff
path: root/tests/drivers/image_run.js
diff options
context:
space:
mode:
Diffstat (limited to 'tests/drivers/image_run.js')
-rw-r--r--tests/drivers/image_run.js14
1 files changed, 14 insertions, 0 deletions
diff --git a/tests/drivers/image_run.js b/tests/drivers/image_run.js
new file mode 100644
index 0000000..6d0b949
--- /dev/null
+++ b/tests/drivers/image_run.js
@@ -0,0 +1,14 @@
+// run a generated image directly, avoiding compiler time in vm execution tests.
+const fs = require('fs');
+const { TinyVM } = require('../../src/js/tinyvm.js');
+const { mapValues } = require('../../src/js/mapvalues.js');
+const header = fs.readFileSync(process.argv[2], 'utf8');
+const org = Number(header.match(/#define\s+GORG\s+(\d+)/)[1]);
+const words = header.match(/genome\[\]\s*=\s*\{([\s\S]*?)\};/)[1].split(',').map(s => s.trim()).filter(Boolean);
+const layout = mapValues(process.argv[3], ['GORG', 'DS0', 'DSLIM', 'RS0', 'RSLIM', 'SYSGATE', 'ZFP', 'HEAP_LO', 'HEAP_HI']);
+const machine = new TinyVM({ layout, onMessage: message => process.stderr.write(message) });
+machine.loadGenome(words, org);
+if (process.argv[4] === '--stdin') machine.setInput(fs.readFileSync(0));
+const status = machine.run();
+process.stdout.write(machine.getOutput());
+process.exit(status);