mirror of
https://github.com/GayPizzaSpecifications/pork.git
synced 2025-08-02 12:50:55 +00:00
bytecode: enhance symbol table with both slab and symbol name
This commit is contained in:
parent
6211ad4ff1
commit
76290a401a
@ -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" }
|
||||
}
|
||||
|
@ -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}"
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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>,
|
||||
|
@ -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
|
||||
|
@ -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()
|
||||
|
@ -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)
|
||||
|
@ -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()) }
|
||||
|
@ -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}"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user