summaryrefslogtreecommitdiffstats
path: root/tests
Commit message (Collapse)AuthorAgeFilesLines
* tests: first FFI regression test case.Kaz Kylheku2017-05-133-0/+53
| | | | | | | | | | | * tests/017/qsort.expected: New file. * tests/017/qsort.tl: New file. * tests/common.tl (libc): New function. * Makefile (tst/tests/017/%): Clear TXR_DBG_OPTS so the GC stress test isn't applied to tests in this directory.
* tests: use internal OS identification method.Kaz Kylheku2017-05-132-4/+10
| | | | | | | | | | * tests/common.tl (osname): Function based on calling shell command removed. (os-symbol): New symbol-returning function based on uname system call. * tests/014/dgram-stream.tl (dgram-test): Use os-symbol function rather than osname.
* Some basic tests for finalization.Kaz Kylheku2017-03-242-0/+105
| | | | | | * tests/012/fini.tl: New file. * tests/012/fini.expected: New file.
* New catch*, giving access to exception symbol.Kaz Kylheku2017-01-251-12/+12
| | | | | | | | | | | | | | | | | | * eval.c (op_catch): The sys:catch operator now passes the exception symbol as the first argument of each clause. This means the catch macro must be adjusted. * share/txr/stdlib/except.tl (catch): Macro now inserts a gensym dummy first argument into each clause to take the symbol passed by the sys:catch operator. (catch*): New macro, which is identical to the previous catch macro, and thus exposes the symbol passed as the first argument. * txr.1: Documented catch*. * tests/012/struct.tl: Some gensym numbers need adjusting in one test case.
* Strengthen :filter test.Kaz Kylheku2017-01-222-2/+2
| | | | | | | | | * tests/008/filtenv.txr (f): Don't just copy the input to the output but transform it by upcase-str. Otherwise the test will pass even if the :filter syntax is not processed at all! * tests/08/filtenv.expected: Updated.
* Test cases for macros in quasiliterals.Kaz Kylheku2017-01-181-0/+11
| | | | * tests/012/quasi.tl: New tests added.
* bugfix: dynamic env handling in parallel bindingKaz Kylheku2016-12-231-0/+29
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In the parallel binding (let ((x s) (s 0) (y s)) ...), both x and y must bind to the prior value of s, not to the new value 0. We have the bug that if s is a special variable, the initialization of y sees the new dynamic environment which contains the new value, so x gets the previous, y gets new. This commit fixes it. * eval.c (reparent_env): New static function. (bindings_helper): Separate logic into two loops, for sequential and parallel binding, so we don't have to repeatedly test this condition in the loop body, and can think separately about each case and streamline it. Nothing new happens under sequential binding; the behavior that is wrong for parallel binding is right for sequential. Under parallel binding, what we do is reset the dynamic environment to the original one prior to each evaluation of an initform. Then if the evaluation changes to a new dynamic environment (a special variable is being bound), we notice this and hook the new environment into a local stack, changing it parent pointer. At the end, we install this stack as the new dynamic env. Thus each init form is evaluated in the original dynamic env. * tests/011/special-1.tl: New tests added.
* Use with-out-string-stream macro in test.Kaz Kylheku2016-12-231-5/+1
| | | | | * tests/011/special-1.tl (with-output-to-string): macro removed; with-out-string-stream used.
* Convert special-1 test from txr to tl.Kaz Kylheku2016-12-232-10/+9
| | | | | * tests/011/special-1.txr: Renamed to tests/011/special-1.tl and @(do ...) removed.
* Refactoring internals of for/each operators.Kaz Kylheku2016-12-181-9/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | NOTE: The socket test cases do not pass under this commit: this is expected. The for and each family of operators will now be macros which expand to let/let* binding construct wrapping a lower level special operator. This is in preparation for a change to how special variable binding is implemented. This change reduces the number of special forms which bind variables. There is a single low-level operator for for loops called sys:for-op. Its syntax is a lot like the C89 for loop: (sys:for-op init-forms test step-forms body). The init-forms do not bind anything; it is just forms. There is a sys:each operator for implementing each, each*, append-each and all those operators. Its syntax is (sys:each-op type-sym optional-vars . body). The type-sym is one of each, append-each or collect-each. If optional-vars is nil, then the operator looks at the immediate lexical environment, and assumes all the bindings there are the each iteration variables and it works with those bindings, like its predecessor did. Otherwise optional-vars is a list of symbols: the operator walks the list and resolves each element to a binding. This is used in two situations: when some of the variables are special (dynamically scoped) or when the variables are bound sequentially with let* and are thus scattered in multiple levels of environment. * eval.c (for_op_s, each_op_s): New symbol variables. (get_bindings): New static function. (op_each): Now implements sys:each-op. (op_for): Now implements sys:for-op. (get_var_syms): New static function. (me_each, me_for): New static functions. (do_expand): Do not expand the each operator family under the same rule. New case handling sys:each-op is introduced due to the different syntax. The for case restructured to handle for_op_s. (eval_init): Intern sys:each-op and sys:for-op symbols. Register the corresponding operators. Move registrations of the public symbols each, each*, for, for* and all the other each variants to be macros. * tests/011/macros-2.expected: Updated with different macro expansion which is now produced for a while loop.
* conformance: handle macro wrong clause syntax.Kaz Kylheku2016-11-291-1/+1
| | | | | | | | | | | | | | | | Contrary to the documentation, handle doesn't in fact have the same syntax as catch. It passes the exception symbol to clauses as the leftmost argument, followed by the exception arguments, whereas catch passes only the exception arguments. * share/txr/stdlib/except.tl (handle): Do not pass the exception sybmol as the leftmost argument, unless operating in TXR 161 or earlier compatibility. * tests/012/except.tl: drop exception symbol argument from handle clause. * txr.1: Compatibility note added.
* Expander warns about unbound variables.Kaz Kylheku2016-11-263-13/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * eval.c (eval_exception): New static function. (eval_error): Reduced to wrapper around eval_exception. (eval_warn): New function. (me_op): Bind the rest symbol in a shadowing env to suppress watnings about unbound rest. (do_expand): Throw a warning when a bindable symbol is traversed that has no binding. (expand): Don't install atoms as last_form_expanded. * lib.c (warning_s, restart_s, continue_s): New symbol variables. (obj_init): Initialize new symbol variables. * lib.h (warning_s, restart_s, continue_s): Declared. * lisplib.c (except_set_entries): New entries for ignwarn and macro-time-ignwarn. * parser.c (repl_warning): New static function. (repl): Use repl_warning function as a handler for warning exceptions: to print their message and then continue by throwing a continue exception. * parser.y (warning_continue): New static function. (parse_once): Use warning_continue to ignore warnings. In other words, we suppress warnings from Lisp that is mixed into TXR pattern language code, because this produces too many false positives. * share/txr/stdlib/except.tl (ignwarn, macro-time-ignwarn): New macros. * share/txr/stdlib/place.tl (call-update-expander, call-clobber-expander, call-delete-expander): Ignore warnings around calls to sys:expand, because of some gensym-related false positives (we expand code into which we inserted some gensyms, without having inserted the constructs which bind them. * tests/011/macros-2.txr: Suppress unbound variable warnings from a test case. * tests/012/ifa.tl: Bind unbound x y variables in one test case. * tests/012/struct.tl: Suppress unbound variable warnings in some test cases. * uwind.c (uw_throw): If a warning is unhandled, then print its message with a "warning" prefix and then throw a continue exception. (uw_register_subtype): Eliminate the check for sub already being a subtype of sup. This allows us to officially register new types against t. (uw_late_init): Register continue exception type as a subtype of the restart type. Formally register warning type. * txr.1: Documented ignwarn.
* New arithmetic tests.Kaz Kylheku2016-11-152-0/+41
| | | | | | | | | * Makefile (TXR_DBG_OPTS): Suppress for new directory tests/016. * tests/016/arith.tl: New file. * tests/016/arith.expected: New file.
* Introduce case{q,ql,qual}* macros which eval keys.Kaz Kylheku2016-11-121-1/+1
| | | | | | | | | | | | | | * eval.c (caseq_star_s, caseql_star_s, casequal_star_s): New symbol variables. (me_case): Implement new macro semantics. (eval_init): Initialize new symbol variables, and register the symbols to the me_case macro expander. * tests/sock-common.tl (local-addr): This function depends on the old broken caseql semantics which evaluate keys. Using caseql* makes it work again. * txr.1: Document case{q,ql,qual}* macros.
* Deprecated undocumented *user-package* etc.Kaz Kylheku2016-11-081-1/+1
| | | | | | | | | | | * eval.c (eval_init): Do not register *user-package*, or *system-package* or *keyword-package* variables unless in compatibility mode. We don't document this in the compatibility notes since the variables are not documented. * tests/009/json.txr: Change use of *keyword-package* to keyword-package.
* Circ print: fix recursion from print methods.Kaz Kylheku2016-11-012-0/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Two issues addressed here, both occurring when *print-circle* is enabled and an object has struct components which have a custom print method that re-enters the object printer. One issue is that the children of these components which occur just once print with spurious labels: like #3=, when no matching #3# occurs. The other bug is a wrong "unexpected duplicate object" exception caused by mismanagement of the child object's label hash table and its merging with the parent. * stream.h (struct stream_ctx): New member, obj_hash_prev. Makes the parent hash table known to populate_obj_hash, if there is a table, otherwise nil. * lib.c (populate_obj_hash): If there is a parent table, check each object in it. If it occurs, then bail. I.e. don't add objects to the child table which occur in the parent. This fixes both issues. Also, we do the unexpected duplicate object check right here now: if we traverse an object that already printed without a label (because it is not known to be duplicate), that means that a custom print method is inappropriately introducing new references to existing objects, contrary to the rules. (obj_hash_merge): The logic here is now simplified. All entries in the child table are simply moved to the parent. If anything already exists, that is an unexpected stuation indicating an internal problem, turned into a variant of the unexpected duplicate object message. * tests/012/circ.tl: New file, giving tests for the bugs. * tests/012/circ.expected: New file.
* Fix tok-str semantics once again.Kaz Kylheku2016-10-261-8/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The problem is that when the regular expression is capable of matching empty strings, tok-str will extract an empty token immediately following a non-empty token. For instance (tok-str "a,b" /[^,]*/) extracts ("a" "" "b") instead of just ("a" "b"). This is a poor behavior and the way to fix it is to impose a rule that an empty token must not be extracted immediately at the ending position of a previous token. Only a non-empty token can be consecutive to a token. * lib.c (tok_str): Rewrite the logic of the loop, using the prev_empty flag to suppress empty tokens which immediately follow non-empty tokens. The addition of 1 to the position when the token is empty to skip a character is done at the bottom of the loop and a new last_end variable keeps track of the end position of the last extracted token for the purposes of extracting the keep-between area if keep_sep is true. The old loop is preserved intact and enabled by compatibility. * tests/015/split.tl: Multiple empty-regex test cases for tok-str updated. * txr.1: Updated tok-str documentation and also added a note between the conditions under which split-str and tok-str, invoked with keep-sep true, produce equivalent output. Added compatibility notes.
* Fix non-working quasiquote over struct literals.Kaz Kylheku2016-10-241-4/+3
| | | | | | | | | | | | | | | | | | | | Turns out that there is missing support for quasiquoting over structs. Code analogous to the way vector and hash literals are handled is missing for structs. * eval.c (expand_qquote_rec): Handle struct_lit_s forms specially, like hash_lit_s and vector_lit_s. commit 1e5bc5708d5763f20a7774f9348e825304a51adc * struct.c (make_struct_lit_s): New symbol variable. (struct_init): Store interned sys:make-struct-lit symbol into make_struct_lit_s, and use that to register the function. * struct.h (make_struct_lit_s): Declared. * tests/012/struct.tl: Update struct literal quasiquote test cases to reflect fixed behavior.
* Changes to the printing framework.Kaz Kylheku2016-10-201-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The print function now takes an optional boolean for pretty printing. The print method is also called with a third argument; hence structures can customize both standard printing and pretty printing. * lib.c (obj_print): Take pretty argument, and pass it down to obj_print_impl. This makes obj_pprint redundant. (obj_pprint): Function removed: it was identical to obj_print except for passing t down to obj_print_impl for the pretty argument. These two wrappers had started small and got bigger with identical changes done in parallel. (pprint): New function. (tostring, dump): Pass nil for pretty argument of obj_print. (tostringp): Use pprint instead of obj_pprint. * lib.h (obj_print): Declaration updated. (obj_pprint): Declaration removed. (print, pprint): Declared. * eval.c (prinl): Pass nil for pretty_p argument of obj_print. Do the stream defaulting here; obj_print doesn't do it. (pprinl): Pass t for pretty_p argument of obj_print, and do stream argument defaulting. (eval_init): Register print to new print function rather than directly to obj_print. Register pprint to new pprint function rather than obj_pprint. * hash.c (hash_print_op): Call obj_print_impl to print the :equal-based keyword, rather than obj_print. Pass down the pretty flag. All the other keywords are treated this way; this fixes an inconsistency. * match.c (dump_var): Call pprint instead of obj_pprint. * stream.c (formatv): Call obj_print, with a calculated pretty argument instead of switching between obj_pprint and obj_print. * struct.c (struct_inst_print): Except when in backward compatibility mode, call the object's print method in both pretty and regular printing mode, passing the mode as a third argument. * tests/012/oop.tl (defstruct animal): Support third argument in print method. Make it optional because there are some explicit calls which don't pass the argument. * txr.1: Documentation updated for print method and the print function. Revised text for some of the related functions. Added compat notes.
* Fix struct lit problem exposed by circular syntax.Kaz Kylheku2016-10-201-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The semantics of how struct literals come to life is poorly designed: namely, the slot-value pairs in the struct literal are used as the plist argument in a call to make-struct. This is wrong because the implied initializations are then clobbered by the structure type's :init and :postinit handlers, resulting in an object with slot values that don't match what is in the literal. When you add circular syntax to the mix, things get worse. Slots may be initialized with (sys:circ-ref ...) expressions corresponding to #<n># syntax. These expressions then get clobbered by the constructor actions before the circ_backpatch processes the syntax. * parser.y (struct): Use make_struct_lit rather than make_struct to instantiate struct object. * struct.tl (sys:struct-lit): Expand to a form which calls sys:make-struct-lit, rather than make-struct. * struct.c (struct_init): Register new make_struct_lit function as sys:make-struct-lit intrinsic. (make_struct_lit): New function. * struct.h (make_struct_lit): Declared. * tests/012/struct.tl: struct literal expansion test case updated. * txr.1: Updated documentation of struct literals. Added compat notes.
* Bugfix: sub and length on abstract sequences.Kaz Kylheku2016-10-132-0/+15
| | | | | | | | | | * lib.c (length_proper_list): New static function. (length): Use length_proper_list for objects. (sub): Call nullify on COBJ object before passing to sub_list. * tests/012/aseq.tl, tests/012/aseq.expected: New files.
* Support curried args in method and meth.Kaz Kylheku2016-10-092-0/+13
| | | | | | | | | | | | | | | | | | | | | * share/txr/stdlib/struct.tl (meth): Take trailing arguments and pass them down to method, which now accepts them. * struct.c (struct_init): Register method intrinsic to the function method_args instead of the method function. (method_args_fun): New static function. (method_args): New function. Behaves like method function if args is empty, otherwise creates a function by means of method_args_fun. * struct.h (method_args_fun): Declared. * tests/012/oop.tl: New test case. * tests/012/oop.expected: Updated. * txr.1: Documented new features in method and meth, revising the documentation in the process.
* Support curried arguments in umethod and umeth.Kaz Kylheku2016-10-092-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | * share/txr/stdlib/struct.tl (umeth): accept variadic arguments. Evaluate them using the dwim brackets and pass to umethod. The (fun umethod) trick is used to refer to the umethod in the function namespace even if it is shadowed by a variable. * struct.c (struct_init): Update registration of umethod to reflect its new variadic argument signature. (umethod_args_fun): New static function. (umethod): Return a function based on umethod_fun, as before, if there are no variadic args. Otherwise, use umethod_args_fun which deals with them. * struct.h (umethod): Declaration updated. * tests/012/oop.tl: Modest testcase for umeth with curried argument. * tests/012/oop.expected: Updated. * txr.1: Updated documentation of umeth and umethod.
* Revision of static slot inheritance.Kaz Kylheku2016-09-302-0/+83
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fixing the broken static slot handling in TXR Lisp's "OOP structs" object system. Inherited static slots are now shared with the base type; only static slots explicitly defined in a derived type have a distinct global instance in that type. * share/txr/stdlib/struct.tl (sys:prune-nil-inits): Function removed. (sys:prune-missing-inits): New function. We now handle static slot forms with missing inits specially, not those with nil or missing inits. (defstruct): Translate a (word name) form to (word name) rather than (word name nil) if word is :static, because we need this nuance for non-shared static slots, so they can inherit the value from the base struct. For the purposes of generating the static init function, prune away all the static slot forms that do not have an initializer; we let those default. * struct.c (struct stslot): New struct for representing a static slot. (stslot_loc, stslot_place): New macros. (struct struct_type): Member eqmslot changes to a pointer to a struct stslot. The stslot dynamic array is no longer an array of val, but an array of stslot structs. (call_stinitfun_chain): The superclass chain of static init functions is now called only in compatibility mode. Otherwise only the type's own static init fun is called, which defclass uses to initialize just the new or repeated static slots. Inherited static slots are completely left alone; they do not require initialization. (static_slot_home_fixup): New static function; needed to fix some internal pointers within the static slot arrays if they are realloc'ed. (make_struct_type): Considerably revised to implement new scheme, while providing backward compatibility switching. New slots live in the struct stslot in which they are allocated. Inherited slots have home pointers to within the array in the base. (struct_type_mark): When walking the static slots, mark only the store cells of those which live in this array. Those that live elsewhere should have store cells that are nil; let's assert on it. (lookup_slot): Static slot lookup code has to retrieve slots in the new way, indirecting through the home pointer, which is hidden behind the stslot_loc macro. (lookup_static_slot_desc): New function, like lookup_static_slot, but returning a pointer to the struct stslot. Formed from the guts of lookup_static_slot. (lookup_static_slot): Gutted and turned into a wrappar around lookup_static_slot_desc. (static_slot_set): Simple change here: add cast because of the pointer type of eqmslot. (static_slot_home_fixup_rec): New static function. Fixes up the cached home in slot arrays in an entire type hierarchy rooted at a given type, which has to be done when its static slot has been reallocated, so all those inherited static slot pointers in the derived types are invalid. (static_slot_rewrite_rec): New static function: rewrites a particular inherited static slot in an inheritance hierarchy to point to a different slot. (static_slot_ens_rec): New static function: factored out recursive logic of static_slot_ensure. Substantially rewritten to handle new static slot scheme, plus support backward compatibility. There is a bug fixed here: if an instance slot is encountered in the no_error_p mode, it looks like we were dereferencing through an invalid ptr through the set(ptr, newval) line. (static_slot_ensure): A wrapper now for static_slot_ens_rec. (get_equal_method): Rework the logic related to the eqmslot member of the struct_type structure, in terms of it being a pointer now rather than an integer. The value -1 cast to a pointer serves the previous -1 sentinel value which indicates that it is confirmed (for the time being) that this type doesn't have an equal method. * txr.1: All documentation related to static slots updated, and compatibility notes added. * tests/012/oop.tl, tests/012/oop.expected: New files.
* Use *load-path* in load/include directive.Kaz Kylheku2016-09-261-1/+1
| | | | | | | | | | | | | | * match.c (v_load): Obtain parent load path from *load-path* variable, rather than from source location info associated with the directive. This changes the semantics of when a @(load ...) occurs in code included via @(include ...). That @(load ...) is processed in the *load-path* context of the parent, rather than the include. * tests/011/txr-case.txr: Load txr-case.txr from the standard library, rather than include it. Otherwise txr-case.txr looks for txr-case.tl in tests/011.
* Tests for tok-str.Kaz Kylheku2016-09-172-0/+73
| | | | * tests/015/split.tl: New cases added.
* Adding tests for split-str.Kaz Kylheku2016-09-172-0/+126
| | | | | | | | * Makefile (TXR_DBG_OPTS): Disable for tst/tests/015. * tests/common.tl (mtest): New macro. * tests/015/split.tl: New file.
* Optimize qref and sys:rslot using slet.Kaz Kylheku2016-09-081-14/+8
| | | | | | | | | | | * share/txr/stdlib/struct.tl (qref): Use slet instead of let in expansion so that in the common case of var.(method ...) the expansion simply produces a form with var evaluated in two places. (sys:rslot): Use slet instead of rlet. * tests/012/struct.tl: Update qref expansion test-cases to test for the now simpler expansions.
* Replace most TXR eval with Lisp eval.Kaz Kylheku2016-06-142-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * match.c (tlist_k): New keyword symbol variable. (tleval_144): New static function. (h_skip): evaluate min and max arguments as Lisp. (h_coll): Evaluate all numeric keyword arguments as Lisp: :min, :max, :gap, :times, :maxtimes, :mintimes, :chars. (h_call): Evaluate function expression as Lisp. (do_output_line, do_output): Evaluate n and m parameters in @(modlast) and @(mod) as Lisp. (v_skip): Evaluate min and max as Lisp. (v_fuzz): Evaluate m and n as Lisp. (v_freeform): Evaluate arguments as Lisp. (v_next): Support new argument, :tlist, which is like :list, but with TXR style evaluation. From now on :list uses Lisp evaluation, unless compatibility is set to 143 or lower. Also, evaluate the :string argument as Lisp. (v_collect): Evaluate all numeric keyword arguments as Lisp: :min, :max, :gap, :times, :maxtimes, :mintimes, :lines. (v_output): Evaluate stream in :continue or :finish expression as Lisp. (v_load): Evaluate load target as Lisp. (v_close): Evaluate stream argument as Lisp. (v_call): Evaluate function expression as Lisp. (syms_init): Initialize tlist_k variable. * tests/007/except-1.txr: Use :tlist instead of :list, since argument is a TXR list expression. * tests/010/block.txr: Likewise.
* Use random padding in PRNG rather than 0xAA.Kaz Kylheku2016-04-281-59/+59
| | | | | | | | | | | | | | | | | | | | | | | | The purpose is to eliminate any biases in the PRNG arising out of the regularity of that pattern, so that the behavior of successive values is good from the beginning. This doesn't solve the problem that a short warm-up period leads to a poor distribution of initial values relative to the seed space. In other words, that similar seeds lead to initially similar sequences. * rand.c (rand_tab): New static array. (make_random_state): Set uninitialized parts of state from the corresponding elements in rand_tab, rather than to the 0xAAAAAAAA values. (rand_compat_fixup): In 139 compatibility mode, clobber rand_tab with 0xAA bytes. * tests/013/maze.expected: Updated. * txr.1: Added some PRNG implementation notes, and also compatibility notes.
* Run IPv6 tests only on some operating systems.Kaz Kylheku2016-03-102-4/+11
| | | | | | | | | | * tests/014/dgram-stream.tl (test): Renamed to dgram-test since now this includes common.tl which has a macro called test. Only include af-inet6 in the family list if the OS is GNU/Linux, Darwin or Cygwin. * tests/common.tl (osname): New function.
* Dgram test: multiple transfers on one stream, IPv6.Kaz Kylheku2016-03-072-0/+39
| | | | | | * tests/014/dgram-stream.tl: New file. * tests/014/dgram-stream.expected: New file.
* Basic regression test case for sockets.Kaz Kylheku2016-03-073-0/+44
| | | | | | | | | | * Makefile: suppress --gc-debug for tst/tests/014 directory. * tests/014/socket-basic.tl: New file. * tests/014/socket-basic.expected: New file. * tests/sock-common.tl: New file.
* random: wrong mask width for power-of-two moduli.Kaz Kylheku2016-01-181-59/+59
| | | | | | | | | | | | | | | | | | | | | | | This mistake causes wasteful behavior for power-of-two moduli in the random function, in both the bignum and fixnum cases. For instance, the modulus 16 is taken to be 17 bits wide. But we really want the width 16: the number of bits needed for values in the range [0, 16). The result isn't wrong, but the loop generates 17-bit random numbers, and then throws away those which equal or exceed the modulus, which is wasteful. * mpi/mpi.c (mp_is_pow_two): New function. * mpi/mpi.h (mp_is_pow_two): Declared. * rand.c (random): In bignum case, after counting bits in the modulus, subtract 1 if the modulus is a power of two. In the fixnum case, subtract 1 from the modulus and then count the bits in the reduced value. * tests/013/maze.expected: regenerate due to different prng behavior.
* Useful feature: object post-initialization.Kaz Kylheku2015-12-161-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Structs can now have code which executes after an object is initialized, which is useful for doing work like registering objects in global lists and whatever, when those actions need access to the initialized slots of the object. * share/txr/stdlib/struct.tl (defstruct): Handle :posinit syntax, by generating lambda as eighth argument of sys:make-struct call. * struct.c (struct struct_type): New member, postinitfun. (struct_init): Adjust registrations of make_struct_type to account for new parameter. The user visible make-struct-type is registered as having one optional argument, for backward compat. (make_struct_type): New argument, postinitfun. Store this in the structure. For backward compatibility, the argument is defaulted. (struct_type_mark): Mark the new postinitfun member. (call_postinitfun_chain): New static function. (make_struct, lazy_struct_init): Call call_postinitfun_chain after slots are initialized, and after the boa function is called. * struct.h (make_struct_type): Declaration updated. * lib.c (time_init): Pass eighth argument to make_struct type. * sysif.c (sysif_init): Likewise. * unwind.c (uw_late_init): Likewise. * tests/012/struct.tl: Update defstruct expansion test case. * txr.1: Document new argument of make-struct-type, and clarify ordering of initfun with regard to other actions. Likewise, document :postinit, and clarify ordering of :init actions with regard to other actions.
* Add man or boy test, based on Knuth's Algol 60 code.Kaz Kylheku2015-11-232-0/+69
| | | | | | | | | | Seems like a good regression test case, combining structs, macros, lambdas, recursion, environments and syntactic places. * tests/012/man-or-boy.tl: New file. * tests/012/man-or-boy.expected: Likewise.
* Add amb test case for continuations.Kaz Kylheku2015-11-021-0/+20
| | | | | | * tests/012/cont.tl (amb-scope): New macro. (amb): New function. New test case using amb.
* New range type, distinct from cons cell.Kaz Kylheku2015-11-011-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * eval.c (eval_init): Register intrinsic functions rcons, rangep from and to. (eval_init): Register rangep intrinsic. * gc.c (mark_obj): Traverse RNG objects. (finalize): Handle RNG in switch. * hash.c (equal_hash, eql_hash): Hashing for for RNG objects. * lib.c (range_s, rcons_s): New symbol variables. (code2type): Handle RNG type. (eql, equal): Equality for ranges. (less_tab_init): Table extended to cover RNG. (less): Semantics defined for ranges. (rcons, rangep, from, to): New functions. (obj_init): range_s and rcons_s variables initialized. (obj_print_impl): Produce #R notation for ranges. (generic_funcall, dwim_set): Recognize range objects for indexing * lib.h (enum type): New enum member, RNG. MAXTYPE redefined to RNG value. (TYPE_SHIFT): Increased to 5 since there are now 16 type codes. (struct range): New struct type. (union obj): New member rn, of type struct range. (range_s, rcons_s, rcons, rangep, from, to): Declared. (range_bind): New macro. * parser.l (grammar): New rule for recognizing the #R sequence as HASH_R token. * parser.y (HASH_R): New terminal symbol. (range): New nonterminal symbol. (n_expr): Derives the new range symbol. The n_expr DOTDOT n_expr rule produces rcons expression rather than const. * match.c (format_field): Recognize rcons syntax in fields which is now what ranges translate to. Also recognize range object. * tests/013/maze.tl (neigh): Fix code which destructures range as a cons. That can't be done any more. * txr.1: Document ranges.
* Add some tests for continuations.Kaz Kylheku2015-10-282-0/+19
| | | | | | * tests/012/cont.tl: New file. * tests/012/cont.expected: New file.
* New test case for handle and frame introspection.Kaz Kylheku2015-10-172-0/+19
| | | | | | * tests/012/except.tl: New file. * tests/012/except.expected: New file.
* Tweaking expansions of when and until.Kaz Kylheku2015-10-091-4/+4
| | | | | | | * eval.c (me_when): Expand to if if there aren't multiple body forms. (me_unless): Simplify progn. * tests/012/struct.tl: Update string representation in struct test case.
* Optional arguments in boa construction.Kaz Kylheku2015-10-041-2/+2
| | | | | | | | | | | | * share/txr/stdlib/struct.tl (defstruct): Split boa arguments on colon and generate the lambda accordingly. The generated function detects which optional arguments are actually present and only performs the slot updates for those. * tests/012/struct.tl: Corrected boa test case. * txr.1: Documented.
* Optimize empty lambdas in defstruct.Kaz Kylheku2015-09-301-16/+14
| | | | | | | * share/txr/stdlib/struct.tl (defstruct): Don't generate lambdas with empty body; just generate nil, which make-struct-type accepts. * tests/012/struct.tl: Updated defstruct expansion test.
* Implementation of static slots for structures.Kaz Kylheku2015-09-291-12/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * share/txr/stdlib/struct.tl (sys:bad-slot-syntax): New helper function. (defstruct): Macro revamped with new slot specifier syntax for writing static slots as well as methods. * struct.c (STATIC_SLOT_BASE): New preprocessor symbol. (struct struct_type): New members, nstslots, stinitfun, stslot. (make_struct_type_compat): New static function. (struct_init): Register make-struct-type to make_struct_type_compat if compatibility is 117 or lower. Register new intrinsics static-slot, static-slot-set, call-super-method, call-super-fun, slot-p and static-slot-p. (call_stinitfun_chain): New static function. (make_struct_type): Two new arguments for specifying static slots and an initialization function for them. Logic added for setting up static slots and handling inheritance. (struct_type_destroy): New static function. (struct_type_mark): Mark the new stinitfun member of struct type. Also iterate over the static slots in the new stslot array and mark them. (lookup_slot): Altered to return a loc instead of a raw pointer, and also to accept the instance object as a member. Now resolves static slots: it can return a loc which references a static slot in the structure type, or an instance slot in the structure. (lookup_static_slot): New static function. (slot, slotset): Implementation adjusted due to new lookup_slot interface. (static_slot, static_slot_set, slot_p, static_slot_p): New functions. (call_super_method, call_super_fun): New static functions. (struct_inst_print): This function can no longer assume that the slots list lines up with the array of slots, since it contains a mixture of static and instance slots. Earnest slot lookup has to be performed. (struct_type_ops): Point the destroy function to struct_type_destroy instead of cobj_destroy_free_op. A structure type now has an array of static slots to free. * struct.h (make_struct_type): Declaration updated. (static_slot, static_slot_set, slot_p, static_slot_p): Declared. * lib.c (time_init): Update call to make_struct_type with new arguments. * sysif.c (sysif_init): Likewise. * tests/012/struct.tl: Update defstruct macro expansion test. * txr.1: Documented static slots and new functions.
* More tests for ifa/conda.Kaz Kylheku2015-09-271-0/+15
| | | | | | * tests/012/ifa.tl: New test cases which test the expansion when the it-form is a place and there are forms before and after it.
* More informative printed rep for functions.Kaz Kylheku2015-09-091-1/+1
| | | | | | | | | * lib.c (obj_print_impl): Print whether a function is interpreted or intrinsic, and include argument information. * tests/012/struct.tl: Test case relying on function printed rep updated.
* Adding struct tests.Kaz Kylheku2015-09-023-4/+148
| | | | | | | | | | | | * tests/common.tl (vtest): New macro based on test. Evaluates the expected expression. (test): Becomes a wrapper for vtest which quotes the expected expression. (stest): New macro for string-based comparison of output. * tests/012/struct.expected: New file. * tests/012/struct.tl: New file.
* Add maze generation to test suite.Kaz Kylheku2015-08-242-0/+152
| | | | | | | | | * Makefile (tst/tests/013/maze.out): Add TXR_ARGS. Disable gc-debugging for tests in new directory. * tests/013/maze.expected: New file. * tests/013/maze.tl: New file.
* Fix broken @@@<n>/@@@rest references in quasiliterals.Kaz Kylheku2015-08-191-0/+4
| | | | | | | | * parser.y (quasi_meta_helper): When obj is a sys:var, leave it alone; don't add another layer of var. Also, do the same if it is a sys:expr. * tests/012/quasi.tl: Added test case.
* Quasiquote regression from 110.Kaz Kylheku2015-08-191-0/+8
| | | | | | | | | | | | | | | | The problem is that one-argument function calls like @(whatever arg) in a quasiliteral being turned into sys:var items. * parser.y (quasi_meta_helper): Remove bogus check on length. The default case is now var, so the var_s check actually matters. The integerp check for the argument of a var form didn't do anything because the entire if statment conditionally selected a useless goto. Removing it for consistent treatment of var items. * tests/012/quasi.tl: Some new test cases involving @rest. These new tests pass whether or not we have that integerp(second(obj)) test in the quasi_meta_helper function. Either way @rest and @@rest produce the same thing.