summaryrefslogtreecommitdiffstats
Commit message (Collapse)AuthorAgeFilesLines
...
* compiler: lambda bug: wrong reg in defaulting.Kaz Kylheku2018-03-201-1/+1
| | | | | | | | | | * share/txr/stdlib/compiler.tl (compiler comp-lambda): To determine whether the argument is missing, we must test it for equivalence to the : symbol. What we're testing here is the wrong thing: the register which will hold the output of the default initform. That fragment would even be executed yet at this spot in the code, never mind being the wrong value to test.
* compiler: improve progn.Kaz Kylheku2018-03-201-6/+15
| | | | | | | | | | * share/txr/stdlib/compiler.tl (compiler comp-progn): If the suggested output register is a variable, progn should not use it for the discarded values of the leading forms, only for the last form. Writes to the variable space of the display are costly because in closures, the underlying vector of a given level has to be passed to gc_mutated. We use a new temp register for the discarded forms.
* compiler: bugfix: arg passing in progn dispatch.Kaz Kylheku2018-03-201-1/+1
| | | | | | * share/txr/stdlib/compiler.tl (compiler compile): Fix nonsensical fourth argument expression in comp-progn call.
* lib: new ldiff function.Kaz Kylheku2018-03-203-2/+61
| | | | | | | | | | * eval.c (eval_init): Use the old ldiff function under compatibility with 190 or lower. * lib.c (ldiff): Rewritten. (ldiff_old): New function, copy of previous version of ldiff. * lib.h (ldiff_old): Declared.
* compiler: let bugfix: wrong output register designated.Kaz Kylheku2018-03-201-1/+1
| | | | | | * share/txr/stdlib/compiler.tl (compiler comp-let): The returned fragment must specify boreg not oreg, because the output is either in oreg or bfrag.oreg.
* compiler: factor recurring conditional mov.Kaz Kylheku2018-03-201-29/+19
| | | | | | | | | | | | | Anyway, this kind of thing should really be (and will be) taken care of peephole optimization. But for now, it's nice to get somewhat better code without doing too much work. * share/txr/stdlib/compiler.tl (compiler comp-setq, compiler comp-cond, compiler cond-if, compiler cond-let, compiler comp-lambda, compiler comp-for): Replace occurrences of (if (nequal reg1 reg2) ^((mov ,reg ,reg2))) with call to maybe-mov. (maybe-mov): New function.
* compiler: handle if special formKaz Kylheku2018-03-201-0/+52
| | | | | | * share/txr/stdlib/compiler.tl (compiler compile): Handle if case via comp-if method. (compiler comp-if): New method.
* compiler: handle cond special form.Kaz Kylheku2018-03-201-0/+54
| | | | | | * share/txr/stdlib/compiler.tl (compiler compile): Handle cond case via comp-cond method. (compiler comp-cond): New method.
* vm: support deferred resolution of ftab bindings.Kaz Kylheku2018-03-191-4/+20
| | | | | | | | | | | | | | | | This allows a virtual machine's funvec to refer to functions that are not yet defined. We resolve all the ones that are defined when the virtual machine description is constructed. The others are resolved at vm execution time when accessed. * vm.c (vm_make_desc): When filling ftab with resolved function bindings, check that lookup_fun has returned nil; in that case, initialize the binding location to zero, instead of blowing up calling cdr_l(nil). (vm_ftab): New static function. Implements the null check and late resolution. (vm_gcall, vm_gapply): Acces ftab through vm_ftab instead of open-coded expression.
* compiler: dump warnings from form expansion.Kaz Kylheku2018-03-191-1/+3
| | | | | | | * share/txr/stdlib/compiler.tl (usr:compile-toplevel): Call release-deferred-warnings to dump accumulated warnings. Otherwise when we are working in the listener, the pent-up warnings get dumped in relation to the next input line.
* vm: bug: vm-desc created with incorrect display depth.Kaz Kylheku2018-03-192-3/+5
| | | | | | | | | | | | | | | | | | * share/txr/stdlib/compiler.tl (sys:env :postinit): The call to register the environment with the compiler must be outside of the unless form. Otherwise it never takes place, and so the compiler doesn't find the maximum number of environment levels, keeping the value at 2. The executing vm then accesses out of bounds memory when setting up display frames. (usr:compile-toplevel): Give the root environment the compiler. Not strictly necessary since we are constent in doing this elsewhere, so we are not relying on inheritance of the compiler from parent environment to child. * vm.c (vm_make_closure): assert added for the environment levels of the closure not exceeding the display depth given in the machine description. This was added during debugging and going off; I'm keeping it.
* vm: variadic arg closures bug 3/3.Kaz Kylheku2018-03-191-1/+1
| | | | | | | | | * share/txr/stdlib/asm.tl (op-close asm): Fix argument count check being incorrect in the variadic argument case, causing the assembler to blow up on a correct (close ...) instruction. The integer indicating the number of fixed args is one *less* than the number of arguments given to the instruction not one *more*.
* vm: variadic arg closures bug 2/3.Kaz Kylheku2018-03-191-6/+5
| | | | | | | | | | | | | | * vm.c (vm_execute_closure): Remove bogus nargs local variable, and replace its uses by fixparam which is the correct one to use for getting the list of trailing arguments using args_get_rest and for the loop which extracts the fixed arguments. The "if (variadic)" statement near the end specifically depends on the variadic destination register not having been extracted yet from the instruction space, so the argument count used in the previousl loop cannot include that register. This bug was causing that statement to extract a zero, thus register t0, which then blew up in the vm execution as an attempt to modify t0.
* vm: variadic arg closures bug 1/3.Kaz Kylheku2018-03-191-1/+1
| | | | | | | * lib.c (func_vm): fix incorrect assignment of int boolean to one-bit-wide bitfield. The argument isn't zero or one; in fact the value 256 gets passed down representing true. This gets truncated to one bit which is zero.
* compiler: bug: inappropriate clobber in block.Kaz Kylheku2018-03-191-2/+2
| | | | | | | | | | | * share/txr/stdlib/compiler.tl (compiler comp-block): Don't use bfrag.oreg as the output register of block. Firstly, bfrag.oreg might be (t 0) which is read-only. Worse, bfrag.oreg could just be a variable from which the block obtains its return value; we mustn't clobber that location with block's dynamic return value. Not only mustn't but possibly we cannot: the location could be out of scope!
* compiler: bug: nil entered into data tab by block.Kaz Kylheku2018-03-191-1/+1
| | | | | | * share/txr/stdlib/compiler.tl (compiler comp-block): If the block is anonymous, just refer to (t 0) as the name; don't intern nil via get-dreg.
* compiler: use VM's function table for global calls.Kaz Kylheku2018-03-191-4/+23
| | | | | | | | | | | | | * share/txr/stdlib/compiler.tl (compiler): New slots fidx-cntr, fidx and ftab. (compiler get-fidx, compiler get-funvec): New methods. (compiler comp-call-impl): New method. (compiler comp-call): Look up the symbol to determine whether the function lexical or global. Call comp-call-impl appropriately to generate a gcall or call. (usr:compile-toplevel): Obtain the funvec from the compiler and pass to vm-make-desc.
* asm: return original object from disassemble function.Kaz Kylheku2018-03-191-1/+2
| | | | | | | | * share/txr/stdlib/asm.tl (usr:disassemble): Return the object that was disassembled, rather than nil. This is useful in the listener: we can compile and disassemble something in one step, then have access to the compiled object via a listener variable.
* compiler: bug: lambda body uses inappropriate output reg.Kaz Kylheku2018-03-191-3/+5
| | | | | | | | | | * share/txr/stdlib/compiler.tl (compiler comp-lambda): The incoming oreg, which indicates where the surrounding context would like to put the closure, cannot be used for the output location of the lambda body. Because then when the closure is called, its return value will overwrite the location where the closure was placed. We must allocate a a new temporary register for this, and be sure to free it.
* compiler: bugfix: misused assoc in function lookup.Kaz Kylheku2018-03-191-1/+1
| | | | | * share/txr/stdlib/compiler.tl (sys:env lookup-fun): Fix swapped args in assoc call.
* vm: function table for faster calls.Kaz Kylheku2018-03-185-34/+176
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The vm now supports gcall and gapply opcodes which index numerically (using an immediate integer field in the instruction word) into a table of pre-resolved global function bindings. * share/txr/stdlib/asm.tl (op-gcall, op-gapply): New opcodes. (disassemble-c-d): Take the function vector as an argument and dump it too. (usr:disassemble): Extract function vector from VM description and pass it to disassemble-c-d. * share/txr/stdlib/compiler.tl (usr:compile-toplevel): Pass empty function symbol vector to vm-make-desc; it's now a required argument. * vm.c (struct vm_desc): New members funvec and ftab. (struct vm_ftent): New struct type. (vm_make_desc): New argument, funvec. Store funvec in the descriptor. Allocate a table of vm_ftent structures equal in number of elements to the function table, and populate it with resolved bindings. (vm_desc_funvec, vm_desc_destroy): New static functions. (vm_desc_mark): Mark the captured bindings in vd->ftab. (vm_gcall, vm_gapply): New static functions. (vm_execute): Handle GCALL and GAPPLY opcodes. (vm_desc_ops): Wire vm_desc_destroy in place of cobj_destroy_free_op. (vm_init): Add argument to vm-make-desc intrinsic. Register vm-desc-funvec intrinsic. * vm.h (vm_make_desc): Declaration updated. * vmop.h: Regenerated
* vm: free display memory when closure reclaimed.Kaz Kylheku2018-03-181-1/+8
| | | | | | * vm.c (vm_closure_destroy): New static function. (vm_closure_ops): Use vm_closure_destroy rather than generic cobj_destroy_free_op.
* compiler: change in output register protocol.Kaz Kylheku2018-03-181-108/+107
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | With this change we get better code, as well fewer situations in which tregs are manually released. There are some subtleties. Previously, a compiled fragment of code would dictate the identity of the location into which it has placed output; then the higher level compile had to work with that location. The new protocol is that the caller specifies a suggested output register to the recursive compile call. If the recursive compile requires a temporary register for the output, it uses the suggested one. If it doesn't require a temporary register, it specifies its own output (for instance a (v x y) entry in the display). The caller has to deal with the output not being in the suggested register. The binding constructs lambda and let also have to deal with the possibility that the body specifies an output which is going out of scope, rather than the suggested register, and in that case must generate a move instruction to transfer from there to the suggested register before the (end ...). * share/txr/stdlib/compiler.tl (sys:env out-of-scope): New method. (compiler compile): Restructured handling of atom forms. Function takes output register argument and passes it down to the special form compile methods. (compiler comp-atom): Bugfix: this must handle nil by returning (t 0) rather than wastefully interning nil into the data table. (quote nil) triggered this. We no longer need to allocate a temporary register in this function; we just use oreg when we need it. (compiler comp-var): Don't alloc temporary, use oreg. (compiler comp-setq): We don't have to free the temporary register from compiling the value expression. When the target is a lexical variable, we pass its location to the sub-compile, so the result is placed in the variable directly. Thus we don't have to generate an additional mov instruction any more, except if that compile wasn't able to use the suggested location. (compiler comp-block): Pass oreg to compile of block bodies. Then use whatever register that block specifies as the block output. (compiler comp-let): Binding of variables is streamlined with oreg in a manner similar to assignment in comp-setq. The body is compiled with the suggested oreg as its output. Because it may put the output in a location that is going out of scope, we have to do the scope check and insert a mov. (compiler comp-lambda): Similar changes as in comp-let. (compiler comp-progn): Just use the incoming oreg as the destination for every form. Use the actual output register of the last frag as the output register, unless there were no frags in which case the nil register is specified as the output. (compiler comp-prog1): Allocate a register for the ignored values of the second and subsequent forms. Use oreg for compiling the first form. (compiler comp-quasi): Take oreg param and pass down. (compiler comp-call): Now allocates a batch of suggested registers for each of the argument compiles, and passes each down to its corresponding argument compile. These registers are freed, and the actual output are used in generating the call. The output of the call goes into oreg; no need to allocate. (compiler comp-for): Mostly the obvious changes here. (usr:compile-toplevel): Here we need to allocate an output register for the top-level call into the compiler.
* compiler: use mac-param-bindKaz Kylheku2018-03-171-15/+15
| | | | | | | | | | | | It's better to use mac-param-bind than tree-bind because it provides diagnostics related to the form being destructured. * share/txr/stdlib/compiler.tl (compiler compile): Pass the whole form rather than (cdr form) to a number of special form handlers. (compiler comp-seq, compiler comp-block, compiler comp-let, compiler comp-lambda, compiler comp-for): Destructure arguments with mac-param-bind.
* listener: fix poor regex handling in balance check.Kaz Kylheku2018-03-171-1/+33
| | | | | | | * parser.c (is_balanced_line): Introduce the ST_RGXC state to which we switch when we encounter a regex character class. Also introduce ST_RGXE for regex subexpressions. In these states, do not recognize / as the regex terminator.
* compiler: replace invalid compound form message.Kaz Kylheku2018-03-171-1/+1
| | | | | | * share/txr/stdlib/compiler.tl (compiler compile): The message will show (car form) followed by a colon, so the wording should refer to that object rather than the entire form.
* compile-toplevel: expand with warnings.Kaz Kylheku2018-03-172-1/+2
| | | | | | | | * eval.c (eval_init): Expose raw expand function as sys:expand*, since sys:expand squelches warnings. * share/txr/stdlib/compiler.tl (usr:compile-toplevel): Use expand* instead of expand.
* compiler: compile string quasiliterals.Kaz Kylheku2018-03-171-0/+84
| | | | | | | | * share/txr/stdlib/compiler.tl (compiler compile): Add sys:quasi case, dispatching new comp-quasi method. (compiler comp-quasi): New method. (expand-quasi-mods, expand-quasi-args, expand-quasi): New functions.
* vm: handle FVM function type thorughout run-time.Kaz Kylheku2018-03-162-2/+51
| | | | | | | | | | | | | | | | * gc.c (mark_obj): Recognize FVM functions and mark their vm_desc. * lib.c (equal): Handle equality for FVM. If the environment pointers are equal, consider the functions equal. (funcall, funcall1, funcall2, funcall3, funcall4): Recognize and call FVM functions. However, there is a lack of robustness here that needs to be addressed: vm_execute_closure doesn't check whether there are too many or not enough arguments. Interpreted functions have a run-time check inside bind_args. (obj_print_impl): Don't print VM functions as #<intrinsic fun...> but rather #<vm fun>.
* quasi: factor out repeated code.Kaz Kylheku2018-03-161-19/+24
| | | | | | | | * eval.c (fmt_tostring, fmt_cat): New static functions. (do_format_field): Replace code block with call to fmt_cat. (fmt_simple, fmt_flex): Insert needed call to fmt_tostring. (subst_vars): Replace blocks of code with calls to fmt_tostring and fmt_cat.
* quasilit: expose access to field formatting.Kaz Kylheku2018-03-161-0/+35
| | | | | | | | | | | | | | | | | | | | | | | | | This is the second round of changes in perparation for compiling the string quasiliterals special form. Having split format_fields into a lower level do_format_field and format_field, we now provide two functions which allow Lisp code to call do_format_field. The sys:fmt-simple function has fixed arguments for the field width/alignment, indexing/slicing, separator and plist. Any of them can be defaulted with nil. This function will be useful when the quasiliteral specifies modifiers that are simple literals or constant expressions. The sys:fmt-flex function takes a variable number of arguments, after the object and the plist. This function has to scan through the arguments and classify them by type: a string is a separator, an integer is a width and left/right alignment and so on. The compiler will use sys:flex when format field modifiers are present whose arguments contain expressions that get evaluated. * eval.c (fmt_simple, fmt_flex): New static functions. (eval_init): sys:fmt-simple and sys:fmt-flex registered.
* compiler: closure bug: (dframe ...) without (end ...).Kaz Kylheku2018-03-161-0/+2
| | | | | | * share/txr/stdlib/compiler.tl (compiler comp-lambda): When we have specials we must generate an extra (end ...), to terminate the (dframe ...) that we inserted.
* compiler: fix wrong, undersized frame size in closure.Kaz Kylheku2018-03-161-3/+3
| | | | | | | | | | | * share/txr/stdlib/compiler.tl (compiler comp-lambda): Frame size can't be calculated from nfixed, because that doesn't account for the extra variables in optional parameters. It can't be calculated from the number of lexical variables either, because parameters that are special variables consume vXXYY frame entries without being counted as lexicals. Rather, the accurate frame size is given to us by the value of the counter in the newly created environment.
* Adding compiler.Kaz Kylheku2018-03-162-0/+425
| | | | | | | | | * lisplib.c (compiler_instantiate, compiler_set_entries): New static functions. (lisplib_init): Register auto-load for compiler via new functions. * share/txr/stdlib/compiler.tl: New file.
* asm: add copyright header.Kaz Kylheku2018-03-161-0/+26
| | | | | * share/txr/stdlib/asm.tl: block comment with copyright and BSD license added.
* quasilit: split format_field into two functions.Kaz Kylheku2018-03-161-46/+55
| | | | | | | | | | | | | | | | | | | | | | | | The objective of this work is to isolate the field-formatting logic so we can target it in the compiler. Currently, the sys:quasi special operator relies on calling subst_vars, which calls format_field. Both subst_vars and format_field perform dynamic evaluation, requiring an environment. In the compiler, this will be replaced by macro-generated logic; but we would like to obtain the use of the lower-level field formatting as a pure function. * eval.c (do_format_field): New static function. Does the field formatting previously done in format_field. Also performs the indexing on the object implied by the numeric or range modifier; but the range or index is already computed and comes in as a parameter. (format_field): Perform the modifier parsing only, requiring the dynamic evaluations via eval_fun, and then call do_format_field on the extracted data. The range indexing on the input sequence is no longer done during the parsing of the modifiers. That unfortunately changes some behaviors that are possible but are fortunately obscure and undocumented.
* vm: bugfix: wrong setup of closure param counts.Kaz Kylheku2018-03-151-1/+1
| | | | | | * lib.c (func_vm): The fixparam argument is the total number of fixed parameters, including optionals. That argument must be stored in the same-named member of the function structure.
* asm: close opcode checks no of registers.Kaz Kylheku2018-03-151-0/+2
| | | | | | * share/txr/stdlib/asm.tl (op-close asm): Check that the list of registers has the right number of registers indicated by the previous operands.
* asm/vm: add ifq and ifql instructions.Kaz Kylheku2018-03-153-17/+64
| | | | | | | | | | * share/txr/stdlib/asm.tl (op-ifq, op-ifql): New opcode types. * vm.c (vm_ifq, vm_ifql): New static functions. (vm_execute): Handle IFQ and IFQL opcodes. * vmop.h (vm_op_t): Regenerated.
* structs: spurious hiding of defmeth: fix needed.Kaz Kylheku2018-03-141-1/+1
| | | | | | | | | | * eval.c (op_defun): There is a hidden reference to the sys:defmeth function here, which should have been updated in commit 0ae617f463290ff4463db2e479604808f940cc76 that renamed the function to define-method! Caught this by incidental code inspection, browsing through special forms in the context of working on the compiler.
* eval: remove eval_initing, which does nothing.Kaz Kylheku2018-03-141-11/+0
| | | | | | | | | | | None of the statements which are conditional on eval_initing are ever executed, because no code is interpreted during eval init time; all intrisinc functions are C functions defined using reg_fun. * eval.c (eval_initing): Global variable removed. (op_defun, op_defmacro, eval_init): References to eval_initing and code conditional on it are removed.
* push can safely use alet rather than rlet.Kaz Kylheku2018-03-141-1/+1
| | | | | | | | | | | push doesn't unconditionally require a temporary location for operational correctness; a temporary is used only for evaluation order. Therefore it is safe to use alet to eliminate the temporary when (after all expansion) the item is a trivial symbolic expression. * share/txr/stdlib/place.tl (push): Use alet to bind the temp which holds the new item.
* asm: block and catch need dest op constraint.Kaz Kylheku2018-03-141-2/+2
| | | | | | | * share/txr/stdlib/asm.tl (op-block, op-catch): Some operands that are destinations need to be parsed as "d", so the assembler diagnoses invalid destinations. Otherwise we don't catch the problem until VM run time.
* asm: wrong labels-outside-of-code test.Kaz Kylheku2018-03-141-1/+1
| | | | | | * share/txr/stdlib/asm.tl (assembler asm): Allow instruction 0 to have a label L labeled by checking for the range 0 <= L < N.
* vm: bugfix: handle empty data vector.Kaz Kylheku2018-03-141-1/+2
| | | | | | * vm.c (vm_make_desc): We can't call vecref_l on an empty vector, because it has no index zero. Let's use a null location in this case.
* asm: bugfix: correct value of (v x y) operands.Kaz Kylheku2018-03-141-1/+1
| | | | | | * share/txr/stdlib/asm.tl (parse-compound-operand): Add the forgotten increment by two to the level number of the v operand, since (v 0 n) is in the third display level.
* expander bug: sequential vars with no init forms.Kaz Kylheku2018-03-131-1/+2
| | | | | | | | | | | | | | | | The test case for this is (let* (a (b a))) which raises suspicion by diagnosing an "unbound variable a" error against the (b a) var-init pair. The error goes away if we make it (let* ((a nil) (b a))), a perfectly equivalent form. The diagnostic is just a symptom; the problem is that in the case when a doesn't have an initform, the (b a) var-init pair is being incorrectly expanded in an environment that hasn't been extended with the a variable. * eval.c (expand_vars): In the sequential binding situation (let*), we must extend the environment for each variable in the no-init-form case exactly as we do in the with-init-form case.
* higher level disassemble function.Kaz Kylheku2018-03-133-4/+32
| | | | | | | | | | | | | | | | * lisplib.c (asm_set_entries): Autoload on usr:disassemble. * share/txr/stdlib/asm.tl (assembler): Drop initializer from bstr slot. Requires complex initialization for the case when the buf is supplied by the constructor caller for the sake of disassembling existing code. (assembler :postinit): Handle cases when only one of buf or bstr are set, and when both are not set, for the greatest flexibility. (disassemble-c-d, disassemble): New functions. * vm.c (vm_desc_datavec): New static function. (vm_init): Registered vm-desc-datavec intrinsic.
* asm: no package qualifiers in textual disassembly.Kaz Kylheku2018-03-131-1/+1
| | | | | | | * share/txr/stdlib/asm.tl (assembler dis-listing): Use tostringp when converting the opcode and arguments to text, so package prefixes won't be shown when the current package isn't sys.
* asm: fix nonworking setv.Kaz Kylheku2018-03-131-2/+3
| | | | | | | * share/txr/stdlib/asm.tl (parse-args): Include the type spec in the diagnostic for invalid type spec. (op-setv): Fix use of invalid type spec s, which should be rs.