load
Executes Do bytecode and registers runtime import handlers.
Types
| Type | Description |
|---|---|
ImportHandler |
A registered runtime import handler. |
Functions
import name
Imports a module through the VM's ordinary global import resolution.
Use this from a program-specific importer to fall back explicitly to native modules, cached modules, and registered import handlers.
Parameters
| Name | Type | Description |
|---|---|---|
name |
Str |
Module name to import. |
Returns
The imported module value.
Errors
| Exception | Condition |
|---|---|
TypeError |
name is not Str |
ImportError |
No global importer accepts name |
Example
import load:
import: global_import
class Virtual
pub field answer = 42
let importer = do |name|
if (name == "virtual")
Virtual()
else
global_import $name
load.run $bytecode importer: $importer
import_handler callback -> ImportHandler
Registers a module import handler.
Handlers run after native modules and cached Do modules. The first successful
handler supplies the imported value. Raise ImportError
to decline a name; any other error aborts the import.
Parameters
| Name | Type | Description |
|---|---|---|
callback |
((Str) -> Value) |
Called with the requested module name. |
Example
class Demo
pub field answer = 42
let handle = import_handler do |name|
if (name == "demo")
Demo()
else
throw std.ImportError(name)
import demo
assert_eq $demo.answer 42
handle.unregister()
run bytecode … -> Value
Executes compiled Do bytecode.
The optional importer belongs to the loaded program and remains active for
retained functions and modules. Imports call it directly, bypassing native
modules, caching, and registered handlers. Results are not cached, and an
ImportError does not trigger automatic fallback.
Parameters
| Name | Type | Description |
|---|---|---|
bytecode |
Bin |
Compiled Do bytecode. |
:importer? |
((Str) -> Value) |
Program-specific module importer, called with the requested module name. |
Returns
The result of executing the bytecode.
Errors
| Exception | Condition |
|---|---|
TypeError |
bytecode is not Bin |
| Various | Bytecode verification or execution fails |