This commit is contained in:
Nilton Constantino
2026-02-02 23:06:09 +00:00
parent 6cf1e71b99
commit 45696b99e7
5 changed files with 308 additions and 21 deletions
+7 -6
View File
@@ -215,14 +215,15 @@ State:
### 6.6 Functions
| Instruction | Cycles | Description |
|----------------| ------ |--------------------------------------------|
| `CALL addr` | 5 | Saves PC and creates a new call frame |
| `RET` | 4 | Returns from function, restoring PC |
| `PUSH_SCOPE` | 3 | Creates a scope within the current function |
| `POP_SCOPE` | 3 | Removes current scope and its local variables |
| Instruction | Cycles | Description |
|----------------------| ------ |-----------------------------------------------|
| `CALL <u32 func_id>` | 5 | Saves PC and creates a new call frame |
| `RET` | 4 | Returns from function, restoring PC |
| `PUSH_SCOPE` | 3 | Creates a scope within the current function |
| `POP_SCOPE` | 3 | Removes current scope and its local variables |
**ABI Rules for Functions:**
* **`func_id`:** A 32-bit index into the **final FunctionTable**, assigned by the compiler linker at build time.
* **Mandatory Return Value:** Every function MUST leave exactly one value on the stack before `RET`. If the function logic doesn't return a value, it must push `null`.
* **Stack Cleanup:** `RET` automatically clears all local variables (based on `stack_base`) and re-pushes the return value.