summaryrefslogtreecommitdiffstats
Commit message (Collapse)AuthorAgeFilesLines
* Harden processing of character escapes.Kaz Kylheku2016-12-021-4/+8
| | | | | | | | | | | | | | | | | | Weakness uncovered by fuzzing with AFL (fast) 2.30b. The failing test case is regex syntax like [\1111111...111abc], where the bad character escape allows an invalid, negatively valued character object to escape out of the parser into the system leading to an an out-of-bounds array access in the char set code in the regex compiler. * parser.l (num_esc): Make sure that an out-of-range character is mapped to zero. Set up a default value of zero for the return variable. If the character token has too many digits, don't pass them through strtol at all, which will produce a garbage value. Then in the final range check, actually replace the value with zero if it is out of range: issuing a diagnostic is not enough.
* Adding functions fr^$, fr^, fr$ and frr.Kaz Kylheku2016-12-013-0/+109
| | | | | | | | * regex.c (regex_range_full_fun, regex_range_left_fun, regex_range_right_fun, regex_range_search_fun): New functions. (regex_init): Register fr^$, fr^, fr$ and frr intrinsics. * txr.1: Documented.
* Adding curry_1234_1 function.Kaz Kylheku2016-12-012-0/+16
| | | | | | | * lib.c (do_curry_1234_1): New static function. (curry_1234_1): New function * lib.h: (curry_1234_1): Declared.
* Awk macro prn becomes function.Kaz Kylheku2016-12-012-47/+60
| | | | | | | | | | | | | | | | | | | | * share/txr/stdlib/awk.tl (sys:awk-let): Renamed to sys:awk-mac-let. Macrolet prn removed from here. (sys:awk-fun-let): New macro, provides awk functions. The prn function removed from sys:awk-mac-let is generated here. (sys:awk-fun-shadowing-env): New function. (awk): Follow rename of sys:awk-let. When expanding p-action forms, use only sys:awk-mac-let; do not include the awk functions, which do not "vaporize" unlike local macros. To compensate for not including the functions, extend the macro environment with one that shadows the functions, so that during this expansion, any global macros of the same name as awk local functions are properlly hidden. In the final expansion, include the awk functions. * txr.1: Updated documentation to consistently call prn an awk function everywhere.
* bugfix: previous loop elision fix in awk.Kaz Kylheku2016-12-011-1/+2
| | | | | | | | | | * share/txr/stdlib/awk.tl (awk): We must generate the code to bind the awk-fun under the same conditions that control whether the loop call is generated to which it is an argument. Otherwise we end up with an unbound var reference: the loop isn't elided because begin/end actions are present, but the call refers to a nonexistent variable.
* bugfix: awk must consume *args*.Kaz Kylheku2016-11-292-1/+34
| | | | | | | | | | | | | | | | | | | | | | This problem happens when awk is issued from the command line followed by one or more arguments as exemplified by the usage txr -e '(awk ...) arg ... . In this case, after awk processes the args as input sources and completes, TXR resumes processing the command line arguments and wants to open arg as a script file! To address this problem, when awk defaults on using *args* as input sources, it consumes *args* by clearing the variable to nil. TXR's command line processing already reacts to changes in *args* by evaluated forms. Code that wants *args* to be left alone by awk can explicitly pass them in using (awk (:inputs *args*) ...). * share/txr/stdlib/awk.tl (sys:awk-state): Move default initialization of inputs into :postinit. If there are no inputs by :postinit time, then take *args* or *stdin*. If *args* is used in this default manner, then consume *args*. * txr.1: Documented.
* bugfix: awk elides loop despite begin/end clauses.Kaz Kylheku2016-11-291-1/+2
| | | | | | | | * share/txr/stdlib/awk.tl (awk): The macro must not elide the processing loop if there are :begin-file, :end-file or :end actions. All these actions must be missing, not only the, cond-actions for that elision to be valid.
* conformance: handle macro wrong clause syntax.Kaz Kylheku2016-11-293-2/+26
| | | | | | | | | | | | | | | | Contrary to the documentation, handle doesn't in fact have the same syntax as catch. It passes the exception symbol to clauses as the leftmost argument, followed by the exception arguments, whereas catch passes only the exception arguments. * share/txr/stdlib/except.tl (handle): Do not pass the exception sybmol as the leftmost argument, unless operating in TXR 161 or earlier compatibility. * tests/012/except.tl: drop exception symbol argument from handle clause. * txr.1: Compatibility note added.
* Expose compat option value as sys:compat variable.Kaz Kylheku2016-11-291-0/+2
| | | | | | | * txr.c (compat): Update sys:compat variable with actual value. (txr_main): Register sys:compat variable with default zero value.
* Awk: assignment to f doesn't yield new value.Kaz Kylheku2016-11-291-2/+2
| | | | | | * share/txr/stdlib/struct.tl (sys:rslotset): Return the new value that comes out of slotset, rather than the value of the method call. Also, we don't need macro-time wrapping.
* doc: return value of slotsetKaz Kylheku2016-11-291-0/+5
| | | | * txr.1: slotset returns the stored value.
* Version 161.txr-161Kaz Kylheku2016-11-274-4/+14
| | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise.
* Eliminate duplicated warning-suppressing function.Kaz Kylheku2016-11-284-12/+12
| | | | | | | | | | | | | | * eval.c (warning_continue): Static function removed. (no_warn_expand): Use uw_muffle_warning instead of removed function. * parser.y (warning_continue): Static function removed. (parse_once): Use uw_muffle_warning instead of removed function. * unwind.c (uw_muffle_warning): New function. * unwind.h (uw_muffle_warning): Declared.
* bugfix: awk macro spews warnings.Kaz Kylheku2016-11-282-9/+21
| | | | | | | | | | | | | | Rather than fix this in the awk macro, let's just have sys:expand block warnings. * eval.c (warning_continue, no_warn_expand): New static function. (eval_init): Change registration of sys:expand to point to no_warn_expand. * share/txr/stdlib/place.tl (call-update-expander, call-clobber-expander, call-delete-expander, sys:placelet-1): Remove ignwarn wrapping from sys:expand calls.
* Version 160.txr-160Kaz Kylheku2016-11-276-600/+652
| | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise. * txr.vim, tl.vim: Regenerated.
* doc: update package example.Kaz Kylheku2016-11-271-16/+16
| | | | | | | | * txr.1: The example illustrating a module with private and public symbols is altered to show a superior practice: use a no-fallback package for the public symbols, and be in the private package when defining the module.
* doc: note about circular notation and hashes.Kaz Kylheku2016-11-271-0/+13
| | | | | * txr.1: Document that circular notation works with eql-based hash tables, but not equal-based.
* doc: grammar under str-inaddr-net.Kaz Kylheku2016-11-271-2/+2
| | | | | * txr.1: eliminate 'large enough to "covers"' with rewording.
* Warn about unbound functions.Kaz Kylheku2016-11-272-21/+25
| | | | | | | | | | | | | | * eval.c (do_expand): If a compound form doesn't expand into anything, then let us check whether it calls an unbound function, and issue a warning. * share/txr/stdlib/place.tl (sys:pl-expand): Move function definition ahead of first use to suppress unbound function warning. Eventually we will have a relaxed model of deferred warning about this. (sys:placelet-1): Suppress warnings around call to sys:expand because we are expanding a body into which we inserted function calls without inserting their definitions.
* bugfix: var environment in expansion of defun.Kaz Kylheku2016-11-271-1/+4
| | | | | | | | | * eval.c (do_expand): When expanding the body of a defun we must create a function shadowing environment which indicates that the function's name is in scope. This must not be done for defmacro; a defmacro doesn't introduce a function binding, and a macros's body doesn't have that macro in scope.
* Don't throw when printing (sys:quasi . atom).Kaz Kylheku2016-11-271-2/+2
| | | | | | | | | | | | | | | | | | | We do not have perfect read/print consistency for quasiliterals. Programs can construct quasiliterals which cause the printer to throw exceptions, or which don't print such that the same object is read back. However, at least we can handle some trivial cases. In particular, the object (sys:quasi . #<function>) occurs in the system, as the top-level binding of the quasi operator. With this change, we can print that instead of throwing. * lib.c (obj_print_impl): Check that a quasiliteral or quasi-list-literal is a list with at least one argument. Don't print (sys:quasi) or (sys:quasi . non-nil-atom) in the notation.
* bugfix: read-print consistency for @(expr).Kaz Kylheku2016-11-271-1/+1
| | | | | | | | * lib.c (obj_print_impl): Only print (sys:expr x . rest) as @x if rest is nil, and x is a cons. Otherwise we create read-print problems: (sys:expr x y) prints as @x, concealing y. And (sys:expr sym) prints as @sym which reads as (sys:var sym).
* doc: fix references to nonexistent title.Kaz Kylheku2016-11-261-4/+4
| | | | | * txr.1: References to EXCEPTIONS corrected to the correct Exceptions section title.
* New function to access exception subtype map.Kaz Kylheku2016-11-262-3/+120
| | | | | | | | | | * uwind.c (exception_subtype_map): New static function. (uw_late_init): Register exception-subtype-map intrinsic function. * txr.1: Exception types are described in more detail. A complete diagram of the existing hierarchyis given, and the exception-subtype-map funtion is documented.
* Expander warns about unbound variables.Kaz Kylheku2016-11-2613-32/+131
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * eval.c (eval_exception): New static function. (eval_error): Reduced to wrapper around eval_exception. (eval_warn): New function. (me_op): Bind the rest symbol in a shadowing env to suppress watnings about unbound rest. (do_expand): Throw a warning when a bindable symbol is traversed that has no binding. (expand): Don't install atoms as last_form_expanded. * lib.c (warning_s, restart_s, continue_s): New symbol variables. (obj_init): Initialize new symbol variables. * lib.h (warning_s, restart_s, continue_s): Declared. * lisplib.c (except_set_entries): New entries for ignwarn and macro-time-ignwarn. * parser.c (repl_warning): New static function. (repl): Use repl_warning function as a handler for warning exceptions: to print their message and then continue by throwing a continue exception. * parser.y (warning_continue): New static function. (parse_once): Use warning_continue to ignore warnings. In other words, we suppress warnings from Lisp that is mixed into TXR pattern language code, because this produces too many false positives. * share/txr/stdlib/except.tl (ignwarn, macro-time-ignwarn): New macros. * share/txr/stdlib/place.tl (call-update-expander, call-clobber-expander, call-delete-expander): Ignore warnings around calls to sys:expand, because of some gensym-related false positives (we expand code into which we inserted some gensyms, without having inserted the constructs which bind them. * tests/011/macros-2.txr: Suppress unbound variable warnings from a test case. * tests/012/ifa.tl: Bind unbound x y variables in one test case. * tests/012/struct.tl: Suppress unbound variable warnings in some test cases. * uwind.c (uw_throw): If a warning is unhandled, then print its message with a "warning" prefix and then throw a continue exception. (uw_register_subtype): Eliminate the check for sub already being a subtype of sup. This allows us to officially register new types against t. (uw_late_init): Register continue exception type as a subtype of the restart type. Formally register warning type. * txr.1: Documented ignwarn.
* bugfix: quasilit read/print consistency, part 2.Kaz Kylheku2016-11-264-16/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In this patch commit I'm addressing the issue introduced in part 1 that expressions in @(output) blocks are still using (sys:expr ...) wrapping, but are passed down to an evaluator which now expects unwrapped expressions now. As part of this change, I'm changing the representation of @expr from (sys:expr . expr) to (sys:expr expr). * eval.c (format_field): Adjust access to sys:expr expression based on new representation. (transform_op): Likewise. * lib.c (obj_print_impl): Likewise. * match.c (dest_bind): Likewise. (do_txeval): Likewise. (do_output_line): Likewise, in some compat code. Here is the fix for the issue: when calling tx_subst_vars, we pass a list of one element containing the expression, not wrapped in sys:expr. Previously, we passed a one-element list containing the sys:expr. * parser.y (o_elem): If a list occurs in the syntax, represent it as (sys:expr list) rather than (sys:expr . list). (list): Do the same for @ n_expr syntax. (expand_meta, make_expr): Harmonize with the representation change.
* bugfix: quasilit read/print consistency, part 1.Kaz Kylheku2016-11-264-42/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The bug is that `@@@a` prints as `@@a` which reads as a different object. In this patch we simplify how quasiliterals are represented. Embedded expressions are no longer (sys:expr E), just E. Meta-numbers N and variables V are still (sys:var N). However `@@a` and `@a` remain equivalent. * eval.c (subst_vars): No need to look for expr_s; just evaluate a compound form. The recursive nested case is unnecessary and is removed. (expand_quasi): Do nothandle expr_s; it is not part of the quasi syntax any more. * lib.c (out_quasi_str): Do not look for expr_s in the quasi syntax; just print any expression with a @ the fallback case. * match.c (tx_subst_vars): Analogous changes to those done in subst_vars in eval.c. * parser.y (quasi_meta_helper): Static function removed. This was responsible for the issue due to stripping a level of meta from expressions already having a meta on them. (quasi_item): In the `@` n_expr syntax case, no longer call quasi_meta_helper. The remaining logic is simple enough to put in line. Symbols and integers get wrapped with (sys:var ...); other expressions are integrated into the syntax as-is.
* bugfix: dohash expander not making shadowing env.Kaz Kylheku2016-11-251-1/+2
| | | | | | | | * eval.c (do_expand): When a dohash special form is expanded, a macro shadowing environment must be created for the two variables that it binds and the body must be expanded in that environment, to protect the variables from symbol macros.
* bugfix: expander traversing (sys:expr ...).Kaz Kylheku2016-11-251-1/+1
| | | | | | * eval.c (do_expand): Do not expand into (sys:expr ...) expressins, the same way (sys:var ...) expressions are avoided. They are not forms.
* bugfix: unbound var in IP-slash-notation functions.Kaz Kylheku2016-11-251-6/+6
| | | | | | * share/txr/stdlib/socket.tl (sys:str-inaddr-net-impl): Use let* so that calculation of we can see dependent w variable.
* bugfix: op handles @rest in dot position.Kaz Kylheku2016-11-251-1/+1
| | | | | | | | | | The test case is (op list . @rest) and similar, which were expanding to a syntax containing an incorrect form like [sys:apply list sys:var rest #:rest-0123] where the sys:var rest are superfluous. * eval.c (transform_op): Missing case: the code which handles metas in the dot position must handle @rest not only @<number>.
* bugfix: don't expand @meta syntax as function call.Kaz Kylheku2016-11-241-0/+2
| | | | | | * eval.c (do_expand): If the form is (sys:var ...) then skip it without expanding. Of course, that does not preclude it form being a macro.
* bugfix: op macro using wrong expansions op.Kaz Kylheku2016-11-241-1/+3
| | | | | | * eval.c (me_op): When the operator is op, the arguments must be expanded as Lisp-1 with expand_forms_lisp1, not with the regular expand_forms.
* macro-time: interleave evaluation and expansion.Kaz Kylheku2016-11-242-2/+19
| | | | | | | | | | * eval.c (do_expand): When expanding the macro-time form, do not macro-expand it entirely and then evaluate. Rather, expand each argument form and evaluate. This way earlier forms can make global definitions which are used while macro-expanding later definitions. * txr.1: Behavior documented.
* bugfix: broken test-inc macro.Kaz Kylheku2016-11-241-1/+1
| | | | | * share/txr/stdlib/place.tl (test-inc): Expander refers to unbound variable.
* bugfix: neglect to expand mac-param-bind forms.Kaz Kylheku2016-11-241-6/+19
| | | | | | | | | | | | | | The syntax of mac-param-bind forms isn't recognized at all in the expander, causing these forms to be incorrectly expanded as if they were function calls. * eval.c (mac_param_bind_s): New symbol variable. (do_expand): Handle mac_param_bind_s with the same block of code as tree_bind_s, adjusted to account for the small syntactic difference. (eval_init): Initialize mac_param_bind_s with interned symbol. Register operator using mac_param_bind_s to avoid redundant intern call.
* bugfix: macrolet args not included in macro env.Kaz Kylheku2016-11-241-29/+31
| | | | | | | | | | | | | | | When the function bodies of macrolets are themselves being macro-expanded, this is incorrectly being done in the original macro environment without taking into account the macrolet parameters which those bodies have in scope. Hence the parameters are not able to shadow symbol macros. * eval.c (make_var_shadowing_env): Moved above expand_macrolet so we can avoid adding a forward declaration. Otherwise unchanged. (expand_macrolet): For each macrolet function, create a shadowing environment which contains its parameters, and use that for expanding the body.
* bugfix: indicator params absent from macro envs.Kaz Kylheku2016-11-241-2/+5
| | | | | | | | | | | | | | The problem is about those Boolean parameters which indicate whether their associated optional parameters are present: in (lambda (: (opt-parm 42 opt-parm-p))), such a parameter is opt-parm-p. When parameter lists are walked by the macro expander, these parameters are not being included as shadow entries in macro-time parameter lists. Thus if opt-parm-p happens to shadow an outer symbol macro, that symbol macro will be expanded anyway. * eval.c (get_opt_param_syms): Function now lists those additional parameters.
* bugfix: reading hash literals with circ notation.Kaz Kylheku2016-11-231-1/+12
| | | | | | | | | | | | | | | | | | | The backpatching of literal hash objects containing circular notation labels is incorrect, because it directly mutates the hash keys, without regard for the fact that this alters their hash values. This change makes the test case #1=#H(() (#1# #1#)) work properly: a hash which contains itself as a key and corresponding value. When this object is constructed by the reader, we can do a gethash call on it, using itself as the key, and it emerges as the value. Before this fix, nil would be returned indicating that the key is not found, although it is listed in the table (corrupt hash). * parser.c (circ_backpatch): When traversing a hash, local list of the cells. Then clear the hash, iterate the list of old cells, and re-insert the key-value pairs.
* Adding clearhash function.Kaz Kylheku2016-11-233-0/+35
| | | | | | | | | | | | This is needed for an upcoming bugfix, so why not expose it as an intrinsic. * hash.c (clearhash): New function. (hash_init): clearhash intrinsic registered. * hash.h (clearhash): Declared. * txr.1: Documented clearhash.
* Move unwind intrinsics from eval.c to unwind.c.Kaz Kylheku2016-11-233-27/+28
| | | | | | | | | | | | | | | | * eval.c (reg_mac): Static function changed to extern. (me_defex, register_exception_subtypes): Static function removed here; relocated into unwind.c. (eval_init): Registrations of defex, throw, throwf, error, register-exception-subtypes and exception-subtype-p removed. * eval.h (reg_mac): Declared. * unwind.c (me_defex, register_exception_subtypes): Static function moved here. (uw_late_init): Registrations of defex, throw, throwf, error, register-exception-subtypes and exception-subtype-p moved here.
* doc: small revision in intro text.Kaz Kylheku2016-11-221-3/+3
| | | | * txr.1: Mention support for OOP.
* doc: misleading dialect note under symbol-function.Kaz Kylheku2016-11-221-2/+3
| | | | | | * txr.1: Fix text saying that symbol-function retrieves only functions; that is true for symbols, not for the compound syntax.
* doc: fixes under tagbody.Kaz Kylheku2016-11-221-2/+2
| | | | | | * txr.1: Grammar: to occurs -> to occur. Also any subforms of a tagbody form may be go, not just one one form as the text seems to be saying.
* doc: formatting fix under boundp.Kaz Kylheku2016-11-221-0/+2
| | | | * txr.1: Fix bad inline expression splitting.
* configure: search for working lex.Kaz Kylheku2016-11-221-2/+41
| | | | | | | | | * configure (lexname, lexname_given, lex_given): New variables. (lex): interpolate lexname (in make syntax). Inform about lexname in help text. (gen_config_make): Generate lexname make var. New lex test.
* doc: formatting issue in awk fconv macro desc.Kaz Kylheku2016-11-221-2/+2
| | | | | * txr.1: Fix two instances of clause parameter being typeset as .code rather than .meta.
* doc: fix in delimited continuations description.Kaz Kylheku2016-11-221-1/+1
| | | | * txr.1: Missing article: *the* sys:capture-cont function.
* doc: fixes under Symbols and Packages.Kaz Kylheku2016-11-221-2/+4
| | | | | * txr.1: Fix .code *package* embedded in paragraph. Remove stray words in code comment in package example.
* Version 159.txr-159Kaz Kylheku2016-11-216-632/+667
| | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise. * txr.vim, tl.vim: Regenerated.