1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-30 11:50:28 +02:00
Commit graph

520 commits

Author SHA1 Message Date
Andy Wingo
b2b33168b1 more care regarding SCM_PACK and SCM_UNPACK
* 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-05-13 15:28:08 +02:00
Andy Wingo
a2230b653b map and for-each in scheme
* module/ice-9/boot-9.scm (map, for-each): Implement in Scheme instead
  of C.  There are boot versions before `cond' is defined.
  (map-in-order): Define this alias here instead of in evalext.h.

* libguile/eval.c: Stub out the map and for-each definitions to just
  call into Scheme.

* libguile/evalext.c: Remove map-in-order definition.

* module/srfi/srfi-1.scm: Replace all calls to map1 with calls to map.
  (map, for-each): Define implementations here, in Scheme, instead of in
  C.

* test-suite/tests/eval.test (exception:wrong-length, "map"): Update the
  expected exception for mapping over lists of different lengths.

* libguile/srfi-1.h:
* libguile/srfi-1.c: Remove map and for-each definitions.  Remove the
  bit that extended the core `map' primitive with another method: the
  right way to do that is with modules.
2011-05-05 23:07:37 +02:00
Andy Wingo
f3a9a51d3e MV truncation in the boot evaluator
* libguile/eval.c (truncate_values): New helper.
  (EVAL1): New macro, does an eval then truncates the values.
  (eval, prepare_boot_closure_env_for_apply)
  (prepare_boot_closure_env_for_eval): Use EVAL1 in appropriate places
  to get multiple-values truncation even here in the boot evaluator.

eval.c fixen
2011-04-29 11:14:54 +02:00
Andy Wingo
572eef50c2 fix prompt and abort with the boot evaluator
* libguile/control.h:
* libguile/control.c (scm_i_prompt_pop_abort_args_x): Take a VM instead
  of a prompt, given that it's the VM's registers that record the abort
  arguments, not the prompt registers (which actually point right below
  the abort values).

* libguile/eval.c (eval):
* libguile/throw.c (pre_init_catch): Pass the vm instead of a prompt.
2011-03-29 17:41:31 +02:00
Andy Wingo
f32e67be0b add scm_call_{5,6}
* libguile/eval.h:
* libguile/eval.c (scm_call_5, scm_call_6): New scm_call functions; why
  not.
2011-03-08 21:02:36 +01:00
Andy Wingo
b6b84131cd remove obsolete comments
* libguile/eval.c (scm_nconc2last):
* libguile/strports.c (scm_c_read_string): Remove some obsolete
  comments.
2011-03-05 21:48:47 +01:00
Andy Wingo
7112a34d56 volatile locals in bootstrap evaluator
* libguile/eval.c (eval): For SCM_M_PROMPT, mark the locals needed after
  a longjmp as volatile.  Perhaps related to bug 32340.
2011-02-10 10:40:57 +01:00
Andy Wingo
4a655e50a3 use scm_from_latin1_symboln for string literals and load-symbol
* 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.
2011-01-07 09:18:41 -08:00
Andy Wingo
3d27ef4bd3 fix a number of assumptions that a pointer could fit into a long
* libguile/debug.c:
* libguile/eval.c:
* libguile/frames.c:
* libguile/objcodes.c:
* libguile/print.c:
* libguile/programs.c:
* libguile/read.c:
* libguile/struct.c:
* libguile/vm.c: Fix a number of instances in which we assumed we could
  fit a pointer into a long.
2010-11-19 15:22:43 +01:00
Andy Wingo
ab9c9100d2 scm_debug_opts to debug.c, backtrace on by default, scm_*_opts internal linkage
* libguile/eval.c:
* libguile/debug.c (scm_debug_opts): Move here, from eval.c. Change
  SCM_BACKTRACE_P to 1, initially.

* libguile/private-options.h: Make all options vars private.
2010-10-01 13:11:51 +02:00
Andy Wingo
ea9f4f4b15 add call-with-vm; remove thread-vm bits; remove vm-apply; engines settable.
* libguile/vm.h (scm_c_vm_run): Make internal.
* libguile/vm.c (vm_default_engine): New static global variable.
  (make_vm): Set vp->engine based on
  (scm_vm_apply): Remove in favor of call-with-vm.
  (scm_thread_vm, scm_set_thread_vm_x): Remove these, as they did not
  have a well-defined meaning, and were dangerous to call on other
  threads.
  (scm_the_vm): Reinstate previous definition.
  (symbol_to_vm_engine, vm_engine_to_symbol)
  (vm_has_pending_computation): New helpers.
  (scm_vm_engine, scm_set_vm_engine_x, scm_c_set_vm_engine_x): New
  accessors for VM engines.
  (scm_c_set_default_vm_engine_x, scm_set_default_vm_engine_x): New
  setters for the default VM engine.
  (scm_call_with_vm): New function, applies a procedure to arguments in
  a context in which a given VM is current.

* libguile/eval.c (eval, scm_apply): VM dispatch goes through
  scm_call_with_vm.

* test-suite/tests/control.test ("the-vm"):
* module/system/vm/coverage.scm (with-code-coverage): Use call-with-vm.

* module/system/vm/vm.scm: Update exports.

* test-suite/vm/run-vm-tests.scm (run-vm-program):
* test-suite/tests/compiler.test ("current-reader"): Just rely on the
  result of make-program being an applicable.

* test-suite/tests/eval.test ("stack overflow"): Add a note that this
  test does not test what it should.
2010-09-27 21:12:29 +02:00
Andy Wingo
3932bdb3af remove a number of debug options
* libguile/private-options.h (SCM_BREAKPOINTS_P, SCM_TRACE_P)
  (SCM_REC_PROCNAMES_P, SCM_BACKTRACE_INDENT, SCM_N_FRAMES)
  (SCM_BACKTRACE_MAXDEPTH, SCM_DEVAL_P): Remove these internal names.

* libguile/eval.c (scm_debug_opts): Remove the corresponding debug
  options -- breakpoints, trace, procnames, indent, frames, maxdepth,
  and debug.

* libguile/debug.c (scm_debug_options): Remove SCM_N_FRAMES check.

* test-suite/lib.scm (with-debugging-evaluator*):
* module/scripts/summarize-guile-TODO.scm:
* module/statprof.scm (statprof-reset):
* module/ice-9/boot-9.scm (turn-on-debugging): Remove useless
  debug-enable 'debug calls.

* module/ice-9/deprecated.scm (debug-enable): As it seems that 'debug is
  a particulatly common option that we just removed, add a deprecation
  shim.

* doc/ref/api-options.texi (Debugger options): Update the set of debug
  options.
2010-09-24 20:57:01 +02:00
Andy Wingo
925c1bae1f remove evaluator-traps-interface
* libguile/debug.h:
* libguile/debug.c (scm_with_traps):
* libguile/eval.c (scm_evaluator_traps, scm_evaluator_trap_table):
  Remove these procedures. Note that scm_evaluator_traps was known in
  Scheme as `evaluator-traps-interface'.

* libguile/private-options.h (SCM_TRAPS_P, SCM_ENTER_FRAME_P)
  (SCM_APPLY_FRAME_P, SCM_EXIT_FRAME_P, SCM_ENTER_FRAME_HDLR)
  (SCM_APPLY_FRAME_HDLR, SCM_EXIT_FRAME_HDLR, SCM_MEMOIZE_P)
  (SCM_MEMOIZE_HDLR): Remove these private interfaces.

* module/ice-9/boot-9.scm (traps, trap-enable, trap-disable, trap-set!):
  Remove.

* module/ice-9/scm-style-repl.scm (error-catching-loop): Remove
  with-traps wrap.

* doc/ref/api-options.texi (Low level options interfaces):
  (User level options interfaces, Evaluator trap options)
* doc/ref/api-evaluation.texi (Evaluator Behavior): Remove references to
  the evaluator traps interface.
2010-09-24 18:44:21 +02:00
Andy Wingo
3b494f511a remove eval-options
* libguile/eval.c:
* libguile/private-options.h (scm_eval_opts, scm_eval_options_interface)
  (SCM_EVAL_STACK): Remove these private interfaces.

* module/ice-9/boot-9.scm (eval-options, eval-enable, eval-disable)
  (eval-set!): Remove these procedures.

* doc/ref/api-evaluation.texi:
* doc/ref/api-options.texi: Remove references to eval options.
2010-09-24 18:11:27 +02:00
Andy Wingo
8cbcaaa0ae remove srcprop.[ch] things that have to do with breakpoints
* libguile/eval.c: Mark "breakpoints", "trace", and "procnames" debug
  options as obsolete. There is lots of work left to do here, though.

* libguile/srcprop.h (scm_sym_breakpoint)
  (scm_c_source_property_breakpoint_p, SRCBRKP): Remove these
  definitions, without replacements.

* libguile/srcprop.c: Remove all code that has to do with breakpoints.
2010-09-24 17:33:17 +02:00
Ludovic Courtès
93003b16b0 Assorted `syntax-check' fixes.
* doc/ref/Makefile.am ($(snarf_doc).am): Untabify.

* libguile/eval.c: Remove unnecessary <assert.h> inclusion.

* .x-sc_m4_quote_check: Update.

* libguile/error.c (scm_error_scm): Use `EXIT_FAILURE' instead of 1.
* libguile/init.c (fixconfig, scm_boot_guile): Likewise.
* libguile/null-threads.h (scm_i_pthread_exit): Likewise.
* libguile/script.c (scm_compile_shell_switches): Likewise.
* test-suite/standalone/test-conversion.c: Likewise.
* test-suite/standalone/test-list.c: Likewise.
* test-suite/standalone/test-unwind.c: Likewise.

* libguile/async.c: Remove unnecessary inclusion of <signal.h>.

* NEWS: "filesystem" -> "file system".
* doc/ref/r6rs.texi: Ditto.

* cfg.mk (local-checks-to-skip): New variable.

* .x-sc_m4_quote_check, .x-sc_obsolete_symbols, .x-sc_program_name,
  .x-sc_prohibit_atoi_atof, .x-sc_prohibit_magic_number_exit: New
  files.

* .gitignore: Update.
2010-08-27 18:59:42 +02:00
Andy Wingo
a310a1d12e primitive-eval takes expanded, not memoized, source
* 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-20 12:25:52 +02:00
Andy Wingo
dc3e203e07 separate boot expansion from memoization
* 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-19 22:51:31 +02:00
Andy Wingo
7572ee5261 evaluator support for case-lambda
* 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-14 00:28:39 +02:00
Andy Wingo
d8a071fc4e primitive support for lambda*
* 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-14 00:28:32 +02:00
Andy Wingo
8f9c5b589d change to format of memoization lambda expressions
* 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-13 23:37:15 +02:00
Andy Wingo
cc00f44743 scm_badargsp is deprecated
* libguile/eval.h:
* libguile/eval.c:
* libguile/deprecated.h
* libguile/deprecated.c (scm_badargsp): Deprecate scm_badargsp.
2010-05-13 23:37:15 +02:00
Andy Wingo
4f692ace90 macro expanders return memoized expressions
* 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.
2010-05-07 22:22:19 +02:00
Andy Wingo
cd038da546 remove libguile/lang.h, deprecate %nil (in favor of #nil)
* libguile/Makefile.am:
* libguile/init.c:
* libguile/lang.c:
* libguile/lang.h: Remove lang.c and lang.h.

* libguile/pairs.h (SCM_NIL_P, SCM_NULL_OR_NIL_P): Moved here.

* module/ice-9/deprecated.scm (%nil): %nil definition moved here.

* libguile/alist.c:
* libguile/async.c:
* libguile/backtrace.c:
* libguile/boolean.c:
* libguile/dynl.c:
* libguile/eval.c:
* libguile/filesys.c:
* libguile/fluids.c:
* libguile/list.c:
* libguile/load.c:
* libguile/options.c:
* libguile/posix.c:
* libguile/print.c:
* libguile/promises.c:
* libguile/sort.c:
* libguile/throw.c:
* libguile/trees.c:
* libguile/vectors.c:
* libguile/vm.c:
* libguile/weaks.c:
* srfi/srfi-1.c: <libguile/lang.h> references removed.
2010-04-09 14:26:31 +02:00
Ludovic Courtès
e2cf8eb921 Don't gratuitously over-engineer things...
* libguile/eval.c (eval)[SCM_M_CALL]: Always use `alloca' for ARGV.
2010-03-05 09:49:04 +01:00
Ludovic Courtès
b7ecadca7b Slightly optimize the memoizer, bootstrap evaluator, and `(ice-9 eval)'.
* libguile/eval.c (CAR, CDR, CAAR, CADR, CDAR, CDDR, CADDR, CDDDR): Use
  the macro variants, not the functions.
  (eval)[SCM_M_CALL]: When invoking a VM program, accumulate its
  arguments on the stack rather than on the heap.

* libguile/memoize.c (CAR, CDR, CAAR, CADR, CDAR, CDDR, CADDR, CDDDR,
  CADDR): Use the macro variants, not the functions.
  (scm_memoized_expression_typecode): Use `SCM_I_MAKINUM' instead of
  `scm_from_uint16'.
2010-03-05 00:36:47 +01:00
Andy Wingo
adbdfd6d24 rewinding prompts works
* libguile/control.h (SCM_PROMPT_HANDLER): Remove, it was unused.
  (SCM_PROMPT_DYNWINDS): Rename from SCM_PROMPT_DYNENV.

* libguile/control.c: (scm_c_make_prompt): Take another arg, the winds
  that are to be in place for the prompt. Fix allocation to be 4 words
  instead of 5 (the handler was never used).

* libguile/eval.c (eval):
* libguile/throw.c (pre_init_catch): Adapt to scm_c_make_prompt change.

* libguile/vm-i-system.c (partial-cont-call): Grovel the new elements of
  the wind list in order to call setjmp() on the new prompts. Pass
  cookie to vm_reinstate_partial_continuation.
  (prompt): Adapt to scm_c_make_prompt change.

* libguile/vm.c (vm_reinstate_partial_continuation): Take a cookie arg,
  used when winding captured prompts onto the stack. Winding a prompt
  implies making a new prompt, actually -- with new registers, a new
  jump buffer, new winds, etc.

* test-suite/tests/control.test ("rewinding prompts"): Add a test for
  rewinding prompts.
2010-02-26 13:05:25 +01:00
Andy Wingo
d296431516 fix a prompt bug
* libguile/control.h:
* libguile/control.c (scm_c_make_prompt): Instead of taking a VM arg,
  take the registers directly.
  (scm_c_abort): Declare as returning void. In fact it will never
  return.

* libguile/eval.c (eval):
* libguile/throw.c (pre_init_catch): Adapt to prompt API change.

* libguile/vm-i-system.c (prompt): Pass the abort ip as the ip to
  scm_c_make_prompt. This fixes a bug in which we used the "offset"
  local var, but it wasn't guaranteed to be around after a longjmp.
2010-02-26 11:05:44 +01:00
Andy Wingo
b8af64db76 simplify handling of nonlocal prompt returns from c
* libguile/control.h:
* libguile/control.c (scm_i_prompt_pop_abort_args_x): New helper.

* libguile/eval.c (eval): Use the new helper.
2010-02-25 20:59:55 +01:00
Andy Wingo
2d026f04cc abort always dispatches to VM bytecode, to detect same-invocation aborts
* 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.
2010-02-22 21:54:06 +01:00
Andy Wingo
747022e4cb 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.
2010-02-19 22:44:24 +01:00
Andy Wingo
bb0229b51d 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.
2010-02-18 22:15:43 +01:00
Andy Wingo
f3a8d1b745 eval.c tweaks
* libguile/eval.c (eval): Fix a couple of uses of scm_cdr that should
  use CDR.
2010-02-18 22:15:43 +01:00
Andy Wingo
d69531e213 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.
2010-02-18 22:12:55 +01:00
Andy Wingo
997659f898 make scm_make_continuation internal
* libguile/continuations.h:
* libguile/continuations.c (scm_i_make_continuation): Change from
  scm_make_continuation, and make internal.

* libguile/vm-i-system.c (call/cc, tail-call/cc): Adapt callers.

* test-suite/standalone/test-unwind.c (check_cont_body): Adapt a test.

* doc/ref/api-control.texi (Continuations): Update docs.
2010-02-08 13:35:06 +01:00
Andy Wingo
babfc7b2c3 eval.c uses scm_i_call_with_current_continuation
* libguile/continuations.h
* libguile/continuations.c (scm_i_call_with_current_continuation): New
  internal function. Not exported because I'm not sure whether or not
  this should have a continuation barrier in the future. Uses a
  hand-coded VM procedure.

* libguile/eval.c (eval): Use scm_i_call_with_current_continuation.
2010-02-08 13:34:26 +01:00
Andy Wingo
86fd6dff2a add scm_call_n, scm_c_run_hookn
* libguile/eval.h:
* libguile/eval.c (scm_call_n): New function, applies a function to an
  array of args.

* libguile/hooks.h:
* libguile/hooks.c (scm_c_run_hookn): New function, runs a hook with an
  array of args.
2009-12-21 21:06:27 +01:00
Ludovic Courtès
bc4adf1739 Remove unneeded #include <assert.h>.
* libguile/backtrace.c, libguile/eval.c, libguile/gc.c,
  libguile/goops.c, libguile/memoize.c, libguile/threads.c,
  libguile/uniform.c, libguile/vm.c,
  test-suite/standalone/test-conversion.c,
  test-suite/standalone/test-list.c: Don't include <assert.h>.
2009-12-15 20:20:38 +01:00
Andy Wingo
9331f91cc4 primitive-eval passes first N args on stack directly, not via apply
* 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.
2009-12-13 17:19:59 +01:00
Andy Wingo
e7efe8e793 decruftify scm_sys_protects
* libguile/root.h
* libguile/root.c (scm_sys_protects): It used to be that for some reason
  we'd define a special array of "protected" values. This was a little
  silly, always, but with the BDW GC it's completely unnecessary. Also
  many of these variables were unused, and none of them were good API.
  So remove this array, and either eliminate, make static, or make
  internal the various values.

* libguile/snarf.h: No need to generate calls to scm_permanent_object.

* guile-readline/readline.c (scm_init_readline): No need to call
  scm_permanent_object.

* libguile/array-map.c (ramap, rafe): Remove the dubious nullvect
  optimizations.

* libguile/async.c (scm_init_async): No need to init scm_asyncs, it is
  no more.

* libguile/eval.c (scm_init_eval): No need to init scm_listofnull, it is
  no more.

* libguile/gc.c: Make scm_protects a static var.
  (scm_storage_prehistory): Change the sanity check to use the address
  of protects.
  (scm_init_gc_protect_object): No need to clear the scm_sys_protects,
  as it is no more.

* libguile/keywords.c: Make the keyword obarray a static var.
* libguile/numbers.c: Make flo0 a static var.
* libguile/objprop.c: Make object_whash a static var.
* libguile/properties.c: Make properties_whash a static var.

* libguile/srcprop.h:
* libguile/srcprop.c: Make scm_source_whash a global with internal
  linkage.

* libguile/strings.h:
* libguile/strings.c: Make scm_nullstr a global with internal linkage.

* libguile/vectors.c (scm_init_vectors): No need to init scm_nullvect,
  it's unused.
2009-12-05 12:38:43 +01:00
Andy Wingo
f39448c5a3 remove a bunch of needless scm_permanent_object calls
* libguile/array-handle.c:
* libguile/bytevectors.c:
* libguile/deprecated.c:
* libguile/eval.c:
* libguile/feature.c:
* libguile/filesys.c:
* libguile/gc.c:
* libguile/gdbint.c:
* libguile/goops.c:
* libguile/instructions.c:
* libguile/load.c:
* libguile/modules.c:
* libguile/numbers.c:
* libguile/options.c:
* libguile/ports.c:
* libguile/scmsigs.c:
* libguile/srcprop.c:
* libguile/srfi-4.c:
* libguile/stacks.c:
* libguile/threads.c:
* libguile/vm.c: Remove calls to scm_permanent_object, as they are no
  longer needed with the BDW GC.
2009-12-05 11:32:50 +01:00
Andy Wingo
314b87163e eval.c closures are now applicable smobs, not tc3s
* libguile/debug.c (scm_procedure_name): Remove a SCM_CLOSUREP case and
  some dead code.
  (scm_procedure_module): Remove. This was introduced a few months ago
  for the hygienic expander, but now it is no longer needed, as the
  expander keeps track of this information itself.

* libguile/debug.h: Remove scm_procedure_module.

* libguile/eval.c: Instead of using tc3 closures, define a "boot
  closure" applicable smob type, and represent closures with that. The
  advantage is that after eval.scm is compiled, boot closures take up no
  address space (besides a smob number) in the runtime, and require no
  special cases in procedure dispatch.

* libguile/eval.h: Remove the internal functions scm_i_call_closure_0
  and scm_closure_apply, and the public function scm_closure.

* libguile/gc.c (scm_storage_prehistory): No tc3_closure displacement
  registration.
  (scm_i_tag_name): Remove closure case, and a dead cclo case.

* libguile/vm.c (apply_foreign):
* libguile/print.c (iprin1):
* libguile/procs.c (scm_procedure_p, scm_procedure_documentation);
* libguile/evalext.c (scm_self_evaluating_p):
* libguile/goops.c (scm_class_of): Remove tc3_closure/tcs_closure cases.
* libguile/hash.c (scm_hasher):

* libguile/hooks.c (scm_add_hook_x): Use new scm_i_procedure_arity.

* libguile/macros.c (macro_print): Print all macros using the same code.
  (scm_macro_transformer): Return any procedure, not just programs.

* libguile/procprop.h:
* libguile/procprop.c (scm_i_procedure_arity): Instead of returning a
  list that the caller has to parse, have the same prototype as
  scm_i_program_arity. An incompatible change, but it's an internal
  function anyway.
  (scm_procedure_properties, scm_set_procedure_properties)
  (scm_procedure_property, scm_set_procedure_property): Remove closure
  cases, and use scm_i_program_arity for arity.

* libguile/procs.h (SCM_CLOSUREP, SCM_CLOSCAR, SCM_CODE)
  (SCM_CLOSURE_NUM_REQUIRED_ARGS, SCM_CLOSURE_HAS_REST_ARGS)
  (SCM_CLOSURE_BODY, SCM_PROCPROPS, SCM_SETPROCPROPS, SCM_ENV)
  (SCM_TOP_LEVEL): Remove these macros that pertain to boot closures
  only. Only eval.c should know abut boot closures.
* libguile/procs.c (scm_closure_p): Remove this function. There is a
  simple stub in deprecated.scm now.
  (scm_thunk_p): Use scm_i_program_arity.
* libguile/tags.h (scm_tc3_closure): Remove. Yay, another tc3 to play
  with!
  (scm_tcs_closures): Remove.

* libguile/validate.h (SCM_VALIDATE_CLOSURE): Remove.

* module/ice-9/deprecated.scm (closure?): Add stub.

* module/ice-9/documentation.scm (object-documentation)
* module/ice-9/session.scm (help-doc, arity)
* module/oop/goops.scm (compute-getters-n-setters)
* module/oop/goops/describe.scm (describe)
* module/system/repl/describe.scm (display-object, display-type):
  Remove calls to closure?.
2009-12-04 19:20:11 +01:00
Andy Wingo
bf5a05f2a0 speed up scm_call_N for non-programs
* libguile/eval.c (scm_call_0, scm_call_1, scm_call_2, scm_call_3): All
  of these should dispatch through the VM, without consing.
2009-12-03 15:58:43 +01:00
Andy Wingo
df9ca8d8b2 all subrs are gsubrs
* libguile/gsubr.c (create_gsubr, create_gsubr_with_generic): Always
  create gsubrs -- never the specialized tc7 types. Allow gsubrs to have
  generics, there doesn't seem to be any reason not to.

* libguile/macros.c (scm_make_synt):
* libguile/values.c (scm_init_values):
* libguile/eval.c (scm_init_eval):
* libguile/gc.c (scm_init_gc): Use scm_c_define_gsubr instead of
  scm_c_define_subr.

* libguile/goops.c (scm_class_of): Allow gsubrs to be primitive
  generics.
2009-12-03 14:54:15 +01:00
Andy Wingo
5f1611640a really boot primitive-eval from scheme.
* 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.
2009-12-03 00:00:38 +01:00
Andy Wingo
67e2d80a6a apply goes to the vm, not the interpreter
* libguile/eval.c (eval): Call scm_vm_apply instead of apply.
  (apply): Deleted, no longer referenced. Heh.
  (scm_apply): Call scm_vm_apply.

* libguile/init.c (scm_i_init_guile): Bootstrap the VM before the
  evaluator.

* libguile/vm.c (scm_vm_apply): Actually it's not necessary that the
  procedure is a program; so that's cool, relax the check.
2009-12-01 22:20:03 +01:00
Andy Wingo
23f276dea7 first step to make the vm stop calling the interpreter
* libguile/eval.h:
* libguile/eval.c (scm_closure_apply): New function, applies a closure.
  Won't be necessary in the future, but for now here it is, with
  internal linkage.

* libguile/gsubr.h:
* libguile/gsubr.c (scm_i_gsubr_apply_array): New function, applies a
  gsubr to an array of values, potentially extending that array for
  optional arguments and rest arguments and such.

* libguile/vm.c (apply_foreign): New function, applies a foreign
  function to arguments on the stack, in place.

* libguile/vm-i-system.c (call): Add a case for procedures-with-setters
  (will go away when they are applicable structs). Instead of calling
  the evaluator for foreign functions, call apply_foreign.
2009-12-01 21:59:42 +01:00
Andy Wingo
3149a5b60d 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.
2009-12-01 21:00:27 +01:00
Andy Wingo
7b89381965 promises are in their own file now
* libguile.h:
* libguile/Makefile.am:
* libguile/eval.c:
* libguile/eval.h:
* libguile/init.c:
* libguile/promises.c:
* libguile/promises.h: Split promises out into their own file.
2009-12-01 21:00:26 +01:00
Andy Wingo
b7742c6b71 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.
2009-12-01 21:00:26 +01:00