nothing's falsity can unwind the unwary

This commit is contained in:
mehbark 2023-04-17 16:44:10 -04:00
parent 4cb13e0a16
commit 855e55bff7

View file

@ -246,7 +246,6 @@ function parse_op(op: string): Option<Op> {
case "swp":
return op;
}
console.log(op);
}
type State = {
@ -262,7 +261,7 @@ const INITIAL_STATE: State = {
};
function steps(state: State, ops: Op[], limit = 300, num_steps = 0): State[] {
if (!ops[state.ip] || num_steps > limit) {
if (typeof ops[state.ip] == "undefined" || num_steps > limit) {
return [state];
}
return cons(
@ -288,7 +287,9 @@ function step(state: State, op: Op): State {
if (typeof op == "number") {
ns.stack.push(op);
} else {
return ns;
}
switch (op) {
case "add":
binary_op(0, 0, (a, b) => a + b);
@ -338,7 +339,6 @@ function step(state: State, op: Op): State {
break;
}
}
}
return ns;
}