From 21eff156a3094c82ad85f8d3658fc1ac79c63da1 Mon Sep 17 00:00:00 2001 From: mryouse Date: Sat, 27 May 2023 01:08:47 +0000 Subject: multiplication --- compiler.d | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'compiler.d') diff --git a/compiler.d b/compiler.d index d55b7f5..f94aad3 100644 --- a/compiler.d +++ b/compiler.d @@ -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 "<": -- cgit v1.2.3