bytecode: enhance symbol table with both slab and symbol name

This commit is contained in:
Alex Zenla 2023-11-21 23:27:21 -08:00
parent 6211ad4ff1
commit 76290a401a
Signed by: alex
GPG Key ID: C0780728420EBFE5
9 changed files with 20 additions and 12 deletions

View File

@ -4,7 +4,10 @@ import kotlinx.serialization.Serializable
@Serializable
data class SymbolInfo(
val id: String,
val slab: String,
val symbol: String,
val offset: UInt,
val size: UInt
)
) {
val commonSymbolIdentity: String by lazy { "$slab $symbol" }
}

View File

@ -28,7 +28,7 @@ class CompilableSymbol(val compilableSlab: CompilableSlab, val scopeSymbol: Scop
}
val id: String
get() = "${compilableSlab.slab.location.commonFriendlyName} ${scopeSymbol.symbol.id}"
get() = "${compilableSlab.slab.location.commonLocationIdentity} ${scopeSymbol.symbol.id}"
override fun toString(): String = "${compilableSlab.slab.location.commonFriendlyName} ${scopeSymbol.symbol.id}"
override fun toString(): String = "${compilableSlab.slab.location.commonLocationIdentity} ${scopeSymbol.symbol.id}"
}

View File

@ -11,7 +11,12 @@ class CompiledWorldLayout(val compiler: Compiler) : StubResolutionContext {
val start = allStubOps.size
val result = symbol.compiledStubOps
val stubOps = result.ops
symbolTable[symbol] = SymbolInfo(symbol.id, start.toUInt(), stubOps.size.toUInt())
symbolTable[symbol] = SymbolInfo(
slab = symbol.compilableSlab.slab.location.commonLocationIdentity,
symbol = symbol.id,
offset = start.toUInt(),
size = stubOps.size.toUInt()
)
allStubOps.addAll(stubOps)
allStubAnnotations.addAll(result.annotations)
}

View File

@ -19,7 +19,7 @@ class Compiler {
fun resolve(scopeSymbol: ScopeSymbol): CompilableSymbol = resolveOrNull(scopeSymbol) ?:
throw RuntimeException(
"Unable to resolve scope symbol: " +
"${scopeSymbol.slabScope.slab.location.commonFriendlyName} ${scopeSymbol.symbol.id}")
"${scopeSymbol.slabScope.slab.location.commonLocationIdentity} ${scopeSymbol.symbol.id}")
fun contributeCompiledSymbols(
into: MutableSet<CompilableSymbol>,

View File

@ -4,7 +4,7 @@ import gay.pizza.pork.ast.gen.FunctionDefinition
import gay.pizza.pork.execution.ArgumentList
class FunctionContext(val slabContext: SlabContext, val node: FunctionDefinition) : CallableFunction {
val name: String by lazy { "${slabContext.slab.location.commonFriendlyName} ${node.symbol.id}" }
val name: String by lazy { "${slabContext.slab.location.commonLocationIdentity} ${node.symbol.id}" }
private fun resolveMaybeNative(): CallableFunction? = if (node.nativeFunctionDescriptor == null) {
null

View File

@ -7,8 +7,8 @@ import gay.pizza.pork.ast.gen.visit
import gay.pizza.pork.frontend.Slab
class SlabContext(val slab: Slab, val evaluator: Evaluator, rootScope: Scope) {
val internalScope = rootScope.fork("internal ${slab.location.commonFriendlyName}")
val externalScope = rootScope.fork("external ${slab.location.commonFriendlyName}")
val internalScope = rootScope.fork("internal ${slab.location.commonLocationIdentity}")
val externalScope = rootScope.fork("external ${slab.location.commonLocationIdentity}")
init {
processAllDefinitions()

View File

@ -3,7 +3,7 @@ package gay.pizza.pork.frontend
import gay.pizza.pork.tokenizer.SourceIndex
data class SourceLocation(val form: String, val filePath: String, val index: SourceIndex? = null) {
val commonFriendlyName: String by lazy { "$form $filePath" }
val commonLocationIdentity: String by lazy { "$form $filePath" }
fun withSourceIndex(index: SourceIndex): SourceLocation =
SourceLocation(form, filePath, index)

View File

@ -21,7 +21,7 @@ class CompileCommand : CliktCommand(help = "Compile Pork to Bytecode", name = "c
val compiledWorld = compiler.compile(compiledMain)
for (symbol in compiledWorld.symbolTable.symbols) {
val code = compiledWorld.code.subList(symbol.offset.toInt(), (symbol.offset + symbol.size).toInt())
println(symbol.id)
println(symbol.commonSymbolIdentity)
for ((index, op) in code.withIndex()) {
var annotation = ""
val annotations = compiledWorld.annotations.filter { it.inst == (symbol.offset + index.toUInt()) }

View File

@ -20,7 +20,7 @@ class ScopeAnalysisCommand : CliktCommand(help = "Run Scope Analysis", name = "s
"symbol ${visibleScopeSymbol.scopeSymbol.symbol.id} " +
"type=${visibleScopeSymbol.scopeSymbol.definition.type.name} " +
"internal=${visibleScopeSymbol.isInternalSymbol} " +
"slab=${visibleScopeSymbol.scopeSymbol.slabScope.slab.location.commonFriendlyName}"
"slab=${visibleScopeSymbol.scopeSymbol.slabScope.slab.location.commonLocationIdentity}"
)
}
}