This commit is contained in:
2026-03-24 13:40:40 +00:00
parent 35f5b8fa86
commit 29736e9577
5 changed files with 286 additions and 93 deletions
-93
View File
@@ -1,96 +1,3 @@
# PR-6.3 — CALL_CLOSURE (Model B Hidden Arg0)
## Briefing
Closures must be dynamically invokable.
Under Model B, invocation semantics are:
* The closure object itself becomes hidden `arg0`.
* User-supplied arguments become `arg1..argN`.
* Captures remain inside the closure and are accessed explicitly.
---
## Target
Introduce opcode:
`CALL_CLOSURE arg_count`
Stack before call:
```
[..., argN, ..., arg1, closure_ref]
```
Execution steps:
1. Pop `closure_ref`.
2. Validate object is `ObjectKind::Closure`.
3. Pop `arg_count` arguments.
4. Read `fn_id` from closure object.
5. Create new call frame:
* Inject `closure_ref` as `arg0`.
* Append user arguments as `arg1..argN`.
6. Jump to function entry.
No environment copying into locals.
---
## Work Items
1. Add `CALL_CLOSURE` opcode.
2. Implement dispatch logic.
3. Integrate with call frame creation.
4. Ensure stack discipline is preserved.
---
## Acceptance Checklist
* [ ] CALL_CLOSURE implemented.
* [ ] closure_ref validated.
* [ ] arg_count respected.
* [ ] Hidden arg0 injected correctly.
* [ ] Errors thrown on non-closure call.
---
## Tests
1. Closure returning constant.
2. Closure capturing value and using it.
3. Calling non-closure results in trap.
4. Nested closure calls work.
---
## Junie Instructions
You MAY:
* Modify interpreter call logic.
* Add tests.
You MUST NOT:
* Change stack model.
* Introduce coroutine semantics.
* Modify GC.
If function signature metadata is insufficient to validate arg_count, STOP and ask.
---
## Definition of Done
Closures can be dynamically invoked with hidden arg0 semantics.
---
# PR-6.4 — GC Traversal for Closures (Model B)
## Briefing
+2
View File
@@ -1,3 +1,5 @@
vamos as PR7s todas em um unico canvas markdown ingles, devem ser auto contidas com briefing, alvo, checklist, test quando necessario e comandos do que a Junie pode ou nao fazer (Junie eh task operator nao arquiteta ou assume nada, questiona quando necessario).
7 — Coroutines (único modelo de concorrência, cooperativo)
7.1. Definir objeto Coroutine no heap: stack/frames próprios, status, wake time, mailbox/queue se existir.