imports: use name imports by module name
`use` only accepted a path expression, so `use math` read `math` as a global and failed. Now the operand may be a bare module name. - compiler: `use NAME` emits the name as a constant (a path expression still works, e.g. `use "std/io/io.cat"` or `use (expr)`). - stdlib: `use_resolve` maps a name to a path, trying, in order: <name>, <name>.cat, std/<name>/<name>.cat, <name>/<name>.cat, std/<name>.cat. A path (contains `.cat` or `/`) is used as-is. - stdlib: a missing module now raises (per project rule: no silent failure) -- "cannot import module 'X'" -- instead of doing nothing. - tests/import.cat: `use math`, `use io` and a path string (109 total, all green).
This commit is contained in:
1 parent
cc893ff677
commit
83629d0e1e
4 files changed
+81
-8
No files matched your search
@@ -0,0 +1,16 @@
|
||||
-- tests/import.cat -- `use name` imports by module name.
|
||||
--
|
||||
-- The operand is a bare module name (`math`) or a path string. A name
|
||||
-- resolves (in order) to: <name>, <name>.cat, std/<name>/<name>.cat,
|
||||
-- <name>/<name>.cat, std/<name>.cat. A path is used as-is.
|
||||
|
||||
use math
|
||||
print("double 21 =", double(21))
|
||||
print("square 7 =", square(7))
|
||||
|
||||
use io
|
||||
print("join:", join({"a", "b", "c"}, "-"))
|
||||
|
||||
-- a path string still works (used as-is)
|
||||
use "std/math/math.cat"
|
||||
print("abs(-5) =", abs(-5))
|
||||
Reference in new issue
Block a user