-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Summary
Bridge existing builtin functions (print, toString, etc.) into the VM call convention so they can be invoked like user functions.
Checklist
Value representation
- Add
BuiltinFn(orFunctionwith builtin/user variants) to the VMValuetype - Register builtins into the VM globals at startup (mirror
builtins.registerAll)
Compiler
- Resolve builtin names as globals (not locals) during compilation
- Compile builtin calls through the same
fn_callpath — emit args +op_call
VM
- In the
op_callhandler, branch on callable type: user fn → push call frame, builtin fn → invoke directly with evaluated args - Pass
RuntimeContextto builtins (needed for stdout/stderr access) - Handle return value from builtins (push onto stack)
toString coercion
- Before passing struct instances to builtins, check for a qualified
TypeName.toStringmethod and call it (mirrors interpreter behavior inevaluateFnCall)
Tests
-
print(42)produces correct output via VM -
print("hello")works - Builtin with return value (e.g.
toString) pushes result onto stack - Struct instance passed to print triggers toString coercion
Depends on #43 (call frames) being merged first.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request