From b66702e49ab7f90a348bb2bea015fd5901c457d8 Mon Sep 17 00:00:00 2001 From: mryouse Date: Thu, 1 Jun 2023 22:47:43 -0400 Subject: add print (no escape sequences) and REPL returns --- compiler.d | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'compiler.d') diff --git a/compiler.d b/compiler.d index 8a00547..08b916b 100644 --- a/compiler.d +++ b/compiler.d @@ -325,6 +325,14 @@ class Compiler { return ValueType.BOOLEAN; } + void compilePrint(Form[] args) { + if (args.length != 1) { + this.error(format("'print': expected [1] argument, received %d", to!int(args.length)), -1); + } + ValueType vt1 = this.resolve(args[0], ValueType.ANY); + this.func.chunk.writeOp(OpCode.OP_PRINT, args[0].line); + } + int parseVariable(Symbol sym) { this.declareVariable(sym); @@ -856,6 +864,10 @@ class Compiler { case "nil?": this.compileIsNil(cons.tail); break; + case "->string": + // does nothing at the moment, as primarily used for printing + // and everything can be printed + break; // LISTS case "append": @@ -877,10 +889,17 @@ class Compiler { case "rest": this.compileRest(cons.tail); break; + + // OTHER + case "print": + this.compilePrint(cons.tail); + break; + default: this.resolve(head); this.call(cons.tail); break; + } return ValueType.NIL; -- cgit v1.2.3