* module/language/tree-il/peval.scm (peval):
* module/language/tree-il/primitives.scm (dynamic-wind): When you make a
gensym that just has to be compared against other gensyms, it will be
unique if the prefix doesn't end in something that can be interpreted
as a number. There's no reason to make that character something
difficult like " ". So change to use a dash in that case.
* module/ice-9/psyntax-pp.scm: Regenerate. More readable now.
* 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.
* module/language/tree-il/primitives.scm (resolve-primitives!): Don't
resolve toplevels defined in the same compilation unit to primitives,
as it could be that the module doesn't have those bindings yet.
* module/language/tree-il/primitives.scm
(*interesting-primitive-names*, *effect-free-primitives*): Recognize
vector-length as an effect-free primitive.
* module/language/tree-il/primitives.scm (*primitive-expand-table*):
Remove a hack to compensate for the lack of a good inliner, now that
we do have a good inliner.
* module/language/tree-il/primitives.scm (*primitive-accessors*): New
set of primitives: those that access mutable memory, but are otherwise
pure. Include bytevector references here.
(accessor-primitive?): New public predicate.
* module/language/tree-il/peval.scm (peval): Refactor to distinguish
constructor-primitive? from accessor-primitive?.
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/optimize.scm (alpha-rename, peval): Handle
<prompt> and <abort>. Attempt to remove the prompt if the tag is
otherwise unreferenced.
* module/language/tree-il/primitives.scm (*primitive-constructors*): Add
make-prompt-tag as a constructor.
* test-suite/tests/tree-il.test ("partial evaluation"): Add a test that
an prompt whose tag is unreferenced is removed.
* module/language/tree-il/primitives.scm (*primitive-constructors*):
Record car, cdr, vector-ref, and struct-ref as "constructors".
Comment to come later.
(*effect-free-primitives*): Update.
* test-suite/tests/tree-il.test ("partial evaluation"): Add tests.
Thanks to William R. Cook for his excellent tutorial,
<http://softlang.uni-koblenz.de/dsl11/>.
* module/language/tree-il/optimize.scm (optimize!): Call `peval' unless
the #:partial-eval? option asks otherwise.
(peval): New procedure.
* module/language/tree-il/inline.scm: Add comment.
* module/language/tree-il/primitives.scm (*primitive-constructors*): New
variable.
(*effect-free-primitives*): Use it.
(constructor-primitive?): New primitive.
* test-suite/tests/tree-il.test (assert-tree-il->glil): Extend to
support `with-partial-evaluation', `without-partial-evaluation', and
`with-options'.
(peval): New binding.
(pass-if-peval): New macro.
("lexical refs"): Run tests without partial evaluation.
("letrec"): Likewise.
("the or hack"): Likewise.
("conditional"): Likewise, for some tests.
("sequence"): Adjust to new generated code.
("partial evaluation"): New test prefix.
* 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.
* 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.
* module/language/tree-il/primitives.scm
(effect+exception-free-primitive?): New predicate, like
effect-free-primitive?, but excludes accessors that could raise
exceptions.
* module/language/tree-il/primitives.scm
(*interesting-primitive-names*, *effect-free-primitives*): Recognize
make-prompt-tag as interesting and effect-free.
* 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/ice-9/boot-9.scm (default-prompt-tag, make-prompt-tag): New
functions.
(call-with-prompt, abort-to-prompt): Rename from `prompt' and `abort',
respectively. These names are more clear, and allow `prompt' and
`abort' to have more convenient, less general bindings.
(default-throw-handler, custom-throw-handler, catch, %start-stack):
Adapt callers.
* module/ice-9/control.scm: Adapt re-export list.
(control): Remove binding, until we're sure that it is Sitaram's
control.
(abort): New binding, aborts to the nearest prompt with the default
tag.
(%): Use call-with-prompt.
* module/language/tree-il/primitives.scm (*primitive-expand-table*):
(*interesting-primitive-names*): Adapt for prompt/abort changes.
* test-suite/tests/control.test: Take advantage of the defaults for %
and abort.
* 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.
* module/language/tree-il/primitives.scm
(*interesting-primitive-names*): Add abort.
(*primitive-expand-table*): Fix so that we inline `prompt' and
`abort', and remove obsolete code dealing in `control'.
* libguile/control.h:
* libguile/control.c: Remove scm_atcontrol and scm_atprompt.
(scm_c_make_prompt): Remove handler arg, as the handler is inline.
(scm_abort): New primitive, exported to Scheme as `abort'. The
compiler will also recognize calls to `abort', but this is the base
case.
(scm_init_control): Remove scm_register_control, just have this
function, which adds `abort' to the `(guile)' module.
* libguile/eval.c (eval): Add SCM_M_PROMPT case.
* libguile/init.c (scm_i_init_guile): Change scm_register_control call
into a nice orderly scm_init_control call.
* libguile/memoize.h: (scm_sym_at_prompt, SCM_M_PROMPT):
* libguile/memoize.c (MAKMEMO_PROMPT, scm_m_at_prompt, unmemoize): Add
prompt support to the memoizer.
* libguile/vm-i-system.c (prompt): Fix to not expect a handler on the
stack.
* module/ice-9/boot-9.scm (prompt): Add definition in terms of @prompt.
* module/ice-9/control.scm: Simplify, and don't play with the compiler
here, now that prompt and abort are primitive.
* module/ice-9/eval.scm (primitive-eval): Add a prompt case.
* module/language/tree-il/primitives.scm
(*interesting-primitive-names*): Add @prompt and prompt.
* 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.
* libguile/memoize.h (scm_sym_at_dynamic_wind, SCM_M_DYNWIND)
* libguile/memoize.c (memoized_tags, MAKMEMO_DYNWIND)
(scm_m_at_dynamic_wind, unmemoize): Add dynwind as a primitive
expression type.
* libguile/dynwind.c (scm_dynamic_wind): Downgrade to a normal C
function.
* libguile/eval.c (eval):
* module/ice-9/eval.scm (primitive-eval): Add dynwind support.
* module/ice-9/r4rs.scm: More relevant docs.
(apply): Define in a more regular way.
(dynamic-wind): Add to this file, with docs, dispatching to
@dynamic-wind.
* module/language/tree-il/primitives.scm: Parse @dynamic-wind into a
tree-il dynamic-wind.
* module/language/tree-il/primitives.scm (define-primitive-expander):
Allow quoted datums. Allow all self-evaluating expressions to be
constants.
(prompt, control): Add primitive expanders to turn these into @prompt
and @control.
* module/ice-9/control.scm: New module, for delimited continuation
operators.
* module/Makefile.am: Add.
* module/language/tree-il/primitives.scm: Resolve calls to dynamic-wind
to <dynamic-wind>, thereby inlining the dynwind to VM ops, and
allowing inline allocation of the body thunk.
* 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/primitives.scm
(*interesting-primitive-names*): Recognize memv and memq as well.
* module/language/tree-il/inline.scm (inline!): Inline calls to memq and
memv where the list is a constant.
* 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.
* module/oop/goops.scm (@slot-ref, @slot-set!): Define "primitives" for
these. Probably should do something more general, though, allowing
@struct-ref.
* module/language/tree-il/primitives.scm (add-interesting-primitive!):
Error if the primitive isn't bound.
* test-suite/Makefile.am:
* test-suite/tests/brainfuck.test: Add a brainfuck test.
* module/system/base/compile.scm: Also export read-and-compile.
* module/language/tree-il/spec.scm (join): Fix the joiner in the
0-expression case.
* module/language/tree-il/primitives.scm (+): Recognize (+ x -1) as 1-.
* module/language/brainfuck/parse.scm (read-brainfuck): Return EOF if we
actually received EOF, and there were no expressions read.
* module/language/brainfuck/compile-tree-il.scm (compile-body): Fix the
compiler for the new format of "lambda" in tree-il.