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:
@ -4,6 +4,7 @@ import gay.pizza.pork.ast.CompilationUnit
|
||||
import gay.pizza.pork.ast.Definition
|
||||
import gay.pizza.pork.ast.FunctionDefinition
|
||||
import gay.pizza.pork.ast.ImportDeclaration
|
||||
import gay.pizza.pork.frontend.ImportLocator
|
||||
|
||||
class CompilationUnitContext(
|
||||
val compilationUnit: CompilationUnit,
|
||||
@ -50,8 +51,8 @@ class CompilationUnitContext(
|
||||
}
|
||||
|
||||
private fun processImport(import: ImportDeclaration) {
|
||||
val path = import.path.text
|
||||
val evaluationContext = evaluator.context(path)
|
||||
val importLocator = ImportLocator(import.path.text, import.form?.id)
|
||||
val evaluationContext = evaluator.context(importLocator)
|
||||
internalScope.inherit(evaluationContext.externalScope)
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +1,18 @@
|
||||
package gay.pizza.pork.evaluator
|
||||
|
||||
import gay.pizza.pork.frontend.ImportLocator
|
||||
import gay.pizza.pork.frontend.World
|
||||
|
||||
class Evaluator(val world: World, val scope: Scope) {
|
||||
private val contexts = mutableMapOf<String, CompilationUnitContext>()
|
||||
private val nativeFunctionProviders = mutableMapOf<String, NativeFunctionProvider>()
|
||||
|
||||
fun evaluate(path: String): Scope =
|
||||
context(path).externalScope
|
||||
fun evaluate(locator: ImportLocator): Scope =
|
||||
context(locator).externalScope
|
||||
|
||||
fun context(path: String): CompilationUnitContext {
|
||||
val unit = world.load(path)
|
||||
val identity = world.contentSource.stableContentIdentity(path)
|
||||
fun context(locator: ImportLocator): CompilationUnitContext {
|
||||
val unit = world.load(locator)
|
||||
val identity = world.stableIdentity(locator)
|
||||
val context = contexts.computeIfAbsent(identity) {
|
||||
CompilationUnitContext(unit, this, scope)
|
||||
}
|
||||
|
Reference in New Issue
Block a user