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

41 commits

Author SHA1 Message Date
Andy Wingo
e2fafeb901 Keywords have a tc7
* libguile/tags.h (scm_tc7_keyword): Allocate a tc7, so that the VM can
  have cheap keyword? tests.

* libguile/keywords.c:
* libguile/keywords.h: Adapt.

* libguile/goops.c (scm_class_of, scm_sys_goops_early_init): Capture
  <keyword>.

* libguile/print.c (iprin1): Inline keyword printer.

* libguile/evalext.c (scm_self_evaluating_p): Add keywords here.

* libguile/deprecated.h:
* libguile/deprecated.c (scm_tc16_keyword): Deprecate.

* module/language/cps/compile-bytecode.scm (compile-fun): Add keyword?
  case, and bitvector? case while we're at it.
* module/language/cps/effects-analysis.scm (define-primitive-effects):
  Add bytevector?, keyword?, and bitvector? cases.

* module/language/cps/primitives.scm (*branching-primcall-arities*): Add
  keyword?.

* module/language/cps/types.scm (bitvector?, keyword?, bytevector?): Add
  branch inferrers.

* module/language/tree-il/primitives.scm (*interesting-primitive-names*):
  (*effect-free-primitives*):
  (*effect+exception-free-primitives*): Add bytevector?, keyword?, and
  bitvector?.

* module/oop/goops.scm (<keyword>): New class.

* module/system/base/types.scm (%tc7-keyword, cell->object): Add cases.

* module/system/vm/assembler.scm (br-if-keyword): New definition.
* module/system/vm/disassembler.scm (code-annotation): Add br-if-tc7
  case for keywords.

* test-suite/tests/types.test ("clonable objects"): Update now that
  keywords are cloneable.
2015-01-22 13:03:11 +01:00
Andy Wingo
27b3b5b92d Add allocate-struct, struct-ref, struct-set! instructions
* libguile/vm-engine.c (allocate-struct, struct-ref, struct-set!): New
  instructions, to complement their "immediate" variants.

* module/language/cps/compile-bytecode.scm (compile-fun):
* module/system/vm/assembler.scm (system): Wire up the new instructions.
2015-01-22 12:53:33 +01:00
Andy Wingo
d613ccaaa0 Compiler emits br-if-logtest
* module/language/cps/compile-bytecode.scm (compile-fun):
* module/language/cps/primitives.scm (*branching-primcall-arities*):
* module/language/cps/type-fold.scm (logtest):
* module/language/cps/types.scm (logtest):
* module/system/vm/assembler.scm (system):
* module/system/vm/disassembler.scm (compute-labels): Add backend
  support for the logtest instruction.
2014-07-03 15:03:40 +02:00
Andy Wingo
59258f7cad Remove $kif
* module/language/cps.scm: Remove $kif.

* module/language/cps/compile-bytecode.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/prune-top-level-scopes.scm:
* module/language/cps/renumber.scm:
* module/language/cps/simplify.scm:
* module/language/cps/slot-allocation.scm:
* module/language/cps/type-fold.scm:
* module/language/cps/types.scm:
* module/language/cps/verify.scm: Adapt.
2014-05-31 21:43:12 -04:00
Andy Wingo
92805e2197 Add $branch expression type
* module/language/cps.scm ($branch): New expression type; will replace
  $kif.

* module/language/cps/arities.scm:
* module/language/cps/closure-conversion.scm:
* module/language/cps/compile-bytecode.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/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/type-fold.scm:
* module/language/cps/types.scm:
* module/language/cps/verify.scm: Adapt to $branch expression type.
2014-05-31 21:15:06 -04:00
Andy Wingo
6129faa0f5 Enable type folding
* module/language/cps/compile-bytecode.scm (optimize): Enable type
  folding.
2014-05-15 17:39:24 +02:00
Andy Wingo
8bc65d2d64 Type and range inference for CPS
* module/language/cps/types.scm: New file, implementing type and range
  inference over CPS.

* module/language/cps/type-fold.scm: New file, implementing abstract
  constant folding for CPS.

* module/Makefile.am: Add the new files.

* module/language/cps/compile-bytecode.scm: Wire up type-fold, but
  currently disabled.
2014-05-15 17:39:19 +02:00
Andy Wingo
d38ca16e2c 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.
2014-04-21 22:47:33 +02:00
Andy Wingo
78351d1065 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.
2014-04-15 14:14:15 +02:00
Andy Wingo
cf8bb03772 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.
2014-04-12 14:59:31 +02:00
Andy Wingo
a0329d0109 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.
2014-04-11 14:01:27 +02:00
Andy Wingo
b85f5f851f 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.
2014-04-11 11:51:34 +02:00
Andy Wingo
6bc36ca55e 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.
2014-04-11 11:34:50 +02:00
Andy Wingo
a16af11320 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.
2014-04-11 11:22:06 +02:00
Andy Wingo
8320f50431 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.
2014-04-10 12:11:35 +02:00
Andy Wingo
24b611e81c 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.
2014-04-10 10:50:17 +02:00
Andy Wingo
c0c93581c4 Remove obsolete comment in compile-bytecode.scm
* module/language/cps/compile-bytecode.scm (optimize): Remove an
  obsolete comment.
2014-04-09 09:05:43 +02:00
Andy Wingo
c4a209b96f 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.
2014-04-08 21:41:42 +02:00
Andy Wingo
85270a8c89 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?.
2014-04-06 11:12:29 +02:00
Andy Wingo
9e94cd9bf5 Prune bailouts after contification
* module/language/cps/compile-bytecode.scm (optimize): Prune bailouts
  after contifying, so that we return to the tail of the contified
  function.
2014-04-05 12:16:39 +02:00
Andy Wingo
634638801c Add prune-bailouts pass
* module/language/cps/prune-bailouts.scm: New pass.
* module/language/cps/compile-bytecode.scm: Wire it up.
* module/Makefile.am: Add new file.
2014-04-05 11:40:21 +02:00
Andy Wingo
7a08e47967 Add common subexpression elimination pass on CPS
* module/language/cps/cse.scm: New file.
* module/language/cps/compile-bytecode.scm: Wire up CSE, on by default.
  Currently using the #:cps-cse? keyword.

* module/Makefile.am: Add new file.
2014-04-04 12:15:10 +02:00
Andy Wingo
f85ce39610 Remove variable-set! clause from compile-fun
* module/language/cps/compile-bytecode.scm (compile-fun): Remove
  vestigial `variable-set!' clause.
2014-04-04 12:05:18 +02:00
Andy Wingo
a8430ab1d7 Compile-fun takes advantage of sorted output of "renumber", avoids CFA
* module/language/cps/dfg.scm ($dfg): Rename nvars and nlabels fields to
  var-count and label-count.  Export dfg-min-var, dfg-min-label,
  dfg-label-count, dfg-var-count.

* module/language/cps/compile-bytecode.scm (compile-fun): No need to
  build a CFA given the renumbering pass.  Adapt to treat labels as
  ordered small integer in a contiguous vector.
2014-04-01 14:51:05 +02:00
Andy Wingo
90dce16db4 Use Tree-IL-like case-lambda clause chaining in CPS
* module/language/cps.scm ($kclause, $kentry): Instead of having an
  entry continuation contain a list of clauses, have the clauses contain
  clauses (as in Tree-IL).  In some ways it's not as convenient but it
  does reflect the continuation tree correctly.

* 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/dce.scm:
* module/language/cps/dfg.scm:
* module/language/cps/elide-values.scm:
* module/language/cps/prune-top-level-scopes.scm:
* module/language/cps/reify-primitives.scm:
* module/language/cps/renumber.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 aaaaaaall users.
2014-03-31 18:54:12 +02:00
Andy Wingo
62b7180bfd Renumber functions before emitting code
* module/language/cps/compile-bytecode.scm (compile-bytecode): Renumber
  a function before going to compile it, so that the vars and labels are
  contiguous within each function.
2014-03-31 18:21:04 +02:00
Andy Wingo
a6f823bd02 Public make-cont-folder
* module/language/cps.scm (make-cont-folder): Add global? parameter, and
  make public.
  (fold-conts): Adapt.
  (fold-local-conts): Use make-cont-folder, and take a function instead
  of a continuation.

* module/language/cps/arities.scm (fix-clause-arities, fix-arities*):
* module/language/cps/compile-bytecode.scm (collect-conts):
* module/language/cps/elide-values.scm (elide-values*): Adapt to
  fold-local-conts change.
2014-03-31 18:21:04 +02:00
Andy Wingo
dd692618b8 Add prune-top-level-scopes pass
* module/language/cps/prune-top-level-scopes.scm: New pass, to prune
  unneeded "cache-current-module!" forms.

* module/language/cps/compile-bytecode.scm:
* module/Makefile.am: Add the new pass to the build and enable by
  default.
2014-02-13 09:30:39 +01:00
Andy Wingo
b3ae2b5068 Add VM and compiler support for calls to known procedures
* module/language/cps.scm ($callk): New expression type, for calls to
  known labels.  Part of "low CPS".
* module/language/cps/arities.scm:
* module/language/cps/closure-conversion.scm:
* module/language/cps/compile-bytecode.scm:
* module/language/cps/dce.scm:
* module/language/cps/dfg.scm:
* module/language/cps/effects-analysis.scm:
* module/language/cps/simplify.scm:
* module/language/cps/slot-allocation.scm:
* module/language/cps/verify.scm: Adapt call sites.

* libguile/vm-engine.c (call-label, tail-call-label): New instructions.
  Renumber the rest; this is an ABI change.

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

* doc/ref/compiler.texi (CPS in Guile): Document $callk.
2014-02-02 23:19:22 +01:00
Andy Wingo
02c624fc09 More precise stack marking via .guile.frame-maps section
* module/language/cps/slot-allocation.scm (lookup-dead-slot-map)
  (allocate-slots): For each non-tail call in a function, compute the
  set of slots that are dead after the function has begun the call.

* module/language/cps/compile-bytecode.scm (compile-fun): Emit the
  `dead-slot-map' macro instruction for non-tail calls.

* module/system/vm/assembler.scm (<asm>): Add `dead-slot-maps' member.
  (dead-slot-map): New macro-instruction.
  (link-frame-maps, link-dynamic-section, link-objects): Write dead
  slots information into .guile.frame-maps sections of ELF files.
* module/system/vm/elf.scm (DT_GUILE_FRAME_MAPS): New definition.

* libguile/loader.h:
* libguile/loader.c (DT_GUILE_FRAME_MAPS, process_dynamic_segment):
  (load_thunk_from_memory, register_elf): Arrange to parse
  DT_GUILE_FRAME_MAPS out of the dynamic section.
  (find_mapped_elf_image_unlocked, find_mapped_elf_image): New helpers.
  (scm_find_mapped_elf_image): Refactor.
  (scm_find_dead_slot_map_unlocked): New interface.

* libguile/vm.c (scm_i_vm_mark_stack): Mark the hottest frame
  conservatively, as before.  Otherwise use the dead slots map, if
  available, to avoid marking data that isn't live.
2014-01-26 20:55:04 +01:00
Andy Wingo
3652769585 Rename $ktrunc to $kreceive
* module/language/cps.scm ($kreceive): Rename from ktrunc.

* module/language/cps/arities.scm:
* module/language/cps/compile-bytecode.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/simplify.scm:
* module/language/cps/slot-allocation.scm:
* module/language/cps/verify.scm:
* module/language/tree-il/compile-cps.scm: Adapt all users.
2014-01-12 12:37:05 +01:00
Andy Wingo
97cfb467f9 Returning too many values to call-with-values raises a runtime error
* module/language/cps/compile-bytecode.scm (compile-fun): Now that all
  $call expressions continue to $ktail or $ktrunc, remove the $kargs
  case, and make receive-values bail if too many values are returned.
2014-01-12 12:28:12 +01:00
Andy Wingo
22a79b55b8 Add simplification pass
* module/Makefile.am:
* module/language/cps/compile-bytecode.scm:
* module/language/cps/simplify.scm: New pass.
2014-01-11 16:01:18 +01:00
Andy Wingo
305cccb43c Add DCE pass.
* module/language/cps/dce.scm: New pass.
* module/Makefile.am:
* module/language/cps/compile-bytecode.scm: Wire up the new pass.
2014-01-11 16:01:11 +01:00
Andy Wingo
e4fa7d403a Prefer "receive" over "receive-values"+"reset-frame"
* module/language/cps/compile-bytecode.scm (compile-fun): Attempt to
  emit "receive" instead of "receive-values"+"reset-frame" where
  possible.
2014-01-11 16:01:11 +01:00
Andy Wingo
4dfcb36006 Only emit receive-values if it is needed
* module/language/cps/compile-bytecode.scm (compile-fun): Don't emit
  receive-values unless there is a minimum or maximum number of values.
2014-01-11 16:01:11 +01:00
Andy Wingo
7ab76a830b Remove "pop" from $prompt
* module/language/cps.scm:
* module/language/cps/closure-conversion.scm:
* module/language/cps/compile-bytecode.scm:
* module/language/cps/dfg.scm:
* module/language/cps/slot-allocation.scm:
* module/language/cps/verify.scm:
* module/language/tree-il/compile-cps.scm: Remove "pop" member from
  $prompt data type, as it is no longer used.
2014-01-11 16:01:11 +01:00
Andy Wingo
58ef5f0712 Fix constant-needs-allocation? for $values uses
* module/language/cps/dfg.scm (constant-needs-allocation?): Use of a
  constant in a $values expression of any arity does not cause slot
  allocation.

* module/language/cps/compile-bytecode.scm (compile-fun): Allow $values
  with a constant value to be compiled in test context.  Really we
  should fold these in a previous pass!
2014-01-11 16:01:10 +01:00
Andy Wingo
d59060ce99 Fix prim -> VM op mapping for u8/s8 bytevector ops
* module/language/cps/primitives.scm (*instruction-aliases*): Fix
  aliases for bytevector u8 / s8 operations.

* module/language/cps/compile-bytecode.scm (compile-fun): Fix s8
  operations.
2014-01-11 16:01:10 +01:00
Andy Wingo
fa48a2f79a (call-with-values foo (lambda (a . b) a)) avoids consing rest list
* module/language/cps/slot-allocation.scm (allocate-slots): Don't
  allocate slots to unused results of function calls.  This can allow us
  to avoid consing a rest list for call-with-values with an ignored rest
  parameter, and can improve the parallel move code.

* module/language/cps/compile-bytecode.scm (compile-fun): Adapt to avoid
  emitting bind-rest in values context if the rest arg is unused.
2013-12-06 11:08:45 +01:00
Andy Wingo
691697de09 Rename "RTL" to "bytecode"
"RTL" didn't make any sense, and now that there's no other bytecode to
disambiguate against, just call it bytecode.

* module/Makefile.am:
* module/ice-9/eval-string.scm:
* module/language/bytecode.scm:
* module/language/bytecode/spec.scm:
* module/language/cps/arities.scm:
* module/language/cps/compile-bytecode.scm:
* module/language/cps/compile-rtl.scm:
* module/language/cps/contification.scm:
* module/language/cps/elide-values.scm:
* module/language/cps/primitives.scm:
* module/language/cps/reify-primitives.scm:
* module/language/cps/spec.scm:
* module/language/cps/specialize-primcalls.scm:
* module/language/rtl.scm:
* module/language/rtl/spec.scm:
* module/scripts/compile.scm:
* module/system/base/compile.scm:
* module/system/repl/common.scm:
* module/system/vm/assembler.scm:
* module/system/vm/debug.scm:
* module/system/vm/disassembler.scm:
* module/system/vm/dwarf.scm:
* test-suite/tests/cross-compilation.test:
* test-suite/tests/dwarf.test:
* test-suite/tests/rtl-compilation.test:
* test-suite/tests/rtl.test:
* test-suite/vm/run-vm-tests.scm: Fixups.
2013-12-02 21:31:47 +01:00
Renamed from module/language/cps/compile-rtl.scm (Browse further)