* libguile/procprop.c (scm_set_procedure_minimum_arity_x): New
function, allows a user to override a function's arity.
(scm_i_procedure_arity): Look up in the overrides table first.
* libguile/procprop.h: Add scm_set_procedure_minimum_arity_x.
* module/ice-9/eval.scm (primitive-eval): Override arity of "general
closures".
* test-suite/tests/procprop.test ("procedure-arity"): Add tests.
Based on a patch from Stefan Israelsson Tampe. Test based on work by
Patrick Bernaud.
* 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/ice-9/eval.scm (primitive-eval): Try using list-ref instead of
cdring in the vm. We'll check the hydra build times to see if this has
any actual merit. Surely the best solution is another representation
of environments, though.
* module/ice-9/eval.scm (primitive-eval):
* libguile/eval.c (scm_c_primitive_eval): Don't expect a memoized
expression -- expect either raw source or an *expanded* expression. We
handle memoization ourselves.
* libguile/expand.c (scm_macroexpand): Settle down into its proper name,
"macroexpand", even as we comment that it is but a fleeting boot
expander.
(scm_macroexpanded_p): New predicate for expanded code.
* libguile/expand.h: Add scm_macroexpanded_p.
* libguile/memoize.c (scm_memoize_expression): Require that the
expression be expanded.
(scm_init_memoize): Don't alias memoize-expression to macroexpand.
* module/ice-9/psyntax-pp.scm:
* module/ice-9/psyntax.scm: Always produce macroexpanded expressions,
and hand them to primitive-eval. No more calls to memoize-expression
here.
* test-suite/tests/optargs.test: Remove some tests, as unfortunately we
have no way to invoke the boot expander after boot.
* libguile/Makefile.am:
* libguile/init.c:
* libguile/expand.c:
* libguile/expand.h: Add new expander. The idea is that macroexpansion
is one thing, and whether to compile or interpret the result of that
is another thing.
* libguile/memoize.c: Adapt to expand as necessary, and then memoize
expanded source without worrying about syntax errors.
* module/ice-9/eval.scm (make-general-closure): Allow alt clauses to not
possess the full make-general-closure arity.
* libguile/memoize.c (patch_case_lambda, scm_m_case_lambda)
(scm_m_case_lambda_star): Add memoizers for case-lambda and
case-lambda*.
(unmemoize): Unmemoize lambdas with multiple arities.
* libguile/eval.c (prepare_boot_closure_env_for_apply):
(prepare_boot_closure_env_for_eval): Adapt to return both body and
env, so that case-lambda clauses can be selected appropriately.
(eval, boot_closure_apply): Adapt callers.
* module/ice-9/eval.scm (make-general-closure): Support multiple
arities.
* libguile/memoize.c (scm_m_lambda_star): Define lambda* in the
pre-psyntax env, and make it memoize lambda* expressions.
* libguile/eval.c (BOOT_CLOSURE_PARSE_FULL): New helper.
(error_invalid_keyword, error_unrecognized_keyword): New helpers.
(prepare_boot_closure_env_for_apply): Flesh out application of boot
closures with "full" arity.
(prepare_boot_closure_env_for_eval): Punt to
prepare_boot_closure_env_for_eval for the full-arity case.
* module/ice-9/eval.scm (make-fixed-closure): Rename from `closure', and
just handle fixed arities, where there is no rest argument..
(make-general-closure): New helper, a procedure, that returns a
closure that can take rest, optional, and keyword arguments.
(eval): Adapt to call make-fixed-closure or make-general-closure as
appropriate.
* test-suite/tests/optargs.test ("lambda* inits"): Test the memoizer as
well.
* libguile/memoize.c (scm_m_lambda, memoize_named_let)
(scm_memoize_lambda, unmemoize)
* libguile/eval.c (eval, prepare_boot_closure_env_for_apply)
(prepare_boot_closure_env_for_eval, boot_closure_apply):
* module/ice-9/eval.scm (primitive-eval): Change the format for memoized
lambda expressions, so as to allow, in the future, case-lambda* to be
supported by the evaluator.
* libguile/eval.c (scm_c_primitive_eval):
* module/ice-9/eval.scm (primitive-eval): Rely on the expander to
produce a memoized expression. If the expression is already memoized,
just pass it through (the equivalent of the old "noexpand" hack).
* libguile/memoize.c (scm_init_memoize): Initialize `memoize-expression'
as the initial binding of `macroexpand'.
* libguile/modules.c (scm_module_transformer): Before modules are
booted, look for `macroexpand', not `%pre-modules-transformer'.
* module/ice-9/boot-9.scm: No more %pre-modules-transformer. Loading
psyntax extends `macroexpand'.
(make-module): `macroexpand' is the default transformer.
* module/ice-9/psyntax.scm: No more `noexpand'.
(top-level-eval-hook, local-eval-hook): Instead of annotating with
noexpand, memoize the expression before handing it to primitive-eval.
(macroexpand): No more noexpand hack -- in its place we have another
hack, to memoize the result when running in eval mode.
* module/ice-9/psyntax-pp.scm: Regenerated.
* 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/tags.h (scm_tc7_with_fluids): Allocate a tc7 for
"with-fluids" objects, which will only live on the dynamic stack (wind
list), not in normal scheme-land.
* libguile/fluids.h (SCM_WITH_FLUIDS_P, SCM_WITH_FLUIDS_LEN)
(SCM_WITH_FLUIDS_NTH_FLUID, SCM_WITH_FLUIDS_NTH_VAL)
(SCM_WITH_FLUIDS_SET_NTH_VAL): Add some accessors.
* libguile/fluids.c (scm_i_make_with_fluids, scm_i_swap_with_fluids):
New internal functions.
(scm_c_with_fluids, scm_c_with_fluid): Push with-fluids objects on the
dynwind list, not winders.
* libguile/dynwind.c (scm_i_dowinds): Add cases for winding and
unwinding with-fluids objects.
* libguile/memoize.h (scm_sym_with_fluids, SCM_M_BEGIN): New public
data.
* libguile/memoize.c (scm_m_with_fluids): Define with-fluids as a
primitive syntax.
(unmemoize): Add with-fluids case.
* libguile/eval.c (eval):
* module/ice-9/eval.scm (primitive-eval): Add with-fluids cases.
* test-suite/tests/fluids.test
("fluids not modified if nonfluid passed to with-fluids"): Enable a
now-passing test.
* module/ice-9/eval.scm: Add a comment explaining the frequencies of the
various memoized expression types.
(eval): Reorder the cases based the profile.
* 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.
* libguile/memoize.c (MAKMEMO_CALL): Memoize in the number of arguments
at the call site.
(memoize, scm_m_cond, memoize_named_let, unmemoize):
* libguile/eval.c (eval): Adapt to changes in call memoization.
* module/ice-9/eval.scm (primitive-eval): For calls, pass the first N
arguments directly on the stack, and only the rest as a consed
argument list to apply. Currently N is 4.
* module/ice-9/eval.scm (primitive-eval): When making a closure with N
formals, actuall return a closure with N formals, if N is less than
*max-static-argument-count*, which currently is 8. If N is greater
than 8, do the arg-parsing loop as we did before. Requires some
macrology, but should reduce unnecessary consing for interpreted
closures.
* test-suite/tests/goops.test:
* test-suite/tests/hooks.test: Now that checks like (thunk? foo) are
going to work as a for interpreted code, remove some (throw
'unresolved).
* libguile/eval.c (scm_primitive_eval, scm_c_primitive_eval):
(scm_init_eval): Rework so that scm_primitive_eval always calls out to
the primitive-eval variable. The previous definition is the default
value, which is probably overridden by scm_init_eval_in_scheme.
* libguile/init.c (scm_i_init_guile): Move ports and load-path up, so we
can debug when initing eval. Call scm_init_eval_in_scheme. Awesome.
* libguile/load.h:
* libguile/load.c (scm_init_eval_in_scheme): New procedure, loads up
ice-9/eval.scm to replace the primitive-eval definition, if everything
is there and up-to-date.
* libguile/modules.c (scm_module_transformer): Export to Scheme, so it's
there for eval.go.
* module/ice-9/boot-9.scm: No need to define module-transformer.
* module/ice-9/eval.scm (capture-env): Only reference the-root-module if
modules are booted.
(primitive-eval): Inline a definition for identity. Throw a more
standard error for "wrong number of arguments".
* module/ice-9/psyntax.scm (chi-install-global): The macro binding for a
syncase macro is now a pair: the transformer, and the module that was
current when the transformer was installed. The latter is used for
hygiene purposes, replacing the use of procedure-module, which didn't
work with the interpreter's shared-code closures.
(chi-macro): Adapt for the binding being a pair, and get the hygiene
from the cdr.
(eval-local-transformer): Adapt to new form of macro bindings.
* module/ice-9/psyntax-pp.scm: Regenerated.
* .gitignore: Ignore eval.go.stamp.
* module/Makefile.am: Reorder for fastest serial compilation, now that
there are no ordering constraints. I did a number of experiments here
and this seems to be the best; but the bulk of the time is compiling
psyntax-pp.scm with eval.scm. Not so great.
* libguile/vm-engine.c (vm-engine): Throw a more standard error for
"wrong type to apply".
* test-suite/tests/gc.test ("gc"): Remove a hack that shouldn't affect
the new evaluator, and throw in another (gc) for good measure.
* test-suite/tests/goops.test ("defining classes"):
* test-suite/tests/hooks.test (proc1): We can't currently check what the
arity is of a closure made by eval.scm -- or more accurately all
closures have 0 required args and no rest args. So punt for now.
* test-suite/tests/syntax.test ("letrec"): The scheme evaluator can't
check that a variable is unbound, currently; perhaps the full "fixing
letrec" expansion could fix this. But barring that, punt.
* module/ice-9/eval.scm: New evaluator, written in Scheme. Whee!
Batteries included but not wired up.
* module/Makefile.am: Abuse touch(1) to make sure eval.go gets built
before everything. Can't just depend on eval.go, because eval.go will
get the timestamp of eval.scm, which might be newer than foo.go (and
thus foo.scm). Something better is warranted.