-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvm_test.go
107 lines (93 loc) · 1.75 KB
/
vm_test.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
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
package vm
import (
"fmt"
"testing"
)
var scriptAndOr = `
// test || and &&
fn main(){
cond1 = 33
cond2 = -1
if (cond2 == -2){
_=printf("true-> cond1 || cond2")
}else{
_=printf("false-> cond1 || cond2")
}
if (cond1 && !cond2){
_=printf("true-> cond1 && cond2")
}else{
_=printf("false-> cond1 && cond2")
}
}
`
var scriptNestedLoops = `
fn main() {
// this is a test
let s = 12;
f = test(1, 2, 4);
_ = printf(f);
for (j=2; j<=120; j = j + 1){
for (kk=3; kk<5; kk = kk + 1){
let xxx = 10
if (xxx<5){
_ = printf("case 1")
for (kkk=0; kkk<2; kkk = kkk + 1){
let g = 3 + -2;
let koko = 3 + 2
let hello = 12;
s = s + 1+kkk+kk+j+add(g, koko, hello);
}
} else if (xxx<15){
_ = printf("case 2");
for (kkk=1; kkk<4; kkk = kkk + 1){
let g = -3 + 4;
let koko = 3 + 2;
let hello = 12;
s = s + 1+kkk+kk+j+add(g, koko, hello);
}
} else if (xxx<11){
_ = printf("case 3");
for (kkk=1; kkk<4; kkk = kkk + 1){
let g = 3 + 4;
let koko = 3 + 2;
let hello = 12;
s = s + 1+kkk+kk+j+add(g, koko, hello);
}
} else {
_ = printf("case 4");
for (kkk=1; kkk<4; kkk = kkk + 1){
let g = 3 + 2;
let koko = 3 + 2;
let hello = 12;
s = s + 1+kkk+kk+j+add(g, koko, hello);
}
}
}
}
_=printf(s);
}
fn test(a, b, c){
return ;
_ = printf("unreachable") ;
}
fn add(a, b, c){
return a + b * c;
}
`
func TestVM_Run(t *testing.T) {
// Hello, world
lex := new(Lexer)
tt, err := lex.Run([]byte(scriptNestedLoops))
if err != nil {
fmt.Println("err" + err.Error())
}
if ok, tree := parseScript(tt); ok {
fmt.Println("OK")
cpl := Compiler{}
cpl.Run(tree)
} else {
fmt.Println("NOK")
printAllErrors()
}
return
}