* libguile/vm-i-system.c (wind):
* module/language/tree-il/compile-glil.scm (flatten-lambda-case):
Instead of making `wind' call `scm_thunk_p' on the winder and unwinder
at runtime, make it the responsibility of the compiler to emit code to
call thunk? and error, but only if the compiler cannot prove them to
be thunks.
* libguile/vm-engine.c (vm_engine): Remove a now-unused error block.
* libguile/boolean.c (scm_nil_p): New function.
* libguile/vm-i-scheme.c (nilp, not_nilp):
* libguile/vm-i-system.c (br_if_nil, br_if_not_nil): New instructions.
Renumber other ops.
* libguile/_scm.h (SCM_OBJCODE_MINOR_VERSION): Increment.
* module/language/assembly/compile-bytecode.scm (compile-bytecode): Add
support for writing `br-if-nil' and `br-if-not-nil' instructions.
* module/language/assembly/disassemble.scm (code-annotation): Add
`br-if-nil' and `br-if-not-nil' to the list of branch instructions.
* module/language/tree-il/compile-glil.scm: Add `nil?' to
`*primcall-ops*'.
(flatten): Use the new branch instructions for `nil?' conditionals.
* module/language/tree-il/primitives.scm: Add `nil?' to
`*interesting-primitive-names*', `*effect-free-primitives', and
`*effect+exception-free-primitives*'.
* module/language/tree-il/compile-glil.scm (flatten-lambda-case): Fix
miscompilation of `values' in a push context with RA.
* test-suite/tests/tree-il.test: Add low-level test for this
miscompilation.
* module/language/tree-il/compile-glil.scm (flatten-lambda-case): Clear
lexical stack slots at the end of a non-tail let, letrec, or fix.
Fixes http://debbugs.gnu.org/9900.
* test-suite/tests/gc.test ("gc"): Add test.
* module/language/tree-il.scm (<tree-il>): Add `pre' and `post' fields
to <dynwind>, so that we can inline the guard bodies in the normal
control-flow case. It also avoids duplicating code in compile-glil,
which probably hides more bugs in 2.0.
(parse-tree-il, unparse-tree-il, tree-il->scheme, tree-il-fold)
(make-tree-il-folder, post-order!, pre-order!): Update.
* module/language/tree-il/analyze.scm (analyze-lexicals): Update.
* module/language/tree-il/compile-glil.scm (flatten-lambda-case): Update
to use `pre' and `post' instead of compiling code twice.
* module/language/tree-il/debug.scm (verify-tree-il): Update.
* module/language/tree-il/peval.scm (peval): Update. Instead of doing
complicated things in <dynwind>, handle 'dynamic-wind primcalls.
* module/language/tree-il/primitives.scm (*primitive-expand-table*):
Remove 'dynamic-wind mess. Adapt '@dynamic-wind.
* test-suite/tests/tree-il.test ("partial evaluation"): Update tests.
* libguile/_scm.h (SCM_OBJCODE_MAJOR_VERSION): Bump the major version,
indicating the first incompatibility between 2.0 and 2.2.
* libguile/vm-i-scheme.c (string-length, string-ref, vector-length): New
instructions.
* module/language/tree-il/compile-glil.scm (*primcall-ops*): Add
primcall ops for the new instructions.
This was a pretty big merge involving a fair amount of porting,
especially to peval and its tests. I did not update psyntax-pp.scm,
that comes in the next commit.
Conflicts:
module/ice-9/boot-9.scm
module/ice-9/psyntax-pp.scm
module/language/ecmascript/compile-tree-il.scm
module/language/tree-il.scm
module/language/tree-il/analyze.scm
module/language/tree-il/inline.scm
test-suite/tests/tree-il.test
* module/language/tree-il/peval.scm: Move to its own file. Remove the
bits about <prompt> thunk-application bodies, as they are not
optimizations, simply expectations of the compiler. `canonicalize'
handles that now.
* module/language/tree-il/optimize.scm: Use peval from its module.
Don't call `inline!', as that's useless now.
* module/language/tree-il/canonicalize.scm: New file, implementing a
pass that `compile-tree-il' runs on the result from the optimizer.
The compiler currently expects a <let> form to have bindings, for
example, and this pass turns a <let> without bindings into its body.
* module/language/tree-il/inline.scm: Deprecate, as `peval' does
everything this function ever did.
* module/language/tree-il/compile-glil.scm: Canonicalize after
optimizing. This should allow us to skip the optimizer entirely, if
we want.
* module/Makefile.am: Update and reorder a little bit.
* module/language/tree-il/primitives.scm (+, *, cons*): In the case of
just one argument (the identity case), expand to (values x) instead of
just x. Fixes values truncation in that case.
(values): Likewise remove (values x) -> x translation, as the compiler
will do it for us, and this fixes (values (values 1 2)).
* module/language/tree-il/compile-glil.scm (flatten-lambda-case): Handle
`values' in a push context here.
* test-suite/tests/tree-il.test ("values"): Add some tests.
http://savannah.gnu.org/bugs/?33362
* module/language/tree-il/compile-glil.scm (flatten-lambda-case): Rename
from flatten, as it really just takes a particular case. Instead of
iteratively compiling lambda cases through `comp', tail-call through
flatten-lambda-case. This allows code to see which case it's being
compiled in. Take advantage of that to limit the self-tail-call
optimization to self-calls to the same case -- otherwise we might be
jumping to a label without having reserved the right number of
locals.
(flatten-lambda): Adapt the caller.
* test-suite/tests/compiler.test ("case-lambda"): Add a test.
* libguile/expand.h:
* module/language/tree-il.scm: Rename "sequence" to "seq", and instead
of taking a list of expressions, take a head and a tail.
* module/language/tree-il/analyze.scm:
* module/language/tree-il/compile-glil.scm:
* module/language/tree-il/fix-letrec.scm:
* module/language/tree-il/spec.scm:
* module/language/elisp/compile-tree-il.scm:
* module/ice-9/psyntax.scm:
* module/ice-9/psyntax-pp.scm:
* module/ice-9/eval.scm:
* libguile/memoize.h:
* libguile/memoize.c:
* libguile/expand.c:
* libguile/eval.c: Adapt to the new seq format.
* module/language/tree-il/compile-glil.scm (flatten): When compiling a
<prompt> in push context with an RA, after the body returns normally,
jump to that RA instead of to our POST label (which in that case does
not need to be emitted). Fixes a tail <prompt> in a push <fix>.
* test-suite/tests/control.test ("prompt in different contexts"): Add
more test cases.
* module/language/tree-il/compile-glil.scm (flatten-lambda): Don't emit
a self-label, because when we can't match the args for a lexical call,
we have no space to shuffle args and jump.
(flatten): Apply the self-tail-call optimization to optional args
too, but only if the procedure is fix-allocated. If we can't apply the
optimization, use the normal tail-call sequence.
* test-suite/tests/optargs.test ("lambda* inits"): Add tests.
* module/language/tree-il/compile-glil.scm (vars->bind-list, flatten):
Make internal self-checking error messages more clear, for
implementors of other languages.
* libguile/vm-i-scheme.c (symbol?, vector?): New
instructions. Renumbered the rest.
* libguile/vm-i-system.c: Renumber instructions.
* libguile/_scm.h (SCM_OBJCODE_MINOR_VERSION): Bump.
* module/ice-9/psyntax.scm (binding-type, binding-value): Define using
macros so that we inline to car and cdr opcodes. Oh, for an inliner :)
* module/language/tree-il/compile-glil.scm (*primcall-ops*)
* module/language/tree-il/primitives.scm
(*interesting-primitive-names*, *effect-free-primitives*)
(*effect+exception-free-primitives*): Add symbol? and vector?
inlines.
* module/ice-9/boot-9.scm (make-struct/no-tail): Define a version of
this function. Because during optimization we resolve make-struct to
make-struct/no-tail, we need an implemented make-struct/no-tail if we
are to be able to run scheme made from tree-il->scheme.
* module/language/tree-il/compile-glil.scm (*primcall-ops*): Remove
variable-set case, as there is no "variable-set!" primitive.
(flatten): Add a special hack for variable-set!. Ugly, I know.
* module/language/tree-il/primitives.scm (*effect-free-primitives*): Add
make-struct/no-tail.
(*effect+exception-free-primitives*): Remove make-struct, as it could
raise an exception.
(variable-set!): Remove expansion to variable-set.
* test-suite/tests/tree-il.test ("letrec"): Add some tests.
* module/language/tree-il/compile-glil.scm (flatten): Add support for
compiling letrec* in its unoptimized form.
* module/language/tree-il/fix-letrec.scm (simple-expression?):
Parameterize, so that letrec* will not treat `(car x)' as primitive
(because it could raise an exception).
(partition-vars): Lump unreferenced vars in with complex vars, when
compiling letrec*.
(fix-letrec!): No need to evaluate inits within a let for letrec*.
* module/language/tree-il.scm (<tree-il>): Rename `vars' fields of
<let>, <letrec>, <fix>, and <lambda-case> to `gensyms'. For clarity,
and to match <lexical-ref>.
* module/language/tree-il.scm:
* module/language/tree-il/analyze.scm:
* module/language/tree-il/compile-glil.scm:
* module/language/tree-il/fix-letrec.scm:
* module/language/tree-il/inline.scm: Update all callers.
* libguile/_scm.h (SCM_OBJCODE_MINOR_VERSION): Bump for make-struct
change.
* libguile/struct.c (scm_i_alloc_struct): Use scm_words instead of
scm_gc_malloc to simplify the code and inline the call to GC_MALLOC.
* module/language/tree-il/compile-glil.scm (*primcall-ops*): Compile
make-struct/no-tail to make-struct.
* module/language/tree-il/primitives.scm (define-primitive-expander):
Allow a conditional branch of #f to aboirt inlining.
(make-struct): Expand into make-struct/no-tail in the case that
tail-size is 0.
* libguile/vm-i-scheme.c (make-struct): Adapt to always assume tail-size
is 0. Inline allocation if possible. Don't decrement the SP past live
objects on the stack, which could cause GC to miss references. Use the
NULLSTACK macro.
* module/language/tree-il/compile-glil.scm (flatten): Change to use the
anonymous <glil-mv-bind> form when truncating to 0 or 1 values. In
those cases, remove the <glil-unbind> statements. As a side effect,
fixes compilation of abort in a "values" context.
Thanks to Tristan Colgate for the bug report.
* test-suite/tests/tree-il.test: Update to expect anonymous mv-bind.
* libguile/control.h:
* libguile/control.c (scm_c_make_prompt): Take an extra arg, a cookie.
Continuations will be rewindable only if the abort has the same cookie
as the prompt.
(scm_at_abort): Redefine from scm_abort, and instead of taking rest
args, take the abort values as a list directly. Also, don't allow
rewinding, because we won't support rewinding the C stack with
delimited continuations.
* libguile/eval.c (eval): Adapt to scm_c_make_prompt change.
* libguile/vm-engine.c (vm_engine): Use vp->cookie to get a unique value
corresponding to this VM invocation.
* libguile/vm-i-system.c (prompt): Pass the cookie to scm_c_make_prompt.
(abort): Take an additional tail arg.
* libguile/vm.c (vm_abort): Parse out the abort tail arg. This is for
the @abort case, or the (apply abort ...) case.
(make_vm): Initialize the cookie to 0.
* libguile/vm.h (struct scm_vm): Add cookie.
* module/ice-9/boot-9.scm (abort): Define here as a trampoline to
@abort. Needed to make sure that a call to abort dispatches to a VM
opcode, so the cookie will be the same.
* module/language/tree-il.scm (<tree-il>): Add a "tail" field to
<abort>, for the (apply abort ...) case, or (@abort tag args). Should
be #<const ()> in the normal case. Add support throughout.
* module/language/tree-il/analyze.scm (analyze-lexicals): Add abort-tail
support here too.
* module/language/tree-il/compile-glil.scm (flatten): Compile the tail
argument appropriately.
* module/language/tree-il/primitives.scm (*primitive-expand-table*): Fix
@abort and abort cases to pass the tail arg to make-abort.
* libguile/control.h:
* libguile/control.c (scm_c_abort): Add an implementation of `abort',
but it doesn't reify the continuation yet.
* libguile/vm-i-system.c (abort):
* libguile/vm.c (vm_abort): Wire up the call to `abort', avoiding
consing the args into a list.
* module/language/tree-il/compile-glil.scm (flatten): Add some compily
bits that can allow the abort to be resumed.
* module/language/tree-il.scm (<dynref>, <dynset>): New tree-il language
elements, corresponding to fluid-ref and fluid-set.
* module/language/tree-il/analyze.scm:
* module/language/tree-il/compile-glil.scm: Wire them up in the usual
manner.
* libguile/control.h:
* libguile/control.c (scm_c_make_prompt, SCM_PROMPT_PRE_UNWIND_HANDLER):
* libguile/vm-i-system.c (prompt)
* module/language/tree-il.scm (<prompt> prompt-pre-unwind-handler):
* module/language/tree-il/analyze.scm:
* module/language/tree-il/compile-glil.scm:
* module/language/tree-il/inline.scm:
* module/language/tree-il/primitives.scm: Remove the "pre-unwind"
handler from prompt; it turns out not to be necessary. Adapt all
references.
* module/language/tree-il/compile-glil.scm (flatten): Push a handler
value even in the inline-handler case, to make prompt's interface more
uniform, and also to correspond to the existing VM implementation.
* module/language/tree-il/compile-glil.scm (*primcall-ops*):
* module/language/tree-il/primitives.scm
(*interesting-primitive-names*): Actually resolve calls to
`variable-bound?' to the opcode that we have for it.
* module/language/tree-il/analyze.scm (<reference-dag>): New record
type.
(dag-reachable-nodes, dag-reachable-nodes*, unused-variable-analysis):
New variables.
(unbound-variable-analysis): Slightly simplify the `up' procedure.
* module/language/tree-il/compile-glil.scm (%warning-passes): Add
`unused-toplevel'.
* module/system/base/message.scm (%warning-types): Likewise.
* test-suite/tests/tree-il.test (%opts-w-unused-toplevel): New variable.
("warnings")["unused-toplevel"]: New test prefix.
* libguile/_scm.h (SCM_OBJCODE_MINOR_VERSION): Bump.
* libguile/programs.h (SCM_PROGRAM_FREE_VARIABLES)
(SCM_PROGRAM_FREE_VARIABLE_REF, SCM_PROGRAM_FREE_VARIABLE_SET)
(SCM_PROGRAM_NUM_FREE_VARIABLES):
* libguile/programs.c (scm_make_program, scm_program_num_free_variables)
(scm_program_free_variable_ref, scm_program_free_variable_set_x):
Allocate free variables inline with programs, instead of being in a
vect. Should improve locality, and require fewer local variables in
the VM.
* libguile/vm-engine.c (vm_engine): Remove free_vars and free_vars_count
variables.
* libguile/vm-engine.h (CACHE_PROGRAM): No need to muck with free_vars
and free_vars_count.
(CHECK_FREE_VARIABLE): Update for inline free vars.
* libguile/vm-i-system.c (FREE_VARIABLE_REF): Update for inline free
vars.
(make-closure, fix-closure): Take the closure vals as separate stack
args, and copy or fix them inline into the appropriate closure.
* module/language/objcode/spec.scm (program-free-variables): Define a
local version of this removed function.
* module/language/tree-il/compile-glil.scm (flatten): Adjust to not make
a vector when making closures.
* module/system/vm/program.scm: Export program-num-free-variables,
program-free-variable-ref, program-free-variable-set!, and remove
program-free-variables.
* test-suite/tests/tree-il.test ("lambda"): Update to not make vectors
when making closures.
* libguile/vm-i-system.c (tail-call, tail-call/nargs, tail-apply)
(tail-call/cc): Rename these back to tail-* from goto/*. We should
reserve the rename-then-goto name for when you actually do a rename
and goto, not when you shuffle the stack.
* doc/ref/vm.texi:
* module/language/glil/decompile-assembly.scm:
* module/language/tree-il/compile-glil.scm:
* test-suite/tests/tree-il.test: Adapt all callers and documentation.
* module/language/tree-il/analyze.scm (analyze-lexicals): Fix bug in
which variables bound within inits were being improperly allocated.
* module/language/tree-il/compile-glil.scm (vars->bind-list): More
detail in terrible debugging clause.
* test-suite/tests/optargs.test ("lambda* inits"): Add tests for binding
vars within inits.
* module/language/tree-il.scm (<tree-il>): Rename the "then" and "else"
clauses of <conditional> to "consequent" and "alternate". More
verbose, yes, but that way we avoid unexpected behavior with "else".
(parse-tree-il, unparse-tree-il, tree-il->scheme, tree-il-fold):
(make-tree-il-folder, post-order!, pre-order!)
* module/language/tree-il/analyze.scm (analyze-lexicals):
* module/language/tree-il/compile-glil.scm (flatten):
* module/language/tree-il/fix-letrec.scm (simple-expression?): Update
callers.
* module/language/tree-il.scm (<tree-il>): Rename the "else" field of
<lambda-case> to "alternate". Conflicts less with the "else" keyword
as used by case, cond, record-case, pmatch, etc.
(parse-tree-il, unparse-tree-il, tree-il->scheme, tree-il-fold)
(make-tree-il-folder, post-order!, pre-order!): Adapt traversal
operators for <lambda-case> change.
* module/language/tree-il/analyze.scm (analyze-lexicals)
(validate-arity):
* module/language/tree-il/compile-glil.scm (flatten):
* module/language/tree-il/inline.scm (inline!): Adapt for <lambda-case>
change.
* module/language/tree-il/compile-glil.scm (*primcall-ops*): Compile
variable-ref and variable-set instructions specially.
* module/language/tree-il/primitives.scm
(*interesting-primitive-names*): Add cases for variable-ref and
variable-set!. The latter is a little tricky, because the args are
switched for the VM op, and we can't really change that easily.