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

@ -13,4 +13,9 @@ class CompilableSlab(val compiler: Compiler, val slab: Slab) {
fun resolve(symbol: Symbol): CompilableSymbol? = compilableSymbols.firstOrNull {
it.scopeSymbol.symbol == symbol
}
fun resolveVisible(symbol: Symbol): CompilableSymbol? {
val scopeSymbol = slab.scope.resolve(symbol) ?: return null
return compiler.resolveOrNull(scopeSymbol)
}
}

View File

@ -53,7 +53,7 @@ class LocalState(val symbol: CompilableSymbol) {
return Loadable(stubVar = found)
}
}
val found = this.symbol.compilableSlab.resolve(symbol)
val found = this.symbol.compilableSlab.resolveVisible(symbol)
if (found != null) {
return Loadable(call = found)
}

View File

@ -285,7 +285,9 @@ class StubOpEmitter(val compiler: Compiler, val symbol: CompilableSymbol) : Func
code.emit(Opcode.Constant, listOf(defConstant))
}
val formConstant = compiler.constantPool.assign(ConstantTag.String, node.form.id.toByteArray())
code.emit(Opcode.Native, listOf(formConstant, node.definitions.size.toUInt()))
val functionDefinition = symbol.scopeSymbol.definition as FunctionDefinition
val functionArgumentCount = functionDefinition.arguments.size
code.emit(Opcode.Native, listOf(formConstant, node.definitions.size.toUInt(), functionArgumentCount.toUInt()))
}
private fun load(callOrStubVar: Loadable) {