summaryrefslogtreecommitdiffstats
path: root/eval.c
Commit message (Collapse)AuthorAgeFilesLines
* * debug.c (help): Added missing help for w command.Kaz Kylheku2012-01-211-3/+4
| | | | | | | | | | | | | | | | | | | | (debug): In backtrace, show the renaming pairs for unbound variables (up_p_a_pairs) if they are present. * debug.h (debug_begin): Renamed to debug_frame. * eval.c (eval): Wrap debug_begin/debug_end around function dispatch, so TXR Lisp functions are included in backtraces. * match.c (h_fun): Follow rename of debug_begin to debug_frame. Pass in evaluated args, not the original ones. (v_fun): Likewise. * unwind.c (uw_push_debug): bindings argument renamed to env. Bugfix: args argument was being assigned to ub_p_a_pairs. * unwind.h (struct uw_debug): Member bindings renamed to env. (uw_push_debug): Declaration updated.
* Improved debugging. Debug nesting depth counter maintainedKaz Kylheku2012-01-211-9/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | and used for next/step/finish stepping. * Makefile (OBJS): debug.o moved to OBJS-y or OBJS-. (OBJS-y, OBJS-): New variables. $(PROG): Depends on OBJS-y also. clean: clean $(OBJS-y). depend: include $(OBJS-y) in dependency generation. * configure: Underscores and dashes are interchangeable in configure variables. (yaccname_given, yacc_given): Default value is y, not yes. (debug_support): New config variable. (CONFIG_DEBUG_SUPPORT): New config.h symbol. * debug.c (debug_depth): New global variable. (debug_block_s): New symbol variable. (next_depth): New static variable. (debug): Renamed some commands. Introduced separate next, step and finish. (debug_init): debug_block_s initialized. * debug.h (debug_depth, debug_block_s): Declared. (debug_enter, debug_leave, debug_return): New macros. (debug_check, debug_init): Conditionally defined based on if this is a debug build. * dep.mk: Regenerated. * eval.c (eval): Instrumented with debug_enter, debug_leave, debug_return. * match.c (match_line, v_fun, match_files): Likewise. * txr.c (txr_main): Bail if -d or --debug used in build that lacks debug support.
* * debug.c (last_command): Initialize to empty string ratherKaz Kylheku2012-01-191-1/+1
| | | | | | | | | | | | | than nil, otherwise hitting enter tries to repeat the nil command. (show_bindings): New function. Prints all levels of bindings. (debug): Flip the corresponding print flags after printing the current form or data, so they are not printed for every prompt. On EOF from standard input, substitute the q command. If enter is hit and there is no last command, just re-print the prompt. The v command uses show_bindings to dump the environment. * eval.c (eval): When calling debug_check, pass the env objects, rather than the bindings it contains.
* * eval.c (eval_init): Make lazy_appendv functionKaz Kylheku2012-01-121-0/+1
| | | | | | available as append*. * txr.1: Documented.
* Before releasing 53, there is this.txr-53Kaz Kylheku2012-01-111-1/+2
| | | | | | | * eval.c (c_var_mark): Bugfix: we cannot use cptr_get from within the garbage collector because of its type check. Bugfix: synchronize the shadow binding with the variable's current contents so we don't hang on to a stale object.
* TXR Lisp regression in C global variables.Kaz Kylheku2012-01-111-6/+34
| | | | | | | | | | | * eval.c (struct c_var): New struct type. (lookup_var, lookup_var_l): cptr type bindings now point to a struct c_var, which has to be handled properly here. (c_var_mark): New static function. (c_var_ops): New static struct. (reg_var): Register variables using struct c_var to provide a pointer to the location and a cached cons that can be returned as a binding.
* * eval.c (each_s, each_star_s, collect_each_s, collect_each_star_s):Kaz Kylheku2012-01-111-2/+59
| | | | | | | | | | | New symbol variables. (op_each): New static function. (expand): Handle the four new operators. (eval_init): Intern new symbols, register new operators. * txr.1: Documented each, each*, collect-each and collect-each*. * txr.vim: Updated.
* * eval.c (eval_init): list_str registered.Kaz Kylheku2012-01-111-0/+1
| | | | | | | | | | * lib.c (list_str): New function. * lib.h (list_str): Declared. * txr.1: Doc stub section created. * txr.vim: Updated.
* * eval.c (generate): Bugfix: do not call gen_fun beforeKaz Kylheku2012-01-101-1/+1
| | | | testing while_pred.
* * eval.c (tostring, tostringp): New static functions.Kaz Kylheku2012-01-101-0/+16
| | | | | | | | (eval_init): New functions registered. * txr.1: Stub sections created. * txr.vim: Updated.
* Spat of new features having to do with lazy processing.Kaz Kylheku2012-01-101-5/+223
| | | | | | | | | | | | | | | | | | | | | | | | * eval.c (prog1_s, gen_s, generate_s, delay_s, promise_s): New symbol variables. (eval_prog1, op_prog1, expand_gen, expand_delay): New static functions. (expand): Handle gen and delay. (lazy_mapcar_func, lazy_mapcar, lazy_mapcarv_func, lazy_mapcarv, lazy_mappendv): New static functions. (rangev_func, rangev, generate_func, generate, repeat_infinite_func, repeat_times_func, repeatv, force): New static functions. (eval_init): New operators and functions interned. lazy-flatten renamed to flatten*. * lib.c (null_f): New global variable. (ltail, lazy_appendv): New functions. (lazy_appendv_func): New static function. (obj_init): null_f protected and initialized. * lib.h (null_f, ltail, lazy_appendv): Declared. * txr.1: Documented. * txr.vim: Updated.
* Non-broken way to achieve intent of previous commit.Kaz Kylheku2012-01-091-2/+4
| | | | | | | | | | | | | | * eval.c (subst_vars): Do not evaluate modifiers as an argument list locally. Pass form-evaluating function to format_field. * match.c (format_field): Modified to accept new argument, a one-argument function for reducing a form to a value. Error checking for invalid modifiers made stricter. (subst_vars): Do not evaluate modifiers as an argument list. Pass form-evaluating function to format_field. * match.h (format_field): Declaration updated.
* * eval.c (subst_vars): Evaluate theKaz Kylheku2012-01-091-1/+1
| | | | | | | modifiers, so expressions can be used. * match.c (subst_vars): Likewise, but using txeval.
* * eval.c (eval_init): Missing documented memql function registered.Kaz Kylheku2012-01-071-0/+1
| | | | * txr.vim: Updated with numerous missing symbols.
* * eval.c (eval_init): Fix regression introduced inKaz Kylheku2012-01-021-1/+1
| | | | | 2011-12-29 commit. We can't use mod_s, because the module which sets up that variable is not yet initialized.
* Make C globals in TXR Lisp properly assignable, so that for instanceKaz Kylheku2012-01-011-14/+36
| | | | | | | | | | | | | | | assigning *stdout*, it really overwrites the underlying C variable. * eval.c (lookup_var): Handle new kind of toplevel binding. If the hash value is a cptr, it points to a val storage location. (lookup_val_l): New function. (op_modplace): Get location of variable using lookup_val_l rather than assuming there is a cons-based binding. (reg_var): Argument changed to val * pointer. Register the variable as a cptr referencing the location. (eval_init): reg_var calls pass address of each global. * eval.h (lookup_var_l): Declared.
* * eval.c (eval_init): New gensym function registered.Kaz Kylheku2012-01-011-0/+1
| | | | | | | | * lib.c (gensym_counter): New variable. (gensymv): New function. (obj_init): Initialize gensym_counter. * lib.h (gensym_counter, gensymv): Declared.
* New functionality: mod and modlast directives in repeat and rep.Kaz Kylheku2011-12-291-1/+1
| | | | | | | | | | | | | | | | | | | | | | * eval.c (eval_init): Use new symbol variable mod_s instead of calling intern. * match.c (mod_s, modlast_s): Symbol variables defined. (do_output_line): mod and modlast directives implemented under rep. (do_output): likewise under repeat. (syms_init): Initialize new symbol variables. * match.h (mod_s, modlast_s): Declared. * parser.l (MOD, MODLAST): Parse new token types. * parser.y (MOD, MODLAST): New tokens. (repeat_parts_opt, rep_parts_opt): New syntax. (repeat_rep_helper): Handle mod and modlast syntax. * txr.1: Updated. * txr.vim: Updated.
* * eval.c (eval_init): New function interned.Kaz Kylheku2011-12-251-0/+1
| | | | | | | | | | | | | * lib.c:x (lazy_flatten_scan, lazy_flatten_func): New static functions. (lazy_flatten): New function. * lib.h (lazy_flatten): Declared. * match.c (v_next): Use lazy_flatten instead of flatten for processing a :list source. This means that @(next :list ...) can be used to process infinite lazy lists. * txr.1: Documented lazy-flatten.
* * Makefile (OBJS): new object file, rand.o.Kaz Kylheku2011-12-211-0/+7
| | | | | | | | | | | | * eval.c: Includes rand.h header. (eval_init): New variable and functions from rand module registered. * lib.c: Includes rand.h header. (init): Call rand_init. * rand.c: New file. * rand.h: New file.
* * eval.c (eval_init): New function registered.Kaz Kylheku2011-12-201-0/+1
| | | | | | | | * lib.c (cat_vec): New function. * lib.h (cat_vec): Declared. * txr.1: Documentation stub.
* Streamlining exception handling macros a little bit.Kaz Kylheku2011-12-201-6/+3
| | | | | | | | | | | | | | | | | | | | | | * eval.c (op_unwind_protect): Use uw_simple_catch_begin, and remove the uw_catch (exsym, exvals) clause. Put explicit braces around the unwind code even though it is only one statement. * match.c (do_txeval): Got rid of empty uw_unwind clause. This is not needed any longer. (v_try): Got rid of explicit uw_do_unwind calls. * unwind.h (uw_simple_catch_begin): New macro. (uw_do_unwind): Macro removed. (uw_catch): Added goto uw_unwind_label at the front. This way if the previous clause falls through, control goes to the unwind logic. (uw_unwind): Got rid of initial break. Previous clause should fall through to unwind logic, whether it is the main clause, or one of the catches. (uw_catch_end): Default case aborts, because we don't expect this.
* * eval.c (eval_init): New functions registered as intrinsics.Kaz Kylheku2011-12-201-0/+2
| | | | | | | | * lib.c (copy_vec, sub_vec): New functions. * lib.h (copy_vec, sub_vec): Declared. * txr.1: Stub sections created.
* * eval.c (subst_vars, op_quasi_list, expand_quasi): New staticKaz Kylheku2011-12-191-0/+95
| | | | | | | | | | functions. (expand): New case for quasiliterals. (eval_init): Register quasi literal as special operator. * match.c (format_field): Linkage changed to external. * match.h (format_field): Declared. Declarations rearranged.
* * eval.c (bindings_helper): Fix format arguments.Kaz Kylheku2011-12-181-2/+13
| | | | | | | | | | | | | | | | | (eval_init): Registered new functions: symbol-function, func-get-form, func-get-env, functionp, interp-fun-p. * lib.c (nappend2, getplist_f, improper_plist_to_alist): tail variable renamed to avoid clash in macro. (func_get_form, func_get_env, interp_fun_p): New functions. * lib.h (func_get_form, func_get_env, interp_fun_p): Declared. (list_collect): Fix macro not to throw error, but handle the case. * match.c (vars_to_bindings, extract_bindings): tail variable renamed to avoid clash in macro. * txr.1: Documentation stubs.
* * eval.c (expand_vars): Bugfix: use expand_forms rather thanKaz Kylheku2011-12-161-1/+1
| | | | expand on a list of forms.
* * eval.c (eval_init): not added as synonym for null.Kaz Kylheku2011-12-151-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | * lib.c (copy_list): Use list_collect_append rather than list_collect_terminate. (append2, appendv): Simplified using new list_collect_append. (nappend2): Simplified using new list_collect_nconc. * lib.h (list_collect): Added check for accidental usage of list_collect after list_append, since PTAIL has different semantics. (list_collect_nconc, list_collect_append): Semantics fixed so that append collecting works more like the Common Lisp append function, allowing trailing atoms or a lone atom. The meaning of PTAIL is changed, however. Now PTAIL actually tracks the head of the most recently appended segment. Each append operation has to first traverse the previously added piece to get to the end. (list_collect_terminate): Macro removed. * match.c (v_gather): Removed useless use of list_collect_terminate. * parser.y: Some headers added that are needed by list_collect. * txr.1: Documented append, list, atom, null, not, consp, make-lazy-cons, lcons-fun, listp, proper-listp, length-list, mapcar, mappend, and apply.
* * eval.c (eval_init): Removed registration for vec_get_fil.Kaz Kylheku2011-12-141-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | Renamed vec_set_fill to vec-set-length. * hash.c (equal_hash): vec_fill to vec_length name change. (hash_grow, make_hash): No need to call vec_set_length. * lib.c (equal, vecref, vec_push, length_vec, list_vector, obj_print, obj_pprint): vec_fill to vec_length name change. (vector): Argument now represents actual length, not just allocated size. (vec_get_fill): Function removed; did exactly the same thing as length_vec. (vec_set_fill): Function renamed to vec_set_length. (vector_list): Allocate a 0 length vector initially. * lib.h (enum vecindex): member changes name from vec_fill to vec_length. (vector): Parameter name changed. (vec_set_fill): Redeclared. (vec_get_fill): Declaration removed. * txr.1: Doc stubs updated.
* * eval.c (op_dohash): Esbatlish anonymous block.Kaz Kylheku2011-12-141-1/+7
| | | | * txr.1: Finished documenting special operators.
* * arith.c (plus, minus, gt, lt, ge, le): Handle character operands.Kaz Kylheku2011-12-141-0/+2
| | | | | | | | | | * eval.c (eval_init): New functions interned. * lib.c (num_chr, chr_num): New functions. * lib.h (num_chr, chr_num): Declared. * txr.1: Documentation stubs.
* * arith.c (exptmod, gcd): New functions.Kaz Kylheku2011-12-131-0/+2
| | | | | | | | * eval.c (eval_init): New functions registered as intrisics. * lib.h (exptmod, gcd): Declared. * txr.1: Documentation stubs added.
* * arith.c (evenp, oddp): New functions.Kaz Kylheku2011-12-131-0/+2
| | | | | | | | * eval.c (eval_init): New functions registered as intrinsics. * lib.h (evenp, oddp): Declared. * txr.1: Documentation stub updated.
* * arith.c (highest_bit): Linkage changed to static.Kaz Kylheku2011-12-131-0/+3
| | | | | | | | | | | | | | | | | (abso, isqrt): New functions. (isqrt_fixnum): New static function. * eval.c (eval_init): Registered abs, sqrt and numberp instrinsics. * lib.c (numberp): New function. * lib.h (numberp, abso, isqrt): Declared. * mpi-patches/series: New patch added. * mpi-patches/faster-square-root: New patch added. * txr.1: Documentation stubs for new functions.
* * arith.c (expt): New function.Kaz Kylheku2011-12-121-0/+3
| | | | | | | | | | | | * eval.c (eval_init): Registering new intrinsic functions, reduce-left, reduce-right and expt. * lib.c (minusv): Return one instead of num(1). (exptv, reduce_right): New functions. * lib.h (expt, exptv, reduce_right): Declared. * txr.1: Blank sections for new functions.
* * arith.c (zerop, gt, lt, ge, le): Functions from lib.c reimplementedKaz Kylheku2011-12-111-0/+2
| | | | | | | | | | | | | | | with bignum support. * eval.c (eval_init): Added bignump and zerop as intrinsic function. Renamed numberp to fixnump. * lib.c (zerop, gt, lt, ge, le): Functions removed. (numeq): Unused function removed. * lib.h (numeq): Declaration removed. * txr.1: Sections for zerop and bignump created. Changed reference to numberp to fixnump.
* * eval.c (eval_init): New functions added as intrinsics.Kaz Kylheku2011-12-101-0/+2
| | | | | | | | * hash.c (hash_eql, hash_equal): New external functions. * hash.h (hash_eql, hash_equal): Declared. * txr.1: Sections added.
* Bignum support, here we go!Kaz Kylheku2011-12-091-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Bignums, based on Michael Fromberger's MPI library, are integrated into the input syntax, stream output, equality testing, the garbage collector, and hashing. The plus operation handles transitions between fixnums and bignums. Other operations are still fixnum only. * Makefile (CFLAGS): Add mpi directory to include file search. (OBJS): Include new arith.o module and all of MPI_OBJS. (MPI_OBJS, MPI_OBJS_BASE): New variables. * configure (mpi_version, have_quilt, have_patch): New variables. Script detects whether patch and quilt are available. Unpacks mpi library, applies patches. Detects 128 bit integer type. Records more information in config.h about the sizes of types. * dep.mk: Updated. * depend.txr: Make work with paths that have directory components. * eval.c (eval_init): Rename of nump to fixnump. * gc.c (finalize, mark_obj): Handle BGNUM case. * hash.c: (hash_c_str): Changed to return unsigned long instead of long. (equal_hash): Handle BGNUM case. (eql_hash): Handle bignums with equal-hash, but other objects as eq. * lib.c (num_s): Variable renamed to fixnum_s. (bignum_s): New symbol variable. (code2type): Follow rename of num_s. Handle BGNUM case. (typeof): Follow rename of num_s. (eql): Handle bignums using equal, and other types using eq. (equal): Handle BGNUM case. (chk_calloc): New function. (c_num): Wording change in error message: is not a fixnum. (nump): Renamed to fixnump. (bignump): New function. (plus): Function removed, reimplemented in arith.c. (int_str): Handle integers which are too large for wcstol using bignum conversion. Base 0 is no longer passed to wcstol but converted to 10 because the special semantics for 0 would be inconsistent for bignums. (obj_init): Follow rename of num_s. Initialize bignum_s.
* C++ maintenance.Kaz Kylheku2011-12-081-3/+1
| | | | | | * eval.c (and_s, or_s): Redundant variables removed. * match.h (do_s): extern storage class specifier added.
* * eval.c (op_defun): Transform a function body by insertingKaz Kylheku2011-12-071-2/+12
| | | | | | | | a named block around it, thereby imitating a Common Lisp feature. (op_for): Establish an anonymous block around the loop body, test form and increment forms. * txr.1: Documented named block in defun. Documented for and for *.
* * eval.c (op_modplace): If the operator is push, then reverseKaz Kylheku2011-12-071-9/+26
| | | | | | | the arguments. We want (push item list) for compatibility with CL. (expand): Bugfix: some of the cases were constructing new forms using unexpanded pieces from the original form. Added separate case for push, which handles the reversed arguments.
* * debug.c (debug): Fix regression: repeat last command by hittingKaz Kylheku2011-12-071-7/+33
| | | | | | | | | | | | | | | | | | | | | | | | Enter stopped working. This was broken by recent bugfixes in the string splitting functions, which introduced a semantics change. * eval.c (flip_s, vecref_s): New symbol variables. (op_modplace): New places (vecref ...) and (flip ...). Bugfix: dec operator was incrementing. (expand_place): Handle vecref and flip. Bugfix: pop has no third argument and so is now handled by the same case as flip. Bugfix: if a modify form has no third argument, then do not resynthesize it with a nil third argument. (eval_init): Initialize new symbol variables. Register new flip operator. Register new list_vectory function as intrinsic. * lib.c (rplacd): When modifying the cdr field of a lazy cons, then lapse the lazy function to nil! This is needed by user-defined lazy conses, and it makes sense to do it this way rather than put in some explicit interface. (list_vector): New function. * lib.h (list_vector): Declared.
* * eval.c (lookup_var, lookup_fun): Reversing assoc arguments.Kaz Kylheku2011-12-071-2/+17
| | | | | | | | | | | | | | | | | | | | | | | (eval_init): New intrinsics. * hash.c (struct_hash): assoc_fun parameters reversed. (gethash, gethash_f, gethash_n): Likewise. * lib.c (assoc, assq): Reversing parameters. (find_package, acons_new, acons_new_l, aconsq_new): Reversing arguments to assoc adn assq. * lib.h (assoc, assq): Declarations updated. * match.c (dest_set, dest_bind, h_var, h_coll, h_parallel, h_fun, subst_vars, do_txeval, v_next, v_parallel, v_gather, v_collect, v_flatten, v_cat, v_output, v_filter, f_fun, match_funcall): Reversing arguments to assoc. * unwind.c (uw_get_func, uw_exception_subtype_p, uw_register_subtype): Reversing arguments to assoc. * txr.1: Blank sections created for new functions.
* * eval.c (eval_init): New functions registered as intrinsics.Kaz Kylheku2011-12-071-0/+2
| | | | | | * lib.c (chr_toupper, chr_tolower): New functions. * lib.h (chr_toupper, chr_tolower): New functions declared.
* * eval.c (eval_init): New character functions registered.Kaz Kylheku2011-12-071-0/+12
| | | | | | | | | | | | | * lib.c (c_num): Generalized to convert characters to numbers also. This allows functions like gt and lt to work with characters. (chr_isalnum, chr_isalpha, chr_isascii, chr_iscntrl, chr_isdigit, chr_isgraph, chr_islower, chr_isprint, chr_ispunct, chr_isspace, chr_isupper, chr_isxdigit): New functions added. * lib.h: (chr_isalnum, chr_isalpha, chr_isascii, chr_iscntrl, * chr_isdigit, chr_isgraph, chr_islower, chr_isprint, chr_ispunct, * chr_isspace, chr_isupper, chr_isxdigit): New functions declared. (c_true): New macro.
* Comment change.Kaz Kylheku2011-12-071-1/+1
|
* * eval.c (progn_s): New symbol variable.Kaz Kylheku2011-12-071-1/+8
| | | | | | | (op_progn): New static function. (eval_init): Initialize new variable, register progn operator. * txr.1: progn documented.
* * eval.c (op_unwind_protect): Fixed uninitialized variableKaz Kylheku2011-12-061-2/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | warning. (eval_init): New functions registered: typeof and vector functions, as well as length_list. * lib.c (length): Function renamed to length_list, because it is list specific. (length_vec, size_vec, vector_list): New functions. (length): New function, generic over lists, vectors and strings. * lib.h (length_list, length_vec, size_vec, vector_list): Declared. * match.c (h_var, h_fun, robust_length, v_deffilter, v_fun): Use length_list instead of length. * parser.l: Introduced # token. * parser.y (vector): New nonterminal. (expr): vector is a kind of expr. (chrlist): Bugfix: single-character syntax was not working; for instance #\x to denote the charcter x. (lit_char_helper): Use length_list instead of length. * stream.c (string_in_get_line): Bugfix: this was using the wrong length function: length was being applied to a string. The genericity of length makes that correct now, but changing to length_str anyway. * txr.1: Blank sections created for functions. Vector syntax documented.
* * eval.c (op_cond): Fixed behavior for singleton clauses.Kaz Kylheku2011-12-051-8/+11
| | | | | | | | | | (eval_init): Use existing function objects car_f, cdr_f, eq_f, eql_f and equal_f. Added identity to function table. * lib.h (eql_f): Missing declaration added. * txr.1: Documented cond, and, if, or, defun, inc, dec, set, push and pop.
* * eval.c (op_qquote_error, op_unquote_error): New static functions.Kaz Kylheku2011-12-041-0/+19
| | | | | | | | | | | | | (expand_qquote): Bugfix: missing case added to handle directly quoted quasiquote. (eval_init): Error-catching pseudo-operators registered in op_table. * parser.y (force_regular_quotes): New function. (list): Quotes within unquotes and splices are regular. * txr.1: Clarified new rules. Removed description of ,'form and ,*'form special syntax.
* Expose lazy lists in TXR Lisp.Kaz Kylheku2011-12-031-0/+4
| | | | | | | | | | | | | | | * eval.c (eval_init): New intrinsic functions. * lib.c (rplaca, rplacd, lcons_fun): New functions. (make_lazycons): Renamed to make_lazy_cons, relocated and turned into external function. (lazy_stream_func, lazy_stream_cons): Follow rename of make_lazycons. * lib.h (rplaca, rplacd, make_lazy_cons, lcons_fun): Declared. * txr.1: Stub sections created.