lab17: part 3

This commit is contained in:
2026-04-22 23:48:59 -07:00
parent 1c5df94c31
commit b7285c39d6

View File

@@ -202,24 +202,29 @@ class Compiler {
break;
case "*":
//
// ***YOUR CODE HERE***
//
// Using the '+' case as a template, add support
// for '*'. Note that the 'MUL' opcode only works
// with two arguments, whereas '*' allows an arbitrary
// number of arguments.
this.writeBytecode(second);
rest.forEach((x) => {
this.writeBytecode(x);
this.writeOp('MUL');
});
break;
case "-":
//
// ***YOUR CODE HERE***
//
// Add support for '-'. The approach here will be
// Similar to the solution for '+' and '*'. However,
// one key difference is that the order of the arguments
// matters. You will need to use 'SWAP1' to get the
// arguments ordered correctly before invoking 'SUB'.
this.writeBytecode(second);
rest.forEach((x) => {
this.writeBytecode(x);
this.writeOp('SWAP1');
this.writeOp('SUB');
});
break;
default: