lab17: part 4
This commit is contained in:
@@ -140,12 +140,12 @@ class Compiler {
|
||||
// Booleans will be stored as either 1 for true, or as a 0 for false.
|
||||
return;
|
||||
} else if (ast.type === VAR) {
|
||||
//
|
||||
// ***YOUR CODE HERE***
|
||||
//
|
||||
// We look up the offset for a variable and push the offset
|
||||
// value on to the stack. The 'MLOAD' operation will
|
||||
// retrieve the value stored at that position in the memory.
|
||||
this.writeOp('PUSH1');
|
||||
this.writeByte(this.varMap[ast.value]);
|
||||
this.writeOp('MLOAD');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -167,9 +167,6 @@ class Compiler {
|
||||
break;
|
||||
|
||||
case "define":
|
||||
//
|
||||
// ***YOUR CODE HERE***
|
||||
//
|
||||
// The define function lets us store variables.
|
||||
//
|
||||
// The variable name is stored in 'second.value'.
|
||||
@@ -182,6 +179,14 @@ class Compiler {
|
||||
//
|
||||
// Increment this.varOffset so that it points to the next
|
||||
// position in memory.
|
||||
this.varMap[second.value] = this.varOffset;
|
||||
rest.forEach((x) => {
|
||||
this.writeBytecode(x);
|
||||
});
|
||||
this.writeOp('PUSH1');
|
||||
this.writeByte(this.varOffset);
|
||||
this.writeOp('MSTORE');
|
||||
this.varOffset++;
|
||||
break;
|
||||
|
||||
case "if":
|
||||
|
||||
Reference in New Issue
Block a user