From 752f8309a72bacef5ce03ac8e98211b1df2ff0a8 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 28 Feb 2014 23:37:45 -0800 Subject: Turn *gensym-counter* into proper special variable. * eval.c (eval_init): Save *gensym-counter* symbol in gensym_counter_s symbol variable right after interning, and use zero as the inital value rather than the gensym_counter variable which is removed now. * lib.c (gensym_counter_s): New symbol variable. (gensym_counter): Variable removed. (gensym): Slight refactoring to avoid a double variable lookup. Also, for generational GC correctness, use the set macro to update it, since the variable could live inside heap object and the counter could overflow to bignums which are heap objects. (obj_init): Remove initialization of gensym_counter. * lib.h (gensym_counter_s): Declared. (gensym_counter): Declaration removed, replaced by macro. --- ChangeLog | 19 +++++++++++++++++++ eval.c | 2 +- lib.c | 7 +++---- lib.h | 4 +++- 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 50671b4b..a5be43ec 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +2014-02-28 Kaz Kylheku + + Turn *gensym-counter* into proper special variable. + + * eval.c (eval_init): Save *gensym-counter* symbol in gensym_counter_s + symbol variable right after interning, and use zero as the inital value + rather than the gensym_counter variable which is removed now. + + * lib.c (gensym_counter_s): New symbol variable. + (gensym_counter): Variable removed. + (gensym): Slight refactoring to avoid a double variable lookup. + Also, for generational GC correctness, use the set macro to update it, + since the variable could live inside heap object and the counter + could overflow to bignums which are heap objects. + (obj_init): Remove initialization of gensym_counter. + + * lib.h (gensym_counter_s): Declared. + (gensym_counter): Declaration removed, replaced by macro. + 2014-02-28 Kaz Kylheku Change in the design of how special variables work, to fix the broken diff --git a/eval.c b/eval.c index ec074b05..89b9c5b5 100644 --- a/eval.c +++ b/eval.c @@ -3294,7 +3294,7 @@ void eval_init(void) reg_fun(intern(lit("make-sym"), user_package), func_n1(make_sym)); reg_fun(intern(lit("gensym"), user_package), func_n1o(gensym, 0)); - reg_var(intern(lit("*gensym-counter*"), user_package), gensym_counter); + reg_var(gensym_counter_s = intern(lit("*gensym-counter*"), user_package), zero); reg_fun(intern(lit("make-package"), user_package), func_n1(make_package)); reg_fun(intern(lit("find-package"), user_package), func_n1(find_package)); reg_fun(intern(lit("delete-package"), user_package), func_n1(delete_package)); diff --git a/lib.c b/lib.c index c615b05b..dee6af8f 100644 --- a/lib.c +++ b/lib.c @@ -86,6 +86,7 @@ val eof_s, eol_s; val error_s, type_error_s, internal_error_s; val numeric_error_s, range_error_s; val query_error_s, file_error_s, process_error_s; +val gensym_counter_s; val nothrow_k, args_k, colon_k, auto_k; @@ -95,8 +96,6 @@ val null_list; val identity_f, equal_f, eql_f, eq_f, car_f, cdr_f, null_f; -val gensym_counter; - val prog_string; static val env_list; @@ -2704,8 +2703,9 @@ val make_sym(val name) val gensym(val prefix) { prefix = default_arg(prefix, lit("g")); + val *gs_loc = &gensym_counter; val name = format(nil, lit("~a~,04a"), prefix, - gensym_counter = plus(gensym_counter, one), nao); + set(*gs_loc, plus(*gs_loc, one)), nao); return make_sym(name); } @@ -5213,7 +5213,6 @@ static void obj_init(void) car_f = func_n1(car); cdr_f = func_n1(cdr); null_f = func_n1(null); - gensym_counter = zero; prog_string = string(progname); } diff --git a/lib.h b/lib.h index cf6b02e0..b6eb69cc 100644 --- a/lib.h +++ b/lib.h @@ -340,6 +340,9 @@ extern val eof_s, eol_s; extern val error_s, type_error_s, internal_error_s; extern val numeric_error_s, range_error_s; extern val query_error_s, file_error_s, process_error_s; +extern val gensym_counter_s; + +#define gensym_counter (*lookup_var_l(nil, gensym_counter_s)) extern val nothrow_k, args_k, colon_k, auto_k; @@ -348,7 +351,6 @@ extern val null_list; /* (nil) */ extern val identity_f, equal_f, eql_f, eq_f, car_f, cdr_f, null_f; -extern val gensym_counter; extern const wchar_t *progname; extern val prog_string; -- cgit v1.2.3