Rework module system
All checks were successful
Test, Build, and Release / test (push) Successful in 1m37s
Test, Build, and Release / build (push) Successful in 1m14s

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:
2025-01-30 13:56:09 -06:00
parent 09eedfb609
commit bf1000d174
34 changed files with 218 additions and 239 deletions

View File

@ -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)
]

View File

@ -1 +0,0 @@
t (t (t (t (t t) (t t t)) t) t t) t

View File

@ -1 +0,0 @@
x = t (t t) t

View File

@ -1,4 +1,3 @@
!module Cycle
!import "test/cycle-2.tri" Cycle2

View File

@ -1,4 +1,3 @@
!module Cycle2
!import "test/cycle-1.tri" Cycle1

View File

@ -1,2 +1 @@
!module A
main = (\x : x) t

4
test/local-ns/1.tri Normal file
View File

@ -0,0 +1,4 @@
!import "test/local-ns/2.tri" Two
main = Two.x

2
test/local-ns/2.tri Normal file
View File

@ -0,0 +1,2 @@
!import "test/local-ns/3.tri" !Local

2
test/local-ns/3.tri Normal file
View File

@ -0,0 +1,2 @@
x = 3

View File

@ -1,5 +0,0 @@
!module Test
!import "lib/base.tri" Lib
main = Lib.not? t

View File

@ -1 +0,0 @@
n = t t t

View File

@ -1,3 +1,2 @@
!module A
!import "./test/multi-level-B.tri" B
main = B.main

View File

@ -1,3 +1,2 @@
!module B
!import "./test/multi-level-C.tri" C
main = C.val

View File

@ -1,2 +1 @@
!module C
val = t

7
test/named-imports/1.tri Normal file
View 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
View File

@ -0,0 +1,2 @@
x = 2

2
test/named-imports/3.tri Normal file
View File

@ -0,0 +1,2 @@
x = 3

View File

@ -1,3 +1,2 @@
!module A
!import "./test/namespace-B.tri" B
main = B.x

View File

@ -1,2 +1 @@
!module B
x = t

View File

@ -1 +0,0 @@
namedTerm = undefinedForTesting

View File

@ -1,2 +1 @@
!module A
main = undefinedVar

View File

@ -1,4 +1,3 @@
!module A
!import "./test/vars-B.tri" B

View File

@ -1,2 +1 @@
!module B
y = \x : x

View File

@ -1,2 +1 @@
!module C
z = t