summaryrefslogtreecommitdiffstats
Commit message (Collapse)AuthorAgeFilesLines
* struct :init :fini specifiers.Kaz Kylheku2015-09-292-3/+93
| | | | | | | | * share/txr/stdlib/struct.tl (defstruct): New (:init ...) and (:fini ...) syntax can be used in the slot list to specify an initialization function and a gc-finalization function. * txr.1: Documented.
* Implementation of static slots for structures.Kaz Kylheku2015-09-297-115/+704
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * share/txr/stdlib/struct.tl (sys:bad-slot-syntax): New helper function. (defstruct): Macro revamped with new slot specifier syntax for writing static slots as well as methods. * struct.c (STATIC_SLOT_BASE): New preprocessor symbol. (struct struct_type): New members, nstslots, stinitfun, stslot. (make_struct_type_compat): New static function. (struct_init): Register make-struct-type to make_struct_type_compat if compatibility is 117 or lower. Register new intrinsics static-slot, static-slot-set, call-super-method, call-super-fun, slot-p and static-slot-p. (call_stinitfun_chain): New static function. (make_struct_type): Two new arguments for specifying static slots and an initialization function for them. Logic added for setting up static slots and handling inheritance. (struct_type_destroy): New static function. (struct_type_mark): Mark the new stinitfun member of struct type. Also iterate over the static slots in the new stslot array and mark them. (lookup_slot): Altered to return a loc instead of a raw pointer, and also to accept the instance object as a member. Now resolves static slots: it can return a loc which references a static slot in the structure type, or an instance slot in the structure. (lookup_static_slot): New static function. (slot, slotset): Implementation adjusted due to new lookup_slot interface. (static_slot, static_slot_set, slot_p, static_slot_p): New functions. (call_super_method, call_super_fun): New static functions. (struct_inst_print): This function can no longer assume that the slots list lines up with the array of slots, since it contains a mixture of static and instance slots. Earnest slot lookup has to be performed. (struct_type_ops): Point the destroy function to struct_type_destroy instead of cobj_destroy_free_op. A structure type now has an array of static slots to free. * struct.h (make_struct_type): Declaration updated. (static_slot, static_slot_set, slot_p, static_slot_p): Declared. * lib.c (time_init): Update call to make_struct_type with new arguments. * sysif.c (sysif_init): Likewise. * tests/012/struct.tl: Update defstruct macro expansion test. * txr.1: Documented static slots and new functions.
* C++ fix in poll wrapper.Kaz Kylheku2015-09-291-2/+1
| | | | | * sysif.c (poll_wrap): We must coerce mem_t * return value of chk_calloc, not convert.
* C++ fixes in configure script.Kaz Kylheku2015-09-291-4/+4
| | | | | | * configure: pointer mismatch in poll test, rejected by g++. Also warning about missing braces in initializer. Test for mkstemps used reserved word template as identifier.
* Additional reductions for and.Kaz Kylheku2015-09-291-0/+6
| | | | | | | * regex.c (reg_optimize): If the empty regex is and-ed with another regex, that other regex must be nullable, otherwise the and matches nothing. This is captured in some new reductions for the and operator.
* Simplify and optimization.Kaz Kylheku2015-09-291-4/+1
| | | | | | * regex.c (reg_optimize): No need to check reg_matches_all in and optimization case because the argument object has already been reduced that way by reg_optimize recursion.
* Optimize some cases of the regex branch operator.Kaz Kylheku2015-09-291-0/+43
| | | | | | * regex.c (reg_compl_char_p): New static function. (reg_optimize): Optimize various cases of the or operator: (R|) -> R?, (a|b) -> [ab] and others.
* Some optimizations for * ? and +.Kaz Kylheku2015-09-291-4/+21
| | | | | | * regex.c (regex_optimize): Simplify compounded uses of repetition operators: RR* -> R, R+? -> R* and so on.
* Regex printer fails on \w, \s or \d in char class.Kaz Kylheku2015-09-291-0/+2
| | | | | regex.c (print_rec): Bugfix: handle symbols in character class syntax.
* Improve lazy_str_force_upto performance on some cases.Kaz Kylheku2015-09-291-2/+8
| | | | | | * lib.c (lazy_str_force_upto): Don't allow wastefully small increments; force at least 1024 characters beyond the current length of the prefix.
* Improve performance of lazy string forcing.Kaz Kylheku2015-09-281-9/+27
| | | | | | | | | * lib (lazy_str_force, lazy_str_force_upto): The existing algorithm keeps catenating pieces onto a string, which triggers wasteful reallocations and is quadratic. This is replaced with a different approach: we collect pieces into a list, and then make a single call to cat_str.
* More complement optimizations.Kaz Kylheku2015-09-281-0/+19
| | | | | * regex.c (reg_optimize): Transform ~.*c to (.*[^c])? and ~c.* to ([^c].*)? where c is a single-character match.
* Streamline some regex optimizations.Kaz Kylheku2015-09-281-15/+48
| | | | | | | * regex.c (reg_single_char_p, invert_single): New static functions. (reg_optimize): Simplify complement operator optimizations using new functions.
* linenoise: backspace also causes parenthesis jump.Kaz Kylheku2015-09-272-0/+5
| | | | | | | * linenoise/linenoise.c (edit): Do paren_jump after backspace * txr.1: Documented.
* Optimization for one-character range.Kaz Kylheku2015-09-271-2/+7
| | | | | * regex.c (reg_optimize): [a] -> a. Also take advantage of this where the complement case generates [a].
* Optimize complement operator more.Kaz Kylheku2015-09-271-0/+28
| | | | | * regex.c (reg_optimize): Recognize and transform several cases: ~c -> ([^c]?|..+); ~[^c] -> ([c]?|..+); and ~.*c.* -> [^c]*.
* S-exp level regex optimization.Kaz Kylheku2015-09-271-32/+156
| | | | | | | | | | | | | | * regex.c (dv_compile_regex): Replaced by two functions, reg_expand_nongreedy and reg_compile_csets. (reg_expand_nongreedy, reg_compile_csets): New static functions. (reg_optimize): New static function. (regex_compile): Expand nongreedy syntax in incoming regex, and then optimize it before deciding whether to use NFA or derivatives. If derivatives are used, compile the character sets in the regex to character set objects. (regex_init): Register some intrinsic functions for debugging, sys:reg-expand-nongreedy and sys:reg-optimize.
* Support t regex in NFA compiler and in printer.Kaz Kylheku2015-09-271-1/+16
| | | | | | | | | | | | | | | | The t regex means "match nothing". This patch allows the NFA compiler to handle it. This will be necessary for an upcoming regex optimizer which can put out such an object. Also, the recursive regex printer can print the object now. * regex.c (nfa_kind_t): New enum member, nfa_reject. (nfa_state_reject): New static function. (nfa_compile_regex): Compile t regex into a reject state which cannot reach its corresponding acceptance state. (nfa_map_states): Handle nfa_reject case in switch, similarly to nfa_accept: nothing to transition into. (print_rec): Render the t regex as the empty character class [].
* Replace internal_error with exception throws in regex.Kaz Kylheku2015-09-271-7/+7
| | | | | | * regex.c (nfa_compile_regex, dv_compile_regex, reg_nullable, reg_matches_all, reg_derivative, regex_requires_dv): Throw an exception for the bad operator case.
* Bug in complement case of reg_matches_all.Kaz Kylheku2015-09-271-1/+2
| | | | | | * regex.c (reg_matches_all): A complement matches all if its argument matches nothing, not if its argument is anything but the empty match nil.
* More tests for ifa/conda.Kaz Kylheku2015-09-271-0/+15
| | | | | | * tests/012/ifa.tl: New test cases which test the expansion when the it-form is a place and there are forms before and after it.
* Treat .( and (( context in completion.Kaz Kylheku2015-09-271-1/+3
| | | | | | | | | * parser.c (provide_completions): Don't pass the context parenthesis to find_matching_syms in additional cases: when preceded by a dot, or another parenthesis. This causes completion situations such as (let ((var[TAB] and obj.(method[TAB] not to be wrongly restricted to the function space.
* Fix cascading message for unbound vars in pattern language.Kaz Kylheku2015-09-271-2/+4
| | | | | | | | | | | | | Commit 5ab2b46a on 2011-10-06 introduced a hack for suppressing redundant location informaton being tacked on to an unbound variable error (in the TXR pattern language, not TXR Lisp). This ugly hack broke along the way when uw_throw was changed so that exception arguments are always lists, because it still expects the exception object to be a string. (The breaking change took place in 55cc8493, on 2015-02-06). * match.c (do_txeval): In exception catch, exc is a list, and not a string.
* linenoise: paren matching jump finds closes paren.Kaz Kylheku2015-09-272-10/+72
| | | | | | | | | | * linenoise/linenoise.c (find_nearest_paren): New static function. (edit_move_matching_paren): Use find_matching_paren to usefully handle situations when the cursor is not on a parenthesis, bracket or brace. * txr.1: Documented.
* Full gc should be done if driven by malloc.Kaz Kylheku2015-09-271-0/+5
| | | | | | | | | * gc.c (gc): If the number of bytes malloced since the last gc exceeds the gc delta, we must do do a full garbage collection. The mature generation is almost certainly holding on to a lot of that memory. A test case for this is (lazy-str-force (lazy-str (get-lines (open-file "file")))). The file doesn't even have to be very large.
* Don't force lazy string in string input streams.Kaz Kylheku2015-09-261-11/+5
| | | | | | | | | * stream.c (find_char): Don't extract C string from string; use abstract access to find the character, without calculating length. (string_in_get_line, string_in_get_char): Don't calculate the length of the string to compare it to the position; use the lazy-safe length_str_gt function instead.
* linenoise: no wasteful retrace on clear screen.Kaz Kylheku2015-09-251-0/+1
| | | | | | | * linenoise/linenoise.c (lino_clear_screen): Set l->maxrows to zero so that refresh_multiline won't emit useless upward cursor movement sequences. These have nowhere to go from the top line of the screen.
* linenoise: no upward retrace after suspend resume.Kaz Kylheku2015-09-251-0/+1
| | | | | | | | | * linenoise/linenoise.c (edit): After coming back from a Ctrl-Z suspend, set l->maxrows to zero to force refresh_multiline to draw the buffer from the current cursor position down, without any retrograde cursor movement to above lines, trying to refresh existing lines which are not there.
* linenoise: fix broken move-to-end on Enter.Kaz Kylheku2015-09-251-18/+26
| | | | | | | | | | | | | | | | | | | | | The switch to Ctr-A/Ctrl-E within a logical line breaks when the edit_move_end function is relied upon to go to the end of the buffer. * linenoise/linenoise.c (edit_move_home): Restored to original behavior. (edit_move_sol): New static function that hosts new behavior of edit_move_home: calls edit_move_home in single-line mode, or implements move within logical line in multi-line mode. (edit_move_end): Restored to original behavior. (edit_move_eol): New static function that hosts new behavior of edit_move_end: calls edit_move_end in single-line mode, or implements move within logical line in multi-line mode. (edit): Call edit_move_sol instead of edit_move_home, and in editing functions onyl, call edit_move_eol instead of edit_move_end.
* return and return-from must throw, not abort.Kaz Kylheku2015-09-251-0/+3
| | | | | | * eval.c (op_return, op_return_from): If uw_block_return doesn't find a block, and just returns, then throw an exception rather than aborting.
* Fix two bugs in ifa macro.Kaz Kylheku2015-09-251-3/+3
| | | | | | | | | | * share/txr/stdlib/ifa.tl (ifa): Misplaced parentheses in mapcar call were causing the lists of before and after temporary variables to come up empty, resulting in a misexpansion (in the case when the it-argument is a place). Also, before and after temporaries swapped in the expansion: afters were inserted before the it-argument and vice-versa.
* Add copyright headers to some lib modules.Kaz Kylheku2015-09-254-0/+100
| | | | | | | | | | * share/txr/stlib/path-test.tl: Added header. * share/txr/stlib/struct.tl: Likewise. * share/txr/stlib/txr-case.tl: Likewise. * share/txr/stlib/with-resources.tl: Likewise.
* linemode: multi-line behavior for Ctrl-A/Ctrl-E.Kaz Kylheku2015-09-252-6/+34
| | | | | | | | * linemode/linemode.c (edit_move_home, edit_move_end): Check for multi-line mode and implement movement within the physical line. * txr.1: Documented.
* linenoise: delete previous word fix for multi-line.Kaz Kylheku2015-09-251-4/+3
| | | | | | | | * linenoise/linenoise.c (SPACE): Preprocessor symbol removed; was only referenced in the edit_delete_prev_word function. (edit_delete_prev_word): Recognize carriage return as word-separating whitespace.
* linenoise: fix multi-line issues with long linesKaz Kylheku2015-09-251-34/+44
| | | | | | | | | | | * linenoise/linenoise.c (screen_rows): Restructured. Calculates correct cursor rows (out.rows[1]). It's now possible that the reported cursor row exceeds the number of rows (out.rows[0]), because the cursor is on the last line, which itself doesn't wrap, but the cursor does. (refresh_multiline): Cursor wrapping calculation is simple now: just check that nrow > rows. Coalesced code for dealing with cursor position.
* regex: major optimization for complement operator.Kaz Kylheku2015-09-241-1/+46
| | | | | | | | | | | This change a huge improvement for expressions that use complement, directly or via the non-greedy % operator. * regex.c (reg_matches_all): New static function. (reg_derivative): When the dervative is applied to a complement expression, identify situations when the remaining expression cannot possibly match anything, and convert them to the t expression.
* Version 117.txr-117Kaz Kylheku2015-09-236-254/+303
| | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise. * txr.vim, tl.vim: Regenerated.
* linenoise: wrong snprintf argument.Kaz Kylheku2015-09-231-1/+1
| | | | | * linenoise/linenoise.c (refresh_multiline): Fix size_t being passed to %d conversion specifier in snprintf call.
* Fix race in ~/.txr_profile security check.Kaz Kylheku2015-09-231-8/+8
| | | | | | | | * parser.c (load_rcfile): Apply the privacy test to the open stream, rather than the file name, thus guarding against the possibility that a verified file object is replaced by another one before it is opened.
* statf becomes external.Kaz Kylheku2015-09-232-2/+3
| | | | | | | | * sysif.c (statf): Linkage changed to external. Also, fixed wrong name being passed down to stat_impl. * sysif.h (statf): Declaration updated.
* doc: note another race in path-private-to-me-pKaz Kylheku2015-09-231-1/+13
| | | | | | * txr.1: document a TOCTTOU race condition in uses of path-private-to-me-p and how to get around it.
* doc: stat functions return structure.Kaz Kylheku2015-09-231-1/+1
| | | | | | * txr.1: Under Unix Filesystem Object Existence, Type and Access Tests, fix text which implies that the stat functions return a list.
* linenoise: correct tab alignment in multi-line mode.Kaz Kylheku2015-09-231-4/+9
| | | | | | | * linenoise/linenoise.c (sync_data_to_buf): Maintain a colum variable which is reset when a new line is put out and takes into account the prompt length; use this for tabs.
* lack of optional arg defaulting in lazy_sub_str.Kaz Kylheku2015-09-231-2/+2
| | | | | | * lib.c (lazy_sub_str): Check from and to args correctly using null_or_missing_p instead of comparing to nil.
* repl: give details about source of error exception.Kaz Kylheku2015-09-231-0/+10
| | | | | * parser.c (repl): Print location info for exception based on last_form_evaled and last_form_expanded.
* Bugfix: sub function not handling lazy strings.Kaz Kylheku2015-09-221-0/+1
| | | | | | | This bug means that range indexing doesn't work on lazy strings. Ouch! * lib.c (sub): Added missing LSTR switch case.
* linenoise: C++ fixes, including g++ warnings.Kaz Kylheku2015-09-221-10/+10
| | | | | | | | * linenoise/linenoise.c (history_search, sync_data_to_buf, screen_rows, paren_jump, edit_move_matching_paren): Fix signed/unsigned warnings. (edit_in_editor): Avoid using template as a variable name. Use const char * for string literal.
* C++ upkeep: cannot assign to volatile sigset_t.Kaz Kylheku2015-09-221-1/+11
| | | | | | | | | | | | | | | | This is a hack for an ugly problem. A plain old struct is actually a class in C++, and assignment to a struct goes thorugh a generated assignment operator. Unfortunately, C++ doesn't generate an assignment operator for volatile destinations, so assignment to a volatile-qualified struct object is erroneous. * signal.h (copy_sigset): New inline function to copy a sigset_t, even if the left hand side is volatile. This works by stripping the qualifier. (sig_save_enable): Use the function.
* Introduce chk_wmalloc function.Kaz Kylheku2015-09-224-11/+20
| | | | | | | | | | | | | | | Two-fold benefit. Simplifies code which allocates wchar_t arrays. Provides overflow check for the multiplication. * lib.c (chk_wmalloc): New function. (chk_strdup, mkstring, mkustring, upcase_str, downcase_str, sub_str, cat_str, trim_str): Use chk_wmalloc. * lib.h (chk_wmalloc): Declared. * stream.c (make_string_output_stream): Use chk_wmalloc. * utf8.c (utf8_dup_from_uc, utf8_dup_from): Likewise.
* linenoise: forward paren jump too.Kaz Kylheku2015-09-222-2/+14
| | | | | | | | * linenoise/linenoise.c (paren_jump): Scan forward also, if reverse scan turns up nothing, thereby jumping to a closing parenthesis in the forward direction. * txr.1: Documentation updated.