summaryrefslogtreecommitdiffstats
path: root/eval.c
Commit message (Collapse)AuthorAgeFilesLines
...
* * eval.c, gc.c, rand.c, regex.c, signal.c: Remove inclusion of unneededKaz Kylheku2014-04-131-1/+0
| | | | headers.
* * eval.c (make_var_shadowing_env): Remove unnecessary test forKaz Kylheku2014-04-111-8/+4
| | | | colon symbol.
* * eval.c (rangev_func, range_star_v_func): Use numericKaz Kylheku2014-04-081-3/+3
| | | | equivalence comparison for end test, rather than eql.
* Change to how locations are passed around, for the sake of generationalKaz Kylheku2014-03-291-44/+45
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | GC. The issue being solved here is the accuracy of the gc_set function. The existing impelmentation is too conservative. It has no generation information about the memory location being stored, and so it assumes the worst: that it is a location in the middle of a gen 1 object. This is sub-optimal, creating unacceptable pressure against the checkobj array and, worse, as a consequence causing unreachable gen 0 objects to be tenured into gen 1. To solve this problem, we replace "val *" pointers with a structure of type "loc" which keeps track of the object too, which lets us discover the generation. I tried another approach: using just a pointer with a bitfield indicating the generation. This turned out to have a serious issue: such a bitfield goes stale when the object is moved to a different generation. The object holding the memory location is in gen 1, but the annotated pointer still indicates gen 0. The gc_set function then makes the wrong decision, and premature reclamation takes place. * combi.c (perm_init_common, comb_gen_fun_common, rcomb_gen_fun_common, rcomb_list_gen_fun): Update to new interfaces for managing mutation. * debug.c (debug): Update to new interfaces for managing mutation. Avoid loc variable name. * eval.c (env_fbind, env_fbind): Update to new interfaces for managing mutation. (lookup_var_l, dwim_loc): Return loc type and update to new interfaces. (apply_frob_args, op_modplace, op_dohash, transform_op, mapcarv, mappendv, repeat_infinite_func, repeat_times_func): Update to new interfaces for managing mutation. * eval.h (lookup_var_l): Declaration updated. * filter.c (trie_add, trie_compress, trie_compress_intrinsic, * build_filter, built_filter_from_list, filter_init): Update to new * interfaces. * gc.c (gc_set): Rewritten to use loc type which provides the exact generation. We do not need the in_malloc_range hack any more, since we have the backpointer to the object. (gc_push): Take loc rather than raw pointer. * gc.h (gc_set, gc_push): Declarations updated. * hash.c (struct hash): The acons* functions use loc instead of val * now. (hash_equal_op, copy_hash, gethash_c, inhash, gethash_n, pushhash, Change to how locations are passed around, for the sake of generational GC. The issue being solved here is the accuracy of the gc_set function. The existing impelmentation is too conservative. It has no generation information about the memory location being stored, and so it assumes the worst: that it is a location in the middle of a gen 1 object. This is sub-optimal, creating unacceptable pressure against the checkobj array and, worse, as a consequence causing unreachable gen 0 objects to be tenured into gen 1. To solve this problem, we replace "val *" pointers with a structure of type "loc" which keeps track of the object too, which lets us discover the generation. I tried another approach: using just a pointer with a bitfield indicating the generation. This turned out to have a serious issue: such a bitfield goes stale when the object is moved to a different generation. The object holding the memory location is in gen 1, but the annotated pointer still indicates gen 0. The gc_set function then makes the wrong decision, and premature reclamation takes place. * combi.c (perm_init_common, comb_gen_fun_common, rcomb_gen_fun_common, rcomb_list_gen_fun): Update to new interfaces for managing mutation. * debug.c (debug): Update to new interfaces for managing mutation. Avoid loc variable name. * eval.c (env_fbind, env_fbind): Update to new interfaces for managing mutation. (lookup_var_l, dwim_loc): Return loc type and update to new interfaces. (apply_frob_args, op_modplace, op_dohash, transform_op, mapcarv, mappendv, repeat_infinite_func, repeat_times_func): Update to new interfaces for managing mutation. * eval.h (lookup_var_l): Declaration updated. * filter.c (trie_add, trie_compress, trie_compress_intrinsic, * build_filter, built_filter_from_list, filter_init): Update to new * interfaces. * gc.c (gc_set): Rewritten to use loc type which provides the exact generation. We do not need the in_malloc_range hack any more, since we have the backpointer to the object. (gc_push): Take loc rather than raw pointer. * gc.h (gc_set, gc_push): Declarations updated. * hash.c (struct hash): The acons* functions use loc instead of val * now. (hash_equal_op, copy_hash, gethash_c, inhash, gethash_n, pushhash,
* * eval.c (me_quasilist): New static function.Kaz Kylheku2014-03-251-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | (eval_init): Register me_quasilist as quasilist macro expander. * lib.c (quasilist_s): New global variable. (obj_init): quasilist_s initialized. * lib.h (quasilist_s): Declared. * match.c (do_txreval): Handle quasilist syntax. * parser.l (QWLIT): New exclusive state. Extend lexical grammar to transition to QWLIT state upon the #` or #*` sequence which kicks off a word literal, and in that state, piecewise lexically analyze the QLL, mostly by borrowing rules from quasiliterals. * parser.y (QWORDS, QWSPLICE): New tokens. (n_exprs): Integrate splicing form of QLL syntax. (n_expr): Integrate non-splicing form of QLL syntax. (litchars): Propagate line number info. (quasilit): Fix "string literal" wording in error message. * txr.1: Introduced WLL abbreviation for word list literals, cleaned up the text a little, and documented QLL's.
* * eval.c (expand_quasi): Bugfix: incorrect logic, failingKaz Kylheku2014-03-251-8/+11
| | | | | to macro-expand the embedded forms in a quasiliteral except when they are the very first item.
* * eval.c (eval_init): Register last function as intrinsic.Kaz Kylheku2014-03-231-0/+1
| | | | | | | | * lib.c (last): New function. * lib.h (last): Declared. * txr.1: Documented last.
* * eval.c (eval_init): Register empty as intrinsic.Kaz Kylheku2014-03-231-0/+1
| | | | | | | | | | | | * lib.c (copy): Bugfix: handle lazy strings. Also, handle hash tables via copy_hash. (length): Bugifx: handle lazy strings. Also, handle hash tables via hash_count. (empty): New function. * lib.h (empty): Declared. * txr.1: Documented.
* * eval.c (not_s): New symbol var.Kaz Kylheku2014-03-231-2/+27
| | | | | | | (me_unless, me_while, m_until): New static functions. (eval_init): Register macros unless, while and until. * txr.1: Document unless, while and until.
* * eval.c (me_when): New static function.Kaz Kylheku2014-03-221-0/+7
| | | | | | (eval_init): Register "when" macro. * txr.1: Documented when macro.
* * arith.c (tofloat, toint): New functions.Kaz Kylheku2014-03-191-0/+2
| | | | | | | | | * arith.h (tofloat, toint): Declared. * eval.c (eval_init): tofloat and toint registered as intrinsics. * txr.1: Documented.
* * eval.c (eval_init): Make seed argument optional in make-random-state.Kaz Kylheku2014-03-141-1/+1
| | | | | | | | | | | | | | | * rand.c (make_random_state): Do argument defaulting on seed. Also, mix getpid() into the seed. (random_fixnum): Bugfix: do proper defaulting on optional agument, rather than relying on nil. (random): Fix 2014-02-05 regression. This was totally broken, ignoring the random state passed in and using the global random state. This function must only use the state passed in; there is no defaulting to the global random state. * txr.1: Documenting that seed is optional in make-random-state. Describing what guarantees can be expected with regard to calls made close together temporally.
* * eval.c (plus_s, prof_s): New symbol global variables.Kaz Kylheku2014-03-121-3/+40
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (op_prof, me_pprof): New static functions. (eval_init): Intern prof symbol, store in prof_s. Captured interned + symbol in plus_s. Register prof operator and pprof macro. * gc.c (gc_bytes): New global variable. (more): Use nse function chk_malloc_gc_more instead of chk_malloc. (make_obj): Increment gc_bytes. * lib.c (malloc_bytes): New global variable. (chk_malloc, chk_realloc): Increment malloc_bytes. (chk_calloc): Bugfix: incorrect size in recursion into oom_realloc. Incorrect calculation of malloc_high_bound. Increment malloc_bytes. (chk_malloc_gc_more): New function. * lib.h (alloc_bytes_t): New typedef. (malloc_bytes, gc_bytes): Declared. (chk_malloc_gc_more): Declared. * stream.c (format_s): New symbol global. (stream_init): format_s inited. format_s used to register formatv function. * stream.h (format_s): Declared. * txr.1: Documented prof and pprof. * genvim.txr: Recognize reg_fun calls with intern followed by a preceding assignment or other syntax. * txr.vim: Updated.
* * eval.c (eval_init): Registration of url_encode and url_decodeKaz Kylheku2014-03-111-3/+0
| | | | | | | | | | | | | | | | moved to filter.c. * filter.c (trie_compress_intrinsic, html_encode, html_decode): New static functions. (filter_init): Register make_trie, trie_add, trie_compress_intrinsic, filter_string_tree, filter_equal, html_encode and html_decode as intrinsics. Move registration of url_encode and url_decode here. * genvim.txr: Look for registrations in filter.c too. * txr.1: Documented. * txr.vim: Updated.
* * eval.c (apply_intrinsic, lazy_mapcar): Changed linkage to external.Kaz Kylheku2014-03-061-2/+2
| | | | | | | | | | | | | * eval.h (apply_intrinsic, lazy_mapcar): Declarations added. * stream.c (open_files, open_file_star): New functions. (stream_init): Registered new functions as intrinsics. * txr.1: Documented open-files and open-files*. Added to make-catenated-stream documentation. * genvim.txr: Replace bunch of code with open-files. * txr.vim: Regenerated.
* g++ regressions.Kaz Kylheku2014-03-061-1/+1
| | | | | | | | | | * eval.c (env_k): Duplicate global variable definition removed. * lib.c (vector, vec_set_length): Fixed signed/unsigned comparison warnings. * stream.h (stdin_s, stdout_s, stddebug_s, stderr_s, stdnull_s): Declarations were definitions due to missing extern.
* * arith.c (logten): New function.Kaz Kylheku2014-03-041-0/+1
| | | | | | | | * eval.c (eval_init): logten registered as intrinsic. * lib.h (logten): Declared. * txr.1: Documented.
* * eval.c (make_env_intrinsic): New static function.Kaz Kylheku2014-03-021-0/+15
| | | | | | (eval_init): Register new intrinsics make-env, env-fbind and env-vbind. * txr.1: Documented.
* * eval.c (expand): Bugfix. When processing a defvar, should markKaz Kylheku2014-03-021-0/+2
| | | | | | the variable as special at expansion time. Without this, binding forms in other parts of the tree won't be expanded properly to bring about the special semantics.
* New quasiquote idea: let's have two quasiquote macros sharing oneKaz Kylheku2014-03-011-21/+37
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | expander. One macro based on sys:qquote, sys:unquote and sys:splice, and the other based on qquote, unquote and splice in the user package. The read syntax puts out the sys: one. * eval.c (expand_qquote): Takes three additional arguments: the qquote, unquote and splice symbols to recognize. The invalid splice diagnostic is adjusted based on which backquote we are expanding. (me_qquote): Look at the symbol in the first position of the form and then expand either the internal quasiquote macro or the public one, passing the right symbols into expand_qquote. (eval_init): Register error-throwing stub functions for the sys_qquote_s, sys_unquote_s and sys_splice_s symbols. Register a macro for sys_qquote_s. * lib.c (sys_qquote_s, sys_unquote_s, sys_splice_s): New symbol variables. (obj_init): Initialize new variables. Change qquote_s, unquote_s and splice_s to user package. (obj_print, obj_pprint): Convert only sys_qquote_s, sys_unquote_s and sys_splice_s to the read syntax. The quote_s, unquote_s and splice_s symbols are not treated specially. * lib.h (sys_qquote_s, sys_unquote_s, sys_splice_s): Declared. * parser.y (n_expr): Use sys_qquote_s, sys_unquote_s and sys_splice_s rather than qquote_s, unquote_s and splice_s. (unquotes_occur): Likewise. * txr.1: Documented.
* * eval.c (expand_qquote): Another bugfix: not recognizing a trailingKaz Kylheku2014-03-011-1/+3
| | | | | | atom that comes out of recursive call, wrapped in (quote ...), resulting in '(,a . b) expanding to (append 'a . quote b) rather than (append (list 'a) (quote b)); i.e. (append (list 'a) 'b).
* * eval.c (lookup_sym_lisp1): Bugfix: wasn't following the dynamicKaz Kylheku2014-03-011-25/+25
| | | | | environment at all, and still had vestiges of support for the the old cptr based global variables.
* * eval.c (self_evaluating_p, maybe_quote): New functions.Kaz Kylheku2014-02-281-1/+21
| | | | | (expand): Use maybe-quote form macro-time, to not quote result unnecessarily.
* Turn *gensym-counter* into proper special variable.Kaz Kylheku2014-02-281-1/+1
| | | | | | | | | | | | | | | | | * 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.
* Change in the design of how special variables work, to fix the brokenKaz Kylheku2014-02-281-224/+33
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* * eval.c (op_defvar): Remove the same-named symbol macro when aKaz Kylheku2014-02-281-0/+11
| | | | | | | | | | | | variable is defined. (op_defsymacro): Remove the same-named variable when a symbol macro is defined. (op_defun): Throw excpetion if an attempt is made to define a special operator as a function. Remove the same-named macro when a function is defined. (op_defmacro): Throw excpetion if an attempt is made to define a special operator as a macro. REmove the same-named function when a macro is defined.
* * eval.c (expand_qquote): Fix broken '(,x . ,y) case, whichKaz Kylheku2014-02-281-2/+4
| | | | | | | | is generating (append (list x) . y) instead of (append (list x) y). Also, added a nil case which is now necessary to prevent '(,x) from generating (append (list x) nil), though this is effectively an optimization, which is pointless, since the expander isn't optimizing overall.
* Bugfixing semantics of symbol macro hiding by variable bindings.Kaz Kylheku2014-02-281-6/+16
| | | | | | | | | | | | | * eval.c (expand_vars): Expand vars needs to know whether it's handling a sequential (let*-like) or parallel (let-like) binding. The init form of a variable sees the previous macro environment, but that variable must, for the remaining variables, shadow any previous symbol macro. (expand): In expand we must inform expand_vars whether we have a sequential or parallel binding construct. Moreover, there was a huge bug here: the new_menv (with the shadows) was passed to expand_vars, so that all the variables were hiding same-named symbol macros from all their initforms.
* * eval.c (delay_s): Global variable removed.Kaz Kylheku2014-02-271-3/+2
| | | | | | | | (eval_init): Initialiation of delay_s removed. Symbol now interned in reg_mac call for registering me_delay . * genvim.txr: Updated to recognize a reg_mac call with intern.
* * lib.c (copy): New function.Kaz Kylheku2014-02-271-1/+1
| | | | | | | | * lib.h (copy): Declared. * eval.c (eval_init): Registered copy function as intrinsic. * txr.1: Added missing documentation for length. Documented copy.
* * eval.c (maybe_progn): New function.Kaz Kylheku2014-02-271-2/+8
| | | | | (expand_macrolet, expand_symacrolet): Use maybe_progn to eliminate unnecessary progn wrapping.
* * eval.c (gun_s): New global variable.Kaz Kylheku2014-02-261-1/+12
| | | | | | | | (me_gun): New static function. (eval_init): New gun symbol interened, me_gun registered as intrinsic macro. * txr.1: Documented gun.
* Converting expander special case code transformations intoKaz Kylheku2014-02-261-50/+59
| | | | | | | | | | | | | | | | | | | | | | | | | | | formal macros that are in the top_mb table, make their symbols fboundp and can be expanded with macroexpand. * eval.c (mefun_t): New typedef name. (expand_macro): If the expander is a cobj, then pull out the C function and call it, otherwise realize the interpreted macro as before. (me_gen, me_delay): New static functions, replace expand_gen and expand_delay. (expand_qquote): Renamed to me_quote. (expand_gen, expand_delay): Renamed to me_gen and me_delay, with an interface adjustment and moved. (expand_op): Renamed to me_op. (expand): Removed qquote, gen, delay, op, and do handling, since these operators are now macros. Removed the unnecessary expansion of with-saved-vars. (reg_op, reg_fun): Assert that the symbol is not nil, to catch initialization order issues. One just showed up: op_do was interned in match.c, which is initialized later. (reg_mac): New static function (eval_init): Intern do_s, because match.c hasn't done it yet at this point. Register me_gen, me_delay, me_op (twice) and me_qquote as intrinsic macros. * txr.1: Documented those operators as macros.
* * eval.c (reg_op): New static function.Kaz Kylheku2014-02-261-45/+50
| | | | | (eval_init): Register operators with reg_op instead of direct sethash calls.
* * eval.c (do_eval): Set last_form_evaled just beforeKaz Kylheku2014-02-261-2/+3
| | | | dispatching function, so it is not clobbered by argument evaluations.
* * eval.c (expand_op): Use rlcp_tree when constructing theKaz Kylheku2014-02-261-6/+6
| | | | | | | | | | | | dwim_body, since the append2 copies list structure. * parser.y (n_exprs): propagate source loc info from both constituents, giving precedence to the left one, rather than just taking it from the left one and ignoring the second constituent. This fixes cases of missing location info. The left constituent n_expr is often a symbol, and those do not have location info. We want a case like like ((x) y) to take from (x), and (x (y)) to take it from (y), and so on.
* * eval.c (expand_place): Unnecessary, buggy function removed.Kaz Kylheku2014-02-261-78/+3
| | | | | | | | | | | | It was handling silly special cases with the net effect of being nearly equivalent to just expand, while failing to expand places which are compound macro calls. It did diagnose nonexistent place types at expansion time, which isn't worth much. (expand): All the expansions for the mutating operator sset, inc, dec, push, pop and flip were also pointless and have been removed. they did the precise equivalent of doing expand(rest(form)), and consing the symbol to the front, which is the fallback case for function call forms.
* * eval.c (eval_init): HAVE_MAKEDEV not HAVE_MKDEV.Kaz Kylheku2014-02-251-1/+1
|
* * configure: Added feature tests for makedev, link/symlink/readlink,Kaz Kylheku2014-02-251-2/+9
| | | | | | | | | | | | | | mkdir and mknod. * eval.c (eval_init): Wrap #ifdefs around the registrations of the wrappers for these functions. * stream.c (mkdir_wrap): Wrap in #ifdef HAVE_MKDIR, and provide a Windows version if HAVE_MKDIR is missing, but HAVE_WINDOWS_H is true. (makedev_wrap, major_wrap, minor_wrap): Wrap with #if HAVE_MAKEDEV. (mknod): Use #if HAVE_MKNOD. (symlink_wrap, link_wrap, readlink_wrap): Wrap with #if HAVE_SYMLINK.
* * eval.c (eval_init): Intern symlink_wrap, link_wrap, readlink_wrap.Kaz Kylheku2014-02-241-0/+3
| | | | | | | | * stream.c (symlink_wrap, link_wrap, readlink_wrap): New functions. * stream.h (symlink_wrap, link_wrap, readlink_wrap): Declared. * txr.1: Documented.
* * eval.c (eval_init): Register forgotten s_ifsock variable.Kaz Kylheku2014-02-241-0/+14
| | | | | | | | | | | | | | | | Register mkdir_wrap, chdir_wrap, getcwd_wrap, makedev_wrap, minor_wrap, major_wrap and mknod_wrap. * stream.c (mkdir_wrap, chdir_wrap, getcwd_wrap, makedev_wrap, minor_wrap, major_wrap, mknod_wrap): New functions. (stream_init): Initialize forgotten variable s-ifsock. * stream.h (s_ifsock): Declared. (mkdir_wrap, chdir_wrap, getcwd_wrap, makedev_wrap, minor_wrap, major_wrap, mknod_wrap): Declared. * txr.1: Forgotten documentation for remove-path and rename-path added. Forgotten mention of s-ifsock. Documented new Unix functions.
* * eval.c (expand_qquote): Bugfix. Was not handling an unquoteKaz Kylheku2014-02-241-1/+3
| | | | | | | | | in the dotted position: (qquote x1 .. xn . (unquote form)), which looks like the structure (qquote x1 .. xn unquote form). Fixed by a hack: after recursively expanding the (unquote form) part (rest of the form), we check whether the unexpanded version has unquote at the front. If so, we know the expansion is just form, and use it to emit the suitable expansion.
* Symbol macros.Kaz Kylheku2014-02-241-31/+189
| | | | | | | | | | | | | | | | | | | | | | | | * eval.c (top_smb, defsymacro_s, symacrolet_s): New global variables. (lookup_symac, get_opt_param_syms, get_param_syms, op_defsymacro, expand_symacrolet, make_var_shadowing_env): New static functions. (expand_tree_cases, expand_catch_clause): Install shadowing environment so lexical bindings hide any symbol macrolets. (expand_place): Fix neglect to expand an atomic form, which breaks symbol macros used as places. (expand): Expand symbol macros, expand symacrolet binding forms. Make sure symbol macros are shadowed in the lexical binding constructs. Take advantage of return value of rlcp_tree in a few places. (macro_form_p): Support for symbol macros; bugfix: not handling default argument. (macroexpand_1): Streamlined, and support added for symbol macros. (eval_init): Protect top_smb from gc. Create new hash, stored in top_smb. Initialize defsymacro_s and symacrolet_s. Register op_defsymacro. * parser.y (rlcp_tree): Return the to form instead of useless t and nil. * txr.1: Documented.
* * eval.c (env_fbind, env_vbind): Use acons_new_c, and provideKaz Kylheku2014-02-231-45/+34
| | | | | | | | | | | | | | | | | | a much more useful return value: the binding cell itself, rather than the symbol. (bind_args): Bugfix: env_vbind was still being called in one case, leading to a neglect to bind a special variable properly. (bindings_helper): Changed interface. Bugfix: in sequential binding, actually bind the successive environments so closures will behave 100% correctly. Returns a list of the actual bindings, in which special variables are not distinguished in any way. (op_let, op_for): Conform to new bindings_helper interface. Use the lexical environment that it returns instead of making a new one. (op_each): Use the environment and list of bindings out of bindings_helper. The bindings are used for stepping the lists, and that includes stepping any special vars. The lexical environment is used for evaluating the body. Thus, we need no special processing for special vars here any more.
* * eval.c (bindings_helper): This must now bind dynamic valuesKaz Kylheku2014-02-231-74/+45
| | | | | | | | | | | | | | | rather than just assign to them. Got rid of the superfluous variable saving array. Fixed the problem in recognizing the special_s symbol (it is bindable). (op_with_saved_vars): This simplifies, since it no longer needs to save individual variables in an array, only to set up and tear down a new dynamic environment frame. (expand_vars): No longer returns two values with a cons. Takes a form argument for error reporting and a pointer to a boolean just to report whether there are special vars without listing them. (expand_save_specials): The with-saved-specials form doesn't need a var list any more, so the expander is updated not to stick them in. (expand): Update calls to expand_vars to new interface.
* Get special variable overriding working in function and macroKaz Kylheku2014-02-231-48/+122
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | parameter lists. There is a bugfix here too (see eval_init below). * eval.c (special_s): New global variable. This symbol is used as a marker in parameter lists denoting expander-generating syntax that gives information about specials. (lookup_var, looup_var_l): Bugfix: walk the dynamic chain properly. Fallback from the lexical chain to the dynamic. (env_vbind_special): New static function. (bind_args, bind_macro_params): Detect special list in params. Use env_vbind_special to bind variables either in the dynamic environment or the lexical one. (expand_opt_params, expand_params): Renamed to expand_opt_params_rec and expand_params_rec, respectively. Now take extra argument for accumulating list of special variables found in the param list. (expand_params): New static function. (set_dyn_env): New static function. (interp_fun, expand_macro): Set up and tear down new dynamic environment around parameter list evaluation and body evaluation. This will take any new dynamic bindings. (bindings_helper, op_each): The special_s symbol is now used instead of colon_k for marking specials. (op_defun): Recognize the specials added to the parameter list so as not to t report that as not a bindable symbol. (op_catch): Set up an tear down new dynamic environment around the evaluation of the catch clause param binding and body. (expand_vars): use colon_s symbol instead of colon_k for marking special var. (eval_init): Bugfix: gc-protect recently added dyn_env variable. Intern special symbol into special_s variable.
* Introducing some changes for improved handling of special variables.Kaz Kylheku2014-02-231-15/+32
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Saving and restoring of individual variables is very silly and it's making it difficult to implement function parameters that are rebindings of special variables. Let's have a global pointer to a dynamic environment called dyn_env. Let's make it part of the extended_jmp_buf structure, so that it's implicitly saved and restored across exception handling. Special variable lookups go through the dyn_env chain, and fall back on the global bindings. To override some specials, we just push a new dynamic environment and stick them there. (As a bonus, the bindings can even be repeated in the lexical environment (i.e. the same objects), so they can be found faster. We have to make sure we remove that environment when we leave the scope in the normal way. If we unwind out, it is done automatically by extended_longjmp mechanism. * eval.c (dyn_env): New global variable. (lookup_var, lookup_var_l): If env is nil, look in the dyn_env first, and only if that fails, look in the global bindings top_vb. * signal.h (extended_jmp_buf): New member, de, for saving/restoring dyn_env. This structure is now used whether or not we have signals. (extended_setjmp, extended_longjmp): Updated to save and restore dyn_env, and to do it regardless of whether there is POSIX signal support. (dyn_env): Declared here.
* * eval.c (symbol_function): Retrieve the global macro binding if theKaz Kylheku2014-02-221-3/+6
| | | | | | | | | | | function lookup fails, and if that fails, retrieve the special operator binding. (fboundp): Report t if there is a global macro binding. * txr.1: Use "global" rather than "toplevel". Added note that the fun operator doesn't see macro bindings. Documented that symbol-function and fboundp see global macro bindings, and that symbol-function can retrieve a special operator binding.
* * eval.c (prinl, pprinl): New functions.Kaz Kylheku2014-02-221-0/+16
| | | | | | (eval_init): Registered as intrinsics. * txr.1: Documented.
* * eval.c (eval_intrinsic): We don't need to make an environmentKaz Kylheku2014-02-221-10/+7
| | | | | | | | | | | | | | | | | | here if the env parameter is nil. The low level environment lookup functions already handle nil. (do_eval): Do not type check the env argument for the ENV type. (expand_forms, expand): No need to default a missing menv to a blank environment; just use nil. (macro_form_p): Take menv parameter and switch to lookup_mac from gethash. (macroexpand_1, macroexpand): Use the environment parameter by using lookup_mac rather than gethash. (eval_init): Fix registration of macro_form_p to reflect new optional argument. * txr.1: Documented optional environment parameters in macro-form-p, macroexpand-1 and macroexpand. Documented macrolet.