with-dynamic-state compiler and VM support

* libguile/dynstack.h (SCM_DYNSTACK_TYPE_DYNAMIC_STATE):
* libguile/dynstack.c (DYNAMIC_STATE_WORDS, DYNAMIC_STATE_STATE_BOX):
  (scm_dynstack_push_dynamic_state):
  (scm_dynstack_unwind_dynamic_state): New definitions.
  (scm_dynstack_unwind_1, scm_dynstack_wind_1): Add with-dynamic-state
  cases.
* libguile/memoize.c (push_dynamic_state, pop_dynamic_state)
  (do_push_dynamic_state, do_pop_dynamic_state): New definitions.
  (memoize, scm_init_memoize): Handle push-dynamic-state and
  pop-dynamic-state.
* libguile/vm-engine.c (push-dynamic-state, pop-dynamic-state): New
  opcodes.
* module/ice-9/boot-9.scm (with-dynamic-state): New definition in Scheme
  so that the push-dynamic-state and pop-dynamic-state always run in the
  VM.
* module/language/cps/compile-bytecode.scm (compile-function):
* module/language/cps/effects-analysis.scm:
* module/language/cps/types.scm:
* module/language/tree-il/effects.scm (make-effects-analyzer):
* module/language/tree-il/peval.scm (peval):
* module/language/tree-il/primitives.scm (*interesting-primitive-names*):
* module/system/vm/assembler.scm: Add support for with-dynamic-state to
  the compiler.
* test-suite/tests/fluids.test ("dynamic states"): Add basic tests.
* doc/ref/vm.texi (Dynamic Environment Instructions): Update.
This commit is contained in:
Andy Wingo 2016-12-05 22:48:49 +01:00
commit 7184c176b4
14 changed files with 260 additions and 5 deletions

View file

@ -1204,6 +1204,18 @@ Set the value of the fluid in @var{dst} to the value in @var{src}.
Write the value of the current thread to @var{dst}.
@end deftypefn
@deftypefn Instruction {} push-dynamic-state s24:@var{state}
Save the current set of fluid bindings on the dynamic stack and instate
the bindings from @var{state} instead. @xref{Fluids and Dynamic
States}.
@end deftypefn
@deftypefn Instruction {} pop-dynamic-state x24:@var{_}
Restore a saved set of fluid bindings from the dynamic stack.
@code{push-dynamic-state} should always be balanced with
@code{pop-dynamic-state}.
@end deftypefn
@node Miscellaneous Instructions
@subsubsection Miscellaneous Instructions
@ -1237,6 +1249,17 @@ Pop the stack pointer by @var{count} words, discarding any values that
were stored there.
@end deftypefn
@deftypefn Instruction {} handle-interrupts x24:@var{_}
Handle pending asynchronous interrupts (asyncs). @xref{Asyncs}. The
compiler inserts @code{handle-interrupts} instructions before any call,
return, or loop back-edge.
@end deftypefn
@deftypefn Instruction {} return-from-interrupt x24:@var{_}
A special instruction to return from a call and also pop off the stack
frame from the call. Used when returning from asynchronous interrupts.
@end deftypefn
@node Inlined Scheme Instructions
@subsubsection Inlined Scheme Instructions