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