From 2ffc9959f3324a234d8337f05643c8e531154081 Mon Sep 17 00:00:00 2001 From: mryouse Date: Fri, 26 May 2023 03:15:51 +0000 Subject: in? (lists and strings) --- compiler.d | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'compiler.d') diff --git a/compiler.d b/compiler.d index 4fb37f2..4a3df27 100644 --- a/compiler.d +++ b/compiler.d @@ -596,6 +596,21 @@ class Compiler { this.func.chunk.writeOp(OpCode.OP_CONCAT, args[0].line); } + void compileIn(Form[] args) { + // TODO how do we identify/propagate errors? + if (args.length != 2) { + this.error(format("'in?': expected [2] arguments, received %d", args.length), -1); + this.advance(); + //writeln("COMPILE ERROR: 'first' expects exactly one argument"); + return; + } + ValueType vt1 = this.resolve(args[0], ValueType.ANY); + ValueType vt2 = this.resolve(args[1], ValueType.SEQ); + this.func.chunk.writeOp(OpCode.OP_TYPE_CHECK_SEQ, args[0].line); + + this.func.chunk.writeOp(OpCode.OP_MEMBER, args[0].line); + } + void compileFirst(Form[] args) { // TODO how do we identify/propagate errors? if (args.length != 1) { @@ -772,6 +787,9 @@ class Compiler { case "first": this.compileFirst(cons.tail); break; + case "in?": + this.compileIn(cons.tail); + break; case "length": this.compileLength(cons.tail); break; -- cgit v1.2.3