Compare commits
1 Commits
7d044b28a4
...
831966323a
| Author | SHA1 | Date | |
|---|---|---|---|
| 831966323a |
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 become labels in `fnLabels` map
|
- See how functions emit inline with JUMP wrappers
|
||||||
- Check short-circuit logic for `and`/`or` (lines 267-282)
|
- Check short-circuit logic for `and`/`or`
|
||||||
- Notice `TRY_CALL` emission for bare identifiers (line 152)
|
- Notice `TRY_CALL` emission for bare identifiers
|
||||||
|
|
||||||
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,14 +211,23 @@ Implementation files:
|
||||||
|
|
||||||
## Compiler Architecture
|
## Compiler Architecture
|
||||||
|
|
||||||
**Function compilation strategy**: The compiler doesn't create inline function objects. Instead it:
|
**Function compilation strategy**: Functions are compiled inline where they're defined, with JUMP instructions to skip over their bodies during linear execution:
|
||||||
|
|
||||||
1. Generates unique labels (`.func_0`, `.func_1`) for each function body (compiler.ts:137)
|
```
|
||||||
2. Stores function body instructions in `fnLabels` map during compilation
|
JUMP .after_.func_0 # Skip over body during definition
|
||||||
3. Appends all function bodies to the end of bytecode with RETURN instructions (compiler.ts:36-41)
|
.func_0: # Function body label
|
||||||
4. Emits `MAKE_FUNCTION` with parameters and label reference
|
(function body code)
|
||||||
|
RETURN
|
||||||
|
.after_.func_0: # Resume here after jump
|
||||||
|
MAKE_FUNCTION (x) .func_0 # Create function object with label
|
||||||
|
```
|
||||||
|
|
||||||
This approach keeps the main program linear and allows ReefVM to jump to function bodies by label.
|
This approach:
|
||||||
|
- 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