global: a working virtual machine for some of the use cases. APIs and validation still WIP.

This commit is contained in:
2023-11-21 22:18:05 -08:00
parent 0a2d029c5c
commit 6211ad4ff1
53 changed files with 434 additions and 182 deletions

View File

@ -4,6 +4,13 @@ import kotlinx.serialization.Serializable
@Serializable
data class Constant(val id: UInt, val tag: ConstantTag, val value: ByteArray) {
fun readAsString(): String {
if (tag != ConstantTag.String) {
throw RuntimeException("Constant $id is not tagged as a string")
}
return String(value)
}
override fun equals(other: Any?): Boolean {
if (this === other) return true
other as Constant

View File

@ -3,4 +3,6 @@ package gay.pizza.pork.bytecode
import kotlinx.serialization.Serializable
@Serializable
data class ConstantPool(val constants: List<Constant>)
data class ConstantPool(val constants: List<Constant>) {
fun read(index: UInt): Constant = constants[index.toInt()]
}