diff options
| author | mryouse | 2023-05-25 21:15:04 +0000 |
|---|---|---|
| committer | mryouse | 2023-05-25 21:15:04 +0000 |
| commit | 9fe6496202bd95d252ed2323a88fd24781780b64 (patch) | |
| tree | 907f85973ab3e5b22b076a27a3933b88855e07ba /dbg.d | |
| parent | d95e4f6f988b16bbd95a9c78c0355d190390f003 (diff) | |
lists as sequences, first and rest
Diffstat (limited to 'dbg.d')
| -rw-r--r-- | dbg.d | 24 |
1 files changed, 22 insertions, 2 deletions
@@ -8,8 +8,8 @@ import parser; //import dbg; //import value; -//bool DEBUG = true; -bool DEBUG = false; +bool DEBUG = true; +//bool DEBUG = false; void printForm(Form f, string prefix = "") { @@ -85,11 +85,17 @@ string printableValue(Value val) { return val.as.type; case ValueType.NIL: return "nil"; + case ValueType.SEQ: + return printableSeq(val.as.seq); default: return "! unknown value type !"; } } +string printableSeq(Seq seq) { + return format("%s", seq); +} + string printableFunction(Obj func) { return format("%s", func); } @@ -119,6 +125,12 @@ int constantInstruction(string message, Chunk chunk, int offset) { return offset + 2; } +int listInstruction(string message, Chunk chunk, int offset) { + ubyte idx = chunk.code[offset + 1]; + writefln("%-16s %4d", message, idx); + return offset + 2; +} + int simpleInstruction(string message, int offset) { writeln(message); return offset + 1; @@ -147,6 +159,8 @@ int disassemble(Chunk chunk, int offset) { return byteInstruction("OP_GET_LOCAL", chunk, offset); case OpCode.OP_SET_LOCAL: return byteInstruction("OP_SET_LOCAL", chunk, offset); + case OpCode.OP_LIST: + return listInstruction("OP_LIST", chunk, offset); case OpCode.OP_ADD: return simpleInstruction("OP_ADD", offset); case OpCode.OP_LESS: @@ -187,6 +201,12 @@ int disassemble(Chunk chunk, int offset) { return simpleInstruction("OP_TYPE_CHECK_NUMBER", offset); case OpCode.OP_TYPE_CHECK_BOOLEAN: return simpleInstruction("OP_TYPE_CHECK_BOOLEAN", offset); + case OpCode.OP_TYPE_CHECK_SEQ: + return simpleInstruction("OP_TYPE_CHECK_SEQ", offset); + case OpCode.OP_FIRST: + return simpleInstruction("OP_FIRST", offset); + case OpCode.OP_REST: + return simpleInstruction("OP_REST", offset); default: writeln("unknown opcode?"); return offset + 1; |
