88 lines
2.2 KiB
Plaintext
88 lines
2.2 KiB
Plaintext
integer n, pc, sp;
|
|
file f;
|
|
text s;
|
|
index code, Data;
|
|
list l, stack, strings;
|
|
|
|
f.affix(argv(1));
|
|
|
|
f.list(l, 0);
|
|
|
|
n = atoi(l[-1]);
|
|
while (n) {
|
|
f.lead(s);
|
|
strings.append(erase(s, -1, 0));
|
|
n -= 1;
|
|
}
|
|
|
|
while (f.list(l, 0) ^ -1) {
|
|
code.put(atoi(lf_x_text(l)), l);
|
|
}
|
|
|
|
pc = sp = 0;
|
|
while (1) {
|
|
l = code[pc];
|
|
s = l[0];
|
|
if (s == "jz") {
|
|
if (lb_pick(stack)) {
|
|
isk_greater(code, pc, pc);
|
|
} else {
|
|
pc = atoi(l[-1]);
|
|
}
|
|
} elif (s == "jmp") {
|
|
pc = atoi(l[-1]);
|
|
} else {
|
|
if (s == "push") {
|
|
lb_push(stack, atoi(l[1]));
|
|
} elif (s == "fetch") {
|
|
lb_push(stack, Data[atoi(erase(l[1], -1, 0))]);
|
|
} elif (s == "neg") {
|
|
stack[-1] = -stack[-1];
|
|
} elif (s == "not") {
|
|
stack[-1] = !stack[-1];
|
|
} elif (s == "halt") {
|
|
break;
|
|
} else {
|
|
n = lb_pick(stack);
|
|
if (s == "store") {
|
|
Data[atoi(erase(l[1], -1, 0))] = n;
|
|
} elif (s == "add") {
|
|
stack[-1] = stack[-1] + n;
|
|
} elif (s == "sub") {
|
|
stack[-1] = stack[-1] - n;
|
|
} elif (s == "mul") {
|
|
stack[-1] = stack[-1] * n;
|
|
} elif (s == "div") {
|
|
stack[-1] = stack[-1] / n;
|
|
} elif (s == "mod") {
|
|
stack[-1] = stack[-1] % n;
|
|
} elif (s == "lt") {
|
|
stack[-1] = stack[-1] < n;
|
|
} elif (s == "gt") {
|
|
stack[-1] = stack[-1] > n;
|
|
} elif (s == "le") {
|
|
stack[-1] = stack[-1] <= n;
|
|
} elif (s == "ge") {
|
|
stack[-1] = stack[-1] >= n;
|
|
} elif (s == "eq") {
|
|
stack[-1] = stack[-1] == n;
|
|
} elif (s == "ne") {
|
|
stack[-1] = stack[-1] != n;
|
|
} elif (s == "and") {
|
|
stack[-1] = stack[-1] && n;
|
|
} elif (s == "or") {
|
|
stack[-1] = stack[-1] || n;
|
|
} elif (s == "prtc") {
|
|
o_byte(n);
|
|
} elif (s == "prti") {
|
|
o_(n);
|
|
} elif (s == "prts") {
|
|
o_(strings[n]);
|
|
} else {
|
|
}
|
|
}
|
|
|
|
isk_greater(code, pc, pc);
|
|
}
|
|
}
|