summaryrefslogtreecommitdiffstats
path: root/lib.c
Commit message (Collapse)AuthorAgeFilesLines
...
* String type related bugfixes: neglecting to handle all three kinds inKaz Kylheku2014-05-101-0/+4
| | | | | | | | | | | | | | | some places. In particular, the test case echo : | ./txr -c '@a:@a' - breaks because of neglected LIT in do_match_line. * arith.c (tofloat, toint): Handle LIT type in switch. * lib.c (ref, refset, replace, update): Handle LSTR type. * match.c (do_match_line, do_output_line): Handle LSTR and LIT objects in switch.
* * lib.c (eql): Bugfix: not handling floating-point types!Kaz Kylheku2014-04-071-5/+13
| | | | | Two objects which are equal floating-point values must be considered eql even if they are distinct objects (not eq).
* Change to how locations are passed around, for the sake of generationalKaz Kylheku2014-03-291-146/+127
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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,
* * lib.c (string_time): If possible, change the timezone in theKaz Kylheku2014-03-291-0/+5
| | | | | struct tm from "GMT" to "UTC", so that the time_string_utc function will use UTC for the %Z format.
* More generational GC fixes. One GC fix.Kaz Kylheku2014-03-271-7/+8
| | | | | | | | | | | | | | | * combi.c (perm_init_common, comb_gen_fun_common, rcomb_gen_fun_common): Use set macro instead of plain assignment. * hash.c (hash_grow, copy_hash, hash_update_1): Use set macro instead of plain assignment. * lib.c (nreverse, lazy_appendv_func, lazy_appendv, vec_push, refset): Use set macro instead of plain assignment. (make_package): Assign all fields of the newly created PKG object before calling a function which can trigger GC. * parser.y (rlset): Use set macro.
* Fix generational GC regression caused by fixesKaz Kylheku2014-03-271-12/+12
| | | | | | | | | | in in 2014-03-12, when prof was introduced. The attempt to fix a bug made things worse. * lib.c (adjust_bounds): New static function. (chk_malloc, chk_calloc, chk_realloc): Replace existing logic with call to adjust_bounds. (chk_malloc_gc_more): Bugfix: add missing call to adjust_bounds.
* * eval.c (me_quasilist): New static function.Kaz Kylheku2014-03-251-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | (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 (eval_init): Register last function as intrinsic.Kaz Kylheku2014-03-231-0/+6
| | | | | | | | * 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/+34
| | | | | | | | | | | | * 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.
* * lib.c (iffi): Bugfix: was still using incorrect, outdated optionalKaz Kylheku2014-03-121-2/+1
| | | | argument defaulting logic.
* * eval.c (plus_s, prof_s): New symbol global variables.Kaz Kylheku2014-03-121-3/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (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.
* * lib.c (lazy_sub_str): Bugfix: "from" was mistakenly usedKaz Kylheku2014-03-091-1/+1
| | | | | | | in the adjustment of the "to" value. * match.c (search_form): Use predefined constants for -1 and 1 instead of calling num.
* * lib.c (upop): New function.Kaz Kylheku2014-03-071-0/+6
| | | | | | | | | | | | | | * lib.h (upop): Declared. * txr.c (txr_main): Two bugfixes. One is that the argument - was being pushed back twice resulting in *args* being ("-" "-"). This is because the option processing loop checked for "-" and pushed it back into args, and then some logic after the loop pushed arg back into args again. But, these pushes were wrong because they push back a different cons cell; we would like to be able to do (ldiff *full-args* *args*). This is solved by upop, which provides one element of undo. After upop, we can restore the prior list from the undo save location.
* * lib.c (assert_s): New global variable.Kaz Kylheku2014-03-061-1/+2
| | | | | | | | | | | | | | | (obj_init): Intern assert symbol, store in assert_s. * lib.h (assert_s): Declared. * match.c (typed_error, v_assert, h_assert): New static functions. (dir_tables_init): Register v_assert and h_assert. Register assert_s as non-data-matching directive. * unwind.c (uw_init): Register assert as a subtype of error. * txr.1: Describe assert.
* g++ regressions.Kaz Kylheku2014-03-061-2/+2
| | | | | | | | | | * 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.
* * parser.l: Allowing ^ to be a quote character, and adjusting definitionKaz Kylheku2014-03-031-3/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | of identifiers to rule this out from being the first character of a symbol which has no prefix. Recognize the ^ character as a token in the NESTED state. * lib.c (obj_print, obj_pprint): Render sys:qquote as ^. * parser.y (choose_quote): Function removed. (n_expr): Recognize '^' as quasiquote. Removed all the "smart quote" hacks that try to make quote behave as quote or quasiquote, or try to cancel out unquotes and quotes. * tests/009/json.txr: Fixed to ^ quasiquote. * tests/010/reghash.txr: Likewise. * tests/011/macros-2.txr: Likewise. * tests/011/mandel.txr: Likewise. * tests/011/special-1.txr: Likewise. * txr.1: Updated docs. * genvim.txr: Revamped definitions for txr_ident and txl_ident so that unqualified identifiers cannot start with # or ^, but ones with @ or : in front can start with these characters. * txr.vim: Regenerated.
* New quasiquote idea: let's have two quasiquote macros sharing oneKaz Kylheku2014-03-011-9/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Turn *gensym-counter* into proper special variable.Kaz Kylheku2014-02-281-4/+3
| | | | | | | | | | | | | | | | | * 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-8/+30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* * lib.c (copy): New function.Kaz Kylheku2014-02-271-0/+18
| | | | | | | | * lib.h (copy): Declared. * eval.c (eval_init): Registered copy function as intrinsic. * txr.1: Added missing documentation for length. Documented copy.
* * lib.c (make_like): If the first element of list isn'tKaz Kylheku2014-02-261-1/+3
| | | | | | a character, then don't try to make it into a string; keep it as a list. This allows [mapcar list "abc" "def"] to work intuitively rather than blow up.
* * lib.c (lit_s): New symbol.Kaz Kylheku2014-02-261-5/+8
| | | | | | | (code2type): Return lit_s for LIT type. (typeof): Return lit_s for TAG_LIT. (replace_str): Error message wording. (obj_init): lit_s interned.
* * lib.c (obj_init): Revert qquote, unquote and spliceKaz Kylheku2014-02-251-3/+3
| | | | | | to the system namespace, for hygiene. * txr.1: Updated.
* * lib.c (obj_print, obj_pprint): Render quasi-quote hash andKaz Kylheku2014-02-241-1/+13
| | | | | | | | | | | | vector literals using their original notation. * parser.y (unquotes_occur): Takes new argument, level. Only finds quotes which are at the given quasiquoting level. Finally, this is the right semantics. In the first version of this function, we were not eager enough: we neglected to find unquotes that were wrapped in nested quasiquotes. Then we were too eager: finding any unquotes, even ones belonging to the inner backquotes. (vector, hash, choose_quote): Pass zero to unquotes_occur function.
* * lib.c (obj_init): changing the quote, qquote, unquoteKaz Kylheku2014-02-221-4/+4
| | | | | and splice symbols to be in the regular user package, rather than the system package.
* * parser.y: Allow the (. expr) syntax to denote expr.Kaz Kylheku2014-02-221-0/+28
| | | | | | | | | * eval.h: Declare existing lambda_s extern variable. * lib.c (obj_print, obj_pprint): print (lambda sym ...) as (lambda (. sym) ...) and (lambda sym) as (lambda (. sym)). * txr.1: document it.
* Replacing uses of the eq function which are used only as C booleans,Kaz Kylheku2014-02-221-10/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | with just using the == operator. Removing cobj_equal_op since it's indistinguishable from eq. Streamlining missingp and null_or_missing_p. * eval.c (transform_op): eq to ==. (c_var_ops): cobj_equal_op to eq. * filter.c (trie_compress, trie_lookup_feed_char, filter_string_tree, html_hex_continue, html_dec_continue): eq to ==. * hash.c (hash_iter_ops): cobj_equal to eq. * lib.c (countq, getplist, getplist_f, search_str_tree, posq): eq to ==. (cobj_equal_op): Function removed. * lib.h (cobj_equal_op): Declaration removed. (missingp): Becomes a simple macro that yields a C boolean instead of t/nil val, because it's only used that way. (null_or_missing_p): Becomes inline function returning int. * match.c (v_output): eq to ==. * rand.c (random_state_ops): cobj_equal_op to eq. * regex.c (char_set_obj_ops, regex_obj_ops): cobj_equal_op to eq. (reg_derivative): Silly if3 expression replaced by null. (regexp): Redundant if2 expression wrapped around eq removed. * stream.c (null_ops, stdio_ops, tail_ops, pipe_ops, string_in_ops, byte_in_ops, string_out_ops, strlist_out_ops, dir_ops, cat_stream_ops): cobj_equal_op to eq. * syslog.c (syslog_strm_ops): cobj_equal_op to eq.
* The C function nullp is being renamed to null, and the rarelyKaz Kylheku2014-02-221-10/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | used global variable null which holds a symbol becomes null_s. A new macro called nilp is added that more efficiently checks whether an object is nil, producing a C boolean value rather than t or nil. Most of the uses of nullp in the codebase just become the more streamlined nilp. * debug.c (show_bindings): nullp to nilp * eval.c (lookup_var, lookup_var_l, lookup_fun, lookup_sym_lisp1, do_eval, expand_qquote, expand_quasi, expand_op): nullp to nilp. (op_modplace): nullp to null. (eval_init): Update registration of null and not from C function nullp to null. * filter.c (trie_compress, html_hex_continue): nullp to nil. (filter_string_tree): null to null_s. * hash.c (hash_next): nullp to nilp. * lib.c (null): Variable renamed to null_s. (code2type): null to null_s. (lazy_flatten_scan, chainv, lazy_str, lazy_str_force_upto, obj_print, obj_pprint): nullp to nilp. (obj_init): null to null_s; nullp to null. * lib.h (null): declaration changed to null_s. (nullp): Inline function renamed to null. (nilp): New macro. * match.c (do_match_line): nullp to nilp. * rand.c (make_random_state): Likewise. * regex.c (compile_regex): Likewise.
* * eval.c (env_hash): new function.Kaz Kylheku2014-02-181-0/+2
| | | | | | | | | | | | | | | | (eval_init): Register env and env_hash functions. Register prog_args and prog_args_full as *args* and *full-args*. * lib.c (timegm_hack): Invalidate env_list, after mucking with the environment via setenv and unsetenv. * txr.c (prog_args_full, prog_args): New global variables. (txr_main): Command-line processing converted to use TXR's library. Populates prog_args_full and prog_args. * txr.h (prog_args_full, prog_args): Declared. * txr.1: Documented *args*, *full-args*, env and env-hash.
* * eval.c (eval_init): Register gensym function as the gensymKaz Kylheku2014-02-171-7/+1
| | | | | | | | | | | | | | intrinsic, rather than gensymv. Register gensym_counter as *gensym-counter*. * lib.c (gensym): Handle missing prefix argument by defaulting the prefix to "g". (gensymv): Function removed. * lib.h (gensymv): Declaration removed. * txr.1: Fixed omission: missing documentation for gensym. Documented *gensym-counter*.
* Replacing acons_new_l and aconsq_new_l interfaces with onesKaz Kylheku2014-02-141-9/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | that return the new or old cons cell rather than a pointer to its cdr field. * eval.c (transform_op): use of acons_new_l replaced with acons_new_c. * hash.c (struct hash): acons_new_l_fun member replaced with acons_new_c_fun. (make_hash, make_similar_hash): initialize acons_new_l_fun member using either acons_new_c or aconsql_new_c. (gethash_l): function becomes an inline in hash.h. (gethash_c): new function, based on gethash_l. (inhash, gethash_n): updated w.r.t struct hash change. * hash.h (gethash_c): declared. (gethash_l): becomes an inline wrapper for gethash_c. * lib.c (acons_new_l, aconsql_new_l): functions removed. (acons_new_c, aconsql_new_c): new functions. (obj_init): use gethash_c and rplacd instead of gethash_l and set. * lib.h (acons_new_l, aconsql_new_l): declarations removed. (acons_new_c, aconsql_new_c): declared.
* * lib.c (class_check): Bugfix: the function was assuming thatKaz Kylheku2014-02-141-1/+2
| | | | | the argument is a pointer type object, leading to a crash if given a fixnum integer or string literal.
* * lib.c (some_satisfy, all_satisfy, none_satisfy): Fix codingKaz Kylheku2014-02-121-3/+3
| | | | mistake from two commits ago leading to a regression.
* * eval.c (eval_init): Register new functions posqual, posql,Kaz Kylheku2014-02-111-0/+66
| | | | | | | | | | posq, pos, and pos_if as intrinsics. * lib.c (posqual, posql, posq, pos, pos_if): New functions. * lib.h (posqual, posql, posq, pos, pos_if): Declared. * txr.1: Documented
* * eval.c (eval_init): Turn a require argument into an optionalKaz Kylheku2014-02-111-0/+3
| | | | | | | | | | one for the functions some, all and none. * lib.c (some_satisfy, all_satisfy, none_satisfy): Add defaulting behavior for pred parameter. * txr.1: Document that the predicate function is optional in calls to some, all and none.
* * eval.c (rperm_list, rperm_vec, rperm_str): n variable renamedKaz Kylheku2014-02-091-0/+2
| | | | | | | | | | | | | | | | | | to k, for consistency with rperm. (rperm): Likewise, and the behavior in the k == zero case is changed to return a single empty permutation. (perm_while_fun, perm_index, perm_gen_fun_common, perm_init_common, perm_vec_gen_fill, perm_vec_gen_fun, perm_vec, perm_list_gen_fill, perm_list_gen_fun, perm_list, perm_str_gen_fill, perm_str_gen_fun, perm_str, perm): New static functions. (eval_init): perm registered as intrinsic. * lib.c (vecref_l): Bugfix: allow negative indices, just like vecref. * lib.h (three, four): New macros. * txr.1: Updated documentation for rperm. Documented perm.
* * lib.c (vector, vec_set_length, cat_vec): When the vector sizeKaz Kylheku2014-02-081-4/+21
| | | | overflows the size_t type that is passed to malloc, throw an exception.
* * lib.c (int_str): Regression: handle base argument properly.Kaz Kylheku2014-02-061-1/+1
|
* * hash.c (hash_grow, make_hash, make_similar_hash, copy_hash):Kaz Kylheku2014-02-061-4/+5
| | | | | | | | | | | | | | | Pass second argument to vector. * lib.c (vector): Takes additional argument specifying the value for the slots of the vector. (vector_list, sub_vec): Pass second argument to vector. * lib.h (vector): Declaration updated. * eval.c (eval_init): Register vector as two-argument function with one required arg. * txr.1: Updated.
* * eval.c (op_dwim): Gutted down to just a few lines.Kaz Kylheku2014-02-061-4/+13
| | | | | | | | | | | | Basically the dwim operator is just a Lisp-1 version of the call operator now. It doesn't have to do anything funny with non-function objects, since they are callable. * lib.c (chr_str, chr_str_set, vecref, vecref_l): Replace inappropriate internal assertions with error exceptions. * unwind.h (numeric_assert, range_bug_unless): Unused macros removed.
* * lib.c (generic_funcall): If a cons cell is passed asKaz Kylheku2014-02-051-0/+2
| | | | | | | one argument to a sequence being used as a function, split it into two arguments. This is consistent with the DWIM operator behavior. * txr.1: Document callable objects.
* Allow sequences and hashes to be called as functions.Kaz Kylheku2014-02-051-25/+51
| | | | | | | | | | | | | | | | This is already supported in the DWIM operator. * eval.c (apply): If object isn't a function, gather the arguments into an array and delegate to generic_funcall. * lib.c (generic_funcall): Changed from static to external linkage. Supports sequences and hashes as functions. Error messages fixed not to refer to "funcall". (funcall, funcall1, funcall2, funcall3, funcall4): Do not throw exception if fun is not of FUN type; instead, delegate to generic_funcall. Error messages fixed not to refer to "funcall". * lib.h (generic_function): Declared.
* * arith.c (lognot): Conform to new scheme for defaulting optional args.Kaz Kylheku2014-02-051-100/+45
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * eval.c (apply): Unconditionally use colon_k for missing optional args, for intrinsic functions. (eval_intrinsic, rangev, rangev_star, errno_wrap): Conform to new scheme for defaulting optional args. (reg_fun_mark): Function removed. (eval_init): Switch reduce_left and reduce_right back to reg_fun registration. * hash.c (gethash_n): Conform to new scheme for defaulting optional arguments. * lib.c (sub_list, replace_list, remove_if, keep_if, remove_if_lazy, keep_if_lazy, tree_find, count_if, some_satisfy, all_satisfy, none_satisfy, search_str, match_str, match_str_tree, sub_str, replace_str, cat_str, tok_str, intern, rehome_sym, sub_vec, replace_vec, lazy_str, sort, multi_sort, find, find_if, set_diff, obj_print, obj_pprint): Conform to new scheme for defaulting optional arguments. (func_f0, func_f1, func_f2, func_f3, func_f4, func_n0, func_n1, func_n2, func_n3, func_n4, func_n5, func_n6, func_n7, func_f0v, func_f1v, func_f2v, func_f3v, func_f4v, func_n0v, func_n1v, func_n2v, func_n3v, func_n4v, func_n5v, func_n6v, func_n7v): Remove references to removed mark_missing_args member of struct func. (func_set_mark_missing): Function removed. (generic_funcall): Unconditionally use colon_k for missing optional args, for intrinsic functions. * lib.h (struct func): mark_missing_args member removed. (func_set_mark_missing): Declaration removed. (default_arg, default_bool_arg): New inline functions. * rand.c (random): Left argument is not optional. (rnd): Conform to new scheme for defaulting optional arguments. * regex.c (search_regex, match_regex): Conform to new scheme for defaulting optional arguments. * stream.c (unget_char, unget_byte, put_string, put_char, put_byte, put_line): Conform to new scheme for defaulting optional arguments. * syslog.c (openlog_wrap): Conform to new scheme for defaulting optional arguments. * txr.1: Remove the specification that nil is a sentinel value in default arguments, where necessary. Use consistent syntax for specifying variable parts in argument lists. A few errors and omissions addressed.
* * eval.c (apply): Pass missing optional arguments as colon_k.Kaz Kylheku2014-02-051-11/+48
| | | | | | | | | | | | | | | | | | | | | | | to functions for which this is requested. (reg_fun_mark): New static function. (eval_init): Register reduce_left and reduce_right as requiring marking for missing optionals. * lib.c (func_set_mark_missing): New function. (generic_funcall): Pass missing optional arguments as colon_k to functions for which this is requested. (reduce_left, reduce_right): Handle missing values of init and key. (func_f0, func_f1, func_f2, func_f3, func_f4, func_n0, func_n1, func_n2, func_n3, func_n4, func_n5, func_n6, func_n7, func_f0v, func_f1v, func_f2v, func_f3v, func_f4v, func_n0v, func_n1v, func_n2v, func_n3v, func_n4v, func_n5v, func_n6v, func_n7v): Initialize new mark_missing_args member of struct func. * lib.h (struct func): New bitfield member, mark_missing_args. (func_set_mark_missing): Declared. (missingp, null_or_missing_p): New inline functions. * txr.1: Updated descriptions of reduce-left and reduce-right.
* * lib.c (nullp): Function removed.Kaz Kylheku2014-02-031-5/+0
| | | | | * lib.h (nullp): New inline function. (eq): Removed useless parentheses: it's not a macro.
* append can now take additional leading arguments before the list.Kaz Kylheku2014-02-021-0/+10
| | | | | | | | | | | | | * eval.c (apply_frob_args): New static function. (apply_intrinsic): Process arguments with apply_frob_args. (eval_init): apply_intrinsic registered differently, as a variadic function with one mandatory arg. * lib.c (lastcons): New function. * lib.h (lastcons): Declared. * txr.1: Updated append documentation.
* * eval.c (apply): Support string and vector arglist.Kaz Kylheku2014-02-021-0/+17
| | | | | | | | | | | (do_eval_args): Support string or vector in dot position. * lib.c (tolist): New function. * lib.h (tolist): Declared. * txr.1: Document how apply and dot position in compound forms supports strings as well as vectors.
* * lib.c (d): Disable garbage collection around the dump.Kaz Kylheku2014-02-011-0/+2
| | | | | | It's importa for this function not to have the side effect of triggering garbage collection, when it is used for debugging issues that show up under --gc-debug.
* * eval.c (meta_meta_p, meta_meta_strip): New static functions.Kaz Kylheku2014-01-281-2/+6
| | | | | | | | | | | | | | | (transform_op): Recognize compounded metas, and strip one level off. (eval_init): Intern sys:expand function so we have access to the form expander from TXR Lisp. * lib.c (obj_print, obj_pprint): Fix: wasn't rendering metanumbers. * parser.y (list): Support @ in front of anything. If it's an atom, treat it similarly to a metasymbol or metanumber. * txr.1: Documented meta-meta arguments in nested op. * genvim.txr, txr.vim: Support coloring for compounded meta syntax.
* * lib.c (reduce_left, reduce_right): changing the behavior so thatKaz Kylheku2014-01-271-1/+24
| | | | | | | | | the initial value is optional. this creates the possibility that the effective list of operands is empty, in which case the function must support a call with no arguments, just like in the common lisp reduce. * txr.1: rewrote reduce-left and reduce-right documentation.