summaryrefslogtreecommitdiffstats
path: root/stream.h
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2014-02-28 23:15:10 -0800
committerKaz Kylheku <kaz@kylheku.com>2014-02-28 23:15:10 -0800
commit94750af472e12acf3a5970c98e4dab6feada2e84 (patch)
tree0f91686515e864ea184cc866c980ddc979783b0c /stream.h
parent8c634953700bdf3199b68e8ccf2eff4132ca81d5 (diff)
downloadtxr-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 'stream.h')
-rw-r--r--stream.h13
1 files changed, 8 insertions, 5 deletions
diff --git a/stream.h b/stream.h
index 254b5cf4..04cdeb26 100644
--- a/stream.h
+++ b/stream.h
@@ -47,7 +47,13 @@ struct strm_ops {
val (*set_prop)(val, val ind, val);
};
-extern val std_input, std_output, std_debug, std_error, std_null;
+#define std_input (*lookup_var_l(nil, stdin_s))
+#define std_output (*lookup_var_l(nil, stdout_s))
+#define std_debug (*lookup_var_l(nil, stddebug_s))
+#define std_error (*lookup_var_l(nil, stderr_s))
+#define std_null (*lookup_var_l(nil, stdnull_s))
+val *lookup_var_l(val env, val sym);
+
extern val output_produced;
extern val dev_k, ino_k, mode_k, nlink_k, uid_k;
@@ -56,10 +62,7 @@ extern val atime_k, mtime_k, ctime_k;
extern val from_start_k, from_current_k, from_end_k;
extern val real_time_k, name_k;
-extern val s_ifmt, s_ifsock, s_iflnk, s_ifreg, s_ifblk, s_ifdir;
-extern val s_ifchr, s_ififo, s_isuid, s_isgid, s_isvtx, s_irwxu;
-extern val s_irusr, s_iwusr, s_ixusr, s_irwxg, s_irgrp, s_iwgrp;
-extern val s_ixgrp, s_irwxo, s_iroth, s_iwoth, s_ixoth;
+val stdin_s, stdout_s, stddebug_s, stderr_s, stdnull_s;
val make_null_stream(void);
val make_stdio_stream(FILE *, val descr);