summaryrefslogtreecommitdiffstats
path: root/lib.h
Commit message (Collapse)AuthorAgeFilesLines
* * arith.c (bignum): Previously static function now exposed as external.Kaz Kylheku2012-04-081-1/+3
| | | | | | | | | | | | | | | | | | | | * arith.h (bignum): Declared. * configure: Added check for tm_gmtoff and tm_tmzone fields being present in struct tm. * eval.c (eval_init): New intrinsic functions: time, time-usec. * lib.c (num): If the cnum is outside of the fixnum range, then construct a bignum. (time_sec, time_sec_usec): New functions. * lib.h (mut): Slight change to macro to eliminate compiler warning. (time_sec, time_sec_usec): Declared. * txr.1: Stub section for time and time-usec. * txr.vim: Highlighting for time and time-usec.
* Rounding out hash table functionality with lazy lists thatKaz Kylheku2012-04-071-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Code cleanup and tweaking.Kaz Kylheku2012-04-051-0/+1
| | | | | | | | | | | | | | | | | | | | | | | * gc.c (BACKPTR_VEC_SIZE): Preprocessor symbol renamed to CHECKOBJ_VEC_SIZE. (FULL_GC_INTERVAL): Increased to 40 since the modified algorithm now leaves less work for the full gc to do. (backptr, backptr_idx): Static variables renamed to checkobj and checkobj_idx. (mark): Follows rename of backptr and backptr_idx. (gc): Commented out handy printf added. (gc_set): Use in_malloc_range check to avoid adding to the check array pointers which are being stored in non-heap locations, since non-heap locations are already GC roots. (gc_mutated): Follows variable renaming. (gc_push): Just do the push using gc_set. * lib.c (malloc_low_bound, malloc_high_bound): New variables. (chk_malloc, chk_calloc, chk_realloc): Updated malloc_low_bound and malloc_high_bound. (in_malloc_range): New function. * lib.h (in_malloc_range): Declared.
* Bunch of fixes.Kaz Kylheku2012-04-051-1/+1
| | | | | | | | | | | | | | | | | * gc.c (gc_mutated): Return the value. * gc.h (gc_mutated): Declaration updated. * hash.c (remhash): Fix unsafe assignment to use set macro. * lib.c (sort): Fix wrong use of mut macro on the list before it is sorted rather than after. * lib.h (mut): Trivial version of macro updated to return argument. * unwind.c (uw_init): The toplevel environment's match_context should be gc_protected. Though this is probably not used, which is why it has not been a problem.
* Generational GC showing signs of working. One test case inKaz Kylheku2012-04-031-4/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | test suite fails. * gc.c (FRESHQ_SIZE): New preprocessor symbol. (backptr_oflow, freshq, freshq_head, freshq_tail): New static variables. (make_obj): Place newly allocated generation 0 object into freshq. If freshq becomes full, transfer oldest item into generation 1. (mark_obj): If doing only a partial gc, then do not mark objects which are not generation 0. (mark_mem_region): Valgrind support: cannot mark t.type field undefined because it is a bitfield. Just mark the first SIZEOF_PTR bytes of the object defined. (mark): Under partial gc, mark the table of back pointers. (sweep_one): New static function from the prior guts of sweep. Reachable objects now get promoted to generation 1. (sweep): Under partial gc, sweep just the freshq which identifies the generation 0 objects, rather than the entire linked list of all the heaps. (gc): Trigger full gc also if the backptr list has overflowed due to gc having been disabled. Under generational gc, reset the static variables afterward: clear the list of backpointers, and the freshq. (gc_is_reachable): Under partial gc, report any mature object as reachable. (gc_set, gc_mutated): Handle backptr array overflow situation when gc is disabled. (gc_push): Bugfix: it is the newly pushed cons cell that has to be marked as a root, not the value being pushed. * hash.c (sethash): Use set macro for storing value. * lib.h (set, mut, mpush): Fix wrong-way #if test for these macros. The trivial versions were being defined uner CONFIG_GEN_GC and vice versa!
* * eval.c (op_modplace): push replaced with mpush (mutating push).Kaz Kylheku2012-04-031-0/+2
| | | | | | | | | | | | | | | * gc.c (gc_push): New function. * gc.h (gc_push): Declared. * hash.c (pushhash): Use mpush. * lib.c (push): Reverted to unsafe operation. TODO comment replaced with warning. (lazy_flatten_scan): push occurence commented as safe. (lazy_stream_func): Unsafe push replaced with mpush. * lib.h (mpush): New macro.
* * configure: Support a gen-gc configuration variable whichKaz Kylheku2012-04-031-18/+33
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | causes CONFIG_GEN_GC to be defined as 1 in config.h. * eval.c (op_defvar, dwim_loc, op_modplace, transform_op): Handle mutating assignments via set macro. (op_dohash): Inform gc about mutated variables. TODO here. * filter.c (trie_add, trie_compress): Handle mutating assignments via set macro. * gc.c (BACKPTR_VEC_SIZE, FULL_GC_INTERVAL): New preprocessor symbols. (backptr, backptr_idx, partial_gc_count, full): New static variables. (make_obj): Initialize generation to zero. (gc): Added logic for deciding between full and partial gc. (gc_set, gc_mutated): New functions. * gc.h (gc_set, gc_mutated): Declared. * hash.c (hash_mark): Changed useless use of vecref_l to vecref. (gethash_f): Use set when assigning through *found since it is a possible mutation. * lib.c (car_l, cdr_l, vecref_l): Got rid of loc macro uses. Using the value properly is going to be the caller's responsibility. (push): push may be a mutation, so use set. (intern): Uset set to mutate a hash entry. (acons_new_l, aconsq_new_l): Use set when replacing *list. * lib.h (PTR_BIT): New preprocessor symbol. (obj_common): New macro for defining common object fields. type_t is split into two bitfields, half a pointer wide, allowing for generation to be represented. (struct any, struct cons, struct string, struct sym, struct package, struct func, struct vec, struct lazy_cons, struct cobj, struct env, struct bignum, struct flonum): Use obj_common macro to defined common fields. (loc): Macro removed. (set, mut): Macros conditionally defined for real functionality. (list_collect, list_collect_nconc, list_collect_append): Replace mutating operations with set. * match.c (dest_set, v_cat, v_output, v_filter): Replace mutating operations with set. * stream.c (string_in_get_line, string_in_get_char, strlist_out_put_string, strlist_out_put_char): Replace mutating operations with set. * unwind.c (uw_register_subtype): Replace mutating operation with set.
* * lib.c (vec_set_length): Use set instead of assignment.Kaz Kylheku2012-04-021-0/+1
| | | | | | | | (vecref_l): Use loc to lift address of cell. (replace_vec): Use macro mut to indicate the object is being mutated. * lib.h (mut): New macro.
* Start of ground-work for ephemeral GC. We must add some abstractionKaz Kylheku2012-04-011-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | to places where we potentially assign a reference to a younger object inside a field located in an older object (chronological backreference) and also where we take the address of an object field, making it possible that the user of the address will do so. This patch does not take care of vectors. No, this is not an April Fool's joke. * eval.c (env_fbind, env_vbind, env_replace_vbind, lookup_var, lookup_sym_lisp1): Use set macro instead of assignment. * hash.c (hash_grow, set_hash_userdata, hash_next): Use set macro instead of assignment. * lib.c (rplaca, rplacd, string_extend, length_str, replace_str, rehome_sym, lazy_stream_func, lazy_str, lazy_str_force, lazy_str_force_upto, obj_init): Use set macro instead of assignment. (car_l, cdr_l): Use loc instead of address-of operator. * lib.h (set, loc): New macros.
* * arith.c (numeq): New function.Kaz Kylheku2012-03-291-0/+2
| | | | | | | | | | | | | | | | | (exptmod): Bugfix: was no normalizing the bignum, ouch. Also was reporting "non-integral operands" for other errors. * eval.c (eval_init): Registered = intrinsic function. * lib.c (numeqv): New function. * lib.h (numeq, numeqv): Declared. * txr.1: Documented expt, sqrt, isqrt, exptmod, fixnump, bignump, integerp, floatp, numberp, zerop, evenp, oddp, >, <, >=, <= and =. * txr.vim: Highlight =
* * arith.c (gcd): Allow zeros. Don't issue "non-integral"Kaz Kylheku2012-03-291-0/+3
| | | | | | | | | | | | | | | exception if MPI fails. (floorf, ceili): Map integer argument to itself. (tang, asine, acosi): New functions. * eval.c (eval_init): New intrinsics: tan, asin, acos. * lib.h (tang, asine, acosi): Declared. * txr.1: Documented gcd, abs, floor, ceil, sin, cos, tan asin, acos, atan, log, and exp. * txr.vim: Highlighting for tang, asine, acosi.
* * eval.c (eval_init): New intrinsic num-str registered.Kaz Kylheku2012-03-261-0/+1
| | | | | | | | | | | | | | | * filter.c (tonumber_k, tointeger_k, tofloat_k, hextoint_k): New keyword variables. (filter_init): New variables initialized; new filters registered. * filter.h (tonumber_k, tointeger_k, tofloat_k, hextoint_k): Declared. * lib.c (num_str): New function. * lib.h (num_str): Declared. * txr.1: New filters documented.
* * lib.c (rebind_s): New symbol variable.Kaz Kylheku2012-03-241-1/+1
| | | | | | | | | | * lib.h (rebind_s): Declared. * match.c (v_rebind): New static function. (dir_tables_init): Registered rebind_s to v_rebind, and also to hv_trampoline in the horizontal directive table. * txr.1: Documented it.
* * arith.c (expo): New function.Kaz Kylheku2012-03-221-0/+1
| | | | | | | | | | * eval.c (eval_init): expo registered as intrinsic exp. * lib.h (expo): Declared. * txr.1: Added to stub heading. * txr.vim: Highlighting for exp.
* Fix sqrt confusion. There must be a separate isqrtKaz Kylheku2012-03-221-0/+1
| | | | | | | | | | | | | | | | | for the integer square root. * arith.c (sqroot_fixnum): Renamed back to isqrt_fixnum. (sqroot): Rewritten to handle only floating-point square root. (isqrt): New function, based on previous sqroot, handles only integers. * eval.c (eval_init): New intrinsic, isqrt. * lib.h (isqrt): New declaration. * txr.1: Doc stubs. * txr.vim: Highlighting for isqrt.
* * arith.c (floorf, ceili, sine, cosi, atang, loga): New functions.Kaz Kylheku2012-03-221-0/+6
| | | | | | | | | | | * eval.c (eval_init): New intrinsic functions registered: floor, ceil, sin, cons, atan, log. * lib.h (floorf, ceili, sine, cosi, atang, loga): Declared. * txr.1: Doc stub section for new functions. * txr.vim: Highighting added.
* * arith.c (to_float): New static function.Kaz Kylheku2012-03-221-1/+1
| | | | | | | | | | | | | (divi): Uses to_float. (zerop, gt, lt, ge, le, expt): Floating support. (isqrt_fixnum): Static function renamed to sqroot_fixnum. (isqrt): Renamed to sqroot. Floating support. (evenp, oddp, exptmod, gcd): Work with integers, not floats. * eval.c (eval_init): intrinsic registration of sqrt follows rename of isqrt to sqroot. * lib.h (isqrt): Declaration replaced.
* * arith.c (divi): New function.Kaz Kylheku2012-03-211-0/+1
| | | | | | | | | | * eval.c (eval_init): divi registered as / intrinsic. * lib.h (divi): Declared. * txr.1: divi added to stub heading. * txr.vim: / operator highlighted.
* * arith.c (flo_int): New function.Kaz Kylheku2012-03-201-0/+1
| | | | | | | | | | | * eval.c (eval_init): flo-int registered as intrinsic. * lib.h (flo_int): Declared. * mpi-patches/series: Added mpi-to-double to patch stack. (mp_to_double): New MPI function. * mpi-patches/mpi-to-double: New file.
* * arith.c (plus): Optimization: use num_fast whenKaz Kylheku2012-03-201-0/+5
| | | | | | | | | | | | | | | | result is in the fixnum range. Implemented FLNUM cases, except for adding a FLNUM to BGNUM. (minus, mul): Use num_fast when the cnum value is in the fixnum range. (int_flo): New function. * eval.c (eval_init): Register int-flo intrinsic. * lib.c (c_flo): New function. * lib.h (TYPE_SHIFT, TYPE_PAIR): New macros, carried over from the lazy strings branch. (c_flo, int_flo): Declared.
* * configure (uintptr): New variable. Indicates whether unsignedKaz Kylheku2012-03-191-2/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | version of intptr_t is available and should be generated in config.h as uintptr_t. * eval.c (eval_init): New intrinsic functions floatp, integerp, flo-str. * gc.c (finalize): Handle FLNUM case. Rearranged cases so that all trivially returning cases are together. (mark): Handle FLNUM case. * hash.c (hash_double): New function. (equal_hash): Handle FLNUM via hash_double. (eql_hash): Likewise. * lib.c: <math.h> is included. (float_s): New symbol variable. (code2type, equal): Handle FLNUM case in switch. (integerp): New function; does the same thing as integerp before. (numberp): Returns t for floats. (flo, floatp, flo_str): New functions. (obj_init): Initialize new float_s variable. (obj_print, obj_pprint): Handle FLNUM case in switch. Printing does not work yet; needs work in stream.c. * lib.h (enum type): New enumeration FLNUM. (struct flonum): New struct type. (union obj): New member, fl. (float_s, flo, floatp, integerp, flo_str): Declared. * parser.l (FLO): New token pattern definition. Scans to a NUMBER token. Corrected uses of yylval.num to yylval.val. * parser.y (%union): Removed num member from yystype.
* Changing type function to not blow up on nil, which makes a lot of codeKaz Kylheku2012-03-171-2/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | simpler. A pseudo type code is introduced called NIL with value 0. * lib.h (enum type): New enumeration value, NIL. (type): Function accepts object nil and maps it to code NIL. * eval.c (dwim_loc, op_dwim): test for nil obj and goto hack is gone, just handle NIL in the switch. * gc.c (make_obj, mark): Handle new NIL type code in switch. * hash.c (equal_hash): Handle NIL in the switch instead of nil test. * lib.c (code2type): Map new NIL type code to null. (typeof, typecheck): Code simplified. (class_check, car): Move nil test into switch. (eql, equal, consp, bignump, stringp, lazy_stringp, symbolp, functionp, vectorp, cobjp): Simplified. (length, sub, ref, refset, replace, obj_print, obj_pprint): Handle NIL in switch instead of nil test. goto hack removed from refset. * match.c (do_match_line, do_output_line): switch condition simplified. * regex.c (regexp): Simplified. (regex_nfa): Assert condition simplified.
* * eval.c (eval_init): New intrinsic functionsKaz Kylheku2012-03-161-0/+4
| | | | | | | | | | | | | | | | | | chain, andf, orf, iff. * lib.c (chainv): New function. (do_and, do_or): Generalized to handle functions of any arguments via apply. (andf, orf): Turn do_and and do_or into variadic function instead of a monadic function. (do_iff): New static function. (andv, orv, iff): New functions. * lib.h (chainv, andv, orv, iff): New functions declared. * txr.1: Doc stubs created. * txr.vim: Updated.
* Fixing two instances of unintentional O(n*n) behavior and poor memory useKaz Kylheku2012-03-011-0/+2
| | | | | | | | | | | | | that occur in horizontal matching of basic text patterns. * lib.c (match_str, match_str_tree): New functions. * lib.h (match_str, match_str_tree): Declared. * match.c (do_match_line): Use match_str_tree and match_str when matching strings and string lists, respectively, rather than stupidly calling search functions and then asserting that the match was found at the starting position.
* * debug.c: Missing d command implemented.Kaz Kylheku2012-02-281-0/+3
| | | | | | | | | | Condense the output to 8 times the screen width, for more context. Condense the output in vertical mode (when the entire input line is shown) not only character mode. * lib.c (remq, remql, remqual): New functions. * lib.h (remq, remql, remqual): Declared.
* * 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.
* * eval.c (eval_init): Intrinsic bindings for sub, ref, refsetKaz Kylheku2012-02-221-1/+2
| | | | | | | | | | | | | | | | and replace. * lib.c (do_sort): Static function renamed to sort_list. (swap, quicksort, sort_vec): New static functions. (sort): Made generic over lists, vectors and strings. (refset): New function. * lib.h (sort): Declaration updated (parameter name change). (refset): Declared. * txr.1: Mention refset. * txr.vim: Updated with refset.
* Introducing optional arguments.Kaz Kylheku2012-02-211-6/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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
* * lib.c (sub, ref, replace): New functions.Kaz Kylheku2012-02-191-0/+3
| | | | | | | | | | * lib.h (sub, ref, replace): Declared. * match.c (format_field): Generic indexing using new functions. * txr.1: Documentation stub. * txr.vim: Highlighting for new functions.
* * eval.c (rest_s, op_s): New variables.Kaz Kylheku2012-02-031-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | (do_eval_args): Allow calls specified by improper lists like (x y . z) where the z expression must evaluate to a list that turns into addition arguments to be applied. (transform_op, expand_op): New static functions. (expand): Call expand_op. (eval_init): Initialize rest_s and op_s. Use rest_s to register rest function. * lib.c (gensym): New function based on gensymv. (gensymv): Now calls gensym. * lib.h (gensym): Declared. * parser.l: Parse @ followed by digits as a new kind of token, METANUM. * parser.y (METANUM): New token. (meta_expr, exprs): Missing rlcp's added. (expr): METANUM variant introduced. (yybadtoken): Handle METANUM. * txr.1: Documented one-symbol argument list of lambda. Documented op. Closed some unbalanced parentheses. * txr.vim: Highlight op.
* * arith.c (plus, minus): Better wording in error messages.Kaz Kylheku2012-01-261-0/+1
| | | | | | | | | | | | | | | | | | * eval.c (dwim_loc): Assignments to string indices and ranges supported. New arguments for this purpose. (op_modplace): Use new dwim_loc interface for returned value. (op_dwim): Support assignment to string ranges. (eval_init): replace_str registered. * lib.c (string_extend): If the argument is a number, let it specify the amount by which to extend the string. (replace_str): New function. * lib.h (replace_str): Declared. * txr.1: Updated. * txr.vim: Updated.
* * eval.c (dwim_loc, dwim_op): Eliminated redundant re-evaluationKaz Kylheku2012-01-261-1/+5
| | | | | | | | | | | | | | | | | of range arguments. They are already evaluated since the cons expression is evaluates as part of the dwim arglist. Replaced some open code with function calls to the new listref and listref_l functions. (tostring, tostringp): made extern and moved to lib.c. * lib.c (listref, listref_l): New functions. (tostring, tostringp): moved here from eval.c. * lib.h (listref, listref_l, tostring, tostringp): Declared. * match.c (format_field): Handle index and range references. * txr.1: Documented new output variable syntax.
* * eval.c (eval_init): New functions registered.Kaz Kylheku2012-01-251-0/+4
| | | | | | | | | | | | | | | | | | * lib.c (sub_list, replace_list, vectorp): New functions. (sub_vec): Allow negative indices from end of array. (replace_vec): New function. * lib.h (sub_list, replace_list, vectorp, replace_vec): Declared. * parser.l (DOTDOT): Scan .. as new token. * parser.y (DOTDOT): New token. (expr): New syntax with DOTDOT. (yybadtoken): Handle DOTDOT. * txr.vim: Added new functions. Also missing append* and dwim. * txr.1: Updated.
* * eval.c (eval_init): list_str registered.Kaz Kylheku2012-01-111-0/+1
| | | | | | | | | | * lib.c (list_str): New function. * lib.h (list_str): Declared. * txr.1: Doc stub section created. * txr.vim: Updated.
* Spat of new features having to do with lazy processing.Kaz Kylheku2012-01-101-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | * eval.c (prog1_s, gen_s, generate_s, delay_s, promise_s): New symbol variables. (eval_prog1, op_prog1, expand_gen, expand_delay): New static functions. (expand): Handle gen and delay. (lazy_mapcar_func, lazy_mapcar, lazy_mapcarv_func, lazy_mapcarv, lazy_mappendv): New static functions. (rangev_func, rangev, generate_func, generate, repeat_infinite_func, repeat_times_func, repeatv, force): New static functions. (eval_init): New operators and functions interned. lazy-flatten renamed to flatten*. * lib.c (null_f): New global variable. (ltail, lazy_appendv): New functions. (lazy_appendv_func): New static function. (obj_init): null_f protected and initialized. * lib.h (null_f, ltail, lazy_appendv): Declared. * txr.1: Documented. * txr.vim: Updated.
* * eval.c (eval_init): New gensym function registered.Kaz Kylheku2012-01-011-0/+3
| | | | | | | | * lib.c (gensym_counter): New variable. (gensymv): New function. (obj_init): Initialize gensym_counter. * lib.h (gensym_counter, gensymv): Declared.
* * eval.c (eval_init): New function interned.Kaz Kylheku2011-12-251-0/+1
| | | | | | | | | | | | | * lib.c:x (lazy_flatten_scan, lazy_flatten_func): New static functions. (lazy_flatten): New function. * lib.h (lazy_flatten): Declared. * match.c (v_next): Use lazy_flatten instead of flatten for processing a :list source. This means that @(next :list ...) can be used to process infinite lazy lists. * txr.1: Documented lazy-flatten.
* * lib.c (memql): New function.Kaz Kylheku2011-12-231-0/+1
| | | | | | | | | | | (some_satisfy): Return the first non-nil result, rather than t. (all_satisfy): Return the value of the last item, if all items are processed. * lib.h (memql): Declared. * txr.1: Documented memq, memql, memqual, tree-find, some, all, none, eq, eql and equal.
* * eval.c (eval_init): New function registered.Kaz Kylheku2011-12-201-0/+1
| | | | | | | | * lib.c (cat_vec): New function. * lib.h (cat_vec): Declared. * txr.1: Documentation stub.
* * eval.c (eval_init): New functions registered as intrinsics.Kaz Kylheku2011-12-201-0/+2
| | | | | | | | * lib.c (copy_vec, sub_vec): New functions. * lib.h (copy_vec, sub_vec): Declared. * txr.1: Stub sections created.
* * eval.c (bindings_helper): Fix format arguments.Kaz Kylheku2011-12-181-1/+4
| | | | | | | | | | | | | | | | | (eval_init): Registered new functions: symbol-function, func-get-form, func-get-env, functionp, interp-fun-p. * lib.c (nappend2, getplist_f, improper_plist_to_alist): tail variable renamed to avoid clash in macro. (func_get_form, func_get_env, interp_fun_p): New functions. * lib.h (func_get_form, func_get_env, interp_fun_p): Declared. (list_collect): Fix macro not to throw error, but handle the case. * match.c (vars_to_bindings, extract_bindings): tail variable renamed to avoid clash in macro. * txr.1: Documentation stubs.
* * eval.c (eval_init): not added as synonym for null.Kaz Kylheku2011-12-151-11/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | * lib.c (copy_list): Use list_collect_append rather than list_collect_terminate. (append2, appendv): Simplified using new list_collect_append. (nappend2): Simplified using new list_collect_nconc. * lib.h (list_collect): Added check for accidental usage of list_collect after list_append, since PTAIL has different semantics. (list_collect_nconc, list_collect_append): Semantics fixed so that append collecting works more like the Common Lisp append function, allowing trailing atoms or a lone atom. The meaning of PTAIL is changed, however. Now PTAIL actually tracks the head of the most recently appended segment. Each append operation has to first traverse the previously added piece to get to the end. (list_collect_terminate): Macro removed. * match.c (v_gather): Removed useless use of list_collect_terminate. * parser.y: Some headers added that are needed by list_collect. * txr.1: Documented append, list, atom, null, not, consp, make-lazy-cons, lcons-fun, listp, proper-listp, length-list, mapcar, mappend, and apply.
* * eval.c (eval_init): Removed registration for vec_get_fil.Kaz Kylheku2011-12-141-4/+3
| | | | | | | | | | | | | | | | | | | | | | | | Renamed vec_set_fill to vec-set-length. * hash.c (equal_hash): vec_fill to vec_length name change. (hash_grow, make_hash): No need to call vec_set_length. * lib.c (equal, vecref, vec_push, length_vec, list_vector, obj_print, obj_pprint): vec_fill to vec_length name change. (vector): Argument now represents actual length, not just allocated size. (vec_get_fill): Function removed; did exactly the same thing as length_vec. (vec_set_fill): Function renamed to vec_set_length. (vector_list): Allocate a 0 length vector initially. * lib.h (enum vecindex): member changes name from vec_fill to vec_length. (vector): Parameter name changed. (vec_set_fill): Redeclared. (vec_get_fill): Declaration removed. * txr.1: Doc stubs updated.
* * arith.c (plus, minus, gt, lt, ge, le): Handle character operands.Kaz Kylheku2011-12-141-0/+2
| | | | | | | | | | * eval.c (eval_init): New functions interned. * lib.c (num_chr, chr_num): New functions. * lib.h (num_chr, chr_num): Declared. * txr.1: Documentation stubs.
* * arith.c (exptmod, gcd): New functions.Kaz Kylheku2011-12-131-0/+2
| | | | | | | | * eval.c (eval_init): New functions registered as intrisics. * lib.h (exptmod, gcd): Declared. * txr.1: Documentation stubs added.
* * arith.c (evenp, oddp): New functions.Kaz Kylheku2011-12-131-0/+2
| | | | | | | | * eval.c (eval_init): New functions registered as intrinsics. * lib.h (evenp, oddp): Declared. * txr.1: Documentation stub updated.
* * arith.c (highest_bit): Linkage changed to static.Kaz Kylheku2011-12-131-0/+3
| | | | | | | | | | | | | | | | | (abso, isqrt): New functions. (isqrt_fixnum): New static function. * eval.c (eval_init): Registered abs, sqrt and numberp instrinsics. * lib.c (numberp): New function. * lib.h (numberp, abso, isqrt): Declared. * mpi-patches/series: New patch added. * mpi-patches/faster-square-root: New patch added. * txr.1: Documentation stubs for new functions.
* * arith.c (expt): New function.Kaz Kylheku2011-12-121-0/+3
| | | | | | | | | | | | * eval.c (eval_init): Registering new intrinsic functions, reduce-left, reduce-right and expt. * lib.c (minusv): Return one instead of num(1). (exptv, reduce_right): New functions. * lib.h (expt, exptv, reduce_right): Declared. * txr.1: Blank sections for new functions.
* * arith.c (zerop, gt, lt, ge, le): Functions from lib.c reimplementedKaz Kylheku2011-12-111-1/+0
| | | | | | | | | | | | | | | with bignum support. * eval.c (eval_init): Added bignump and zerop as intrinsic function. Renamed numberp to fixnump. * lib.c (zerop, gt, lt, ge, le): Functions removed. (numeq): Unused function removed. * lib.h (numeq): Declaration removed. * txr.1: Sections for zerop and bignump created. Changed reference to numberp to fixnump.
* Bignum support, here we go!Kaz Kylheku2011-12-091-4/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Bignums, based on Michael Fromberger's MPI library, are integrated into the input syntax, stream output, equality testing, the garbage collector, and hashing. The plus operation handles transitions between fixnums and bignums. Other operations are still fixnum only. * Makefile (CFLAGS): Add mpi directory to include file search. (OBJS): Include new arith.o module and all of MPI_OBJS. (MPI_OBJS, MPI_OBJS_BASE): New variables. * configure (mpi_version, have_quilt, have_patch): New variables. Script detects whether patch and quilt are available. Unpacks mpi library, applies patches. Detects 128 bit integer type. Records more information in config.h about the sizes of types. * dep.mk: Updated. * depend.txr: Make work with paths that have directory components. * eval.c (eval_init): Rename of nump to fixnump. * gc.c (finalize, mark_obj): Handle BGNUM case. * hash.c: (hash_c_str): Changed to return unsigned long instead of long. (equal_hash): Handle BGNUM case. (eql_hash): Handle bignums with equal-hash, but other objects as eq. * lib.c (num_s): Variable renamed to fixnum_s. (bignum_s): New symbol variable. (code2type): Follow rename of num_s. Handle BGNUM case. (typeof): Follow rename of num_s. (eql): Handle bignums using equal, and other types using eq. (equal): Handle BGNUM case. (chk_calloc): New function. (c_num): Wording change in error message: is not a fixnum. (nump): Renamed to fixnump. (bignump): New function. (plus): Function removed, reimplemented in arith.c. (int_str): Handle integers which are too large for wcstol using bignum conversion. Base 0 is no longer passed to wcstol but converted to 10 because the special semantics for 0 would be inconsistent for bignums. (obj_init): Follow rename of num_s. Initialize bignum_s.