Skip to content

feat: Glia import path — (import "foo") for .glia scripts #273

@lthibault

Description

@lthibault

Parent

Part of #272 (Glia import system)

Summary

Implement the Glia-script import path: (import "foo") resolves /lib/foo.glia from the merged FHS image, evals it in an isolated Env, and binds all top-level defs into the caller's Env with a foo/ prefix.

Scope

  • Add Expr::Import variant to crates/glia/src/expr.rs (match arm in analyze_list())
  • Create crates/glia/src/import.rs with resolution pipeline
  • Resolution order: search /lib/{name}.glia first, then /lib/{name}.wasm
  • Eval imported .glia in fresh Env (isolated — no leaking unprefixed defs)
  • Bind results as {module}/ prefixed names in caller's root frame via set_root()
  • Support absolute /ipfs/-prefixed paths: (import "/ipfs/QmHash.../foo.glia")
  • Circular import detection via HashSet<String> threaded through eval

Non-goals

  • WASM imports (see sibling issue)
  • Import caching / idempotent require (see TODOS.md)
  • Guard clauses, namespace objects

Test cases (from design doc)

  • (import "utils")utils/helper-fn callable
  • Isolated eval: imported defs don't leak unprefixed into caller
  • Module not found → error
  • Empty .glia file → no bindings, no error
  • Parse error in imported file → propagated error
  • Nested path: (import "math/core")/lib/math/core.glia
  • Circular import detection
  • /ipfs/-prefixed absolute import

Dependencies

  • None (pure Glia-side work, uses existing WASI fs)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions