-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
52 lines (48 loc) · 1 KB
/
main.go
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
package main
import (
"fmt"
)
func main() {
ins := Instructions{
// test fn call
// OP_CONST, 0,
// OP_CALL, 0x00, 0x08, 1,
// OP_PRINT,
// OP_HALT,
// // fnc
// OP_CONST, 1,
// OP_CONST, 2,
// OP_STORE, 0,
// OP_LOAD, 0,
// OP_IADD,
// OP_RET,
// test array
// OP_CONST, 0,
// OP_CONST, 0,
// OP_CONST, 1,
// OP_CONST, 0,
// OP_CONST, 0,
// OP_ARRAY, 0x00, 0x05,
// OP_PRINT,
// OP_ARRID, 0x00, 0x02,
// OP_PRINT,
// OP_HALT,
// test branching
OP_CONST, 0,
OP_CONST, 1,
OP_EQ,
OP_JF, 0x00, 0x0a,
OP_CONST, 2,
OP_CONST, 3,
OP_PRINT,
}
vm := VMNew(ins)
vm.constants[0] = ObjInt{10}
vm.constants[1] = ObjInt{20}
vm.constants[2] = ObjInt{30}
vm.constants[3] = ObjInt{40}
e := vm.Run()
if e != nil {
fmt.Println(e.Error())
}
}