diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2014-02-28 23:15:10 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2014-02-28 23:15:10 -0800 |
commit | 94750af472e12acf3a5970c98e4dab6feada2e84 (patch) | |
tree | 0f91686515e864ea184cc866c980ddc979783b0c /txr.c | |
parent | 8c634953700bdf3199b68e8ccf2eff4132ca81d5 (diff) | |
download | txr-94750af472e12acf3a5970c98e4dab6feada2e84.tar.gz txr-94750af472e12acf3a5970c98e4dab6feada2e84.tar.bz2 txr-94750af472e12acf3a5970c98e4dab6feada2e84.zip |
Change in the design of how special variables work, to fix the broken
re-binding. C code now has to go through the dynamic environment lookup
to access things like *random-state*, or *stdout*. As part of this,
I'm moving some intrinsic variable and function initializations out of
eval.c and into their respective modules. Macros are are used to make
global variables look like ordinary C variables. This is very similar
to the errno trick in POSIX threads implementations.
* eval.c (looup_var, lookup_var_l): Restructured to eliminate silly
goto, the cobjp handling is gone.
(reg_fun, reg_var): Internal function becomes external.
reg_var registers a simple cons cell binding now, without any
C pointer tricks to real C global variables.
(c_var_mark): Static function removed.
(c_var_ops): Static struct removed.
(eval_init): Numerous initializations for streams, syslog, rand,
signals and others moved to their respective modules.
The new symbol variables user_package_s, keyword_package_s
and system_package_s are interned here, and the variables are
created in a special way.
* eval.h (reg_var, reg_fun): Declared.
* gc.c (prot1): Added assert that the loc pointer isn't null.
This happened, and blew up during garbage collection.
* lib.c (system_package, keyword_package, user_package): Variables
removed these become macros.
(system_package_var, keyword_package_var, user_package_var): New
global variables.
(system_package_s, keyword_package_s, user_package_s): New
symbol globals.
(get_user_package, get_system_package, get_keyword_package): New
functions.
(obj_init): Protect new variables. Initialization order of modules
tweaked: the modules sig_init, stream_init, and rand_init are moved
after eval_init because they register variables.
* lib.h (keyword_package, system_pckage, user_package): Variables
turned into macros.
(system_package_var, keyword_package_var, user_package_var): Declared.
(system_package_s, keyword_package_s, user_package_s): Declared.
(get_user_package, get_system_package, get_keyword_package): Declared.
* rand.c (struct random_state): Renamed to struct rand_state to
avoid clash with new random_state macro.
(random_state): Global variable removed.
(random_state_s): New symbol global.
(make_state, rand32, make_random_state, random_fixnum, random):
Follow rename of struct random_state.
Diffstat (limited to 'txr.c')
-rw-r--r-- | txr.c | 9 |
1 files changed, 4 insertions, 5 deletions
@@ -49,7 +49,6 @@ const wchli_t *version = wli("82"); const wchar_t *progname = L"txr"; -val self_path, prog_args_full, prog_args; /* * Can implement an emergency allocator here from a fixed storage @@ -182,7 +181,7 @@ int txr_main(int argc, char **argv) val arg; list_collect_decl(arg_list, arg_tail); - protect(&spec_file_str, &self_path, &prog_args, &prog_args_full, (val *) 0); + prot1(&spec_file_str); setvbuf(stderr, 0, _IOLBF, 0); @@ -196,7 +195,7 @@ int txr_main(int argc, char **argv) while (*argv) arg_tail = list_collect(arg_tail, string_utf8(*argv++)); - prog_args_full = arg_list; + reg_var(intern(lit("*full-args*"), user_package), arg_list); arg_list = cdr(arg_list); @@ -414,7 +413,7 @@ int txr_main(int argc, char **argv) } } - prog_args = arg_list; + reg_var(intern(lit("*args*"), user_package), arg_list); { int gc = gc_state(0); @@ -434,7 +433,7 @@ int txr_main(int argc, char **argv) format(std_error, lit("bindings:\n~s\n"), bindings, nao); } - self_path = spec_file_str; + reg_var(intern(lit("*self-path*"), user_package), spec_file_str); { int retval = extract(spec, arg_list, bindings); |