-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.js
executable file
·44 lines (43 loc) · 1.17 KB
/
main.js
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
#!/bin/node
'use strict';
const readline = require('readline'),
rt = require('./rt'),
pjson = require('./package.json');
rt().then(async runt => {
runt.mod.genesis();
const env = runt.mkref(runt.mod.initPrelude());
await runt.evalWait();
if (process.argv.length < 3) {
if (process.stdin.isTTY) {
console.log(`Luwa ${pjson.version} https://github.com/serprex/luwa`);
const line = runt.newstr('return 1+2');
console.log(await runt.eval(env, line));
runt.free(line);
return;
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
prompt: '> ',
});
rl.on('line', async ioline => {
const line = runt.newstr(ioline.replace(/^\s*=/, 'return '));
try {
console.log(await runt.eval(env, line));
} catch (e) {
console.log(e);
}
runt.free(line);
}).on('close', () => process.exit(0));
rl.prompt();
} else {
const result = [];
process.stdin.resume();
process.stdin.on('data', buf => result.push(buf));
process.stdin.on('end', () => {
const src = Buffer.concat(result);
runt.eval(env, src.toString());
});
}
} else {
}
}).catch(e => setImmediate(() => { throw e; }));