summaryrefslogtreecommitdiffstats
path: root/lib.c
Commit message (Collapse)AuthorAgeFilesLines
* * lib.c (intern): fix the previous diagnostic bug once more with moreKaz Kylheku2013-12-161-3/+4
| | | | | | | | | | feeling. * parser.l (grammar): Recognize package prefixes in symbol tokens. Got rid of special rule for handling lone colon. * parser.y (sym_helper): Catch undefined package as a parsing error rather allowing intern function to throw exception.
* Changing the tokenizer to get rid of IDENT, KEYWORD and METAVARKaz Kylheku2013-12-151-3/+4
| | | | | | | | | | | | | | | | | | | | | token categories, replaced by a single one called SYMTOK. Package prefixes are now recognized and processed in tokens. * lib.c (delete_package): Fix problem in no-such-package error case: it would always report nil as the name. (intern): Fix nonsensical error message: in the no-such-package case it would report that the symbol exists already. * parser.l (grammar): Occurences of KEYWORD, METAVAR, and IDENT scrubbed. All rules reporting any of these now return SYMTOK. The main one of these is greatly simplified. * parser.y (sym_helper): New function. (char_from_name): const qualifier inside param's type declaration. (grammar): IDENT, KEYWORD and METAVAR tokens are gone. New token SYMTOK. Grammar refactored around SYMTOK and using the new sym_helper function. (char_from_name): Updated.
* First cut at signal handling support.Kaz Kylheku2013-12-121-0/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Makefile (OBJS-y): Include signal.o if have_posix_sigs is "y". * configure (have_posix_sigs): New variable, set by detecting POSIX signal stuff. * dep.mk: Regenerated. * arith.c, debug.c, eval.c, filter.c, hash.c, match.c, parser.y, parser.l, rand.c, regex.c, syslog.c, txr.c, utf8.c: Include new signal.h header, now required by unwind, and the <signal.h> system header. * eval.c (exit_wrap): New function. (eval_init): New functions registered as intrinsics: exit_wrap, set_sig_handler, get_sig_handler, sig_check. * gc.c (release): Unused functions removed. * gc.h (release): Declaration removed. * lib.c (init): Call sig_init. * stream.c (set_putc, se_getc, se_fflush): New static functions. (stdio_put_char_callback, stdio_get_char_callback, stdio_put_byte, stdio_flush, stdio_get_byte): Use new functions to enable signals when blocked on I/O. (tail_strategy): Allow signals across sleep. (pipev_close): Allow signals across waitpid. (se_pclose): New static function. (pipe_close): Use new function to enable signals across pclose. * unwind.c (uw_unwind_to_exit_point): use extended_longjmp instead of longjmp. * unwind.h (struct uw_block, struct uw_catch): jb member changes from jmp_buf to extended_jmp_buf. (uw_block_begin, uw_simple_catch_begin, uw_catch_begin): Use extended_setjmp instead of setjmp. * signal.c: New file. * signal.h: New file.
* * arith.c, hash.c, lib.c, rand.c, stream.c, syslog.c: RemovingKaz Kylheku2013-12-111-1/+0
| | | | | include <assert.h> since none of these modules uses the standard C assert macro.
* Bumping copyrights to 2014 and expressing them as year ranges.Kaz Kylheku2013-12-101-1/+1
| | | | Fixing some errors in copyright comments.
* syslog support; bitwise logior and logand functions become variadic.Kaz Kylheku2013-12-101-0/+18
| | | | | | | | | | | | | | | | | | | | * Makefile: Use -iquote to restrict our #include search paths from being processed for #include <...>. Add syslog.o to OBJS-y if have_syslog is y. * configure (have_syslog): New variable, set by detecting syslog API. * eval.c (eval_init): logand and logior registrations changed to go to variadic versions. New syslog variables and functions registered. * lib.c (logandv, logiorv): New functions. * lib.h (logandv, logiorv): Declared. * txr.c (main): Call syslog_init. * syslog.c: New file. * syslog.h: New file.
* Fixing some old-style coding that became obsoleteKaz Kylheku2013-12-061-2/+2
| | | | | | | | | | | | around November 2009. * lib.c (lazy_str): Use the efficient lit("...") that doesn't allocate memory instead of string(L"..."). (lazy_str_get_trailing_list): Likewise. * stream.c (open_process): Likewise. * txr.c (remove_hash_bang_line): Likewise.
* Steps toward fixing an issue: lazy list readahead.Kaz Kylheku2013-12-011-7/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The problem is that accurate lazy lists are not suitable for real time use, where we want the TXR program to respond immediately to matching some datum. I'm implementing a simple, naive variant of lazy stream lists which simply populates the lazy cons by reading from the stream when the car or cdr fields are accessed. This type of stream can never be nil (empty list) even if the file is empty; in that case it will be (nil) and in general, it will have a spurious nil item at the end instead of ending in a string. (An adjustment was made in match.c to detect this; more will be needed.) I'm adding attributes to streams so streams can now have a "real-time" attribute. When a lazy string list is constructed over a real-time stream, the simple implementation is used. File streams are automatically real-time if (on Unix) they are tied to tty streams. Tail streams are also real-time. More work is needed to achieve the goal of this change, but this is a big step in the right direction. * configure: Detect isatty function. * lib.c (simple_lazy_stream_func): New static function. (lazy_stream_cons): Use simple implementation for real-time streams. * match.c (match_files): Do not call match_line_completely with a data line that is nil (as a result of simple lazy list over a real-time stream). A nil item in a lazy list of strings is treated as eof. * stream.c (real_time_k): New symbol variable. (struct strm_ops): New members: get_prop, set_prop. (struct stdio_handle): New member: is_real_time. (stdio_get_prop, stdio_set_prop): New static function. (stdio_ops, tail_ops, pipe_ops): stdio_get_prop and stdio_set_prop funtions wired in. (make_stdio_stream_common): Attribute streams as real-time if they are tty devices. (make_tail_stream): Tail streams are real-time attributed. (stream_set_prop, real_time_stream_p): New functions. (stream_init): Initialize real_time_k. * stream.h (real_time_k): Declared. (real_time_stream_p, stream_set_prop): Likewise.
* * eval.c (eval_init): New functions countqual, countql, countqKaz Kylheku2013-11-291-0/+51
| | | | | | | | | | and count_if registered as intrinsics. * lib.c (countqual, countql, countq, count_if): New functions. * lib.h (countqual, countql, countq, count_if): Declared. * txr.1: New functions documented.
* * configure (config_flags): New variable, allowing us toKaz Kylheku2013-11-291-4/+48
| | | | | | | | | | | | | | | | | | | have stricter diagnosis for configure tests. (have_timegm, need_svid_source, need_bsd_source): New variables. sys/stat.h test only declares static data and compiles an object file. Adding tests for timegm, tzset, setenv and unsetenv. * eval.c (eval_init): Register new intrinsic, make_time_utc. * lib.c (make_time_impl): New static function. (make_time): Reimplemented as call to make_time_impl. (timegm_hack): New conditionally-defined static function. (make_time_utc): New function. * lib.h (make_time_utc): Declared. * txr.1: make-time-utc documented.
* * lib.c (make_time): We must subtract from the 1-12Kaz Kylheku2013-11-281-1/+1
| | | | | month for the tm_mon member of struct tm; we were adding 1 instead.
* Extending intrinsic functions to go up to 7 arguments.Kaz Kylheku2013-11-281-1/+121
| | | | | | | | | | | | | | | | | | | Adding wrapper for mktime. * eval.c (apply): Handle function codes N5 through N7. (eval_init): Register make_time as intrinsic. * lib.c (auto_k): New keyword symbol variable. (equal, generic_funcall): Handle N5-N7. (func_n5, func_n6, func_n7, func_n5v, func_n6v, func_n7v): New functions. (obj_init): Initialize auto_k. (make_time): New function. * lib.h (functype_t): New enum members: N5, N6, N7. (struct func): New members: n5, n6, n7, n5v, n6v, n7v. (auto_k, func_n5, func_n6, func_n7, func_n5v, func_n6v, func_n7v, make_time): Declared.
* Ouch! Turns out the code base has numerous unintendedKaz Kylheku2013-10-241-9/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | deviations from C90, like mixed declations and statements. GCC doesn't diagnose these without the --pedantic flag. * configure: GCC's --ansi flag should be spelled -ansi. * lib.c (split_str, obj_print): Reorder declaration before statements. (make_sym): Fix similar problem by eliminating a statement. (funcall1, funcall2, funcall3, funcall4): Use assignment to initialize local array with non-constant elements. This is actually good for performance because we only initialize those parts of the array that we use. * lib.h (struct func): Change functype member to unsigned, since enum-typed bitfields are a GCC extension. * match.c (ml_all, mf_all): Use assignments to initialize local struct with non-constants. (do_txeval, v_collect): Slightly revise unwinding macrology with help of new macros to avoid mixing declarations and statements. (spec_bind): Removed spurious semicolon from macro expansion. (v_gather): Reorder two lines to avoid mixed decls and statements. (match_filter): Move declaration of ret a few lines up, ahead of statements. * unwind.c (uw_pop_until): New function. * unwind.h (uw_pop_until): Declared. (uw_mark_frame, uw_fast_return): New macros.
* Improving behavior of op and fixing a bug.Kaz Kylheku2013-10-061-1/+1
| | | | | | | | | | | | | | | | | | | | | Explicitly specifying @rest using (op ... . @rest) did not work at all. The then-func agument of iff and iffi may now be nil. * eval.c (format_op_arg): New static function. (transform_op): Handle dotted lists ending in @rest or @<num>. (supplement_op_syms): New static function. (expand_op): Add missing numeric arguments, so that all 1 through n are in the list. Trailing rest is now added under different conditions. * lib.c (do_iff): Give thenfun the same behavior on nil that elsefun enjoys. * txr.1: Updated.
* * eval.c (eval_init): tok-str acquires new parameterKaz Kylheku2013-06-111-2/+8
| | | | | | | | * lib.c (tok_str): New parameter, keep_sep. * lib.h (tok_str): Declaration updated. * txr.1: Documentation for tok-str updated.
* * eval.c (eval_init): lazy-str's third argument is optional.Kaz Kylheku2013-06-111-14/+19
| | | | | | | | | | | | | | | | | | | Added lazy-stringp. Changing names of length-str-{gt,ge,lt,le} to be consistent with the >, >=, < and <= functions. * lib.c (lazy_stream_func): Greatly simplified implementation. The lazy list now continues by means of recursing via an optimized version of lazy_stream_cons called lazy_stream_cont. The environment structure is simplified to just hold the next item, rather than a pointless list. The pointless setting of lcons->lc.func to nil is also removed; this is always done by the caller. (lazy_stream_cont): New static function, similar to lazy_stream_cons, but optimized by not consing up a new function and new environment cell. (lazy_stream_cons): The environment for the update function is simplified to just a single cons. * txr.1: Documented lazy string functions and lazy-stream-cons.
* * eval.c (eval_init): lazy string related functions become intrinsics.Kaz Kylheku2013-05-221-0/+39
| | | | | | | * lib.c (string_cmp): New function. * lib.h (TYPE_SHIFT, TYPE_PAIR): New macros. (string_cmp): Declared.
* * eval.c (eval_init): Register tok_str as intrinsic.Kaz Kylheku2013-05-201-0/+25
| | | | | | | | * lib.c (tok_str): New function. * lib.h (tok_str): Declared. * txr.1: Documented.
* * eval.c (eval_init): New intrinsics, time-string-local andKaz Kylheku2013-05-151-0/+39
| | | | | | | | | | | | | time-string-utc. * lib.c (string_time): New static function. (time_string_local, time_string_utc): New functions. * lib.h (time_string_local, time_string_utc): Declared. * txr.1: Documented. * RELNOTES: Updated.
* * RELNOTES: Updated in preparation for release.Kaz Kylheku2013-05-141-3/+31
| | | | | | | | | | | | | * eval.c (eval_init): Expose delete-package, rehome-sym and packagep. * lib.c (make_package, intern): use ~s formatting for package name in error message. (packagep, delete_package, rehome_sym): New functions. * lib.h (packagep, delete_package, rehome_sym): Declared. * txr.1: Documented process functions and packages.
* * eval.c (eval_init): New instrinsic function iffi registered.Kaz Kylheku2013-01-111-2/+9
| | | | | | | | | | * lib.c (iff): Reversed argument names corrected. No functional change. (iffi): New function. * lib.h (iffi): Declared. * txr.1: Documented iffi.
* * lib.c (int_str): Fix gaping bug introduced by previous commit,Kaz Kylheku2012-10-311-0/+3
| | | | | which could have been caught by running the regression test suite. The revised function was returning small integers as bignums.
* Merge branch 'master' of ssh://kylheku.com/git/txrKaz Kylheku2012-10-311-2/+1
|\ | | | | | | | | Conflicts: ChangeLog
| * * lib.c (string_lt): Bugfix: wcscmp returns some value less than zero,Kaz Kylheku2012-10-301-2/+1
| | | | | | | | not specifically -1.
* | * arith.c (bignum_from_long): New function.Kaz Kylheku2012-10-011-6/+11
|/ | | | | | | | | * arith.h (bignum_from_long): Declared. * lib.c (int_str): Streamlined. Only use mp_read_radix in the case when wcstol fails, because now we have bignum_from_long to handle all values of long. Ensure that the bignum is normalized, in case it falls in the fixnum range (does not happen on our usual platforms).
* Bugfix: internal funcall functions not handling functionsKaz Kylheku2012-09-241-1/+113
| | | | | | | | | with optional arguments. * lib.c (generic_funcall): New static function, based on apply from eval.c. (funcall, funcall1, funcall2, funcall3, funcall4): If the function being called has optional arguments, then go through generic_funcall.
* * eval.c (eval_init): new instrinsic function /= registered.Kaz Kylheku2012-09-111-0/+12
| | | | | | | | * lib.c (numneqv): New function. * lib.h (numneqv): Declared. * txr.1: New function documented.
* * eval.c (eval_init): Follow function renames.Kaz Kylheku2012-09-021-17/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | * hash.c (make_hash): Likewise. * lib.c (assq): Renamed to assql for consistency. (aconsq_new): Renamed to aconsql_new. (aconsq_new_l): Renamed to aconsql_new_l. (alist_remove_test): Use equal rather than eq. Association lists use equal equality by default. (alist_nremove): Use memqual rather than memq. (alist_nremove1): Use equal rather than eq. (merge): Bugfix: unnecessary consing caused by using append instead of nconc on list pieces that are already destructively chopped up. This has implications for the efficiency of sort over lists! (multi_sort_less): Implement key functions. (multi_sort): Interface change: arguments rearranged, and new argument to specify key functions. * lib.h (assoc, assq, assql, aconsq_new, aconsq_new_l): Declarations renamed. (multi_sort): Declaration updated. * txr.1: Documented alist library, list sorting and completed documenting lazy library. * txr.vim: multi-sort highlighted.
* * lib.c (multi_sort_less): Fixing semantics of return value. IndividualKaz Kylheku2012-08-291-2/+4
| | | | sorted lists are returned, rather than a list of zipped tuples.
* * lib.c (multi_sort_less): Change the semantics so that when theKaz Kylheku2012-08-291-5/+5
| | | | | list of the functions is empty, the left item is considered less than the right, thereby preserving the order.
* * eval.c (mapcarv): Changed to external linkage.Kaz Kylheku2012-08-291-0/+31
| | | | | | | | | | | | * eval.h (mapcarv): Declaration added. (eval_init): New intrinsic multi-sort registered. * lib.c (multi_sort_less): New static function. (multi_sort): New function. * lib.h (multi_sort): Declared. * txr.1: stub section added.
* First cut at implementing \s, \d, \w, \S, \D and \W regex tokens.Kaz Kylheku2012-04-191-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * lib.c (init): Call regex_init. * parser.l: return new REGTOKEN kind. * parser.y (REGTOKEN): New token type. (REGTERM): Translate REGTERM to keyword. (regclass): Restructured to handle inherited nodes as lists. (regclassterm): Produce $$ as list. Add handling for REGTOKEN occurring inside character class by expanding it. This might not be the best approach. (yybadtoken): Handle REGTOKEN in switch. * regex.c (struct any_char_set, struct small_char_set, struct displaced_char_set, struct large_char_set, struct xlarge_char_set): New bitfield member, stat. (char_set_create): New parameter for indicating static char set. (char_set_destroy): Do not free a static char set. (char_set_compile): Pass zero to new parameter of char_set_create. (spaces): New static array. (space_cs, digit_cs, word_cs, cspace_cs, cdigit_cs, cword_cs): New static pointers to char_set_t. (init_special_char_sets, nfa_compile_given_set): New static function. (nfa_compile_regex, dv_compile_regex): Handle new character set token keywords. (space_k, digit_k, word_char_k, cspace_k, cdigit_k, cword_char_k, regex_space_chars): New variables. (regex_init): New function. * regex.h (space_k, digit_k, word_char_k, cspace_k, cdigit_k, cword_char_k, regex_space_chars, regex_init): Declared.
* * eval.c (eval_init): New intrinsic functions remq*, remql*,Kaz Kylheku2012-04-151-0/+50
| | | | | | | | | | | | | remqual*, remove-if*, keep-if*. * lib.c (rem_lazy_func, rem_lazy_rec): New static functions. (remq_lazy, remql_lazy, remqual_lazy, remove_if_lazy, keep_if_lazy): New functions. * lib.h (remq_lazy, remql_lazy, remqual_lazy, remove_if_lazy, keep_if_lazy): Declared. * txr.1: New functions documented.
* * eval.c (eval_init): find-if intrinsic registered.Kaz Kylheku2012-04-141-5/+26
| | | | | | | | | | | * lib.c (find): First and second arguments reversed. The item should be first. (find_if): New function. * lib.h (find): Declaration updated. (find_if): Declaration added. * txr.1: Stub section.
* * eval.c (eval_init): New functions remove-if and keep-if.Kaz Kylheku2012-04-141-0/+42
| | | | | | | | * lib.c (remove_if, keep_if): New functions. * lib.h (remove_if, keep_if): Declared. * txr.1: Documented.
* * arith.c (INT_PTR_MAX_MP): New static variable.Kaz Kylheku2012-04-101-3/+10
| | | | | | | | | | | | | | | (in_int_ptr_range): New function. (arith_init): Initialize INT_PTR_MAX_MP. * arith.h (in_int_ptr_range): Declared. * lib.c (c_num): Allow bignums to be converted to a cnum, if they are in range, rather than allowing only fixnums. * rand.c (make_random_state): Now that we have such a function, initialize random seed using time value from time_sec_usec rather than from time and clock. clock is bad for random seeding because it measures virtual time since the start of the process.
* * eval.c (eval_init): Expose regex-compile and regexp as intrinsics.Kaz Kylheku2012-04-101-1/+1
| | | | | | | | | | | | | * lib.c (obj_init): Change spelling of nongreedy operator and put it into the user package so that it is available for use with regex-compile. * regex.c (match_regex, search_regex): Bugfix: optional start position argument argument not defaulting to zero. * txr.1: Documented regex-compile and regexp. * txr.vim: Highlighting regex-compile and regexp.
* * arith.c (bignum): Previously static function now exposed as external.Kaz Kylheku2012-04-081-2/+20
| | | | | | | | | | | | | | | | | | | | * 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.
* * lib.c: Revert earlier change: config.h must be included before theKaz Kylheku2012-04-071-1/+1
| | | | | <windows.h> section because that header is conditionally included based on one of the config constants.
* * configure: Added new check for some clashing external names,Kaz Kylheku2012-04-071-1/+1
| | | | | | which we can redefine out of the way in config.h. * lib.c: config.h was being included before <windows.h>.
* Rounding out hash table functionality with lazy lists thatKaz Kylheku2012-04-071-0/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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/+19
| | | | | | | | | | | | | | | | | | | | | | | * 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.
* The mut macro should only be used for vectors or vector-like objectsKaz Kylheku2012-04-051-2/+6
| | | | | | | | | | | | | which hold direct references to other objects and must be used each time a mutation takes place. * eval.c (op_dohash): invocations of mut macro removed. Comment rewritten. * lib.c (sort_list): Use set macro for mutating assignment. Do not invoke mut on sorted list; it won't work anyway, because it doesn't mean what the code wants it to mean: that the list will be fully traversed during gc marking.
* Bunch of fixes.Kaz Kylheku2012-04-051-2/+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.
* Fix failing test case tests/006/freeform-1.txr.Kaz Kylheku2012-04-031-6/+12
| | | | | | | | | | | | | | | * lib.c (lazy_str_force, lazy_str_force_upto): Use set macro when assigning lim. This won't cause a problem unless lim is in the bignum range, however. (acons_new, aconsq_new): When overwriting the cdr value of the existing entry, use set. This is the smoking gun; these functions are used for manipulating bindings. (sort): After sorting a list, we must mark it as having been mutated. If a list contains only mature conses or only fresh conses, there is no problem. But if it contains a mixture, then sorting could reverse their relationship, causing mature conses to backpoint to the fresh ones. (obj_init): Use set when installing the t symbol into the user package.
* * eval.c (op_modplace): push replaced with mpush (mutating push).Kaz Kylheku2012-04-031-5/+4
| | | | | | | | | | | | | | | * 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-9/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-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.