From 334eafaff25014b0326b2b42e62e9b4f486736e6 Mon Sep 17 00:00:00 2001 From: mryouse Date: Sat, 27 May 2023 01:48:07 +0000 Subject: any? and nil? --- compiler.d | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/compiler.d b/compiler.d index a9d3c3d..5b06f4c 100644 --- a/compiler.d +++ b/compiler.d @@ -205,6 +205,25 @@ class Compiler { //advance(); } + void compileIsAny(Form[] args) { + if (args.length != 1) { + this.error(format("'any?': expecting [1] argument, received %d", args.length), -1); + this.advance(); + return; + } + this.compileAtom(new Atom(true, args[0].line), ValueType.ANY); + } + + void compileIsNil(Form[] args) { + if (args.length != 1) { + this.error(format("'nil?': expecting [1] argument, received %d", args.length), -1); + this.advance(); + return; + } + ValueType vt = this.resolve(args[0], ValueType.ANY); + this.func.chunk.writeOp(OpCode.OP_IS_NIL, args[0].line); + } + void compileAdd(Form[] args, ValueType expecting) { int line = args[0].line; this.resolve(args[0], expecting); @@ -897,6 +916,14 @@ class Compiler { case "concat": return this.compileConcat(cons.tail); + // TYPES + case "any?": + this.compileIsAny(cons.tail); + break; + case "nil?": + this.compileIsNil(cons.tail); + break; + // LISTS case "append": this.compileAppend(cons.tail); -- cgit v1.2.3