summaryrefslogtreecommitdiffstats
path: root/lib.c
Commit message (Collapse)AuthorAgeFilesLines
* * unwind.c (unhandled_hook_s): New static variable.Kaz Kylheku2015-02-061-0/+1
| | | | | | | | | | | | | | | | | | | (uw_throw): In the unhandled case, check if *unhandled-hook* variable has a function, and use it instead of the default logic. If it's not a function, abort with an error message. Clear it so that if the hook function re-enters this code, it will not be used. Always exit now on unhandled exceptions; do not abort. (uw_late_init): New function. * unwind.h (uw_late_init): Declared. * lib.c (init): Call uw_late_init. * txr.1: Documented *unhandled-hook*. * genvim.txr: Scan the unwind.c file, since it has a reg_var now. * tl.vim, txr.vim: Updated.
* 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.
* * lib.c (make_like): Fix regression introduced in 102.Kaz Kylheku2015-01-271-1/+1
| | | | | A one element list being converted to a string treated as an empty list, leading to empty string.
* * eval.c (eval_init): Register dupl and swap_12_21 asKaz Kylheku2015-01-251-0/+10
| | | | | | | | | | | the dup and flip intrinsics. * lib.c (do_dup): New static function. (dupl): New function. * lib.h (dupl): Declared. * txr.1: Documented dup and flip.
* * lib.c (make_like): Bugfix. (make-like nil "abc")Kaz Kylheku2015-01-111-0/+4
| | | | | | | | | | must return the empty string, not nil. Only lists of non-characters fail to convert to a string. Since programs may depend on the hitherto wrong, undocumented behavior, this is made subject to compatibility. * txr.1: Added compatibility note.
* * lib.c (replace_str, replace_vec): Bugfix. The replacement itemKaz Kylheku2014-12-311-87/+91
| | | | | | sequence may be an infinite list in the case that the from argument specifies a list of indices. We must avoid trying to calculate its length before we have detected this case.
* * lib.c (simple_lazy_stream_func): Bugfix: close the streamKaz Kylheku2014-12-251-2/+4
| | | | | | | | | | if get_line returns nil. * stream.c (cat_get_line, cat_get_char, cat_get_byte): The catenated stream read operations close an exhausted stream before popping to the next one. * txr.1: Document closing behavior of catenated streams.
* * eval.c (eval_init): Registered intrinsic function unique.Kaz Kylheku2014-12-231-4/+11
| | | | | | | | | | | * lib.c (unique): New function. (uniq): Becomes wrapper around unique. * lib.h (unique): Declared. * txr.1: Documented unique, and equivalence between uniq and unique. * tl.vim, txr.vim: Regenerated.
* * lib.c (func_n1ov, func_n2ov, func_n3ov): New functions.Kaz Kylheku2014-12-231-0/+21
| | | | * lib.h (func_n1ov, func_n2ov, func_n3ov): Declared.
* * lib.c (func_n0o): Useless, unused function removed.Kaz Kylheku2014-12-231-7/+0
| | | | * lib.h (func_n0o): Declaration removed.
* * lib.c (copy): Support copying random state objectsKaz Kylheku2014-12-181-1/+4
| | | | | | vi make_random_state. * txr.1: Updated.
* * eval.c (eval_init): Register in function as intrinsic.Kaz Kylheku2014-12-051-0/+70
| | | | | | | | | | * lib.c (in): New function. * lib.h (in): Declared. * txr.1: Documented in. * txr.vim, tl.vim: Regenerated.
* * lib.c (set_diff): Bugfix: use member rather than find,Kaz Kylheku2014-12-051-1/+1
| | | | so that a nil set element is handled properly.
* * eval.c (eval_init): Register lequal and gequal.Kaz Kylheku2014-11-271-0/+41
| | | | | | | | | | * lib.c (lequal, gequal, lequalv, gequalv): New functions. * lib.h (lequal, gequal, lequalv, gequalv): Declared. * txr.1: Documented lequal and gequal. * txr.vim, tl.vim: Regenerated.
* * eval.c (eval_init): Register less and greater toKaz Kylheku2014-11-271-0/+28
| | | | | | | | | | the lessv and greaterv functions instead of less and greater. * lib.c (lessv, greaterv): New functions. * lib.h (lessv, greaterv): Declared. * txr.1: Document variadic nature of less and greater.
* * eval.c (eval_init): Register sort-group.Kaz Kylheku2014-11-211-1/+9
| | | | | | | | * lib.c (sort_group): New function. * lib.h (sort_group): Declared. * txr.1: Documented.
* * lib.c (partition_star_func): Bugfix: doing rplaca(env, seq)Kaz Kylheku2014-11-211-8/+7
| | | | | | too early, before the loop which adjusts its value. Restructuring this slightly to avoid duplicated code, by moving the !first check later.
* * lib.c (partition_by_func): Rename one local variable for clarity.Kaz Kylheku2014-11-211-9/+8
| | | | | Remove unessential variable last, and move the next variable into loop scope.
* * lib.c (where): Argument order reversed, with compat support.Kaz Kylheku2014-11-201-1/+7
| | | | | | * lib.h (where): Declaration updated. * txr.1: Documented.
* * lib.c (sel): Accept a function in place of the index list.Kaz Kylheku2014-11-201-1/+3
| | | | * txr.1: Documented.
* * lib.c (split_str): If the separator string is empty,Kaz Kylheku2014-11-171-1/+24
| | | | | | | | | | then unless opt_compat is 100 or less, provide a more consistent behavior, rather than splitting the string into characters. This latter behavior was never documented. * txr.1: Documented. * dep.mk: Updated.
* * lib.c (max2, min2): Use the less comparison functionKaz Kylheku2014-11-151-4/+4
| | | | | | | | | for generic semantics. * lib.h (max2, min2): Parameter names changed to avoid suggesting that the operands are numbers. * txr.1: Documentation for min and max updated.
* * lib.c (sub, ref, refset, replace, update, search_list):Kaz Kylheku2014-11-061-6/+6
| | | | | | Fix cut and paste problem: type_mismatch argument expression referring to the C function cons rather than the intended object seq.
* * eval.c (eval_init): Register chand intrinsic.Kaz Kylheku2014-11-061-0/+23
| | | | | | | | | * lib.c (do_chand): New static function. (chandv): New function. * lib.h (chandv): Declared. * txr.1: Documented chand.
* Allow then-func to be omitted in iff. Cleanup.Kaz Kylheku2014-11-061-1/+2
| | | | | | | | | * eval.c (eval_init): Register iff as requiring only one arg. * lib.c (do_iff): Do not check thenfun for nil. Just call it. (iff): Default thenfun to identity. * txr.1: Documentation updated.
* * lib.c (iff): Bugfix: forgotten handling of defaultKaz Kylheku2014-11-051-0/+1
| | | | | | | | argument, resulting in : symbol being called as a function. * txr.1: Removing description of situation when the then-function argument of iff or iffi is specified as nil. This is deprecated behavior which can be obtained by using the false function.
* * lib.c (chk_grow_vec): New function.Kaz Kylheku2014-10-301-9/+27
| | | | | | | | | (string_extend): Use chk_grow_vec. (vec_set_length): Avoid subtractions for comparing numbers. * lib.h (chk_grow_vec): Declared. * stream.c (snarf_line, string_out_put_string): Use chk_grow_vec.
* * lib.c (type_check): Function moved to header file inline.Kaz Kylheku2014-10-261-4/+2
| | | | | | | (throw_mismatch): New function. * lib.h (throw_mismatch): Declared. (type_mismatch): Declaration turned into inline function.
* * Makefile: Removing trailing spaces.Kaz Kylheku2014-10-241-15/+15
| | | | | | | | | | (GREP_CHECK): New macro. (enforce): Rewritten using GREP_CHECK, with new checks. * arith.c, combi.c, debug.c, eval.c, filter.c, gc.c, hash.c, lib.c, * lib.h, match.c, parser.l, parser.y, rand.c, regex.c, signal.c, * signal.h, stream.c, syslog.c, txr.c, unwind.c, utf8.c: Remove trailing spaces.
* * eval.c (eval_init): Register notf intrinsic function.Kaz Kylheku2014-10-211-0/+10
| | | | | | | | | | | | | | * lib.c (do_not): New static function. (notf): New function. * lib.h (notf): Declared. * txr.1: Documented notf. * share/txr/stdlib/txr-case.txr (bindable): Eliminated. (txr-if): Use functional expression, taking advantage of notf. * txr.vim: Regenerated.
* Converting cast expressions to macros that are retargettedKaz Kylheku2014-10-171-36/+36
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | to C++ style casts when compiling as C++. * lib.h (strip_qual, convert, coerce): New casting macros. (TAG_MASK, tag, type, wli_noex, auto_str, static_str, litptr, num_fast, chr, lit_noex, nil, nao): Use cast macros. * arith.c (mul, isqrt_fixnum, bit): Use cast macros. * configure (INT_PTR_MAX): Define using cast macro. * debug.c (debug_init): Use cast macro. * eval.c (do_eval, expand_macro, reg_op, reg_mac, eval_init): Use cast macros. * filter.c (filter_init): Use cast macro. * gc.c (more, mark_obj, in_heap, mark, sweep_one, unmark): Use cast macros. * hash.c (hash_double, equal_hash, eql_hash, hash_equal_op, hash_hash_op, hash_print_op, hash_mark, make_hash, make_similar_hash, copy_hash, gethash_c, gethash, gethash_f, gethash_n, remhash, hash_count, get_hash_userdata, set_hash_userdata, hash_iter_destroy, hash_iter_mark, hash_begin, hash_uni, hash_diff, hash_isec): Use cast macros. * lib.c (code2type, chk_malloc, chk_malloc_gc_more, chk_calloc, chk_realloc, chk_strdup, num, c_num, string, mkstring, mkustring, upcase_str, downcase_str, string_extend, sub_str, cat_str, trim_str, c_chr, vector, vec_set_length, copy_vec, sub_vec, cat_vec, cobj_print_op, obj_init): Likewise. * match.c (do_match_line, hv_trampoline, match_files, dir_tables_init): Likewise. * parser.l (grammar): Likewise. * parser.y (parse): Likewise. * rand.c (make_state, make_random_state, random_fixnum, random): Likewise. * regex.c (CHAR_SET_L2_LO, CHAR_SET_L2_HI, CHAR_SET_L1_LO, CHAR_SET_L1_HI, CHAR_SET_L0_LO, CHAR_SET_L0_HI, L0_full, L0_fill_range, L1_full, L1_fill_range, L1_contains, L1_free, L2_full, L2_fill_range, L2_contains, L2_free, L3_fill_range, L3_contains, L3_free, char_set_create, char_set_cobj_destroy, nfa_state_accept, nfa_state_empty, nfa_state_single, nfa_state_wild, nfa_state_set,
* Purge stray occurrences of "void *" from code base.Kaz Kylheku2014-10-171-5/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * lib.c (cobj_print_op): In the format call, cast the C pointer to val, since the ~p conversion now takes a val rather than void *. (cptr_equal_op, obj_print, obj_pprint): Remove cast to void *, since obj now already has the type that ~p expects. * lib.h (struct any): Use mem_t * instead of void *. * parser.h (yyscan_t): Repeat the definition from inside the Flex-generated lex.yy.c. (yylex_init, yylex_destroy, yyget_extra, yyset_extra): Re-declare using yyscan_t typedef in place of void *. * parser.l (yyget_column, yyerrprepf): Re-declare using yyscan_t. (grammar): Use yyg in place of yyscanner in calls to yyerrprepf. * parser.y (yylex, %lex-param): Use yyscan_t instead of void *. (parse): Use yyscan_t for local variable. * signal.c (stack): Change type from void * to mem_t *. * stream.c (vformat): Conversion specifier p extracts val instead of void *. (run): Use casts that only remove const, not all the way to void *. * txr.1: Documented p conversion specifier of format. * Makefile (OBJS-y): Initialize with := to make sure it is a simple variable, and not a macro. (SRCS): New variable, listing source files. (enforce): New rule for enforcing coding conventions. Currently checks for void * occurrences.
* * arith.c (gcd): Fix semantics. If either operand isKaz Kylheku2014-10-161-0/+18
| | | | | | | | | | | | | | | | zero, return the other operand. (lcm): New function. * eval.c (eval_init): Retarget registration of gcd to variable argument gcdv function. Register lcm. * lib.c (gcdv, lcmv): New functions. * lib.h (gcdv, lcm, lcmv): Declared. * txr.1: Re-document gcd with coverage of lcm. * txr.vim: Regenerated.
* * eval.c (eval_init): Register greater function as intrinsic.Kaz Kylheku2014-10-131-10/+14
| | | | | | | | | | | | | | | | | | | | * lib.c (gt_f, lt_f): Global variables removed. (greater_f): New variable. (greater): New function. (find_max, pos_max): Use greater_f as default for testfun, rather than gt_f. (find_min, pos_min): Use less_f as default for testfun, rather than lt_f. (obj_init): Remove references to gt_f and lt_f. GC-protect and initialize greater_f. * lib.h (greater_f): Declared. (gt_f, lt_f): Declarations removed. * txr.1: Documented greater, and use of less and greater in pos-min, pos-max, find-min and find-max. * txr.vim: Regenerated.
* * eval.c (merge_wrap): New static functionKaz Kylheku2014-10-121-2/+129
| | | | | | | | | | | | | | | | | | | | | | | | | | (eval_init): Register less as intrinsic. Retarget merge intrinsic to merge_wrap for proper argument defaulting which is missing from merge, and which we don't want to introduce there since internal calls to merge don't erquire it. Change registration of sort so it has only one required argument, not two. * lib.c (less_f): New global variable. (less_tab): New static array. (less_tab_init): New static function. (less): New function. (sort): Default lessfun argument to the less function. (obj_init): GC-protect the less_f variable. Initialize it with a function object made from the less function. (init): Call less_tab_init. * lib.h (enum type): New enumeration member MAX_TYPE, an alias for the largest type. (less_f, less): Declared. * txr.1: Documented new less function, and that the lessfun argument in sort and merge is optional, defaulting to less. * txr.vim: Regenerated.
* * eval.c (eval_init): Register chr_isblank and chr_isunisp asKaz Kylheku2014-10-111-0/+10
| | | | | | | | | | | | | | | | intrinsics. * lib.c (chr_isblank, chr_isunisp): New functions. * lib.h (chr_isblank, chr_isunisp): Declared. * regex.h (spaces): Declaration for existing variable added. * txr.1: Documented chr-isblank and chr-isunisp. * genvim.txr: Add missing sysif.c. * txr.vim: Regenerated.
* Moving system interface functions to separate module out ofKaz Kylheku2014-10-081-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | the eval and stream modules. * Makefile (OBJS): Add sysif.o. * dep.mk: Regenerated. * eval.c (errno_wrap, daemon_wrap, exit_wrap, usleep_wrap, getpid_wrap, getppid_wrap, env_hash): Functions moved to sysif.c and changed to static functions. (eval_init): Registrations of functions moved to sysif.c. * lib.c (init): Call sysif_init. * stream.c (w_stat, statf, mkdir_wrap, chdir_wrap, getcwd_wrap, makedev_wrap, minor_wrap, major_wrap, mknod_wrap): Functions moved to sysif.c and become static functions. (stream_init): Registration of stat moved to sysif.c. (open_files, open_files_star): Bugfix: no longer erroneously included in #ifdef HAVE_UNISTD_H block. * stream.h (mkdir_wrap, chdir_wrap, getcwd_wrap, makedev_wrap, minor_wrap, major_wrap, mknod_wrap, symlink_wrap, link_wrap, readlink_wrap): Declarations removed. * sysif.c: New file. * sysif.h: New file.
* Fix 2011-12-03 regression. The freeform directive codeKaz Kylheku2014-10-081-0/+3
| | | | | | | | | | | | | | | | | | | relies on lazy_str_get_trailing_list and the behavior of that function changed because (split-str "" any-separator) changed from returning nil to returning the empty string. The resulting behavior change of lazy_str_get_trailing_list was later described in the documentation, thereby codifying it. This patch changes the lazy_str_get_trailing_list behavior, which is poor, and causes infinite looping. We do not want an extra empty string prepended, because it looks like a spurious line. * lib.c (lazy_str_get_trailing_list): if split_str produces a the list (""), then just return the unmaterialized list from the lazy string without prepending that one-element list to it. * txr.1: Updated documentation for lazy-str-get-trailing-list.
* Using unified COBJ representation for both regex kinds,Kaz Kylheku2014-10-021-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | rather than the list-based notation for derivative-based regexes, and an encapsulated COBJ for NFA-based regexes. * lib.c (compiled_regex_s): Variable removed. (obj_init): Initialization of compiled_regex_s removed. * lib.h (compiled_regex_s): Declaration removed. * regex.c (struct regex, regex_t): New type. (regex_destroy): Object is now a regex_t, not nfa_t. (regex_mark): New function. (regex_obj_ops): Register regex_mark operation. (reg_nullable, reg_derivative): Remove cases that handles compiled_regex_s. (regex_compile): Output of dv_compile_regex becomes a cobj nwo. Output of nfa_compile_regex must be embedded in regex_t structure. (regexp): Drop the check for compiles_regex_s. (regex_nfa): Function removed. (regex_run, regex_machine_init): Use cobj_handle to retrieve regex_t * pointer and dispatch appropriate code based on regex->kind.
* * lib.c (do_and): Fix andf again: (andf) not producingKaz Kylheku2014-09-261-1/+1
| | | | a function that returns t, as documented.
* * lib.c (do_and, do_or): Fix broken andf and orf,Kaz Kylheku2014-09-251-6/+8
| | | | | lacking the semantics of returning the last value, or the first true value, respectively.
* * lib.c (compat_fixup): void return changed to int.Kaz Kylheku2014-09-101-2/+7
| | | | | | | | | Returns minimum supported emulation. * lib.h (compat_fixup): Declaration fixed. * txr.c (compat): Replace hard-coded min version by return value of compat_fixup.
* * eval.c (eval_init): Register intrinsic partition* function.Kaz Kylheku2014-09-091-0/+77
| | | | | | | | | * lib.c (partition_star_func): New static function. (partition_star): New function. * lib.h (partition_star): Declared. * txr.1: Documented partition*.
* * eval.c (eval_init): Register intrinsic partition function.Kaz Kylheku2014-09-091-0/+55
| | | | | | | | | * lib.c (partition_func): New static function. (partition): New function. * lib.h (partition): Declared. * txr.1: Documented partition.
* * gc.c (MALLOC_DELTA_THRESH): Macro remaned to DFL_MALLOC_DELTA_THRESH.Kaz Kylheku2014-09-081-0/+1
| | | | | | | | | | | | | | | | | | | | | (opt_gc_delta): New global variable. (make_obj): Use opt_gc_delta rather than MALLOC_DELTA_THRESH. (gc_set_delta, gc_wrap): New static functions. (gc_late_init): New function. * gc.h (gc_late_init): Declared. * genvim.txr: scan gc.c also. * lib.c (init): call gc_late_init. * txr.1: Document new --gc-delta option and the functions gc and gc-set-delta. * txr.c (help): Help text for --gc-delta. (txr_main): Parse --gc-delta option. * txr.h (opt_gc_delta): Declared.
* * lib.c (symbol_setname): New static function.Kaz Kylheku2014-09-031-7/+26
| | | | | | | | | | | | | | (obj_init): Change exception symbol names with underscores to use friendly dashes instead. (compat_fixup): New function. * lib.h (compat_fixup): Declared. * txr.1: Change occurrences of exception symbols from underscores to dashes. * txr.c (txr_main): Call compat_fixup when -C option is processed.
* * eval.c (eval_init): Update registration of lisp-parse and readKaz Kylheku2014-09-021-1/+2
| | | | | | | | | | | | | | | | | | | | to account for new parameter. * lib.c (syntax_error_s): New symbol_variable. (obj_init): New symbol variable initialized. * lib.h (syntax_error_s): Declared. * parser.h (lisp_parse): Declaration updated. * parser.l (lisp_parse): Takes third parameter. * txr.1: Third parameter of read described. * txr.c (txr_main): Pass colon_k to third parameter of lisp_parse to obtain exception throwing behavior. * unwind.c (uw_init): Register syntax-error as subtype of error.
* * arith.c (arith_init): Register some variables: *flo-dig*,Kaz Kylheku2014-09-011-1/+1
| | | | | | | | | | | | *flo-min*, *flo-max*, *flo-epsilon*, *pi* and *e*. * genvim.txr: Include arith.c in scan for symbols. * lib.c (init): arith_init() must now be called after eval_init(). * txr.1: Documented new variables.. * txr.vim: Updated.
* GC correctness fixes: make sure we pin down objects for which we borrowKaz Kylheku2014-08-251-2/+9
| | | | | | | | | | | | | | | low level C pointers, while we execute code that can cons memory. * lib.c (list_str): Protect the str argument. (int_str): Likewise. * regex.c (search_regex): protect the haystack string, while using the h pointer to its data, since regex_run can use the derivative-based engine which conses. * stream.c (vformat_str): Protect str argument, since put_char might conceivably cons. (vformat): Protect fmtstr.
* * eval.c (eval_init): Register uniq function.Kaz Kylheku2014-07-291-0/+33
| | | | | | | | * lib.c (uniq): New function. * lib.h (uniq): Declared. * txr.1: Documented uniq.