summaryrefslogtreecommitdiffstats
path: root/eval.c
Commit message (Collapse)AuthorAgeFilesLines
...
* Allow sys:var and sys:expr redefinition.Kaz Kylheku2017-08-281-0/+2
| | | | | * eval.c (builtin_reject_test): Suppress warning if the symbol is sys:var or sys:expr.
* expander: do dot-to-apply for meta-expressions.Kaz Kylheku2017-08-281-4/+35
| | | | | | | | | | | | | | | | | | | The dot-to-apply transformation is now applied when meta-expressions like @foo and @(bar) apparently occur in the dot position. This change is made in anticipation of a rewrite of the op macro, in which the @1, @2, and @rest arguments will be implemented as macrolets, rather than the ad-hoc, hacky code walk currently performed in the transform_op function. * eval.c (dot_meta_list_p): New static function. (dot_to_apply): Detect the presence of a sys:var or sys:expr argument in a form. If found, then turn it and the remaining forms into a single compound form which replaces them. * txr.1: Update doc under Dot Position in Function Calls.
* Make len a synonym for length.Kaz Kylheku2017-08-071-1/+3
| | | | | | | * eval.c (eval_init): Register the same function under length and len. * txr.1: Documented.
* New spl and tok: variants of tok-str and split-str.Kaz Kylheku2017-08-071-0/+2
| | | | | | | | * eval.c (eval_init): Register spl and tok intrinsics. * lib.c (spl, tok): New functions. * txr.1: Documented.
* tok-str requires two arguments, not just one.Kaz Kylheku2017-08-071-1/+1
| | | | * eval.c (eval_init): Fix incorrect registration of tok-str.
* Add sum and prod convenience functions.Kaz Kylheku2017-08-051-0/+2
| | | | | | | | | | * eval.c (eval_init): prod and sum intrinsics registered. * lib.c (sum, prod): New functions. * lib.h (sum, prod): Declared. * txr.1: Documented.
* bugfix: spurious nils in pad function's output.Kaz Kylheku2017-08-021-5/+6
| | | | | | * eval.c (pad): Incoming sequence must be nullified, otherwise empty vectors and strings produce a spurious nil. This affects the weave function, which uses pad.
* lib: deprecate set-diff; extend set operations.Kaz Kylheku2017-07-261-1/+5
| | | | | | | | | | | | | | * eval.c (eval_init): Register set-diff under two names: set-diff and diff. Register new isec and uni intrinsics. * lib.c (isec, uni): New functions. * lib.h (isec, uni): Declared. * txr.1: Documented new uni and isec functions, new diff function name, and the deprecation of set-diff and its order guarantee w.r.t the left sequence.
* new function: nthKaz Kylheku2017-07-181-0/+1
| | | | | | | | | | | | | | | | Just the ANSI CL nth for lists. * eval.c (eval_init): Register nth intrinsic. * lib.c (nth): New function. * lib.h (nth): Declared. * share/txr/stdlib/place.tl (nth): New place macro, trivially takes care of making nth an accessor. Place macros are terrific! * txr.1: Documented.
* lib: new function, relate.Kaz Kylheku2017-07-171-0/+1
| | | | | | | | | | | * eval.c (eval_init): Register new intrinsic relate. * lib.c (do_relate, do_relate_dfl): New static functions. (relate): New function. * lib.h (relate): Declared. * txr.1: Documented.
* bugfix: spurious warnings issued against lisp1 eval.Kaz Kylheku2017-07-141-2/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Repro test cases for this: A: (progn (defun f ()) [f]). This emits a warning against the [f] usage, even though there is a tentative definition of f as a function. B: (progn (defun g () [f]) (defun f ())). Emits a warning against [f] usage which is not purged by the evaluation of the later definition. Both problems are related to the separation of deferred warnings into the tag namespaces: symbols and functions. When [f] is being expanded, the deferred warning is put into the variable namespace. So it doesn't match a tentative def in the function namespace which would otherwise suppress it. A subsequent function definition only purges the warning for the function space. We introduce a third space, the "symbol space". Lisp-1 deferred warnings are introduced against this namespace and both variable and function definitions purge deferred warnings from that namespace also, in addition to their respective proper namespace. This solves problem B. Problem A is solved by checking, when [f] is expanded, for tentative definitions of f in both the variable and function tag space. Note that test case B still warns when entered into the listener, because the listener dumps deferred warnings prior to evaluation, thus prior to evaluating (defun f ()). * eval.c (op_defvarl, op_defun): Purge deferred warnings from the sym tag namespace also. (expand_lisp1): Do not emit the deferred warning for a nonexistent name if it has a tentative definition either as a function or variable. When emitting the deferred warning, use the sym namespace.
* structs: improve access to initfun and postinitfun.Kaz Kylheku2017-07-091-2/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In this change, a struct type's initfun and postinitfun become mutable. This is achieved by modeling them as the pseudo-static-slots :initfun and :postinitfun. Effectively these now behave as reserved names which do not denote static slots but these special functions. * eval.c (lookup_fun): When (meth type slot) syntax is encountered, treat the slot names :init and :postinit specially: retrieve these special functions instead of accessing static slots. * share/txr/stdlib/place.tl (sys:get-fun-getter-setter): Similarly, when handling (meth type slot) syntax, return the alternative getter/setter functions for the special functions, not the static slot accessing functions. Also, getting rid of a useless @1 here in existing code, since (op foo @1) is equivalent to (op foo). * share/txr/stdlib/struct.tl (sys:defmeth): Check for the special names :init and :postinit, handling these through the appropriate setter functions rather than static-slot-ensure. * struct.c (init_k, postinit_k): New keyword symbol variables. (struct_init): Initialize init_k and postinit_k. Register intrinsics struct-get-initfun, struct-set-initfun, struct-get-postinitfun and struct-set-postinitfun. * (struct_get_initfun, struct_set_initfun, struct_get_postinitfun, struct_set_postinitfun): New functions. (method_name): For each struct type visited, check whether the function is the initfun or postinitfun and return the appropriate meth syntax if so. * struct.h (init_k, postinit_k, struct_get_initfun, struct_set_initfun, struct_get_postinitfun, struct_set_postinitfun): Declared. * txr.1: Documented. Updated description of method-name, defmeth, and documented new functions.
* expander: fix neglect to expand lambda and fun.Kaz Kylheku2017-07-071-4/+15
| | | | | | | | | | | | | Now that lambda expressions are supported as function names in the first position of a compound expression and as an argument to the fun operator, it will greatly behoove us if we expand them properly. Then tests/012/quine.tl will pass. * eval.c (do_expand): Handle fun specially. If the argument is a lambda expression, then expand that and generate an expanded fun form, otherwise just yield form. When expanding function calls, check whether the first argument is a lambda and expand it.
* Lisp: lambda expressions are function names now.Kaz Kylheku2017-07-071-0/+2
| | | | | | | | | | | | | | | | | | | * eval.c (lookup_fun): With this two-liner change, the forms ((lambda (x) x) 42) and (fun (lambda ())) just work. This is not just compatibility with other dialects; it is necessary for consistency with func-get-name, which already returns lambda expressions, effectively asserting that they are function names. * txr.1: Fix documentation for fun operator. The Dialect Note saying that a lambda expression is not a function name in TXR Lisp is removed. Document that function names may be any of those produced by func-get-name. This has already been true for macros and methods, just not for lambda expressions. Under fun-get-name, document that lambda expressions are produced for interpreted functions not found in any binding by the previous searches.
* New Cartesian product mapping functions.Kaz Kylheku2017-06-281-0/+59
| | | | | | | | | | * eval.c (prod_common): New static function. (maprodv, maprendv): New functions. (eval_init): Registered maprod and maprend intrinsics. * eval.h (maprodv, maprendv): Declared. * txr.1: Documented.
* New cptr functions cptr-cast and int-cptr.Kaz Kylheku2017-06-261-0/+2
| | | | | | | | | | | * eval.c (eval_init): Register new intrinsics cptr-cast and int-cptr. * lib.c (cptr_cast, int_cptr): New functions. * lib.h (cptr_cast, int_cptr): Declared. * txr.1: Documented.
* cptr-int and cptr-obj can make typed cptr objects.Kaz Kylheku2017-06-191-2/+2
| | | | | | | | | | | | | | | | | * eval.c (eval_init): Update registration of cptr-int and cptr-obj with one optional argument. * lib.c (cptr_int): New type symbol argument, defaulting to nil. Also, don't bother defaulting the integer argument; the function isn't registered for that being optional. (cptr_obj): New type symbol argument, defaulting to nil. * lib.h (cptr_int, cptr_obj): Declarations updated. * txr.1: Documented cptr-int and cptr-obj function changes. Added discussion of type tag to introductory paragraph. Also added neglected documentation of the FFI cptr type, both unparametrized and parametrized.
* mkstring char argument is optional.Kaz Kylheku2017-06-011-1/+1
| | | | | | | | | * eval.c (eval_init): Update registration of mkstring intrinsic to make second argument optional. * lib.c (mkstring): Default second argument to space. * txr.1: Documentation of mkstring updated.
* Refactoring hash bang support; hash bang null hack.Kaz Kylheku2017-05-301-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The hash bang mechanism is handled in one place, and disentangled from all parsing logic. It is also endowed with special powers. * eval.c (load): Pass one less argument to read_eval_stream. * match.c (v_load): Likewise. * parser.c (read_eval_stream): hash_bang_support Boolean argument removed. Hash bang logic removed. (load_rcfile): Pass only two arguments to read_eval_stream. * parser.h (read_eval_stream): Declaration updated. * txr.c (remove_hash_bang_line): Function removed. (check_hash_bang): New static function. (txr_main): Recognize the script file name while still inside the argument processing loop. Open the file, and check for a hash bang line, doing the special processing which can generate more arguments from material after a null byte in the hash bang line. The parse_stream variable is now initialized to nil and doubles as a Boolean indicating whether a stream has been opened. After the loop, we remove the script file from the arguments, if we have an open stream and the spec_file_str matches. read_eval_stream is called only with two arguments. * txr.1: Revised existing documentation and described new features.
* command line: --eargs semantics change.Kaz Kylheku2017-05-301-1/+1
| | | | | | | | | | | | | | | | | The --eargs mechanism won't perform a blind substring replacement of {} with the following argument. Only arguments which match {} exactly are replaced. * eval.c (retf): Static function becomes extern. * eval.h (retf): Declared. * txr.c (txr_main): Replace the filtering logic on the split eargs argument list to just look for items equal to the string "{}" and replace with the following argument. * txr.1: Updated --eargs documentation.
* Splitting cptr object into separate CPTR tag.Kaz Kylheku2017-05-151-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | CPTR shares representation and a lot of implementation with COBJ. The COBJ class symbol is the CPTR type tag. There is no hierarchy among CPTR tags. The nil tag is used for a modicum of type looseness, so that we don't straitjacket ourselves too much into this tag-based typing scheme. All existing cptr objects are becoming CPTR, and all get a nil tag, except for dlopen library handles, and dlsym symbols, which are tagged as dlhandle and dlsym. The FFI framework will support tag-declared cptr's. This will help with safety. For instance, suppose an API has half a dozen different kinds of opaque handles. If they are all just cptr on the TXR Lisp side, it's easy to mix them up, passing the wrong one to the wrong C function. * lib.h (enum type): New enum member, CPTR. (cptr_print_op, cptr_typed, cptrp, cptr_type, cptr_handle): Declared. (cptr_addr_of): Parameters added. * lib.c (code2type): Map CPTR type code to cptr_s. (equal): Handle CPTR objects. They are only equal to other CPTR objects which have the same operations, and are equal under the equal function of those operations. (cptr_print_op): New function. (cptr_ops): Use cptr_print_op rather than cobj_print_op. (cptr_typed): New function. (cptr): Use cptr_typed to make a cptr with tag nil, rather than using cobj. (cptrp, cptr_handle, cptr_type): New functions. (cptr_get): Go through cptr_handle rather than cobj_handle. (cptr_addr_of, cptr_zap, cptr_free): Use call to cptr_handle rather than cobj_handle for the type checking side effect. New parameters for type and parent function name. (obj_print_impl): Handle CPTR with same case as COBJ. * gc.c (finalize, mark_obj): Handle CPTR cases using common code with COBJ. * hash.c (equal_hash): Handle CPTR just like COBJ. * eval.c (eval_init): Register cptrp and cptr-type intrinsic functions. * ffi.c (ffi_cptr_put, ffi_cptr_get, ffi_cptr_alloc): Use the potentially type-safe cptr_handle, instead of cptr_get. However, for an untagged cptr, there is no type safety because tft->mtypes is nil. The argument can be any kind of cptr. * sysif.c (dlhandle_s, dlsym_s): New symbol variables. (cptr_dl_ops): Use cptr_print_op. (dlopen_wrap, dlclose_wrap): Use typed cptr with dlhandle as the type. (dlsym_wrap, dlsym_checked, dlvsym_wrap, dlvsym_checked): Recognize only a cptr of type dlhandle for the library. Construct a typed cptr of type dlsym. (sysif_init): Initialize dlhandle_s and dlsym_s. Register dlsym function using dlsym_s.
* cptr: new functions.Kaz Kylheku2017-05-091-0/+6
| | | | | | | | | | * eval.c (eval_init): Register cptr-int, ctpr-obj, cptr-zap and cptr-free functions and cptr-null variable. * lib.c (cptr_int, cptr_obj, cptr_zap, cptr_free): New functions. * lib.c (cptr_int, cptr_obj, cptr_zap, cptr_free): Declared.
* Bugfix expansion: return-from, sys:abscond-from, block*.Kaz Kylheku2017-04-151-3/+8
| | | | | | | | | | | | | | These three forms are not being traversed properly by the macro expander. * eval.c (do_expand): Do not treat return-from, sys:abscond-from and block* in the same case as block. block* evaluates all of its forms and so can just be walked as a function call in the fallback case. The other two must be in their own case because we must not use expand_progn on them; they do not evaluate a progn-like list of forms. This leads to inappropriate optimizations like (return-from x (progn a b c)) -> (return-from x a b c).
* Make it a warning only when built-ins redefined.Kaz Kylheku2017-04-141-4/+4
| | | | | | | * eval.c (builtin_reject_test): Issue warnings rather than errors when built-in macros, functions or operators are redefined. For now, we don't provide any way to suppress the warning.
* Indexing in variable subst applies to any sequence.Kaz Kylheku2017-04-051-9/+18
| | | | | | | | | | | | | | | | | | | | The @{a [3]} syntax in quasiliterals and @(output) now indexes into the original object a if it is any sequence kind, not specifically a list. Otherwise it indexes into its string representation. * eval.c (format_field): Combine the elements of the object with the separator if it is any sequence type other than a string. Subject to compat option. (subst_vars): Avoid converting any kind of sequence to string, rather than just lists. After any field formatting is applied, if the object is any sequence (not just alist), combine the elements with a space. All subect to compat option. * match.c (tx_subst_vars): Same treatment as subst_vars. * txr.1: Compatibility notes added.
* New time-parse-local and time-parse-utc functions.Kaz Kylheku2017-04-041-0/+2
| | | | | | | | | | | | | | | * eval.c (eval_init): Register intrinsic functions time-parse-local and time-parse-utc. * lib.c (strptime_wrap): New static function. (time_parse): Now implemented as by call to strptime_wrap. (time_parse_local, time_parse_utc): New functions. These get the time_t time from struct tm without constructing the intermediate Lisp structure. * lib.h (time_parse_local, time_parse_utc): Declared. * txr.1: Documented new functions.
* apply and iapply bugfix: split sequences into args.Kaz Kylheku2017-04-031-2/+17
| | | | | | | | | | | | | | | | | | | | | These functions don't conform with the documentation. For instance [apply list "abc"] yields "abc". It is supposed to yield (#\a #\b #\c), since the characters of "abc" must become individual arguments to list. Part of the fix is in the apply_frob_args logic; however, we have to clone that function because it is used for implementing other things which will break: we cannot, for for example, have (list* 1 "ab") producing (1 #\a #\b). * eval.c (apply_intrisic_frob_args): New static function. Differs from apply_frob_args in that it calls tolist on the final element. (apply_intrinsic): Use apply_intrinsic_frob_args instead of apply_frob_args. (iapply): Invoke tolist on the value assigned to last_arg. * txr.1: Add a clarifying note for iapply that the terminating atom is not split into arguments if it is a sequence.
* Important improvement in opip: support slot access.Kaz Kylheku2017-03-291-1/+1
| | | | | | | | | | * eval.c (me_opip): Just like dwim forms are left untransformed, we also leave untransformed (uref ...) and (qref ...) forms. Otherwise they get wrapped in the (do ...) syntax and don't work right. This treatment is so broken/useless that no compatibility switch is needed here. * txr.1: Documentation for opip/oand updated.
* Short-circuit lisp-1 expander for atoms.Kaz Kylheku2017-03-241-0/+3
| | | | | | * eval.c (expand_lisp1): if the form is an atom that is not a bindable symbol, just return it; don't wastefully call into expand which has to save and restore some context.
* bugfix: neglected unbound warnings in DWIM syntax.Kaz Kylheku2017-03-241-0/+4
| | | | | | | | | | | DWIM expressions like [a b c] are not raising expansion-time warnings about a, b, c being unbound. * eval.c (expand_lisp1): The problem is that here we just return in the case that the symbol is bindable and has no macro expansion! Before returning, we must check whether the symbol has a binding in the variable or function space. If not, raise a warning.
* Sandboxing support via *package-alist*.Kaz Kylheku2017-03-171-0/+1
| | | | | | | | | | | | | | | | | | | * eval.c (eval_init): Register *package-alist* variable, taking on the contents of the packages variable. * lib.c (package_alist_s): New symbol variable. (make_package, packagep, find_package, package_alist); Work with dynamic package alist variable via cur_package_alist_loc macro. (get_current_package_alist_loc): New function. * lib.h (cur_package_alist_loc): New macro. (packages, package_alist_s, get_current_package_alist_loc): Declared. * txr.1: Documented *package-alist* along with notes about sandboxing. Documented that the package-alist function is now obsolescent.
* Rename badly named default_bool_argKaz Kylheku2017-03-171-17/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * lib.h (default_bool_arg): Inline function renamed to default_null_arg. * eval.c (if_fun, pad, ginterate, giterate, range_star, range, constantp, macroexpand_1, macro_form_p, expand_with_free_refs, do_expand, eval_intrinsic, func_get_name, make_env_intrinsic): Follow rename. * arith.c (lognot): Likewise. * gc.c (gc_finalize): Likewise. * glob.c (glob_wrap): Likewise. * hash.c (group_reduce, gethash_n): Likewise. * lib.c (print, multi_sort, lazy_str, vector, iff, tok_str, split_str_keep, search_str, remove_if, val): Likewise. * match.c (match_fun): Likewise. * parser.c (lisp_parse_impl, regex_parse): Likewise. * rand.c (make_random_state): Likewise. * regex.c (read_until_match, search_regex, regex_compile): Likewise. * socket.c (sock_accept, sock_connect): Likewise. * stream.c (open_files_star, open_files, run, open_process, open_tail, get_string, record_adapter): Likewise. * struct.c (static_slot_ensure, static_slot_ens_rec, clear_struct, make_struct_type): Likewise. * sysif.c (exec_wrap, errno_wrap, cobj_ops_init): Likewise. * unwind.c (uw_capture_cont, uw_find_frames_impl): Likewise.
* trace: implement redefinition checks.Kaz Kylheku2017-03-171-0/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | The tracing module should warn when traced functions or methods are being redefined, and stop tracing the original methods. * eval.c (trace_check): New function. Calls sys:trace-redefined-check if the trace module has been loaded, otherwise does nothing. (op_defun, op_defmacro): Call trace_check to have a warning issued for a redefined traced function or macro. * eval.h (trace_check): Declared. * lisplib.c (trace_loaded): New global variable. (trace_instantiate): Flip trace_loaded to t. * lisplib.h (trace_loaded): Declared. * share/txr/stdlib/trace.tl (sys:trace-redefine-check): New function. Checks two situations: traced function or method is redefined (neither old nor new is traced any longer), and traced method is overridden (base method continues to be traced, override is not traced). * struct.c (static_slot_ensure): Do a trace check here, taking care of defmeth.
* Fix missing nao terminator in formatted printing.Kaz Kylheku2017-03-131-2/+2
| | | | | | | | | | | | | | * arith.c (trunc1, trunc, floorf, ceili): Add missing nao terminator to uw_throwf calls. * debug.c (debug): Missing nao terminator in format call. * eval.c (expand_opt_params_rec, me_equot): Missing nao terminator in eval_error call. * lib.c (use_sym): Missing nao in uw_throw call. * regex.c (reg_derivative): Missing nao in uw_throwf.
* New functions starts-with and ends-with.Kaz Kylheku2017-03-121-0/+2
| | | | | | | | | | | * eval.c (eval_init): Register starts-with and ends-with intrinsics. * lib.c (starts_with, ends_with): New functions. * lib.c (starts_with, ends_with): Declared. * txr.1: Documented.
* New rmismatch function.Kaz Kylheku2017-03-121-0/+1
| | | | | | | | | | * eval.c (eval_init): Register rmismatch intrinsic. * lib.c (rmismatch): New function. * lib.h (rmismatch): Declared. * txr.1: Documented
* match-fun: make last two args optional.Kaz Kylheku2017-03-121-1/+1
| | | | | | | | * eval.c (eval_init): Update registration of match-fun. * match.c (match_fun): Do defaulting on third and fourth arg. * txr.1: Documenation updated.
* uref: the a.b.c syntax extended to .a.b.cKaz Kylheku2017-03-061-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Now it is possible to use a leading dot on the referencing dot syntax. This is the is the "unbound reference dot". It expands to the uref macro, which denotes an unbound-reference: it produces a function which takes an object as the argument, and curries the reference implied by the remaining arguments. * eval.c (uref_s): New global symbol variable. (eval_init): Intern uref symbol and init uref_s. * eval.h (uref_s): Declared. * lib.c (simple_qref_args_p): A qref expression is now also not simple if it contains an embedded uref, meaning that it cannot be rendered into the dot notation without ambiguity. (obj_print_impl): Support printing (uref a b c) as .a.b.c. * lisplib.c (struct_set_entries): Add uref to the list of autoload triggers for struct.tl. * parser.l (DOTDOT): Consume any leading whitespace as part of recognizing the DOTDOT token. Otherwise the new rule for UREFDOT, which matches (mandatory) leading space will take precedence, causing " .." to be scanned wrong. (UREFDOT): Rule for new kind of dot token, which is preceded by mandatory whitespace, and isn't consing dot (which has mandatory trailing whitespace too, matched by an earlier rule). * parser.y (UREFDOT): New token type. (i_dot_expr, n_dot_expr): New grammar rules. (list): Handle a leading dot on the first element of a list as a special case. Things are done this way because trying to work a UREFDOT into the grammar otherwise causes intractable conflicts. (i_expr): The ^, ' and , punctuators are now followed by an i_dot_expr, so that the expression can be an unbound dot. (n_expr): Same change as in i_expr, but using n_dot_expr. Plus new UREFDOT n_expr production. * share/txr/stdlib/struct.tl (uref): New macro. * txr.1: Documented.
* New floor-rem, ceil-rem and round-rem.Kaz Kylheku2017-02-261-1/+4
| | | | | | | | | | | | * arith.c (trunc_rem): Move function to below round function. Make second argument optional, defaulting to one. (floor_rem, ceil_rem, round_rem): New functions. * eval.c (eval_init): Registration of trunc-rem altered for optional argument. New registrations for floor-rem, ceil-rem, round=rem. * txr.1: Documented for new functions folded with trunc-rem.
* Second argument optional in trunc.Kaz Kylheku2017-02-251-1/+1
| | | | | | | | | | | | | | * arith.c (trunc1): New static function. (trunc): Detect a missing second argument and call func1. * eval.c (eval_init): Update registration of trunc intrinsic to make second arg optional. * txr.1: Describe optional argument of trunc. Trunc documentation is merged with the floor, ceil and round section. The mod and trunc-rem functions are split off into their own sections, leaving the / function described by itself. The documentation of / is substantially revised.
* Adding round function.Kaz Kylheku2017-02-251-0/+1
| | | | | | | | | | | * arith.c (round1): New static function. (roundiv): New function. * configure: New test for C99 round function. * eval.c (eval_init): Register round intrinsic. * txr.1: Documented.
* floor and ceil do division, with optional second arg.Kaz Kylheku2017-02-241-2/+2
| | | | | | | | | | | | | | | Also, with one argument, these functions handle ranges. * arith.c (floordiv, ceildiv): New functions. (floorf, ceili): Handle ranges. * eval.c (eval_init): Register floor and ceil to new functions. * lib.h (floordiv, ceildiv): Declared. * txr.1: Documentation updated.
* Add rassoc and rassql functions.Kaz Kylheku2017-02-111-0/+2
| | | | | | | | | | | * eval.c (eval_init): Register rassoc and rassql intrinsics. * lib.c (rassoc, rassql): New functions. * lib.h (rassoc, rassql): Declared. * txr.1: Documented rassoc and rassql, with small fixes to assql and assoc.
* consistency: treat members of struct env in order.Kaz Kylheku2017-02-101-2/+2
| | | | | | | * eval.c (make_env, copy_env): Assign to vbindings, then to fbindings. The members are in that order and elsewhere, wherever we treat both bindings, we treat the variables first.
* Use non-hacky representation for deferrable warnings.Kaz Kylheku2017-02-101-10/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Deferrable warnings now get their own subtype, defr-warning. The tag is a regular argument: no funny dotted argument list. * eval.c (eval_defr_warn): Throw new style deferrable warning. (me_op, no_warn_expand): Catch defr-warning rather than warning. Use uw_muffle_warning to suppress it. (gather_free_refs): Parse new representation of deferrable warning. (expand_with_free_refs): Catch defr-warning rather than warning. * lib.c (defr_warning_s): New symbol variable defined. (obj_init): Initialize defr_warning_s. * lib.h (defr_warning_s): Declared. * share/txr/stdlib/error.tl (compile-defr-warning): Throw new-style deferrable warning. * unwind.c (uw_muffle_deferrable_warning): Function removed. (uw_throw): Bugfix: handle warnings by checking by subtype rather than exactly for the warning type. Distinguish deferrable warnings by subtype rather than argument list shape. (uw_defer_warning): Take the new style args and reconstruct the (msg . tag) representation for a deferred warning, so the other functions don't have to change. (uw_late_init): Register defr-warning as exception subtype of warning. * unwind.h (uw_muffle_deferrable_warning): Decl removed. * txr.1: Adjusted all documentation touching on the subject of the representation of deferrable warnings.
* Properly default arguments in expand_with_free_refs.Kaz Kylheku2017-02-101-1/+3
| | | | | * eval.c (expand_with_free_refs): Properly handle defaulting of the two optional arguments.
* Better way for releasing deferred warnings.Kaz Kylheku2017-02-101-3/+3
| | | | | | | | | | | | | | | | | | | | We should be re-throwing deferred warnings as ordinary warnings, not dumping them to a stream. * eval.c (eval_exception): Use uw_release_deferred_warnings instead of uw_dupm_deferred_warnings. (load): Likewise. * parser.c (read_eval_ret_last): Likewise. * txr.c (txr_main): Likewise. * unwind.c (uw_release_deferred_warnings): New function. * unwind.h (uw_release_deferred_warnings): Declared. * txr.1: Documented release-deferred-warnings and updated documentation for dump-deferred-warnings.
* Extend functionality of sys:expand-with-free-refs.Kaz Kylheku2017-02-091-5/+71
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This function's return list now has two additional elements. The first two elements give, respectively, the free variables and functions which occur in the form: variables and functions which have no lexical binding. As before, these lists omit the variables which do have bindings in the specified environment that is passed as an argument. The two new elements give, respectively, all variable and function references emanating out of the form, regardless of whether they have bindings in the form's surrounding lexical environment or whether they are free. The function also takes a new argument: an additional environment beyond which the erasure of bindings doesn't take place. * eval.c (squash_menv_deleting_range): New static function. (gather_free_refs): Do not intercept non-deferrable warnings. (gather_free_refs_nw): New static function. (expand_with_free_refs): Expand the form twice, the second time with a collapsed environment which has been stripped of all macros and of all var shadowing entries in a specified range, using the squash_menv_deleting_range function. The second pass yields the extra variables and functions. Also take a second env argument for this purpose. (eval_init): Register sys:expand-with-free-refs as a three argument function with one optional argument.
* sys:op: don't warn about @var targets.Kaz Kylheku2017-02-091-5/+11
| | | | | | | | * eval.c (do_expand): The previous commit exposes this false warning. Basically, the (sys:var <sym>) place expander generates a (sys:setq (sys:var <sym>) <val>) form. That is valid, and the expander shoud not warn that sys:var form is an unbound variable.
* Suppress only deferrable warnings in op expander.Kaz Kylheku2017-02-091-1/+1
| | | | | * eval.c (me_op): Switch from uw_muffle_warning to uw_muffle_deferrable_warning.