-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.js
More file actions
46 lines (42 loc) · 1.05 KB
/
run.js
File metadata and controls
46 lines (42 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const executor = require("./src/executer.js");
const parser= require("./src/parser.js");
const evaluator = require("./src/evaluator.js");
const fs = require('fs');
const path = require('path');
const readline = require('readline').createInterface({
input: process.stdin,
output: process.stdout
});
let inputCallback = ()=>{}
readline.on('line', (line) => {
inputCallback(line.trim());
})
let runtime = executor.runtimeExecuter();
runtime.config(
parser.runtimeParser(),
evaluator.runtimeEvaluator(),
null,
{
Write: (t) => {process.stdout.write(t);},
Input: (callback) => {
inputCallback = callback;
readline.prompt();
}
},
null,
{},
{inBrowser:false}
);
if (process.argv.length < 3) {
console.error('Excepted an input file as an argument.');
process.exit(1);
}
let fileName = process.argv[2];
let src = fs.readFileSync(path.resolve(__dirname, fileName), 'utf8')
runtime.executeAll(
{"os_host": "node (js)"},
src,
()=>{
readline.close();
}
);