diff --git a/src/main/kotlin/lumen/bytecode/Chunk.kt b/src/main/kotlin/lumen/bytecode/Chunk.kt new file mode 100644 index 0000000..2cd9c1b --- /dev/null +++ b/src/main/kotlin/lumen/bytecode/Chunk.kt @@ -0,0 +1,28 @@ +package lumen.bytecode + +import lumen.runtime.Value + +class Chunk { + val code = mutableListOf() + val lines = mutableListOf() + val columns = mutableListOf() + val constants = mutableListOf() + + fun emit(byte: Int, line: Int, column: Int): Int { + code.add(byte) + lines.add(line) + columns.add(column) + return code.size - 1 + } + + fun emit(op: Opcode, line: Int, column: Int): Int = emit(op.ordinal, line, column) + + fun addConstant(value: Value): Int { + constants.add(value) + return constants.size - 1 + } + + fun patch(offset: Int, value: Int) { + code[offset] = value + } +}