bpt/guile.git
10 years agoSet-car! on a dead pair does not force the pair to be live
Andy Wingo [Fri, 2 May 2014 18:06:30 +0000 (20:06 +0200)]
Set-car! on a dead pair does not force the pair to be live

* module/language/cps/dce.scm (constant-type, lookup-type)
  (default-type-checker, *primcall-type-checkers*)
  (define-primcall-type-checker, define-simple-primcall-types)
  (check-primcall-arg-types): Define a really lame type analysis that
  can elide some expressions causing &type-check.
  (compute-live-code): Wire up the type checker.

10 years agoAdd auxiliary definitions for boxes
Andy Wingo [Sat, 3 May 2014 10:21:20 +0000 (12:21 +0200)]
Add auxiliary definitions for boxes

* module/language/cps/cse.scm (compute-equivalent-subexpressions): Add
  auxiliary definitions for boxes.

10 years agoCSE does scalar replacement of aggregates
Andy Wingo [Fri, 2 May 2014 15:47:20 +0000 (17:47 +0200)]
CSE does scalar replacement of aggregates

* module/language/cps/effects-analysis.scm (effects-clobber): New
  helper.
  (length): Only depend on &cdr.
  (synthesize-definition-effects!): New interface.

* module/language/cps/cse.scm (compute-available-expressions): Don't
  count out constructors here -- we'll do that below.
  (compute-defs): Add a comment.
  (compute-equivalent-subexpressions): Synthesize getter calls at
  constructor/setter sites, so that (set-car! x y) can cause a
  future (car x) to just reference y.  The equiv-labels set now stores
  the defined vars, so there is no need for the defs vector.
  (cse, apply-cse): Adapt to compute-equivalent-subexpressions change.

10 years agoMore inlinable effects-analysis procedures
Andy Wingo [Fri, 2 May 2014 15:29:39 +0000 (17:29 +0200)]
More inlinable effects-analysis procedures

* module/language/cps/effects-analysis.scm (exclude-effects)
  (effect-free?, constant?): Define to be inlinable.
  (allocate-struct/immediate): Add effects.

10 years agoUpdate NEWS
Andy Wingo [Fri, 2 May 2014 09:13:34 +0000 (11:13 +0200)]
Update NEWS

* NEWS: Update.

10 years agoRewrite boot-9 map to be recursive and pure
Andy Wingo [Thu, 1 May 2014 19:14:42 +0000 (21:14 +0200)]
Rewrite boot-9 map to be recursive and pure

* module/ice-9/boot-9.scm (map): Rewrite to be recursive and pure
  instead of iterative and effectful.  At best this is faster; at worst
  it is slower.  In any case it resolves continuation-related issues.

* module/srfi/srfi-1.scm (fold): Specialize the two-arg case.
  (map): Rewrite to be recursive.

* test-suite/tests/r5rs_pitfall.test (8.3): Update for new expected map
  behavior.

10 years agoFix inner and outer stack cuts to match on procedure code
Andy Wingo [Thu, 1 May 2014 12:26:20 +0000 (14:26 +0200)]
Fix inner and outer stack cuts to match on procedure code

* doc/ref/api-debug.texi (Stack Capture): Update make-stack docs.

* libguile/programs.h:
* libguile/programs.c (scm_program_address_range): New internal
  procedure.

* libguile/stacks.c (narrow_stack): Interpret a pair of integers as an
  address range.  If a cut is a procedure, attempt to resolve it to an
  address range.
  (scm_make_stack): Update docstring.

* module/system/vm/program.scm (program-address-range): New exported
  procedure.

* module/statprof.scm (statprof, gcprof): Use program-address-range to
  get the outer-cut, for efficiency.

10 years agoMerge remote-tracking branch 'origin/stable-2.0'
Andy Wingo [Mon, 28 Apr 2014 16:51:21 +0000 (18:51 +0200)]
Merge remote-tracking branch 'origin/stable-2.0'

Conflicts:
.gitignore
doc/example-smob/Makefile
doc/ref/api-smobs.texi
doc/ref/libguile-concepts.texi
doc/ref/libguile-smobs.texi
libguile.h
libguile/finalizers.c
libguile/finalizers.h
libguile/goops.c
module/language/tree-il/compile-glil.scm
module/oop/goops.scm

10 years agoPrefer foreign objects over smobs in manual
Andy Wingo [Mon, 28 Apr 2014 16:00:05 +0000 (18:00 +0200)]
Prefer foreign objects over smobs in manual

* doc/ref/api-memory.texi (Memory Blocks): Recommend against
  scm_gc_free.  Refer to foreign objects instead of smobs.  Remove
  discussion of scm_must_malloc et al.

* doc/ref/guile.texi (API Reference): Rename SMOB menu item.

* doc/ref/libguile-snarf.texi (Function Snarfing): Update example to not
  refer to smobs.
* doc/ref/tools.texi (How guile-snarf works): Likewise.

10 years agoAdd new standalone tests to gitignore
Andy Wingo [Mon, 28 Apr 2014 15:47:54 +0000 (17:47 +0200)]
Add new standalone tests to gitignore

* .gitignore: Add entries.

10 years agoRemove doc/example-smob/
Andy Wingo [Mon, 28 Apr 2014 15:46:59 +0000 (17:46 +0200)]
Remove doc/example-smob/

* doc/example-smob/: Remove example.  It's smaller than it used to be in
  Guile 1.8, and with foreign objects there's practically nothing
  interesting to test.

* doc/oldfmt.c: Remove this hoary thing.

* doc/README:
* doc/Makefile.am: Update.

10 years agoRemove SMOB tutorial; update manual.
Andy Wingo [Mon, 28 Apr 2014 15:45:07 +0000 (17:45 +0200)]
Remove SMOB tutorial; update manual.

* doc/ref/libguile-smobs.texi: Remove; this tutorial is superseded by
  libguile-foreign-objects.

* doc/ref/libguile-foreign-objects.texi: Proofreading.

* doc/ref/libguile-program.texi: Update Dia examples to refer to foreign
  objects.

* doc/ref/libguile-concepts.texi (Garbage Collection): Update to
  accurately describe the BDW-GC, and to avoid reference to mark
  functions.

* doc/ref/guile.texi: Remove libguile-smobs, and reword API menu.

* doc/ref/api-utility.texi (Equality): Mention GOOPS instead of SMOBs.

* doc/ref/api-smobs.texi (Smobs): Describe as a legacy interface.
  Exhort readers against the writing of mark functions.

* doc/ref/api-foreign-objects.texi (Foreign Objects): Proofreading.

* doc/ref/api-control.texi (Catch): Fix ref to point to foreign
  objects.

* doc/ref/Makefile.am: Remove libguile-smobs.texi.

10 years agoAdd foreign object documentation
Andy Wingo [Mon, 28 Apr 2014 14:27:09 +0000 (16:27 +0200)]
Add foreign object documentation

* doc/ref/api-foreign-objects.texi:
* doc/ref/libguile-foreign-objects.texi: New files.

* doc/ref/guile.texi:
* doc/ref/Makefile.am: Link new files into docs.

10 years agoAdd more foreign object interfaces
Andy Wingo [Mon, 28 Apr 2014 09:27:31 +0000 (11:27 +0200)]
Add more foreign object interfaces

* libguile/foreign-object.c:
* libguile/foreign-object.h (scm_make_foreign_object_1)
  (scm_make_foreign_object_2, scm_make_foreign_object_3)
  (scm_make_foreign_object_n): Change to take void * arguments, and to
  add a comment to the header indicating that these are convenience
  constructors.

* libguile/foreign-object.c:
* libguile/foreign-object.h (scm_foreign_object_unsigned_ref)
  (scm_foreign_object_unsigned_set_x): New functions, equivalent to the
  old scm_foreign_object_ref and scm_foreign_object_set_x.

* libguile/foreign-object.c:
* libguile/foreign-object.h (scm_foreign_object_signed_ref)
  (scm_foreign_object_signed_set_x): New functions taking
  scm_t_signed_bits.

* libguile/foreign-object.c:
* libguile/foreign-object.h (scm_foreign_object_ref)
  (scm_foreign_object_set_x): New functions that take void*.

10 years agoAvoid non-constant struct initializers
Andy Wingo [Mon, 28 Apr 2014 09:01:44 +0000 (11:01 +0200)]
Avoid non-constant struct initializers

* libguile/foreign-object.c (scm_make_foreign_object_2):
  (scm_make_foreign_object_3): Avoid non-constant struct initializers.

10 years agoAdd scm_make_foreign_object_0; optimize scm_make_foreign_object_n.
Andy Wingo [Mon, 28 Apr 2014 08:55:26 +0000 (10:55 +0200)]
Add scm_make_foreign_object_0; optimize scm_make_foreign_object_n.

* libguile/foreign-object.c (scm_make_foreign_object_0): New function.
  (scm_make_foreign_object_n): Pre-fetch layout_chars.

* libguile/foreign-object.h: Add scm_make_foreign_object_0.

10 years agoNew foreign object facility, to replace SMOBs
Andy Wingo [Sun, 27 Apr 2014 12:47:40 +0000 (14:47 +0200)]
New foreign object facility, to replace SMOBs

* libguile/foreign-object.c:
* libguile/foreign-object.h:
* module/system/foreign-object.scm:
* test-suite/standalone/test-foreign-object-c.c:
* test-suite/standalone/test-foreign-object-scm: New files.

* test-suite/standalone/Makefile.am:
* module/Makefile.am:
* libguile/Makefile.am: Add new files.

* libguile.h: Add foreign-object.h.
* libguile/init.c (scm_i_init_guile): Call scm_register_foreign_object.

10 years agoFix foreign slot initialization and access
Andy Wingo [Sun, 27 Apr 2014 09:02:35 +0000 (11:02 +0200)]
Fix foreign slot initialization and access

* libguile/goops.c (scm_sys_initialize_object): Refactor initialization
  so that we don't ref uninitialized slots before initializing them.
  This allows foreign slots, whose initial value is 0, to be initialized
  via #:init-form.

* module/oop/goops.scm (@slot-ref, @slot-set!): Remove definitions.
  Change callers to use struct-ref and struct-set!.  slot-ref and
  slot-set! were only marginally more efficient and were much more
  dangerous.  This change allows the standard accessors to work on
  foreign slots; that was not the case before, as the 'u' fields of the
  struct were read as if they were 'p' slots.
* module/language/tree-il/compile-glil.scm (lambda): Remove support for
  compiling @slot-ref/@slot-set!.  These were private to GOOPS.

* test-suite/tests/goops.test ("active-slot"): Update to not expect a
  ref before initialization.
  ("foreign slots"): Add tests.

10 years agoAdd interface to disable automatic finalization
Andy Wingo [Thu, 17 Apr 2014 13:29:13 +0000 (15:29 +0200)]
Add interface to disable automatic finalization

* libguile/finalizers.h:
* libguile/finalizers.c (run_finalizers_async_thunk): Call the new
  scm_run_finalizers helper.
  (scm_set_automatic_finalization_enabled, scm_run_finalizers): New
  functions.
  (scm_init_finalizers): Only set a finalizer notifier if automatic
  finalization is enabled.

* doc/ref/libguile-smobs.texi (Garbage Collecting Smobs): Add discussion
  of concurrency.

* doc/ref/api-smobs.texi (Smobs): Document new functions.

10 years agoMerge branch 'stable-2.0'
Mark H Weaver [Fri, 25 Apr 2014 06:06:01 +0000 (02:06 -0400)]
Merge branch 'stable-2.0'

Conflicts:
GUILE-VERSION
NEWS
guile-readline/ice-9/readline.scm
libguile/async.c
libguile/backtrace.c
libguile/deprecated.h
libguile/gc-malloc.c
libguile/gdbint.c
libguile/init.c
libguile/ioext.c
libguile/mallocs.c
libguile/print.c
libguile/rw.c
libguile/scmsigs.c
libguile/script.c
libguile/simpos.c
libguile/snarf.h
libguile/strports.c
libguile/threads.c
libguile/vm-i-scheme.c
libguile/vm-i-system.c
module/srfi/srfi-18.scm
test-suite/Makefile.am
test-suite/standalone/test-num2integral.c

10 years agoprint: Fix printing of weak vectors.
Mark H Weaver [Fri, 25 Apr 2014 05:39:59 +0000 (01:39 -0400)]
print: Fix printing of weak vectors.

* libguile/print.c (print_vector_or_weak_vector): New static function.
  (iprin1): Use 'print_vector_or_weak_vector' in the vector and weak
  vector cases.

10 years agoSupport weak vectors, arrays, and bitvectors in (system base types).
Mark H Weaver [Thu, 24 Apr 2014 21:57:19 +0000 (17:57 -0400)]
Support weak vectors, arrays, and bitvectors in (system base types).

* module/system/base/types.scm (%tc7-wvect, %tc7-array, %tc7-bitvector):
  New variables.
  (cell->object): Add cases for weak vectors, arrays, and bitvectors.

10 years agoprint: avoid triggering deprecation warnings when printing weak vectors.
Mark H Weaver [Thu, 24 Apr 2014 21:55:47 +0000 (17:55 -0400)]
print: avoid triggering deprecation warnings when printing weak vectors.

* libguile/print.c (iprin1): Use 'scm_c_weak_vector_ref' to access
  elements of weak vectors.

10 years agobuild: Clean up rules for meta/{guild,guile-config}.
Ludovic Courtès [Thu, 24 Apr 2014 21:46:20 +0000 (23:46 +0200)]
build: Clean up rules for meta/{guild,guile-config}.

* meta/Makefile.am (guile-config, guild): Avoid useless 'cat'
  invocation'.  Quote all occurrences of '@'.
  Suggested by Eric Blake <eblake@redhat.com>.

10 years agobuild: Clean up rules for meta/{guild,guile-config}.
Ludovic Courtès [Thu, 24 Apr 2014 21:46:20 +0000 (23:46 +0200)]
build: Clean up rules for meta/{guild,guile-config}.

* meta/Makefile.am (guile-config, guild): Avoid useless 'cat'
  invocation'.  Quote all occurrences of '@'.
  Suggested by Eric Blake <eblake@redhat.com>.

10 years agobuild: Honor program name transformation in 'guild'.
Ludovic Courtès [Thu, 24 Apr 2014 09:16:21 +0000 (11:16 +0200)]
build: Honor program name transformation in 'guild'.

* configure.ac: Remove erroneous 'guile_program_name' substitute; see
  <https://lists.gnu.org/archive/html/autoconf/2014-04/msg00010.html>
  for details.  Remove 'meta/guild' config file.
* meta/Makefile.am (guild): New target.
  (CLEANFILES): Add 'guild'.
* meta/guild.in: Remove 'prefix' and 'exec_prefix' definitions; use
  @installed_guile@.

10 years agobuild: Honor program name transformation in 'guild'.
Ludovic Courtès [Thu, 24 Apr 2014 09:16:21 +0000 (11:16 +0200)]
build: Honor program name transformation in 'guild'.

* configure.ac: Remove erroneous 'guile_program_name' substitute; see
  <https://lists.gnu.org/archive/html/autoconf/2014-04/msg00010.html>
  for details.  Remove 'meta/guild' config file.
* meta/Makefile.am (guild): New target.
  (CLEANFILES): Add 'guild'.
* meta/guild.in: Remove 'prefix' and 'exec_prefix' definitions; use
  @installed_guile@.

10 years agoSet $GC_MARKERS to 1 when libgc 7.4.0 is used.
Ludovic Courtès [Wed, 23 Apr 2014 16:12:26 +0000 (18:12 +0200)]
Set $GC_MARKERS to 1 when libgc 7.4.0 is used.

* libguile/gc.c (scm_storage_prehistory) [GC_VERSION == 7.4.0]: Add
  'setenv' call.

10 years agoFix memory leak on `realloc' failure
Dmitry Bogatov [Thu, 10 Apr 2014 05:23:28 +0000 (09:23 +0400)]
Fix memory leak on `realloc' failure

* libguile/script.c (realloc0): New helper.
  (script_read_arg, scm_get_meta_args): Use realloc0, not realloc.

Signed-off-by: Dmitry Bogatov <KAction@gnu.org>
10 years agoAdd make-vector opcode
Andy Wingo [Mon, 21 Apr 2014 19:48:39 +0000 (21:48 +0200)]
Add make-vector opcode

* libguile/vm-engine.c (make-vector): New opcode.
* module/language/cps/compile-bytecode.scm (compile-fun):
* module/system/vm/assembler.scm (system): Support the new opcode.
  (*bytecode-minor-version*): Bump.

* libguile/_scm.h (SCM_OBJCODE_MINOR_VERSION): Bump.

* test-suite/tests/compiler.test ("limits"): Add vector test.

10 years agoOperations on 8-bit and 12-bit operands shuffle args into range
Andy Wingo [Mon, 21 Apr 2014 17:28:06 +0000 (19:28 +0200)]
Operations on 8-bit and 12-bit operands shuffle args into range

* module/language/cps/slot-allocation.scm (allocate-slots): Avoid
  allocating locals in the range [253,255].

* module/system/vm/assembler.scm: List exports explicitly.  For
  operations with limited-range operands, export wrapper assemblers that
  handle shuffling their operands into and out of their range.
  (define-assembler): Get rid of enclosing begin.
  (shuffling-assembler, define-shuffling-assembler): New helpers to
  define shuffling wrapper assemblers.
  (emit-mov*, emit-receive*): New functions.
  (shuffle-up-args): New helper.
  (standard-prelude, opt-prelude, kw-prelude): Call shuffle-up-args
  after finishing.

* test-suite/tests/compiler.test ("limits"): Add test cases.

10 years agoMore expansion-time-only definitions in assembler.scm
Andy Wingo [Mon, 21 Apr 2014 10:13:54 +0000 (12:13 +0200)]
More expansion-time-only definitions in assembler.scm

* module/system/vm/assembler.scm (define-inline): Change so that the
  defined macro is only defined at expansion-time.
  (u32-ref, u32-set!, s32-ref, s32-set!, pack-arity-flags): Use
  define-inline.
  (pack-flags, assert-match, *block-size*, id-append, assembler)
  (define-assembler, visit-opcodes, define-macro-assembler): Wrap in
  eval-when expand.

10 years agodefine-inline in assembler.scm
Andy Wingo [Mon, 21 Apr 2014 10:01:46 +0000 (12:01 +0200)]
define-inline in assembler.scm

* module/system/vm/assembler.scm (define-inline): New local helper.
  Update local users of define-inlinable to use it.

10 years agoVM opcodes only have <24-bit slot operands in the first word
Andy Wingo [Sun, 20 Apr 2014 09:52:14 +0000 (11:52 +0200)]
VM opcodes only have <24-bit slot operands in the first word

* libguile/vm-engine.c (make-array): Change to only have
  restricted-width operands in the first word.  This instruction is
  currently unused, however.

* module/system/vm/assembler.scm (assembler):
* module/system/vm/disassembler.scm (disassembler): Disallow
  restricted-width operands in tail words.

10 years agoAdd interface to disable automatic finalization
Andy Wingo [Thu, 17 Apr 2014 13:29:13 +0000 (15:29 +0200)]
Add interface to disable automatic finalization

* libguile/finalizers.h:
* libguile/finalizers.c (run_finalizers_async_thunk)
  (finalization_thread_proc): Call the new scm_run_finalizers helper.
  (scm_i_finalizer_pre_fork): Only spawn the thread if automatic
  finalization is enabled.
  (scm_set_automatic_finalization_enabled, scm_run_finalizers): New
  functions.
  (scm_init_finalizers, scm_init_finalizer_thread): Only set a finalizer
  notifier if automatic finalization is enabled.

* doc/ref/libguile-smobs.texi (Garbage Collecting Smobs): Add discussion
  of concurrency.

* doc/ref/api-smobs.texi (Smobs): Document new functions.

10 years agoSlot allocation can re-use closure and argument slots
Andy Wingo [Wed, 16 Apr 2014 17:21:50 +0000 (19:21 +0200)]
Slot allocation can re-use closure and argument slots

* module/language/cps/slot-allocation.scm (allocate-slots): Allow slot
  allocation to re-use the closure and argument slots.

10 years agoRemove SCM_FRAME_PROGRAM
Andy Wingo [Wed, 16 Apr 2014 17:20:42 +0000 (19:20 +0200)]
Remove SCM_FRAME_PROGRAM

* libguile/frames.h: Remove SCM_FRAME_PROGRAM, now unused.

10 years agoVM robustness for optimized closures
Andy Wingo [Wed, 16 Apr 2014 17:20:23 +0000 (19:20 +0200)]
VM robustness for optimized closures

* libguile/vm.c (vm_error_unbound, vm_error_unbound_fluid): Remove proc
  argument.  The value in slot 0 is not necessarily the procedure being
  applied, after the prelude is done.

* libguile/vm-engine.c (vm_engine): Use LOCAL_REF (0) instead of
  SCM_FRAME_PROGRAM, and adapt to above changes.

10 years agoFix rewinding continuations when outermost frame has zero locals
Andy Wingo [Wed, 16 Apr 2014 17:18:29 +0000 (19:18 +0200)]
Fix rewinding continuations when outermost frame has zero locals

* libguile/vm.c (vm_reinstate_partial_continuation_inner): Fix boundary
  condition when the outermost frame has zero locals.

10 years agoframe-previous, frame-procedure robustness
Andy Wingo [Wed, 16 Apr 2014 17:17:38 +0000 (19:17 +0200)]
frame-previous, frame-procedure robustness

* libguile/frames.c (scm_c_frame_closure): Don't use SCM_FRAME_PROGRAM,
  as we don't know if the frame actually has any locals.
  (scm_c_frame_previous): More robustly detect end-of-stack.  Allows
  scm_c_frame_previous to work on partial continuations.

10 years agomake-stack works on delimited continuations
Andy Wingo [Wed, 16 Apr 2014 17:16:10 +0000 (19:16 +0200)]
make-stack works on delimited continuations

* libguile/stacks.c (scm_make_stack, scm_stack_id):
* libguile/vm.c (scm_i_vm_cont_to_frame): Allow delimited continuations
  as the argument to make-stack.

10 years agoMore robust coverage tests
Andy Wingo [Wed, 16 Apr 2014 17:13:49 +0000 (19:13 +0200)]
More robust coverage tests

* test-suite/tests/coverage.test ("line-execution-counts"): Allow zero
  or one count on the loop head.

10 years agoChange some make-stack tests to use frame-call-representation
Andy Wingo [Wed, 16 Apr 2014 17:13:09 +0000 (19:13 +0200)]
Change some make-stack tests to use frame-call-representation

* test-suite/tests/eval.test ("stacks"): Use frame-call-representation.

10 years agoFix statprof for optimizations
Andy Wingo [Wed, 16 Apr 2014 17:12:43 +0000 (19:12 +0200)]
Fix statprof for optimizations

* module/statprof.scm (profile-signal-handler): Bind in a letrec.
  Otherwise the compiler may see the closure slot as dead, and the inner
  stack cut won't work.

10 years agoFix a frame-call-representation bug
Andy Wingo [Wed, 16 Apr 2014 12:54:46 +0000 (14:54 +0200)]
Fix a frame-call-representation bug

* module/system/vm/frame.scm (frame-call-representation): Fix logic for
  displaying names of non-procedures and procedures out of arities.

10 years agoBetter backtraces from C, especially for optimized closures
Andy Wingo [Wed, 16 Apr 2014 12:33:20 +0000 (14:33 +0200)]
Better backtraces from C, especially for optimized closures

* libguile/frames.h:
* libguile/frames.c (scm_frame_call_representation): New interface;
  dispatches to Scheme.

* libguile/backtrace.c (display_application): Use
  scm_frame_call_representation.  This should be monotonically better,
  given that scm_frame_arguments (which was previously called) also
  dispatched to Scheme and actually ended up calling
  frame-call-representation.

10 years agoframe-call-representation checks available-bindings, as appropriate
Andy Wingo [Wed, 16 Apr 2014 12:19:18 +0000 (14:19 +0200)]
frame-call-representation checks available-bindings, as appropriate

* module/system/vm/frame.scm (available-bindings): Map indexes in such a
  way that the first argument is index 1.
  (frame-call-representation): Update to search the bindings for live
  bindings.

10 years agoUpdate frame-bindings interface
Andy Wingo [Wed, 16 Apr 2014 11:58:17 +0000 (13:58 +0200)]
Update frame-bindings interface

* module/system/repl/debug.scm (print-locals): Update to work with new
  interface.
  (frame->module): Update.  Still doesn't work due to lack of
  `program-module', though.

* module/system/vm/program.scm (make-binding, binding:name)
  (binding:definition-offset, program-arity-bindings-for-ip): Remove
  these.

* module/system/vm/frame.scm (<binding>): New type.
  (available-bindings): Return a list of <binding> instances.
  (frame-lookup-binding, frame-binding-set!, frame-binding-ref):
  (frame-environment, frame-object-name): Adapt.

10 years agoImplement frame-bindings
Andy Wingo [Wed, 16 Apr 2014 10:59:45 +0000 (12:59 +0200)]
Implement frame-bindings

* module/system/vm/frame.scm (parse-code, compute-predecessors):
  (compute-genv, compute-defs-by-slot, compute-killv, available-bindings):
  (frame-bindings): Add a bunch of hairy code to compute the set of
  bindings that are live in a frame.

10 years agoAdd arity-code
Andy Wingo [Wed, 16 Apr 2014 10:58:35 +0000 (12:58 +0200)]
Add arity-code

* module/system/vm/debug.scm (arity-code): New interface.

10 years agoAdd parsing interfaces to the disassembler
Andy Wingo [Wed, 16 Apr 2014 10:58:20 +0000 (12:58 +0200)]
Add parsing interfaces to the disassembler

* module/system/vm/disassembler.scm (instruction-length):
  (instruction-has-fallthrough?, instruction-relative-jump-targets):
  (instruction-slot-clobbers): New interfaces; to be used when
  determining the bindings available at a given point of a procedure.

10 years agoFix up some opcode metadata
Andy Wingo [Wed, 16 Apr 2014 10:51:34 +0000 (12:51 +0200)]
Fix up some opcode metadata

* libguile/vm-engine.c (make-long-immediate, static-ref): Mark as "dst"
  instructions.

10 years agoUpdate libgc URL in README.
Mark H Weaver [Wed, 16 Apr 2014 04:49:40 +0000 (00:49 -0400)]
Update libgc URL in README.

* README: Update libgc URL.  Suggested by Ian Grant
  <ian.a.n.grant@googlemail.com>.

10 years agoAdd ability to query local definitions for a procedure
Andy Wingo [Tue, 15 Apr 2014 20:24:48 +0000 (22:24 +0200)]
Add ability to query local definitions for a procedure

* module/system/vm/debug.scm (arity-definitions): New interface.

* module/system/vm/program.scm (make-binding, binding:boxed?)
  (binding:index, binding:start, binding:end): Remove.
  (binding:definition-offset, binding:slot): Add.
  (program-arity-bindings-for-ip): Rename from program-bindings-for-ip,
  as it gives all definitions in an arity.  The user will have to do
  data-flow analysis to recover the set of variables that are actually
  available at any given point.
  (arity->arguments-alist): Remove crufty code.

10 years agoFix rtl tests
Andy Wingo [Tue, 15 Apr 2014 20:00:30 +0000 (22:00 +0200)]
Fix rtl tests

* module/system/vm/assembler.scm (write-arities): Add a diagnostic.

* test-suite/tests/rtl.test: Fix tests to emit "definition"
  instructions.

10 years agoFix frame-call-representation for primitive applications
Andy Wingo [Tue, 15 Apr 2014 19:47:46 +0000 (21:47 +0200)]
Fix frame-call-representation for primitive applications

* module/system/vm/frame.scm (frame-call-representation): Fix to work
  for primitives.

* test-suite/tests/eval.test ("stacks"): Update expected result for
  substring.

10 years agoAssembler residualizes local variable definition locations
Andy Wingo [Tue, 15 Apr 2014 18:25:16 +0000 (20:25 +0200)]
Assembler residualizes local variable definition locations

* module/system/vm/assembler.scm (write-arities): Serialize definition
  locations after names.
  (definition): Store definition as a byte offset.

10 years agoBump minor objcode version for recent changes
Andy Wingo [Tue, 15 Apr 2014 18:20:01 +0000 (20:20 +0200)]
Bump minor objcode version for recent changes

* libguile/_scm.h (SCM_OBJCODE_MINOR_VERSION):
* module/system/vm/assembler.scm (*bytecode-minor-version*): Bump.

10 years agoWrite all local variable names into the arities section
Andy Wingo [Tue, 15 Apr 2014 15:52:41 +0000 (17:52 +0200)]
Write all local variable names into the arities section

* module/system/vm/assembler.scm (put-uleb128, put-sleb128)
  (port-position): Lift out these helpers.
  (arity-header-len, write-arities, link-arities): Add "nlocals" to the
  arity headers.  Write names of all locals into the arities section,
  not just the arguments.  Write them as uleb128's instead of uint32's,
  to save space.

* module/system/vm/debug.scm (arity-header-len, arity-nlocals*)
  (arity-nlocals, arity-locals, arity-arguments-alist): Adapt to new
  encoding for arities.

10 years agoTweak arities debugging representation
Andy Wingo [Tue, 15 Apr 2014 13:27:19 +0000 (15:27 +0200)]
Tweak arities debugging representation

* module/system/vm/assembler.scm (meta-arities-size, write-arity-links):
* module/system/vm/debug.scm (arity-keyword-args)
  (arity-arguments-alist): Rewrite to put they keyword literals link
  first.  Unfortunately requires a recompile :/

10 years agoBeginnings of local variable information
Andy Wingo [Tue, 15 Apr 2014 12:02:25 +0000 (14:02 +0200)]
Beginnings of local variable information

* module/system/vm/assembler.scm (<arity>, begin-kw-arity, end-arity):
  (definition): Add definition macro-instruction.  Arrange to record
  variable definitions.

* module/language/cps/compile-bytecode.scm (compile-fun): Emit
  definition macro-instructions as appropriate.

10 years agoRemove needless label remapping in slot-allocation
Andy Wingo [Tue, 15 Apr 2014 10:25:26 +0000 (12:25 +0200)]
Remove needless label remapping in slot-allocation

* module/language/cps/slot-allocation.scm (dead-after-def?):
  (dead-after-use?, allocate-slots): Remove some needless remapping
  between label indexes in the CFA, the DFA, and their names.

10 years agoDFA datums don't rename their labels
Andy Wingo [Tue, 15 Apr 2014 10:16:41 +0000 (12:16 +0200)]
DFA datums don't rename their labels

* module/language/cps/dfg.scm (analyze-reverse-control-flow): Don't
  compute and return an order vector; it's not needed.
  ($dfa): Remove label renaming.  We can just rename labels before
  returning the DFA.
  (dfa-k-idx, dfa-k-sym, dfa-k-count): Adapt.
  (compute-live-variables): Adapt, and rename labels before returning.

10 years agoBetter backtraces for optimized closures
Andy Wingo [Tue, 15 Apr 2014 09:18:50 +0000 (11:18 +0200)]
Better backtraces for optimized closures

* module/system/vm/debug.scm (arity-keyword-args, find-program-arity):
  New exports.

* module/system/vm/frame.scm (frame-call-representation): Prefer to use
  the frame IP to get the procedure.

10 years agostatprof avoids mucking with VM trace levels when not counting calls
Andy Wingo [Mon, 14 Apr 2014 15:06:05 +0000 (17:06 +0200)]
statprof avoids mucking with VM trace levels when not counting calls

* module/statprof.scm (statprof-start, statprof-stop): Don't futz the vm
  trace level when we aren't counting calls.  With this change, statprof
  now imposes no overhead on the measured program.

10 years agoBetter state handling in statprof
Andy Wingo [Mon, 14 Apr 2014 14:54:51 +0000 (16:54 +0200)]
Better state handling in statprof

* module/statprof.scm (statprof-fold-call-data)
  (statprof-proc-call-data): Add optional state arg.
  (gcprof): Add optional port arg, and pass state arg explicitly.
  (statprof-display-anomalies, statprof-display)
  (statprof-call-data->stats): Pass state explicitly.

10 years agoOptimize make-stack
Andy Wingo [Mon, 14 Apr 2014 14:31:02 +0000 (16:31 +0200)]
Optimize make-stack

* libguile/continuations.h:
* libguile/continuations.c (scm_i_continuation_to_frame): Operate on
  low-level C structures instead of heap objects.

* libguile/frames.h:
* libguile/frames.c (frame_offset, frame_stack_base): Const args.
  (scm_c_frame_closure): New helper.
  (scm_frame_procedure): Use the new helper.

* libguile/stacks.c (stack_depth, narrow_stack, scm_make_stack): Rework
  to avoid allocating frames as we traverse the stack, and to avoid an
  n**2 case where there are outer cuts.

10 years agoReadline history preserves newlines
Andy Wingo [Mon, 14 Apr 2014 14:12:14 +0000 (16:12 +0200)]
Readline history preserves newlines

* guile-readline/ice-9/readline.scm (make-readline-port): Preserve
  newlines.  This preserves the semantics of history entries that
  contain until-end-of-line comments using `;'.

10 years agoscm_c_make_frame takes struct scm_frame as arg
Andy Wingo [Mon, 14 Apr 2014 13:14:26 +0000 (15:14 +0200)]
scm_c_make_frame takes struct scm_frame as arg

* libguile/frames.h:
* libguile/frames.c (scm_c_make_frame): Adapt to take a const struct
  scm_frame as the argument.  Adapt callers.

* libguile/continuations.c:
* libguile/stacks.c: Adapt callers.

10 years agoRefactor to frames code
Andy Wingo [Mon, 14 Apr 2014 12:54:14 +0000 (14:54 +0200)]
Refactor to frames code

* libguile/frames.h:
* libguile/frames.c (scm_c_frame_previous): New internal helper.
  (scm_frame_previous): Use the helper.
  (RELOC): Take kind and low-level frame args separately.  Adapt
  callers.
  (frame_stack_base, frame_offset): New helpers.
  (scm_i_frame_offset, scm_i_frame_stack_base): Use low-level helpers.

10 years agoOptimize make-global-cont-folder
Andy Wingo [Mon, 14 Apr 2014 11:53:35 +0000 (13:53 +0200)]
Optimize make-global-cont-folder

* module/language/cps.scm (make-global-cont-folder): Inline the
  fold-values, as peval doesn't do so.  Allows closure conversion to
  avoid any closure creation.

10 years agoImprove disassembly for optimized closures
Andy Wingo [Sun, 13 Apr 2014 12:40:22 +0000 (14:40 +0200)]
Improve disassembly for optimized closures

* module/system/vm/disassembler.scm (code-annotation): Add call-label
  and tail-call-label cases.
  (disassemble-addr): With call-label we can see sets of mutually
  recursive functions, so keep a global "visited?" set.

10 years agoRemove debugging code in closure-conversion
Andy Wingo [Sun, 13 Apr 2014 12:26:03 +0000 (14:26 +0200)]
Remove debugging code in closure-conversion

* module/language/cps/closure-conversion.scm (prune-free-vars): Remove
  pk.

10 years agoEval has no more free variables
Andy Wingo [Sun, 13 Apr 2014 12:22:22 +0000 (14:22 +0200)]
Eval has no more free variables

* module/ice-9/eval.scm (primitive-eval): Expand out the call to
  make-general-closure, so that make-general-closure becomes
  well-known.  Now eval has no more free variables!

10 years agoClosure conversion eliminates self-references introduced by fixpoint
Andy Wingo [Sun, 13 Apr 2014 12:21:25 +0000 (14:21 +0200)]
Closure conversion eliminates self-references introduced by fixpoint

* module/language/cps/closure-conversion.scm (analyze-closures): Build a
  bound-vars set as well, to resolve introduced self-references.
  (prune-free-vars, convert-one): Arrange to eliminate self-references.

10 years agoRefactor to closure-conversion
Andy Wingo [Sun, 13 Apr 2014 11:52:56 +0000 (13:52 +0200)]
Refactor to closure-conversion

* module/language/cps/closure-conversion.scm (convert-one): Refactor to
  pull in helpers locally, as they will need more state.

10 years agoAvoid consing an unbound-arg marker in the evaluator
Andy Wingo [Sun, 13 Apr 2014 10:21:36 +0000 (12:21 +0200)]
Avoid consing an unbound-arg marker in the evaluator

* module/ice-9/eval.scm (primitive-eval): Turns out we don't need to
  cons to make the unbound-arg marker.

10 years agoOptimize closures with one free variable
Andy Wingo [Sun, 13 Apr 2014 09:47:17 +0000 (11:47 +0200)]
Optimize closures with one free variable

* module/language/cps/closure-conversion.scm (convert-free-var)
  (allocate-closure, init-closure, prune-free-vars, convert-one)
  (convert-closures): Optimize closures with one free variable.

10 years agoWell-known closures represented using pairs or vectors
Andy Wingo [Sat, 12 Apr 2014 21:31:08 +0000 (23:31 +0200)]
Well-known closures represented using pairs or vectors

* module/language/cps/closure-conversion.scm (convert-free-var):
  (convert-free-vars): Take self-known? param, to do the right thing for
  well-known closures.
  (allocate-closure): New helper.  Well-known closures are represented
  using pairs or vectors.
  (init-closure): Adapt tpo DTRT for well-known closures.
  (prune-free-vars): Move up.
  (convert-one): Adapt to new well-known closure representation.

10 years agoUpdate verify-cps
Andy Wingo [Sat, 12 Apr 2014 20:42:23 +0000 (22:42 +0200)]
Update verify-cps

* module/language/cps/verify.scm (verify-cps): Update for recent CPS
  changes.

10 years agoAvoid creating closures with no free variables
Andy Wingo [Sat, 12 Apr 2014 17:46:23 +0000 (19:46 +0200)]
Avoid creating closures with no free variables

* module/language/cps/closure-conversion.scm (init-closure): Return just
  one value.
  (analyze-closures): Rewrite the well-known set to key off the label
  instead of the closure identifiers before returning.
  (convert-one): Avoid creating closure objects at runtime or load-time
  when "instantiating" or calling well-known closures with no free
  variables.
  (prune-free-vars): New pass.
  (convert-closures): Adapt.

10 years agoHard-wire calls to known procedures
Andy Wingo [Sat, 12 Apr 2014 14:12:33 +0000 (16:12 +0200)]
Hard-wire calls to known procedures

* module/language/cps/closure-conversion.scm (analyze-closures):
  (convert-one, convert-closures): Hard-wire calls to known procedures
  by transforming $call to $callk.

10 years agoclosure conversion computes well-known functions
Andy Wingo [Sat, 12 Apr 2014 13:53:58 +0000 (15:53 +0200)]
closure conversion computes well-known functions

* module/language/cps/closure-conversion.scm (analyze-closures)
  (convert-closures, convert-one): Adapt to compute well-known
  functions.  We don't yet produce $callk though.

10 years agoFirst-order CPS has $program and $closure forms
Andy Wingo [Sat, 12 Apr 2014 09:52:38 +0000 (11:52 +0200)]
First-order CPS has $program and $closure forms

* module/language/cps.scm ($closure, $program): New CPS types, part of
  low-level (first-order) CPS.
  (build-cps-exp, build-cps-term, parse-cps, unparse-cps)
  (compute-max-label-and-var): Update for new CPS types.

* module/language/cps/closure-conversion.scm: Rewrite to produce a
  $program with $closures, and no $funs.

* module/language/cps/reify-primitives.scm:
* module/language/cps/compile-bytecode.scm (compile-fun):
  (compile-bytecode): Adapt to new first-order format.

* module/language/cps/dfg.scm (compute-dfg): Add $closure case.

* module/language/cps/renumber.scm (renumber): Allow this pass to work
  on either format.

* module/language/cps/slot-allocation.scm (allocate-slots): Add $closure
  case.

10 years agoSeparate make-cont-folder into global and local variants
Andy Wingo [Fri, 11 Apr 2014 16:01:23 +0000 (18:01 +0200)]
Separate make-cont-folder into global and local variants

* module/language/cps.scm (make-global-cont-folder)
  (make-local-cont-folder): Separate this macro in two.  It's hot and
  the difference can be important for perf.

* module/language/cps/dfg.scm (compute-label-and-var-ranges):
* module/language/cps/cse.scm (compute-label-and-var-ranges):
* module/language/cps/dce.scm (compute-live-code): Adapt.

10 years agoRoot higher-order CPS term is always $kfun $cont
Andy Wingo [Fri, 11 Apr 2014 12:01:27 +0000 (14:01 +0200)]
Root higher-order CPS term is always $kfun $cont

* module/language/cps/arities.scm:
* module/language/cps/closure-conversion.scm:
* module/language/cps/compile-bytecode.scm:
* module/language/cps/constructors.scm:
* module/language/cps/contification.scm:
* module/language/cps/cse.scm:
* module/language/cps/dce.scm:
* module/language/cps/elide-values.scm:
* module/language/cps/prune-bailouts.scm:
* module/language/cps/prune-top-level-scopes.scm:
* module/language/cps/renumber.scm:
* module/language/cps/self-references.scm:
* module/language/cps/simplify.scm:
* module/language/cps/specialize-primcalls.scm:
* module/language/tree-il/compile-cps.scm: Adapt to produce and consume
  raw $kfun $cont instances.

* .dir-locals.el: Update $letrec indentation.

10 years agoClosure conversion, reify-primitives use $kfun $cont
Andy Wingo [Fri, 11 Apr 2014 09:51:34 +0000 (11:51 +0200)]
Closure conversion, reify-primitives use $kfun $cont

* module/language/cps/closure-conversion.scm: Produce a $kfun $cont.
* module/language/cps/reify-primitives.scm: Produce and consume $kfun
  $cont.
* module/language/cps/compile-bytecode.scm: Adapt.

10 years agoPreparation for compile-bytecode to work on $kfun $conts
Andy Wingo [Fri, 11 Apr 2014 09:34:50 +0000 (11:34 +0200)]
Preparation for compile-bytecode to work on $kfun $conts

* module/language/cps/compile-bytecode.scm (compile-fun): Change to take
  a $kfun $cont instead of a $fun.
  (visit-funs): Change likewise, and call the proc on $kfun $cont's, not
  $fun's.
  (compile-bytecode): Adapt.

* module/language/cps/dfg.scm (analyze-reverse-control-flow): Adapt to
  expect a $kfun $cont.

10 years agocompute-dfg takes a $kfun $cont, not a $fun
Andy Wingo [Fri, 11 Apr 2014 09:22:06 +0000 (11:22 +0200)]
compute-dfg takes a $kfun $cont, not a $fun

* module/language/cps/dfg.scm (compute-dfg): Take a $kfun $cont instead
  of a $fun.

* module/language/cps/arities.scm:
* module/language/cps/compile-bytecode.scm:
* module/language/cps/contification.scm:
* module/language/cps/cse.scm:
* module/language/cps/dce.scm:
* module/language/cps/simplify.scm:
* module/language/cps/specialize-primcalls.scm: Adapt callers.

10 years agowith-fresh-name-state takes a cont, not a $fun
Andy Wingo [Fri, 11 Apr 2014 08:21:04 +0000 (10:21 +0200)]
with-fresh-name-state takes a cont, not a $fun

* module/language/cps.scm (with-fresh-name-state): Take a cont instead
  of a fun.

* module/language/cps/closure-conversion.scm:
* module/language/cps/constructors.scm:
* module/language/cps/elide-values.scm:
* module/language/cps/prune-bailouts.scm:
* module/language/cps/reify-primitives.scm: Adapt.

10 years agoFunction defined by make-cont-folder takes a cont, not a $fun
Andy Wingo [Fri, 11 Apr 2014 08:12:37 +0000 (10:12 +0200)]
Function defined by make-cont-folder takes a cont, not a $fun

* module/language/cps.scm (make-cont-folder): Take a cont instead of a
  $fun.
  (with-fresh-name-state): Adapt.

* module/language/cps/cse.scm (compute-label-and-var-ranges):
* module/language/cps/dce.scm (compute-live-code):
* module/language/cps/dfg.scm (compute-dfg):
* module/language/cps/elide-values.scm (elide-values):
* module/language/cps/reify-primitives.scm (reify-primitives):
* module/language/cps/renumber.scm (compute-new-labels-and-vars):
  (renumber): Adapt.

10 years agoRename $kentry to $kfun
Andy Wingo [Thu, 10 Apr 2014 10:11:35 +0000 (12:11 +0200)]
Rename $kentry to $kfun

* module/language/cps.scm ($kfun): Rename from $kentry.

* module/language/cps/arities.scm:
* module/language/cps/closure-conversion.scm:
* module/language/cps/compile-bytecode.scm:
* module/language/cps/constructors.scm:
* module/language/cps/contification.scm:
* module/language/cps/cse.scm:
* module/language/cps/dce.scm:
* module/language/cps/dfg.scm:
* module/language/cps/effects-analysis.scm:
* module/language/cps/elide-values.scm:
* module/language/cps/prune-bailouts.scm:
* module/language/cps/prune-top-level-scopes.scm:
* module/language/cps/reify-primitives.scm:
* module/language/cps/renumber.scm:
* module/language/cps/self-references.scm:
* module/language/cps/simplify.scm:
* module/language/cps/slot-allocation.scm:
* module/language/cps/specialize-primcalls.scm:
* module/language/cps/verify.scm:
* module/language/tree-il/compile-cps.scm: Adapt users.

10 years agosrc and meta are fields of $kentry, not $fun
Andy Wingo [Thu, 10 Apr 2014 08:50:17 +0000 (10:50 +0200)]
src and meta are fields of $kentry, not $fun

* module/language/cps.scm ($kentry, $fun): Attach "src" and "meta" on
  the $kentry, not the $fun.  This prepares us for $callk to $kentry
  continuations that have no corresponding $fun.

* module/language/cps/arities.scm:
* module/language/cps/closure-conversion.scm:
* module/language/cps/compile-bytecode.scm:
* module/language/cps/constructors.scm:
* module/language/cps/contification.scm:
* module/language/cps/cse.scm:
* module/language/cps/dce.scm:
* module/language/cps/dfg.scm:
* module/language/cps/elide-values.scm:
* module/language/cps/prune-bailouts.scm:
* module/language/cps/prune-top-level-scopes.scm:
* module/language/cps/reify-primitives.scm:
* module/language/cps/renumber.scm:
* module/language/cps/self-references.scm:
* module/language/cps/simplify.scm:
* module/language/cps/slot-allocation.scm:
* module/language/cps/specialize-primcalls.scm:
* module/language/cps/verify.scm:
* module/language/tree-il/compile-cps.scm: Adapt.

10 years agoRemove tests for old Tree-IL CSE module
Andy Wingo [Thu, 10 Apr 2014 07:25:38 +0000 (09:25 +0200)]
Remove tests for old Tree-IL CSE module

* test-suite/tests/cse.test: Remove.
* test-suite/Makefile.am:

10 years agoRemove obsolete comment in compile-bytecode.scm
Andy Wingo [Tue, 8 Apr 2014 12:10:36 +0000 (14:10 +0200)]
Remove obsolete comment in compile-bytecode.scm

* module/language/cps/compile-bytecode.scm (optimize): Remove an
  obsolete comment.

10 years agoNew pass to avoid free variable creation for self-recursion
Andy Wingo [Tue, 8 Apr 2014 19:41:42 +0000 (21:41 +0200)]
New pass to avoid free variable creation for self-recursion

* module/language/cps/self-references.scm: New pass, avoids the need for
  self-recursion to allocate free variables.

* module/Makefile.am:
* module/language/cps/compile-bytecode.scm: Wire up the new pass.

10 years agoCompile some standalone tests to bytecode
Andy Wingo [Tue, 8 Apr 2014 08:06:40 +0000 (10:06 +0200)]
Compile some standalone tests to bytecode

* test-suite/standalone/test-out-of-memory:
* test-suite/standalone/test-stack-overflow: Compile these files before
  running them.  That way, recursion can check the stack-overflow
  mechanism instead of the memory allocation mechanism.  We compile
  beforehand as a prepass so as not to impose an rlimit on a Guile that
  previously ran auto-compilation.

10 years agoRemove old Tree-IL CSE pass
Andy Wingo [Sun, 6 Apr 2014 09:08:05 +0000 (11:08 +0200)]
Remove old Tree-IL CSE pass

* module/language/tree-il/cse.scm: Delete.

* module/language/tree-il/optimize.scm: Remove use of Tree-IL CSE.

* module/Makefile.am: Remove language/tree-il/cse.scm.

* module/language/cps/compile-bytecode.scm: Rename CSE keyword to
  #:cse?.

10 years agoFlow-sensitive analysis of truth values
Andy Wingo [Sat, 5 Apr 2014 19:08:09 +0000 (21:08 +0200)]
Flow-sensitive analysis of truth values

* module/language/cps/cse.scm (compute-truthy-expressions):
  (compute-equivalent-subexpressions, apply-cse): Arrange to infer
  truthiness of expressions, and use that information to elide redundant
  tests.

10 years agoAdd effects for specialized primitives
Andy Wingo [Sat, 5 Apr 2014 19:06:35 +0000 (21:06 +0200)]
Add effects for specialized primitives

* module/language/cps/effects-analysis.scm (make-vector)
  (make-vector/immediate, vector-ref/immediate, vector-set!/immediate)
  (struct-ref/immediate, struct-set!/immediate): Add effects.