mirror of
https://github.com/GayPizzaSpecifications/pork.git
synced 2025-08-03 13:11:32 +00:00
add a standard library, and introduce formed imports (import std "myfile.pork")
This commit is contained in:
@ -10,6 +10,7 @@ dependencies {
|
||||
api(project(":parser"))
|
||||
api(project(":frontend"))
|
||||
api(project(":evaluator"))
|
||||
api(project(":stdlib"))
|
||||
api(project(":ffi"))
|
||||
api("com.github.ajalt.clikt:clikt:4.2.0")
|
||||
implementation(project(":common"))
|
||||
|
@ -1,16 +1,17 @@
|
||||
package gay.pizza.pork.tool
|
||||
|
||||
import gay.pizza.pork.ast.NodeVisitor
|
||||
import gay.pizza.pork.parser.Printer
|
||||
import gay.pizza.pork.ast.CompilationUnit
|
||||
import gay.pizza.pork.ast.NodeVisitor
|
||||
import gay.pizza.pork.ast.visit
|
||||
import gay.pizza.pork.evaluator.Arguments
|
||||
import gay.pizza.pork.evaluator.CallableFunction
|
||||
import gay.pizza.pork.evaluator.Evaluator
|
||||
import gay.pizza.pork.evaluator.Scope
|
||||
import gay.pizza.pork.frontend.ContentSource
|
||||
import gay.pizza.pork.frontend.ImportLocator
|
||||
import gay.pizza.pork.frontend.StandardImportSource
|
||||
import gay.pizza.pork.frontend.World
|
||||
import gay.pizza.pork.parser.*
|
||||
import gay.pizza.pork.stdlib.PorkStdlib
|
||||
|
||||
abstract class Tool {
|
||||
abstract fun createCharSource(): CharSource
|
||||
@ -31,11 +32,13 @@ abstract class Tool {
|
||||
fun <T> visit(visitor: NodeVisitor<T>): T = visitor.visit(parse())
|
||||
|
||||
fun loadMainFunction(scope: Scope, setupEvaluator: Evaluator.() -> Unit = {}): CallableFunction {
|
||||
val contentSource = createContentSource()
|
||||
val world = World(contentSource)
|
||||
val fileContentSource = createContentSource()
|
||||
val standardImportSource = StandardImportSource(fileContentSource)
|
||||
standardImportSource.addContentSource("std", PorkStdlib)
|
||||
val world = World(standardImportSource)
|
||||
val evaluator = Evaluator(world, scope)
|
||||
setupEvaluator(evaluator)
|
||||
val resultingScope = evaluator.evaluate(rootFilePath())
|
||||
val resultingScope = evaluator.evaluate(ImportLocator(rootFilePath()))
|
||||
return resultingScope.value("main") as CallableFunction
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user