Commands only have a single argument

This commit is contained in:
Jordan Eldredge 2019-07-14 15:41:33 -07:00
parent e015c15625
commit 5a7489db4e
4 changed files with 11 additions and 14 deletions

View file

@ -1,7 +1,7 @@
import React from "react";
import Variable from "./Variable";
export default function Command({ command, variables }) {
const arg = command.arguments[0];
const { arg } = command;
let foo = null;
switch (command.opcode) {
case 1:

View file

@ -222,8 +222,7 @@ function parseComand({ start, makiFile, length, pos, localFunctions }) {
start,
pos,
opcode,
// TODO: This should just be a single nullable value I think
arguments: [],
arg: null,
command: COMMANDS[opcode],
};
@ -278,7 +277,7 @@ function parseComand({ start, makiFile, length, pos, localFunctions }) {
throw new Error("Invalid argType");
}
command.arguments = [arg];
command.arg = arg;
// From perl: look forward for a stack protection block
// (why do I have to look FORWARD. stupid nullsoft)

View file

@ -44,9 +44,7 @@ function printCommand({ i, command, stack, variables }) {
`${i} (${command.start} + ${command.offset})`,
command.command.name.toUpperCase(),
command.opcode,
command.arguments.map(offset => {
return printValue(variables[offset]);
})
printValue(variables[command.arg])
);
stack.forEach((value, j) => {
const name = printValue(value, { runtime });

View file

@ -22,7 +22,7 @@ async function interpret(start, program, stack = [], { logger = null }) {
switch (command.opcode) {
// push
case 1: {
const offsetIntoVariables = command.arguments[0];
const offsetIntoVariables = command.arg;
stack.push(variables[offsetIntoVariables]);
break;
}
@ -35,7 +35,7 @@ async function interpret(start, program, stack = [], { logger = null }) {
case 3: {
const a = stack.pop();
let aValue = a instanceof Variable ? a.getValue() : a;
const offsetIntoVariables = command.arguments[0];
const offsetIntoVariables = command.arg;
const toVar = variables[offsetIntoVariables];
toVar.setValue(aValue);
break;
@ -109,14 +109,14 @@ async function interpret(start, program, stack = [], { logger = null }) {
if (value) {
break;
}
const offset = command.arguments[0];
const offset = command.arg;
const nextCommandIndex = offsetToCommand[offset];
i = nextCommandIndex - 1;
break;
}
// jump
case 18: {
const offset = command.arguments[0];
const offset = command.arg;
const nextCommandIndex = offsetToCommand[offset];
i = nextCommandIndex - 1;
break;
@ -125,7 +125,7 @@ async function interpret(start, program, stack = [], { logger = null }) {
// strangeCall (seems to behave just like regular call)
case 24:
case 112: {
const methodOffset = command.arguments[0];
const methodOffset = command.arg;
const { name: methodName, typeOffset: classesOffset } = methods[
methodOffset
];
@ -147,12 +147,12 @@ async function interpret(start, program, stack = [], { logger = null }) {
// callGlobal
case 25: {
// This is where the version checked wa5 scripts start with this offset
if (command.arguments[0].offset === 4294967296) {
if (command.arg.offset === 4294967296) {
// skip ahead to where the real program begins
i = i + 3;
break;
}
const offset = command.arguments[0].offset;
const offset = command.arg.offset;
const nextCommandIndex = offsetToCommand[offset];
const value = await interpret(nextCommandIndex, program, stack, {
logger,