feat(bytecode): add chunk container
This commit is contained in:
1 parent
3fa3ba4aba
commit
d72611f946
1 file changed
+28
@@ -0,0 +1,28 @@
|
|||||||
|
package lumen.bytecode
|
||||||
|
|
||||||
|
import lumen.runtime.Value
|
||||||
|
|
||||||
|
class Chunk {
|
||||||
|
val code = mutableListOf<Int>()
|
||||||
|
val lines = mutableListOf<Int>()
|
||||||
|
val columns = mutableListOf<Int>()
|
||||||
|
val constants = mutableListOf<Value>()
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user