~brenns10/funlisp

ed6d9705e5166b1cf143d43389e187b2c87d8fba — Stephen Brennan 3 years ago 67007e4
Allow some symbols to not be owned by the interpreter
2 files changed, 4 insertions(+), 1 deletions(-)

M src/funlisp_internal.h
M src/types.c
M src/funlisp_internal.h => src/funlisp_internal.h +1 -0
@@ 66,6 66,7 @@ struct lisp_type {

struct lisp_symbol {
	LISP_VALUE_HEAD;
	char can_free;
	char *sym;
};


M src/types.c => src/types.c +3 -1
@@ 305,6 305,7 @@ static lisp_value *symbol_new(void)
{
	lisp_symbol *symbol = malloc(sizeof(lisp_symbol));
	symbol->sym = NULL;
	symbol->can_free = 1;
	return (lisp_value*)symbol;
}



@@ 319,7 320,8 @@ static lisp_value *symbol_eval(lisp_runtime *rt, lisp_scope *scope,
static void symbol_free(void *v)
{
	lisp_symbol *symbol = (lisp_symbol*) v;
	free(symbol->sym);
	if (symbol->can_free)
		free(symbol->sym);
	free(symbol);
}