lab17: part 3
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user