summaryrefslogtreecommitdiffstats
path: root/hash.h
Commit message (Collapse)AuthorAgeFilesLines
* Copyright year bump.Kaz Kylheku2015-12-311-1/+1
| | | | | | | | | | | | | | | | | | | | | | | * LICENSE, METALICENSE, Makefile, args.c, args.h, arith.c, arith.h, cadr.c, cadr.h, combi.c, combi.h, configure, debug.c, debug.h, eval.c, eval.h, filter.c, filter.h, gc.c, gc.h, glob.c, glob.h, hash.c, hash.h, jmp.S, lib.c, lib.h, lisplib.c, lisplib.h, match.c, match.h, parser.c, parser.h, parser.l, parser.y, rand.c, rand.h, regex.c, regex.h, share/txr/stdlib/cadr.tl, share/txr/stdlib/except.tl, share/txr/stdlib/hash.tl, share/txr/stdlib/ifa.tl, share/txr/stdlib/path-test.tl, share/txr/stdlib/place.tl, share/txr/stdlib/struct.tl, share/txr/stdlib/txr-case.tl, share/txr/stdlib/type.tl, share/txr/stdlib/with-resources.tl, share/txr/stdlib/with-stream.tl, share/txr/stdlib/yield.tl, signal.c, signal.h, stream.c, stream.h, struct.c, struct.h, sysif.c, sysif.h, syslog.c, syslog.h, txr.1, txr.c, txr.h, unwind.c, unwind.h, utf8.c, utf8.h: Add 2016 copyright. * linenoise/LICENSE, linenoise/linenoise.c, linenoise/linenoise.h: Bump one principal author's copyright from 2014 to 2015. The code is based on a snapshot of 2015 upstream work.
* New function: group-reduce.Kaz Kylheku2015-11-101-0/+2
| | | | | | | | | | * eval.c (eval_init): Register group-reduce intrinsic. * hash.c (group_reduce): New function. * hash.h (group_reduce): Declared. * txr.1: Documented group-reduce.
* Large scale conversion to new way of handling arguments.Kaz Kylheku2015-08-231-5/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Function arguments are now allocated on the stack using alloca, in conjunction with the struct alloc header structure. The generic_funcall and apply functions are refactored for this, as are most functions that take variadic arguments. * args.c (args_add_list, args_cons_list): Functions removed. (args_normalize, args_normalize_fill): New functions. (args_get_checked): Draw arguments from list when array runs out. (args_copy, args_copy_zap): New functions. * args.h (ARGS_MAX): Reduced to 32. (ARGS_MIN): New preprocessor symbol. (args_init): Call args_init_list. (args_add2, args_add3, args_add4): New inline functions. (args_more): Take into account list, which may hold additional arguments. (args_two_more): New inline function. (args_normalize, args_normalize_fill): Declared. (args_get_list): Normalize all arguments into one list and return it. (args_get_rest, args_at, args_atz): New inline functions. (args_get): Draw arguments from list when array runs out. (args_clear): New inline function. * arith.c (maskv): Convert to new args. * eval.c (APPLY_ARGS): Preprocessor symbol removed. (bind_args): Converted to accept struct args. (apply): Function reduced down to trivial adapter which converts a list of arguments to args, and calls the new generic_funcall. (applyv): New static function: struct args wrapper around apply_intrinsic. (iapply): Converted to struct args. (call): Static function removed. The call intrinsic function binding now goes directly to generic_funcall. (list_star_intrinsic, interp_fun): Converted to struct args. (op_catch): Adjustments for bind_args, which requires a struct args arglist. (me_op): Must use the new minl and maxl, since minv and maxv don't take lists any more. (mapcarv, mappendv, lazy_mapcarv, lazy_mappendv, mapdov, weavev, or_fun, and_fun, tf, nilf, do_retf, do_apf, do_ipf, callf, do_mapf, mapf): Converted. (mapcarl): New function, like the old mapcarv. (eval_init): call_f initialized from generic_funcall rather than call. apply registered to applyv rather than apply_intrinsic. Registrations for zip, hash_from_pairs, vec, alist-remove, alist-nremove, and throw similarly updated to new or renamed functions. * eval.h (interp_fun, mapcarv): Declarations updated. (mapcarl): Declard. * hash.c (hashv): Converted to struct args. (hashl): New function. (hash_construct): Use hashl, not hashv. (hash_from_pairs, hash_list, group_by): Converted. * hash.h (hashv, hash_construct, hash_from_pairs, hash_list, group_by): Declarations updated. (hashl): Declared. * lib.c (appendv, nconcv, lazy_appendv): Converted to struct args. (lazy_appendl): New function. (multi): Converted. (listv): New function. (nary_op, plusv, mulv, logandv, logiorv, gtv, ltv, gev, lev, numeqv, numneqv, maxv, minv): Converted. (maxl, minl): New functions, like old maxv and minv. (exptv, gcdv, lcmv, lessv, greaterv, lequalv, gequalv): Converted. (func_f0v, func_f1v, func_f2v, func_f3v, func_f4v): Converted. (func_n0v, func_n1v, func_n2v, func_n3v, func_n4v): Converted. (func_n0v, func_n1v, func_n2v, func_n3v, func_n4v): Converted. (func_n1ov, func_n2ov, func_n3ov): Converted. (generic_funcall): Converted to take struct args. (funcall, funcall1, funcall2, funcall4): Pass stack-allocated struct args as trailing arguments to variadic functions, and to generic_funcall. (do_curry_12_1_v): New struct-args-based static function, needed to implement curry_12_1_v now. (curry_12_1_v): Converted. (transposev): New function based on previous tranpose. (transpose): Now a wrapper for transposev. (do_chain, chainv, do_chand, chandv, do_juxt, juxtv, do_and, andv, do_or, orv, do_not, do_iff): Converted. (vectorv): New function. Implementation basis for vec intrinsic function. (alist_removev, alist_nremovev): New functions. (multi_sort): Switch from mapcarv to mapcarl. (unique): Converted. (uniq): Allocate struct args for calling unique. (obj_init): list_f function now based on new listv, rather than identity. * list.h (varg): New typedef. (struct func): All variadic function pointers converted to use struct args. (appendv, nconcv, lazy_appendv, multi, nary_op, plusv, minusv, mulv, gtv, ltv, gev, lev, numeqv, numneqv, maxv, minv, exptv, gcdv, lcmv, logadnv, logiorv, maskv, lessv, greaterv, lequalv, gequalv, func_f0v, func_f1v, func_f2v, func_f3v, func_f4v, func_n0v, func_n1v, func_n2v, func_n3v, func_n4v, func_n0v, func_n1v, func_n2v, func_n3v, func_n4v, func_n1ov, func_n2ov, func_n3ov, generic_funcall, chainv, chandv, juxtv, adnv, orv, unique): Declarations updated. (lazy_appendl, listv, maxl, minl, transposev, vectorv, alist_removev, alist_nremovev): Declared. * stream.c (make_catenated_stream_v): New function. (aformat): Renamed to formatv. The recognition of the nil and t streams (standard output and string) is done here now. (vformat): Follow rename of aformat to formatv. (formatv): Function removed. Nobody calls this anymore. (stream_init): make-catenated-stream re-registered to new make_catenated_stream_v function. * stream.h (formatv): Declaration updated. (make_catenated_v): Declared. * syslog.c (syslog_init): syslog registred to syslog_wrapv. (syslog_wrapv): New function based on syslog_wrap converted to struct args. (syslog_wrap): Now wrapper for syslog_wrapv. * syslog.h (syslog_wrapv): Declared. * unwind.h (uw_throwv): New function. (uw_throwfv, uw_errorfv): Converted to struct args. * unwind.h (uw_throwv): Declared. (uw_throwfv, uw_errorfv): Declarations updated.
* * hash.c (hash_revget): New function.Kaz Kylheku2015-08-041-0/+1
| | | | | | | | * hash.h (hash_revget): Declared. * eval.c (eval_init): Registered hash-revget intrinsic. * txr.1: Documented hash-revget.
* * hash.c (hash_from_pairs, hash_list): New functions.Kaz Kylheku2015-06-241-0/+2
| | | | | | | | | * hash.h (hash_from_pairs, hash_list): Declared. * eval.c (eval_init): Registered hash-from-pairs and hash-list intrinsic. * txr.1: Documented new functions.
* Hash subset testing.Kaz Kylheku2015-06-231-0/+2
| | | | | | | | | | | * eval.c (eval_init): Register hash-subset and hash-proper-subset intrinsics. * hash.c (hash_subset, hash_proper_subset): New functions. * hash.h (hash_subset, hash_proper_subset): Declared. * txr.1: New functions documented.
* Update copyright notices from 2014 to 2015.Kaz Kylheku2015-02-011-1/+1
| | | | | | | | | | | * arith.c, arith.h, combi.c, combi.h, debug.c, debug.h, eval.c, eval.h, filter.c, filter.h, gc.c, gc.h, hash.c, hash.h, lib.c, lib.h, match.c, match.h, parser.h, rand.c, rand.h, regex.c, regex.h, signal.c, signal.h, stream.c, stream.h, sysif.c, sysif.h, syslog.c, syslog.h, txr.c, txr.h, unwind.c, unwind.h, utf8.c, utf8.h: Update. * LICENSE, METALICENSE: Likewise.
* * Makefile, arith.c, arith.h, combi.c, combi.h, configure, debug.c,Kaz Kylheku2014-07-231-16/+16
| | | | | | | | debug.h, eval.c, eval.h, filter.c, filter.h, gc.c, gc.h, hash.c, hash.h, lib.c, lib.h, match.c, match.h, parser.h, parser.l, parser.y, rand.c, rand.h, regex.c, regex.h, signal.c, signal.h, stream.c, stream.h, syslog.c, syslog.h, txr.c, txr.h, unwind.c, unwind.h, utf8.c, utf8.h: Synchronize license header with LICENSE.
* Change to how locations are passed around, for the sake of generationalKaz Kylheku2014-03-291-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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,
* Replacing acons_new_l and aconsq_new_l interfaces with onesKaz Kylheku2014-02-141-1/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* * eval.c (eval_init): Registered hash_update_1 as intrinsic.Kaz Kylheku2014-02-141-0/+1
| | | | | | | | * hash.c (hash_update_1): New function. * hash.h (hash_update_1): Declared. * txr.1: Documented hash-update-1.
* Different approach: optional arguments on hash-isec and hash-uni allowKaz Kylheku2014-02-141-4/+2
| | | | | | | | | | | | | | | | | | | | | for more flexible joining of data from the hash tables. * eval.c (eval_init): Remove hash_guni and hash_gisec. Change registration for hash_uni and hash_isec to three arguments with one optional. * hash.c (hash_uni): Third parameter introduced, join_func. The default behavior changes: in the two argument case, clashing keys prefer the value from hash1 rather than hash2. For this reason, we now iterate over hash2 first, then hash1. (hash_guni): Removed. (hash_isec): Third parameter introduced, join_func. (hash_gisec): Removed. * hash.h (hash_uni, hash_isec): Declarations updated. (hash_guni, hash_gisec): Delarations removed. * txr.1: Documentation updated.
* * eval.c (eval_init): Register hash_guni and hash_gisec as intrinsics.Kaz Kylheku2014-02-141-0/+2
| | | | | | | | | | | * hash.c (hash_guni, hash_gisec): New functions. (hash_isec): Bugfix: since gethash was naively used, keys in hash2 associated with the value nil were erroneously omitted from the intersection. * hash.h (hash_guni, hash_gisec): Declared. * txr.1: Documented new functions.
* * eval.c (eval_init): Register inhash as intrinsic.Kaz Kylheku2014-02-141-0/+1
| | | | | | | | | * hash.c (inhash): New function. * hash.h (inhash): Declared. * txr.1: Documented inhash. Also, added surprisingly missing documentation for gethash!
* * hash.c (hash_update): New function.Kaz Kylheku2014-01-241-0/+1
| | | | | | | | | | | | * hash.h (hash_update): Declared. * lib.c (update): New function. * lib.h (update): Declared. * eval.c (eval_init): Register hash_update and update as intrinsics. * txr.1: Documented.
* * hash.c (group_by): New function.Kaz Kylheku2014-01-161-0/+1
| | | | | | | | * hash.h (group_by): Declared. * eval.c (eval_init): group_by registered as group-by intrinsic. * txr.1: Documented.
* Bumping copyrights to 2014 and expressing them as year ranges.Kaz Kylheku2013-12-101-1/+1
| | | | Fixing some errors in copyright comments.
* * eval.c (eval_init): New intrinsics: make-similar-hash, copy-hash,Kaz Kylheku2012-09-121-0/+5
| | | | | | | | | | | | | | hash-uni, hash-diff, hash-isec. * hash.c (make_similar_hash, copy_hash, hash_uni, hash_diff, hash_isec): New functions. * hash.h (make_similar_hash, copy_hash, hash_uni, hash_diff, hash_isec): Declared. * txr.1: Updated. * txr.vim: Highlighting for these new functions.
* Rounding out hash table functionality with lazy lists thatKaz Kylheku2012-04-071-1/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | can walk table content in different ways. * eval.c (op_dohash): Follow interface change of hash_next. (eval_init): hash-keys, hash-values, hash-pairs and hash-alist intrinsics introduced. * filter.c (trie_compress): Follow interface change of hash_next. * hash.c (hash_next): Silly interface which takes a pointer to the iterator has changed to just take the iterator. The function unambiguously returns nil when the iteration ends, so there is no need to set the iterator variable to nil. (maphash): Follows interface change of hash_next. (hash_keys_lazy, hash_values_lazy, hash_pairs_lazy, hash_alist_lazy): New static functions. (hash_keys, hash_values, hash_pairs, hash_alist): New functions. * hash.h (hash_next): Declaration updated. (hash_keys, hash_values, hash_pairs, hash_alist): Declared. * lib.c (make_half_lazy_cons): New way of constructing lazy cons, with the car field specified. It simplifies situations when the previous cons computes the car of the next one. Why hadn't I thought of this before? * lib.h (make_half_lazy_cons): Declared. * txr.1: Doc stubs for new hash functions. * txr.vim: Highlighting for new hash functions.
* Support quasiquoting over vectors also, and a bugfix for hashKaz Kylheku2012-03-141-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | quasiquoting. We cannot use the same symbol for the literal form from the parser, and for the expanded form, because this creates a confusion when there are multiple nestings of quasiquote expansion. * eval.c (vector_lit_s, vector_list_s, hash_lit_s): New symbol variables. (hash_construct_s): Relocated here from hash.c. (expand_qquote): Part of bugfix: look for hash_lit_s instead of has_construct_s. Translate to a hash_construct_s form which is no longer recognizes as a hash literal. Implementing recognition of a quasiquote vector literal, handled similarly. (eval_init): Initialize vector_lit_s, vector_list_s, hash_list_s and hash_lit_s. Use vector_list_s when registering vector_list function. * eval.h (vector_lit_s, vector_list_s, hash_lit_s, hash_constuct_s): Declared. * hash.c (hash_construct_s): Variable removed and relocated into eval.c. (hash_init): Initialization of hash_construct_s removed. * hash.h (hash_construct_s): Declaration removed. * parser.y: (vector): Action updated to generate a (vec-lit ...) form if the object contains unquotes, otherwise generate a vector object. (hash): Generate hash-lit form, not a hash-construct form.
* Allow quasi-quoting over hash table literals,Kaz Kylheku2012-03-141-0/+2
| | | | | | | | | | | | | | | | | | | | to express dynamic hash table construction * eval.c (expand_qquote): Recognize hash-construct forms: expand the hash arguments and pairs separately, then rewrite to a new hash-construct form. (eval-init): hash-construct intrinsic function added. * hash.c (hash_construct_s): New symbol variable. (hash_construct): New function. (hash_init): Initialize hash_construct_s. * hash.h (hash_construct_s, hash_construct): Declared. * parser.y (hash): Rule rewritten to emit either a literal hash table object, or a hash-construct form, based on whether quasiquote unquotes occur within the syntax. (hash_from_notation): Function removed.
* * arith.c: Updated copyright year.Kaz Kylheku2012-02-251-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * arith.h: Likewise. * debug.c: Added copyright header. * debug.h: Updated copyright year. * eval.c: Likewise. * eval.h: Likewise. * filter.c: Likewise. * filter.h: Likewise. * gc.c: Likewise. * gc.h: Likewise. * hash.c: Likewise. * hash.h: Likewise. * lib.c: Likewise. * lib.h: Likewise. * match.c: Likewise. * match.h: Likewise. * parser.h: Likewise. * regex.c: Likewise. * regex.h: Likewise. * stream.c: Likewise. * stream.h: Likewise. * txr.c: Likewise, and e-mail address. * txr.h: Updated copyright year. * unwind.c: Likewise. * unwind.h: Likewise.
* Introducing optional arguments.Kaz Kylheku2012-02-211-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * debug.c (help, show_bindings): put_string arguments reversed. * eval.c (bind_args): Support colon notation in interpreted function lambda lists for optional arguments. Improved error checking. (apply): Allow optional arguments to be left out. (dwim_loc): Reversed arguments to replace_str, replace_vec, replace_list. (eval_init): Numerous intrinsics now have arguments that are optional. New function rand introduced which reverses arguments relative to random. New intrinsic function hash introduced for alternative construction of hashes. * gc.c (sweep): Reversed arguments to put_char. * hash.c (weak_keys_k, weak_vals_k, equal_based_k): New keyword symbol variables. (hashv): New function. (hash_init): Intern new symbols. * hash.h (weak_keys_k, weak_vals_k, equal_based_k, hashv): Declared. * lib.c (colon_k): New keyword symbol variable. (replace_list, replace_str, replace_vec): Arguments rearranged. (tree_find): testfun becomes optional argument. (int_str): base becomes optional argument. (func_f0, func_f1, func_f2, func_f3, func_f4, func_n0, func_n1, func_n2, func_n3, func_n4, func_f0v, func_f1v, func_f2v, func_f3v, func_f4v, func_n0v, func_n1v, func_n2v, func_n3v, func_n4v, func_interp): Initialize optargs to zero. (func_n0o, func_n1o, func_n2o, func_n3o, func_n4o): New functions. (cobj_print_op): Reversed arguments to put_string. (find): testfun and keyfun become optional arguments. (replace): Parameters rearranged and arguments rearranged in calls to replace_list, replace_str and replace_vec. (obj_init): colon_k initialized. (obj_print, obj_pprint): Arguments reversed, and stream defaults to std_output. Arguments reversed in calls to put_char and put_string. (dump): Arguments reversed in call to put_char. * lib.h (struct func): sizes of minparam, fixparam bitfields adjusted. New bitfield optargs. New unnamed bitfield added so the previous ones add up to 16 bits. (colon_k): Declared. (func_n0o, func_n1o, func_n2o, func_n3o, func_n4o): Declared. (replace_list, replace_str, replace_vec, replace): Declarations updated. * match.c (debuglf, dump_shell_string, dump_byte_string, dump_var, do_output_line, extract): Reversed arguments to put_char and
* Critical regression. Hash lookup was crashing on some platformsKaz Kylheku2011-12-201-1/+0
| | | | | | | | | | | | | | due to negative hashing values being reduced modulo table size to a negative array index. * hash.c (equal_hash, eql_hash): Ensure that value returned is in the range [0,NUM_MAX]. (hash_obj): Unused function removed. (cobj_hash_op): Use hashing similar to eql hash for other kinds of references. (hash_eql, hash_equal): Removed bogus % NUM_MAX reduction. * hash.h (hash_obj): Declaration removed.
* * eval.c (eval_init): New functions added as intrinsics.Kaz Kylheku2011-12-101-0/+2
| | | | | | | | * hash.c (hash_eql, hash_equal): New external functions. * hash.h (hash_eql, hash_equal): Declared. * txr.1: Sections added.
* * eval.c (eval_init): hashp and maphash functions registered.Kaz Kylheku2011-11-291-0/+1
| | | | | | * hash.c (maphash): New function. * hash.h (maphash): Declared.
* Task #11436Kaz Kylheku2011-11-261-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Lisp interpreter added. * gc.c (finalize, mark_obj): Handle ENV objects. * hash.c (struct hash): acons_new_l_fun function pointer order of arguments change. (equal_hash): Handle ENV. (make_hash, gethash_l): Use cobj_handle for type safety. Follow change in acons_new_l. (gethash, gethash_f, remhash, hash_count, hash_get_userdata, hash_set_userdata, hash_next): Use cobj_handle. (gethash_n): New function. * hash.h (gethash_n): Declared. * lib.c (env_s): New symbol variable. (code2type, equal): Handle ENV. (plusv, minusv, mul, mulv, trunc, mod, gtv, ltv, gev, lev, maxv, minv, int_str): New functions. (rehome_sym): New static function. (func_f0, func_f1, func_f2, func_f3, func_f4, func_n0, func_n1, func_n2, func_n3, func_n4): Initialize new fields of struct func. (func_f0v, func_f1v, func_f2v, func_f3v, func_f4v, func_n0v, func_n1v, func_n2v, func_n3v, func_n4v, func_interp): New functions. (apply): Function removed: sanely re-implemented in new eval.c file. (funcall, funcall1, funcall2, funcall3, funcall4): Handle variadic and interpreted functions. (acons, acons_new, acons_new_l, aconsq_new, aconsq_new_l): Reordered arguments for compatibility with Common Lisp acons. (obj_init): Special hack to prepare hash_s symbol, which is needed for type checking inside the hash table funtions invoked by make_package, at a time when the symbol is not yet interned. Initialize new env_s variable. (obj_print, obj_pprint): Handle ENV. Fix confusing rendering of of function type. (init): Call new function eval_init. * lib.h (enum type): New enumeration member ENV. (struct func): functype member changed to bitfield. New bitfied members minparam and variadic. New members in f union: f0v, f1v, f2v, f3v, f4v, n0v, n1v, n2v, n3v, n4v. (struct env): New type. (union obj): New member e of type struct env. (env_s): Variable declared. (plusv, minusv, mul, mulv, trunc, mod, gtv, ltv, gev, lev, maxv, minv,
* Infrastructure for storing line number informationKaz Kylheku2011-11-121-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | outside of the code, in hash tables. * filter.c (make_trie, trie_add): Update to three-argument make_hash. * hash.c (struct hash): New members, hash_fun, assoc_fun acons_new_l_fun. (ll_hash): Renamed to equal_hash. (eql_hash): New static function. (cobj_hash_op): Follows ll_hash rename. (hash_grow): Use new function indirection to call hashing function. (make_hash): New argument to specify type of hashing. Initialize new members of struct hash. (gethash_l, gethash, remhash): Use function indirection for hashing and chain search and update. (pushhash): New function. * hash.h (make_hash): Declaration updated with new parameter. (pushhash): Declared. * lib.c (eql_f): New global variable. (eql, assq, aconsq_new, aconsq_new_l): New functions. (make_package): Updated to new three-argument make_hash. (obj_init): gc-protect and initialize new variable eql_f. * lib.h (eql, assq, aconsq_new, aconsq_new_l): Declared. * match.c (dir_tables_init): Updated to there-argument make_hash. * parser.h (form_to_ln_hash, ln_to_forms_hash): Global variables declared. * parser.l (form_to_ln_hash, ln_to_forms_hash): New global variables. (grammar): Set yylval.lineno for tokens that are classified to that type in parser.y. (parse_init): Initialize and gc-protect new global variables. * parser.y (rl): New static helper function. (%union): New member, lineno. (ALL, SOME, NONE, MAYBE, CASES, CHOOSE, GATHER, AND, OR, END, COLLECT, UNTIL, COLL, OUTPUT, REPEAT, REP, SINGLE, FIRST, LAST, EMPTY, DEFINE, TRY, CATCH, FINALLY, ERRTOK, '('): Reclassified as lineno type. In the grammar, these keywords can thus provide a stable line number from the lexer. (grammar): Numerous rules updated to add constructs to the line number hash tables via the rl helper. * dep.mk: Updated. * Makefile (depend): Use the installed, stable txr in the system path to update dependencies rather than locally built ./txr, to prevent the problem that txr is broken because out out-of-date dependencies, and thus cannot regenerate dependencies.
* * LICENSE, Makefile, configure, filter.c, filter.h, gc.c, gc.h, hash.c,Kaz Kylheku2011-10-041-1/+1
| | | | | | hash.h, lib.c, lib.h, match.c, match.h, parser.h, parser.l, parser.y, regex.c, regex.h, stream.c, stream.h, txr.1, txr.c, txr.h, unwind.c, unwind.h, utf8.c, utf8.h: Updated e-mail address.
* Trie compression. Hash table iteration.Kaz Kylheku2011-09-261-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Bugfix in typeof. * filter.c (trie_compress): New function. (trie_value_at, trie_lookup_feed_char, filter_string): Handle cons cell nodes in trie. (build_filter): Call trie_compress. * gc.c (cobj_destroy_op): Function renamed to cobj_destroy_stub_op since it doesn't do anything. (cobj_destroy_free_op): New function. * hash.c (struct hash_iter): New type. (hash_destroy): Function removed. (hash_ops): Reference to hash_destroy replaced with cobj_destroy_free_op. (hash_count, hash_iter_mark, hash_begin, hash_next): New functions. (hash_iter_ops): New static structure. * hash.h (hash_count, hash_begin, hash_next): New functions declared. * lib.c (hash_iter_s): New symbol variable. (typeof): Bugfix: TAG_LIT type tag not handled. (vecref): New function. (obj_init): Initialize hash_iter_s. * lib.h (cobj_destroy_op): Declaration renamed. (cobj_destroy_free_op, vecref): New functions declared. (hash_iter_s): New variable declared. * stream.c (string_in_ops, byte_in_ops): cobj_destroy_op renamed to cobj_destroy_stub_op.
* Filtering feature for variable substitution in output.Kaz Kylheku2011-09-251-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * filter.c, filter.h: New files. * Makefile (OBJS): filter.o added. * gc.c (mark_obj): Mark new alloc field of string objets. * hash.c (struct hash): New member, userdata. (hash_mark): Mark new userdata member of hash. (make_hash): Initialize userdata. (get_hash_userdata, set_hash_userdata, hashp): New functions. * hash.h (get_hash_userdata, set_hash_userdata, hashp): New functions declared. * lib.c (getplist, string_extend, cobjp): New functions. (string_own, string, string_utf8): Initialize new alloc field to nil. (mkstring, mkustring): Initialize new alloc field to actual size. (length_str): When length is computed and cached, also compute and cache alloc. (init): Call filter_init. * lib.h (string string): New member, alloc. (num_fast): Macro converted to inline function. (getplist, string_extend, cobjp): New functions declared. * match.c (match_line): Follows change of modifier s-exp syntax. (format_field): New parameter, filter. New modifier syntax parsed. Filter retrieved, and applied. (subst_vars): New parameter, filter. Filter is either applied in this function or passed to format_field, as needed. (eval_form): Pass nil to new parameter of subst_vars. (do_output_line): New parameter, filter. Passed down to subst_vars. (do_output): New parameter, filter. Passed down to do_output_line. (match_files): Pass nil filter to subst_vars in cat directive. Output directive refactored to parse keywords, extract the filter and pass down to do_output. * parser.y (regex): Generate (sys:regex regex syntax ...) instead of (regex syntax ...). (elem, expr): Updated w.r.t. regex syntax change. (var): Cases '{' IDENT regex '}' and '{' IDENT NUMBER '}' are removed. new syntax '{' IDENT exprs '}' to handle these more generally and allow for keywords. * txr.1: Updated.
* * LICENSE, Makefile, configure, gc.c, gc.h, hash.c, hash.h, lib.c,Kaz Kylheku2011-09-231-1/+1
| | | | | | lib.h, match.c, match.h, parser.h, parser.l, parser.y, regex.c, regex.h, stream.c, stream.h, txr.1, txr.c, txr.h, unwind.c, unwind.h, utf8.c, utf8.h: Updated copyright year.
* Bump copyrights to 2010.Kaz Kylheku2010-10-051-1/+1
|
* * hash.c (sethash): New function.Kaz Kylheku2009-12-091-0/+1
| | | | | | | | * hash.h (sethash): Declared. * lib.c (cobj_handle): New function. * lib.h (cobj_handle): Declared.
* Introducing symbol packages. Internal symbols are now inKaz Kylheku2009-11-211-1/+1
| | | | | | | | | | a system package instead of being hacked with the $ prefix. Keyword symbols are provided. In the matcher, evaluation is tightened up. Keywords, nil and t are not bindeable, and errors are thrown if attempts are made to bind them. Destructuring in dest_bind is strict in the number of items. String streams are exploited to print bindings to objects that are not strings or characters. Numerous bugfixes.
* Changing ``obj_t *'' occurences to a ``val'' typedef. (Ideally,Kaz Kylheku2009-11-201-5/+5
| | | | | we wouldn't have to declare object variables at all, so why use an obtuse syntax to do so?)
* Add hash removal.Kaz Kylheku2009-11-091-0/+1
|
* Add hash table growth.Kaz Kylheku2009-11-091-1/+1
|
* First cut at hash tables. One known problem is allocation during gc,Kaz Kylheku2009-11-091-0/+33
due to use of boxed numbers for vector access.