aboutsummaryrefslogtreecommitdiff
path: root/compiler.d
diff options
context:
space:
mode:
Diffstat (limited to 'compiler.d')
-rw-r--r--compiler.d16
1 files changed, 16 insertions, 0 deletions
diff --git a/compiler.d b/compiler.d
index f94aad3..a9d3c3d 100644
--- a/compiler.d
+++ b/compiler.d
@@ -255,6 +255,19 @@ class Compiler {
}
}
+ void compileDivide(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);
+ vt = this.resolve(args[1], ValueType.NUMBER);
+ this.func.chunk.writeOp(OpCode.OP_TYPE_CHECK_NUMBER, args[1].line);
+ this.func.chunk.writeOp(OpCode.OP_DIVIDE, args[1].line);
+ }
+
//ValueType compileLess(Form[] args, ValueType expected = ValueType.ANY) {
ValueType compileLess(Form[] args, ValueType expected) {
if (args.length != 2) {
@@ -851,6 +864,9 @@ class Compiler {
case "*":
this.compileMultiply(cons.tail);
break;
+ case "/":
+ this.compileDivide(cons.tail);
+ break;
// BOOLEAN
case "<":