Rework module system
Don't require/allow naming a module, instead require that the importer names it. Allow importing into the local scope with the name !Local. Simplify namespacing logic. Updates all tests to reflect these changes.
This commit is contained in:
@ -532,6 +532,9 @@ modules = testGroup "Test modules"
|
||||
, testCase "Lambda expression namespaces" $ do
|
||||
res <- liftIO $ evaluateFileResult "./test/lambda-A.tri"
|
||||
res @?= Leaf
|
||||
, testCase "Local namespace import chain" $ do
|
||||
res <- liftIO $ evaluateFileResult "./test/local-ns/1.tri"
|
||||
res @?= Fork (Stem Leaf) (Fork (Stem Leaf) Leaf)
|
||||
]
|
||||
|
||||
|
||||
|
@ -1 +0,0 @@
|
||||
t (t (t (t (t t) (t t t)) t) t t) t
|
@ -1 +0,0 @@
|
||||
x = t (t t) t
|
@ -1,4 +1,3 @@
|
||||
!module Cycle
|
||||
|
||||
!import "test/cycle-2.tri" Cycle2
|
||||
|
||||
|
@ -1,4 +1,3 @@
|
||||
!module Cycle2
|
||||
|
||||
!import "test/cycle-1.tri" Cycle1
|
||||
|
||||
|
@ -1,2 +1 @@
|
||||
!module A
|
||||
main = (\x : x) t
|
||||
|
4
test/local-ns/1.tri
Normal file
4
test/local-ns/1.tri
Normal file
@ -0,0 +1,4 @@
|
||||
|
||||
!import "test/local-ns/2.tri" Two
|
||||
|
||||
main = Two.x
|
2
test/local-ns/2.tri
Normal file
2
test/local-ns/2.tri
Normal file
@ -0,0 +1,2 @@
|
||||
|
||||
!import "test/local-ns/3.tri" !Local
|
2
test/local-ns/3.tri
Normal file
2
test/local-ns/3.tri
Normal file
@ -0,0 +1,2 @@
|
||||
|
||||
x = 3
|
@ -1,5 +0,0 @@
|
||||
!module Test
|
||||
|
||||
!import "lib/base.tri" Lib
|
||||
|
||||
main = Lib.not? t
|
@ -1 +0,0 @@
|
||||
n = t t t
|
@ -1,3 +1,2 @@
|
||||
!module A
|
||||
!import "./test/multi-level-B.tri" B
|
||||
main = B.main
|
||||
|
@ -1,3 +1,2 @@
|
||||
!module B
|
||||
!import "./test/multi-level-C.tri" C
|
||||
main = C.val
|
||||
|
@ -1,2 +1 @@
|
||||
!module C
|
||||
val = t
|
||||
|
7
test/named-imports/1.tri
Normal file
7
test/named-imports/1.tri
Normal file
@ -0,0 +1,7 @@
|
||||
|
||||
!import "lib/base.tri"
|
||||
|
||||
!import "test/named-imports/2.tri"
|
||||
!import "test/named-imports/3.tri" ThreeRenamed
|
||||
|
||||
main = equal? (equal? Two.x 2) (equal? ThreeRenamed.x 3)
|
2
test/named-imports/2.tri
Normal file
2
test/named-imports/2.tri
Normal file
@ -0,0 +1,2 @@
|
||||
|
||||
x = 2
|
2
test/named-imports/3.tri
Normal file
2
test/named-imports/3.tri
Normal file
@ -0,0 +1,2 @@
|
||||
|
||||
x = 3
|
@ -1,3 +1,2 @@
|
||||
!module A
|
||||
!import "./test/namespace-B.tri" B
|
||||
main = B.x
|
||||
|
@ -1,2 +1 @@
|
||||
!module B
|
||||
x = t
|
||||
|
@ -1 +0,0 @@
|
||||
namedTerm = undefinedForTesting
|
@ -1,2 +1 @@
|
||||
!module A
|
||||
main = undefinedVar
|
||||
|
@ -1,4 +1,3 @@
|
||||
!module A
|
||||
|
||||
!import "./test/vars-B.tri" B
|
||||
|
||||
|
@ -1,2 +1 @@
|
||||
!module B
|
||||
y = \x : x
|
||||
|
@ -1,2 +1 @@
|
||||
!module C
|
||||
z = t
|
||||
|
Reference in New Issue
Block a user