summaryrefslogtreecommitdiffstats
path: root/eval.c
Commit message (Collapse)AuthorAgeFilesLines
* * eval.c (eval_init): Register have function, synonym of true.Kaz Kylheku2015-06-201-1/+4
| | | | * txr.1: Document have.
* Adding anaphoric ifa macro.Kaz Kylheku2015-06-171-0/+5
| | | | | | | | | | | | | | | | | | | | * Makefile (install): Install .tl files present in stdlib directory. (INSTALL): Handle argument 2 being a list. * eval.c (load): New function. * eval.h (load): Declared. * lisplib.c (ifa_set_entries, ifa_instantiate): New functions to lazily load ifa.tl. (lisplib_init): Register new functions. * txr.c (stdlib_path): New variable. (sysroot_init): Store the stdlib path in stdlib_path. * txr.h (stdlib_path): Declared. * share/txr/stdlib/ifa.tl: New file.
* Lisp load macro.Kaz Kylheku2015-06-131-0/+44
| | | | | | | * eval.c (sys_load_s): New symbol variable. (sys_load, me_load): New static functions. (eval_init): Initialize sys_load_s, register sys:load intrinsic function and load macro.
* Fix mismanaged dyn_env variable.Kaz Kylheku2015-05-251-3/+4
| | | | | | | | | | * eval.c (bindings_helper): In the parallel binding case, only allocate a new dynamic env when it is needed (because a special variable is being bound), rather than unconditionally. Consequently, only modify dyn_env when the dynamic environment actually needs to be extended. Constructs that use bindings_helper are only wrapped in the dynamic environment save/restore form sys:with-saved-vars if they bind special variables.
* Ligher weight debug instrumentation.Kaz Kylheku2015-05-221-3/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This speeds up the TXR Lisp interpreter, because do_eval sets up a debug frame and uses debug_return. * debug.c (debug_block_s): Symbol removed. (debug_init): Remove initialization of debug_block_s. * debug.h (debug_block_s): Declaration removed. (debug_enter): Do not establish a named block or a catch block; no time-wasting unwind stack manipulation at all. The debug_depth variable is managed by the extended setjmp context now. Provide a return value variable, and a well-defined name to branch to to exit from the debug block. (debug_return): Do not use heavy-weight uw_block_return; simply set the return variable and branch to debug_return_out label. * signal.h (EJ_DBG_MEMB, EJ_DBG_SAVE, EJ_DBG_REST, EJ_OPT_MEMB, EJ_OPT_SAVE, EJ_OPT_REST): New macros. (extended_jmp_buf): Define optional global state variables using EJ_OPT_MEMB. (extended_setjmp): Save and restore optional globals using EJ_OPT_SAVE and EJ_OPT_RESTORE. Now debug_depth is saved and restored if debugging support is compiled in. * match.c (open_data_source): Remove bogus debug_return invocations which were uncovered here by changes to the macro. * eval.c (do_eval, expand_macro): debug_return must now be after debug_end, because it won't dynamically clean up frames that it doesn't know about. The set_dyn_env is no longer unreachable in expand_macro; it is now necessary because debug_return isn't doing the longjmp that previously restored dyn_env.
* symbol-function, symbol-value and fun become places.Kaz Kylheku2015-05-221-0/+19
| | | | | | | | | * eval.c (op_setqf): New function. (eval_init): Register sys:setqf operator. Also expose global variable hash tables via sys:top-vb and sys:top-fb. * place.tl (sys:get-fb, sys:get-vb): New functions. (fun, symbol-function, symbol-value): New places defined.
* Introduce defparm operator.Kaz Kylheku2015-05-211-0/+18
| | | | | | | | * eval.c (me_defparm): New function. (eval_init): Register defparm. * txr.1: Documented defparm together with defvar. defvar documentation is revised.
* * eval.c (symbol_value): Retrieve the binding of a symbolKaz Kylheku2015-05-151-2/+24
| | | | | | | | | | macro also. (boundp): Return t for symbol macros. (makunbound, fmakunbound): New functions. (eval_init): Register makunbound and fmakunbound. * txr.1: Document changes to symbol-value and boundp, and add dialect notes about the different semantics of binding.
* * eval.c (env_vb_to_fb): Allow null env argument. ThisKaz Kylheku2015-05-121-3/+5
| | | | case occurs when (flet () ...) is expanded.
* DWIM places must use Lisp-1 semantics.Kaz Kylheku2015-05-121-0/+33
| | | | | | | | | | | | | | | | | | | | This really only affects code which does something like (set [f x] y) and f resolves as a function. (The TXR Program bent over backwards to install a mutable object into a function binding.) In this situation, we need to update the function binding f, rather than some variable f. * eval.c (op_lisp1_setq, op_lisp1_value): New static functions. (eval_init): Register sys:lisp1-setq and sys:lisp1-value special forms. * place.tl (sys:*lisp1*): New special variable. (sys:sym-place-update-expander, sys:sym-place-clobber-expander): React to sys:*lisp1* variable by doing symbol access using Lisp-1 semantics, with help of newly introduced special forms. (dwim): Bind sys:*lisp1* to true, if main argument is a symbolic place, so that the update is done using Lisp-1 semantics. Use the sys:lisp1-value operator when evaluating arguments.
* * eval.c (lookup_var_l): Gut this function of its sillyKaz Kylheku2015-05-121-30/+6
| | | | | | | reimplementation of lookup_var. (op_setq): Use lookup_var instead of lookup_var_l. Now only outside modules use the lookup_var_l interface. Error message fix: sys:setq, not setvar.
* Fix argument count checking regression.Kaz Kylheku2015-05-111-4/+6
| | | | | | * eval.c (apply): Revert some changes from 2015-03-13 which cause the too many arguments case not to be diagnosed.
* Improve error message related to splice misuse.Kaz Kylheku2015-05-091-2/+2
| | | | | * eval.c (expand_qquote): Corrected awkward error message text which was saying that a splice "cannot occur as an atom".
* Crack down on redefinitions of built-ins.Kaz Kylheku2015-05-081-8/+44
| | | | | | | | | | | | | | | | | | | | | | | | | | | * eval.c (builtin, eval_initing): New global variable. (op_defun, op_defmacro): During initialization, record functions and macros in builtin hash. (builtin_reject_test): New static function. (expand_macrolet): Perform builtin reject test for fbind, lbind, and macrolet. (regfun, reg_mac): Add symbol to builtin hash. (eval_init): GC-protect new hash table variable and initialize it. Set eval_initing to true over eval initialization. The flip function is renamed fo flipargs. (eval_compat_fixup): New function, for dealing with the operator/function conflict over flip. * eval.h (eval_compat_fixup): Declared. * lib.c (compat_fixup): Call eval_compat_fixup. * tests/011/macros-2.txr: This test was defining a macro called while which is now illegal. Renamed to whilst. * tests/011/macros-2.expected: Regenerated. * txr.1: Function flip renamed to flipargs and documented in Compatibility section.
* * Makefile (LISP_TO_C_STRING): Strip comments, but not comment lines,Kaz Kylheku2015-05-071-2/+2
| | | | | | | | | | | | | | | | | | so line numbers don't change. * eval.c (eval_init): Fix registrations of lisp-parse and read. * lisplib.c (place_instantiate): Give name to parsed string stream using new lisp_parse argument. * parser.c (lisp_parse): Takes new argument to override name. * parser.h (lisp_parse): Declaration updated. * txr.c (txr_main): Call lisp_parse with four args, defaulting the new one. * txr.1: Documented new argument.
* New macro-based framework for assignment places.Kaz Kylheku2015-05-061-312/+55
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The operators set, inc, dec, pop and others are now macros which generate code, rather than built-in special forms that use "C magic". Moreover, new such macros are easy to write, and several new ones are already available. Moreover, new kinds of assignable places are easy to create. * place.tl: New file. * lisplib.c, lisplib.h: New files. * Makefile (OBJS): New target, lisplib.o. (GEN_HDRS): New variable. (LISP_TO_C_STRING): New recipe macro, with rule. (clean): Remove generated headers named in $(GEN_HDRS). * eval.c (dec_s, push_s, pop_s, flip_s, del_s): Variables removed. (setq_s): New variable. (lookup_var, lokup_sym_lisp_1, lookup_var_l, lookup_fun, lookup_mac, lookup_symac, lookup_symac_lisp1): Trigger the delayed loading of libraries for undefined global symbols, and re-try the lookup. (op_modplace, dwim_loc, force_l): Static functions removed. (op_setq): New static function. (eval_init): Initialize setq_s; remove initializations of removed variables; remove registrations for op_modplace; add registration for sys:setq, sys:rplaca, sys:rplacd, sys:dwim-set and sys:dwim-del intrinsics. Call lisplib_init to initialize the dynamic library loading module. * lib.c (sys_rplaca, sys_rplacd): New functions, differing in return value from rplaca and rplacd. (ref, refset): Handle hash table. (dwim_set, dwim_del): New functions. * lib.h (sys_rplaca, sys_rplacd, dwim_set, dwim_del): Declared. * genvim.txr: Include place.tl in scan. * tests/010/seq.txr: The del operator test case no longer throws at run-time but at macro-expansion time, so the test case is simply removed. * tests/010/seq.expected: Updated output. * tests/011/macros-2.txr: Reset *gensym-counter* to zero, because the textual output of the test case includes gensyms, whose numberings fluctuate with the content of the new Lisp library material. * tests/011/macros-2.expected: Updated output.
* Do some cleanup in progn-like form sequences.Kaz Kylheku2015-05-051-9/+45
| | | | | | * eval.c (expand_progn): New function. (do_expand): Use expand_progn for constructs which have an implicit progn body.
* Deal with bad quote syntax.Kaz Kylheku2015-05-031-0/+4
| | | | | | | * eval.c (op_quote): Throw error on bad syntax. * lib.c (obj_print, obj_pprint): Do not hide bad quote syntax using ' notation; print it using ordinary notation.
* Improved syntax checking: defun, flet, labels, lambda.Kaz Kylheku2015-04-291-48/+75
| | | | | | | | | | | | | | * eval.c (check_lambda_list): New static function. (op_defun): Argument list checking moved into check_lambda_list, which is called for defun out of do_expand. Name checks moved into do_expand. Thus, defun is checked earlier, at expansion time. (me_flet_labels): Check the lambda list of each lexical function with check_lambda_list. (do_expand): Check the syntax of the lambda form, and the validity of its argument list. Check the name of a defun or defmacro for validity. Check the validity of the defun argument list.
* Allow (force ...) to be an assignable place.Kaz Kylheku2015-04-251-4/+21
| | | | | | | | | | | | | | This allows mlet variables to be assignable. * eval.c (force_s): New global variable. (op_modplace): Handle force form. (me_mlet): Use force_s symbol. (force_l): New static function. (eval_init): Initialize force_s variable. Use it in registration of force function. * txr.1: Remove text in mlet definition that variables are not assignable. Replace with note about an unspecified behavior.
* Introducing mlet macro.Kaz Kylheku2015-04-251-0/+59
| | | | | | | * eval.c (me_mlet): New static function. (eval_init): Registered mlet macro. * txr.1: Documented mlet.
* delay/force overhaul.Kaz Kylheku2015-04-221-7/+30
| | | | | | | | | | | | | * eval.c (promise_forced_s, promise_inprogress_s): New symbol variables. (me_delay): Change representation of promises so that the original delay form is stashed there for better reporting in the force function. Also, propagate the debug info from the second argument of the form to the entire form; otherwise it will inherit it from elsewhere. (force): Rewritten to follow new three-state representation to detect the recursive case and diagnose it. (eval_init): Register new symbol variables.
* Improvement in error reporting.Kaz Kylheku2015-04-191-15/+10
| | | | | | | | | | | | This fix prevents certain situations when an inappropriate form is reported, in the default unhandled exception handler, as pertaining to an error. * eval.c (do_eval): Save and restore the last_form_evaled, in an exception-unsafe way. If we successfully evaluate a form or subform, we can restore the previous one. (expand): Save and restore last_form_expanded similarly. We don't need the unwind block and counter.
* Adding lcons macro.Kaz Kylheku2015-04-181-0/+17
| | | | | | | | | * eval.c (me_lcons): New function. (eval_init): Registered lcons macro. * txr.1: Documented lcons. * tl.vim, txr.vim: Regenerated.
* Adding dotimes macro.Kaz Kylheku2015-04-161-0/+21
| | | | | | | * eval.c (me_dotimes): New function. (eval_init): Registering dotimes macro. * txr.1: Documented dotimes.
* Implementing while* and until* loops.Kaz Kylheku2015-04-111-1/+27
| | | | | | | | | | | * eval.c (while_star_s, until_star_s): New symbol variables. (me_while_star, me_until_star): New static functions. (eval_init): Initialize new variables. Register while* and until* macros. * txr.1: Documented while* and until*. * txr.vim, tl.vim: Regenerated.
* * eval.c (eval_init): There is an until_s global variable, soKaz Kylheku2015-04-101-1/+1
| | | | no need to intern the symbol when registering me_until.
* * eval.c (iflet_s, when_s): New global variables.Kaz Kylheku2015-04-061-2/+22
| | | | | | | | | | | (me_iflet_whenlet): New static function. (eval_init): Initialize when_s, iflet_s. Use when_s for registering me_when. Register me_iflet_whenlet. * txr.1: Documented iflet and whenlet. * tl.vim, txr.vim: Regenerated.
* New whilet macro.Kaz Kylheku2015-04-051-2/+23
| | | | | | | | | | | * eval.c (while_s): New symbol variable. (me_whilet): New static function. (eval_init): Initialize while_s. Use while_s in registration of while macro. Register new whilet macro. * txr.1: whilet is documented. * tl.vim, txr.vim: Regenerated.
* New zap operator.Kaz Kylheku2015-04-011-1/+7
| | | | | | | | * eval.c (zap_s): New global variable. (op_modplace): Support zap. (eval_init): Initialize zap_s, and register as operator. * txr.1: Documented zap.
* Array overrun fix in apply.Kaz Kylheku2015-03-311-12/+11
| | | | | | | | | * eval.c (APPLY_ARGS): New preprocessor symbol, replaces hard-coded 32 inside apply. (apply): Use APPLY_ARGS for argument array. Fix overrun of args array in non-variadic function case when list has more than APPLY_ARGS elements. Eliminate superflous "variadic" local variable.
* Deal with spurious retention in function application.Kaz Kylheku2015-03-311-38/+40
| | | | | | | | | | | | * gc.h (zap): New inline function. (z): New macro. * lib.c (generic_funcall, funcall1, funcall2, funcall4, do_not, do_dup, do_iff): Use z macro to burn funargs with no next use. * eval.c (apply, apply_frob_args, iapply, call, do_eval, op_dwim, mapcarv, mappendv, lazy_mapcarv_func, mapdov, do_apf, do_ipf, callf): Use z macro to burn funargs with no next use.
* * eval.c (prinl, pprinl): Become external functions.Kaz Kylheku2015-03-281-2/+26
| | | | | | | | | | | (tprint): New function. (eval_init): Register tprint as intrinsic. * eval.h (prinl, pprinl, tprint): Declared. * txr.c (txr_main): New option, -t. * txr.1: Documented tprint and -t option.
* * eval.c (eval_init): register get-lines as having one optionalKaz Kylheku2015-03-281-1/+1
| | | | | | | | argument. * lib.c (lazy_stream_cons): Default the argument to std_input. * txr.1: Document that the stream is optional in get-lines.
* New ignerr macro.Kaz Kylheku2015-02-251-0/+6
| | | | | | | | | * eval.c (me_ignerr): New static function. (eval_init): Registered ignerr macro. * txr.1: Documented. * tl.vim, txr.vim: Regenerated.
* Improved error reporting, particularly for macro expansion.Kaz Kylheku2015-02-211-3/+26
| | | | | | | | | | | | | | | | | | | * eval.c (last_form_expanded): New variable. (do_expand): New static function; contains previous expand function. (expand): Becomes a wrapper for do_expand, with re-entry counting. (eval_init): GC-protect last_form_expanded. * eval.h (last_form_expanded): Declared. * parser.l (regex_parse, lisp_parse): Just use a simple word for the name of the regex or string parse location, not the entire expression itself. * unwind.c (uw_throw): Check whether expansion was going on when the unhandled exception was thrown and print additional information.
* String-returning wrappers for some regex matching functions.Kaz Kylheku2015-02-201-0/+4
| | | | | | | | | | | * eval.c (eval_init): Register search-regst, match-regst and match-regst-right intrinsics. * regex.c (search_regst, match_regst, match_regst_right): New functions. * regex.h (search_regst, match_regst, match_regst_right): Declared. * txr.1: Documented new variants.
* New functions pad and weave.Kaz Kylheku2015-02-121-0/+81
| | | | | | | | * eval.c (pad_func, pad, weave_while, weave_gen, weavev): New static functions. (eval_init): Registered pad and weave intrisics. * txr.1: Documented pad and weave.
* * eval.c (symacro_k, fun_k): New keyword variables.Kaz Kylheku2015-02-101-1/+30
| | | | | | | | | | (lexical_lisp1_binding): New static function. (eval_init): Initialize symacro_k and fun_k; register new intrinsic function lexical-lisp1-binding. * match.h (var_k): Existing external name declared. * txr.1: Documented lexical-lisp1-binding.
* * arith.c (trunc_rem): New function.Kaz Kylheku2015-02-071-0/+1
| | | | | | | | | | * eval.c (eval_init): Register trunc-rem intrinsic. * lib.h (trunc_rem): Declared. * txr.1: Documented trunc-rem. * tl.vim, txr.vim: Updated.
* Slight internal representation change of string-only exceptions.Kaz Kylheku2015-02-061-3/+1
| | | | | | | | | | | | | | | | | | | | | | | | | One upshot of all this is that (throw 'foo "msg") now does exactly the same thing as (throwf 'foo "msg"). A message-only exception really is a one-string exception argument list ("message ..."), like the documentation says. * unwind.h (struct uw_catch): exception member renamed to args. (uw_catch): Macro follows structure member rename. * eval.c (op_catch): Removed now unnecessary kludge of turning non-list exception argument list into a one-element argument list. * match.c (v_try): Similar hack to the one in op_catch removed here. * unwind.c (uw_unwind_to_exit_point, uw_push_catch): Follows rename of exception member. (uw_throw): The exception parameter is renamed to args. The kludge removed from op_catch re-appears here, because numerous calls to uw_throw just pass a string as args. It's less of a kludge here because this is the master entry point to exception processing, and it straightens out the representation right away. The exception arguments or message are printed in a clearer way.
* Serious bugfix in the op macro, and derived macro, inKaz Kylheku2015-02-061-3/+1
| | | | | | | | | | | the handling of missing meta-numbers (for instance (op ... @1 .. @3): 1 and 3 occur, but not 2. * eval.c (supplement_op_syms): Bugfix: loop was testing and updating the wrong variable, causing it to be looking at the first element of the syms list in every iteration. Not a regression: this was implemented wrong when the function was introduced on October 6, 2013.
* * eval.c (subst_vars): Bugfix. When an ordinary variableKaz Kylheku2015-02-061-12/+2
| | | | | | | | | | | occurs in the quasi syntax (which is the result of substitution of metanums like @1 by the op macro), if that variable evaluated to a list form, it was not being converted to a string. The resulting form was then examined for variable substitutions as if it were part of the quasi syntax. This was introduced at the same time as the feature of being able to use metanums in a quasiliteral (Feb 13, 2012: last change before Version 57).
* * eval.c (transform_op): When expanding @rest and metanumsKaz Kylheku2015-02-061-2/+6
| | | | | | | like @1, @2, preserve the (sys:var X args ..) structure if there are args (but of course with X replaced by the appropriate gensym). This allows syntax like `@{1 10}` to work in quasiliterals: in other words, modifiers on interpolated metas, on par with @{a 10}.
* Symbol macros shadowed by functions under dwim.Kaz Kylheku2015-02-031-0/+68
| | | | | | | | | | | * eval.c (lookup_symac_lisp1, expand_lisp1, expand_forms_lisp1): New static functions. (expand): Handle dwim's arguments via expand_forms_lisp1, rather than as a generic compound form. * txr.1: Revised text in several places to clarify this expansion rule.
* 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.
* * arith.c (make_ubignum): New static function.Kaz Kylheku2015-01-291-0/+1
| | | | | | | | | | | | (sign_extend): New function. * eval.c (eval_init): Register sign-extend intrinsic. * lib.h (sign_extend): Declared. * txr.1: Documented sign-extend. * tl.vim, txr.vim: Updated.
* * eval.c (get_opt_param_syms): Fix broken function. ThisKaz Kylheku2015-01-281-9/+8
| | | | | | was choking on keywords like :env in the lambda list, and failing to handle the nested patterns of macro lambda lists. Failing case: (defmacro x (: opt :env foo)).
* * eval.c (bind_macro_params): Bugfix: the colon argument's specialKaz Kylheku2015-01-281-1/+1
| | | | | meaning "treat the argument as missing" must apply only to optional parameters.
* * arith.c (width): New function.Kaz Kylheku2015-01-271-0/+1
| | | | | | | | * arith.h (width): Declared. * eval.c (eval_init): Width registered as intrisinc. * txr.1: Documented width.