-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode-main.ts
More file actions
42 lines (38 loc) · 972 Bytes
/
node-main.ts
File metadata and controls
42 lines (38 loc) · 972 Bytes
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
import { run } from "./runner";
function cli() {
const importObject = {
imports: {
// we typically define print to mean logging to the console. To make testing
// the compiler easier, we define print so it logs to a string object.
// We can then examine output to see what would have been printed in the
// console.
print_num: (arg: any) => {
console.log(arg);
return arg;
},
print_bool: (arg: any) => {
if (arg !== 0) {
console.log("True");
} else {
console.log("False");
}
},
print_none: () => {
console.log("None");
},
abs: Math.abs,
pow: Math.pow,
min: Math.min,
max: Math.max,
},
output: "",
};
// command to run:
// node node-main.js 987
const input = process.argv[2];
const config = { importObject };
run(input, config).then((value) => {
console.log(value.ans);
});
}
cli();