add macro support

This commit is contained in:
Lobo 2026-01-13 18:27:02 -03:00
parent c63c1eaf6e
commit 2e7d05f783
6 changed files with 95 additions and 20 deletions

View file

@ -61,9 +61,9 @@ typedef struct Bc {
typedef struct In In;
typedef struct Pr {
const char *name;
O (*fn)(In *, O *, int, O); // fn(interp, args_array, argc, env)
int min_args; // Minimum number of arguments (-1 for no check)
int max_args; // Maximum number of arguments (-1 for variadic)
O (*fn)(In *, O *, int, O);
int min_args;
int max_args;
} Pr;
// Symbol table
@ -165,23 +165,23 @@ enum {
OP_JUMP,
OP_JUMP_IF_NIL,
OP_CALL,
OP_TAIL_CALL,
OP_RET,
OP_POP,
OP_CLOS,
OP_TAIL_CALL,
OP_MAC,
OP_BIND,
OP_BIND_REST,
OP_PEEK,
OP_GET_LOCAL, // Get local variable from stack frame
OP_SET_LOCAL, // Set local variable in stack frame
OP_RESERVE, // Reserve space for local variables
OP_GET_LOCAL,
OP_SET_LOCAL,
OP_RESERVE,
};
// Local variable info
typedef struct Lv {
O name; // Symbol name
U16 index; // Stack slot index
int captured; // Is this variable captured by a closure?
O name;
U16 index;
} Lv;
// Compiler context
@ -199,6 +199,7 @@ typedef struct Cm {
O quote;
O iff;
O fn;
O mac;
O progn;
O def;
} specials;
@ -207,7 +208,7 @@ typedef struct Cm {
Z count;
Z capacity;
} locals;
int use_stack_locals; // Use stack-based locals instead of env
I use_locals;
} Cm;
enum {