summaryrefslogtreecommitdiffstats
path: root/eval.c
Commit message (Collapse)AuthorAgeFilesLines
* Fix wrongly named hash_lit_s symbol.Kaz Kylheku2015-09-011-1/+1
| | | | | * eval.c (eval_init): Fix wrong name of hash_lit_s symbol; it should be sys:hash-lit and not sys:hash-construct.
* Time structure.Kaz Kylheku2015-08-311-0/+2
| | | | | | | | | | | | | * eval.c (eval_init): Register time-struct-local and time-struct-utc intrinsic funtions. * lib.c (time_s, year_s, month_s, day_s, hour_s, min_s, sec_s): New global symbol variables. (broken_time_struct, time_init): New static functions. (time_struct_local, time_struct_utc): New functions. (init): Call time_init. * lib.h (time_struct_local, time_struct_utc): Declared.
* Introducing structs.Kaz Kylheku2015-09-021-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * args.c (args_cat_zap): New function. * args.h: (args_cat_zap): Declared. * eval.c (struct_lit_s): New symbol variable. (eval_init): Initialize struct_lit_s. * eval.h (struct_lit_s): Declared. * gc.c (finalize): If a symbol has a struct slot hash attached to it, we must free it when the symbol is reclaimed. * lib.c (make_sym): Initialize symbol's slot_cache pointer to null. (copy): Copy structure objects. (init): Call struct_init to initialize struct module. * lib.h (SLOT_CACHE_SIZE): New preprocessor symbol (slot_cache_line_t, slot_cache_t): New typedefs. (struct sym): New member, slot_cache. * lisplib.c (struct_set_entries, struct_instantiate): New static functions. (liplib_init): Register new functions in dl_table. parser.y (HASH_S): New terminal symbol. (struct): New grammar rule. (n_expr): Derive struct. (yybadtoken): Map HASH_S to #S string. parser.l (grammar): Recognize #S and return HASH_S token. share/txr/stdlib/place.tl (slot): New defplace. share/txr/stdlib/struct.tl: New file. struct.c: New file. struct.h: New file. * Makefile (OBJS): Adding struct.o.
* Renaming c_true to tnil.Kaz Kylheku2015-08-271-2/+2
| | | | | | | | | | | | | | | | | | | | Macros called c_* should produce C counterparts of Lisp val objects, like c_num and c_str. * lib.h (c_true): Renamed to tnil. * eval.c (lexical_var_p, lexical_fun_p): c_true to tnil. * lib.c (less, chr_isalnum, chr_isalnum, chr_isalpha, chr_isascii, chr_iscntrl, chr_isdigit, chr_isgraph, chr_islower, chr_isprint, chr_ispunct, chr_isspace, chr_isblank, chr_isunisp, chr_isupper, chr_isxdigit, chr_toupper, keywordp): Likewise. * stream.c (catenated_stream_p): Likewise. * sysif.c (wifexited, wifsignaled, wcoredump, wifstopped, wifcontinued): Likewise.
* Replace two-step initialization of args with macros.Kaz Kylheku2015-08-241-15/+8
| | | | | | | | | | | | | | | | | | | | | * args.h (args_init_list, args_init): Return the struct args * pointer. (args_decl_list, args_decl): New macros. * eval.c (apply, do_eval, expand_macro, op_dwim, op_catch, (mapcarl, lazy_mapcarl): Switch to new macros. * hash.c (hashl): Likewise. * lib.c (generic_funcall, lazy_appendl, maxl, minl, funcall, funcal1, funcall2, funcall3, funcall4, transpose, juxtv, do_and, do_or, do_iff, unique): Likewise. * match.c (h_fun, v_fun): Likewise. * stream.c (vformat): Likewise. * syslog.c (syslog_wrap): Likewise.
* Compatibility <= 107 allows redefinition of builtins.Kaz Kylheku2015-08-241-0/+2
| | | | | | | | * eval.c (builtin_reject_test): Suppress the diagnostic against redefinition of built-in macros and operators if the compatibility is 107 or lower. The rejection appeared in 108. * txr.1: Document this compatibility behavior.
* New function: shuffle.Kaz Kylheku2015-08-241-0/+1
| | | | | | | | * eval.c (eval_init): Register shuffle as intrinsic. * lib.c (shuffle): New function. * lib.h (shuffle): Declared.
* Use of new args for function calls in interpreter.Kaz Kylheku2015-08-231-18/+49
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * args.c (args_copy_to_list): New function. * args.h (ARGS_MIN): New preprocessor symbol. (args_add_list): New inline function. (args_copy_to_list): Declared. * debug.c (debug): Args in debug frame are now struct args *. Pull them out nondestructively for printing using args_copy_to_list. * eval.c (do_eval_args): Fill struct args argument list rather than returning evaluated list. Dot position evaluation is handled by installing the dot position value as args->list. (do_eval): Allocate args of at least ARGS_MAX for the call to do_eval_args. Then use generic_funcall to invoke the function rather than apply. (eval_args_lisp1): Modified similarly to do_eval_args. (eval_lisp1): New static function. (expand_macro): Construct struct args argument list for the sake of debug_frame. (op_dwim): Allocate args which are filled by eval_args_lisp1, and applied to the function/object with generic_funcall. The object expression is separately evaluated with eval_lisp1. * match.c (h_fun, v_fun): Construct struct args arglist for the sake of debug_frame call. * unwind.c (uw_push_debug): args argument becomes struct args *. * unwind.h (struct uw_debug): args member becomes struct args *. (uw_push_debug): Declaration updated. * txr.1: Update documentation about dot position argument in function calls. (list . a) now works, which previously didn't.
* Large scale conversion to new way of handling arguments.Kaz Kylheku2015-08-231-199/+118
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Function arguments are now allocated on the stack using alloca, in conjunction with the struct alloc header structure. The generic_funcall and apply functions are refactored for this, as are most functions that take variadic arguments. * args.c (args_add_list, args_cons_list): Functions removed. (args_normalize, args_normalize_fill): New functions. (args_get_checked): Draw arguments from list when array runs out. (args_copy, args_copy_zap): New functions. * args.h (ARGS_MAX): Reduced to 32. (ARGS_MIN): New preprocessor symbol. (args_init): Call args_init_list. (args_add2, args_add3, args_add4): New inline functions. (args_more): Take into account list, which may hold additional arguments. (args_two_more): New inline function. (args_normalize, args_normalize_fill): Declared. (args_get_list): Normalize all arguments into one list and return it. (args_get_rest, args_at, args_atz): New inline functions. (args_get): Draw arguments from list when array runs out. (args_clear): New inline function. * arith.c (maskv): Convert to new args. * eval.c (APPLY_ARGS): Preprocessor symbol removed. (bind_args): Converted to accept struct args. (apply): Function reduced down to trivial adapter which converts a list of arguments to args, and calls the new generic_funcall. (applyv): New static function: struct args wrapper around apply_intrinsic. (iapply): Converted to struct args. (call): Static function removed. The call intrinsic function binding now goes directly to generic_funcall. (list_star_intrinsic, interp_fun): Converted to struct args. (op_catch): Adjustments for bind_args, which requires a struct args arglist. (me_op): Must use the new minl and maxl, since minv and maxv don't take lists any more. (mapcarv, mappendv, lazy_mapcarv, lazy_mappendv, mapdov, weavev, or_fun, and_fun, tf, nilf, do_retf, do_apf, do_ipf, callf, do_mapf, mapf): Converted. (mapcarl): New function, like the old mapcarv. (eval_init): call_f initialized from generic_funcall rather than call. apply registered to applyv rather than apply_intrinsic. Registrations for zip, hash_from_pairs, vec, alist-remove, alist-nremove, and throw similarly updated to new or renamed functions. * eval.h (interp_fun, mapcarv): Declarations updated. (mapcarl): Declard. * hash.c (hashv): Converted to struct args. (hashl): New function. (hash_construct): Use hashl, not hashv. (hash_from_pairs, hash_list, group_by): Converted. * hash.h (hashv, hash_construct, hash_from_pairs, hash_list, group_by): Declarations updated. (hashl): Declared. * lib.c (appendv, nconcv, lazy_appendv): Converted to struct args. (lazy_appendl): New function. (multi): Converted. (listv): New function. (nary_op, plusv, mulv, logandv, logiorv, gtv, ltv, gev, lev, numeqv, numneqv, maxv, minv): Converted. (maxl, minl): New functions, like old maxv and minv. (exptv, gcdv, lcmv, lessv, greaterv, lequalv, gequalv): Converted. (func_f0v, func_f1v, func_f2v, func_f3v, func_f4v): Converted. (func_n0v, func_n1v, func_n2v, func_n3v, func_n4v): Converted. (func_n0v, func_n1v, func_n2v, func_n3v, func_n4v): Converted. (func_n1ov, func_n2ov, func_n3ov): Converted. (generic_funcall): Converted to take struct args. (funcall, funcall1, funcall2, funcall4): Pass stack-allocated struct args as trailing arguments to variadic functions, and to generic_funcall. (do_curry_12_1_v): New struct-args-based static function, needed to implement curry_12_1_v now. (curry_12_1_v): Converted. (transposev): New function based on previous tranpose. (transpose): Now a wrapper for transposev. (do_chain, chainv, do_chand, chandv, do_juxt, juxtv, do_and, andv, do_or, orv, do_not, do_iff): Converted. (vectorv): New function. Implementation basis for vec intrinsic function. (alist_removev, alist_nremovev): New functions. (multi_sort): Switch from mapcarv to mapcarl. (unique): Converted. (uniq): Allocate struct args for calling unique. (obj_init): list_f function now based on new listv, rather than identity. * list.h (varg): New typedef. (struct func): All variadic function pointers converted to use struct args. (appendv, nconcv, lazy_appendv, multi, nary_op, plusv, minusv, mulv, gtv, ltv, gev, lev, numeqv, numneqv, maxv, minv, exptv, gcdv, lcmv, logadnv, logiorv, maskv, lessv, greaterv, lequalv, gequalv, func_f0v, func_f1v, func_f2v, func_f3v, func_f4v, func_n0v, func_n1v, func_n2v, func_n3v, func_n4v, func_n0v, func_n1v, func_n2v, func_n3v, func_n4v, func_n1ov, func_n2ov, func_n3ov, generic_funcall, chainv, chandv, juxtv, adnv, orv, unique): Declarations updated. (lazy_appendl, listv, maxl, minl, transposev, vectorv, alist_removev, alist_nremovev): Declared. * stream.c (make_catenated_stream_v): New function. (aformat): Renamed to formatv. The recognition of the nil and t streams (standard output and string) is done here now. (vformat): Follow rename of aformat to formatv. (formatv): Function removed. Nobody calls this anymore. (stream_init): make-catenated-stream re-registered to new make_catenated_stream_v function. * stream.h (formatv): Declaration updated. (make_catenated_v): Declared. * syslog.c (syslog_init): syslog registred to syslog_wrapv. (syslog_wrapv): New function based on syslog_wrap converted to struct args. (syslog_wrap): Now wrapper for syslog_wrapv. * syslog.h (syslog_wrapv): Declared. * unwind.h (uw_throwv): New function. (uw_throwfv, uw_errorfv): Converted to struct args. * unwind.h (uw_throwv): Declared. (uw_throwfv, uw_errorfv): Declarations updated.
* Don't implement range and range* with variadic functions.Kaz Kylheku2015-08-211-15/+14
| | | | | | | | | * eval.c (rangev, range_star_v): Functions renamed to range and rangev, and take three arguments instead of an argument list. (rangev_func, range_star_v_func): Static functions renamed to range_func and range_star_func. (eval_init): Register of range and rangev as three-argument functions with all arguments optional.
* New function, clamp.Kaz Kylheku2015-08-131-0/+1
| | | | | | | | | | * eval.c (eval_init): Register clamp as intrinsic function. * lib.c (clamp): New function. * lib.h (clamp): Declared. * txr.1: Documented.
* New display-width function.Kaz Kylheku2015-08-131-0/+1
| | | | | | | | | | * eval.c (eval_init): Register display-width intrinsic. * lib.c (display_width): New function. * lib.h (display_width): Declared. * txr.1: Documented display-width.
* Dot with no whitespace generates qref syntax.Kaz Kylheku2015-08-101-1/+2
| | | | | | | | | | | | | | | | | | | | | | | a.b.(expr ...).c -> (qref a b (expr ...) c) Consing dot requires whitespace. * eval.c (qref_s): New symbol global variable. (eval_init): Initialize qref_s. * eval.h (qref_s): Declared. * parser.l (REQWS): New pattern definition, required whitespace. (grammar): New rules to scan CONSDOT (space required on both sides) and LAMBDOT (space required after). * parser.y (CONSDOT, LAMBDOT): New token types. (list): (. n_expr) rule replaced with LAMBDOT and CONSDOT. (r_exprs): r_exprs . n_expr consing dot rule replaced with CONSDOT. (n_expr): New n_expr . n_expr rule introduced here for producing qref expressions. (yybadtoken): Handle CONSDOT and LAMBDOT. * txr.1: Documented qref dot.
* C++ upkeep: resolve multiple definitions of fun_k.Kaz Kylheku2015-08-071-2/+1
| | | | | | | | | | | | | | | * eval.c (fun_k): Global definition removed. (eval_init): Do not initialize fun_k here. * filter.c (fun_k): Definition removed. (filter_init): Do not initialize fun_k. * filter.h (fun_k): Declaration removed. * lib.c (fun_k): Defined in this file now. (obj_init): Initialize fun_k here. * lib.h (fun_k): Declare here.
* Better diagnosis for loose @ forms.Kaz Kylheku2015-08-061-0/+7
| | | | | | | | | | | | | * eval.c (op_meta_error): New static function. (eval_init): Register sys:var and sys:expr as operators that throw error. * parser.y (sym_helper): Take parser_t instead of scanner_t argument so we have access to the name and line number. Obtain scanner internally from parser. Add source location info to (sys:var ...) form. (symhlpr): Retarget macro to pass parser rather than scanner to sm_helper.
* * eval.c (do_eval): Bugfix: though last_form_evaled isKaz Kylheku2015-08-051-0/+1
| | | | | saved and restored around the execution of a special operator, it is never set the current form.
* * eval.c (bind_args): Use new ~! for proper indentationKaz Kylheku2015-08-041-5/+5
| | | | | | | of multi-line context form. (apply): Use ~! for proper indentation of function code. * unwind.c (uw_throw): Use ~! for proper indentation of code.
* * eval.c (func_get_name): New function.Kaz Kylheku2015-08-041-7/+41
| | | | | | | | | | | | (bind_args): Include the entire context form in argument mismatch errors. (apply): Include the function name, or else source code if it has no name, in argument mismatch erors. (eval_init): Register func-get-name intrinsic. * eval.h (func_get_name): Declared. * txr.1: Documented func-get-name.
* * eval.c (force): Default the new second argument of source_loc_str.Kaz Kylheku2015-08-041-6/+7
| | | | | | | | | | | | | | | | | | | (eval_error): Derive location of error from the last_form_evaled, if form doesn't have it. (eval_init): Re-register source-loc-str as binary with an optional arg. * match.c (debuglf, sem_error, file_err, typed_error): Default new argument of source_loc_str. * parser.h (source_loc_str): Declaration updated. * parser.l (source_loc_str): Take second argument which specifies alternative value if the source loc info is not found. * unwind.c (uw_throw): Simplify code thanks to source_loc_str default argument. * txr.1: Document new argument of source-loc-str.
* * hash.c (hash_revget): New function.Kaz Kylheku2015-08-041-0/+1
| | | | | | | | * hash.h (hash_revget): Declared. * eval.c (eval_init): Registered hash-revget intrinsic. * txr.1: Documented hash-revget.
* Switching some globals to lexical and changing some names.Kaz Kylheku2015-08-031-12/+31
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * arith.c (arith-init): Changing *flo-...* from special to lexical, and adding un-earmuffed variants. The earmuffed versions are obsolescent. Adding %pi% and %e% global lexicals. Earmuffed versions are also made global lexical, and obsolescent. * eval.c (lookup_global_var, lookup_global_var_l): New functions. (lookup_var): Uses lookup_global_var. (reg_varl): New function. (reg_var): Uses reg_var. (eval_init): Register global lexicals user-package, system-package and keyword-package. Old symbols with earmuffs are obsoleted, and also turned into global lexicals. (top-vb, top-fb): Changed to lexical. * eval.h (lookup_global_var, lookup_global_var_l, reg_varl): Declared. * genvim.txr: Scan ver.tl so that the lib-version variable is included. Extract reg_varl calls. * glob.c (glob_init): glob-err and other variables made lexical. * lib.c (get_user_package, get_system_package, get_keyword_package): Use lookup_global_var_l to avoid searching dynamic scope for lexicals which cannot be dynamically rebound. * share/txr/stdlib/ver.tl (lib-version): New global lexical variable. (*lib-version*): Turned lexical. Obsolescent. * signal.c (sig-init): sig-* variables turned lexical. * sysif.c (sysif-init): s-*, poll-* and w-* variables turned lexical. * syslog.c (syslog-init): log-* variables turned lexical. * txr.c (sysroot-init): stdlib and *txr-version* variables turned lexical. txr-version variable added, and *txr-version* is obsolescent. (txr-main): self-path variable added. *self-path* turns lexical and is obsolescent. * txr.1: Documentation updated. Lexical variables not referred to as special. Special variables referred to as special.
* Introducing global lexicals: defvarl, defparml.Kaz Kylheku2015-08-031-13/+32
| | | | | | | | | | | | | | | | | | | | | * eval.c (defvarl_s, defparm_s, defparml_s, sys_mark_special_s): New symbol variables. (mark_special): Return val rather than void, since it's hoisted into Lisp domain now with func_n1. (op_defvar): Renamed to op_defvarl, and doesn't call mark_special. defvarl is now the special form for defining variables, and special marking is an embellishment added by macros. (me_defparm): Renamed to me_def_variable. Handles defvar, defparm and defparml. (do_expand): Expand defvarl, rather than defvar. (eval_init): Intern defvarl, defparm, defparml and mark-special symbols, and initialize corresponding globals. Register defvarl special operator, retiring defvar. Register defparm to me_def_variable, and register defvar and defparml to the same. * txr.1: Document support for global lexical scopes and the new macros.
* * eval.c (special_p): Function renamed to special_var_p.Kaz Kylheku2015-08-011-7/+9
| | | | | | | | (expand_opt_params_rec, expand_vars): Follow rename of special_p. (eval_init): Register special-operator-p and special-var-p intrinsics. * txr.1: Document special-operator-p and special-var-p.
* Multi-line, indented printing of structure.Kaz Kylheku2015-07-311-4/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * eval.c (op_error): New static function. (macro_form_p, fboundp): Static to external. (special_operator_p): New function. (eval_init): Register macrolet and symacrolet to op_error. These are recognized and processed by expand, but we want them in the op table so they are reported by special_operator_p. * eval.h (fboundp, macro_form_p, special_operator_p): Declared. * hash.c (print_key_val): Break long lines on spaces between pairs with stream_width_check. (hash_print_op): Implement split and indented printing. * lib.c (obj_print_impl): New static function, resulting from a merge of obj_print and obj_pprint. Fixes some wrong-way recursion bugs: obj_pprint recursed into obj_print in some places. Adds support for multi-line printing of vectors and lists, with indentation using the new interfaces in streams. * stream.c (strm_base_init): Update initializer. (put_indent, indent_mode_put_string): New static functions. (put_string): Use indent_mode_put_string in either of the two indent modes. (put_char): Implement indent mode. (get_indent_mode, test_set_indent_mode, set_indent_mode, get_indent, set_indent, inc_indent, width_check): New functions. * stream.h (enum indent_mode): New. (struct strm_base): indent_on member becomes indent_mode. New members data_width and code_width. (get_indent_mode, test_set_indent_mode, set_indent_mode, get_indent, set_indent, inc_indent, width_check): Declared. * tests/009/json.expected: Updated. * tests/010/seq.expected: Likewise. * tests/011/macros-2.expected: Likewise.
* * eval.c (op_quote): Improved diagnostic.Kaz Kylheku2015-07-241-1/+1
|
* Adding nthcdr as accessor.Kaz Kylheku2015-07-221-0/+1
| | | | | | | | | | | | * eval.c (eval_init): Register nthcdr function. * lib.c (nthcdr): New function. * lib.h (nthcdr): Declared. * share/txr/stdlib/place.tl (nthcdr): New defplace. * txr.1: Documented.
* Improve bad argument diagnosis for place macros.Kaz Kylheku2015-07-221-0/+13
| | | | | | | | | | * eval.c (op_mac_param_bind): New static function. (eval_init): Register mac-param-bind operator. * share/txr/stdlib/place.tl (define-place-macro): Use mac-param-bind inside a lambda instead of tb macro. * txr.1: Document mac-param-bind.
* Implementing second through tenth as places.Kaz Kylheku2015-07-221-0/+4
| | | | | | | | | | | | | | | | | | * eval.c (eval_init): Register second through tenth as intrinsic. * gencadr.txr: New cadr.c changes encoded. * lib.c (second, third, fourth, fifth, sixth): Functions reimplemented using ref, so they are much more efficient for vectors and strings. (seventh, eighth, ninth, tenth): New functions. * lib.h (seventh, eighth, ninth, tenth): Declared. * share/txr/stdlib/place.tl: place macros defined for second through tenth. * txr.1: Documented.
* * eval.c (eval_init): Register new split function.Kaz Kylheku2015-07-211-0/+1
| | | | | | | | | | | | * lib.c (split_func): New static function. (partition_split_common): New static function, based on on contents of partition function. (partition): Now a wrapper around partition_split_common. (split): New function. * lib.h (split): Documented. * txr.1: Documented split.
* Expand away sys:lisp1-value based on lexical info.Kaz Kylheku2015-07-111-2/+28
| | | | | | | * eval.c (sys_lisp1_value_s): New global symbol variable. (expand_lisp1_value): New static function. (do_expand): Use expand_lisp1_value. (eval_init): Initialize sys_lisp1_value_s.
* * eval.c (eval_init): Register bindable as intrinsic.Kaz Kylheku2015-07-101-1/+1
| | | | * txr.1: Documented.
* Hash-bang support for .tl files.Kaz Kylheku2015-07-021-1/+1
| | | | | | | | | | | | | | | | * parser.c (read_eval_stream): New boolean argument to request hash bang support. * parser.h (read_eval_stream): Declaration updated. * eval.c (sys_load): Pass new thid argument to read_eval_stream, to decline hash bang support. * match.c (v_load): Likewise. * txr.c (txr_main): Request hash bang support from read_eval_stream. Thus files referenced from the txr command line can have a #! line, which is ignored.
* Fix TXR 97 regression in quasiliterals.Kaz Kylheku2015-06-271-1/+1
| | | | | | | | | * eval.c (expand_quasi): When the modifiers argument of a var item is expanded, the expansion incorrectly places it as the fourth item rather than third. This is effectively a continuation of the incomplete regression fix that was applied on 2014-08-29. The breakage is that `@{(expr) modifier}` ignores modifier whenever (expr) is an expression that undergoes expansion.
* * hash.c (hash_from_pairs, hash_list): New functions.Kaz Kylheku2015-06-241-0/+2
| | | | | | | | | * hash.h (hash_from_pairs, hash_list): Declared. * eval.c (eval_init): Registered hash-from-pairs and hash-list intrinsic. * txr.1: Documented new functions.
* Hash subset testing.Kaz Kylheku2015-06-231-0/+2
| | | | | | | | | | | * eval.c (eval_init): Register hash-subset and hash-proper-subset intrinsics. * hash.c (hash_subset, hash_proper_subset): New functions. * hash.h (hash_subset, hash_proper_subset): Declared. * txr.1: New functions documented.
* * 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.