changed the macro args to start from 0
This commit is contained in:
2
SPEC.md
2
SPEC.md
@@ -43,7 +43,7 @@ This document reflects the implementation that ships in this repository today (`
|
||||
- `while <condition> do <body> end`; the conditional block lives between `while` and `do` and re-runs every iteration.
|
||||
- `n for ... end`; the loop count is popped, stored on the return stack, and decremented each pass. The compile-time word `i` exposes the loop index inside macros.
|
||||
- `label name` / `goto name` perform local jumps within a definition.
|
||||
- **Text macros** – `macro name [param_count] ... ;` records raw tokens until `;`. `$1`, `$2`, ... expand to positional arguments. Macro definitions cannot nest (attempting to start another `macro` while recording raises a parse error).
|
||||
- **Text macros** – `macro name [param_count] ... ;` records raw tokens until `;`. `$0`, `$1`, ... expand to positional arguments. Macro definitions cannot nest (attempting to start another `macro` while recording raises a parse error).
|
||||
- **Struct builder** – `struct Foo ... end` emits `<Foo>.size`, `<Foo>.field.size`, `<Foo>.field.offset`, `<Foo>.field@`, and `<Foo>.field!` helpers. Layout is tightly packed with no implicit padding.
|
||||
- **With-blocks** – `with a b in ... end` rewrites occurrences of `a`/`b` into accesses against hidden global cells (`__with_a`). On entry the block pops the named values and stores them in those cells; reads compile to `@`, writes to `!`. Because the cells live in `.data`, the slots persist across calls and are not re-entrant.
|
||||
- **List literals** – `[ values ... ]` capture the current stack slice, allocate storage (`mmap`), copy the elements, and push the pointer. The record stores `len` at offset 0 and items afterwards so user code can fetch length via `@` and iterate.
|
||||
|
||||
2
main.py
2
main.py
@@ -786,7 +786,7 @@ class Parser:
|
||||
replaced: List[str] = []
|
||||
for lex in word.macro_expansion or []:
|
||||
if lex.startswith("$"):
|
||||
idx = int(lex[1:]) - 1
|
||||
idx = int(lex[1:])
|
||||
if idx < 0 or idx >= len(args):
|
||||
raise ParseError(f"macro {word.name} missing argument for {lex}")
|
||||
replaced.append(args[idx])
|
||||
|
||||
@@ -13,14 +13,14 @@ macro square
|
||||
;
|
||||
|
||||
macro defconst 2
|
||||
word $1
|
||||
$2
|
||||
word $0
|
||||
$1
|
||||
end
|
||||
;
|
||||
|
||||
macro defadder 3
|
||||
word $1
|
||||
$2 $3 +
|
||||
word $0
|
||||
$1 $2 +
|
||||
end
|
||||
;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user