diff --git a/lab17/compiler.js b/lab17/compiler.js index 2750835..01240a5 100644 --- a/lab17/compiler.js +++ b/lab17/compiler.js @@ -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: