ilusm.dev

link

Module linker and bundler - extract use dependencies from source text, parse and merge multiple source files into a single AST (stripping use nodes), resolve transitive path-based dependencies depth-first, produce the canonical ilusm runtime pipeline file list, and bundle the whole pipeline into one merged AST ready for compilation.

Load with: use link

What this module does

link is used by the ilusm bootstrap process (boot.ilu) to produce a self-hosting single compilation unit. It resolves use "path.ilu" (quoted path) dependencies recursively to build a dependency-ordered file list, then merges all parsed ASTs into one flat program node with all use statements removed.

The canonical pipeline file list includes runtime, frontend (lexer, parser), and backend (compiler, VM) modules in the correct load order.

Quick example

use link

# Extract deps from source text
src = fs.rd("src/app.ilu")
deps = link.deps(src)  # ["trl", "txt", "\"./util.ilu\""]

# Resolve transitive path deps in order
files = link.resolve("src/app.ilu", "lib/")
# ["lib/runtime/trl.ilu", ..., "src/app.ilu"]

# Bundle the full ilusm pipeline
ast = link.bundle("lib/", \(src, path) prs.parse_at(src, path))

# Get canonical pipeline file list
flist = link.pipeline_files()

Functions

Dependency extraction

link.deps(src)

Returns a list of all raw dependency strings from use statements in the source text. Includes both bare module names ("trl") and quoted paths ("\"./util.ilu\"").

Merging

link.merge(files, lib_root, parse_fn)

Reads and parses each file in the files list (paths relative to lib_root). Strips use nodes from each parsed AST and concatenates all remaining statements into a single {t:"prg", st:[...]} node. parse_fn(src, path) must return {ok, pr, er}.

Resolution and bundling

link.resolve(entry, lib_root)

Performs a depth-first traversal of quoted path dependencies starting from entry. Returns an ordered list of file paths with each dependency appearing before its dependents (no duplicates).

link.bundle(lib_root, parse_fn)

Merges the canonical pipeline files (returned by link.pipeline_files) into one AST using link.merge.

link.pipeline_files()

Returns the hardcoded ordered list of ilusm runtime, frontend, and backend source files that constitute the full self-hosting pipeline.

Notes

  • Only quoted use "path.ilu" dependencies are followed for path resolution. Bare use modulename dependencies are listed but not traversed.
  • Requires trl, txt, and host.