aboutsummaryrefslogtreecommitdiff
path: root/compiler.d
diff options
context:
space:
mode:
Diffstat (limited to 'compiler.d')
-rw-r--r--compiler.d18
1 files changed, 18 insertions, 0 deletions
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 "<":