summaryrefslogtreecommitdiffstats
Commit message (Collapse)AuthorAgeFilesLines
...
* Start of fallback package list implementation.Kaz Kylheku2016-11-165-11/+72
| | | | | | | | | | | | | | | | | | | | * eval.c (eval_init): Register package-fallback-list and set-package-fallback-list intrinsics. * lib.c (package_fallback_list, set_package_fallback_list, intern_fallback): New functions * lib.h (package_fallback_list, set_package_fallback_list, intern_fallback): Declared. * parser.y (sym_helper): Slightly restructure function so that the symbol interning is done separately in the various cases. In the unqualified symbol case, use intern_fallback to search the fallback list of the current package. * share/txr/stdlib/package.tl (defpackage): Implement :fallback clause.
* Adjust some gen-gc array sizes.Kaz Kylheku2016-11-151-2/+2
| | | | | | | | | | | | | | Tuning some parameters by experimenting with timings. * gc.c (CHECKOBJ_VEC_SIZE): Reduce to 2*HEAP_SIZE; this doesn't have to be equal in size to FRESHOBJ_VEC_SIZE; entries into the checkobj array are not expected to be as frequent as in the freshobj array. (MUTOBJ_VEC_SIZE): On the other hand, at HEAP_SIZE/4, this may be too small. Increasing to 2*HEAP_SIZE. Overall, the storage for these arrays is reduced by over 25%, with seemingly better performance.
* Version 158.txr-158Kaz Kylheku2016-11-156-520/+545
| | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise. * txr.vim, tl.vim: Regenerated.
* doc: fixes under equal method.Kaz Kylheku2016-11-151-2/+4
| | | | * txr.1: clarification; article-noun plurality agreement.
* mpi: must clamp result of conversion to bignum.Kaz Kylheku2016-11-151-0/+3
| | | | | | * mpi/mpi.c (mp_set_uintptr, mp_set_double_intptr): The value of z might not require all of the digits implied by the size of its C data type. We must clamp the result to trim trailing zero limbs from the bignum.
* New arithmetic tests.Kaz Kylheku2016-11-153-0/+42
| | | | | | | | | * Makefile (TXR_DBG_OPTS): Suppress for new directory tests/016. * tests/016/arith.tl: New file. * tests/016/arith.expected: New file.
* Fix bad mutation in arg handling.Kaz Kylheku2016-11-151-2/+1
| | | | | | | | * args.h (args_atz): Do not zap the car field of the first list cons; rather, zap the list itself. The list shouldn't be modified because in apply calls, it is a data structure belonging to the caller.
* mpi: eliminate trailing whitespace.Kaz Kylheku2016-11-142-104/+69
| | | | | | | | | * mpi/mpi-config.h: Eliminate several trailing spaces. * mpi/mpi.c: Eliminate all trailing spaces. Removed some commented-out code, and adjusted brace placement and indentation in one place. Also removed some spurious blank lines.
* Fix bug in bignum addition.Kaz Kylheku2016-11-141-1/+1
| | | | | | | | | * mpi/mpi.c (s_mp_add): It looks like this function had the same kind of bug I fixed years ago in the multiplication routines. ("fix-mult-bug" patch, originally). In the main loop, two digit-sized values are added together to produce a partial sum with carry. Unfortunately, both operands digit-sized, so the result is truncated to the digit type. The cast of one of the operands to mp_word is missing.
* Switch to user package before entering repl.Kaz Kylheku2016-11-141-0/+1
| | | | | | * txr.c (txr_main): The file loaded by the -i command line argument could manipulate *package*. Let's reset *package* to the user package before running the REPL.
* Introducing struct instance dirty flags.Kaz Kylheku2016-11-143-1/+119
| | | | | | | | | | | | | | | | * struct.c (struct struct_inst): New bitfield member, dirty. (struct_init): Register test-dirty, test-clear-dirty and clear-dirty intrinsics. (make_struct): Initialize dirty flag to 1. (slotset): If the object is clean, then determine whether the slot being set is an instance slot. If so, then set the dirty flag. (test_dirty, test_clear_dirty, clear_dirty): New functions. * struct.h (test_dirty, test_clear_dirty, clear_dirty): Declared. * txr.1: Documented dirty flags concept and new functions.
* New in-package macro.Kaz Kylheku2016-11-143-1/+33
| | | | | | | | | * lisplib.c (package_set_entries): Add in-package symbol name to autload list. * share/txr/stdlib/package.tl (in-package): New macro. * txr.1: Documented.
* Version 157.txr-157Kaz Kylheku2016-11-146-646/+705
| | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise. * txr.vim, tl.vim: Regenerated.
* Fix spectacular bug in number of syntactic places.Kaz Kylheku2016-11-131-9/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Test case: (symacrolet ((f g)) (set [f x] y)) fails to expand. The root cause is that f is not expanded, because a nil environment is passed down to with-update-expander macro. This problem affects not only the dwim place, but nthcdr, sub and others. This bug was surprising at first because the Awk macro establishes the field array f via symbol macro. But assignments like (set [f 0] ...) worked! The thing is, they only worked by fluke due to the way expansions are handled in the Awk macro. That fluke came to an end in the November 4 commit 157fd76ee20125f409929b95b768b931268b43cf, just before 156 was released. The changes there don't cause this problem, but they remove the circumstances which protect the awk macro from the problem. So yes, that commit effectively caused another regression in 156: assignment to awk fields not working. * share/txr/stdlib/place.tl (nthcdr, nthlast, ref, sub, dwim): Do not pass an environment value of nil to with-update-expander! Pass the value of the special variable sys:*pl-env* which is there exactly for this purpose: to give to place expanders like these the original macro environment where the form occurs, so they can expand embedded places.
* New functions for command or file I/O in one call.Kaz Kylheku2016-11-133-0/+301
| | | | | | | | | | | | | | | | * lisplib.c (getput_set_entries, getput_instantiate): New static functions. (dlt_register): Register auto-loading for getput module via new functions. * share/txr/stdlib/getput.tl: New file. * txr.1: Documented new functions file-get, file-put, file-append, file-get-string, file-put-string, file-append-string, file-get-lines, file-put-lines, file-append-lines, command-get, command-put, command-get-string, command-put-string, command-get-lines, and command-put-lines.
* Introduce case{q,ql,qual}* macros which eval keys.Kaz Kylheku2016-11-123-4/+95
| | | | | | | | | | | | | | * 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.
* New :use-from clause in defpackage.Kaz Kylheku2016-11-112-4/+48
| | | | | | | | * share/txr/stdlib/package.tl (defpackage): Implemented new :use-from clause. * txr.1: Documented :use-from and made some improvements to the defpackage documentation.
* Clause in case{q,ql,qual} with no forms yields nil.Kaz Kylheku2016-11-112-5/+21
| | | | | | | | * eval.c (me_case): If forms is nil, substitute the object (nil) for forms, to ensure a nil result through the expansion to a cond. * txr.1: Documented and added compat notes.
* Bugfix in case{q,ql,qual} macro expansion.Kaz Kylheku2016-11-112-6/+35
| | | | | | | | | * eval.c (me_case): The key must be quoted unconditionally whether it's an atom or list. Let's make this subject to the compatibility flag in case someone's code depends on it. * txr.1: Compat notes added.
* vim: colorize #n= and #n#.Kaz Kylheku2016-11-113-17/+23
| | | | | | | | | * genvim.txr (txr_circ): New match. Link to Special highlight group. (txr_bracevar, txr_directive, txr_list, txr_mlist, txr_mbracket): Introduce txr_circ into these regions. * txr.vim, tl.vim: Regenerated.
* Add defpackage macro.Kaz Kylheku2016-11-113-0/+152
| | | | | | | | | | | * lisplib.c (package_set_entries, package_instantiate): New static functions. (lisplib_init): Register auto-loading for new package.tl file using new functions. * share/txr/stdlib/package.tl: New file. * txr.1: Documented.
* Streamline variable assignment operators slightly.Kaz Kylheku2016-11-111-15/+12
| | | | | | | | * eval.c (op_setq, op_lisp1_setq): Take the bindable(var) test out of the frequently executed path. We can safely do the variable lookup with any object. If the lookup fails, then we can complain that the object isn't a bindable symbol, if that is the case.
* Fix circular printing issue for package objects.Kaz Kylheku2016-11-101-1/+1
| | | | | | * lib.c (obj_print_impl): Print package name using ~a rather than ~s. Otherwise if the string object occurs elsewhere in the structure being printed, we have a problem.
* Handle interpreted functions in circle printing.Kaz Kylheku2016-11-102-0/+14
| | | | | | | | | | | | | | | | | | | Interpreted functions print as #<interpreted fun: name args>, thus repeating some list structure in their notation. This means we must traverse them when populating the object hash during printing, and also when backpatching after parsing. Test case: evaluate and print (let ((s '(lambda (a b c) d))) (list s (eval s))) with *print-circle* enabled. * lib.c (populate_obj_hash): Handle FUN objects of functype FINTERP. * parser.c (circ_backpatch): Likewise.
* Fix some gc-unsafe mutations found by inspection.Kaz Kylheku2016-11-102-3/+3
| | | | | | | | | | | | | | | | | | * eval.c (force): When replacing the promise by a forced value, we must use the set macro. Only the deref assignments which store symbols are safe, not the one storing ret. * lib.c (alist_nremove, alist_nremove1): We must use the set macro here instead of assigning through deref. Even though these assignments preserve the direction of the list (they just splice out nodes), it's possible that the list already contains a "wrong-way" reference (old generation to new) and that the node making this reference is appropriately marked to be processed properly in the next GC cycle. If we remove *that* node, we then cause its predecessor to point to the new generation node and that predecessor could be old generation.
* Check for non-package value in *package*.Kaz Kylheku2016-11-101-1/+9
| | | | | | * lib.c (get_current_package): If *package* contains nonsense, then reset it to a sane value and throw an exception.
* Implementing package foreign symbol concept.Kaz Kylheku2016-11-105-57/+667
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * eval.c (eval_init): Register new intrinsics: package-local-symbols, package-foreign-symbols, use-sym, unuse-sym, use-package, unuse-package, unintern. * gc.c (mark_obj): Mark new hidhash member of struct package. * lib.c (make_package): Initialize new hidhash member of struct package. (lookup_package): New static function. (find_package): Allow string or symbol argument. (get_package): New static function. (delete_package, package_symbols): Use get_package for flexible package argument; delete_package removes symbols from other packages via unuse_package. (package_local_symbols, package_foreign_symbols): New functions. (use_sym, unuse_sym): New functions. (resolve_package_designators): New static function. (use_package, unuse_package): New functions. (symbol_present): New static function. (intern): Revised with get_package for flexible package argument. (unintern): New function. (rehome_sym): Use get_package. Semantics revised. (obj_print_impl): Use symbol_present function to determine whether object is visible in *package* and can be printed without a prefix, rather than naive home package test. * lib.h (struct package): New member, hidhash. (package_local_symbols, package_foreign_symbols, use_sym, unuse_sym, use_package, unuse_package, unintern): Declared. * txr.1: Documentation updated. Extended section introducing the design of packages, and argument conventions. New functions described. Existing function descriptions revised, particularly rehome-sym. Missing description of delete-package added.
* Check that name is stringp in some sym functions.Kaz Kylheku2016-11-081-6/+18
| | | | | * lib.c (make_sym, make_package, intern): Check that the name argument is a string.
* Implement *package* special var; package overhaul.Kaz Kylheku2016-11-087-43/+57
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * eval.c (load): Rebind *package* in the local dynamic environment already established for the sake of *load-path*. By doing this we cause *package* to be restored to its prior value, which allows the loaded file to alter it. Common Lisp works this way. (eval_init): Register *package* variable, with the user package as its default value. * lib.c (package_s): New symbol variable. (intern, rehome_sym): Default the package argument to the current package, not to user_package. (get_user_package, get_system_package, get_keyword_package): Functions removed. (get_current_package): New function. (obj_print_impl): Revise symbol printing. Keyword and uninterned symbols are printed with : and #: prefixes. The remainder are printed with a package prefix if their home package isn't the current package. * lib.h (keyword_package, user_package, system_package): These macros are just straight aliases for the global variables, not going through the lookup mechanism, which was pointless. (cur_package): New macro. (package_s): Declared. (get_current_package): Declared. * lisplib.c (lisplib_try_load): Establish a local dynamic environment, and bind the *package* variable to the user package which the library modules expect. * parser.c (find_matching_syms, provide_completions): Treat unqualified symbols in the current package rather than user package. * parser.y (sym_helper): Intern unqualified symbols in the current package, not user package. * txr.1: Document that the variables user-package, system-package and keyword-package should not be modified. Document the *package* special variable, and that intern and rehome-sym default their package argument to its value. (Here we get rid of wrong references to the undocumented variable *user-package*).
* Don't access *print-circle* in early init.Kaz Kylheku2016-11-081-1/+1
| | | | | | | | * lib.c (obj_print): Check that print_circle_s has been interned before trying to look it up as a variable. Otherwise the auto-load code will be triggered, and try to use a hash table that doesn't exist yet. This can happen when this code is called during early initialization.
* Deprecated undocumented *user-package* etc.Kaz Kylheku2016-11-082-4/+6
| | | | | | | | | | | * 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.
* Support #: reading for uninterned symbols.Kaz Kylheku2016-11-073-10/+92
| | | | | | | | | | | | | | * parser.l (BTKEY, NTKEY): Renamed to BTKWUN and NTKWUN ("keyword and uninterned") respectively. Include an optional match for the # character. (BTOK, NTOK): Refer to BTKEY and NTKEY respectively * parser.y (sym_helper): Implement uninterned symbols by detecting when the package name string is "#" and handling specially. * txr.1: Documented package prefixes and uninterned symbols.
* New #; syntax for erasing following object.Kaz Kylheku2016-11-078-17/+165
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * parser.c (parser_circ_ref): Don't generate the circular reference if circular suppression is in effect. * parser.h (struct parser): New member, circ_suppress. We use this for suppressing the generation of circular #n# references in erased objects. * parser.l (grammar): Scan #; producing HASH_SEMI token. * parser.y (HASH_SEMI): New token. (hash_semis_n_expr, hash_semis_i_expr, ignored_i_exprs, ignored_n_exprs): New nonterminals, needed for supporting the use of #; in front of top-level forms. (spec): Use hash_semis_n_expr and hash_semis_i_expr instead of n_expr and i_expr. (r_expr): Support object erasure within nested syntax. (yybadtoken): Handle H_SEMI token. (parse): Initialize new circ_suppress member of parser struct to zero. * txr.1: Documented. * genvim.txr (txr_ign_par, txr_ign_bkt, txr_ign_par_interior, txr_ign_bkt_interior): New regions for colorizing erased objects (partial support). (txr_list, txr_bracket, txr_mlist, txr_mbrackets): Include erased objects by including regions txr_ign_par and txr_ign_bkt. * txr.vim, tl.vim: Regenerated.
* vim syntax: support #H properly, plus #R, #S.Kaz Kylheku2016-11-073-3/+3
| | | | | | * genvim.txr (txr_list): Rewrite start delimiter regex. * txr.vim, tl.vim: Regenerated.
* parser: missing case for #R in yybadtoken.Kaz Kylheku2016-11-071-0/+1
| | | | | * parser.y (yybadtoken): HASH_R token not handled; must be mapped to "#R" string.
* Fix regression: infinite loop in place expansion.Kaz Kylheku2016-11-061-4/+6
| | | | | | | | | | | | This shows up when the anaphoric ifa is used. Test case: | (ifa (f a) | (set it (g it))) * share/txr/stdlib/place.tl (sys:pl-expand): In the origin chasing loop, use a stack to more thoroughly detect a cycle.
* Version 156.txr-156Kaz Kylheku2016-11-056-502/+565
| | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise. * txr.vim, tl.vim: Regenerated.
* Expose slots function.Kaz Kylheku2016-11-052-1/+16
| | | | | | | * struct.c (struct_init): Register slots intrinsic. (slots): Pass correct name string to stype_handle. * txr.1: Slots function documented.
* Fix broken tracking of place expansion origins.Kaz Kylheku2016-11-041-14/+22
| | | | | | | | | | | | | | | | | | | | | | | | | This change actually achieves the original intent that forms generated by place expansion register the place as their macro-expansion origin, enabling clearer diagnostics when things go wrong in that generated code. * share/txr/stdlib/place.tl (sys:cp-origin): Drop the syms argument; it's useless because we want to walk over the fully expanded to-tree in which those syms (denoting the names of local macros) will no longer appear. Now instead we find any conses in to-tree which already have macro ancestors. We trace the ancestor chain to the end and install the place form as the grand-ancestor, to express that all the expansion ultimately is derived from the place that is being manipulated. (call-update-expander, call-clobber-expander, call-delete-expander): After calling the expander, fully expand whatever it returns in the given environment. Then, propagate place as the macro origin throughout the forms contained in the expansion before returning it.
* Don't track macro origin of interned objects.Kaz Kylheku2016-11-041-1/+3
| | | | | | * eval.c (set_origin): If either form or origin isn't a heap object, or is an interned symbol, then don't record the relationship.
* Remove spurious slash in cadr autoload pathname.Kaz Kylheku2016-11-042-2/+2
| | | | | | | * cadr.c: Regenerated. * gencadr.txr (cadr_register): stdlib_path already has a slash; we don't have to add one.
* Don't print distracting path in error trace.Kaz Kylheku2016-11-041-2/+2
| | | | | | * eval.c (error_trace): No need to indicate where an expansion was calculated; it is distracting information when the exception isn't happening at expansion time.
* No need to track origin of entire macrolet.Kaz Kylheku2016-11-041-4/+1
| | | | | | | | | | * eval.c (expand_macrolet): Do not call set_origin to establish a macro ancestry link between the output of the expansion and the original macrolet block. This is not necessary. What is useful and important that the individual expansions of the actual macrolets have their origins tracked to the respective subforms of the original macrolet form. That's already taken care of by expand_macro.
* Show location of expanded form in exp-time errors.Kaz Kylheku2016-11-041-3/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Old behavior: | 1> (sys:expand '(defstruct foo bar)) | ** defstruct: inheritance base bar does | not name a struct type | ** during expansion at | /usr/local/share/txr/stdlib/struct.tl:120 | of form (defstruct foo bar) New behavior: | 1> (sys:expand '(defstruct foo bar)) | ** defstruct: inheritance base bar does | not name a struct type | ** during expansion at expr-1:1 of form (defstruct foo | bar) | ** by macro code located at | /home/kaz/txr/share/txr/stdlib/struct.tl:120 * eval.c (error_trace): Show location of the form being expanded in the "during expansion" message, rather than, confusingly, the locaton of the code of its macro. Then, if the location of the macro is available, show that in a separate message whose wording makes it clear that the location of the expanding macro is being given.
* Support simple list arguments in getopts.Kaz Kylheku2016-11-032-10/+40
| | | | | | | | | | | | | | | | | * share/txr/stdlib/getopts.tl (defstruct sys:opt-parsed): New slot eff-type, appearing as an optional parameter in the boa constructor parameter list. (opt-desc check): Allow a type to be a cons with list in the car position. (sys:opt-parsed convert-type): Use the eff-type slot if it is set instead of the type from the descriptor. This lets us override the type for a slot, which is key to the recursive approach to how lists are handled in this same function. (opthelp): Show list type options in a visual way which suggests the use. No details are given. * txr.1: Documented list option type.
* Introducing command line option processing system.Kaz Kylheku2016-11-033-0/+725
| | | | | | | | | | | * lisplib.c (getopts_set_entries, getopts_instantiate): New functions. (lisplib_init): Register auto-loading for getopt.tl via new functions. * share/txr/stdlib/getopts.tl: New file. * txr.1: Documented new library area.
* New negated equality test functions.Kaz Kylheku2016-11-013-1/+54
| | | | | | | | | * eval.c (eval_init): Register neq, neql and nequal intrinsics. * lib.h (neq, neql, nequal): New inline functions. * txr.1: Documented neq, neql and nequal
* Circ print: fix recursion from print methods.Kaz Kylheku2016-11-014-12/+40
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Flush *stdout* upon unhandled exception.Kaz Kylheku2016-10-311-0/+1
| | | | | | | | * unwind.c (uw_unwind_to_exit_point): Prior to printing diagnostics related to an unhandled exception to std_error, flush std_output. This clarifies the output in situations when both std_error and std_output go to the same destination, and the exception occurred while producing output on std_output.
* Don't enter symbols into cycle-identifying hash.Kaz Kylheku2016-10-311-2/+7
| | | | | | | | | * lib.c (circle_print_eligible): New inline function. (obj_print_impl): Do not bother with hash lookup for interned objects that don't participate in circle notation. (populate_obj_hash): Replace open-coded test with call to circle_print_eligible.