-
Notifications
You must be signed in to change notification settings - Fork 0
compile
ffredyk edited this page Jul 23, 2026
·
1 revision
Code Execution
Unary — compile <string>.
compile <string>
Compiles a string containing SQ# source code into a Code value at runtime. The resulting code can be stored in a variable and executed later with call or spawn. This is runtime compilation — useful for dynamic code generation, user input evaluation, or config-driven behavior.
The source string is passed through the SQ# lexer and parser, producing a compiled Code object. If the string contains syntax errors, compilation fails with a diagnostic error. The compiled code captures no lexical closure — it runs in the calling context's scope.
_code = compile "hint str _this;";
"hello" call _code; // hints "hello"_expr = compile _userInput; // e.g., "2 + 3 * 4"
_result = call _expr; // 14_myFunc = compile "(_this select 0) * (_this select 1)";
_result = [5, 3] call _myFunc; // 15
_result = [10, 2] call _myFunc; // 20_op = "+";
_src = f"(_this select 0) {_op} (_this select 1)";
_calc = compile _src;
_result = [10, 5] call _calc; // 15_code = compile "sleep 2; systemChat 'done';";
_handle = spawn _code;- Compilation has a cost — cache compiled code when reused.
- No lexical closure — code runs in its call site's variable scope.
- Syntax errors occur at compile time, not call time.
- Dynamic code from untrusted input is a security risk — validate carefully.
Compilation is CPU-only with no side effects. Safe from any scheduler. The resulting Code value is immutable.
- call — execute compiled code synchronously
- spawn — execute compiled code asynchronously
- execVM — compile and spawn file
- callUnscheduled — execute outside scheduler
- Getting Started
- Language Guide
- Type System
- Control Flow
- Functions & Code
- Strings & Text
- Arrays & Collections
- Concurrency
- Promise System
- Thread Safety
- Host API & Embedding
- CLI Tool
- Bytecode Reference
- Multiplayer
- Syntax Sugar
- Optimization Guide
- Benchmarks
- count
- select
- pushBack
- append
- deleteAt
- deleteRange
- resize
- reverse
- sort
- find
- in
- forEach
- freeze
- thaw
- isFrozen
- currentScheduler
- clientOwner
- allSchedulers
- schedulerName
- schedulerExists
- schedulerBudget
- setSchedulerBudget
- fiberCount
- readyFiberCount
- waitingFiberCount
- schedulerLoad
- sendTo