* 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.
Turns out this was not a very useful idea, and semantically tricky to
boot.
This reverts commit 24bf130fd1, and makes
the following additional changes:
* module/ice-9/optargs.scm (parse-lambda-case, let-optional)
(let-optional*, let-keywords, let-keywords*):
* module/language/tree-il.scm: (<lambda-case>, 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 (compile-glil):
* module/language/tree-il/inline.scm (inline!): Remove all traces of
#:predicate from tree-il.
* module/ice-9/psyntax.scm (build-simple-lambda, build-lambda-case)
(chi-lambda-case): Adapt to tree-il change.
* module/ice-9/psyntax-pp.scm: Regenerated.
* module/language/brainfuck/compile-tree-il.scm (compile-body):
* module/language/ecmascript/compile-tree-il.scm (comp, comp-body):
* test-suite/tests/tree-il.test: Adapt to tree-il change.
* doc/ref/api-procedures.texi (Case-lambda): Remove mention of
#:predicate.
* module/language/tree-il.scm (<lambda-case>): Add "inits" field, so we
don't have to parse it out of opt and kw. Adapt the traversal
procedures.
* module/language/tree-il/analyze.scm (analyze-lexicals): Analyze
lexicals in the <lambda-case> init expressions as well. Fix keyword
allocation.
* module/language/tree-il/compile-glil.scm (compile-glil): Adapt to
make-lambda-case change.
(flatten): Adapt to "inits" slot, actually init uninitialized args,
and fix bugs related to keyword arguments.
* module/language/tree-il/inline.scm (inline!): Adapt a little bit --
but with no effect.
* module/language/glil/compile-assembly.scm (glil->assembly): Flesh out
<glil-kw-prelude> compilation some more. Add a "bound?" op for
<glil-lexical>, which will push #t if the local is bound.
* module/ice-9/psyntax.scm (build-simple-lambda, build-lambda-case):
Update for new signature of make-lambda-case.
* module/ice-9/psyntax-pp.scm: Regenerated.
* module/language/brainfuck/compile-tree-il.scm (compile-body):
* module/language/ecmascript/compile-tree-il.scm (comp):
* test-suite/tests/tree-il.test ("lambda"): Update for new lambda-case
syntax.
* libguile/_scm.h (SCM_OBJCODE_MINOR_VERSION): Bump.
* libguile/vm-i-system.c (br-if-nargs-ne, br-if-args-lt)
(br-if-nargs-gt): New instructions, for use by different lambda cases.
(bind-optionals, bind-optionals/shuffle, bind-kwargs): New
instructions, for binding optional and keyword arguments. Renumber
other ops.
* module/language/ecmascript/compile-tree-il.scm (comp, comp-body):
Update for new tree-il. Use the new optional argument mechanism
instead of emulating it with rest arguments.
* module/language/glil/compile-assembly.scm (glil->assembly): Tweaks for
optional and keyword argument compilation.
* module/language/tree-il.scm (parse-tree-il, unparse-tree-il): Make the
else case optional, in the s-expression serialization of tree-il.
* module/language/tree-il/compile-glil.scm (flatten): Handle all of the
lambda-case capabilities.
* module/language/tree-il.scm (<lambda>, <lambda-case>): Split lambda
into the lambda itself, denoting the procedure, and lambda-case,
denoting a particular arity case. Lambda-case is fairly featureful,
and has not yet been fully tested.
(<let-values>): Use a <lambda-case> as the binding expression. Seems
to suit the purpose well.
Adapt parsers, unparsers, traversal operators, etc. Sometimes in this
first version we assume there are no optional args, rest args, or a
predicate.
* module/language/tree-il/analyze.scm (analyze-lexicals): Adapt for the
new case-lambda regime. Fairly well commented. It actually simplifies
things.
(report-unused-variables): Update for new tree-il.
* module/language/tree-il/compile-glil.scm: Adapt for the new tree-il.
There are some first stabs here at proper case-lambda compilation, but
they are untested as of yet.
* module/language/tree-il/inline.scm (inline!): Rework so we can
recurse on a single node; though these transformations are strictly
reductive, so they should complete in bounded time. Simplify
accordingly, and adapt to case-lambda. Oh, and we handle lambda->let
in not just the nullary case.
* module/ice-9/psyntax.scm (build-simple-lambda, build-case-lambda)
(build-lambda-case): New constructors. The idea is that after syntax
expansion, we shouldn't have to deal with improper lists any more.
Build-simple-lambda is a shortcut for the common case. The others are
not fully exercised yet. Adapt callers.
(syntax): Add some debugging in the lambda case. I don't fully
understand this, but in practice we don't seem to see rest args here.
(lambda): Inline chi-lambda-clause, and adapt for build-simple-lambda.
* module/ice-9/psyntax-pp.scm: Regenerated.
* test-suite/tests/tree-il.test: Update tests for new tree-il lambda
format, and to expect post-prelude labels for all glil programs.
* module/Makefile.am (SOURCES): Reorganize so GHIL is compiled last,
along with ecmascript.
* module/language/scheme/spec.scm: Remove references to GHIL, as it's
bitrotten and obsolete..
* module/language/tree-il.scm (make-tree-il-folder): Rework so that we
only have down and up procs, and call down and up on each element.
* module/language/tree-il/analyze.scm (analyze-lexicals): Fix a thinko
handling let-values.
* module/language/tree-il/fix-letrec.scm: Actually implement fixing
letrec. The resulting code will perform better, but violations of the
letrec restriction are not detected. This behavior is allowed by the
spec, but it is undesirable. Perhaps that will be fixed later.
* module/language/tree-il/inline.scm (inline!): Fix a case in which
((lambda args foo)) would be erroneously inlined to foo. Remove empty
let, letrec, and fix statements.
* module/language/tree-il/primitives.scm (effect-free-primitive?): New
public predicate.
* module/language/tree-il.scm (tree-il-fold): Fix for let-values case.
(make-tree-il-folder): New public macro, makes a multi-valued folder
specific to the number of seeds that the user wants.
* module/language/tree-il/optimize.scm (optimize!): Reverse the order of
inline! and fix-letrec!, as the latter might expose opportunities for
the former.
* module/srfi/srfi-11.scm (let-values): Reimplement in terms of
syntax-case, so that its expressions may reference hygienically bound
variables. See the NEWS for the rationale.
(let*-values): An empty let*-values still introduces a local `let'
binding contour.
* module/system/base/syntax.scm (record-case): Yukkkk. Reimplement in
terms of syntax-case. Ug-ly, but see the NEWS again: "Lexical bindings
introduced by hygienic macros may not be referenced by nonhygienic
macros."
* libguile/vm-i-system.c (fix-closure): New instruction, for wiring
together fixpoint procedures.
* module/Makefile.am (TREE_IL_LANG_SOURCES): Add fix-letrec.scm.
* module/language/glil/compile-assembly.scm (glil->assembly): Reindent
the <glil-lexical> case, and handle 'fix for locally-bound vars.
* module/language/tree-il.scm (<fix>): Add the <fix> tree-il type and
accessors, for fixed-point bindings. This IL construct is taken from
the Waddell paper.
(parse-tree-il, unparse-tree-il, tree-il->scheme, tree-il-fold)
(pre-order!, post-order!): Update for <fix>.
* module/language/tree-il/analyze.scm (analyze-lexicals): Update for
<fix>. The difference here is that the bindings may not be assigned,
and are not marked as such. They are not boxed.
(report-unused-variables): Update for <fix>.
* module/language/tree-il/compile-glil.scm (flatten): Compile <fix> to
GLIL.
* module/language/tree-il/fix-letrec.scm: A stub implementation of
fixing letrec -- will flesh out in a separate commit.
* module/language/tree-il/inline.scm: Fix license, it was mistakenly
added with LGPL v2.1+.
* module/language/tree-il/optimize.scm (optimize!): Run the fix-letrec!
pass.
* module/Makefile.am (BRAINFUCK_LANG_SOURCES): Compile at the end. Add
compile-tree-il.scm.
* module/language/brainfuck/compile-tree-il.scm: New compiler, compiles
to tree-il instead of scheme. I thought it would be more illustrative,
though there are some uncommented bits.
* module/language/brainfuck/parse.scm: Modify not to put a header on the
scheme representation. After all, we don't put <scheme> before scheme
code, do we? :)
* module/language/brainfuck/spec.scm: Add tree-il compiler.
* module/language/tree-il.scm: Understand (set! (lexical foo) ...).
* module/system/base/language.scm: Update license. Actually, updates
licenses on all these.
* module/language/tree-il.scm: Rename let-exp and letrec-exp to let-body
and letrec-body. Add <let-values>, a one-expression let-values that
should avoid the needless creation of two closures in many common
multiple-value cases. We'll need to add an optimization pass to the
compiler to produce this form, though, as well as rewriting lambdas
into lets, etc.
I added this form instead of adding more special cases to the
call-with-values compile code because it's a useful intermediate form
-- it will allow the optimizer to perform constant folding across more
code.
* module/language/tree-il.scm (parse-tree-il, unparse-tree-il)
(tree-il->scheme, post-order!, pre-order!): Adapt to let/letrec body
renaming, and let-values.
* module/language/tree-il/analyze.scm (analyze-lexicals): Adapt for
renaming, and add cases for let-values.
* module/language/tree-il/compile-glil.scm (flatten): Add a new context,
`vals', used by let-values code for the values producer. Code that
produces multiple values can then jump to the let-values MV return
address directly, instead of trampolining into a procedure. Add code to
compile let-values.
* doc/ref/api-procedures.texi (Compiled Procedures): Fix for API changes.
* doc/ref/compiler.texi (Compiling to the Virtual Machine): Replace GHIL
docs with Tree-IL docs. Update the bits about the Scheme compiler to
talk about Tree-IL and the expander instead of GHIL. Remove
<glil-argument>. Add placeholder sections for assembly and bytecode.
* doc/ref/vm.texi: Update examples with what currently happens. Reword
some things. Fix a couple errors.
* libguile/vm-i-system.c (externals): Remove this instruction, it's not
used.
* module/ice-9/documentation.scm (object-documentation): If the object is
a macro, try to return documentation on the macro transformer.
* module/language/assembly/disassemble.scm (disassemble-load-program):
Fix problem in which we skipped the first element of the object vector,
because of changes to procedure layouts a few months ago.
* module/language/scheme/spec.scm (read-file): Remove read-file
definition.
* module/language/tree-il.scm: Reorder exports. Remove <lexical>, it was
a compat shim to something that was never released. Fix `location'.
* module/language/tree-il/primitives.scm (/): Fix expander for more than
two args to /.
* module/system/base/compile.scm (read-file-in): Remove unused
definition.
* module/system/base/language.scm (system): Remove language-read-file.
* module/language/ecmascript/spec.scm (ecmascript): Remove read-file
definition.
* module/language/tree-il.scm (tree-il->scheme):
* module/ice-9/psyntax.scm (build-conditional): Attempt to not generate
(if #f #f) as the second arm of an if, but it doesn't seem to be
successful.
* module/ice-9/psyntax-pp.scm (syntax-rules): Regenerate.
* test-suite/tests/syntax.test (exception:unexpected-syntax): Change
capitalization.
("unquote-splicing"): Update test.
("begin"): Add in second arms on these ifs, to avoid the strange though
harmless expansion of `if'.
(matches?): New helper macro.
("lambda"): Match on lexically bound symbols, as they will be
alpha-renamed.
* module/language/tree-il.scm (parse-tree-il): Fix a number of bugs.
(unparse-tree-il): Apply takes rest args now.
* module/language/tree-il/analyze.scm (analyze-lexicals)
(analyze-lexicals): Heap vars shouldn't increment the number of locals.
* module/language/tree-il/optimize.scm (resolve-primitives!): Don't
resolve public refs to primitives, not at the moment anyway.
* test-suite/Makefile.am (SCM_TESTS): Add tree-il test.
* test-suite/lib.scm (pass-if, expect-fail, pass-if-exception)
(expect-fail-exception): Rewrite as syntax-rules macros. In a very
amusing turn of events, it turns out that bindings introduced by
hygienic macros are not visible inside expansions produced by
defmacros. This seems to be expected, so go ahead and work around the
problem.
* test-suite/tests/srfi-31.test ("rec special form"): Expand in eval.
* test-suite/tests/syntax.test ("begin"): Do some more expanding in eval,
though all is not yet well.
* test-suite/tests/tree-il.test: New test suite, for tree-il->glil
compilation.
* module/ice-9/psyntax.scm (build-lambda, build-let, build-named-let)
(build-letrec): Actually pass along the original ids to tree-il
constructors.
* module/ice-9/psyntax-pp.scm: Regenerated.
* module/language/tree-il.scm: Add fields in <lambda>, <let>, and
<letrec> for the original variable names.
* module/language/tree-il/compile-glil.scm (compile-glil): Adapt for new
make-lambda arg.
* module/language/tree-il/analyze.scm: Break analyzer out into its own
file.
* module/language/tree-il/compile-glil.scm: Port the GHIL->GLIL compiler
over to work on tree-il. Works, but still misses a number of important
optimizations.
* module/language/tree-il.scm: Add <void>. Not used quite yet.
* module/language/glil.scm: Remove <glil-argument>, as it is the same as
<glil-local> (minus an offset).
* module/language/glil/compile-assembly.scm:
* module/language/glil/decompile-assembly.scm:
* module/language/ghil/compile-glil.scm: Adapt for <glil-argument>
* removal.
* module/Makefile.am (TREE_IL_LANG_SOURCES): Reorder, and add
analyze.scm.
* module/Makefile.am: Add inline.scm.
* module/language/tree-il.scm (pre-order!, post-order!): pre-order! is
new. post-order! existed but was not public. They do destructive tree
traversals of tree-il, and need more documentation. Also, add
predicates to tree-il's export list.
* module/language/tree-il/inline.scm: New file, which expands primitives
into more primitive primitives. In the future perhaps it will not be
necessary, as the general inlining infrastructure will handle these
cases, but for now it's useful.
* module/language/tree-il/optimize.scm: Move post-order! out to better
pastures.
* module/language/tree-il/optimize.scm: New module, for optimizations.
Currently all we have is resolving some toplevel refs to primitive
refs.
* module/Makefile.am: Add new module.
* module/language/tree-il.scm: Fix exports for accessors for `src'.
* module/language/tree-il/compile-glil.scm: Tweaks, things still aren't
working yet.
* module/Makefile.am: Add tree-il sources.
* module/ice-9/compile-psyntax.scm: Adjust for sc-expand producing
tree-il in compile mode.
* module/ice-9/psyntax.scm: Switch from expand-support to tree-il for
generating output in compile mode. Completely generate tree-il -- the
output wasn't Scheme before, but now it's completely not Scheme.
* module/ice-9/psyntax-pp.scm: Regenerated.
* module/language/scheme/compile-ghil.scm: Strip structures using
tree-il, not expand-support.
* module/language/tree-il.scm:
* module/language/tree-il/spec.scm
* module/language/tree-il/compile-glil.scm: New language. It will compile
to GLIL, though it doesn't yet.