summaryrefslogtreecommitdiffstats
Commit message (Collapse)AuthorAgeFilesLines
...
* listener: auto compound expression mode.Kaz Kylheku2023-08-143-2/+39
| | | | | | | | | | | | | * parser.c (listener_auto_compound_s): New symbol variable. (repl): If *listener-auto-compound-p* is true, then evaluate multiple forms directly as a compound expression, without inserting progn at the head. (parse_init): Initialize symbol variable and register the *listener-auto-compound-p* special. * txr.1: Documented. * stdlib/doc-syms.tl: Updated.
* listener: change *listener-sel-inclusive-p* default.Kaz Kylheku2023-08-131-1/+1
| | | | | | * parser.c (parse_init): Set the initial value of *listener-sel-inclusive-p* to t instead of nil, since terminals tend to have block cursors by default.
* configure: fix: _TIME_BITS is tied to _FILE_OFFSET_BITSKaz Kylheku2023-08-121-29/+69
| | | | | | | | | | | | | | This problem was reported by Void Linux package maintainer adigitoleo. * configure: in glibc, _TIME_BITS and _FILE_OFFSET_BITS are not independent. You cannot make the former 64 if the latter isn't. I'm rewriting the test to check for these together, in all combinations. We succeed if we detect a combination that makes both time_t and off_t 64 bits. If we don't find such a combination then we at least enable 64 bit off_t alone or 64 bit time_t alone, if we encountered an option which does that.
* build: remove mkdir commands from build steps.Kaz Kylheku2023-08-111-3/+8
| | | | | | | | | | | | | | * Makefile (COMPILE_C_WITH_DEPS, WINDRES): Do not call mkdir. (win/%.res): Express dependency on existence of win subdirectory in the build directory. We use an order-only prerequisite, so that timestamps are not compared. We don't want to be rebuilding objects if the directory they are in has a newer timestamp, which is often the case. (OBJS): Extract the relative directory paths from $(OBJS), and make each directory the target of a rule which creates it. Then, make each target in $(OBJS) dependent (order-only) on the directory into which it will be placed, so before that object is built, the directory gets created with mkdir -p.
* build: remove cruft, simplifying dep generation.Kaz Kylheku2023-08-111-34/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | We get rid of the sed-based processing which produces .v files from .d files. The only purpose of the variable assignments in the .v files ended up being a filter expression in the ABBREVN macro. I think the idea here was to show all the direct prerequisites of the target, suppressing the ones computed by generated dependency rules. * Makefile (ABBREVN): Just use $^ instead filtering out $^ using the $(DEP_$@) computed variable that holds all the dependencies. I don't see an issue. This is only used for linking and it correctly shows the .o files. (DEPGEN): Macro removed. (COMPILE_C_WITH_DEPS): Remove call to DEPGEN, removing an ugly sed step from the compilation of each file. (NL, CM, DEP): Macros removed. (OBJS, EXTRA_OBJS): Directly write rule which makes all objects depend on config.make. (opt/lex.yy.o, opt/txr.o, opt/match.o, opt/parser.o, opt/y.tab.o, dbg/lex.yy.o, dbg/txr.o, dbg/match.o, dbg/parser.o, dbg/y.tab.o): Explicitly write direct rules for these so the parser generation is correctly hooked into the dependency graph.
* unuse-sym: fix in face of use-sym-as.Kaz Kylheku2023-08-103-0/+60
| | | | | | | | | | | | | * lib.c (unuse_sym): A used symbol may now appear in a package under a different name. So if we don't find a symbol under the symbol's name, or find a different symbol, we must try a reverse hash search before giving up. * txr.1: Add notes to use-sym-as that unuse-sym must be used to undo its effect. Add notes to unuse-sym discussing similarities and differences versus unintern. * tests/012/use-as.tl: New test cases.
* New feature: local symbol renaming.Kaz Kylheku2023-08-107-32/+203
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The new function use-sym-as can bring a foreign symbol into a package under a different name, which is not that symbol's name. This is also featured in a new defpackage clause, :use-syms-as. With this simple relaxation in the package system, we don't require package local nicknames, which is more complicated to implement and less ergonomic, because it doesn't actually vanquish the use of ugly package prefixes on clashing symbols. * eval.c (eval_init): Register use-syms-as. * lib.c (use_sym_as): New function, made out of use_sym. (use_sym): Now a wrapper for use_sym_as. * lib.h (use_sym_as): Declared. * stdlib/package.tl (defpackage): Implement :use-syms-as clause. * tests/012/use-as.tl: New file. * txr.1: Documented, * stdlib/doc-syms.tl: Updated.
* compiler/match: eliminate (subtypep (typeof x) y).Kaz Kylheku2023-08-092-2/+3
| | | | | | | | | * stdlib/compiler.tl (compiler comp-fun-form): Recognize the pattern (subtypep (typeof x) y) and rewrite it to (typep x y). * stdlib/match.tl (compile-struct-match): Don't generate the (subtype (typeof x) y) pattern, but (typeof x y).
* new: left-inserting pipeline operators.Kaz Kylheku2023-08-085-20/+83
| | | | | | | | | | | | | | | | | | | * stdlib/op.tl (opip-expand): Take arguments which specify the op and do operators to be inserted. Pass these through the recursive calls. (opip, oand): Pass op and do for the new arguments. (lopip, loand): New macros like opip and oand, but passing lop and ldo to the expander. (lflow): New macro. * autoload.c (op_set_entries): Add autoload entries for lopip, loand and lflow. * tests/012/op.tl: A few new tests. * txr.1: Documented. * stdlib/doc-syms.tl: Regenerated.
* doc: bit ore advice on unused variable diagnotics.Kaz Kylheku2023-08-081-1/+12
| | | | | * txr.1: Mention that @nil can be used in pattern matching to suppress unused variable warnings.
* close-stream: new : protocol from close method.Kaz Kylheku2023-08-074-4/+70
| | | | | | | | | | | | | * stream.c (close_stream): If the underlying method returns the colon symbol :, then keep the cached close_result as nil, so that the method can be called again, but return t to the caller to indicate success. * tests/018/close-delegate.tl: Test case added. * tests/018/close-delegate.expected: Updated. * txr.1: Documented.
* streams: a few close funtions should return t.Kaz Kylheku2023-08-072-1/+4
| | | | | | | | * socket.c (dgram_close): Return t when a descriptor is closed, returning nil only when the object is already in a closed state. * stream.c (dev_null_close, dir_close): Likewise.
* streams: close-stream only caches non-nil result.Kaz Kylheku2023-08-074-3/+28
| | | | | | | | | | | | | | | | | | | | This is motivated by trying to implement a struct delegate stream which performs reference counting in close, in order to close the real stream when the count hits zero. The caching behavior of close-stream is a problem. * stream.c (strm_base_init): Initialize close_result to nil, rather than nao. (strm_base_mark): Don't check close_result for nao. (close_stream): Suppress the call to op->close if close_result has a non-nil value, rather than a value other than nao. * tests/018/close-delegate.tl, * tests/018/close-delegate.expected: New files. * txr.1: Document that only a non-nil return is cached by close-stream.
* compiler: bug: ensure numbers externalized sanely.Kaz Kylheku2023-08-061-0/+3
| | | | | | | | | | | | * stdlib/compiler.tl (dump-to-tlo): To ensure numbers are externalized in such a way that they will be loaded back exactly, we need to set a few special variables. For integers, we want *print-base* to be 10. Numbers printed in other bases cannot be read back correctly. Octal, hex and binary could be, but they would need to be printed with the correct prefixes. For floating-point values, we want to switch to the default print format, and use flo-max-dig for the precision. That one s not not the default value; the default is flo-dig.
* build: speed up bootstrap compilation of stdlib.Kaz Kylheku2023-08-061-1/+1
| | | | | | | | | | | | | | | | | | | | | | The compilation of stdlib from source code (an initial state when no .tlo files exist obtained by "make clean" or "make clean-tlo") is very sensitive to the file order. If the compiler and optimize modules are compiled late, it slows down the build greatly. The compiler mainly executes the code in the files compiler.tl, param.tl, optimize.tl and asm.tl. These should be compiled first, and I empirically determined the best order. * Makefile (STDLIB_EARLY_PATS): Remove error.tlo. The circular dependency involving error.tl doesn't seem to be an issue any more. A while ago I addressed some circular dependencies in stdlib that prevented it from being usable uncompiled; make tests didn't pass with a source-only stdlib. We instead repurpose STDLIB_EARLY_PATS to specify the four modules that should compile first, in their desired order, at least if parallel make is not being used.
* Version 291.txr-291Kaz Kylheku2023-08-066-211/+235
| | | | | | | | | | | | * RELNOTES: Updated. * configure (txr_ver): Bumped version. * stdlib/ver.tl (lib-version): Bumped. * txr.1: Bumped version and date. * txr.vim, tl.vim: Regenerated.
* compiler: bug: constant folding load-time dregs.Kaz Kylheku2023-08-041-1/+2
| | | | | | | | | | | | | | | | The optimizer eliminates calls to pure library functions when all their arguments are D-registers. The call is made at compiled time and its value is inserted into the program as a constant (in a newly allocated D register). The bug is that we can't do this for a D register that is linked to a load-time value, because we don't know its value until run-time. * stdlib/optimize.tl (basic-blocks do-peephole-block): Add a constraint that none of the D registers can be a member of bb.lt-dregs, which holds the list of D registers that are used for load-time values.
* doc: new typo in compat notes.Kaz Kylheku2023-08-031-1/+1
| | | | * txr.1: Fix misspelled "elements" in 289 compatibility notes.
* opip: new special handling of (let ...).Kaz Kylheku2023-08-033-10/+166
| | | | | | | | | | | | | * stdlib/op.tl (sys:opip-single-let-p, sys:opip-let-p): New functions. (sys:opip-expand): Restructure from collect loop to car/cdr recursive form, because the new let operators in opip need access to the rest of the pipeline. Implement let operators. * tests/012/op.tl: New tests. * txr.1: Documented.
* bug: :vars not usable with :counter in @(repeat).Kaz Kylheku2023-08-024-2/+11
| | | | | | | | | | | | | | | | | | | | | | This is a regression due to a March 2016 commit which introduced the ability for :vars in an output-side @(repeat) block to have initial values. The bug has the effect that all arguments in @(repeat) which are conses/lists get duplicated, which messes up the property list structure. * parser.y (expand_repeat_rep_args): Do not unconditionally add reg to the output at the bottom of the loop. A few cases above in the consp(arg) case handle that themselves, and do not continue the loop, so control ends up at the bottom, adding a spurious item. By removing this list_collect, we have to introduce it to just one case which relies on it. * tests/008/repeat.txr, * tests/008/repeat.expected: New files. * y.tab.c.shipped: Updated.
* compiler: bug: disappearing basic block nojoin flag.Kaz Kylheku2023-07-311-0/+1
| | | | | | | | | | | Discovered while experimenting with new optimizations. * stdlib/optimize.tl (basic-blocks join-block): When we join the following block into the current block, we must propagate the nojoin property of the following block. The nojoin property has to do with the last instruction being xend. The joined block has that last instruction and so must be nojoin.
* compiler: bugfix: dangling rlinks after dead code eliminationKaz Kylheku2023-07-311-8/+10
| | | | | | | | | | | | | Discovered while experimenting with new optimizations. * stdlib/optimize.tl (basic-blocks :postinit): Pass t argument to new parameter of basic-blocks link-graph. (basic-blocks link-graph): New parameter indicating whether this is the first call; if false, we reset all the links. (basic-blocks elim-dead-code): This no longer has to reset the links before calling link-graph. But now calls link-graph one more time after the dead code removal so that no dead blocks appear in the graph.
* places: regression in symbol-function place.Kaz Kylheku2023-07-291-5/+5
| | | | | | | | | * stdlib/place.tl (sys:get-fun-getter-setter): The check added recently for a non-bindable sym at the top is completely bogus, and makes it impossible to use trace for methods. The function handles various kinds of function names that are not symbols. The check must be done in the fallback case, where plain symbols are handled.
* Version 290.txr-290Kaz Kylheku2023-07-297-1437/+1546
| | | | | | | | | | | | | | * RELNOTES: Updated. * configure (txr_ver): Bumped version. * stdlib/ver.tl (lib-version): Bumped. * txr.1: Bumped version and date. * txr.vim, tl.vim: Regenerated. * protsym.c: Regenerated.
* unwind: bind *print-circle* to t in error trace.Kaz Kylheku2023-07-281-0/+5
| | | | | | * eval.c (error_trace): Push a new dynamic environment and bind *print-circle* to t. More could be done here like setting object limits.
* compiler: use partition-if for basic block division.Kaz Kylheku2023-07-281-5/+5
| | | | | | | | * stdlib/optimize.tl (basic-blocks :postinit): Calculate the basic block partitions more directly using partition-if, eliminating the calculation of two sequences of indices that have to be merged and then passed to the partition function.
* symbol-function: check symbol argument.Kaz Kylheku2023-07-271-0/+2
| | | | | | | * stdlib/place.tl (sys:get-fun-setter-getter): Throw error if sym isn't a bindable symbol, so that nonsense like (set (symbol-function 3) ...) isn't allowed.
* match: bug: lexical symbol macros neglectedKaz Kylheku2023-07-273-6/+28
| | | | | | | | | | | | | | | | | | When a pattern variable match like @foo references a global symbol macro, that's treated as an existing expression to match, and not a new binding. However, local symbol macros are not treated this way; they are invisible to variable patterns. That is an unintended inconsistency. * stdlib/match.tl (var-list exists): Use lexical-binding-kind rather than lexical-var-p. This returns true for lexical symbol macros also. * tests/011/patmatch.tl: New test cases. * txr.1: Documentation revised to clarify that both global and local symbol macros are considered to be existing variable bindings by pattern matching.
* New functions and fixes in lexical introspection.Kaz Kylheku2023-07-273-37/+161
| | | | | | | | | | | | | | | | | | | | | | * evalc (macro_k): New keyword symbol variable. (lexical_binding_kind, lexical_fun_binding_kind) New functions. (lexical_var_p): Bugfix: if the symbol is a special variable, do not short-circuit to a nil answer. Special variables can be shadowed by symbol macros. The function is now defined in terms of lexical_binding_kind. (lexical_symacro_p, lexical_macro_p): New functions. (lexical_fun_p): Now defined using lexical_fun_binding_kind. (lexical_lisp1_binding): Bugfix: check for special variables; do not report special variables as :var. (eval_init): Initialize macro_k. Register new intrinsics: lexical-binding-kind, lexical-fun-binding-kind, lexical-symacro-p, lexical-macro-p. * txr.1: Documented. * stdlib/doc-syms.tl: Updated.
* tests: match: move file compiling step to end.Kaz Kylheku2023-07-261-6/+6
| | | | | | * tests/011/patmatch.tl: Move the form which compiles the entire file to the end of the file, so that all the interpreted test cases complete before we compile.
* compiler: compress symbol tables also.Kaz Kylheku2023-07-262-31/+46
| | | | | | | | | | | | | | | | | | | | | | | | When functions are optimized away due to constant folding, instead of replacing them with a nil, we now compact the table to close the gaps and renumber the references in the code. * stdlib/compiler.tl (compiler null-stab): Method removed. (compiler compact-dregs): Renamed to compact-dregs-and-syms. Now compacts the symbol table also. This is combined with D-reg compacting because it makes just two passes through the instruction: a pass to identify the used D registers and symbol indices, and then another pass to edit the instructions with the renamed D registers and renumbered symbol indices. (compiler optimize): Remove the call to the null-unused-data on the basic-blocks object; nulling out D regs and symbol table entries is no longer required. Fllow the rename of compact-dregs to compact-dregs-and-syms which is called the same way otherwise. * stdlib/optimize.tl (basic-blocks null-unused-data): No longer used method removed.
* compiler: compact D registers.Kaz Kylheku2023-07-252-16/+34
| | | | | | | | | | | | | | | | | | | | | | | | We now have some constant folding in the optimizer too, not just in the front end compiler pass. This is leaving behind dead D registers that are not referenced in the code. Let's compact the D register table to close the gap. * stdlib/compiler.tl (compiler get-dreg): In this function we no longer check that we have allocated too many D registers. We let the counter blow past %lev-size%. Because this creates the fighting chance that the compaction of D regs will reduce their number to %lev-size% or less. By doing this, we allow code to be compilable that otherwise would not be: code that allocates too many D regs which are then optimized away. (compiler compact-dregs): New function. Does all the work. (compiler optimize): Compact the D regs at optimization level 5 or higher. (compile-toplevel): Check for an overflowing D reg count here, after optimization. * stdlib/optimize.tl (basic-blocks null-unused-data): Here, we no longer have to do anything with the D registers.
* compiler: code formatting.Kaz Kylheku2023-07-252-4/+4
| | | | | | | | * stdlib/compiler.tl (compiler get-dreg): Fix indentation proble. * stdlib/optimize.tl (basic-block fill-treg-compacting-map): Likewise.
* hash: out of bound array access in hash-iter-peek.Kaz Kylheku2023-07-251-2/+2
| | | | | | | * hash.c (hash_iter_peek): The loop here must be a top-of-test while loop, not a bottom-test do loop. In the chained hashing implementation, this was a do loop, but it also had a test with a break for the index.
* rel-path: treat empty paths as relative.Kaz Kylheku2023-07-252-5/+8
| | | | | | | | | | | | | * stdlib/path-test.tl (path-volume): Don't return :abs for a path whose empty first component isn't followed by any more items. Otherwise we return :abs for a path formed by splitting the empty string, and then calls like (rel-path "" "a") complain about a mixture of absolute and relative. With this change, empty paths given to rel-path behave as if they were ".". * tests/018/rel-path.tl: New test cases.
* del/replace with index-list: fix semantics.Kaz Kylheku2023-07-185-22/+257
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit does two things. The replace function, implemented under the hood by four specializations: replace-list, replace-vec, replace-str and replace-buf, will handle the index-list case a little differently. This is needed to fix the ability of the del macro work on place designated by an index list, such as: (del [sequence '(1 3 5 6)] which now deletes elements 1, 3, 5 and 6 from the sequence, and returns a sequence of those items. The underlying implementation uses replace with an index-list, which is now capable of deleting items. Previously, replace would stop processing the index list when the replacement-sequence corresponding to the index list ran out of items. Now, when the replacement-sequence runs out of items, the remaining index-list sequence elements specify items to be deleted. For instance if str holds "abcdefg" then: (set [str '(1 3 5)] "xy") will change str to "axcyeg". Elements 1 and 3 are replaced by x and y, respectively. Element 5, the letter f, is deleted, because the replacement "xy" has no element corresponding to 5. * lib.c (replace_list, replace_str, replace_vec): Implement new deleteion semantics for the case when the replacement sequence runs out of items. * buf.c (replace_buf): Likewise. * tests/010/seq.txr: Some new test cases here for deletion. * tests/010/seq.expected: Updated. * txr.1: Documented new semantics of replace, including a new restriction that if elements are being deleted, the indices should be monotonically increasing regardless of the type of the sequence (not only list). A value of 289 for the -C option documented, which restores the previous behavior of replace (breaking deletion by index-list, unfortunately: you don't always get to simulate an old version of TXR while using new features.)
* doc: fix recent typos.Kaz Kylheku2023-07-181-2/+2
| | | | | | * txr.1: fix misspelling of Arithmetic and algorithm introduced by recent updates: new math functions, and documentation of CRC-32 parameters.
* compiler: constant fold gapply like gcall.Kaz Kylheku2023-07-171-3/+6
| | | | | | | * stdlib/optimize.tl (basic-blocks do-peephole-block): Extend constant-folding case to recognize gapply as well as gcall. We just have to take care in how we apply apply arguments to the actual function to get the value.
* compiler: new apply-to-gapply optimizationKaz Kylheku2023-07-171-0/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Let's consider the DIM expression [a . b c]. Without this change we get: syms: 0: a 1: b 2: c code: 0: 98020000 getf t2 0 1: 98030001 getf t3 1 2: 98040002 getf t4 2 3: 1C020002 apply t2 t2 t3 t4 4: 00030002 5: 00000004 6: 10000002 end t2 With this change: syms: 0: a 1: b 2: c code: 0: 98030001 getf t3 1 1: 98040002 getf t4 2 2: 24020002 gapply t2 0 t3 t4 3: 00030000 4: 00000004 5: 10000002 end t2 There are 17 hits for this optimization in optimize.tl alone! * stdlib/optimize.tl (basic-blocks do-peephole-block): New pattern here. We recognize an instruction sequence which begins with a (getf treg idx) and ends in an (apply dest treg ...), without any instructions in between accessing or redefining treg. Additionally, the treg value must not be used after the apply, unless the apply redefines it. In that case, we rewrite this pattern to eliminate that initial getf instruction, and substitute (gapply dest idsx ..) for the apply.
* Do not unnecessarily invalidate vm binding cache.Kaz Kylheku2023-07-171-7/+18
| | | | | | * eval.c (op_defsymacro, rt_defsymacro, makunbound, fmakunbound): Don't call vm_invalidate_binding if there is no binding for the symbol.
* printer: print (sys:vector-list ()) as #() not #nil.Kaz Kylheku2023-07-171-1/+4
| | | | | * lib.c (obj_print_impl): Check for this case and handle. The #nil syntax is not readable.
* bug: compiled code keeps seeing var clobbered by symacro.Kaz Kylheku2023-07-172-0/+6
| | | | | | | | * eval.c (op_defsymacro, rt_defsymacro): We must call vm_invalidate_binding so the VM forgets a cached binding for this variable. * tests/019/redef.tl: Test added.
* Bug exposed due to to environment changes.Kaz Kylheku2023-07-172-1/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | There was a bug in rt_defun in that it was not calling vm_invalidate_binding. This mean that compiled functions were not picking up redefinitions. This bug is fixed now because rt_defun now calls sethash on the top_fb directly, which modifies the existing binding cell; it is not allocating a new cell. We put in new test cases to confirm the proper redefinition behaviors. The proper redefinition behavior exposes an issue in pattern matching. * tests/019/redef.tl: New file. * stdlib/match.tl (transform-quote): This function's compiled image, when deposited into a .tlo file, becomes incorrect because (sys:hash-lit) turns into #H() syntax, which reads back as something else. In other words (sys:hash-lit) deosn't have print-read consistency and so doesn't externalize. To fix this right we would need a print mode which ensures machine readability rather than human readability, like in Common Lisp. For now, we just break up the pattern so that it's not a literal match. This bug was hidden due to theredefinition issue. When match.tl is being compiled, it defines non-triv-pat-p twice. Due to redefinitions not kicking in properly, the first definition of non-triv-pat-p remains in effect for some functions. When transform-qquote is being expanded, the (sys:hash-lit) pattern is treated as non-trivial, even though it is is trivial, and so it is turned into pattern matching code. The code doesn't contain a (sys:hash-lit) literal and so the issue doesn't occur.
* Simplify top-level macro environments also.Kaz Kylheku2023-07-172-23/+16
| | | | | | | | | | | | Like was done with the function and variable top-level environments, we simplify the macro ones. * eval.c (func_get_name, lookup_mac, lookup_symac, lookup_symac_lisp1, op_defsymacro, rt_defsymacro, rt_defmacro, op_defmacro, reg_mac, reg_symacro): Adjust to simpler representation where the hash cell itself is the binding cell, rather than holding a binding cell in its cdr.
* Simplify top-level variable and function environments.Kaz Kylheku2023-07-164-27/+23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Since their inception, the top_fb and top_fb hashes associated symbols with bindings cells, causing an extra cons cell to be allocated for each entry. I don't remember why this is. It might have been that way so that gethash(top_fb, sym) would return a cell when the variable exists, or else nil. This was before we had functions like gethash_e and inhash that return the hash cell itself. A hash cell is also a cons and can serve as a binding just fine by itself.Let's make it so. For now, the macro and symbol macro environments stay the way they are; I will likely convert them also. * eval.c (env_fbind, env_vbind, lookup_global_var, lookup_sym_lisp1, lookup_fun, func_get_name, rt_defv, rt_defun, set_symbol_value, reg_fun, reg_varl): Update all these functions so they treat the hash cell from top_vb or top_fb as the binding cell, rather than putting or expecting the cdr of that cell (i.e the hash value) to be a binding cell. * hash.[ch] (gethash_d): New function. Jus gethash_e without the pesky self argument, that would only be needed for error reporting if we pass an object that isn't a hash. * stdlib/place.tl (sys:get-fun-getter-setter, sys:get-vb): These two functions must be adjusted since they refer to the top-fb and top-vb variables. sys:get-vb isn't used anywhere; it continues to exist in order to provide run-time support to files that were compiled with an buggy version of the symbol-value place.
* fix self name of var defining run-time support function.Kaz Kylheku2023-07-161-1/+1
| | | | * eval.c (rt_defv): Report as sys:rt-defv, not sys:defv.
* compiler: recognize T0 register (nil) as constant.Kaz Kylheku2023-07-151-2/+4
| | | | | | * stdlib/optimize.tl (basic-blocks do-peephole-block): The constant folding case should fire even if some of the arguments of the call aren't D registers but T0.
* compiler: move material into constfun.tlKaz Kylheku2023-07-153-30/+32
| | | | | | | | | | | | | * stdlib/compiler.tl (%effect-free-funs%, %effect-free%, %functional-funs%, %functional%): Move variables into stdlib/constfun.tl * stdlib/constfun.tl %effect-free-funs%, %effect-free%, %functional-funs%, %functional%): Moved here. * stdlib/optimize.tl: Use load-for to express dependency on constfun module; don't depend on the compiler having loaded it.
* compiler: constant folding in optimizer.Kaz Kylheku2023-07-153-20/+58
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The compiler handles trivial constant folding over the source code, as a source to source transformation. However, there are more opportunities for constant folding after data flow optimizations of the VM code. Early constant folding will not fold, for instance, (let ((a 2) (b 3)) (* a b)) but we can reduce this to an end instruction that returns the value of a D register that holds 6. Data flow optimizations will propagate the D registers for 2 and 3 into the gcall instruction. We can then recognize that we have a gcall with nothing but D register operands, calling a constant-foldable function. We can allocate a new D register to hold the result of that calculation and just move that D register's value into the target register of the original gcall. * stdlib/compiler.tl (compiler get-dreg): When allocating a new D reg, we must invalidate the datavec slot which is calculated from the data hash. This didn't matter before, because until now, get-datavec was called after compilation, at which point no new D regs will exist. That is changing; the optimizer can allocate D regs. (compiler null-dregs, compiler null-stab): New methods. (compiler optimize): Pass self to constructor for basic-blocks. basic-blocks now references back to the compiler. At optimization level 5 or higher, constant folding can now happen, so we call the new method in the optimizer to null the unused data. This overwrites unused D registers and unused parts of the symbol vector with nil. * stdlib/optimize (basic-blocks): Boa constructor now takes a new leftmost param, the compiler. (basic-blocks do-peephole-block): New optimization case: gcall instruction invoking const-foldable function, with all arguments being dregs. (basic-blocks null-unused-data): New method.
* Math library: add numerous C99 functions.Kaz Kylheku2023-07-155-115/+822
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * configure: Detect all the new functions, with separate tests for the unary and binary ones. * arith.c (cbrt_s, erf_s, erfc_s, exp10_s, exp2_s, expm1_s, gamma_s, j0_s, j1_s, lgamma_s, log1p_s, logb_s, nearbyint_s, rint_s, significand_s, tgamma_s, y0_s, y1_s, copysign_s, drem_s, fdim_s, fmax_s, fmin_s, hypot_s, jn_s, ldexp_s, nextafter_s, remainder_s, scalb_s, scalbln_s, yn_s, r_copysign_s, r_drem_s, r_fdim_s, r_fmax_s, r_fmin_s, hypot_s, r_jn_s, r_ldexp_s, r_nextafter_s, r_remainder_s, r_scalb_s, scalbln_s, r_yn_s): New symbol variables. (not_available): New static function. (cbrt_wrap, erf_wrap, erfc_wrap, exp10_wrap, exp2_wrap, expm1_wrap, gamma_wrap, j0_wrap, j1_wrap, lgamma_wrap, log1p_wrap, logb_wrap, nearbyint_wrap, rint_wrap, significand_wrap, tgamma_wrap, y0_wrap, y1_wrap, copysign_wrap, drem_wrap, fdim_wrap, fmax_wrap, fmin_wrap, hypot_wrap, jn_wrap, ldexp_wrap, nextafter_wrap, remainder_wrap, scalb_wrap, scalbln_wrap, yn_wrap): New static functions. (arith_set_entries, arith_instantiate): New static functions. (arith_init): Initialize symbols and instantiate functions via autoload mechanism. In a program that doesn't use the functions, we suffer only the overhead of interning the symbols. * lib.h (UNUSED): New macro for GCC unused attribute. * txr.1: Documented. * stdlib/doc-syms.tl: Updated.