From 46a9b83a118207f414f2f7e4c0391785dc440fa4 Mon Sep 17 00:00:00 2001 From: mryouse Date: Fri, 26 May 2023 02:24:35 +0000 Subject: make 'concat' work for sequences --- compiler.d | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'compiler.d') diff --git a/compiler.d b/compiler.d index ecd7785..992e36b 100644 --- a/compiler.d +++ b/compiler.d @@ -483,7 +483,7 @@ class Compiler { ValueType vt = this.resolve(args[0], ValueType.STRING); for (int i = 1; i < args.length; i++) { vt = this.resolve(args[i], ValueType.STRING); - this.func.chunk.writeOp(OpCode.OP_TYPE_CHECK_STRING, args[i].line); + this.func.chunk.writeOp(OpCode.OP_TYPE_CHECK_SEQ, args[i].line); // TODO wrong this.func.chunk.writeOp(OpCode.OP_CONCAT, args[i].line); } return ValueType.STRING; @@ -544,6 +544,22 @@ class Compiler { this.func.chunk.writeOp(OpCode.OP_LENGTH, args[0].line); } + void compileAppend(Form[] args) { + if (args.length != 2) { + this.error(format("'append': expected [2] arguments, received %d", args.length), -1); + this.advance(); + return; + } + + ValueType vt1 = this.resolve(args[0], ValueType.SEQ); + this.func.chunk.writeOp(OpCode.OP_TYPE_CHECK_SEQ, args[0].line); + + // TODO if this is used for both string/list, should be able to typecheck second arg here + ValueType vt2 = this.resolve(args[1], ValueType.ANY); + + this.func.chunk.writeOp(OpCode.OP_CONCAT, args[0].line); + } + void compileFirst(Form[] args) { // TODO how do we identify/propagate errors? if (args.length != 1) { -- cgit v1.2.3