A lot of work

This commit is contained in:
2026-01-19 05:57:18 -08:00
parent c7af58f674
commit c63b104bc6
12 changed files with 217 additions and 13 deletions

46
src/stack.h Normal file
View File

@ -0,0 +1,46 @@
#ifndef INCLUDED_STACK_H
#define INCLUDED_STACK_H
#include "base.h"
#define DEFAULT_MAX_LISP_EVAL_DEPTH 1000
#define LOCAL_REFERENCES_BLOCK_LENGTH 64
struct LocalReferencesBlock {
LispVal *refs[LOCAL_REFERENCES_BLOCK_LENGTH];
};
struct LocalReferences {
size_t num_blocks;
size_t num_refs;
struct LocalReferencesBlock **blocks;
};
struct StackFrame {
LispVal *name; // name of function call
LispVal *fobj; // the function object
LispVal *args; // arguments of the function call
LispVal *lexenv; // lexical environment (plist)
struct LocalReferences local_refs;
};
struct LispStack {
size_t max_depth;
size_t depth;
size_t first_clear_local_refs; // index of the first frame that has local
// refs that has not been grown
struct StackFrame *frames;
};
extern struct LispStack the_stack;
static ALWAYS_INLINE struct StackFrame *LISP_STACK_TOP() {
return the_stack.depth ? &the_stack.frames[the_stack.depth - 1] : NULL;
}
void lisp_init_stack(void);
void push_stack_frame(LispVal *name, LispVal *fobj, LispVal *args);
void pop_stack_frame(void);
void add_local_reference(LispVal *obj);
#endif