* module/language/tree-il.scm (<prompt>): Change to have the body and
handler be lambdas, and add an "escape-only?" field. This will make
generic prompts work better in CPS or ANF with the RTL VM, as it
doesn't make sense in that context to capture only part of a frame.
Escape-only prompts can still be fully inlined.
(parse-tree-il, unparse-tree-il): Add escape-only? to the
serialization.
(make-tree-il-folder, pre-post-order): Deal with escape-only?.
* module/language/tree-il/analyze.scm (analyze-lexicals): Handle
escape-only?, and the new expectations for the body and handler.
* module/language/tree-il/canonicalize.scm (canonicalize): Ensure that
the body of an escape-only continuation is a thunk, and that the
handler is always a lambda.
* module/language/tree-il/debug.scm (verify-tree-il): Assert that
escape-only? is a boolean.
* module/language/tree-il/cse.scm (cse):
* module/language/tree-il/effects.scm (make-effects-analyzer):
* module/language/tree-il/peval.scm (peval):
* module/language/tree-il/primitives.scm (*primitive-expand-table*):
* test-suite/tests/peval.test ("partial evaluation"):
* module/language/tree-il/compile-glil.scm (flatten-lambda-case): Adapt
to <prompt> change.
* libguile/vm-i-system.c (push-fluid, pop-fluid):
* doc/ref/vm.texi (Dynamic Environment Instructions): Rename wind-fluids
to push-fluid, and unwind-fluids to pop-fluid. They now only work on
one fluid binding at a time.
* module/ice-9/boot-9.scm (with-fluid*): Implement in Scheme in terms of
primcalls to push-fluid and pop-fluid.
(custom-throw-handler, catch, with-throw-handler): Use with-fluid*
instead of with-fluids, as with-fluids is no longer available before
psyntax is loaded.
(with-fluids): Define in Scheme in terms of with-fluid*.
* libguile/fluids.c (scm_with_fluid): Rename from scm_with_fluids, and
don't expose to Scheme.
* libguile/eval.c (eval): Remove SCM_M_WITH_FLUIDS case.
* libguile/expand.c (expand_with_fluids): Remove with-fluids syntax.
(DYNLET): Remove, no longer defining dynlet in the %expanded-vtables.
* libguile/expand.h: Remove dynlet definitions.
* module/ice-9/eval.scm (primitive-eval): Remove with-fluids case.
* libguile/memoize.c (do_push_fluid, do_pop_fluid): New primitive
helpers, like wind and unwind.
(memoize): Memoize wind and unwind primcalls. Don't memoize dynlet to
with-fluids.
(scm_init_memoize): Initialize push_fluid and pop_fluid here.
* libguile/memoize.h (SCM_M_WITH_FLUIDS): Remove definition.
* module/ice-9/psyntax.scm (build-dynlet): Remove; this just supported
with-fluids, which is now defined in boot-9.
* module/ice-9/psyntax-pp.scm: Regenerate.
* doc/ref/compiler.texi (Tree-IL):
* module/language/tree-il.scm:
* module/language/tree-il/analyze.scm:
* module/language/tree-il/canonicalize.scm:
* module/language/tree-il/compile-glil.scm:
* module/language/tree-il/cse.scm:
* module/language/tree-il/debug.scm:
* module/language/tree-il/effects.scm: Remove <dynlet>. Add cases for
primcalls to push-fluid and pop-fluid in compile-glil.scm and
effects.scm.
* module/language/tree-il/peval.scm (peval): Factor out
with-temporaries; probably a bad idea, but works for now. Factor out
make-begin0 (a better idea). Inline primcalls to with-fluid*, and
remove dynlet cases.
* module/language/tree-il/primitives.scm (*interesting-primitive-names*):
Add with-fluid*.
* doc/ref/compiler.texi: Remove mention of <dynwind>.
* libguile/eval.c (eval): Remove SCM_M_DYNWIND case.
* libguile/expand.c: Remove scm_sym_at_dynamic_wind.
* libguile/memoize.c (do_wind, do_unwind): A couple of hacky subrs. If
we see a wind or unwind primcall, we expand to a call of a quoted subr
value. It works and removes a kind of memoized value from the
interpreter. For the compiler,primcalls to wind and unwind are
handled specially.
(MAKMEMO_DYNWIND): Remove.
(scm_tc16_memoizer): Remove. Yay!
(memoize): Remove speculative lookup for toplevels to see if they are
memoizers: there are no more memoizers. Memoize calls to the wind and
unwind primitives.
(m_dynamic_wind): Remove.
(unmemoize): Remove dynwind case.
(scm_init_memoize): Add wind and unwind local definitions.
* module/ice-9/boot-9.scm (dynamic-wind): Reimplement in terms of "wind"
and "unwind" primitives. These primitives are not exposed to other
modules.
* module/ice-9/eval.scm (primitive-eval): Remove dynwind case.
* module/language/scheme/decompile-tree-il.scm (do-decompile):
(choose-output-names): Remove dynwind cases.
* module/language/tree-il.scm: Remove <dynwind>. Yaaay!
* module/language/tree-il/analyze.scm (analyze-lexicals): Remove dynwind
cases.
* module/language/tree-il/compile-glil.scm (*primcall-ops*): Add wind
and unwind.
(flatten-lambda-case): Remove dynwind case. Yay!
* module/language/tree-il/cse.scm (cse):
* module/language/tree-il/debug.scm (verify-tree-il):
* module/language/tree-il/effects.scm (make-effects-analyzer):
* module/language/tree-il/peval.scm (singly-valued-expression?, peval):
Remove <dywind> cases. Inline primcalls to dynamic-wind. Add
constant folding for thunk?.
* module/language/tree-il/primitives.scm (*interesting-primitive-names*):
Remove @dynamic-wind, and add procedure? and thunk?.
(*effect+exception-free-primitives*): Add procedure? and thunk?.
(*multiply-valued-primitives*): Remove @dynamic-wind.
Remove @dynamic-wind expander.
* test-suite/tests/peval.test ("partial evaluation"): Update tests for
dynwind desugaring.
* module/language/tree-il.scm (<tree-il>): Remove pre and post fields
from <dynwind>. A dynwind now assumes that in normal entry and exit,
that the code runs the winders and unwinders using <seq> and
<let-values> and such things.
(parse-tree-il, unparse-tree-il, make-tree-il-folder, pre-post-order):
Adapt <dynwind> users.
* module/language/tree-il/analyze.scm (analyze-lexicals):
* module/language/tree-il/compile-glil.scm (flatten-lambda-case):
* module/language/tree-il/cse.scm (cse):
* module/language/tree-il/debug.scm (verify-tree-il):
* module/language/tree-il/effects.scm (make-effects-analyzer): Adapt.
* module/language/tree-il/peval.scm (peval):
* module/language/tree-il/primitives.scm (*primitive-expand-table*):
Produce tree-il that calls the winder and unwinder. Recognize
singly-valued dynamic-wind expressions.
* test-suite/tests/peval.test ("partial evaluation"): Add tests.
* module/language/tree-il.scm (tree-il-fold): Implement using
make-tree-il-folder. This is an incompatible change: there is no more
"leaf" procedure, and tree-il-fold only works on tree-il and not
lists.
* module/language/tree-il/analyze.scm (<tree-analysis>, analyze-tree):
Adapt to tree-il-fold change, losing the "leaf" handler.
(unused-variable-analysis, unused-toplevel-analysis)
(unbound-variable-analysis, arity-analysis): Adapt to tree-analysis
change.
* module/language/tree-il/canonicalize.scm (tree-il-any)
* module/language/tree-il/cse.scm (build-assigned-var-table)
* module/language/tree-il/peval.scm (tree-il-any, build-var-table)
(peval): Adapt to tree-il-fold change.
* test-suite/tests/tree-il.test ("tree-il-fold"): Adapt tests for new
interface and expectations.
* module/language/tree-il/analyze.scm (format-string-argument-count):
Handle ~t and ~k options case-insensitively.
~! ~| ~/ ~q and ~Q should not update the min-count or max-count.
~^ returns the min-count and 'any
+ - # and ' should not increase the argument count.
* test-suite/tests/tree-il.test (*): Tests for new parameters.
* module/language/tree-il/analyze.scm (validate-arity): Fix for
applicable structs. Applicable structs are procedures, but not every
struct has a first slot, and not every struct with a procedure in its
first slot is applicable. Besides, the approach in this patch gives
better errors.
* module/language/tree-il/analyze.scm (proc-ref?)[special?]: New
procedure.
Return #t for any toplevel-ref of `_'.
* test-suite/tests/tree-il.test ("warnings")["format"]("non-literal
format string using gettext as top-level _"): New test.
* module/language/tree-il/analyze.scm (proc-ref?): Check for
SPECIAL-NAME in the <module-ref> and <lexical-ref> cases too.
* test-suite/tests/tree-il.test ("warnings")["format"]("non-literal
format string using gettext as module-ref _", "non-literal format
string using gettext as lexical _"): New tests.
* module/language/tree-il/analyze.scm (proc-ref?): Change to use less
false-if-exception and more variable-bound?. If a variable is present
in the local module but not bound, assume that it is gettext if it has
the right name. This is to allow for (define _ gettext).
* test-suite/tests/tree-il.test ("warnings"): Update (_ "foo") example.
There are a some failures currently:
FAIL: tree-il.test: warnings: format: non-literal format string with forward declaration
ERROR: srfi-18.test: current-exception-handler: current handler returned at top level - arguments: ((wrong-type-arg "car" "Wrong type argument in position ~A (expecting ~A): ~S" (1 "pair" #<unspecified>) (#<unspecified>)))
ERROR: srfi-18.test: current-exception-handler: multiple levels of handler nesting - arguments: ((wrong-type-arg "car" "Wrong type argument in position ~A (expecting ~A): ~S" (1 "pair" #<unspecified>) (#<unspecified>)))
ERROR: srfi-18.test: current-exception-handler: exception handler installation is thread-safe - arguments: ((wrong-type-arg "car" "Wrong type argument in position ~A (expecting ~A): ~S" (1 "pair" #<unspecified>) (#<unspecified>)))
Conflicts:
module/language/tree-il/peval.scm
module/language/tree-il/primitives.scm
test-suite/tests/tree-il.test
* module/language/tree-il/analyze.scm (proc-ref?): Wrap `variable-ref'
in `false-if-exception'.
* test-suite/tests/tree-il.test ("warnings")["format"]("non-literal
format string with forward declaration"): New test.
* module/language/tree-il/analyze.scm (gettext?): Rename to...
(proc-ref?): ... this. Add `proc' and `special-name' parameters.
(gettext?): Define in terms of `proc-ref?'.
(ngettext?): New procedure.
(const-fmt): Recognize `ngettext' calls.
(format-analysis)[<down>](check-format-args]: Check
constant-but-non-string 2nd argument in the (not (const-fmt ...))
case.
[check-simple-format-args]: Use `const-fmt'.
* test-suite/tests/tree-il.test ("warnings")["format"]("non-literal
format string using ngettext", "non-literal format string using
ngettext as N_"): New tests.
("simple-format")["unsupported, ngettext"]: New test.
Fixes <http://bugs.gnu.org/10846>.
Reported by Bruno Haible <bruno@clisp.org>.
* module/language/tree-il/analyze.scm (gettext?): New procedure.
(const-fmt): Add `env' parameter; update callers. Use `gettext?'.
(format-analysis)[check-simple-format-args]: Actually support
gettextized format strings.
* test-suite/tests/tree-il.test ("warnings")["format"]("non-literal
format string using gettext"): Use `gettext' as the procedure name.
("non-literal format string using gettext as _"): New test.
["simple-format"]("unsupported, gettext"): New test.
* module/language/tree-il/analyze.scm (format-string-argument-count):
Add support for ~h.
* test-suite/tests/tree-il.test ("warnings")["format"]("~h", "~:h with
locale object", "~:h without locale object"): New tests.
* module/language/tree-il/analyze.scm
(format-analysis)[check-simple-format-args]: New procedure. Use it.
Add support for applications of <module-ref>.
* module/system/base/message.scm (%warning-types): Handle the `format
simple-format' warning.
* module/language/scheme/spec.scm (scheme)[make-default-environment]:
Use `simple-format' as the default `format'.
* test-suite/tests/tree-il.test ("warnings")["format"]: Explicitly use
(@ (ice-9 format) format) where needed.
("simple-format"): New test prefix.
* 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/analyze.scm (analyze-lexicals): When stepping
into a non-tail form, we know that labels allocation will be invalid,
so use an empty labels set. Fixes http://debbugs.gnu.org/9769.
* test-suite/tests/tree-il.test ("labels allocation"): Add a test.
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
* 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/analyze.scm (gensym?): New procedure.
(unused-variable-analysis): Ignore variables whose name passes
`gensym?' or is `_'.
(unused-toplevel-analysis): Ignore variables whose name passes
`gensym?'.
* test-suite/tests/tree-il.test ("warnings")["unused-variable"]("special
variable names"): New test.
["unused-toplevel"]("special variable names"): New test.
* module/language/tree-il/analyze.scm (format-analysis): Don't warn on
non-literal format string if the format string is a lexical ref to a
variable named "fmt". A slight hack, but effective :)
* module/system/repl/command.scm (display-stat): Rename the format
string to "fmt".
* module/language/tree-il/analyze.scm (&syntax-error): New variable.
(format-string-argument-count): Throw to &SYNTAX-ERROR when a syntax
error in a format string is encountered.
(format-analysis): Catch &SYNTAX-ERROR and convert as a warning of the
appropriate type.
* module/system/base/message.scm (%warning-types)[format]: Handle
`syntax-error' warnings.
* test-suite/tests/tree-il.test
("warnings")["conditionals"]("unterminated", "unexpected ~;",
"unexpected ~]"): New tests.
["unterminated ~{...~}"]: New test.
* module/language/tree-il/analyze.scm (format-analysis): Add new
sub-warnings: `wrong-port', `wrong-format-string',
`non-literal-format-string', and `wrong-num-args'.
* module/system/base/message.scm (%warning-types)[format]: Handle
them.
* test-suite/tests/tree-il.test ("warnings")["wrong port arg",
"wrong format string", "non-literal format string",
"wrong number of args"]: New tests.
* module/language/tree-il/analyze.scm (format-string-argument-count):
Return two values, the minimum and maximum number of arguments.
Add support for most of `format' escapes, including conditionals.
(format-analysis): Adjust accordingly.
* module/system/base/message.scm (%warning-types)[format]: Take two
arguments, MIN and MAX, instead of EXPECTED. Display warning
accordingly.
* test-suite/tests/tree-il.test ("warnings")["format"]("~%, ~~, ~&, ~t,
~_, and ~\\n", "~{...~}", "~{...~}, too many args", "~@{...~}",
"~@{...~}, too few args", "~(...~)", "~v", "~v:@y", "~*", "~?",
"complex 1", "complex 2", "complex 3"): New tests.
("conditionals"): New test prefix.
* 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/procprop.h (scm_sym_arity): Deprecate. I didn't move it to
deprecated.h though, because that might have some boot implications --
though I didn't check.
* libguile/procprop.c (scm_procedure_properties)
(scm_set_procedure_properties_x, scm_procedure_property)
(scm_set_procedure_property_x): Deprecate access to a procedure's
arity via procedure-properties. Users should use
procedure-minimum-arity.
* module/ice-9/channel.scm (eval):
* module/ice-9/session.scm (arity):
* module/language/tree-il/analyze.scm (validate-arity): Fix up instances
of (procedure-property x 'arity) to use procedure-minimum-arity.
* libguile/programs.h:
* libguile/programs.c (scm_program_name): Remove. procedure-name is
sufficient.
* module/system/vm/program.scm (program-name): Remove from exports list.
(program-documentation): Remove; procedure-documentation is
sufficient.
* libguile/debug.c (scm_procedure_name): Remove special case for
programs.
* module/language/tree-il/analyze.scm (validate-arity): Use
procedure-name.
* module/ice-9/documentation.scm (object-documentation): Just use
procedure-documentation, without special cases for programs.