summaryrefslogtreecommitdiffstats
path: root/eval.c
Commit message (Collapse)AuthorAgeFilesLines
* Move PRNG-related initialization to rand.cKaz Kylheku2016-04-281-8/+0
| | | | | | | | | * eval.c (eval_init): Remove registration of make-random-state, random-state-get-vec, random-state-p, random-fixnup, random, and rand. * rand.c (rand_init): Move registrations removed from eval_init here.
* Recycle temporary list-of-lists in mapping functions.Kaz Kylheku2016-04-221-3/+9
| | | | | | | | * eval.c (mapcarv, mappendv, mapdov): When done, we can recycle the conses used for the temporary copy of the list-of-lists, whose car-s are used for iterating over the lists in paralle. This is safe because the temporary list's conses aren't shared with any other function.
* Don't quote path in load and @(load) diagnostics.Kaz Kylheku2016-04-221-1/+1
| | | | | | | * eval.c (sys_load): Use ~a format specifier rather than ~s for the load path (if already known to be a string). * match.c (v_load): Likewise.
* Close source files after parsing.Kaz Kylheku2016-04-151-0/+3
| | | | | | | | | | | | | * eval.c (sys_load): close stream in all cases. * match.c (v_load): Likewise. * parser.c (load_rcfile): Close stream in unwind block, if open. * txr.c (txr_main): Close stream after parsing in all cases. If stream is std_input, or a string stream, close_stream does nothing.
* Fix proper-listp to proper-list-p.Kaz Kylheku2016-04-141-3/+7
| | | | | | | | | | | | | | | | | | | | This is really a gratuitous incompatibility with Common Lisp and other dialects. Let's fix it internally also, but keep the proper-listp function binding for backwards compatibility. * eval.c (dot_to_apply, me_op): Update proper_listp call to proper_list_p. (eval_init): Register proper-list-p to the same C function as proper-listp, and that C function is now called proper_list_p. * lib.c (proper_listp): Renamed to proper_list_p. * lib.h (proper_listp): Declaration updated. * parser.y (define_transform): Update proper_listp call. * txr.1: Replace all occurrences of proper-listp with proper-list-p. Add note explaining the rename situation.
* Trace expansion more in expansion-time errors.Kaz Kylheku2016-04-131-5/+32
| | | | | | * eval.c (error_trace): If an error occurs during the expansion of a form, that form may be the result of expansions. Dump those expansions.
* Bugfix: track origin for built-in macros.Kaz Kylheku2016-04-131-0/+1
| | | | | | | | | | | This fix is no longer that important, since due to the previous commit, expand now tracks expansion origins thoroughly, which hides this bug. However, expand_macro is directly called from a few other functions, like macroexpand, which don't benefit from that fix. * eval.c (expand_macro): Add forgotten set_origin call in the case when the native C expander is called.
* More thorough job of tracking expansion origins.Kaz Kylheku2016-04-131-7/+6
| | | | | | | | | | | | | This promotes better diagnostics. Simple test case: [(ret @5) 1]. * eval.c (do_expand): Manual tail recursion via backwards goto is removed; the function recurses now, and it recurses through the expand wrapper rather than by calling itself. That is needed in order to properly install the origin tracking for each expansion. (expand): Record origin for each expansion that already doesn't have one.
* Don't expand replacements of symbol macros.Kaz Kylheku2016-04-121-3/+6
| | | | | | | | | * eval.c (expand_symacrolet, do_expand): Don't expand the replacement form of a global or lexical symbol macro at the time it is bound to its symbol. This is almost certainly wrong in situations where it makes a difference. * txr.1: Noted in compatibility section.
* Better handling of dot position function calls.Kaz Kylheku2016-04-111-12/+50
| | | | | | | | | | | | | | | | | | | | | | | | | | The expander now actually produces apply forms for dot position function call and dwim forms. This allows symbol macros to work naturally. * eval.c (sys_apply_s): New symbol variable. (imp_list_to_list, dot_to_apply): New static functions. (expand_forms, expand_forms_lisp1): We now throw an error if a non-nil atom terminates a form, Except in compatibility mode with TXR 137 or less, whereby we emulate the old behavior of not expanding this atom. (do_expand): Perform the dot_to_apply transformation on the arguments of the dwim form. Perform the dot_to_apply transformation on an entire function call form. (eval_init): Initialize sys_apply_s and register sys:apply function (using the same function object that is registered under apply). * txr.1: Documented that both DWIM forms and regular function call forms work as if by a transformation to apply form, removing verbiage which separately described the DWIM handling. Documented that symbol macros work properly in dot position.
* Allow symbol macro in function call dot position.Kaz Kylheku2016-04-071-1/+5
| | | | | | | | | | * eval.c (expand_forms): If the forms list is an atom, then don't just return it. Try to expand it as a macro. If the macro produces a compound form, diagnose with an exception, otherwise return the expansion. * txr.1: Document the treatment of symbol macros in function call dot position.
* Adding rightmost item search functions.Kaz Kylheku2016-03-271-1/+14
| | | | | | | | | | | | | | | | | | * eval.c (eval_init): Registered intrinsics rmemq, rmemql, rmemqual, rmember, rmember-if, rposqual, rposql, rposq, rpos, rpos-if, rfind, rfind-if and rsearch. * lib.c (rmemq, rmemql, rmemqual, rmember, rmember-if, rposqual, rposql, rposq, rpos, rpos-if, rfind, rfind-if, rsearch): New functions. (rsearch_list): New static function. (search): Omit unreachable return statement. * lib.h (rmemq, rmemql, rmemqual, rmember, rmember-if, rposqual, rposql, rposq, rpos, rpos-if, rfind, rfind-if, rsearch): Declared. * txr.1: Documented.
* Bugfix in error location reporting across macro expansions.Kaz Kylheku2016-03-261-2/+2
| | | | | | | * eval.c (do_expand, macroexpand_1): The original form must have priority in providing source location info, over the macro. Otherwise macro bodies may get reported as locations of errors that occur in substituted code.
* Bugfix: append-each is wrongly destructive.Kaz Kylheku2016-02-291-1/+1
| | | | | * eval.c (op_each): Use list_collect_append not list_collect_nconc. Ouch!
* expand-left and nexpand-left functions.Kaz Kylheku2016-02-291-0/+35
| | | | | | | | * eval.c (expand_left, nexpand_left): New static functions. (eval_init): Registered expand-left and nexpand-left intrinsics. * txr.1: Documented.
* Header file cleanup.Kaz Kylheku2016-01-221-1/+0
| | | | | | | * arith.c, cadr.c, debug.c, eval.c, filter.c, gencadr.txr, glob.c, hash.c, linenoise/linenoise.c, lisplib.c, match.c, parser.c, rand.c, regex.c, signal.c, stream.c, struct.c, sysif.c, syslog.c, txr.c, unwind.c, utf8.c: Remove unncessary header files.
* Reduce header pollution caused by mpi.h.Kaz Kylheku2016-01-221-0/+1
| | | | | | | | | | | | | * eval.c: include <assert.h> that was previously coming via "mpi.h". * mpi/mpi.c: Includes of <stdio.h>, <ctype.h> and <assert.h> moved here. * mpi/mpi.h: Remove include of <stdio.h>, <ctype.h> and <assert.h>. Keeping <limits.h> for now; needed for CHAR_BIT. * mpi/mplogic.c: Needs <assert.h>
* New random-state-get-vec function.Kaz Kylheku2016-01-181-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | * arith.c (UINT_PTR_MAX_MP): New static variable. (biggnum_from_uintptr): New function. (in_uint_ptr_range): New static function. (c_uint_ptr_num): New function. (arith_init): Initialize UINT_PTR_MAX_MP. * arith.h (bignum_from_uintptr, c_uint_ptr_num): Declared. * eval.c (eval_init): Register random-state-get-vec. * mpi/mpi.c (mp_set_uintptr, mp_get_uintptr): New functions. (mp_set_intptr, mp_get_intptr): Expressed in terms of mp_set_uintptr and mp_get_uintptr. * mpi/mpi.h (mp_set_uintptr, mp_get_uintptr): Declared. * rand.c (make_random_state): Handle vector seed. (random_state_get_vec): New function. * rand.h (random_state_get_vec): Declared. * txr.1: Documented new feature in make-random-state and new random-state-get-vec function.
* New function, split*.Kaz Kylheku2016-01-171-0/+1
| | | | | | | | | | | | | | | | | | * eval.c (eval_init): Register split*. * lib.c (split_star_func): New static function. (partition_split_common): Take pointer-to-function argument instead of boolean. Hoist this C function into the lazy cons. (partition): Pass pointer to partition_func ito partition_split_common, intsead of a flag requesting the use of partition_func. (split): Pass apointer to split_func into partition_split_common. (split_star): New function. * lib.h (split_star): Declared. * txr.1: Documented split*.
* Fix omission: the / function becomes n-ary.Kaz Kylheku2016-01-131-1/+1
| | | | | | | | | | * eval.c (eval_init): Register / function to divv instead of divi. * lib.c (divv): New function. * lib.h (divv): Declared. * txr.1: Documented.
* bugfix: no location info for unbound var in dohash.Kaz Kylheku2016-01-131-5/+5
| | | | | | | * eval.c (do_expand): Add missing rlcp in the construction of the return value of the clause which expands a dohash. Let's make it a rlcp_tree. Test case: (dohash (a b c) d e) with c unbound.
* The identity function gets an alias: use.Kaz Kylheku2016-01-131-0/+1
| | | | | | * eval.c (eval_init): Register "use" as alias for identity. * txr.1: Documented use function.
* New internal function scat: variable arg cat_str.Kaz Kylheku2016-01-101-2/+2
| | | | | | | | | | | | | | Avoids consing up list of strings. * lib.c (vscat): New static function. (scat): New function. (lazy_str): Use scat instead of cat_str. * lib.h (scat): Declared. * eval.c (format_field): Use scat instead of cat_str. * parser.c (open_txr_file, read_eval_stream): Likewise.
* Don't record form as its own macro origin.Kaz Kylheku2016-01-091-2/+2
| | | | | | | * eval.c (set_origin): Add form != origin to the condition for recording the ancestry. (expand_macro): Use set_origin function instead of direct call to sethash.
* Revert chr-isdigit/isxdigit, provide new functions.Kaz Kylheku2016-01-041-0/+2
| | | | | | | | | | | | | | | | | | | It was a mistake to change the semantics of the return value of chr-isdigit and chr-isdigit. It breaks code like [partition-by chr-isdigit ...]. The behavior of chr-isdigit and chr-isxdigit is restored to returning t and nil. New chr-digit and chr-xdigit functions are introduced for returning the digit value or nil. * eval.c (eval_init): Register chr-digit and chr-xdigit intrinsics. * lib.c (chr_isdigit, chr_isxdigit): Restore old behavior. (chr_digit, chr_xdigit): New functions. * lib.h (chr_digit, chr_xdigit): Declared. * txr.1: Everything documented.
* Wording change in error_trace.Kaz Kylheku2016-01-021-2/+2
| | | | | * eval.c (error_trace): Change "possibly triggered by" to "during evaluation of".
* Use last-form-evaled mechanism for pattern language.Kaz Kylheku2016-01-021-0/+7
| | | | | | | | | | | | | | We need this now, since file system errors aren't handled in the pattern language any more, after the complex_open refactoring. * eval.c (set_last_form_evaled): New function. * eval.h (set_last_form_evaled): Declared. * match.c (do_match_line, match_files): Save, set up and restore last_form_evaled via set_last_form_evaled function.
* Copyright year bump.Kaz Kylheku2015-12-311-1/+1
| | | | | | | | | | | | | | | | | | | | | | | * LICENSE, METALICENSE, Makefile, args.c, args.h, arith.c, arith.h, cadr.c, cadr.h, combi.c, combi.h, configure, debug.c, debug.h, eval.c, eval.h, filter.c, filter.h, gc.c, gc.h, glob.c, glob.h, hash.c, hash.h, jmp.S, lib.c, lib.h, lisplib.c, lisplib.h, match.c, match.h, parser.c, parser.h, parser.l, parser.y, rand.c, rand.h, regex.c, regex.h, share/txr/stdlib/cadr.tl, share/txr/stdlib/except.tl, share/txr/stdlib/hash.tl, share/txr/stdlib/ifa.tl, share/txr/stdlib/path-test.tl, share/txr/stdlib/place.tl, share/txr/stdlib/struct.tl, share/txr/stdlib/txr-case.tl, share/txr/stdlib/type.tl, share/txr/stdlib/with-resources.tl, share/txr/stdlib/with-stream.tl, share/txr/stdlib/yield.tl, signal.c, signal.h, stream.c, stream.h, struct.c, struct.h, sysif.c, sysif.h, syslog.c, syslog.h, txr.1, txr.c, txr.h, unwind.c, unwind.h, utf8.c, utf8.h: Add 2016 copyright. * linenoise/LICENSE, linenoise/linenoise.c, linenoise/linenoise.h: Bump one principal author's copyright from 2014 to 2015. The code is based on a snapshot of 2015 upstream work.
* Fix regression in tab completion.Kaz Kylheku2015-12-301-1/+1
| | | | | | | | | | | Same issue as with Vim syntax highlighting. * eval.c (mboundp): Externalize static function. * eval.h (mboundp): Declared. * parser.c (find_matching_syms): Expand fboundp check to encompass mboundp and special_operator_p.
* last_form_evaled must track argument evaluation.Kaz Kylheku2015-12-291-4/+3
| | | | | | | * eval.c (do_eval): Set last_form_evaled to form before evaluating the arguments, so that any errors which are not attributed to their own sub forms (such as unbound symbols) are attributed to this form.
* Propagate macro ancestry info across macrolet.Kaz Kylheku2015-12-291-1/+4
| | | | | | | | | * eval.c (expand_macrolet): Install a macro ancestor for the expansion of the macrolet. If the original form has a macro ancestor, then use that grandparent ancestor. Otherwise use the original form itself. This way intermediate macrolets which are generated by macros are abbreviated out of ancestry traces.
* Detect loop in error_trace.Kaz Kylheku2015-12-291-0/+3
| | | | | | * eval.c (error_trace): If a form has itself as its macro ancestor, bail the loop. (This only happens in deliberately contrived pathological cases, useful for testing).
* Suppress "which is located at nil".Kaz Kylheku2015-12-291-3/+9
| | | | | * eval.c (error_trace): If info is nil, print alternative message about the location being unavailable.
* Don't suppress detailed error trace for eval-error.Kaz Kylheku2015-12-291-2/+2
| | | | | | | | * eval.c (error_trace): The original idea behind the eval_error_s check is that eval errors already carry line number info, so we don't want to print redundant information. However, the scope of the detailed information has greatly increased, so we need to do this check in the loop.
* Don't record nil as the macro ancestor of a form.Kaz Kylheku2015-12-291-1/+2
| | | | | * eval.c (set_origin): Don't store nil value in the origin_hash.
* Use subtype check for eval error.Kaz Kylheku2015-12-271-1/+1
| | | | | * eval.c (error_trace): Don't check exsym for exact equality to eval-error, but whether it is a subtype.
* TXR quasiliterals and output vars treated as Lisp.Kaz Kylheku2015-12-261-7/+102
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * eval.c (format_field): Function moved here from match.c, along with the introduction of a new behavior: if a meta-expr occurs among the modifiers, its constituent expression is evaluated in its place. This allows for @{a @[expr]} which was previously not allowed in Lisp quasiliterals, but worked in TXR quasiliterals due to the treatment of @ by txeval. (subst_vars): Static function turns external, so code in match.c can call it instead of the subst_vars in that module. For that purpose, it needs to take a filter argument and process filters, like the match.c subst_vars. (op_quasi_lit): Pass nil as filter argument to subst_vars. * eval.h (format_field, subst_vars): Declared. * match.c (format_field): Function removed, moved to eval.c and slightly changed. (subst_vars): Renamed to tx_subst_vars. By default, now just a wrapper for subst_vars. In compatibility mode, invokes the old logic. (do_txeval, do_output_line): Call tx_subst_vars rather than subst_vars. * match.h (format_field): Declaration removed. * parser.y (expr): Grammar production removed: no longer referenced. (o_var): Braced variable case now parsed as n_expr, and expanded as expr by default, since this is Lisp now. In compatibility mode, expanded using expand_meta. Also SYMTOK case must be subject to expansion; an output var can now be a symbol macro. (expand_meta): Expand a quasi-literal as Lisp, except in compatibility mode. * txr.1: Bit of a documentation update. Existing doc isn't totally clear.
* New condlet macro; small change to iflet/whenlet.Kaz Kylheku2015-12-181-6/+14
| | | | | | | | | | | | | | | | | | | | | | | * eval.c (me_iflet_whenlet): Allow the test form to be an atomic expression instead of bindings. This allows iflet to be used as the sole target construct of condlet, while allowing condlet to have a fallback clause with t. It also means that an empty list of bindings is allowed (since it is the atom nil). * lisplib.c (ifa_set_entries): Add "condlet" to the autoload names for the ifa module. That's where we are adding condlet. * share/txr/stdlib/ifa.tl (sys:if-to-cond): New macro expander helper function, generalizing the writing cond-like macros based on if-like operators. (conda): Rewritten using sys:if-to-cond. (condlet): New macro. * txr.1: Documented change in iflet/whenlet. Documented condlet.
* Set macro ancestry info in place expansions.Kaz Kylheku2015-12-171-0/+7
| | | | | | | | | | | | | | | * eval.c (set_origin): New static function. (eval_init): Register set_origin as sys:set-macro-ancestor. * share/txr/stdlib/place.tl (sys:pl-expand): Set macro ancestry when expanding a place macro. (sys:cp-origin): New function. (call-update-expander, call-clobber-expander, call-delete-expander): Use sys:cp-origin to walk through expanded code and attach the place form as the macro ancestor of all the getter, setter or deleter calls, effectively to say that those calls are expansions of the place, which is approximately the case.
* Allow :whole and :form to do destructuring.Kaz Kylheku2015-12-141-7/+15
| | | | | | | | | * eval.c (bind_macro_params): Remove the restriction that the :whole and :form do not allow a destructuring pattern, requring strictly a symbol. Common Lisp's &whole also does destructuring. As a side effect of this change, the :env parameter also supports destructuring, thought this isn't going to be meaningful since macro environments aren't lists.
* symbol-function semantics change; new symbol-macro.Kaz Kylheku2015-12-101-6/+19
| | | | | | | | | | | | | | | | | | | | | | | * eval.c (symbol_function): Only retrieve function binding, and not macro or operator bindings, unless compatibility <= 127 is in effect. (symbol_macro): New function. (fboundp): Only test for existence of function, not macro or operator, unless <= 127 compatibility is in effect. (fmakunbound): Do not remove macro binding, unless compatibility <= 127 is in effect. (eval_init): Register sys:top-mb variable for use in place.tl library module. Register symbol-macro intrinsic function. * share/txr/stdlib/place.tl (sys:get-mb): New function (symbol-macro): New syntactic place. * txr.1: Updated incorrect documentation about environments from the perspective that macros and functions coexist. Documented symbol-macro. Updated symbol-function, fboundp and fmakunbound documentation. Added missing documentation for mmakunbound. Reference to fboundp under define-place-macro revised to mboundp. Added compatibility notes.
* Change representation of top-level macro bindings.Kaz Kylheku2015-12-101-6/+8
| | | | | | | | | | * eval.c (expand_macro): The expander argument is now a macro binding, which is a cons cell for built-in macros written in C also, not only for Lisp-defined macros. (symbol_function): Dereference macro binding. (reg_mac): Construct cons cell binding for built-in macro instead of sticking it into the table directly.
* Allow defmacros and defuns to co-exist.Kaz Kylheku2015-12-081-3/+0
| | | | | | | | | | | | | | | Already we have the situation that there is an if function and an if macro, and same for and and or. This change allows such situations to be programmer-defined. * eval.c (op_defun): Don't remhash the name from the toplevel macro bindings. (op-defmacro): Don't remhash the name from the toplevel function bindings. * txr.1: Document the permissive behavior as dialect notes under defmacro and defun.
* Adding mboundp and mmakunbound.Kaz Kylheku2015-12-081-0/+14
| | | | | | | | | * eval.c (mboundp, mmakunbound): New static functions. (eval_init): Registering mboundp and mmakunbound intrinsics. * txr.1: Documenting new functions. Also clarifying that fboundp checks for an operator macro binding (not a symbol macro binding).
* New function macro-ancestor.Kaz Kylheku2015-12-081-0/+1
| | | | | | | * eval.c (eval_init): Register lookup_origin as macro-ancestor intrinsic. * txr.1: Documented.
* Suppress superfluous "located at" message.Kaz Kylheku2015-11-301-9/+5
| | | | | * eval.c (error_trace): Restructure loop. Suppress "which is located at" message in first iteration.
* defun can define methods.Kaz Kylheku2015-11-301-9/+24
| | | | | | | | | | | | * eval.c (op_defun): Handle (meth type name) syntax in place of name via sys:defmeth function, which is dynamically resolved and autoloaded as necessary. (builtin_reject_test): When defun is being checked, recognize a (method ...) form and allow it. * struct.h (meth_s): Declaration added. * txr.1: Documented new defun capability.
* Refactor propagation of contexts in evaluator.Kaz Kylheku2015-11-301-58/+74
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The context form arguments become just context objects in various places. When a context form is actually needed, or the context's symbolic name, they must be retrieved via functions applied to a context. * debug.c (debug): form argument is now a context. Use the ctx_form function to retrieve the form. * debug.h (debug_check): Rename form parameter to ctx. * eval.c (ctx_form, ctx_name): New functions. (eval_error): Leftmost parameter is a context now. Use ctx_form API to obtain the context form from this object, from which the source location info can then be retrieved as before. (abbrev_ctx): Function removed. (bind_args, bindings_helper, fbindings_helper): Convert ctx_form argument to ctx, and use the API to access name or form. (do_eval, do_eval_args, eval, eval_args_lisp1, eval_lisp1, eval_progn, eval_prog1): ctx_form param renamed to ctx. (funcall_interp): Pass the original interpreted function as the context to bind_args, not the extracted code. When ctx_name sees this object, it will compute the function name, which was not possible from the code being used as the context. This is the big reason for all these changes. * eval.h (eval_error): Declaration updated. (ctx_form, ctx_name): Declared.
* Drop ctx_form param on env_vbind_special and apply.Kaz Kylheku2015-11-301-23/+23
| | | | | | | | | | | | | | | | | * eval.c (env_vbind_special): Remove unused ctx_form parameter. (bind_args, bind_macro_params): Don't pass ctx_form to env_vbind_special. (apply): Remove unused ctx_form parameter. (apply_intrinsic, applyv, mapcarv, mappendv, lazy_mapcarv_func, mapdov, do_mapf): Don't pass nil third argument to apply. * eval.h (apply): Declaration updated. * lib.c (do_juxt): Do not bind third argument of apply to lin when currying; curry as two argument function. (do_not): Do not pass third nil argument to apply.
* Change funcall_interp API.Kaz Kylheku2015-11-301-1/+3
| | | | | | | | | | | | | | * eval.c (funcall_interp): Drop the env argument. The fun argument is now the whole function object, not the encapsulated code to be interpreted. We pull the environment and code out of the object locally and interpret as before. * eval.h (funcall_interp): Declaration updated. * lib.c (generic_funcall, funcall, funcall1, funcall2, * funcall3, funcall4): Calls to funcall_interp simplified, just passing fun.