From 28bc0e384297b72b69fa25d0c175d97482e3f97e Mon Sep 17 00:00:00 2001 From: igor Date: Wed, 18 Feb 2026 09:45:13 +0100 Subject: [PATCH] changed the macro args to start from 0 --- SPEC.md | 2 +- main.py | 2 +- tests/integration_core.sl | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/SPEC.md b/SPEC.md index cb5eb87..93dedbf 100644 --- a/SPEC.md +++ b/SPEC.md @@ -43,7 +43,7 @@ This document reflects the implementation that ships in this repository today (` - `while do 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 `.size`, `.field.size`, `.field.offset`, `.field@`, and `.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. diff --git a/main.py b/main.py index 0fcdc83..6eee6f2 100644 --- a/main.py +++ b/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]) diff --git a/tests/integration_core.sl b/tests/integration_core.sl index f5de7a8..4ade32a 100644 --- a/tests/integration_core.sl +++ b/tests/integration_core.sl @@ -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 ;