-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathulisp.js
executable file
·49 lines (35 loc) · 961 Bytes
/
ulisp.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
45
46
47
48
49
#!/usr/bin/env node
const { writeFileSync, readFileSync } = require('fs');
const { execSync } = require('child_process');
const { parse, compile } = require('./lib');
const CC = 'gcc';
const SOURCE = 'program.S';
function main(args) {
let script = args[2];
if (!script) {
console.log('no source');
return;
}
if (script === '-f') {
if (!args[3]) {
console.log('no sourse by file');
return;
}
script = readFileSync(args[3]).toString();
}
const sExpression = parse(script);
console.warn('s-expression:');
console.dir(sExpression, { depth: 8 });
const program = compile(sExpression[0][0]);
console.log('program:');
console.log(program);
writeFileSync(SOURCE, program);
try {
execSync(`${CC} -mstackrealign -masm=intel -o program ${SOURCE}`);
} catch (error) {
console.error(error);
return;
}
console.log('done; \nrun ./program and echo $? for output');
}
main(process.argv);