summaryrefslogtreecommitdiff
path: root/libguile/memoize.c
AgeCommit message (Collapse)AuthorFilesLines
2015-03-12Remove unused "nargs" field of memoized call expressionsAndy Wingo1-11/+10
* libguile/eval.c (eval): * libguile/memoize.c (MAKMEMO_CALL, memoize, unmemoize): * module/ice-9/eval.scm (primitive-eval): Remove "nargs" field from memoized call expressions, and adapt callers.
2014-12-10Convert primitive-eval to "compile" its expressions to linked closuresAndy Wingo1-1/+1
* libguile/memoize.c (memoize): Fix meta on subsequent case-lambda clauses. * module/ice-9/eval.scm (primitive-eval): Rewrite to compile expressions to thunks, to avoid runtime dispatch cost.
2014-12-07Minor evaluator tweaksAndy Wingo1-4/+9
* libguile/eval.c (eval): Remove unused variable. * libguile/memoize.c (unmemoize): Fix unmemoization. * module/ice-9/eval.scm: Attempt to speed up common box-ref cases.
2014-12-07Simplify variable resolution in the evaluatorAndy Wingo1-131/+105
* libguile/expand.c (convert_assignment): Handle creation of the default lambda-case body here. * libguile/eval.c (eval): * module/ice-9/eval.scm (primitive-eval): * libguile/memoize.h: * libguile/memoize.c (MAKMEMO_BOX_REF, MAKMEMO_BOX_SET): (MAKMEMO_TOP_BOX, MAKMEMO_MOD_BOX): Refactor all global var resolution to go through "resolve". Add "box-ref" and "box-set!". Rename memoize-variable-access! to %resolve-variable, and don't be destructive.
2014-12-07Closure conversion in evaluatorAndy Wingo1-13/+110
* libguile/memoize.c (MAKMEMO_CAPTURE_ENV, push_nested_link) (push_flat_link, env_link_is_flat, env_link_vars) (env_link_add_flat_var, lookup, capture_flat_env, memoize): Capture flat environments around closures.
2014-12-06Add capture-env to evaluatorAndy Wingo1-0/+5
* libguile/eval.c (eval): * libguile/memoize.c (memoized_tags, unmemoize): * libguile/memoize.h (SCM_M_CAPTURE_ENV): * module/ice-9/eval.scm (primitive-eval): Add capture-env memoized expression type.
2014-12-05Simplify the interpreter for trivial inits and no letrecAndy Wingo1-78/+16
* libguile/memoize.c (FULL_ARITY): Serialize "ninits" and the unbound value instead of the init list. (memoize): Adapt to FULL_ARITY changes. Remove LETREC case. (unmemoize): Adapt to memoized code change. * libguile/eval.c (BOOT_CLOSURE_PARSE_FULL): Adapt to parse ninits and unbound instead of inits. (eval): Lexical-ref can no longer raise an error. (prepare_boot_closure_env_for_apply): Adapt to inits change. * module/ice-9/eval.scm (primitive-eval): Adapt to ninits/unbound change. * libguile/expand.c (expand_named_let): Fix lambda-case creation to make lists for opt and inits.
2014-12-05Assignment conversion in the interpreterAndy Wingo1-1/+1
* libguile/expand.c (compute_assigned, convert_assignment) (scm_convert_assignment): New functions. * libguile/expand.h: Declare scm_convert_assignment. * libguile/memoize.c (scm_memoize_expression): Do assignment conversion before memoization. * test-suite/tests/syntax.test ("letrec"): Detection of unbound letrec variables now works.
2013-10-31Be smarter about capturing the environment for memoized codeAndy Wingo1-15/+52
* libguile/memoize.h (SCM_M_CAPTURE_MODULE) * libguile/memoize.c (MAKMEMO_CAPTURE_MODULE, capture_env): (maybe_makmemo_capture_module, memoize): Determine when to capture the module on the environment chain at compile-time, instead of at runtime. Introduces a new memoized expression type, capture-module. (scm_memoized_expression): Start memoizing with #f as the environment. (unmemoize): Add unmemoizer. (scm_memoize_variable_access_x): Cope with #f as module, and treat as the root module (captured before modules were booted). * libguile/eval.c (eval): * module/ice-9/eval.scm (primitive-eval): Adapt.
2013-10-27Memoized expressions are pairs, not SMOBsAndy Wingo1-53/+5
* libguile/memoize.c (MAKMEMO): Memoized objects are pairs now, not SMOBs. This lets eval.scm destructure them more efficiently. (scm_print_memoized, scm_memoized_p, scm_memoized_expression_typecode) (scm_memoized_expression_data): Remove these interfaces. (unmemoize, scm_memoize_variable_access_x): Remove SMOB type checks. (scm_init_memoize): Remove SMOB type definition. * libguile/memoize.h (scm_tc16_memoized, SCM_MEMOIZED_P) (scm_memoized_expression_typecode, scm_memoized_expression_data) (scm_memoized_p): Remove declarations. * libguile/validate.h (SCM_VALIDATE_MEMOIZED): Remove declaration. * libguile/eval.c (eval): Remove memoized type check, and inline the inum unpacking. * module/ice-9/eval.scm (memoized-expression-case): Use car and cdr to destructure memoized expressions. A big win!
2013-10-26Evaluator sets same procedure properties as compilerAndy Wingo1-13/+9
* libguile/memoize.c (MAKMEMO_LAMBDA, memoize): Instead of passing the docstring in the memoized lambda, pass the meta as-is. That way we get all procedure properties, including "name". * module/ice-9/eval.scm (primitive-eval): Set procedure properties when making lambdas. Don't set the name when defining toplevel variables -- before we did so only if the procedure didn't have a name property, but I would like to avoid calls to procedure-property in eval, because getting the name for an RTL function requires loading up other modules.
2013-10-25Evaluator uses two-dimensional environmentAndy Wingo1-97/+97
* libguile/memoize.c (MAKMEMO_LEX_REF, MAKMEMO_LEX_SET): Change to address lexicals by depth and width. (try_lookup_rib, lookup_rib, make_pos): New helpers. (lookup): Adapt to return a pair. (memoize, unmemoize_bindings, unmemoize_lexical): Adapt. * libguile/eval.c (eval, prepare_boot_closure_env_for_eval): (prepare_boot_closure_env_for_apply): * module/ice-9/eval.scm (make-fixed-closure, make-general-closure) (eval): Adapt to new environment. This is currently a slight win for C, and a slight lose for Scheme -- because the lookup loop is so poorly compiled by the stack VM. I expect that the RTL-compiled eval will fix this.
2013-06-28Simplify dynstack API to only wind one fluid at a timeAndy Wingo1-3/+3
* libguile/dynstack.h (SCM_DYNSTACK_TYPE_WITH_FLUID): Rename from with-fluids. * libguile/dynstack.c (scm_dynstack_push_fluid): (scm_dynstack_unwind_fluid): Change API to only wind/unwind one fluid binding. (WITH_FLUID_WORDS): New define, always 2 words (fluid and value box). (WITH_FLUID_FLUID, WITH_FLUID_VALUE_BOX): New macros to get offsets of fluid and value box. (scm_dynstack_push_rewinder, scm_dynstack_push_unwinder): Use WINDER_WORDS. (scm_dynstack_push_dynwind): Use DYNWIND_WORDS. (scm_dynstack_wind_1): Update for scm_swap_fluid API change. * libguile/fluids.h: * libguile/fluids.c (scm_prepare_fluids): Remove; no longer needed. (scm_swap_fluid): Update to just swap one fluid binding. (scm_c_with_fluids, scm_c_with_fluid): Update to use scm_dynstack_push_fluid. * libguile/memoize.c (do_push_fluid, do_pop_fluid): Adapt to API change. * libguile/vm-engine.c (rtl_vm_engine): Change wind-fluids / unwind-fluids to push-fluid / pop-fluid, and actually enable. Woo! * libguile/vm-i-system.c (push-fluid, pop-fluid): Update to new API.
2013-06-28Remove with-fluids; replaced by with-fluid* and inlined push-fluid primopsAndy Wingo1-20/+27
* 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*.
2013-06-27dynamic-wind in terms of wind and unwind; remove <dynwind>, @dynamic-windAndy Wingo1-53/+30
* 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.
2013-06-27remove @call-with-values memoizerAndy Wingo1-12/+5
* libguile/memoize.h: * libguile/expand.c (scm_sym_at_call_with_values): Remove. * libguile/memoize.c (memoize, m_call_values, unmemoize): Adapt to memoize call-with-values primcalls. * module/ice-9/boot-9.scm (call-with-values): Expand to a call-with-values primcall. * module/language/tree-il/compile-glil.scm (flatten-lambda-case): Expect call-with-values primcall, without the @, and fall back to a normal call. * module/language/tree-il/peval.scm (peval): Match bare call-with-values. * module/language/tree-il/primitives.scm (*interesting-primitive-names*): (*multiply-valued-primitives*): Remove @call-with-values.
2013-06-27remove @call-with-current-continuation memoizerAndy Wingo1-11/+8
* module/ice-9/boot-9.scm (call-with-current-continuation): Change to primcall call-with-current-continuation. * libguile/memoize.h: * libguile/expand.c (scm_sym_atcall_cc): Remove. * libguile/memoize.c (memoize): Memoize call/cc primcalls to SCM_M_CONT. (m_call_cc): Remove. (unmemoize): Unmemoize to call-with-current-continuation. * module/language/tree-il/compile-glil.scm (flatten-lambda-case): Update to call-with-current-continuation without @ prefix, and fix fallback case. * module/language/tree-il/primitives.scm (*multiply-valued-primitives*): (*interesting-primitive-names*): Remove @call-with-current-continuation. (call/cc): Expand to call-with-current-continuation. * test-suite/tests/tree-il.test ("call/cc"): Update to use and expect call-with-current-continuation primcalls / toplevel refs.
2013-06-27remove @apply memoizerAndy Wingo1-44/+5
* libguile/memoize.c (memoize): Recognize a primcall to 'apply as SCM_M_APPLY. (@apply): Remove @apply memoizer. (unmemoize): Unmemoize using "apply", not "@apply". * libguile/memoize.h: * libguile/expand.c (scm_sym_atapply): Remove. * module/ice-9/boot-9.scm (apply): Re-implement using apply primcall. Use case-lambda, so as to give an appropriate minimum arity. * module/language/tree-il/compile-glil.scm (flatten-lambda-case): Compile a primcall of "apply" specially, not "@apply". * module/language/tree-il/peval.scm (peval): Match primcalls to "apply", not "@apply". Residualize "apply" primcalls. * module/language/tree-il/primitives.scm (*interesting-primitive-names*): (*multiply-valued-primitives*): Remove @apply, and apply primitive expander. * test-suite/tests/peval.test: * test-suite/tests/tree-il.test: Update tests to expect residualized "apply". * test-suite/tests/procprop.test ("procedure-arity"): Update test for better apply arity. * test-suite/tests/strings.test ("string"): Update expected error.
2013-06-27Remove @prompt memoizerAndy Wingo1-25/+22
* libguile/memoize.h: * libguile/memoize.c (MAKMEMO_CALL_WITH_PROMPT, memoize, unmemoize): Remove the @prompt memoizer in favor of recognizing call-with-prompt primcalls. Rename SCM_M_PROMPT to SCM_M_CALL_WITH_PROMPT, and pass a thunk instead of an expression so that it has normal applicative order. * libguile/expand.c (PRIMITIVE_REF, PRIMCALL, expand): Produce primcalls from forms whose car is a primitive. (expand_atat): Recognize (@@ primitive FOO) as being a primitive-ref. * module/ice-9/boot-9.scm (call-with-prompt): Instead of dispatching to the wonky @prompt memoizer, residualize a primcall to call-with-prompt. The memoizer will DTRT to allow call-with-prompt to be interpreted correctly without needing an additional binding. * module/ice-9/eval.scm (primitive-eval): Change the 'prompt clause to a call to call-with-prompt. * module/language/tree-il/primitives.scm: No more need to recognize @prompt. * libguile/eval.c (eval): Adapt to SCM_M_PROMPT renaming to SCM_M_CALL_WITH_PROMPT, and apply the thunk. * libguile/throw.c (pre_init_throw): Adapt to scm_abort_to_prompt_star rename.
2013-03-28Merge remote-tracking branch 'origin/stable-2.0'Mark H Weaver1-3/+22
Conflicts: configure.ac libguile/deprecated.c libguile/deprecated.h libguile/filesys.h libguile/fluids.c libguile/fports.c libguile/gc.c libguile/guile.c libguile/numbers.c libguile/objcodes.c libguile/r6rs-ports.c libguile/smob.c libguile/socket.c libguile/threads.h module/language/scheme/decompile-tree-il.scm module/language/tree-il/peval.scm test-suite/tests/syncase.test
2013-03-09allow case-lambda expressions with no clausesAndy Wingo1-3/+22
* module/ice-9/psyntax-pp.scm: * module/ice-9/psyntax.scm (case-lambda, case-lambda*): Allow 0 clauses. * module/language/scheme/decompile-tree-il.scm (do-decompile): (choose-output-names): * module/language/tree-il.scm (unparse-tree-il): (tree-il-fold, post-order!, pre-order!): * module/language/tree-il/effects.scm (make-effects-analyzer): * module/language/tree-il/cse.scm (cse): * module/language/tree-il/debug.scm (verify-tree-il): * module/language/tree-il/peval.scm (peval): Allow for lambda-body to be #f. * libguile/memoize.c (memoize): * module/language/tree-il/canonicalize.scm (canonicalize!): Give a body to empty case-lambda before evaluating it or compiling it, respectively. * test-suite/tests/optargs.test ("case-lambda", "case-lambda*"): Add tests.
2013-01-31Merge remote-tracking branch 'origin/stable-2.0'Andy Wingo1-2/+1
Conflicts: module/ice-9/psyntax-pp.scm module/ice-9/psyntax.scm module/language/bytecode/spec.scm module/language/tree-il/spec.scm
2013-01-28Remove unneeded SMOB mark procedure in `memoize.c'.Ludovic Courtès1-2/+1
* libguile/memoize.c (scm_init_memoize): Remove unnecessary call to `scm_set_smob_mark'.
2013-01-07Merge remote-tracking branch 'origin/stable-2.0'Mark H Weaver1-40/+61
Conflicts: GUILE-VERSION libguile/posix.c module/ice-9/eval.scm test-suite/tests/cse.test
2012-11-28eval: Store docstrings for lambdas.Ludovic Courtès1-40/+61
Fixes <http://bugs.gnu.org/12173>. Reported by Ian Price <ianprice90@googlemail.com>. * libguile/memoize.c (MAKMEMO_LAMBDA): New `docstring' parameter. Add it as the second argument of `SCM_M_LAMBDA'. Update caller. (memoize)[SCM_M_LAMBDA]: Extract docstring from EXP; when `memoize' returns, add the docstring to the lambda's arguments. (unmemoize)[SCM_M_LAMBDA]: Adjust to new argument layout of `SCM_M_LAMBDA'. * libguile/eval.c (BOOT_CLOSURE_NUM_REQUIRED_ARGS, BOOT_CLOSURE_HAS_REST_ARGS, BOOT_CLOSURE_IS_REST, BOOT_CLOSURE_PARSE_FULL): Adjust to new argument layout of `SCM_M_LAMBDA'. * module/ice-9/eval.scm (primitive-eval)[make-general-closure]: Likewise. [eval]: When EXP is a lambda, match its docstring; when the docstring is not #f, add it to the closures procedure properties. * test-suite/tests/eval.test ("docstrings"): New test prefix. * libguile/procs.c (sym_documentation): Rename to... (scm_sym_documentation): ... this. Make it global. * libguile/procs.h (scm_sym_documentation): New declaration.
2011-12-01Merge remote-tracking branch 'origin/stable-2.0'Andy Wingo1-1/+1
Conflicts: configure.ac libguile/fluids.c libguile/gc.c libguile/gc.h libguile/objcodes.c libguile/procprop.c libguile/vm.c module/ice-9/psyntax-pp.scm module/ice-9/psyntax.scm
2011-11-16memoize: booleanify the rest argAndy Wingo1-1/+1
* libguile/memoize.c (memoize): Turn the rest arg into a boolean. Fixes an error when rest gets passed to set-procedure-minimum-arity!.
2011-11-08locking for putc, putsAndy Wingo1-2/+2
* libguile/ports.c (scm_putc, scm_puts): * libguile/ports.h (scm_putc_unlocked, scm_puts_unlocked): Separate into _unlocked and locked variants. Change all callers to use the _unlocked versions.
2011-10-25most uses of scm_from_locale_symbol become scm_from_utf8_symbolAndy Wingo1-1/+1
* libguile/array-handle.c: * libguile/chars.c: * libguile/expand.c: * libguile/feature.c: * libguile/goops.c: * libguile/gsubr.c: * libguile/instructions.c: * libguile/load.c: * libguile/macros.c: * libguile/memoize.c: * libguile/modules.c: * libguile/options.c: * libguile/print.c: * libguile/smob.c: * libguile/snarf.h: Change most uses of scm_from_locale_symbol to scm_from_utf8_symbol, as the symbols really are not locale-dependent.
2011-06-02sequence of expressions -> seq of head and tailAndy Wingo1-16/+29
* 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.
2011-06-02add <primcall> to tree-ilAndy Wingo1-0/+14
* libguile/expand.c: * libguile/expand.h (SCM_EXPANDED_PRIMCALL_TYPE_NAME): (SCM_EXPANDED_PRIMCALL_FIELD_NAMES): (SCM_EXPANDED_PRIMCALL_SRC): (SCM_EXPANDED_PRIMCALL_NAME): (SCM_EXPANDED_PRIMCALL_ARGS): (SCM_MAKE_EXPANDED_PRIMCALL): Add "primcall" Tree-IL type. * doc/ref/compiler.texi (Tree-IL): Update docs. * libguile/memoize.c (memoize): Memoizer for primcalls. * module/ice-9/psyntax.scm: Build primcalls, sometimes. Also change build-primref to just make a primitive-ref. * module/language/tree-il.scm: Add primcall to the exports, parsers, serializers, etc. * 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: * module/language/tree-il/primitives.scm: * module/language/elisp/compile-tree-il.scm: Add primcall support. * test-suite/tests/tree-il.test: Use primcalls sometimes.
2011-06-02rename <application> to <call>Andy Wingo1-3/+3
* doc/ref/compiler.texi (The Scheme Compiler): Update docs. * libguile/expand.h: * libguile/expand.c: * module/language/tree-il.scm: Rename <application> to <call>. Change the external representation from (apply proc arg ...) to (call proc arg ...). * libguile/memoize.c: * module/ice-9/psyntax-pp.scm: * module/ice-9/psyntax.scm: * module/language/brainfuck/compile-tree-il.scm: * module/language/ecmascript/compile-tree-il.scm: * module/language/elisp/compile-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: * module/language/tree-il/primitives.scm: * test-suite/tests/tree-il.test: Update all callers.
2011-05-13more care regarding SCM_PACK and SCM_UNPACKAndy Wingo1-3/+4
* libguile/control.c (reify_partial_continuation): * libguile/eval.c (RETURN_BOOT_CLOSURE): * libguile/frames.c (scm_frame_num_locals, scm_frame_local_ref) (scm_frame_local_set_x) * libguile/frames.h (SCM_FRAME_SET_RETURN_ADDRESS): (SCM_FRAME_SET_MV_RETURN_ADDRESS, SCM_FRAME_SET_DYNAMIC_LINK): * libguile/goops.c (scm_class_of, scm_primitive_generic_generic) (scm_c_extend_primitive_generic, compute_getters_n_setters) (scm_sys_initialize_object): * libguile/guardians.c (finalize_guarded): * libguile/list.c (SCM_I_CONS): * libguile/macros.c (scm_i_make_primitive_macro) (scm_make_syntax_transformer): * libguile/memoize.c (MAKMEMO, SCM_MAKE_MEMOIZER) (SCM_MAKE_REST_MEMOIZER): * libguile/modules.c (scm_module_reverse_lookup) * libguile/print.c (iprin1): * libguile/promises.c (scm_make_promise) * libguile/srcprop.c (scm_make_srcprops): * libguile/vectors.c (scm_c_vector_ref): * libguile/vm-engine.c (vm_engine) * libguile/vm-i-scheme.c (REL, add1, sub1): * libguile/vm-i-system.c (new_frame, call_cc) * libguile/weaks.h (SCM_WEAK_PAIR_WORD_DELETED_P): Be more careful about SCM_PACK / SCM_UNPACK.
2011-01-07use scm_from_latin1_symboln for string literals and load-symbolAndy Wingo1-4/+4
* libguile/bytevectors.c: * libguile/eval.c: * libguile/goops.c: * libguile/i18n.c: * libguile/load.c: * libguile/memoize.c: * libguile/modules.c: * libguile/ports.c: * libguile/print.c: * libguile/procs.c: * libguile/programs.c: * libguile/read.c: * libguile/script.c: * libguile/srfi-14.c: * libguile/stacks.c: * libguile/strings.c: * libguile/throw.c: * libguile/vm.c: Use scm_from_latin1_symboln to make symbols from string literals, because they aren't in the user's locale -- they are in ASCII, and we can optimize this case. * libguile/vm-i-loader.c: Also use scm_from_latin1_symboln when loading narrow symbols.
2010-08-16@apply for multiple args in the boot memoizerAndy Wingo1-5/+37
* libguile/memoize.c (m_apply): Fix for multiple arguments, as in (@apply proc foo bar baz).
2010-06-17psyntax, primitive expander, and memoizer support for letrec*Andy Wingo1-15/+32
* libguile/expand.c (expand_letrec_helper): Factor out common code. (expand_letrec): Use expand_letrec_helper. (expand_letrec_star): New primitive syntax: letrec*. * libguile/memoize.c (memoize): Add memoizer support for in-order letrec (letrec*). * module/ice-9/psyntax.scm (build-letrec): Another arg, `in-order?'. (chi-body): Adapt to build-letrec change. We don't yet use letrec* for internal definitions. (letrec): Adapt to build-letrec change. (letrec*): New expander. * module/ice-9/psyntax-pp.scm: Regenerated.
2010-06-17fix bug in memoizeAndy Wingo1-3/+3
* libguile/memoize.c (memoize): Fix a bug where LETREC was being accessed as LET, and it just happened to coincide.
2010-05-20iron out inconsistency between eval and compile expansionAndy Wingo1-1/+18
* libguile/expand.c (expand_lambda_star_case): Harmonize with tree-il, expanding keywords to (aok? (kw name gensym) ...), not (aok? (kw . index) ...). * libguile/memoize.c (memoize): Process the (kw name gensym) format into (kw . index). * module/ice-9/psyntax.scm (build-lambda-case): Remove a compile-versus-eval special case. * module/ice-9/psyntax-pp.scm: Regenerate.
2010-05-20primitive-eval takes expanded, not memoized, sourceAndy Wingo1-4/+1
* 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.
2010-05-19fix a couple expander naming bugsAndy Wingo1-1/+1
* libguile/expand.h: * libguile/memoize.c: Fix a couple bugs: it's application-args, not application-exps, and public?, not public.
2010-05-19separate boot expansion from memoizationAndy Wingo1-1068/+202
* 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.
2010-05-18remove the new scm_memoize_begin, etcAndy Wingo1-165/+0
* libguile/memoize.h: * libguile/memoize.c: Remove the recently-added scm_memoize_begin, scm_memoize_lambda, et al. We'll take a different tack.
2010-05-16scm_memoize_lambda updateAndy Wingo1-5/+22
* libguile/memoize.h: * libguile/memoize.c (scm_memoize_lambda): Update to memoize "full-arity" lambdas.
2010-05-14evaluator support for case-lambdaAndy Wingo1-9/+96
* 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.
2010-05-14primitive support for lambda*Andy Wingo1-0/+171
* 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.
2010-05-13tweak to lambda* memoization formatAndy Wingo1-4/+18
* libguile/memoize.c (FULL_ARITY): Change the form to more closely approximate <lambda-case>. (unmemoize): Unmemoize lambda* expressions.
2010-05-13change to format of memoization lambda expressionsAndy Wingo1-13/+37
* 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.
2010-05-07add memoize-begin, memoize-let, etc functionsAndy Wingo1-0/+148
* libguile/memoize.h: * libguile/memoize.c (scm_memoize_begin, scm_memoize_if, scm_memoize_lambda, scm_memoize_let, scm_memoize_quote, scm_memoize_define, scm_memoize_with_fluids, scm_memoize_call, scm_memoize_lexical_ref, scm_memoize_lexical_set, scm_memoize_toplevel_ref, scm_memoize_toplevel_set, scm_memoize_module_ref, scm_memoize_module_set): New functions, public to Scheme but private to C. For use by psyntax, in the future.
2010-05-07add "memoizer" data typeAndy Wingo1-88/+135
* libguile/memoize.h: * libguile/memoize.c (MAKMEMO_APPLY): Take the proc and args separately. (scm_tc16_memoizer, SCM_MEMOIZER_P, SCM_MEMOIZER): New smob type, for "syntax" like @apply that have normal evaluation order. (memoize_env_ref_macro, memoize): Refactor to handle "memoizers" generically. Reorganize the list of SCM_SYNTAX forms. Move @apply, @dynamic-wind, @call-with-current-continuation, @call-with-values, @prompt handling down to be generic "memoizer" data types. (scm_memoizer_p, scm_memoizer): New functions, exposed to Scheme. Will be used by psyntax.
2010-05-07macro expanders return memoized expressionsAndy Wingo1-0/+3
* 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.