Skip to content

load

Execute Do bytecode and register runtime import handlers.

Functions

run bytecode

Executes compiled Do bytecode.

Parameters

Name Type Description
bytecode Bin Compiled Do bytecode

Returns

The result of executing the bytecode.

Errors

Exception Condition
TypeError bytecode is not Bin
Various Bytecode verification or execution fails
import compile
import load

let result = load.run $ (compile.compile "example.dol" "(1 + 1)").bytecode
assert_eq $result 2

import_handler callback

Registers a module import handler.

Handlers are tried after native modules and cached Do modules. The first handler that returns successfully supplies the imported value.

To decline a module name, raise ImportError. Any other error aborts the import.

Parameters

Name Type Description
callback Func Called with the requested module name

Returns

ImportHandler

let handle = load.import_handler do |name|
  if (name == "demo")
    record answer: 42
  else
    throw std.ImportError(name)

import demo
assert_eq $demo.answer 42
handle.unregister()