Work on functions

This commit is contained in:
2026-01-29 00:00:05 -08:00
parent 22ffac9321
commit 5029405a70
12 changed files with 292 additions and 123 deletions

View File

@ -2,6 +2,7 @@
#define INCLUDED_STACK_H
#include "base.h"
#include "list.h"
#define DEFAULT_MAX_LISP_EVAL_DEPTH 1000
#define LOCAL_REFERENCES_BLOCK_LENGTH 64
@ -19,6 +20,7 @@ struct LocalReferences {
struct StackFrame {
LispVal *name; // name of function call
LispVal *fobj; // the function object
bool evaled_args; // whether args have been evaluated yet
LispVal *args; // arguments of the function call
LispVal *lexenv; // lexical environment (plist)
struct LocalReferences local_refs;
@ -56,10 +58,18 @@ void pop_stack_frame(void);
void add_local_reference_no_recurse(LispVal *obj);
void add_local_reference(LispVal *obj);
// replace the args in the top stack frame with ARGS and mark them as evaluted
// (this is for backtraces)
void set_stack_evaluated_args(LispVal *args);
// Return true if successful, false if not found and not created
bool set_lexical_variable(LispVal *name, LispVal *value, bool create_if_absent);
// Just add a new lexical variable without any checking
void new_lexical_variable(LispVal *name, LispVal *value);
static inline void new_lexical_variable(LispVal *name, LispVal *value) {
assert(the_stack.depth != 0);
LISP_STACK_TOP()->lexenv =
CONS(name, CONS(value, LISP_STACK_TOP()->lexenv));
}
// Copy the previous frame's lexenv to the top of the stack.
void copy_parent_lexenv(void);