From aab6510a0e59c26a31526ff303a9d581736815fc Mon Sep 17 00:00:00 2001 From: mryouse Date: Fri, 26 May 2023 02:52:39 +0000 Subject: eq? for many things --- compiler.d | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'compiler.d') diff --git a/compiler.d b/compiler.d index eccc4ce..4fb37f2 100644 --- a/compiler.d +++ b/compiler.d @@ -304,6 +304,20 @@ class Compiler { return ValueType.BOOLEAN; } + ValueType compileEq(Form[] args) { + if (args.length != 2) { + this.error(format("'eq?': expected [1] argument, received %d", to!int(args.length)), -1); + this.advance(); + return ValueType.NIL; + } + ValueType vt1 = this.resolve(args[0], ValueType.ANY); + ValueType vt2 = this.resolve(args[1], ValueType.ANY); + + this.func.chunk.writeOp(OpCode.OP_EQUAL, args[1].line); + + return ValueType.BOOLEAN; + } + //int parseVariable(Def def) { int parseVariable(Symbol sym) { @@ -726,6 +740,8 @@ class Compiler { return this.compileSubtract(cons.tail, ValueType.NUMBER); } break; + + // BOOLEAN case "<": return this.compileLess(cons.tail, ValueType.NUMBER); break; @@ -742,6 +758,8 @@ class Compiler { return vt; case "not": return this.compileNot(cons.tail); + case "eq?": + return this.compileEq(cons.tail); // STRINGS case "concat": -- cgit v1.2.3