From 8e1f84b1369909745859777d07a5e8e74b5df334 Mon Sep 17 00:00:00 2001 From: Ben Winston Date: Sun, 21 May 2023 20:26:59 -0400 Subject: move disassembly into compiler, preparing for functions --- chunk.d | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'chunk.d') diff --git a/chunk.d b/chunk.d index 87c9fb6..c512f14 100644 --- a/chunk.d +++ b/chunk.d @@ -6,6 +6,7 @@ import parser; enum ObjType { FUNCTION, + SCRIPT, } abstract class Obj { @@ -14,19 +15,22 @@ abstract class Obj { class Function : Obj { Chunk chunk; + int arity; string name; + ObjType type; - this() { - this.type = ObjType.FUNCTION; + this(ObjType type) { + this.type = type; this.chunk = new Chunk(); + this.arity = 0; this.name = ""; } override string toString() { - if (name == "") { + if (type == ObjType.SCRIPT) { return ""; } else { - return name; + return format("", name); } } } -- cgit v1.2.3