-
Notifications
You must be signed in to change notification settings - Fork 0
/
VM.js
95 lines (94 loc) · 3.47 KB
/
VM.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
fso = new ActiveXObject("Scripting.FileSystemObject");
program = fso.OpenTextFile(WSH.Arguments(0));
memory = [];
while (!program.AtEndOfStream) {
line = program.ReadLine();
memory = memory.concat(line.split(" "));
}
prgLen = memory.length;
ip = 0;
while (true) {
switch (memory[parseInt(ip)]) {
case "end":
WSH.Quit();
case "checkgoodnum":
if ((memory[memory[parseInt(ip) + 1]] % 1 != 0) || (memory[memory[parseInt(ip) + 1]] < 0)) {
WScript.Echo("Incorrect value");
WScript.Quit();
}
case "check":
if ((memory[memory[parseInt(ip) + 1]] % 1 != 0) || (memory[memory[parseInt(ip) + 1]] < 0) || (memory[memory[parseInt(ip) + 1]] > 17)) {
WScript.Echo("Incorrect value");
WScript.Quit();
}
case "input":
memory[memory[parseInt(ip) + 1]] = WScript.StdIn.ReadLine();
ip = parseInt(ip) + 2;
break;
case "is":
memory[memory[parseInt(ip) + 1]] = memory[memory[parseInt(ip) + 2]];
ip = parseInt(ip) + 3;
break;
case "print":
WSH.Echo(memory[memory[parseInt(ip) + 1]]);
ip = parseInt(ip) + 2;
break;
case "plus":
memory[memory[parseInt(ip) + 3]] = parseInt(memory[memory[parseInt(ip) + 1]]) + parseInt(memory[memory[parseInt(ip) + 2]]);
ip = parseInt(ip) + 4;
break;
case "minus":
memory[memory[parseInt(ip) + 3]] = memory[memory[parseInt(ip) + 1]] - memory[memory[parseInt(ip) + 2]];
ip = parseInt(ip) + 4;
break;
case "mult":
memory[memory[parseInt(ip) + 3]] = parseInt(memory[memory[parseInt(ip) + 1]]) * parseInt(memory[memory[parseInt(ip) + 2]]);
ip = parseInt(ip) + 4;
break;
case "div":
memory[memory[parseInt(ip) + 3]] = parseInt(memory[memory[parseInt(ip) + 1]] / memory[memory[parseInt(ip) + 2]]);
ip = parseInt(ip) + 4;
break;
case "goto":
ip = memory[parseInt(ip) + 1];
break;
case "gotox":
ip = memory[memory[parseInt(ip) + 1]];
break;
case "ifequalx":
if (memory[memory[parseInt(ip) + 1]] == memory[memory[parseInt(ip) + 2]]) {
ip = memory[memory[parseInt(ip) + 3]];
} else {
ip = memory[memory[parseInt(ip) + 4]];
}
break;
case "ifequal":
if (memory[memory[parseInt(ip) + 1]] == memory[memory[parseInt(ip) + 2]]) {
ip = memory[parseInt(ip) + 3];
} else {
ip = memory[parseInt(ip) + 4];
}
break;
case "iflessx":
if (memory[memory[parseInt(ip) + 1]] < memory[memory[parseInt(ip) + 2]]) {
ip = parseInt(memory[memory[parseInt(ip) + 3]]);
} else {
ip = parseInt(memory[memory[parseInt(ip) + 4]]);
}
break;
case "ifless":
if (memory[memory[parseInt(ip) + 1]] < memory[memory[parseInt(ip) + 2]]) {
ip = parseInt(memory[parseInt(ip) + 3]);
} else {
ip = parseInt(memory[parseInt(ip) + 4]);
}
break;
default:
if (parseInt(ip) <= memory.length) {
ip++;
} else {
WSH.Echo("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
WSH.Quit();
}
}
}