bpt/guile.git
10 years agoCorrectness fix for vector constructor inlining.
Andy Wingo [Sun, 3 Nov 2013 11:28:47 +0000 (12:28 +0100)]
Correctness fix for vector constructor inlining.

* module/language/tree-il/compile-cps.scm (convert): Don't inline the
  vector constructor if any arg could capture the current continuation.

10 years agoEval evaluates initializers before creating environment ribs.
Andy Wingo [Sun, 3 Nov 2013 11:16:49 +0000 (12:16 +0100)]
Eval evaluates initializers before creating environment ribs.

* module/ice-9/eval.scm (let-env-evaluator, primitive-eval): Evaluate
  initializers of let expressions before creating the environment rib.
  This prevents call/cc-related shenanigans.

10 years ago"length" is an interesting primitive
Andy Wingo [Sun, 3 Nov 2013 11:15:09 +0000 (12:15 +0100)]
"length" is an interesting primitive

* module/language/tree-il/primitives.scm (*effect-free-primitives*):
  (*interesting-primitive-names*): Add "length", so that we can
  constant-fold it.

10 years agoRevert "Compile-time debugging"
Andy Wingo [Fri, 1 Nov 2013 18:43:45 +0000 (19:43 +0100)]
Revert "Compile-time debugging"

This reverts commit 6a37b7faaf150e9fb7945ef79969cb7671d17367.

10 years agoFix call/cc with the RTL VM
Andy Wingo [Fri, 1 Nov 2013 18:28:36 +0000 (19:28 +0100)]
Fix call/cc with the RTL VM

* libguile/vm.c (vm_return_to_continuation): The RTL VM saves the
  registers for the caller of call/cc, but the caller will expect values
  in the normal MV return location: above the frame.  Make it so, number
  four!

10 years agoFix order of evaluation in elisp lexer
Andy Wingo [Fri, 1 Nov 2013 17:23:51 +0000 (18:23 +0100)]
Fix order of evaluation in elisp lexer

* module/language/elisp/lexer.scm (lex): Use let*, to ensure that the
  port position is read before reading the next char.

10 years agoFix contification of non-recursive closures
Andy Wingo [Fri, 1 Nov 2013 17:22:58 +0000 (18:22 +0100)]
Fix contification of non-recursive closures

* module/language/cps/contification.scm (compute-contification): When
  eliding let-bound functions, also record the cont that declares the
  function.
  (apply-contification): Instead of reifying ($values ()) gotos instead
  of the elided function, inline the body that binds the function
  directly.  This ensures that the function gets contified in its own
  scope.

10 years agoRTL compilation sorts continuations topologically before visiting them
Andy Wingo [Fri, 1 Nov 2013 13:37:57 +0000 (14:37 +0100)]
RTL compilation sorts continuations topologically before visiting them

* module/language/cps/compile-rtl.scm (compile-fun): Rewrite to visit
  conts in reverse-post-order, which is a topological sort on the basic
  blocks.

* module/language/cps/slot-allocation.scm (allocate-slots): Expect a DFG
  as an argument.

10 years agoFailed match errors generate less code
Andy Wingo [Fri, 1 Nov 2013 12:37:27 +0000 (13:37 +0100)]
Failed match errors generate less code

* module/ice-9/match.upstream.scm (match-next): Call out to an external
  procedure on error, and use a begin instead of double-parens.  This
  results in less generated code.

10 years agoAdd compile-cps hack for vectors
Andy Wingo [Fri, 1 Nov 2013 07:51:52 +0000 (08:51 +0100)]
Add compile-cps hack for vectors

* module/language/tree-il/compile-cps.scm (convert): Add a special case
  for "vector" primcalls.  Boo!

10 years agoBetter range checks in the assembler
Andy Wingo [Thu, 31 Oct 2013 21:57:06 +0000 (22:57 +0100)]
Better range checks in the assembler

* module/system/vm/assembler.scm (pack-u8-u24, pack-u8-s24):
  (pack-u1-u7-u24, pack-u8-u12-u12, pack-u8-u8-u16, pack-u8-u8-u8-u8):
  Prevent adjacent fields from stompling each other.

10 years agoBe smarter about capturing the environment for memoized code
Andy Wingo [Thu, 31 Oct 2013 21:16:10 +0000 (22:16 +0100)]
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.

10 years agodefine! is an interesting primitive
Andy Wingo [Thu, 31 Oct 2013 19:39:22 +0000 (20:39 +0100)]
define! is an interesting primitive

* module/language/tree-il/primitives.scm (*interesting-primitive-names*):
  Add define!.

10 years agofix compilation of (let lp () (lp))
Andy Wingo [Thu, 31 Oct 2013 19:24:38 +0000 (20:24 +0100)]
fix compilation of (let lp () (lp))

* module/language/cps/dfg.scm (reverse-post-order): Add an optional
  "fold-all-conts" argument.
  (compute-live-variables): Take the function as an arg instead of the
  start continuation, and implement fold-all-conts so that nodes that
  never reach the tail also get liveness information.

10 years agoDFG: Export analyze-control-flow.
Andy Wingo [Thu, 31 Oct 2013 18:24:42 +0000 (19:24 +0100)]
DFG: Export analyze-control-flow.

* module/language/cps/dfg.scm ($cfa, $dominator-analysis): Remove
  dominator things from $cfa, to break out to separate structure.
  (cfa-k-idx, cfa-k-count, cfa-k-sym, cfa-predecessors): New public
  accessors.
  (analyze-control-flow): New public function.
  (analyze-dominators): Adapt.

10 years agostatic-patch! for pair and vector fields
Andy Wingo [Thu, 31 Oct 2013 18:21:31 +0000 (19:21 +0100)]
static-patch! for pair and vector fields

* module/system/vm/assembler.scm (intern-constant): Use static-patch!
  for fields.

10 years agoBetter REPL support for disassembling RTL images
Andy Wingo [Thu, 31 Oct 2013 13:18:25 +0000 (14:18 +0100)]
Better REPL support for disassembling RTL images

* module/system/repl/command.scm (load-image): New helper.
  (compile, disassemble): Handle bytevectors.

10 years agoDefault to compiling to RTL
Andy Wingo [Thu, 31 Oct 2013 13:17:30 +0000 (14:17 +0100)]
Default to compiling to RTL

* module/ice-9/eval-string.scm (eval-string)
* module/language/tree-il/spec.scm (tree-il)
* module/scripts/compile.scm (compile)
* module/system/base/compile.scm (compile-file, read-and-compile)
* module/system/repl/common.scm (repl-compile, repl-prepare-eval-thunk):
  Default to compiling to RTL.

* module/language/rtl/spec.scm (rtl->value): Add value compiler.

10 years agoAvoid calling procedure-name when doing a make-procedure-with-setter
Andy Wingo [Thu, 31 Oct 2013 11:52:23 +0000 (12:52 +0100)]
Avoid calling procedure-name when doing a make-procedure-with-setter

* libguile/procs.c (scm_make_procedure_with_setter): Don't set the name
  of the procedure.  Instead rely on procedure-name to look it up from
  the wrapped procedure as needed.
* libguile/procprop.c (scm_procedure_name): If there was no override and
  the procedure is a procedure-with-setter, recurse on the procedure.

10 years agoBetter aliased primcall compilation
Andy Wingo [Thu, 31 Oct 2013 11:06:06 +0000 (12:06 +0100)]
Better aliased primcall compilation

* libguile/vm-engine.c (define!): Rename from define.
* module/language/cps/arities.scm (fix-clause-arities): If a prim
  aliases an RTL instruction with a different name and we reify a
  primcall, reify the instruction name.
* module/language/cps/compile-rtl.scm (emit-rtl-sequence): Update
  emit-define! for new name.
* module/language/cps/primitives.scm (*rtl-instruction-aliases*): Add
  bytevector native accessors.

10 years agoBetter compiler support for bytevector ops
Andy Wingo [Thu, 31 Oct 2013 10:39:43 +0000 (11:39 +0100)]
Better compiler support for bytevector ops

* module/language/cps/compile-rtl.scm (emit-rtl-sequence): Add emitters
  for bytevector ops.  Add br-if-bytevector emitter.
* module/language/cps/primitives.scm (*branching-primcall-arities*):
  Mark bytevector? as a branching primitive.
* module/system/vm/assembler.scm (br-if-bytevector): New instruction
* module/system/vm/disassembler.scm (code-annotation): Add support for
  bytevector?.

10 years agoFix bytevector error messages.
Andy Wingo [Thu, 31 Oct 2013 10:30:53 +0000 (11:30 +0100)]
Fix bytevector error messages.

* libguile/vm-engine.c (BV_FIXABLE_INT_SET, BV_INT_SET):
  (BV_FLOAT_SET): Fix instruction names in error messages.

10 years agoSupport serialization of uniform vector literals
Andy Wingo [Wed, 30 Oct 2013 20:11:03 +0000 (21:11 +0100)]
Support serialization of uniform vector literals

* libguile/uniform.h:
* libguile/uniform.c (scm_uniform_vector_element_type_code): New
  interface, returns a type code as an integer.

* module/system/vm/assembler.scm (<uniform-vector-backing-store>)
  (simple-vector?, uniform-array?, statically-allocatable?)
  (intern-constant, link-data, link-constants): Support uniform arrays,
  and punt on vectors aren't contiguous from 0.  Support for general
  arrays will come later.

* test-suite/tests/rtl.test ("load-constant"): Add tests.

10 years agoCompile-time debugging
Andy Wingo [Sun, 27 Oct 2013 19:10:59 +0000 (20:10 +0100)]
Compile-time debugging

* module/language/cps/compile-rtl.scm:
* module/language/cps/contification.scm: Add some compile-time
  printouts.  Will be removed later.

10 years agoDFG: $block no longer stores control-flow analysis
Andy Wingo [Thu, 31 Oct 2013 09:49:38 +0000 (10:49 +0100)]
DFG: $block no longer stores control-flow analysis

* module/language/cps/dfg.scm ($block): Remove dominator-related things
  from $block.
  (reverse-post-order, convert-predecessors): Be more abstract, taking
  arbitrary identifiers for nodes instead of assuming the nodes are
  continuation names.
  (make-block-mapping): New helper.
  ($cfa): New data type, for dominator and loop analysis.  Not yet
  public.
  (analyze-control-flow): Rewrite to only compute the dominator tree in
  one direction, but take that direction as an argument.  To be public
  once there is some code that uses it.
  ($dfa): Refactor function fields to be hash tables.
  (dfa-k-idx, dfa-var-idx): Adapt to refactor.
  (compute-live-variables): Adapt to refactor.

10 years agostatic-patch! replaces link-procedure!
Andy Wingo [Thu, 31 Oct 2013 08:44:59 +0000 (09:44 +0100)]
static-patch! replaces link-procedure!

* libguile/vm-engine.c (static-patch!): Replace link-procedure! with
  this more versatile primitive.
* module/system/vm/assembler.scm (intern-constant): Emit static-patch!
  for static procedures and for strings.
* module/system/vm/disassembler.scm (code-annotation): Remove annotation
  for link-procedure!.  There can be no annotation for static-patch!, as
  neither operand is guaranteed to be a SCM value.

10 years agoFix primitive reification for class-of, bytevector-u8-ref, etc
Andy Wingo [Wed, 30 Oct 2013 20:08:38 +0000 (21:08 +0100)]
Fix primitive reification for class-of, bytevector-u8-ref, etc

* module/language/cps/reify-primitives.scm (primitive-module): Not all
  primitives are bound in (guile).

10 years agoDFG: Disable control-flow analysis.
Andy Wingo [Tue, 29 Oct 2013 22:06:07 +0000 (23:06 +0100)]
DFG: Disable control-flow analysis.

* module/language/cps/dfg.scm (visit-fun): Disable control-flow analysis
  for now, as it is not used.

10 years agoAdd "pop" field to $prompt
Andy Wingo [Tue, 29 Oct 2013 21:57:29 +0000 (22:57 +0100)]
Add "pop" field to $prompt

* module/language/cps.scm ($prompt): Add a "pop" field, indicating the
  continuation at which this prompt is popped.  The body of the prompt
  is dominated by the prompt, and post-dominated by the pop.  Adapt all
  builders and users.

* module/language/cps/closure-conversion.scm:
* module/language/cps/compile-rtl.scm:
* module/language/cps/slot-allocation.scm:
* module/language/cps/verify.scm:
* module/language/tree-il/compile-cps.scm: Adapt.

* module/language/cps/dfg.scm (visit-fun): Add an arc from the pop to
  the handler, to keep handler variables alive through the prompt body.

10 years agoDWARF return arity fixen
Andy Wingo [Sun, 27 Oct 2013 19:59:50 +0000 (20:59 +0100)]
DWARF return arity fixen

* module/system/vm/dwarf.scm (read-die-abbrev): Fix return arity.
  (read-compilation-unit): Fix return arity of read-die.

10 years agoDynamic-wind doesn't call thunk? on the out-guard.
Andy Wingo [Sun, 27 Oct 2013 10:40:55 +0000 (11:40 +0100)]
Dynamic-wind doesn't call thunk? on the out-guard.

* module/ice-9/boot-9.scm (dynamic-wind): Remove the thunk? check of the
  out-guard.

10 years agoWalk the stack to determine extent of partial continuation
Andy Wingo [Wed, 23 Oct 2013 15:18:24 +0000 (17:18 +0200)]
Walk the stack to determine extent of partial continuation

* libguile/control.c (reify_partial_continuation): Walk the stack to
  determine the bottom of the captured stack.

10 years agoResumable partial continuations in the RTL VM
Andy Wingo [Sun, 20 Oct 2013 16:09:52 +0000 (18:09 +0200)]
Resumable partial continuations in the RTL VM

* libguile/vm-engine.c (receive-values): Bugfix for the case where we
  want an exact number of values.
  (abort): Advance the IP before capturing.  The captured SP is fp - 1,
  not fp.

* libguile/vm.c (vm_reinstate_partial_continuation): Don't push on a
  number-of-values marker.

10 years agoVM has "builtins": primitives addressable by emitted RTL code
Andy Wingo [Sun, 20 Oct 2013 13:49:22 +0000 (15:49 +0200)]
VM has "builtins": primitives addressable by emitted RTL code

* libguile/Makefile.am:
* libguile/vm-builtins.h: New header, declaring stubs needed by the
  compiler like values, apply, and abort-to-prompt.

* libguile/vm.c: Adapt the apply and values stubs to conform to a
  standard interface.  Add an abort-to-prompt stub.  Add call/cc and
  call-with-values stubs.
  (scm_vm_builtin_ref): New helper, for the builtin-ref opcode.
  (scm_vm_builtin_name_to_index)
  (scm_vm_builtin_index_to_name): New helpers, for the compiler and
  disassembler, respectively.
  (scm_init_vm_builtins, scm_bootstrap_vm): Allow the compiler helpers
  to be loaded later into a module.
* module/language/rtl.scm: Export builtin-index->name and
  builtin-name->index.

* libguile/vm-engine.c (RETURN_VALUE_LIST): Update to use new names of
  "apply" and "values".
  (tail-call/shuffle): New opcode.
  (abort): Update to be a tail VM op, and reorder and renumber other
  ops.
  (builtin-ref): New opcode.

* libguile/continuations.h:
* libguile/continuations.c (scm_i_call_with_current_continuation):
  Move this to vm.[ch], implemented as a builtin.

* module/language/tree-il/compile-cps.scm (convert): Convert to
  'abort-to-prompt calls, possibly with 'apply, effectively undoing the
  tree-il transformation.

* module/language/cps/reify-primitives.scm (builtin-ref): New helper.
  (reify-primitives): Convert builtin primitives to builtin-ref.

* module/language/cps/dfg.scm (constant-needs-allocation?):
* module/language/cps/compile-rtl.scm (emit-rtl-sequence): Add support
  for compiling builtin-ref.

* module/system/vm/disassembler.scm (code-annotation): Add annotation
  for builtin-ref.

10 years agoPartial continuations are RTL stubs
Andy Wingo [Fri, 18 Oct 2013 17:33:50 +0000 (19:33 +0200)]
Partial continuations are RTL stubs

* libguile/control.c: Implement partial continuations as RTL programs.

* libguile/programs.c (scm_i_rtl_program_minimum_arity): Add partial
  continuation case.

* libguile/vm-engine.c (compose-continuation): Fix to look for vm_cont
  from the free variables.

* libguile/vm-i-system.c (abort): Poison continuations captured in the
  stack VM, as the can't be rewound by the RTL stubs.

10 years agoFix toplevel-ref with named modules before boot in stack VM
Andy Wingo [Sun, 27 Oct 2013 10:25:18 +0000 (11:25 +0100)]
Fix toplevel-ref with named modules before boot in stack VM

* libguile/vm.c (resolve_variable): Fix, as in
  e23f9e4423bbbe8521d13e1c9a223612a5e86762.

10 years agoMemoized expressions are pairs, not SMOBs
Andy Wingo [Sun, 27 Oct 2013 08:52:39 +0000 (09:52 +0100)]
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!

10 years agoTree-IL->GLIL: Fix primitive-ref reification bug
Andy Wingo [Sun, 27 Oct 2013 08:14:04 +0000 (09:14 +0100)]
Tree-IL->GLIL: Fix primitive-ref reification bug

* module/language/tree-il/compile-glil.scm (flatten-lambda-case): Fix a
  bug whereby a primitive that is present in the compilation module but
  not at runtime was getting compiled as a toplevel-ref.  This was
  causing current-module to fail to resolve in R6RS modules.

10 years agoMark current-module as an interesting primitive
Andy Wingo [Sat, 26 Oct 2013 20:54:29 +0000 (22:54 +0200)]
Mark current-module as an interesting primitive

* module/language/tree-il/primitives.scm (*interesting-primitive-names*):
  Add current-module, to allow RTL compilation.

10 years agoNew pass: elide-values
Andy Wingo [Sat, 26 Oct 2013 20:30:54 +0000 (22:30 +0200)]
New pass: elide-values

* module/Makefile.am:
* module/language/cps/elide-values.scm (elide-values): New pass.

* module/language/cps/compile-rtl.scm (optimize): Call the new pass.

10 years agoAdd make-vector, constant-make-vector instructions
Andy Wingo [Sat, 26 Oct 2013 20:06:01 +0000 (22:06 +0200)]
Add make-vector, constant-make-vector instructions

* libguile/vm-engine.c (rtl_vm_engine): Add make-vector and
  constant-make-vector instructions and renumber.

* module/language/cps/compile-rtl.scm (emit-rtl-sequence): Emit
  constant-make-vector and make-vector as appropriate.

* module/language/cps/dfg.scm (constant-needs-allocation?): In some
  cases, make-vector doesn't need to allocate its index.

*  module/language/tree-il/primitives.scm
   (*interesting-primitive-names*, *primitive-constructors*): Add
   make-vector.

10 years agoEmit constant-vector-ref, constant-vector-set! for known small indices
Andy Wingo [Sat, 26 Oct 2013 19:30:37 +0000 (21:30 +0200)]
Emit constant-vector-ref, constant-vector-set! for known small indices

* libguile/vm-engine.c (rtl_vm_engine): Add constant-vector-set!
  instruction and renumber.

* module/language/cps/compile-rtl.scm (emit-rtl-sequence): Emit
  constant-vector-ref and constant-vector-set! as appropriate.

* module/language/cps/dfg.scm (constant-needs-allocation?): In some
  cases, vector-ref and vector-set! don't need to allocate their index.

10 years agoNew pass: inline-constructors
Andy Wingo [Sat, 26 Oct 2013 19:07:27 +0000 (21:07 +0200)]
New pass: inline-constructors

* module/Makefile.am:
* module/language/cps/constructors.scm (inline-constructors): New pass.

* module/language/cps/compile-rtl.scm (optimize): Call the new pass.

* module/language/tree-il/compile-cps.scm (convert): Don't handle "list"
  specially here.

10 years agoCompile variable-ref, variable-set!
Andy Wingo [Sat, 26 Oct 2013 13:40:49 +0000 (15:40 +0200)]
Compile variable-ref, variable-set!

* libguile/vm-engine (box-ref, box-set!): Instead of aborting if a box
  isn't a var, call out to vm_error_not_a_variable.  This makes these
  instructions equivalent to variable-ref/variable-set!.
  (vector-set!): Rename from vector-set.

* module/language/cps/compile-rtl.scm (emit-rtl-sequence): Add
  variable-set! case, and adapt vector-set!.

* module/language/cps/primitives.scm (*rtl-instruction-aliases*): Add
  variable-ref / variable-set! aliases to box-ref / box-set!.

10 years agoRecognize tree-il variable? primitive
Andy Wingo [Sat, 26 Oct 2013 13:25:49 +0000 (15:25 +0200)]
Recognize tree-il variable? primitive

* module/language/tree-il/primitives.scm (*interesting-primitive-names*)
  (*effect-free-primitives*, *effect+exception-free-primitives*): Add
  variable?.  Fix nil? spelling.

10 years agoRTL compiler: Compile TC7 branches.
Andy Wingo [Sat, 26 Oct 2013 13:16:09 +0000 (15:16 +0200)]
RTL compiler: Compile TC7 branches.

* module/system/vm/assembler.scm:
* module/system/vm/disassembler.scm (code-annotation):
* module/language/cps/primitives.scm (*branching-primcall-arities*):
* module/language/cps/compile-rtl.scm (emit-rtl-sequence): Add support
  for compiling symbol?, variable?, vector?, and string? branches.

10 years agoFix primcall return arities
Andy Wingo [Wed, 23 Oct 2013 13:07:34 +0000 (15:07 +0200)]
Fix primcall return arities

* module/language/cps/arities.scm (fix-clause-arities): Primcalls of
  known arity that continue to ktrunc should, if their return arity does
  not match the ktrunc, adapt via a call to `values'.  This call may
  later get removed.

10 years agoRTL compiler: Compile `wind' primcalls
Andy Wingo [Wed, 23 Oct 2013 08:35:04 +0000 (10:35 +0200)]
RTL compiler: Compile `wind' primcalls

* module/language/cps/compile-rtl.scm (emit-rtl-sequence): Add handler
  for `wind'.

10 years agoRTL VM: Fix fluid-ref local addressing.
Andy Wingo [Wed, 23 Oct 2013 08:05:28 +0000 (10:05 +0200)]
RTL VM: Fix fluid-ref local addressing.

* libguile/vm-engine.c (push-fluid): Fix variable addressing.

10 years agoRTL VM: Fix variable lookup before modules boot
Andy Wingo [Wed, 23 Oct 2013 08:03:17 +0000 (10:03 +0200)]
RTL VM: Fix variable lookup before modules boot

* libguile/vm-engine.c (toplevel-box, module-box): Handle the case where
  the module system isn't booted yet.

10 years agoAdd stringbuf printer
Andy Wingo [Thu, 24 Oct 2013 08:19:07 +0000 (10:19 +0200)]
Add stringbuf printer

* libguile/strings.h:
* libguile/strings.c (scm_i_print_stringbuf):
* libguile/print.c (iprin1): Add a printer for stringbufs.  The
  disassembler can print a stringbuf.

10 years agoPeval: Fold `thunk?' in more cases.
Andy Wingo [Wed, 23 Oct 2013 08:35:30 +0000 (10:35 +0200)]
Peval: Fold `thunk?' in more cases.

* module/language/tree-il/peval.scm (peval): Better folding of the
  `thunk?' predicate.

10 years agoSetting procedure properties does not cause metadata lookup
Andy Wingo [Sat, 26 Oct 2013 11:12:25 +0000 (13:12 +0200)]
Setting procedure properties does not cause metadata lookup

* libguile/procprop.c (scm_procedure_properties, scm_procedure_property)
  (scm_set_procedure_properties_x, scm_set_procedure_property_x)
  (scm_procedure_name, scm_procedure_documentation): Rework to treat the
  overrides table as complementary to the RTL program properties.  In
  this way setting a procedure property doesn't require loading up
  the (system vm debug) module.

10 years agoEvaluator sets same procedure properties as compiler
Andy Wingo [Sat, 26 Oct 2013 11:10:43 +0000 (13:10 +0200)]
Evaluator sets same procedure properties as compiler

* 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.

10 years agoEvaluator uses two-dimensional environment
Andy Wingo [Fri, 25 Oct 2013 10:25:53 +0000 (12:25 +0200)]
Evaluator uses two-dimensional environment

* 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.

10 years agoAlways resolve-primitives in the root module.
Andy Wingo [Wed, 23 Oct 2013 14:57:14 +0000 (16:57 +0200)]
Always resolve-primitives in the root module.

* module/language/tree-il/primitives.scm (resolve-primitives): If we are
  compiling in the root module, ignore local definitions.

10 years agoRTL VM: Fix LOCAL_REF, LOCAL_SET for unsigned indices
Andy Wingo [Wed, 23 Oct 2013 13:06:24 +0000 (15:06 +0200)]
RTL VM: Fix LOCAL_REF, LOCAL_SET for unsigned indices

* libguile/vm-engine.c (LOCAL_REF, LOCAL_SET): Fix so to work with
  unsigned 0.  Previously subtracting 1 was making the index wrap
  around.

10 years agoOptimize closures with only required and rest arguments in eval
Andy Wingo [Wed, 23 Oct 2013 17:01:03 +0000 (19:01 +0200)]
Optimize closures with only required and rest arguments in eval

* module/ice-9/eval.scm: Pregenerate closures with rest arguments, as we
  do for fixed arguments.  This is important given the amount of (lambda
  args (apply foo args)) that we are doing lately.

10 years agoFix assembler for keyword args
Andy Wingo [Tue, 22 Oct 2013 20:31:26 +0000 (22:31 +0200)]
Fix assembler for keyword args

* module/system/vm/assembler.scm (begin-kw-arity, kw-prelude): Fix
  functions with keywords.

10 years agoCPS conversion doesn't automatically produce $values
Andy Wingo [Tue, 22 Oct 2013 20:30:54 +0000 (22:30 +0200)]
CPS conversion doesn't automatically produce $values

* module/language/tree-il/compile-cps.scm (convert): Don't convert
  values primcalls to $values, because we don't know that the
  continuation can accept that number of values.

10 years agoContify returns via calls to "values"
Andy Wingo [Tue, 22 Oct 2013 20:29:56 +0000 (22:29 +0200)]
Contify returns via calls to "values"

* module/language/cps/contification.scm: Returns from contified
  functions should primcall to 'values, as in general the return
  continuation is a multiple value context ($ktrunc or $ktail).  A later
  pass can elide the primcall if appropriate.

10 years agoCPS->RTL compiler: add push-fluid and pop-fluid
Andy Wingo [Mon, 21 Oct 2013 20:25:27 +0000 (22:25 +0200)]
CPS->RTL compiler: add push-fluid and pop-fluid

* module/language/cps/compile-rtl.scm (emit-rtl-sequence): Add cases for
  push-fluid and pop-fluid.

10 years agoDFG: Remove lift-definition!
Andy Wingo [Mon, 21 Oct 2013 20:24:54 +0000 (22:24 +0200)]
DFG: Remove lift-definition!

* module/language/cps/dfg.scm: Remove lift-definition!.

10 years agoFix contification bugs
Andy Wingo [Mon, 21 Oct 2013 20:24:18 +0000 (22:24 +0200)]
Fix contification bugs

* module/language/cps/contification.scm (compute-contification): Rewrite
  to avoid mutating the DFG and the function while we are rewriting.
  Instead we compute a contification, and if it is not empty, we apply
  it and loop.

10 years agoMore robust contification
Andy Wingo [Mon, 21 Oct 2013 14:59:42 +0000 (16:59 +0200)]
More robust contification

* module/language/cps/contification.scm (contify): It could be that
  visiting pending contifications could enqueue more contifications, so
  iterate to a fixed point.  Signal an error if there are any pending
  contifications at the end of an iteration.

10 years agoadd lookup-block-scope
Andy Wingo [Mon, 21 Oct 2013 14:32:36 +0000 (16:32 +0200)]
add lookup-block-scope

* module/language/cps/dfg.scm (lookup-block-scope): New interface.
  (visit-fun): Give a bit more info if link-blocks! fails.

10 years agoDFG fixup.
Andy Wingo [Mon, 21 Oct 2013 14:31:49 +0000 (16:31 +0200)]
DFG fixup.

* module/language/cps/dfg.scm: Remove dead-after-def? and
  dead-after-use? export.

10 years agoRTL slot allocator uses more precise, correct liveness information
Andy Wingo [Mon, 21 Oct 2013 13:45:19 +0000 (15:45 +0200)]
RTL slot allocator uses more precise, correct liveness information

* module/language/cps/dfg.scm (control-point?): New interface, replaces
  branch?.
  (dead-after-def?, dead-after-use?, dead-after-branch?): Remove these.
  The first one was fine; dead-after-use? was conservative but OK; but
  dead-after-branch? was totally bogus.  Instead we use precise liveness
  information in the allocator.

* module/language/cps/slot-allocation.scm ($allocation): Remove "def"
  and "dead" slots.  We'll communicate liveness information in some
  other way to the compiler.
  (allocate-slots): Rework to use precise liveness information.

10 years agoDFG: Add code to compute live variable sets.
Andy Wingo [Mon, 21 Oct 2013 09:51:51 +0000 (11:51 +0200)]
DFG: Add code to compute live variable sets.

* module/language/cps/dfg.scm (compute-live-variables)
  (compute-maximum-fixed-point, print-dfa): New code to compute live
  variable sets.

10 years agoDFG: Use maps have variable names
Andy Wingo [Mon, 21 Oct 2013 09:51:11 +0000 (11:51 +0200)]
DFG: Use maps have variable names

* module/language/cps/dfg.scm ($use-map): Add variable names to the use
  maps.
  (visit-fun, lookup-def, lookup-uses, constant-needs-allocation?)
  (variable-free-in?, dead-after-def?, dead-after-use?)
  (dead-after-branch?): Adapt to use-map change.

10 years agoContinuations are RTL stubs
Andy Wingo [Fri, 18 Oct 2013 16:44:11 +0000 (18:44 +0200)]
Continuations are RTL stubs

* libguile/continuations.h:
* libguile/continuations.c: Reimplement continuations and the call_cc
  stub as RTL programs.

* libguile/programs.c (scm_i_rtl_program_minimum_arity): Add a case for
  continuations.

* libguile/vm-engine.c (rtl_vm_debug_engine): Always call the abort
  continuation hook with the number of non-procedure locals.  Fix
  compose-continuation argument count.  Enable call/cc.

10 years ago(language tree-il analyze) works better with RTL programs
Andy Wingo [Fri, 18 Oct 2013 16:41:59 +0000 (18:41 +0200)]
(language tree-il analyze) works better with RTL programs

* module/system/vm/program.scm (program-arguments-alists): Export this
  interface.  Fall back to grovelling through procedure-minimum-arity if
  the program has no arities, as might be the case for continuations.

* module/language/tree-il/analyze.scm (validate-arity): Use
  program-arguments-alists instead of the program-arities interface, to
  cover both stack VM and RTL programs.

10 years agoForeign procedures are RTL programs
Andy Wingo [Fri, 18 Oct 2013 15:41:33 +0000 (17:41 +0200)]
Foreign procedures are RTL programs

* libguile/foreign.c: Convert to using RTL stubs.  Because RTL code has
  different GC characteristics than objcode -- it's mostly assumed that
  RTL code will never go away -- we go ahead and pre-generate code for
  100 arguments.  This is actually less memory than the stack VM code,
  and doesn't require any relocations at load-time: bonus!  We'll cross
  the >=100 args bridge if we ever come to it.
  (get_foreign_stub_code) New function.
  (scm_i_foreign_arity): New helper, like scm_i_primitive_arity.
  (cif_to_procedure): Rework to make RTL programs.

* libguile/foreign.h: Declare scm_pointer_to_scm and
  scm_scm_to_pointer.  Declare new internal helpers.

* libguile/gsubr.c (create_subr): Refactor to set the flags when the
  object is allocated.

* libguile/instructions.h: Define SCM_PACK_RTL_12_12.

* libguile/programs.c (scm_i_rtl_program_minimum_arity): Dispatch to
  scm_i_foreign_arity if the procedure has the FOREIGN flag.
* libguile/programs.h (SCM_F_PROGRAM_IS_FOREIGN)
  (SCM_PROGRAM_IS_FOREIGN): New interfaces.

* test-suite/tests/foreign.test ("procedure->pointer"): Add a test for
  foreign arities.

10 years agoFix statprof-proc-call-data for recent changes
Andy Wingo [Fri, 18 Oct 2013 09:47:05 +0000 (11:47 +0200)]
Fix statprof-proc-call-data for recent changes

* module/statprof.scm (statprof-proc-call-data): Fix statprof for recent
  fixes.

10 years agoSubrs are RTL programs
Andy Wingo [Fri, 18 Oct 2013 08:03:26 +0000 (10:03 +0200)]
Subrs are RTL programs

* libguile/gsubr.c: Define RTL stubs instead of stack VM stubs.
  (SUBR_STUB_CODE, get_subr_stub_code): Adapt to return a uint32_t*
  pointer instead of a SCM value.
  (create_subr): Create RTL procedures instead of stack VM procedures.
  For RTL procedures, the function pointer, name, and generic address
  pointer go inline to the procedure, as free variables.
  (scm_i_primitive_arity, scm_i_primitive_call_ip): New helpers.
  (scm_c_make_gsubr, scm_c_define_gsubr, scm_c_make_gsubr_with_generic)
  (scm_c_define_gsubr_with_generic): Adapt to create_gsubr being renamed
  to create_subr.

  Remove gsubr test code.

* libguile/gsubr.h (SCM_PRIMITIVE_P, SCM_PRIMITIVE_GENERIC_P): Only RTL
  programs can be primitives now.
  (SCM_SUBRF, SCM_SUBR_NAME, SCM_SUBR_GENERIC): These fields are now in
  the RTL free variables, not the object table.

* libguile/programs.c (scm_i_rtl_program_name):
  (scm_i_rtl_program_documentation):
  (scm_i_rtl_program_properties):
  (scm_i_rtl_program_minimum_arity): Implement these appropriately for
  primitives, which lack debugging information.
  (scm_primitive_p, scm_primitive_call_ip): New helpers.

* libguile/snarf.h: Remove static allocation for subrs.  Since there is
  nothing to allocate besides the program itself, which needs runtime
  relocation, static allocation is not a win.

* system/vm/program.scm: Fix up various arity-related things for
  primitives, which don't use ELF arity info.

* test-suite/tests/eval.test ("stack involving a primitive"): Add an
  XFAIL until we get just one VM.

10 years ago(system vm debug): implement arity-low-pc, arity-high-pc
Andy Wingo [Fri, 18 Oct 2013 09:38:36 +0000 (11:38 +0200)]
(system vm debug): implement arity-low-pc, arity-high-pc

* module/system/vm/debug.scm (arity-low-pc, arity-high-pc): Implement
  these exports.

10 years agoclass-of fix for RTL programs
Andy Wingo [Fri, 18 Oct 2013 07:45:53 +0000 (09:45 +0200)]
class-of fix for RTL programs

* libguile/goops.c (scm_class_of): Use the same logic for RTL programs
  and stack VM programs.

10 years agoStack traces skip RTL boot frames
Andy Wingo [Thu, 17 Oct 2013 21:25:01 +0000 (23:25 +0200)]
Stack traces skip RTL boot frames

* libguile/frames.c (frame-previous)
* libguile/stacks.c (make-stack): Skip RTL boot frames.

10 years agoRTL engine can apply smobs and applicable structs w/o stack VM
Andy Wingo [Thu, 17 Oct 2013 21:24:16 +0000 (23:24 +0200)]
RTL engine can apply smobs and applicable structs w/o stack VM

* libguile/vm-engine.c (rtl_vm_engine): Allow the RTL VM to handle the
  dispatch for SMOBs and applicable structs.

10 years agoFix subr-call
Andy Wingo [Thu, 17 Oct 2013 21:21:29 +0000 (23:21 +0200)]
Fix subr-call

* libguile/vm-engine.c (subr-call): Fix for locals count including the
  procedure.

10 years agoFix tail-apply bugs
Andy Wingo [Thu, 17 Oct 2013 21:19:57 +0000 (23:19 +0200)]
Fix tail-apply bugs

* libguile/vm-engine.c (tail-apply): Fix for old change that made
  the procedure indexed 0 instead of -1.

10 years agoBetter vm.c support for RTL programs
Andy Wingo [Thu, 17 Oct 2013 21:16:32 +0000 (23:16 +0200)]
Better vm.c support for RTL programs

* libguile/vm.c (scm_c_vm_run): Directly dispatch to the RTL VM for RTL
  programs.
  (scm_bootstrap_vm): Initialize the RTL program stubs early, and mark
  the RTL boot program with the boot flag.

10 years agoProcedure traps work with RTL programs.
Andy Wingo [Thu, 17 Oct 2013 21:14:56 +0000 (23:14 +0200)]
Procedure traps work with RTL programs.

* module/system/vm/traps.scm (frame-matcher): Work with RTL programs.

10 years agominimal RTL program support in (system xref)
Andy Wingo [Thu, 17 Oct 2013 21:14:26 +0000 (23:14 +0200)]
minimal RTL program support in (system xref)

* module/system/xref.scm (procedure-sources*): Work with RTL programs.

10 years ago(system vm coverage) works with RTL programs
Andy Wingo [Thu, 17 Oct 2013 21:13:56 +0000 (23:13 +0200)]
(system vm coverage) works with RTL programs

* module/system/vm/coverage.scm (hashq-proc, assq-proc)
  (program-sources*, closed-over-procedures, coverage-data->lcov): Work
  with RTl procedures.

10 years agoStatprof works better with RTL programs
Andy Wingo [Thu, 17 Oct 2013 21:12:23 +0000 (23:12 +0200)]
Statprof works better with RTL programs

* module/statprof.scm (get-call-data, procedure=?): Work with RTL
  programs.

10 years agobind-rest works in the optional-and-rest-arg case.
Andy Wingo [Mon, 14 Oct 2013 19:45:48 +0000 (21:45 +0200)]
bind-rest works in the optional-and-rest-arg case.

* libguile/vm-engine.c (bind-rest): If the sp is below the dst reg,
  alloc the frame to ensure there is enough space, and to fill in
  intermediate values with SCM_UNDEFINED.

10 years agoRefactor vm_abort
Andy Wingo [Mon, 14 Oct 2013 15:32:16 +0000 (17:32 +0200)]
Refactor vm_abort

* libguile/vm.c (vm_abort):
* libguile/vm-i-system.c (abort): Refactor abort interface so that it is
  more amenable to the RTL VM.

10 years agoReify call-thunk/no-inline.
Andy Wingo [Mon, 14 Oct 2013 14:43:42 +0000 (16:43 +0200)]
Reify call-thunk/no-inline.

* module/language/cps/reify-primitives.scm (reify-primitives): Remove
  call-thunk/no-inline in this late phase.

10 years agoRTL: Compile prompts
Andy Wingo [Mon, 14 Oct 2013 14:13:57 +0000 (16:13 +0200)]
RTL: Compile prompts

* libguile/vm-engine.c (prompt): Adapt to explicitly set the saved SP so
  we know how many incoming values the handler will receive, and to make
  escape-only? a flag.

* module/language/cps/compile-rtl.scm (emit-rtl-sequence): $prompt
  should only be found in a "seq" context, as it just pushes on a prompt
  and doesn't bind any values.  On the other hand it should emit
  appropriate code for the handler to bind its values, so do that.

* module/language/cps/slot-allocation.scm ($cont-allocation): Add a note
  that proc-slot is used by prompts as well.
  (allocate-slots): Compute the allocation of a prompt handler's args.

* module/language/tree-il/compile-cps.scm (convert): Use "unwind"
  instead of the nonexistent "pop-prompt".

* module/system/vm/disassembler.scm (code-annotation): Adapt to change
  in prompt VM op.

10 years agoRTL VM: receive-values has allow-extra? flag
Andy Wingo [Mon, 14 Oct 2013 14:09:43 +0000 (16:09 +0200)]
RTL VM: receive-values has allow-extra? flag

* libguile/vm-engine.c (receive-values): Add an ALLOW-EXTRA? flag in
  unused bits of the third word.  Without it, receive-values will check
  for the exact number of incoming values.

* libguile/vm.c (vm_error_wrong_number_of_values): New error case.

* module/language/cps/compile-rtl.scm (emit-rtl-sequence): Adapt to add
  the ALLOW-EXTRA? flag.

10 years agoAdd SCM_F_DYNSTACK_PROMPT_PUSH_NARGS prompt flag
Andy Wingo [Mon, 14 Oct 2013 14:05:45 +0000 (16:05 +0200)]
Add SCM_F_DYNSTACK_PROMPT_PUSH_NARGS prompt flag

* libguile/dynstack.h (scm_t_dynstack_prompt_flags): New flag,
  SCM_F_DYNSTACK_PROMPT_PUSH_NARGS, set if the continuation expects the
  number of args to be pushed on the top of the stack.

* libguile/control.c (scm_c_abort): Only push nargs if requested.

* libguile/eval.c (eval):
* libguile/throw.c (pre_init_catch):
* libguile/vm-i-system.c (prompt): Set
  SCM_F_DYNSTACK_PROMPT_PUSH_NARGS.

10 years agocall-with-prompt always compiles to CPS $prompt
Andy Wingo [Mon, 14 Oct 2013 10:20:58 +0000 (12:20 +0200)]
call-with-prompt always compiles to CPS $prompt

* module/language/tree-il/compile-cps.scm (convert): For prompts without
  inline handlers, eta-convert the handler.

10 years agoPut the readline extension in the extensionsdir
Andy Wingo [Mon, 14 Oct 2013 09:33:41 +0000 (11:33 +0200)]
Put the readline extension in the extensionsdir

* GUILE-VERSION:
* acinclude.m4:
* guile-readline/LIBGUILEREADLINE-VERSION:
* guile-readline/Makefile.am: Rename libguile-readline-v-18.so to
  guile-readline.so, and install it to the extensions dir instead of the
  libdir.

* guile-readline/ice-9/readline.scm: Load guile-readline instead of
  libguile-readline-v-18.

10 years agoMore precise dead-after-use? for loop variables
Andy Wingo [Sat, 12 Oct 2013 14:36:28 +0000 (16:36 +0200)]
More precise dead-after-use? for loop variables

* module/language/cps/dfg.scm (dead-after-use?):
  (dead-after-branch?): A symbol defined in the header block of a loop
  is still within the same loop.

10 years agoRTL slot allocation: Don't kill variables that flow into loops
Andy Wingo [Sat, 12 Oct 2013 14:22:45 +0000 (16:22 +0200)]
RTL slot allocation: Don't kill variables that flow into loops

* module/language/cps/dfg.scm (dead-after-use?): Don't kill a variable
  if it was defined outside the current loop.
  (dead-after-branch?): Likewise, but I don't think this helper is
  correct yet :/

10 years agoCompute post-dominators
Andy Wingo [Sat, 12 Oct 2013 14:11:36 +0000 (16:11 +0200)]
Compute post-dominators

* module/language/cps/dfg.scm ($block): Add pdom and pdom-level fields,
  for post-dominators.
  (reverse-post-order, convert-predecessors): Arrange to work either
  way: for dominators or for post-dominators.
  (analyze-control-flow!): Compute post-dominators.
  (dominates?): Refactor.
  (post-dominates?): New helper.

10 years agoIdentify loops
Andy Wingo [Sat, 12 Oct 2013 13:19:01 +0000 (15:19 +0200)]
Identify loops

* module/language/cps/dfg.scm (compute-dom-edges)
  (compute-join-edges, compute-reducible-back-edges)
  (compute-irreducible-dom-levels, compute-nodes-by-level)
  (mark-loop-body, mark-irreducible-loops, identify-loops): Identify
  loops.  Irreducible loops are TODO.

* test-suite/tests/rtl-compilation.test ("contification"): Add an
  irreducible loop test.

10 years agoDFG refactorings
Andy Wingo [Sat, 12 Oct 2013 10:48:08 +0000 (12:48 +0200)]
DFG refactorings

* module/language/cps/dfg.scm ($block): Add "irreducible" field, format
  TBD.
  (reverse-post-order): Return a vector directly.
  (convert-predecessors, compute-dom-levels, compute-idoms):
  (analyze-control-flow!): Factor out control flow analsysis a bit
  better.
  (identify-loops): New helper.  Currently a NOP.
  (visit-fun): Adapt to compute-dominator-tree rename to
  analyze-control-flow!.

10 years agoReplace conservatively-dominates? with a precise dominator lookup
Andy Wingo [Fri, 11 Oct 2013 12:10:19 +0000 (14:10 +0200)]
Replace conservatively-dominates? with a precise dominator lookup

* module/language/cps/dfg.scm (dominates?): Use the dominator tree
  instead of the scope tree.