Compare commits
1 Commits
831966323a
...
7d044b28a4
| Author | SHA1 | Date | |
|---|---|---|---|
| 7d044b28a4 |
27
CLAUDE.md
27
CLAUDE.md
|
|
@ -51,9 +51,9 @@ When exploring Shrimp, focus on these key files in order:
|
||||||
|
|
||||||
3. **src/compiler/compiler.ts** - CST to bytecode transformation
|
3. **src/compiler/compiler.ts** - CST to bytecode transformation
|
||||||
|
|
||||||
- See how functions emit inline with JUMP wrappers
|
- See how functions become labels in `fnLabels` map
|
||||||
- Check short-circuit logic for `and`/`or`
|
- Check short-circuit logic for `and`/`or` (lines 267-282)
|
||||||
- Notice `TRY_CALL` emission for bare identifiers
|
- Notice `TRY_CALL` emission for bare identifiers (line 152)
|
||||||
|
|
||||||
4. **packages/ReefVM/src/vm.ts** - Bytecode execution
|
4. **packages/ReefVM/src/vm.ts** - Bytecode execution
|
||||||
- See `TRY_CALL` fall-through to `CALL` (lines 357-375)
|
- See `TRY_CALL` fall-through to `CALL` (lines 357-375)
|
||||||
|
|
@ -211,23 +211,14 @@ Implementation files:
|
||||||
|
|
||||||
## Compiler Architecture
|
## Compiler Architecture
|
||||||
|
|
||||||
**Function compilation strategy**: Functions are compiled inline where they're defined, with JUMP instructions to skip over their bodies during linear execution:
|
**Function compilation strategy**: The compiler doesn't create inline function objects. Instead it:
|
||||||
|
|
||||||
```
|
1. Generates unique labels (`.func_0`, `.func_1`) for each function body (compiler.ts:137)
|
||||||
JUMP .after_.func_0 # Skip over body during definition
|
2. Stores function body instructions in `fnLabels` map during compilation
|
||||||
.func_0: # Function body label
|
3. Appends all function bodies to the end of bytecode with RETURN instructions (compiler.ts:36-41)
|
||||||
(function body code)
|
4. Emits `MAKE_FUNCTION` with parameters and label reference
|
||||||
RETURN
|
|
||||||
.after_.func_0: # Resume here after jump
|
|
||||||
MAKE_FUNCTION (x) .func_0 # Create function object with label
|
|
||||||
```
|
|
||||||
|
|
||||||
This approach:
|
This approach keeps the main program linear and allows ReefVM to jump to function bodies by label.
|
||||||
- Emits function bodies inline (no deferred collection)
|
|
||||||
- Uses JUMP to skip bodies during normal execution flow
|
|
||||||
- Each function is self-contained at its definition site
|
|
||||||
- Works seamlessly in REPL mode (important for `vm.appendBytecode()`)
|
|
||||||
- Allows ReefVM to jump to function bodies by label when called
|
|
||||||
|
|
||||||
**Short-circuit logic**: ReefVM has no AND/OR opcodes. The compiler implements short-circuit evaluation using:
|
**Short-circuit logic**: ReefVM has no AND/OR opcodes. The compiler implements short-circuit evaluation using:
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user