summaryrefslogtreecommitdiffstats
path: root/lib.c
Commit message (Collapse)AuthorAgeFilesLines
* * lib.c (vec_set_length): Use set instead of assignment.Kaz Kylheku2012-04-021-3/+5
| | | | | | | | (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-22/+22
| | | | | | | | | | | | | | | | | | | | | | | | | 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.
* * lib.c (num_str): Much more accurate test for deciding whetherKaz Kylheku2012-03-301-3/+6
| | | | | | | | | to treat the number as floating or integer. We can't just look for the presence of E, e or . because these coudl be part of trailing junk for instance "123XYZE." should convert to the integer 123, where "XYZE." is trailing junk. * txr.1: Documented int-str, flo-str and num-str.
* * lib.c (min2, max2): Semantics tweak. If the numbers are equal,Kaz Kylheku2012-03-291-2/+2
| | | | | | favor the left one. * txr.1: Documented min and max.
* * arith.c (numeq): New function.Kaz Kylheku2012-03-291-0/+14
| | | | | | | | | | | | | | | | | (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 =
* * lib.c (obj_print, obj_pprint): Do not use the #<lazy-string ..>Kaz Kylheku2012-03-281-2/+10
| | | | notation for lazy strings that have been forced.
* * eval.c (eval_init): New intrinsic num-str registered.Kaz Kylheku2012-03-261-0/+8
| | | | | | | | | | | | | | | * 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.
* * arith.c (to_float): Fix unterminated argument list in throwf.Kaz Kylheku2012-03-261-1/+1
| | | | * lib.c (funcall): Likewise.
* * lib.c (rebind_s): New symbol variable.Kaz Kylheku2012-03-241-1/+2
| | | | | | | | | | * 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.
* * eval.c (eval_init): Register match-str and match-str-treeKaz Kylheku2012-03-241-0/+6
| | | | | | | | | | intrinsics. * lib.c (match_str, match_str_tree): Default position to zero. * txr.1: Doc stubs created. * txr.vim: Highlighting for match-str and match-str-tree.
* * lib.c (search_str): If start_num is nil, default it to zero.Kaz Kylheku2012-03-241-0/+4
| | | | This is needed for this to work right as an optional argument.
* * arith.c (plus): Optimization: use num_fast whenKaz Kylheku2012-03-201-0/+6
| | | | | | | | | | | | | | | | 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/+54
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-80/+54
| | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* * lib.c (do_chain): More useful behavior. The firstKaz Kylheku2012-03-161-3/+10
| | | | | | function, if any, is treated as variadic. Subsequent functions are monadic. (chain, chainv): Turn do_chain into variadic.
* * eval.c (eval_init): New intrinsic functionsKaz Kylheku2012-03-161-6/+36
| | | | | | | | | | | | | | | | | | 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.
* * lib.c (quicksort): Bugfix: incorrect loop from 0 rather than fromKaz Kylheku2012-03-161-1/+1
| | | | leading to unbounded recursion.
* * lib.c (split_str): Separator can be a regex now.Kaz Kylheku2012-03-041-23/+46
|
* * lib.c (sub_str): Removed second check for lazy string thatKaz Kylheku2012-03-031-2/+1
| | | | | | | | | | | | | | | | can't ever come out true. * match.c (search_form, h_var, h_coll, h_parallel, h_fun): Handle position t emanating from match_line, indicating match to end of line. (h_skip): When skipping to the end of line (empty spec), just return t as the position rather than the end of the line. This avoids calculating the length of the line, which forces a lazy string. (do_match_line): Near the beginning of the loop, if the position is t, then substitute the length of the line. (freeform_prepare): Return the freeform line limit value. (v_freeform): Check for t coming out of match line and do the conversion back to the trailing list in that case, but only if the freeform was limited by number of lines.
* Fixing two instances of unintentional O(n*n) behavior and poor memory useKaz Kylheku2012-03-011-0/+35
| | | | | | | | | | | | | 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.
* * lib.c (numberp): Fix bad type check: null pointer dereference whenKaz Kylheku2012-02-281-0/+2
| | | | | | | | | | object is nil. * match.c (do_match_line): Bugfix for incorrect treatment of long lines. Must return the absolute position from the start of the original line (plus(c->pos, c->base)), rather than just c->pos, which only measures from the start of a line that may have been chopped by consume_prefix.
* * debug.c: Missing d command implemented.Kaz Kylheku2012-02-281-0/+45
| | | | | | | | | | 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.
* * lib.c (sub_list, replace_list, lazy_sub_str, sub_str, replace_str,Kaz Kylheku2012-02-281-7/+7
| | | | | sub_vec, replace_vec): Regression: replace incorrect zerop(to) test with to == zero, because to is not necessarily a number.
* * 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.
* * lib.c (sub_list, replace_list, lazy_sub_str, sub_str,Kaz Kylheku2012-02-221-6/+27
| | | | | | | | | replace_str, sub_vec, replace_vec): Implementing floating zero behavior. This is necessary so that the important case index .. (+ index 1) for selecting one element as a subrange works even if index is negative. * txr.1: Floating zero behavior for ranges documented.
* * eval.c (dwim_loc): del operator's return value is theKaz Kylheku2012-02-221-2/+2
| | | | | | | | deleted range of values. Missing del cases added for single index cases. * lib.c (quicksort): Fix pivot selection one more time. (length): Fix bad argument in "not a sequence" error.
* * lib.c (quicksort): Incorrect pivot selection.Kaz Kylheku2012-02-221-1/+1
|
* * lib.c (init): Hash bugfix: added missing call to hash_init.Kaz Kylheku2012-02-221-0/+1
| | | | | Previously this function did nothing, but now it interns some important symbols.
* * eval.c (eval_init): Intrinsic bindings for sub, ref, refsetKaz Kylheku2012-02-221-5/+69
| | | | | | | | | | | | | | | | 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-94/+161
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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-1/+56
| | | | | | | | | | * 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.
* * lib.c (lazy_flatten): Bugfix: function was assuming thatKaz Kylheku2012-02-121-7/+11
| | | | | | the input is a list, and not handling the case atom -> (atom) like its non-lazy counterpart. This broke @(next :list expr).
* * lib.c (obj_print): Print control characters in string andKaz Kylheku2012-02-121-9/+14
| | | | | | | | | | | | | | | | | character literals as hex escapes, followed by semicolon if necessary. Don't use iswprint function since it is locale-specific and concludes that non-ASCII characters are unprintable. Changed print syntax for lazy strings. (obj_pprint): Changed print syntax for lazy strings. * parser.l: Bugfix in hex/octal character constant. num_esc(yytext) was called rather than num_esc(yytext+1). * parser.y (chrlit): Bugfix: missing case for hex and octal constants which are given by a LITCHAR token. * stream.c (vformat): Bugfix: strings were being printed as if using ~a even under ~s.
* * lib.c (lazy_sub_str): New static function.Kaz Kylheku2012-02-091-8/+70
| | | | | | | (sub_str): Bugfix: handle t values of from from and to, and negative indices, just like sub_vec. Special handling for lazy strings introduced. If to is the value t, then the a lazy string can be produced.
* * eval.c (rest_s, op_s): New variables.Kaz Kylheku2012-02-031-3/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | (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.
* * hash.c (hash_begin): Missing type check added, otherwiseKaz Kylheku2012-01-271-3/+2
| | | | | | | | passing in an object that is not a hash results in corruption or crashing behavior. * lib.c (class_check): Improved to a one-step check with a clear message.
* * eval.c (op_modplace): Fix warning caught by gcc, but not g++.txr-55Kaz Kylheku2012-01-261-2/+2
| | | | * lib.c (replace_list): Fix code that is valid C++ but not C.
* * lib.c (replace_list): Always convert the input items to a list,Kaz Kylheku2012-01-261-13/+33
| | | | | | | | | | | even in the trivial case that an empty list is being replaced. Allow a string to be the replacement (split into a list of characters). (replace_str): Bugfix in assignment from vector; wrong index used over source vector. (split_str): If the splitting set is empty, just split the string into characters instead of getting into an infinite loop. (replace_vec): Allow replacement source to be a string.
* * arith.c (plus, minus): Better wording in error messages.Kaz Kylheku2012-01-261-1/+74
| | | | | | | | | | | | | | | | | | * 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.
* * lib.c (listref, listref_l): Negative indices must have semanticsKaz Kylheku2012-01-261-1/+4
| | | | consistent with vecref and ranges.
* * lib.c (cat_str): Throw error if one of the list elementsKaz Kylheku2012-01-261-1/+2
| | | | is not a character or string instead of silently returning nil.
* * eval.c (dwim_loc, dwim_op): Eliminated redundant re-evaluationKaz Kylheku2012-01-261-0/+37
| | | | | | | | | | | | | | | | | 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.
* * arith.c (zerop): Misspelling in error message.Kaz Kylheku2012-01-251-15/+27
| | | | | | | * lib.c (sub_list, replace_list, sub_vec, replace_vec): Allow the value t to specify one element past the end, so that t t refers to zero-length sequence just past the end of the array or list. Also, fixed out of bounds memmoves in replace_vec.
* * eval.c (eval_init): New functions registered.Kaz Kylheku2012-01-251-4/+163
| | | | | | | | | | | | | | | | | | * 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 (dwim_s): New symbol variable.Kaz Kylheku2012-01-251-22/+56
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (dwim_loc, op_dwim): New static functions. (op_modplace): Support assignment to dwim forms with the help of dwim_loc. (expand_place): Handle dwim places. (eval_init): Initialize dwim_s. Register dwim operator in op_table. * eval.h (dwim_s): Declared. * lib.c (chr_str, chr_str_set): Allow negative indices to index backwards from end of string. (vecref, vecref_l): Allow negative indices to index from rear of array. (obj_print, obj_pprint): Render (dwim ...) forms as [...]. * parser.l: Peoduce new METABKT token type for @[, and '[', ']' tokens. * parser.y (METABKT): New token. %type declaration for '['. (list): Support square-bracket style of list, translated into dwim form. (meta_expr): Support @[...] variant. (yybadtoken): Handle METABKT in switch. * txr.1: Documented [...] syntax and dwim operator. * txr.vim: Updated.
* * lib.c (car_l, cdr_l): Bugfix: do not call the lazy consKaz Kylheku2012-01-191-2/+8
| | | | force function if it is already nil, and set it to nil afterward.
* * eval.c (eval_init): list_str registered.Kaz Kylheku2012-01-111-0/+9
| | | | | | | | | | * 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-2/+60
| | | | | | | | | | | | | | | | | | | | | | | | * 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/+12
| | | | | | | | * 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/+56
| | | | | | | | | | | | | * 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.