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:
Minus committed 2026-11-17 18:40:10 +00:00
1 parent cc893ff677
commit 83629d0e1e
4 files changed
+81 -8

No files matched your search

+8
View File
@@ -174,6 +174,14 @@ check "repr-list" "list: [a, b, _repr_]" "`echo "$out" | sed -
out=`printf 'x = 50\nx\nx + 5\n' | $BIN | tr '>' '\n' | grep -oE '[0-9]+'`
check "repl-echo" "50" "`echo "$out" | sed -n 1p`"
check "repl-state" "55" "`echo "$out" | sed -n 2p`"
# ---- imports: `use name` ---------------------------------------------
out=`$BIN tests/import.cat`
check "import-name" "double 21 = 42" "`echo "$out" | sed -n 1p`"
check "import-sq" "square 7 = 49" "`echo "$out" | sed -n 2p`"
check "import-io" "join: a-b-c" "`echo "$out" | sed -n 3p`"
check "import-path" "abs(-5) = 5" "`echo "$out" | sed -n 4p`"
# ---- the `module` global ---------------------------------------------
out=`$BIN tests/module.cat`