-
Notifications
You must be signed in to change notification settings - Fork 1
/
cli.js
executable file
·113 lines (84 loc) · 1.86 KB
/
cli.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/usr/bin/env node
var vm = require('./v3/runtime/VM').create();
var O = require('./v3/runtime/opcodes');
var mod = {
k : [ 42, 50, 1337, 303, 606 ],
vars : [],
code : []
};
// var co1 = {
// code: [
// O.LOADK | (0x0 << 16) | 0x00,
// O.PRINT | 0x00,
// O.LOADK | (0x0 << 16) | 0x01,
// O.PRINT | 0x00,
// O.JMP | 0x00
// ],
// module: mod
// };
var co1 = {
code: [
// make function into R[1] from code object 0x01
O.MKFUN | (0x01 << 16) | 0x01,
O.MKFUN | (0x03 << 16) | 0x02,
// spawn task from function in R[1], with 0 args, and place task object in R[0]
O.SPAWN | (0x01 << 16) | (0x00 << 8) | (0x00 << 0),
O.SPAWN | (0x03 << 16) | (0x00 << 8) | (0x00 << 2),
O.TERM
],
module: mod
}
mod.code.push(co1);
var co2 = {
code: [
O.LOADK | (0x0 << 16) | 0x02,
O.PRINT | 0x00,
O.YIELD,
O.JMP | 0x01
],
module: mod
};
mod.code.push(co2);
var co3 = {
code: [
O.MKFUN | (0x1 << 16) | 0x03,
O.LOADK | (0x2 << 16) | 0x03,
O.LOADK | (0x3 << 16) | 0x04,
O.CALL | (0x01 << 16) | (0x02 << 8) | 0x00,
O.PRINT | 0x00,
O.YIELD,
O.JMP | 0x03
],
module: mod
};
mod.code.push(co3);
var co4 = {
code: [
O.ADD | (0x02 << 16) | (0x00 << 8) | (0x01 << 0),
O.RETURN | 0x02
],
module: mod,
stackSize: 3
}
mod.code.push(co4);
vm.start(co1);
// console.log(vm);
// vm.run(co);
// var Assembler = require('./v3/compiler/Assembler');
// var asm = new Assembler();
// var cc = asm.newCodeObject();
// cc.stackSize = 3;
// cc.loadConstant(0, 10);
// cc.loadConstant(1, 35);
// cc.add(2, 0, 1);
// cc.halt();
// var co = cc.compile();
// console.log(co);
// var parser = require('./v3/parser'),
// analyse = require('./v3/analysis/analyse'),
// fs = require('fs');
// var args = process.argv.slice(1);
// fs.readFile(args[1], 'utf8', function(err, source) {
// var mod = parser.parse(source);
// analyse(mod);
// });