From b7285c39d642904794180b4f765485916ae2171f Mon Sep 17 00:00:00 2001 From: Yuri Tatishchev Date: Wed, 22 Apr 2026 23:48:59 -0700 Subject: [PATCH] lab17: part 3 --- lab17/compiler.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) 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: