summaryrefslogtreecommitdiff
path: root/libguile/memoize.h
Commit message (Expand)AuthorAgeFilesLines
* Simplify variable resolution in the evaluator...* 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. Andy Wingo2014-12-071-6/+4
* Add capture-env to evaluator...* 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. Andy Wingo2014-12-061-1/+2
* Be smarter about capturing the environment for memoized code...* 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. Andy Wingo2013-10-311-0/+1
* Memoized expressions are pairs, not SMOBs...* 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! Andy Wingo2013-10-271-8/+2
* Remove with-fluids; replaced by with-fluid* and inlined push-fluid primops...* 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*. Andy Wingo2013-06-281-2/+0
* dynamic-wind in terms of wind and unwind; remove <dynwind>, @dynamic-wind...* 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. Andy Wingo2013-06-271-2/+0
* remove @call-with-values memoizer...* 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. Andy Wingo2013-06-271-1/+0
* remove @call-with-current-continuation memoizer...* 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. Andy Wingo2013-06-271-1/+0
* remove @apply memoizer...* 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. Andy Wingo2013-06-271-2/+1
* Remove @prompt memoizer...* 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. Andy Wingo2013-06-271-2/+1
* sequence of expressions -> seq of head and tail...* 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. Andy Wingo2011-06-021-2/+2
* remove scm_memoizer_p and scm_memoizer declarations...* libguile/memoize.h (scm_memoizer_p, scm_memoizer): Remove these declarations. Andy Wingo2010-05-271-3/+0
* remove the new scm_memoize_begin, etc...* libguile/memoize.h: * libguile/memoize.c: Remove the recently-added scm_memoize_begin, scm_memoize_lambda, et al. We'll take a different tack. Andy Wingo2010-05-181-16/+0
* scm_memoize_lambda update...* libguile/memoize.h: * libguile/memoize.c (scm_memoize_lambda): Update to memoize "full-arity" lambdas. Andy Wingo2010-05-161-1/+2
* add memoize-begin, memoize-let, etc functions...* 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. Andy Wingo2010-05-071-0/+15
* add "memoizer" data type...* 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. Andy Wingo2010-05-071-0/+3
* prompt as part of guile's primitive language...* 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. Andy Wingo2010-02-191-1/+3
* add with-fluids objects and primitive syntax...* 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. Andy Wingo2010-02-181-0/+2
* dynwind is now a part of guile's primitive language...* 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. Andy Wingo2010-02-181-1/+3
* add memoized expression accessors to scheme...* libguile/eval.c: Fix a comment. (eval): Abstract out the variable memoization into a function, scm_memoize_variable_access_x. * libguile/memoize.c (memoized_tags): Fix a couple names. (scm_memoize_variable_access_x): New internal function. Actually it's public to Scheme, but we can't do much about that, because the new evaluator will need it. (scm_memoized_expression_typecode, scm_memoized_expression_data): New accessors for memoized code, for Scheme. (scm_memoized_typecode): Looks up the typecode for a symbol. Andy Wingo2009-12-011-0/+4
* new evaluator, y'all...* libguile/eval.c: So, ladies & gents, a new evaluator. It's similar to the old one, in that we memoize and then evaluate, but in this incarnation, memoization of an expression happens before evaluation, not lazily as the expression is evaluated. This makes the evaluation itself much cleaner, in addition to being threadsafe. In addition, since this C evaluator will in the future just serve to bootstrap the Scheme evaluator, we don't have to pay much concern for debugging conveniences. So the environment is just a list of values, and the memoizer pre-computes where it's going to find each individual value in the environment. Interface changes are commented below, with eval.h. (scm_evaluator_traps): No need to reset the debug mode after rnning te traps thing. But really, the whole traps system needs some love. * libguile/memoize.h: * libguile/memoize.c: New memoizer, which runs before evaluation, checking all syntax before evaluation begins. Significantly, no debugging information is left for lexical variables, which is not so great for interactive debugging; perhaps we should change this to have a var list in the future as per the classic interpreters. But it's quite fast, and the resulting code is quite good. Also note that it doesn't produce ilocs, memoized code is a smob whose type is in the first word of the smob itself. * libguile/eval.h (scm_sym_and, scm_sym_begin, scm_sym_case) (scm_sym_cond, scm_sym_define, scm_sym_do, scm_sym_if, scm_sym_lambda) (scm_sym_let, scm_sym_letstar, scm_sym_letrec, scm_sym_quote) (scm_sym_quasiquote, scm_sym_unquote, scm_sym_uq_splicing, scm_sym_at) (scm_sym_atat, scm_sym_atapply, scm_sym_atcall_cc) (scm_sym_at_call_with_values, scm_sym_delay, scm_sym_eval_when) (scm_sym_arrow, scm_sym_else, scm_sym_apply, scm_sym_set_x) (scm_sym_args): Remove public declaration of these symbols. (scm_ilookup, scm_lookupcar, scm_eval_car, scm_eval_body) (scm_eval_args, scm_i_eval_x, scm_i_eval): Remove public declaration of these functions. (scm_ceval, scm_deval, scm_ceval_ptr): Remove declarations of these deprecated functions. (scm_i_print_iloc, scm_i_print_isym, scm_i_unmemocopy_expr) (scm_i_unmemocopy_body): Remove declarations of these internal functions. (scm_primitive_eval_x, scm_eval_x): Redefine as macros for their less destructive siblings. * libguile/Makefile.am: Add memoize.[ch] to the build. * libguile/debug.h (scm_debug_mode_p, scm_check_entry_p) (scm_check_apply_p, scm_check_exit_p, scm_check_memoize_p) (scm_debug_eframe_size): Remove these vars that were tied to the old evaluator's execution model. (SCM_RESET_DEBUG_MODE): Remove, no more need for this. (SCM_MEMOIZEDP, SCM_MEMOIZED_EXP, SCM_MEMOIZED_ENV): Remove macros referring to old memoized code representation. (scm_local_eval, scm_procedure_environment, scm_memoized_environment) (scm_make_memoized, scm_memoized_p): Remove functions operating on old memoized code representation. (scm_memcons, scm_mem_to_proc, scm_proc_to_mem): Remove debug-only code for old evaluator. * libguile/debug.c: Remove code to correspond with debug.h removals. (scm_debug_options): No need to set the debug mode or frame limit here, as we don't have C stack limits any more. Perhaps this is a bug, but as long as we can compile eval.scm, we should be fine. * libguile/init.c (scm_i_init_guile): Init memoize.c. * libguile/modules.c (scm_top_level_env, scm_env_top_level) (scm_env_module, scm_system_module_env_p): Remove these functions. * libguile/print.c (iprin1): No more need to handle isyms. Adapt to new form of interpreted procedures. * libguile/procprop.c (scm_i_procedure_arity): Adapt to new form of interpreted procedures. * libguile/procs.c (scm_thunk_p): Adapt to new form of interpreted procedures. * libguile/procs.h (SCM_CLOSURE_FORMALS): Removed, this exists no more. (SCM_CLOSURE_NUM_REQUIRED_ARGS, SCM_CLOSURE_HAS_REST_ARGS): New accessors. * libguile/srcprop.c (scm_source_properties, scm_source_property) (scm_set_source_property_x): Remove special cases for memoized code. * libguile/stacks.c (read_frame): Remove a source-property case for interpreted code. (NEXT_FRAME): Remove a case that I don't fully understand, that seems to be designed to skip over apply frames. Will be obsolete in the futures. (read_frames): Default source value for interpreted frames to #f. (narrow_stack): Don't pay attention to the system_module thing. * libguile/tags.h: Remove isyms and ilocs. Whee! * libguile/validate.h (SCM_VALIDATE_MEMOIZED): Fix to use the new MEMOIZED_P formulation. * module/ice-9/psyntax-pp.scm (do, quasiquote, case): Adapt for these no longer being primitive macros. * module/ice-9/boot-9.scm: Whitespace change, but just a poke to force a rebuild due to and/or/cond/... not being primitives any more. * module/ice-9/deprecated.scm (unmemoize-expr): Deprecate, it's unmemoize-expression now. * test-suite/tests/eval.test ("define set procedure-name"): XFAIL a couple of tests here; I don't know what to do about them. I reckon the expander should ensure that defined values are named. * test-suite/tests/chars.test ("basic char handling"): Fix expected exception when trying to apply a char. Andy Wingo2009-12-011-0/+106