diff options
| author | mryouse | 2023-05-27 01:08:47 +0000 |
|---|---|---|
| committer | mryouse | 2023-05-27 01:08:47 +0000 |
| commit | 21eff156a3094c82ad85f8d3658fc1ac79c63da1 (patch) | |
| tree | 2b0ec423038b812ba5fc0130f2744bd3a23d7083 /compiler.d | |
| parent | a043f552ddca8d890b14bcddf555472ef69e9014 (diff) | |
multiplication
Diffstat (limited to 'compiler.d')
| -rw-r--r-- | compiler.d | 18 |
1 files changed, 18 insertions, 0 deletions
@@ -240,6 +240,21 @@ class Compiler { return ValueType.NUMBER; } + void compileMultiply(Form[] args) { + if (args.length < 2) { + this.error(format("'*': expected [2+] arguments, received %d", args.length), -1); + this.advance(); + return; + } + ValueType vt = this.resolve(args[0], ValueType.NUMBER); + this.func.chunk.writeOp(OpCode.OP_TYPE_CHECK_NUMBER, args[0].line); + for (int i = 1; i < args.length; i++) { + vt = this.resolve(args[i], ValueType.NUMBER); + this.func.chunk.writeOp(OpCode.OP_TYPE_CHECK_NUMBER, args[i].line); + this.func.chunk.writeOp(OpCode.OP_MULTIPLY, args[i].line); + } + } + //ValueType compileLess(Form[] args, ValueType expected = ValueType.ANY) { ValueType compileLess(Form[] args, ValueType expected) { if (args.length != 2) { @@ -833,6 +848,9 @@ class Compiler { return this.compileSubtract(cons.tail, ValueType.NUMBER); } break; + case "*": + this.compileMultiply(cons.tail); + break; // BOOLEAN case "<": |
