summaryrefslogtreecommitdiffstats
Commit message (Collapse)AuthorAgeFilesLines
...
* ffi: bugfix: char array shouldn't null terminate.Kaz Kylheku2019-01-151-1/+3
| | | | | | | | | | | * ffi.c (ffi_char_array_put): The char array put operation should only null terminate when the null_term flag is set; i.e. it's a zarray type. The bug here is that when a Lisp string of length > N is put into an (array N char), the C array gets null terminated, which is wrong. Only in the case when the string is exactly of length N is there no null termination. In all cases when the length >= N, we want truncation without null termination.
* ffi: remove useless loop.Kaz Kylheku2019-01-151-12/+6
| | | | | | * ffi.c (make_ffi_type_array): Remove a useless loop that was left behind when the essential part of its body was removed.
* asm: fix wrong level check in operand parsing.Kaz Kylheku2019-01-091-1/+1
| | | | | | | | * share/txr/stdlib/asm.tl (parse-compound-operand): The index of a (v <lev> <index>) operand must be compard to the maximum index constant, not to the maximum level constant. This bug will prevent compiling frames that have more than 64 variables, which is a serious limitation from 1024.
* asm: fix incorrect level check in frame opcode.Kaz Kylheku2019-01-091-2/+2
| | | | | | * share/txr/stdlib/asm.tl (op-frame): Check the level of the operand against %max-v-lev%, not %max-lev-idx%, which gives the maximum index within a level.
* asm/compiler: fix incorrect frame-related constant.Kaz Kylheku2019-01-091-1/+1
| | | | | | * share/txr/stdlib/vm-param.tl (%max-lev-idx%): The maximum index within a level is one less than the maximum level size, not two less. Use pred rather than ppred to derive it.
* asm/compiler: rename small level/index constants.Kaz Kylheku2019-01-092-3/+4
| | | | | | | | | | | | | | | | * share/txr/stdlib/vm-param.tl (%max-sm-lev-idx%): This constant is named inconsistently relative to %max-lev-idx%. It is providing the maximum level (encodable in a small operand), whereas %max-lev-idx% provides the maximum index within a level. It is hereby renamed to %max-sm-lev%. The %max-sm-lev-idx% name is re-used to denote the quantity which it suggests: the maximum index within a level (encodable in a small operand), which is 63. * share/txr/stdlib/asm.tl (small-op-p): Use the new %max-sm-lev-idx% in place of %sm-lev-size%, getting rid of the funny range starting with -1. Replace the original %max-sm-lev-idx% with its new name, %max-sm-lev%.
* New function: square.Kaz Kylheku2019-01-054-0/+75
| | | | | | | | | | | | | The square function calulates (* x x) but is faster for bignum integers by taking advantage of mp_sqr. * arith.c (square): New function. * eval.c (eval_init): Register square as intrinsic. * lib.h (square): Declared. * txr.1: Documented.
* Eliminate ALLOCA_H.Kaz Kylheku2018-12-3119-22/+22
| | | | | | | | | | | | | * configure: Instead of generating a definition of ALLOCA_H, generate the variable HAVE_ALLOCA_<name> with a value of 1, where <name> is one of stdlib, alloca or malloc. * alloca.h: New header. * args.c, eval.c, ffi.c ffi.c, ftw.c, hash.c, lib.c, match.c, parser.c, parser.y, regex.c, socket.c, stream.c, struct.c, sysif.c, syslog.c, termios.c, unwind.c, vm.c: Include "alloca.h" instead of ALLOCA_H.
* Get alloca from stdlib.h, if possible.Kaz Kylheku2018-12-311-1/+1
| | | | | | | | | | * configure: try <stdlib.h> first for alloca. This should fix a build issue which happens on the Musl library and perhaps elsewhere. The problem on Musl is that #include <stdlib.h> already includes <alloca.h>. That header contains an alloca macro which interfers with our subsequent #include ALLOCA_H directive: ALLOCA_H expands to <alloca.h> and the alloca token gets further expanded.
* Remove HAVE_ALLOCA.Kaz Kylheku2018-12-311-1/+0
| | | | | * configure: don't define HAVE_ALLOCA in config.h. It is not used anywhere. Moreover, alloca isn't optional.
* doc: formatting under lop.Kaz Kylheku2018-12-241-2/+2
| | | | | | * txr.1: Closing quote didn't come out in .codn; we must use the \(dq code in this context. Let's make the opening quote \(dq also for consistency.
* doc: grammar fixes under registeer-tentative-def.Kaz Kylheku2018-12-241-4/+2
| | | | | * txr.1: Wrong tense/person of "to expect"; spurious occurrence of foo identifier deleted.
* doc: formatting under caseql*.Kaz Kylheku2018-12-241-1/+1
| | | | * txr.1: .meti should be used to typeset code inline.
* Version 204.txr-204Kaz Kylheku2018-12-176-464/+491
| | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise. * txr.vim, tl.vim: Regenerated.
* UTF-8: fix incorrect decoding of four-byte sequences.Kaz Kylheku2018-12-171-1/+1
| | | | | | | | | utf8.c (utf8_decode): The wch_min value is set incorrectly for the four byte case due to an extra zero; it should be only 0x10000. Code points encoded to four utf8 bytes start at this value. The consequence of this error is that utf8-encoded characters in this range are treated as invalid bytes after being decoded due to failing the range test.
* defvar: bugfix: bad state caused by exception.Kaz Kylheku2018-12-141-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | The following situation can occur: (defvar v expr) ;; expr throws! What happens is that the internal hash table of global variables ends up with an entry that has a nil value, instead of the expected (v . <value>) cons cell. The hash table entry is created when the table is probed for the existence of v, but then is never populated with a binding because expr throws. The consequence then is that (boundp v) returns nil, yet subsequent (defvar v ...) expressions think that v exists, and refuse to define it. (defparm v ...) also fails; it relies on (defvar ...) which fails to define the variable, and then tries to assign to it, which throws. * eval.c (rt_defvarl): If the hash table exists, but has a nil value, treat that as an undefined variable. Thus, define the variable not only if the hash cell is newly made, but also if it already exists, with a null cdr.
* compiler: move variable down in file.Kaz Kylheku2018-12-131-2/+2
| | | | | | * share/txr/stdlib/compiler.tl (assumed-fun): This variable shouldn't be the first item in the compiler. It is moved after the definitions of structs and important constants.
* nzerop: new function.Kaz Kylheku2018-12-134-1/+48
| | | | | | | | | | * arith.c (nzerop): New function. * eval.c (eval_init): Register nzerop intrinsic. * lib.h (nzerop): Declared. * txr.1: Documented.
* Use tnil instead of if2 in arithmetic predicates.Kaz Kylheku2018-12-131-9/+9
| | | | | * arith.c (zerop, plusp, minusp): style: if2(expr, t) should be using tnil(expr).
* plusp: wrong name in error message.Kaz Kylheku2018-12-131-1/+1
| | | | * arith.c (plusp): plusp wrongly reports itself as zerop.
* configure: extend some config variable descriptions.Kaz Kylheku2018-12-121-2/+11
| | | | | | | * configure: Add some help text for variables controllinig the compiler command. Mention that CFLAGS and LDFLAGS are honored from the environment or make command line on top of any of the flags settable here.
* Turn off stack protector gcc option.Kaz Kylheku2018-12-121-1/+1
| | | | | | | * configure (opt_flags): Add -fno-stack-protector to disable this feature that is on by default in some toolchains/distros. As a result, I'm seeing an over 5% VM speedup on a loop benchmark.
* bugfix: LDFLAGS not pulled in.Kaz Kylheku2018-12-121-1/+1
| | | | | * Makefile (TXR_LDFLAGS): Fix use of wrong assignment operator which clobbers the previous assignment of $(LDFLAGS).
* Eliminate various unneeded header inclusions.Kaz Kylheku2018-12-124-7/+0
| | | | | | | | | | * hash.c: Don't include "cadr.h". * stream.c: Don't include "struct.h". * strudel.c: No <syslog.h>, ALLOCA_H, "args.h" or "utf8.h". * vm.c: No "hash.h".
* Drastically reduce inclusion of <dirent.h>.Kaz Kylheku2018-12-1125-25/+1
| | | | | | | | | | | | | | | | | | | The <dirent.h> header is included all over the place because it is needed by a single declaration in stream.h. That declaration is for a function that is only called within stream.c, so we make it internal. Now only stream.c has to include <dirent.h>. * buf.c, debug.c, eval.c, ffi.c, filter.c, gc.c, gencadr.txr, hash.c, lib.c, lisplib.c, match.c, parser.c, regex.c, socket.c, struct.c, strudel.c, sysif.c, syslog.c, termios.c, txr.c, unwind.c, vm.c: Remove #include <dirent.h>. * cadr.c: Regenerated. * stream.c (make_dir_stream): Make external function static. * stream.h (make_dir_stream): Declaration updated.
* Version 203.txr-203Kaz Kylheku2018-11-296-593/+611
| | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise. * txr.vim, tl.vim: Regenerated.
* doc: bad formatting under --noninteractiveKaz Kylheku2018-11-281-1/+3
| | | | * txr.1: Fix .code macro occurring in middle of line.
* New range testing functions.Kaz Kylheku2018-11-274-0/+76
| | | | | | | | | | | * eval.c (eval_init): Register in-range and in-range* intrinsics. * lib.c (in_range, in_range_star): New functions. * lib.h (in_range, in_range_star): Declared. * txr.1: Documented.
* case macros: bugfixes for evaluated keys.Kaz Kylheku2018-11-271-5/+5
| | | | | | | | | * eval.c: Fix incorrect treatment of cases like (caseql* ((a b) ...)). The check for evaluation must come before we do the keys = car(keys) transformation. Also, hash_keys must be updated to the evaluated keys, otherwise if the hash table optimization is used, the table will contain the original expressions as the keys, not their values.
* doc: caseql* macro expands cases in global envKaz Kylheku2018-11-271-1/+1
| | | | | | * txr.1: Use the correct term "global environment" rather than "dynamic environment" to desribe the scope in which caseq*, caseql* and casequal* expand the key forms.
* doc: avoid "empty lexical environment".Kaz Kylheku2018-11-271-4/+5
| | | | | | | | | * txr.1: Replace the term "empty lexical environment" with "global environment" in a few places. In one case, it is removed, and the surrounding wording is adjusted. The "empty lexical environment" term is poor because the situations which it describes retain visibility of the "global lexical" variables.
* case macros: stricter syntactic check.Kaz Kylheku2018-11-271-0/+3
| | | | * eval.c (me_case): Throw error if the test form is missing.
* case macros: bugfix empty case.Kaz Kylheku2018-11-271-2/+3
| | | | | | | | | | * eval.c (me_case): When there are no keys, then it is logically true that all keys are integer, and the hash table logic kicks in. The minkey and maxkey variables are supposed to be calculated as zero in that case, but the empty test is bungled since nkeys doesn't test false when it is zero. We end up with minkey and maxkey containing nil which get passed to the minus function. And so, here we fix the empty test.
* doc: clarify pretty printing.Kaz Kylheku2018-11-251-3/+34
| | | | | * txr.1: adding more details to description of the effect of pretty printing.
* print: keep colon in keyword symsKaz Kylheku2018-11-252-2/+14
| | | | | | | | * lib.c (obj_print_impl): Always include leading colon when printing keyword symbols, regardless of pretty flag. Subject to backward compatibility. * txr.1: Compat note added.
* doc: refresh documentation of make-lazy-consKaz Kylheku2018-11-251-8/+34
| | | | | | * txr.1: Documentation of make-lazy-cons revised with important clarifications and details, and removal of some overly informal language.
* Streamline logand and logior slightly.Kaz Kylheku2018-11-251-18/+4
| | | | | | | | * arith.c (logand, logior): Remove wasteful zerop tests which involve a type check. Also don't check for a == b equivalence in CHR and NUM cases; this is a rare case that just adds to the cycles and instruction count. Blindly copying and pasting this code is what led to the bug in logxor.
* logxor: fix seriously broken function.Kaz Kylheku2018-11-254-1/+53
| | | | | | | | | | | | | Reported by Guillaume le Vaillant. * arith.c (logxor): Fix broken behavior when the arguments are the same nonzero fixnum, or the same bignum object. (logxor_old): New function: verbatim copy of previous logxor. * eval.c (eval_init): Register logxor intrinsic to the broken function if compatibility is 202 or less. * txr.1: Compat note added.
* vm: some optimizations.Kaz Kylheku2018-11-221-11/+27
| | | | | | | | | | | | * vm.c (vm_getz): Manual CSE: calculate address of location, then conditionally set to zero. (vm_set_nil_error): New static function. (vm_set, vm_sm_set): Call zero-argument vm_set_nil_error instead of three_argument uw_throwf. (vm_stab_slowpath): New function. (vm_stab): Function marked inline. The slow path when the binding is not cached goes through vm_stab_slowpath which is not inlined.
* Version 202.txr-202Kaz Kylheku2018-11-226-276/+308
| | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise. * txr.vim, tl.vim: Regenerated.
* doc: clarify delimited continuation compiled semanticsKaz Kylheku2018-11-181-10/+30
| | | | | | | | | | * txr.1: Text describing the changes in behavior, under delmited continuations, of compiled code that mutates variables seemed unclear; it is revised. Also, in the section that discusses compiled versus interpreted differences under Lisp Compilation, a paragraph is added mentioning delimited continuations, referring the reader to this detailed section.
* doc: move functionpKaz Kylheku2018-11-171-14/+14
| | | | | * txr.1: functionp belongs under Functions, not Global Environment.
* doc: use bulleted list under copy.Kaz Kylheku2018-11-171-56/+29
| | | | | * txr.1: Present the type cases of the copy function using a more compact and visually appealing bulleted list.
* copy: call copy-fun for functions.Kaz Kylheku2018-11-172-0/+8
| | | | | | * lib.c (copy): Handle FUN type through copy_fun. * txr.1: Documented.
* compiler: use binary versions of common math functions.Kaz Kylheku2018-11-162-0/+28
| | | | | | | | | | | | | | | * arith.c (arith_init): Register functions in the sys package: b<, b>, b<=, b=, b+, b-, b*, b/ and neg. * share/txr/stdlib/compiler.tl (%nary-ops%, %bin-ops%, %bin-op%): New global variables. (compiler comp-fun-form): Transform two-argument calls to any of the variadic functions in %nary-ops% functions into calls to their binary counterpart. These calls are faster, since they bypass the wrapper which deals with the variable argument list. Also, we detect unary - and map it to the new sys:neg function, and reduce the one-argument cases of certain functions to noops.
* vm: provide special case call entry points.Kaz Kylheku2018-11-163-14/+112
| | | | | | | | | | | | | | | * lib.c (funcall, funcall1, funcall2, funcall3, funcall4): Use vm_funcall, vm_funcall1, vm_funcall2, vm_funcall3, and vm_funcall4, respectively instead of the general vm_execute_closure. Also, missing argument count check added in funcall. * vm.c (vm_funcall_common): New macro. (vm_funcall, vm_funcall1, vm_funcall2, vm_funcall3, vm_funcall4): New functions. * vm.h (vm_funcall, vm_funcall1, vm_funcall2, vm_funcall3, vm_funcall4): Declared.
* vm: use faster funcall functions in vm_gcall.Kaz Kylheku2018-11-161-15/+58
| | | | | * vm.c (vm_gcall): For the 0 to 4 argument cases, use funcall, funcall1, ..., funcall4 instead of generic_funcall.
* math: remove redundant type checks from NUM.Kaz Kylheku2018-11-162-118/+122
| | | | | | | | | | | | * arith.c (plus, minus, neg, abso, signum, mul, trunc, mod, floordiv, plusp, minusp, evenp, oddp, gt, lt, ge, le, numeq, expt, exptmod, isqrt, gcd, flo_int, logand, logior, logxor, comp_trunc, lognot, logtrunc, sign_extend, ash, bit, logcount, tofloat, toint, width, poly, rpoly): Use the unchecked c_n rather than c_num on quantities that are known to be of NUM and CHR type. * lib.h (c_n): New inline function.
* args: remove unused macro.Kaz Kylheku2018-11-141-4/+0
| | | | * args.h (args_alloc): Macro removed.
* compile: handle functions that have environments.Kaz Kylheku2018-11-133-2/+93
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | With this patch, the compile function can handle interpreted function objects that have captured environments. For instance, if the following expression is evaluated (let ((counter 0)) (labels ((bm () (bump)) (bump () (inc counter))) (lambda () (bm)))) then a function object emerges. We can now feed this function object to the compile function; the environment will now be handled. Of course, the above expression is already compileable; compile-toplevel handles it and so does the file compiler. This patch allows the expression to be interpreted and then the function object to be compiled, without access to the surrounding expression. The compiled function will contain a compiled version of the environment, carrying compiled versions of the captured variables and their contents. * eval.c (env_vbindings, env_fbindings, env_next): New static functions. (eval_init): Register env-vbinding, env-fbindings and env-next intrinsics. * share/txr/stdlib/compiler.tl (sys:env-to-let): New function. (usr:compile): Wrap the interpreted lambda terms with let bindings carefully reconstructed from their captured environments. * txr.1: Documented new intrinsic functions.