bpt/guile.git
12 years agomost uses of scm_from_locale_symbol become scm_from_utf8_symbol
Andy Wingo [Tue, 25 Oct 2011 15:45:29 +0000 (17:45 +0200)]
most uses of scm_from_locale_symbol become scm_from_utf8_symbol

* libguile/array-handle.c:
* libguile/chars.c:
* libguile/expand.c:
* libguile/feature.c:
* libguile/goops.c:
* libguile/gsubr.c:
* libguile/instructions.c:
* libguile/load.c:
* libguile/macros.c:
* libguile/memoize.c:
* libguile/modules.c:
* libguile/options.c:
* libguile/print.c:
* libguile/smob.c:
* libguile/snarf.h: Change most uses of scm_from_locale_symbol to
  scm_from_utf8_symbol, as the symbols really are not locale-dependent.

12 years agooptimize utf8 symbol lookup
Andy Wingo [Tue, 25 Oct 2011 15:32:50 +0000 (17:32 +0200)]
optimize utf8 symbol lookup

* libguile/symbols.c (utf8_string_equals_wide_string)
  (utf8_lookup_predicate_fn, lookup_interned_utf8_symbol): Optimize
  utf8 symbol lookup.

12 years agoslight scm_procedure_p, scm_i_procedure_arity refactor
Andy Wingo [Mon, 24 Oct 2011 16:29:45 +0000 (18:29 +0200)]
slight scm_procedure_p, scm_i_procedure_arity refactor

* libguile/procs.c (scm_procedure_p):
* libguile/procprop.c (scm_i_procedure_arity): Refactor.

12 years agoremove CELL_P macro
Andy Wingo [Mon, 24 Oct 2011 16:28:24 +0000 (18:28 +0200)]
remove CELL_P macro

* libguile/private-gc.h: Remove private CELL_P macro.

12 years agoadd SCM_HEAP_OBJECT_BASE
Andy Wingo [Mon, 24 Oct 2011 16:22:35 +0000 (18:22 +0200)]
add SCM_HEAP_OBJECT_BASE

* libguile/tags.h (SCM_HEAP_OBJECT_BASE): New macro.  Given a SCM,
  returns a pointer to the start of its memory area on the heap.

* libguile/bytevectors.c:
* libguile/fluids.c:
* libguile/foreign.c:
* libguile/gc.h:
* libguile/guardians.c:
* libguile/numbers.h:
* libguile/ports.c:
* libguile/smob.c:
* libguile/struct.c:
* libguile/weak-set.c:
* libguile/weak-table.c:
* libguile/weak-vector.c: Use it.

12 years agoadd SCM_HEAP_OBJECT_P
Andy Wingo [Mon, 24 Oct 2011 16:13:51 +0000 (18:13 +0200)]
add SCM_HEAP_OBJECT_P

* libguile/tags.h (SCM_HEAP_OBJECT_P): New macro, an alias for
  SCM_NIMP.

* libguile/arrays.c:
* libguile/debug.c:
* libguile/foreign.c:
* libguile/gdbint.c:
* libguile/guardians.c:
* libguile/list.c:
* libguile/modules.c:
* libguile/options.c:
* libguile/smob.c:
* libguile/validate.h:
* libguile/weak-set.c:
* libguile/weak-table.c:
* libguile/weak-vector.c: Use it instead of SCM_NIMP or !SCM_IMP.

12 years agoboot_closure_print cleanup
Andy Wingo [Mon, 24 Oct 2011 15:59:23 +0000 (17:59 +0200)]
boot_closure_print cleanup

* libguile/eval.c (boot_closure_print): Get at the bits directly.

12 years agoadd SCM_{PACK,UNPACK}_POINTER
Andy Wingo [Mon, 24 Oct 2011 15:58:22 +0000 (17:58 +0200)]
add SCM_{PACK,UNPACK}_POINTER

* libguile/tags.h (SCM_UNPACK_POINTER, SCM_PACK_POINTER): New macros.
  The old SCM2PTR and PTR2SCM were defined in such a way that
  round-tripping through a pointer could lose precision, even in the
  case in which you weren't interested in actually dereferencing the
  pointer, it was simply that you needed to plumb a SCM through APIs
  that take pointers.  These new macros are more like SCM_PACK and
  SCM_UNPACK, but for pointer types.  The bit representation of the
  pointer should be the same as the scm_t_bits representation.

* libguile/gc.h (PTR2SCM, SCM2PTR): Remove support for (old) UNICOS
  pointers.  We are going to try tagging the SCM object itself in the
  future, and I don't think that keeping this support is worth its
  cost.  It probably doesn't work anyway.

* libguile/backtrace.c:
* libguile/bytevectors.c:
* libguile/continuations.c:
* libguile/fluids.c:
* libguile/foreign.c:
* libguile/gc.h:
* libguile/guardians.c:
* libguile/hashtab.c:
* libguile/load.c:
* libguile/numbers.c:
* libguile/ports.c:
* libguile/smob.c:
* libguile/strings.c:
* libguile/symbols.c:
* libguile/vm.c:
* libguile/weak-set.c:
* libguile/weak-table.c:
* libguile/weak-vector.c: Update many sites to use the new macros.

12 years agorefactor tc7 and tc16 checks
Andy Wingo [Mon, 24 Oct 2011 15:34:47 +0000 (17:34 +0200)]
refactor tc7 and tc16 checks

* libguile/tags.h (SCM_HAS_TYP7, SCM_HAS_TYP7S, SCM_HAS_TYP16): New
  macros.

* libguile/bytevectors.h (SCM_BYTEVECTOR_P):
* libguile/control.h (SCM_PROMPT_P):
* libguile/filesys.h (SCM_DIRP):
* libguile/fluids.h (SCM_WITH_FLUIDS_P, SCM_FLUID_P)
  (SCM_I_DYNAMIC_STATE_P):
* libguile/foreign.h (SCM_POINTER_P):
* libguile/fports.h (SCM_FPORTP):
* libguile/frames.h (SCM_VM_FRAME_P):
* libguile/hashtab.h (SCM_HASHTABLE_P):
* libguile/inline.h (scm_get_byte_or_eof):
* libguile/numbers.h (SCM_REALP, SCM_BIGP, SCM_COMPLEXP, SCM_FRACTIONP):
* libguile/objcodes.h (SCM_OBJCODE_P):
* libguile/ports.h (SCM_OUTPUT_PORT_P):
* libguile/programs.h (SCM_PROGRAM_P):
* libguile/smob.h (SCM_SMOB_PREDICATE):
* libguile/srfi-14.h (SCM_CHARSETP):
* libguile/strings.c (IS_STRING):
* libguile/strports.h (SCM_STRPORTP):
* libguile/symbols.h (scm_is_symbol):
* libguile/variable.h (SCM_VARIABLEP):
* libguile/vectors.h (SCM_I_IS_VECTOR, SCM_I_IS_NONWEAK_VECTOR):
* libguile/vm-i-system.c (call, tail-call, mv-call)
* libguile/vm.h (SCM_VM_P, SCM_VM_CONT_P):
* libguile/weak-set.c (SCM_WEAK_SET_P):
* libguile/weak-table.c (SCM_WEAK_TABLE_P):
* libguile/weak-vector.h (SCM_I_WVECTP): Use them.

12 years agocheck for pairs with scm_is_pair, not scm_nimp
Andy Wingo [Mon, 24 Oct 2011 15:22:47 +0000 (17:22 +0200)]
check for pairs with scm_is_pair, not scm_nimp

* libguile/array-map.c (scm_ra_matchp, scm_ramapc):
* libguile/dynwind.c (scm_swap_bindings):
* libguile/hooks.c (hook_print, scm_c_run_hook, scm_c_run_hookn):
* libguile/objprop.c (scm_object_property, scm_set_object_property_x):
  Use !scm_is_pair as the termination condition, not scm_imp.

12 years agode-inline cons in scm_acons
Andy Wingo [Mon, 24 Oct 2011 15:14:27 +0000 (17:14 +0200)]
de-inline cons in scm_acons

* libguile/alist.c (scm_acons): Don't inline the conses.

12 years agoremove mutex in make-object-property
Andy Wingo [Mon, 24 Oct 2011 08:55:46 +0000 (10:55 +0200)]
remove mutex in make-object-property

* module/ice-9/boot-9.scm (make-object-property): Remove the mutex; weak
  tables are now threadsafe.

12 years agoremove weak pairs, rewrite weak vectors
Andy Wingo [Mon, 24 Oct 2011 08:52:55 +0000 (10:52 +0200)]
remove weak pairs, rewrite weak vectors

* libguile/weak-vector.c:
* libguile/weak-vector.h: Renamed from weaks.[ch].  Remove weak pairs.
  They were not safe to access with `car' and `cdr'.  Remove weak alist
  vectors, as we have weak tables and sets.  Reimplement weak vectors,
  moving the implementation here.

* libguile/vectors.c:
* libguile/vectors.h: Remove the extra header word.  Use
  scm_c_weak_vector_ref / scm_c_weak_vector_set_x to access weak
  vectors.

* libguile/snarf.h: Remove the extra header word in vectors.

* libguile/threads.c (do_thread_exit, fat_mutex_lock, fat_mutex_unlock):
  Instead of weak pairs, store thread-owned mutexes in a list of
  one-element weak vectors.

* libguile/guardians.c (finalize_guarded): Similarly, store object
  guardians in a list of one-element weak vectors.

* libguile/modules.c (scm_module_reverse_lookup): We no longer need to
  handle the case of weak references.

* libguile/print.c (iprin1): Use the standard vector accessor to print
  vectors.

* libguile.h:
* libguile/Makefile.am:
* libguile/gc-malloc.c:
* libguile/gc.c:
* libguile/goops.c:
* libguile/init.c:
* libguile/objprop.c:
* libguile/struct.c: Update includes.

* module/ice-9/weak-vector.scm: Load weak vector definitions using an
  extension instead of %init-weaks-builtins.

* test-suite/tests/weaks.test: Use the make-...-hash-table names instead
  of the old alist vector names.

12 years agoremove a stale comment
Andy Wingo [Mon, 24 Oct 2011 06:28:06 +0000 (08:28 +0200)]
remove a stale comment

* module/system/foreign.scm (define-wrapped-pointer-type): Remove stale
  comment.

12 years agoconvert internal weak hash table users to use the weak table api
Andy Wingo [Sun, 23 Oct 2011 21:38:51 +0000 (23:38 +0200)]
convert internal weak hash table users to use the weak table api

The weak table API isn't public yet.  It could be after some review.
But we can go ahead and use it now internally.

* libguile/foreign.c:
* libguile/goops.c:
* libguile/objprop.c:
* libguile/procprop.c:
* libguile/smob.c:
* libguile/srcprop.c: Update weak table users to new API.  No locking
  needed!

12 years agoreimplement hashtab.c's weak hash tables in terms of weak-table.c
Andy Wingo [Mon, 24 Oct 2011 05:57:17 +0000 (07:57 +0200)]
reimplement hashtab.c's weak hash tables in terms of weak-table.c

* libguile/hashtab.c:
* libguile/hashtab.h: Reimplement the weak hash table implementation in
  terms of weak tables.  All is well except for the horrific hack for
  hashx tables.

* libguile/weak-table.h:
* libguile/weak-table.c (scm_make_weak_key_hash_table)
  (scm_make_weak_value_hash_table, scm_make_doubly_weak_hash_table)
  (scm_weak_key_hash_table_p, scm_weak_value_hash_table_p)
  (scm_doubly_weak_hash_table_p): Move these definitions here.

12 years agoadd weak table implementation
Andy Wingo [Sun, 23 Oct 2011 21:23:47 +0000 (23:23 +0200)]
add weak table implementation

* libguile/weak-table.c:
* libguile/weak-table.h: New files, implementing open-addressed weak
  hash tables, similar to the implementation of weak sets.  This will
  let us remove weak pairs.

* libguile.h:
* libguile/Makefile.am:
* libguile/evalext.c:
* libguile/gc.c:
* libguile/init.c:
* libguile/print.c:
* libguile/tags.h: Update all the pieces for the new files and tc7.

12 years agoadd scm_c_make_port; the port table is now a weak set
Andy Wingo [Sun, 23 Oct 2011 18:51:52 +0000 (20:51 +0200)]
add scm_c_make_port; the port table is now a weak set

* libguile/ports.c (scm_c_make_port_with_encoding, scm_c_make_port): New
  functions, to replace scm_new_port_table_entry.  Use a weak set
  instead of a weak table.
  (scm_i_remove_port):
  (scm_c_port_for_each, scm_port_for_each): Adapt to use weak set.
  (scm_i_void_port): Use scm_c_make_port.
  (scm_init_ports): Make a weak set.

* libguile/fports.c:
* libguile/ioext.c:
* libguile/r6rs-ports.c:
* libguile/strports.c:
* libguile/vports.c: Adapt to use the new scm_c_make_port API.

12 years agosymbols.c uses weak sets
Andy Wingo [Sun, 23 Oct 2011 18:46:48 +0000 (20:46 +0200)]
symbols.c uses weak sets

* libguile/symbols.c (lookup_interned_symbol)
  (lookup_interned_latin1_symbol, intern_symbol): Adapt to use weak sets
  instead of weak-key hash tables.

12 years agoadd weak sets
Andy Wingo [Sun, 23 Oct 2011 18:45:01 +0000 (20:45 +0200)]
add weak sets

* libguile/weak-set.c:
* libguile/weak-set.h: New files, implementing weak sets, for use in the
  symbol table and port set.  Eventually we will be able to remove weak
  pairs.

* libguile.h:
* libguile/Makefile.am: Add new files.

* libguile/evalext.c:
* libguile/gc.c:
* libguile/init.c:
* libguile/print.c:
* libguile/tags.h: Add support for the new types.

12 years agorevise comments in libguile/tags.h
Andy Wingo [Sat, 15 Oct 2011 09:22:10 +0000 (11:22 +0200)]
revise comments in libguile/tags.h

* libguile/tags.h: Revise the comments to reflect libgc reality.

12 years agoregenerate psyntax-pp.scm
Andy Wingo [Mon, 10 Oct 2011 14:21:06 +0000 (16:21 +0200)]
regenerate psyntax-pp.scm

* module/ice-9/psyntax-pp.scm: Regenerate, now with optimizations.

12 years agoMerge remote-tracking branch 'origin/stable-2.0'
Andy Wingo [Mon, 10 Oct 2011 14:20:08 +0000 (16:20 +0200)]
Merge remote-tracking branch 'origin/stable-2.0'

Does not include psyntax regeneration.

Conflicts:
module/ice-9/psyntax-pp.scm
module/language/tree-il/peval.scm
test-suite/tests/tree-il.test

12 years agoregenerate psyntax-pp.scm
Andy Wingo [Mon, 10 Oct 2011 11:01:54 +0000 (13:01 +0200)]
regenerate psyntax-pp.scm

* module/ice-9/psyntax-pp.scm: Regenerate, now with inlined letrec
  bindings.  Whee!!

12 years agopeval support for memq and memv
Andy Wingo [Mon, 10 Oct 2011 12:42:40 +0000 (14:42 +0200)]
peval support for memq and memv

* module/language/tree-il/peval.scm (peval): Add special handlers for
  memq and memv, as inline.scm used to have.  This is important for
  `case' clauses.  It is very ugly, though.

* test-suite/tests/tree-il.test ("partial evaluation"): Add tests.

12 years agoadd accessor-primitive?, peval uses it
Andy Wingo [Mon, 10 Oct 2011 11:23:26 +0000 (13:23 +0200)]
add accessor-primitive?, peval uses it

* module/language/tree-il/primitives.scm (*primitive-accessors*): New
  set of primitives: those that access mutable memory, but are otherwise
  pure.  Include bytevector references here.
  (accessor-primitive?): New public predicate.

* module/language/tree-il/peval.scm (peval): Refactor to distinguish
  constructor-primitive? from accessor-primitive?.

12 years agopeval: visit operands on-demand, to inline mutually recursive bindings
Andy Wingo [Mon, 10 Oct 2011 10:58:28 +0000 (12:58 +0200)]
peval: visit operands on-demand, to inline mutually recursive bindings

This commit changes to use <operand> structures to hold the context
needed to visit lexical bindings lazily, in context, instead of eagerly
visiting them for value.  This laziness enables inlining of mutually
recursive bindings.

* module/language/tree-il/peval.scm (<var>): Remove comment about copy
  propagation having to run build-var-table; things don't work like that
  any more.
  (build-var-table): Build <var> entries for all variables, even
  unreferenced variables.
  (alpha-rename): Remove.  We will rename bindings on-demand now.

  (peval lookup-var): New helper, to fetch the <var> of a gensym.

  (peval fresh-gensyms): Fold here, under peval, and in it, handle
  updating the store to record a mapping between new names and <var>
  entries from the source program.

  (peval record-source-expression): Don't call build-var-table on the
  new expression, as alpha-renaming happens on-demand now.

  (peval prune-bindings): Rewrite to work with mutually-recursive
  bindings, while optionally preserving binding order.

  (peval extend-env): New helper.

  (peval loop): OK, here goes... Remove the `operand' context, as now we
  visit operands lazily.  Add a `call' context, which does not
  copy-propagate lambda expressions, used to residualize a call after
  aborting an inlining attempt.  Change the `env' to be a mapping of
  gensym to <operand>.  Instead of looking up the operand's binding then
  alpha-renaming it, just rely on the fact that visiting the operand
  will rename it if necessary.

  If we residualize a lexical, do so with the fresh name from the
  environment.  If we visit an operand and it doesn't turn out to be
  constant, we will never be able to copy it, and so cache that fact in
  the operand.  If we residualize a binding and we know what the value
  should be, record that binding so that prune-bindings won't have to
  visit it again.  If the operand folds to a constant, cache that too,
  to save effort when unrolling loops.

  For let, letrec, fix, and lambda-case, instead of visiting the
  bindings eagerly for value, simply record the source expressions and
  environments in an <operand> and rely on copy-propagation to visit
  them later in the right context.  In the case of letrec and fix, this
  allows mutually-recursive bindings to be inlined.

  Refactor folding of "constructors" (which still need renaming) to
  avoid visiting operands twice in some contexts.

  For applications, if we have to abort, process the procedure in call
  context, which allows some folding but avoids copying lambdas.  If we
  find a recursive procedure, mark intervening counters as recursive
  too, to allow for mutual recursion at the top level.

  For lambdas, if we are processing for value, record the source
  expression so we can detect recursion.  This was previously done in
  the lexical-ref copy propagator.

* test-suite/tests/tree-il.test ("partial evaluation"): Remove unused
  recursive lexicals in a couple of cases.  Add a couple test cases for
  pruning.  Add a few recursive binding cases.

12 years agopeval: add operand structure
Andy Wingo [Thu, 6 Oct 2011 08:56:12 +0000 (10:56 +0200)]
peval: add operand structure

* module/language/tree-il/peval.scm (<operand>): Add operand structure,
  to be used by peval.

12 years agopeval: refactor logging
Andy Wingo [Mon, 10 Oct 2011 10:03:17 +0000 (12:03 +0200)]
peval: refactor logging

* module/language/tree-il/peval.scm: Make it easier to turn on logging.

12 years agoNew functions scm_is_exact and scm_is_inexact
Mike Gran [Mon, 10 Oct 2011 03:54:37 +0000 (20:54 -0700)]
New functions scm_is_exact and scm_is_inexact

* doc/ref/api-data.texi (Exact and Inexact Numbers): doc for scm_is_exact
  and scm_is_inexact
* libguile/numbers.c (scm_is_exact, scm_is_inexact): new functions
* libguile/numbers.h: declarations for scm_is_exact and scm_is_inexact
* test/suite/standalone/test-conversion.c (test_is_exact, test_is_inexact):
  new tests

12 years agoDocument SCM_ASSERT_TYPE and SCM_ASRTGO macros
Mike Gran [Sun, 9 Oct 2011 00:12:12 +0000 (17:12 -0700)]
Document SCM_ASSERT_TYPE and SCM_ASRTGO macros

* doc/ref/api-control.texi (Signalling Type Errors): document macros

12 years agopeval: logging
Andy Wingo [Fri, 7 Oct 2011 13:49:36 +0000 (15:49 +0200)]
peval: logging

* module/language/tree-il/peval.scm: Define a quick and dirty
  infrastructure for logging.  Use it in peval.

12 years agopeval: bugfix in constant-expression?
Andy Wingo [Thu, 6 Oct 2011 21:28:19 +0000 (23:28 +0200)]
peval: bugfix in constant-expression?

* module/language/tree-il/peval.scm (constant-expression?): Correctly
  handle lambda-case alternates.

12 years agooptimizer verifies its output
Andy Wingo [Thu, 6 Oct 2011 21:28:06 +0000 (23:28 +0200)]
optimizer verifies its output

* module/language/tree-il/optimize.scm: Verify the result of partial
  evaluation.

12 years agoadd tree-il verifier
Andy Wingo [Thu, 6 Oct 2011 21:27:43 +0000 (23:27 +0200)]
add tree-il verifier

* module/Makefile.am: Add debug.scm.
* module/language/tree-il/debug.scm: New file, a verifier for tree-il.

12 years agopeval refactor
Andy Wingo [Thu, 6 Oct 2011 10:14:10 +0000 (12:14 +0200)]
peval refactor

* module/language/tree-il/peval.scm (peval): Refactor the for-value, etc
  helpers.

12 years agocomment peval.scm
Andy Wingo [Thu, 6 Oct 2011 08:39:14 +0000 (10:39 +0200)]
comment peval.scm

* module/language/tree-il/peval.scm: Add comments.  Move alpha-rename
  later in the file.

12 years agofix reading of #||||#
Andy Wingo [Wed, 5 Oct 2011 18:41:11 +0000 (20:41 +0200)]
fix reading of #||||#

* libguile/read.c (scm_read_r6rs_block_comment):
* test-suite/tests/reader.test ("reading"): Fix reading of #||||#,
  originally reported in bug debbugs.gnu.org/9672, by Bruno Haible.
  Thanks, Bruno!

12 years agopeval: Add test for possible infinite recursion.
Ludovic Courtès [Fri, 30 Sep 2011 13:20:16 +0000 (15:20 +0200)]
peval: Add test for possible infinite recursion.

* test-suite/tests/tree-il.test ("partial evaluation"): Add test.

12 years agoAdd link to the (ice-9 match) bug.
Ludovic Courtès [Fri, 30 Sep 2011 13:16:02 +0000 (15:16 +0200)]
Add link to the (ice-9 match) bug.

* module/ice-9/match.scm: Add comment.

12 years agopeval: Recognize module-refs to primitives.
Ludovic Courtès [Fri, 23 Sep 2011 15:27:28 +0000 (17:27 +0200)]
peval: Recognize module-refs to primitives.

* module/language/tree-il/optimize.scm (peval): Handle module-refs to
  primitives.

* test-suite/tests/tree-il.test ("partial evaluation"): Add test, using
  `pmatch'.

12 years agoregenerate psyntax-pp.scm
Andy Wingo [Thu, 29 Sep 2011 16:07:02 +0000 (18:07 +0200)]
regenerate psyntax-pp.scm

* module/ice-9/psyntax-pp.scm: Regenerate.

12 years agoMerge remote-tracking branch 'origin/stable-2.0'
Andy Wingo [Thu, 29 Sep 2011 16:02:28 +0000 (18:02 +0200)]
Merge remote-tracking branch 'origin/stable-2.0'

This was a pretty big merge involving a fair amount of porting,
especially to peval and its tests.  I did not update psyntax-pp.scm,
that comes in the next commit.

Conflicts:
module/ice-9/boot-9.scm
module/ice-9/psyntax-pp.scm
module/language/ecmascript/compile-tree-il.scm
module/language/tree-il.scm
module/language/tree-il/analyze.scm
module/language/tree-il/inline.scm
test-suite/tests/tree-il.test

12 years agogenerate psyntax-pp in canonical form
Andy Wingo [Wed, 28 Sep 2011 17:42:32 +0000 (19:42 +0200)]
generate psyntax-pp in canonical form

* module/ice-9/compile-psyntax.scm (source): Canonicalize after
  optimizing.  The optimizer should be a little more clever, but
  currently fix-letrec outputs some non-canonical forms.

* module/ice-9/psyntax-pp.scm: Regenerate.

12 years agoseparate peval and a new canonicalization pass into their own modules
Andy Wingo [Wed, 28 Sep 2011 17:39:25 +0000 (19:39 +0200)]
separate peval and a new canonicalization pass into their own modules

* module/language/tree-il/peval.scm: Move to its own file.  Remove the
  bits about <prompt> thunk-application bodies, as they are not
  optimizations, simply expectations of the compiler.  `canonicalize'
  handles that now.

* module/language/tree-il/optimize.scm: Use peval from its module.
  Don't call `inline!', as that's useless now.

* module/language/tree-il/canonicalize.scm: New file, implementing a
  pass that `compile-tree-il' runs on the result from the optimizer.
  The compiler currently expects a <let> form to have bindings, for
  example, and this pass turns a <let> without bindings into its body.

* module/language/tree-il/inline.scm: Deprecate, as `peval' does
  everything this function ever did.

* module/language/tree-il/compile-glil.scm: Canonicalize after
  optimizing.  This should allow us to skip the optimizer entirely, if
  we want.

* module/Makefile.am: Update and reorder a little bit.

12 years agoregenerate psyntax-pp.scm, with optimizations
Andy Wingo [Tue, 27 Sep 2011 13:09:25 +0000 (15:09 +0200)]
regenerate psyntax-pp.scm, with optimizations

* module/ice-9/psyntax-pp.scm: Regenerate.

12 years ago((lambda ...) ...) fix
Andy Wingo [Tue, 27 Sep 2011 21:29:10 +0000 (23:29 +0200)]
((lambda ...) ...) fix

* module/language/tree-il/optimize.scm (peval): If it's a lambda in the
  operator position, inline without a nested counter, as it's not
  possible to increase code size.

12 years agopeval: more effective binding pruning
Andy Wingo [Tue, 27 Sep 2011 21:21:53 +0000 (23:21 +0200)]
peval: more effective binding pruning

* module/language/tree-il/optimize.scm (peval): Factor prune-bindings
  out of `let' and company.  Have it process unreferenced bindings in
  effect context instead of always residualizing non-constant
  expressions.

12 years agodon't propagate pure primcalls that might not type-check
Andy Wingo [Tue, 27 Sep 2011 21:20:49 +0000 (23:20 +0200)]
don't propagate pure primcalls that might not type-check

* module/language/tree-il/optimize.scm (types-check?): New helper, to
  determine if a primcall will apply without throwing an exception.
  (peval): constant-expression? returns #f for expressions that don't
  types-check?.  Effect-free primitives that type-check are void.

12 years agofix unparse-tree-il of <dynset>
Andy Wingo [Tue, 27 Sep 2011 13:08:39 +0000 (15:08 +0200)]
fix unparse-tree-il of <dynset>

* module/language/tree-il.scm (unparse-tree-il): Fix printing of
  `dynset'.

12 years agopeval works on all expressions
Andy Wingo [Tue, 27 Sep 2011 13:08:17 +0000 (15:08 +0200)]
peval works on all expressions

* module/language/tree-il/optimize.scm (alpha-rename, peval): Add
  <dynset> cases.  Allow any kind of <application>.  Remove the `catch'
  wrapper as now peval handles all kinds of expressions.

12 years agopeval: elide make-prompt-tag in effect context
Andy Wingo [Tue, 27 Sep 2011 11:42:43 +0000 (13:42 +0200)]
peval: elide make-prompt-tag in effect context

* module/language/tree-il/optimize.scm (peval): Fix a duplicate
  traversal for constructors in effect or test context.  Add support for
  eliding make-prompt-tag.

* test-suite/tests/tree-il.test ("partial evaluation"): Update the test
  for make-prompt-tag elision.

12 years agopeval: add support for <prompt> and <abort>
Andy Wingo [Tue, 27 Sep 2011 11:39:29 +0000 (13:39 +0200)]
peval: add support for <prompt> and <abort>

* module/language/tree-il/optimize.scm (alpha-rename, peval): Handle
  <prompt> and <abort>.  Attempt to remove the prompt if the tag is
  otherwise unreferenced.

* module/language/tree-il/primitives.scm (*primitive-constructors*): Add
  make-prompt-tag as a constructor.

* test-suite/tests/tree-il.test ("partial evaluation"): Add a test that
  an prompt whose tag is unreferenced is removed.

12 years agopeval: fix algorithmic behavior of `cons'
Andy Wingo [Tue, 27 Sep 2011 07:48:18 +0000 (09:48 +0200)]
peval: fix algorithmic behavior of `cons'

* module/language/tree-il/optimize.scm (peval): Fix treatment of `cons'
  to not process the value twice, leading to n^2 work.  This prevented
  primitives.scm from compiling in a reasonable amount of time, because
  it contained a `(foo ... ,@bar) form that resulted in a long sequence
  of nested conses, and no effort counter was in place as it was not
  within an inlining attempt.

12 years agodoc: (ice-9 match) doesn't have `__1'.
Ludovic Courtès [Tue, 27 Sep 2011 16:00:20 +0000 (18:00 +0200)]
doc: (ice-9 match) doesn't have `__1'.

* doc/ref/match.texi (Pattern Matching): Remove `__1', which doesn't
  exist.  Thanks to Chris K. Jester-Young.

12 years agodoc: Update (ice-9 match) reference.
Ludovic Courtès [Tue, 27 Sep 2011 11:46:35 +0000 (13:46 +0200)]
doc: Update (ice-9 match) reference.

* doc/ref/match.texi (Pattern Matching): Document `***', `..1', and
  `__1'; remove `..k' and `__k'.  Reported by Chris K. Jester-Young.

12 years agodoc: Fix typesetting of function definitions in "Accessing Modules from C".
Ludovic Courtès [Tue, 27 Sep 2011 11:41:21 +0000 (13:41 +0200)]
doc: Fix typesetting of function definitions in "Accessing Modules from C".

* doc/ref/api-modules.texi (Accessing Modules from C): Use the phrase "C
  Function" instead of "C Procedure".  Enclose multiple-word type names
  in braces.  Reported by Dale P. Smith.

12 years agopeval: more strict accounting
Andy Wingo [Mon, 26 Sep 2011 22:21:16 +0000 (00:21 +0200)]
peval: more strict accounting

* module/language/tree-il/optimize.scm (transfer!, make-nested-counter):
  (make-recursive-counter, peval): Limit the algorithm's time to be
  strictly O(N) by transferring effort and size counters of recursive
  inlining attempts from containing counters.

* test-suite/tests/tree-il.test ("partial evaluation"): Update
  expectations for the ((lambda (x) (x x)) (lambda (x) (x x))) case, as
  the new accounting policy will cause the entire inlining attempt to
  abort.

12 years agopeval: fix inlining of lambda* with #:optional
Andy Wingo [Mon, 26 Sep 2011 20:32:45 +0000 (22:32 +0200)]
peval: fix inlining of lambda* with #:optional

* module/language/tree-il/optimize.scm (peval): Fix calculation of how
  many init expressions to drop when inlining lambdas.

* test-suite/tests/tree-il.test ("partial evaluation"): Add tests.

12 years agoremove unused peval helpers
Andy Wingo [Mon, 26 Sep 2011 20:24:00 +0000 (22:24 +0200)]
remove unused peval helpers

* module/language/tree-il/optimize.scm (peval): Remove a couple unused
  helpers.

12 years agopeval: simpler and more precise treatment of mutability
Andy Wingo [Fri, 23 Sep 2011 10:43:04 +0000 (12:43 +0200)]
peval: simpler and more precise treatment of mutability

* module/language/tree-il/optimize.scm (peval): The old approach of
  optimistically producing constants and then de-constifying them at
  their uses was not only cumbersome but incorrect: it both failed to
  preserve identity in some cases and failed to retain immutable
  constant values.  Instead, now we only produce constants if they
  really are constant and immutable.  The constant folder has to have a
  few more algebraic cases to be as effective as it was, to destructure
  (car (cons _ _)) appropriately.  On the plus side, now constructors
  and deconstructors can handle impure cases more generally.

* test-suite/tests/tree-il.test ("partial evaluation"): Add constructor
  and destructuring tests.  Adapt other tests to new expectations.

12 years agopeval: add a bunch of missing maybe-unconst calls
Andy Wingo [Sun, 25 Sep 2011 00:54:34 +0000 (02:54 +0200)]
peval: add a bunch of missing maybe-unconst calls

* module/language/tree-il/optimize.scm (peval): Add missing
  maybe-unconst calls.  Things are getting ugly.  They will get better
  in the next commit though.

12 years agopeval uses effort counters, propagates lambdas more effectively
Andy Wingo [Thu, 22 Sep 2011 22:29:14 +0000 (00:29 +0200)]
peval uses effort counters, propagates lambdas more effectively

* module/language/tree-il/optimize.scm (code-contains-calls?): Remove
  this helper, we will deal with recursion when it happens, not after
  the fact.
  (peval): Add keyword args for various size and effort limits.  Instead
  of keeping a call stack, keep a chain of <counter> records, each with
  an abort continuation.  If ever an inlining attempt is taking too
  long, measured in terms of number of trips through the main loop, the
  counter will abort.  Add new contexts, `operator' and `operand'.  They
  have different default size limits.  In the future we should actually
  use the size counter, instead of these heuristics.

  The <lexical-ref> case is smarter now, and tries to avoid propagating
  too much data.  Perhaps it should be dumber though, and use a
  counter.  That would require changes to the environment structure.

  Inline <lambda> applications to <let>, so that we allow residual
  lexical references to have bindings.  Add a `for-operand' helper, and
  use it for the RHS of `let' expressions.  A `let' is an inlined
  `lambda'.

  `Let' and company no longer elide bindings if the result is a
  constant, as the arguments could have effects.  Peval will still do as
  much as it can, though.

* test-suite/tests/tree-il.test ("partial evaluation"): Update the tests
  for the new expectations.  They are uniformly awesomer, with the
  exception of two cases in which pure but not constant data is not
  propagated.

12 years agoprune unused letrec bindings
Andy Wingo [Thu, 22 Sep 2011 22:21:46 +0000 (00:21 +0200)]
prune unused letrec bindings

* module/language/tree-il/optimize.scm (peval): Prune unused `letrec'
  bindings.

12 years agomore peval refactoring
Andy Wingo [Thu, 22 Sep 2011 22:18:13 +0000 (00:18 +0200)]
more peval refactoring

* module/language/tree-il/optimize.scm (peval): Rename `var-table' to
  `store', as we're going to put some more things in it.  Rename
  `record-lexical-bindings' to `record-source-expression', which also
  takes the original, pre-renaming expression.  Keep a mapping from new
  expressions to original expressions, available using the
  `source-expression' helper.

12 years agoadd helpers for effort counters
Andy Wingo [Thu, 22 Sep 2011 22:12:21 +0000 (00:12 +0200)]
add helpers for effort counters

* module/language/tree-il/optimize.scm (<counter>, abort-counter)
  (record-effort!, record-size!, find-counter, make-top-counter)
  (make-nested-counter, make-recursive-counter): New helpers, as yet
  unused, but which will implement fixed effort bounds on the inlining
  algorithm.

12 years agopeval refactor
Andy Wingo [Thu, 22 Sep 2011 22:05:27 +0000 (00:05 +0200)]
peval refactor

* module/language/tree-il/optimize.scm (peval): Add for-value, for-test,
  for-effect, and for-tail helpers.  Use them.

12 years agoattempt to prune unreferenced bindings
Andy Wingo [Thu, 22 Sep 2011 13:56:22 +0000 (15:56 +0200)]
attempt to prune unreferenced bindings

* module/language/tree-il/optimize.scm (peval): Rename `record-lexicals'
  to `record-lexical-bindings'.  Record residualized lexical
  references.  Record lexical references in maybe-unlambda.
  Unfortunately this has the disadvantage that the speculative mapping
  of lambda expressions to lexical references records that reference,
  even if we are not going to residualize it.  After processing a `let',
  prune pure unreferenced bindings.  (We can do better than this in the
  future: we can simply process them for effect.)

* test-suite/tests/tree-il.test (pass-if-peval): More debugging.
  ("partial evaluation"): Update to reflect the fact that the `y'
  binding won't be emitted.

12 years agopeval handles lexical-set
Andy Wingo [Thu, 22 Sep 2011 11:16:36 +0000 (13:16 +0200)]
peval handles lexical-set

* module/language/tree-il/optimize.scm (alpha-rename, peval): Add
  support for lexical-set, while avoiding copy propagation and pruning
  of assigned variables.

12 years agopeval: pre-analyze mutated or reffed-once lexicals
Andy Wingo [Wed, 21 Sep 2011 21:59:02 +0000 (23:59 +0200)]
peval: pre-analyze mutated or reffed-once lexicals

* module/language/tree-il/optimize.scm (<var>, build-var-table, peval):
  Before going into peval, build a table indicating refcounts and a set?
  flag for all lexicals.  Add to the table when introducing new bindings
  (via alpha-renaming).

12 years agopeval: don't propagate expressions that access memory
Andy Wingo [Sat, 24 Sep 2011 16:57:59 +0000 (18:57 +0200)]
peval: don't propagate expressions that access memory

* module/language/tree-il/optimize.scm (peval): Rename
  `pure-expression?' to `constant-expression?', in the sense of GCC's
  `pure' and `const'.  A <toplevel-ref> is not constant, because it can
  be mutated.  A <dynref> isn't constant either, for the same reason.

* test-suite/tests/tree-il.test ("partial evaluation"): Add a test, and
  update existing tests that assumed that toplevel-ref would propagate.

12 years agocontext-specific folding for peval in test and effect contexts
Andy Wingo [Thu, 22 Sep 2011 10:06:21 +0000 (12:06 +0200)]
context-specific folding for peval in test and effect contexts

* module/language/tree-il/optimize.scm (peval): Add a "test" context,
  which folds statically decidable values to <const>.  Fold pure
  expressions to <void> in "effect" contexts.  Adapt the <conditional>
  and <sequence> tests to simply look for <const> or <void> expressions,
  respectively.

12 years agothread a context through peval
Andy Wingo [Thu, 22 Sep 2011 09:23:06 +0000 (11:23 +0200)]
thread a context through peval

* module/language/tree-il/optimize.scm (peval): Thread a "context"
  through the evaluator.

12 years agopaper around `match' bug
Andy Wingo [Sat, 24 Sep 2011 15:05:30 +0000 (17:05 +0200)]
paper around `match' bug

* module/ice-9/match.scm (match): Always introduce a lexical binding, to
  avoid http://debbugs.gnu.org/9567.  Real fix ongoing.  Patch and
  original report by Stefan Israelsson Tampe.

* test-suite/tests/match.test: Add test.

12 years agopeval: various bugfixes
Andy Wingo [Sat, 24 Sep 2011 15:15:32 +0000 (17:15 +0200)]
peval: various bugfixes

* module/language/tree-il/optimize.scm (alpha-rename): Rename the
  init
  expressions of a <lambda-case>.
  (peval): Coalesce the <let-values> clauses.
  Fix pure-expression? matching of <lambda> clauses.
  Loop over and maybe-unconst the inits of a <lambda-case>.

12 years agotree-il-any bugfix
Andy Wingo [Thu, 22 Sep 2011 12:14:02 +0000 (14:14 +0200)]
tree-il-any bugfix

* module/language/tree-il/optimize.scm (tree-il-any): Fix to be called
  on all values, including leaves.  It didn't matter for the use case,
  though.

12 years agominor peval style tweak
Andy Wingo [Thu, 22 Sep 2011 10:26:02 +0000 (12:26 +0200)]
minor peval style tweak

* module/language/tree-il/optimize.scm (peval): Minor refactor to
  <lexical-ref> copy propagation.

12 years agofix alpha-rename for kwargs
Andy Wingo [Thu, 22 Sep 2011 15:43:36 +0000 (17:43 +0200)]
fix alpha-rename for kwargs

* module/language/tree-il/optimize.scm (alpha-rename): Fix
  alpha-renaming of keyword arguments.

12 years agopeval: Add test for multiple-value returns.
Ludovic Courtès [Wed, 21 Sep 2011 20:56:45 +0000 (22:56 +0200)]
peval: Add test for multiple-value returns.

* test-suite/tests/tree-il.test (pass-if-peval): Support the
  `resolve-primitives' keyword.
  ("partial evaluation"): Add test for `call-with-values'.

12 years agopeval: Rectify style.
Ludovic Courtès [Wed, 21 Sep 2011 13:17:56 +0000 (15:17 +0200)]
peval: Rectify style.

* module/language/tree-il/optimize.scm (peval): Rename `src' to
  `lv-src', and `src2' to `src'; pass `make-let-values' the right source
  locations.  Reindent `let*'.

12 years agoprevent propagation for memory-dependent operations like `car'
Andy Wingo [Fri, 23 Sep 2011 16:02:05 +0000 (18:02 +0200)]
prevent propagation for memory-dependent operations like `car'

* module/language/tree-il/primitives.scm (*primitive-constructors*):
  Record car, cdr, vector-ref, and struct-ref as "constructors".
  Comment to come later.
  (*effect-free-primitives*): Update.

* test-suite/tests/tree-il.test ("partial evaluation"): Add tests.

12 years agopeval comment & reindentation
Andy Wingo [Wed, 21 Sep 2011 06:50:45 +0000 (08:50 +0200)]
peval comment & reindentation

* module/language/tree-il/optimize.scm (peval): Add a comment regarding
  failure modes, and reindent one clause.

12 years agofix comment regarding alpha-renaming
Andy Wingo [Wed, 21 Sep 2011 06:49:36 +0000 (08:49 +0200)]
fix comment regarding alpha-renaming

* module/language/tree-il/optimize.scm (peval): Fix comment regarding
  alpha-renaming: it's not simply the allocator that needs unique names;
  rather, all transformations depend on it.

12 years agobetter pure-expression?
Andy Wingo [Wed, 21 Sep 2011 06:46:44 +0000 (08:46 +0200)]
better pure-expression?

* module/language/tree-il/optimize.scm (peval): Allow dynref, fix, and
  let-values to be pure expressions.

12 years agomore alpha-rename robustness
Andy Wingo [Wed, 21 Sep 2011 06:46:03 +0000 (08:46 +0200)]
more alpha-rename robustness

* module/language/tree-il/optimize.scm (alpha-rename): Handle all kinds
  of tree-il, with the current exceptions of lexical set!, prompt, and
  abort.

12 years agomore robust alpha-renaming
Andy Wingo [Wed, 21 Sep 2011 06:44:19 +0000 (08:44 +0200)]
more robust alpha-renaming

* module/language/tree-il/optimize.scm (fresh-gensyms): New helper.
  (alpha-rename): Name the new gensyms using the old names as templates,
  not the old gensyms.  This prevents accidental collisions between
  gensyms, if #{x 1}# becomes #{x 12}# instead of #{x 2}#.

12 years agopeval: inlining of let-values
Andy Wingo [Wed, 21 Sep 2011 06:58:09 +0000 (08:58 +0200)]
peval: inlining of let-values

* module/language/tree-il/optimize.scm (peval): Add support for
  let-values.  Try to inline the consumer into the body of the producer,
  if there is only one return point, and we can figure out how many
  values are being returned, and that number is compatible with the
  consumer.

12 years agopeval support for more forms
Andy Wingo [Wed, 21 Sep 2011 06:56:09 +0000 (08:56 +0200)]
peval support for more forms

* module/language/tree-il/optimize.scm (peval): Add support for fix,
  dynwind, dynlet, dynref, module-set, and toplevel-set.  (Mutating a
  variable directly is similar to calling a function that does so behind
  our backs, so this presents no additional problem.)

12 years agoadd singly-valued-primitive?
Andy Wingo [Wed, 21 Sep 2011 06:53:06 +0000 (08:53 +0200)]
add singly-valued-primitive?

* module/language/tree-il/primitives.scm (singly-valued-primitive?): New
  predicate, for primitives that return exactly one value.

12 years agomore optimize.scm factoring
Andy Wingo [Tue, 20 Sep 2011 00:59:53 +0000 (20:59 -0400)]
more optimize.scm factoring

* module/language/tree-il/optimize.scm (vlist-any): New helper.
  (peval): Use it here.

12 years agooptimize.scm refactor
Andy Wingo [Tue, 20 Sep 2011 00:49:50 +0000 (20:49 -0400)]
optimize.scm refactor

* module/language/tree-il/optimize.scm (let/ec, tree-il-any): New
  helpers.
  (code-contains-calls?): Use them here.

12 years agoFix compilation of untyped arrays of rank not 1
Daniel Llorens [Mon, 5 Sep 2011 09:09:08 +0000 (11:09 +0200)]
Fix compilation of untyped arrays of rank not 1

* module/language/glil/compile-assembly.scm: vector-fold2 expects vector.

12 years agoRemove extraneous semicolon from `SCM_STATIC_SUBR_OBJVECT' to prevent ISO C90 warning.
Julian Graham [Sun, 18 Sep 2011 20:58:47 +0000 (16:58 -0400)]
Remove extraneous semicolon from `SCM_STATIC_SUBR_OBJVECT' to prevent ISO C90 warning.

* snarf.h (SCM_STATIC_SUBR_OBJVECT): Remove semicolon at end of macro
  definition.

12 years agopeval: Abort inlining when the residual code contains recursive calls.
Ludovic Courtès [Sun, 18 Sep 2011 21:01:51 +0000 (23:01 +0200)]
peval: Abort inlining when the residual code contains recursive calls.

* module/language/tree-il/optimize.scm (code-contains-calls?): New
  procedure.
  (peval): Use it and abort inlining if the residual code of a procedure
  application contains recursive calls.  Suggested by Wingo, Waddell,
  and Dybvig.  Fixes <http://debbugs.gnu.org/9542>.

* test-suite/tests/tree-il.test ("partial evaluation"): Update 2 tests
  that relied on the previous behavior.  Add 1 another test.

12 years agopeval: Improve alpha-renaming test.
Ludovic Courtès [Sun, 18 Sep 2011 20:34:40 +0000 (22:34 +0200)]
peval: Improve alpha-renaming test.

* test-suite/tests/tree-il.test ("partial evaluation")["inlined lambdas
  are alpha-renamed"]: Rewrite.

12 years agoArrange so that stack-cleaning loops in GC tests are not optimized out.
Ludovic Courtès [Sun, 18 Sep 2011 19:41:25 +0000 (21:41 +0200)]
Arrange so that stack-cleaning loops in GC tests are not optimized out.

* test-suite/tests/gc.test (stack-cleanup): New procedure.
  ("Unused modules are removed"): Use it.

* test-suite/tests/threads.test (stack-cleanup): Likewise.
  ("mutex with owner not retained (bug #27450)"): Use it.

12 years agopeval: Typo.
Ludovic Courtès [Sat, 17 Sep 2011 14:53:23 +0000 (16:53 +0200)]
peval: Typo.

* module/language/tree-il/optimize.scm (peval)[maybe-unlambda]: Fix
  typo in comment.

12 years agopeval: Alpha-rename anonymous lambdas that are duplicated.
Ludovic Courtès [Sat, 17 Sep 2011 14:49:41 +0000 (16:49 +0200)]
peval: Alpha-rename anonymous lambdas that are duplicated.

* module/language/tree-il/optimize.scm (alpha-rename): New procedure.
  (peval)[maybe-unlambda]: Use it.

* test-suite/tests/tree-il.test ("partial evaluation"): Add two test
  cases for <https://lists.gnu.org/archive/html/bug-guile/2011-09/msg00019.html>.

12 years agoRevert "SCM is a union"
Andy Wingo [Thu, 15 Sep 2011 19:28:17 +0000 (12:28 -0700)]
Revert "SCM is a union"

This reverts commit 8787d7a17029a8add20bb8e652ec744bc5d4e6c4.

12 years agoRevert "SCM is either a union or scm_t_bits"
Andy Wingo [Thu, 15 Sep 2011 19:28:03 +0000 (12:28 -0700)]
Revert "SCM is either a union or scm_t_bits"

This reverts commit 80125469ef95f6d8d46a26619fb2f85151f32719.

Conflicts:

libguile/__scm.h