mirror of
https://github.com/GayPizzaSpecifications/pork.git
synced 2025-08-02 12:50:55 +00:00
Complex import sample and support for import dependency cycles.
This commit is contained in:
parent
4f567eb287
commit
bf3967544a
3
examples/complex/a.pork
Normal file
3
examples/complex/a.pork
Normal file
@ -0,0 +1,3 @@
|
||||
export func a() {
|
||||
println("A")
|
||||
}
|
6
examples/complex/b.pork
Normal file
6
examples/complex/b.pork
Normal file
@ -0,0 +1,6 @@
|
||||
import "c.pork"
|
||||
|
||||
export func b() {
|
||||
c()
|
||||
println("B")
|
||||
}
|
6
examples/complex/c.pork
Normal file
6
examples/complex/c.pork
Normal file
@ -0,0 +1,6 @@
|
||||
import "a.pork"
|
||||
|
||||
export func c() {
|
||||
a()
|
||||
println("C")
|
||||
}
|
6
examples/complex/d.pork
Normal file
6
examples/complex/d.pork
Normal file
@ -0,0 +1,6 @@
|
||||
import "b.pork"
|
||||
|
||||
export func d() {
|
||||
b()
|
||||
println("D")
|
||||
}
|
5
examples/complex/main.pork
Normal file
5
examples/complex/main.pork
Normal file
@ -0,0 +1,5 @@
|
||||
import "d.pork"
|
||||
|
||||
export func main() {
|
||||
d()
|
||||
}
|
@ -8,12 +8,18 @@ class EvaluationContext(
|
||||
val evaluationContextProvider: EvaluationContextProvider,
|
||||
rootScope: Scope
|
||||
) {
|
||||
private var isAlreadySetup = false
|
||||
|
||||
val internalScope = rootScope.fork()
|
||||
val externalScope = rootScope.fork()
|
||||
|
||||
private val evaluationVisitor = EvaluationVisitor(internalScope)
|
||||
|
||||
fun setup() {
|
||||
if (isAlreadySetup) {
|
||||
return
|
||||
}
|
||||
isAlreadySetup = true
|
||||
val imports = compilationUnit.declarations.filterIsInstance<ImportDeclaration>()
|
||||
for (import in imports) {
|
||||
val evaluationContext = evaluationContextProvider.provideEvaluationContext(import.path.text)
|
||||
|
@ -3,7 +3,7 @@ package gay.pizza.pork.eval
|
||||
import gay.pizza.pork.ast.NodeVisitor
|
||||
import gay.pizza.pork.ast.nodes.*
|
||||
|
||||
class EvaluationVisitor(val root: Scope) : NodeVisitor<Any> {
|
||||
class EvaluationVisitor(root: Scope) : NodeVisitor<Any> {
|
||||
private var currentScope: Scope = root
|
||||
|
||||
override fun visitIntLiteral(node: IntLiteral): Any = node.value
|
||||
|
@ -1,7 +0,0 @@
|
||||
package gay.pizza.pork.eval
|
||||
|
||||
import gay.pizza.pork.ast.nodes.CompilationUnit
|
||||
|
||||
interface ImportLoader {
|
||||
fun load(path: String): CompilationUnit
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
package gay.pizza.pork.eval
|
||||
|
||||
import gay.pizza.pork.ast.nodes.CompilationUnit
|
||||
|
||||
object NullImportLoader : ImportLoader {
|
||||
override fun load(path: String): CompilationUnit {
|
||||
throw RuntimeException("NullImportLoader cannot import compilation units.")
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user