mirror of
https://github.com/GayPizzaSpecifications/pork.git
synced 2025-08-02 21:00:56 +00:00
rework some bits of the compiler to work more appropriately
This commit is contained in:
parent
17b1aa44c0
commit
a48fac4581
@ -1,5 +1,7 @@
|
||||
package gay.pizza.pork.common
|
||||
|
||||
import java.util.stream.IntStream
|
||||
|
||||
class IndentBuffer(
|
||||
val buffer: StringBuilder = StringBuilder(),
|
||||
indent: String = " "
|
||||
@ -13,4 +15,12 @@ class IndentBuffer(
|
||||
}
|
||||
|
||||
override fun toString(): String = buffer.toString()
|
||||
|
||||
override fun chars(): IntStream {
|
||||
return buffer.chars()
|
||||
}
|
||||
|
||||
override fun codePoints(): IntStream {
|
||||
return buffer.codePoints()
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,11 @@ abstract class IndentTracked(val indent: String) {
|
||||
emit(indentLevelText)
|
||||
}
|
||||
|
||||
fun emitIndented(text: String) {
|
||||
emitIndent()
|
||||
emit(text)
|
||||
}
|
||||
|
||||
fun emitIndentedLine(line: String) {
|
||||
emitIndent()
|
||||
emitLine(line)
|
||||
|
@ -46,7 +46,11 @@ class CompilableSymbol(val compilableSlab: CompilableSlab, val scopeSymbol: Scop
|
||||
}
|
||||
val type = if (what is NativeFunctionDescriptor) {
|
||||
IrDefinitionType.NativeFunction
|
||||
} else IrDefinitionType.CodeFunction
|
||||
} else if (scopeSymbol.definition is LetDefinition) {
|
||||
IrDefinitionType.Variable
|
||||
} else {
|
||||
IrDefinitionType.CodeFunction
|
||||
}
|
||||
val irCodeElement = irCodeEmitter.visit(what)
|
||||
val irCodeBlock = if (irCodeElement is IrCodeBlock) {
|
||||
irCodeElement
|
||||
|
@ -42,7 +42,9 @@ class Compiler(val world: World) {
|
||||
}
|
||||
}
|
||||
|
||||
fun compileIrWorld(): IrWorld {
|
||||
fun compileIrWorld(entryPointSymbol: CompilableSymbol): IrWorld {
|
||||
val usedSymbolSet = mutableSetOf<CompilableSymbol>()
|
||||
contributeCompiledSymbols(usedSymbolSet, entryPointSymbol.scopeSymbol, entryPointSymbol)
|
||||
val slabs = mutableListOf<IrSlab>()
|
||||
for (slab in world.slabs) {
|
||||
slabs.add(compilableSlabs.of(slab).compiledIrSlab)
|
||||
|
@ -8,6 +8,6 @@ func fib(n) {
|
||||
}
|
||||
|
||||
export func main() {
|
||||
let result = fib(20)
|
||||
let result = fib(28)
|
||||
println(result)
|
||||
}
|
||||
|
@ -18,5 +18,5 @@ include(
|
||||
":ffi",
|
||||
":tool",
|
||||
":minimal",
|
||||
":support:pork-idea"
|
||||
":support:pork-idea",
|
||||
)
|
||||
|
@ -39,7 +39,7 @@ class CompileCommand : CliktCommand("compile") {
|
||||
val compiledSlab = compiler.compilableSlabs.of(slab)
|
||||
val compiledMain = compiledSlab.resolve(Symbol("main"))
|
||||
?: throw RuntimeException("'main' function not found.")
|
||||
val irWorld = compiler.compileIrWorld()
|
||||
val irWorld = compiler.compileIrWorld(compiledMain)
|
||||
val compiledWorld = compiler.compile(compiledMain)
|
||||
if (showIrCode) {
|
||||
printCompiledIr(irWorld)
|
||||
|
@ -16,7 +16,7 @@ class RootCommand : CliktCommand("pork") {
|
||||
AttributeCommand(),
|
||||
ScopeAnalysisCommand(),
|
||||
CopyStdlibCommand(),
|
||||
CompileCommand()
|
||||
CompileCommand(),
|
||||
)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user