1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-01 04:10:18 +02:00
Commit graph

1799 commits

Author SHA1 Message Date
Andy Wingo
2f45cfcb9c free-ref, free-set take immediate parameters
* module/language/cps/closure-conversion.scm (convert-one):
* module/language/cps/compile-bytecode.scm (compile-function):
* module/language/cps/effects-analysis.scm (define-primitive-effects*)
  (expression-effects, primitive-effects): Only fall back to passing
  constant table if the immediate parameter is false.  Adapt closure
  effects analysis.
* module/language/cps/slot-allocation.scm (compute-needs-slot): Remove
  special cases for free-ref/free-set!.
2017-11-05 15:00:16 +01:00
Andy Wingo
6be04684e6 load-f64, etc take immediate parameters
* module/language/cps/compile-bytecode.scm (compile-function): Make
  load-f64, load-s64, and load-u64 take an immediate parameter instead
  of a CPS value.
* module/language/cps/effects-analysis.scm: Remove CPS argument from
  immediate load instructions.
* module/language/cps/slot-allocation.scm (compute-needs-slot): Remove
  special case for load-64 etc.
* module/language/cps/specialize-numbers.scm
  (specialize-u64-scm-comparison): Adapt.
* module/language/cps/specialize-primcalls.scm (specialize-primcalls):
  Adapt.
* module/language/cps/types.scm (define-type-inferrer*): Also take param
  argument.
  (define-type-inferrer, define-predicate-inferrer): Adapt.
  (define-type-inferrer/param): New helper.
  (load-f64, load-s64, load-u64): Adapt inferrers to pass on value from
  param.
* module/language/cps/utils.scm (compute-constant-values): Adapt.
2017-11-05 15:00:16 +01:00
Andy Wingo
4fb538e90e cache-current-module, etc use immediate primcall parameters
* module/language/bytecode.scm (*macro-instruction-arities*):
* module/language/cps/compile-bytecode.scm (compile-function):
* module/language/cps/effects-analysis.scm (current-module):
* module/language/cps/primitives.scm (*macro-instruction-arities*):
* module/language/cps/prune-top-level-scopes.scm (compute-used-scopes):
  (prune-top-level-scopes):
* module/language/cps/reify-primitives.scm (module-box):
* module/language/cps/slot-allocation.scm (compute-needs-slot):
* module/language/tree-il/compile-cps.scm (toplevel-box):
  (module-box, capture-toplevel-scope): Move the primcalls that deal
  with top-level references to use immediate parameters.
2017-11-05 15:00:16 +01:00
Andy Wingo
c54c151eb6 $primcall has a "param" member
* module/language/cps.scm ($primcall): Add "param" member, which will be
  a constant parameter to the primcall.  The idea is that constants used
  by primcalls as immediates don't need to participate in optimizations
  in any way -- they should not participate in CSE, have the same
  lifetime as the primcall so not part of DCE either, and don't need
  slot allocation.  Indirecting them through a named $const binding is
  complication for no benefit.  This change should eventually improve
  compilation time and memory usage, once we fully take advantage of it,
  as the number of labels and variables will go down.
* 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/effects-analysis.scm:
* module/language/cps/elide-values.scm:
* module/language/cps/handle-interrupts.scm:
* module/language/cps/licm.scm:
* module/language/cps/peel-loops.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/rotate-loops.scm:
* module/language/cps/self-references.scm:
* module/language/cps/simplify.scm:
* module/language/cps/slot-allocation.scm:
* module/language/cps/specialize-numbers.scm:
* module/language/cps/specialize-primcalls.scm:
* module/language/cps/split-rec.scm:
* module/language/cps/type-checks.scm:
* module/language/cps/type-fold.scm:
* module/language/cps/types.scm:
* module/language/cps/utils.scm:
* module/language/cps/verify.scm:
* module/language/tree-il/compile-cps.scm: Adapt all users.
2017-11-05 15:00:16 +01:00
Andy Wingo
9ceab9962a Simplify special immediate predicate inferrer.
* module/language/cps/types.scm
  (define-special-immediate-predicate-inferrer): Simplify.
2017-10-30 12:06:11 +01:00
Andy Wingo
0d42f5467f Lower logtest branches to instead be 'zero? logand'
* module/language/cps/compile-bytecode.scm (compile-function): Rename
  the binary* helper back to binary, update uses, and remove logtest
  branch as we no longer put logtest in test context.
* module/language/cps/primitives.scm (*comparisons*): Remove logtest.
* module/language/cps/type-fold.scm: Remove logtest folder.
  (logbit?): Fold to logand.
* module/language/cps/types.scm (logtest): Update to be a type inferrer
  and not a predicate inferrer.
* module/language/tree-il/peval.scm (peval): Transform logtest and
  logbit? to (zero? (logand _ _)).
2017-10-30 11:50:45 +01:00
Andy Wingo
d1c69b5c95 Remove compiler support for u64-scm comparisons
* module/language/cps/compile-bytecode.scm (compile-function):
* module/language/cps/effects-analysis.scm:
* module/language/cps/primitives.scm (*comparisons*):
* module/language/cps/type-fold.scm:
* module/language/cps/types.scm: Remove compiler support for u64-scm
  comparisons, as this is now inlined.
2017-10-29 21:02:56 +01:00
Andy Wingo
6bb0a96fa1 Inline u64/scm comparisons
* module/language/cps/specialize-numbers.scm
  (specialize-u64-scm-comparison): Inline comparisons against fixnums.
2017-10-29 20:35:30 +01:00
Andy Wingo
f34abbc396 Add hacks around lack of allocation sinking
* module/language/cps/compile-bytecode.scm (compile-function):
* module/language/cps/cse.scm (compute-equivalent-subexpressions):
* module/language/cps/effects-analysis.scm:
* module/language/cps/primitives.scm (*macro-instruction-arities*):
* module/language/cps/specialize-numbers.scm (compute-specializable-vars):
* module/language/cps/types.scm: Add new variants of u64->scm and
  s64->scm that can't be replaced by CSE's auxiliary definitions, so we
  can sink unlikely allocations to side branches.  This is a hack until
  we can get allocation sinking working
2017-10-29 20:33:35 +01:00
Andy Wingo
c9ec866ef9 Add untag-fixnum instruction
* libguile/vm-engine.c (untag-fixnum): New instruction.
* module/language/cps/compile-bytecode.scm (compile-function):
* module/system/vm/assembler.scm (untag-fixnum):
* module/language/cps/slot-allocation.scm (compute-var-representations):
* module/language/cps/types.scm (untag-fixnum): Add compiler support for
  untag-fixnum.
2017-10-29 19:56:51 +01:00
Andy Wingo
31e7f44340 Add compiler support for fixnum? primcall predicate
* module/language/cps/compile-bytecode.scm (compile-function):
* module/language/cps/type-fold.scm (fixnum?):
* module/language/cps/types.scm (fixnum?):
* module/system/vm/assembler.scm (system): Add cases for fixnum?
  primcall predicate.
2017-10-29 19:42:50 +01:00
Andy Wingo
79a2748f83 Add compiler support for s64 comparisons.
* module/language/cps/compile-bytecode.scm (compile-function): Add
  emitters for s64 comparisons.
* module/language/cps/effects-analysis.scm: Add entries.
* module/language/cps/primitives.scm (*comparisons*):
* module/language/cps/type-fold.scm (s64-<, s64-<=, s64-=, s64->=)
  (s64->): Add folders.
* module/language/cps/types.scm (s64-<, s64-<=, s64-=, s64->=, s64->):
  Add type checkers and inferrers.
2017-10-29 19:42:14 +01:00
Andy Wingo
73d1502630 Lower eqv? and equal? to new instructions.
* libguile/numbers.h:
* libguile/eq.c (scm_i_heap_numbers_equal_p): New helper, factored out
  of scm_eqv_p.
  (scm_eqv_p): Use new helper.
* libguile/vm-engine.c (heap-numbers-equal?): New op.
* module/language/cps/compile-bytecode.scm (compile-function): Add
  support for heap-number? and heap-numbers-equal?.  Remove case for
  eqv?.
* module/language/cps/effects-analysis.scm: Add heap-numbers-equal?.
* module/language/cps/primitives.scm (*comparisons*): Add
  heap-numbers-equal?.
* module/language/cps/type-fold.scm (heap-numbers-equal?): Update.
* module/language/cps/types.scm (heap-numbers-equal?): Update.
* module/language/tree-il/compile-cps.scm (canonicalize): Completely
  inline eqv?, and partially inline equal?.
* module/system/vm/assembler.scm (system): Export emit-heap-numbers-equal?.
2017-10-29 15:47:25 +01:00
Andy Wingo
c2fa345093 Add missing compiler support for heap-object? primcall et al.
* module/language/cps/effects-analysis.scm: Reorder effect-free
  primitives.  Add immediate predicates and heap-number?.
* module/language/cps/primitives.scm (*heap-type-predicates*): Add
  heap-number?.
* module/language/cps/type-fold.scm (heap-number?): New folder.
* module/language/cps/types.scm (heap-number?): New inferrer.
2017-10-29 14:35:19 +01:00
Andy Wingo
587842d874 Simplify lowering of branching primcalls to CPS
* module/language/tree-il/compile-cps.scm (canonicalize, convert):
  Simplify handling of branching primcalls so that `convert' only ever
  sees branching primcalls in a test context.
2017-10-29 14:31:36 +01:00
Andy Wingo
3ae245bc98 Minor optimization compiling 'and'
* module/language/tree-il/compile-cps.scm (convert): Fold test of
  constants directly to their branches without reifying booleans, to
  simplify "and" chains early.
2017-10-29 14:07:23 +01:00
Andy Wingo
9d1235af96 Use new instructions for f64 comparisons
* module/language/cps/compile-bytecode.scm (compile-function): Use new
  instructions for f64 comparisons.
2017-10-29 10:05:24 +01:00
Andy Wingo
8a96b5d085 Use new instructions for u64 comparisons.
* module/language/cps/compile-bytecode.scm (compile-function): Compile
  new instructions for u64 comparisons.
2017-10-29 10:05:24 +01:00
Andy Wingo
f8ac680965 Use new instructions for less-than, etc
* module/language/cps/compile-bytecode.scm (compile-function): Use new
  instructions for generic numeric comparisons (< <= = >= >).
2017-10-29 10:05:24 +01:00
Andy Wingo
056914b555 Emit new eq? instruction
* module/language/cps/compile-bytecode.scm (compile-function): Emit
  new-style eq? instruction.
2017-10-29 10:05:24 +01:00
Andy Wingo
c119623e45 Simplify $branch to always take a $primcall
* module/language/tree-il/compile-cps.scm (convert): Lower (if foo A B)
  to (if (false? foo) B A).
* module/language/cps/specialize-numbers.scm:
* module/language/cps/closure-conversion.scm:
* module/language/cps/contification.scm:
* module/language/cps/cse.scm:
* module/language/cps/dce.scm:
* module/language/cps/peel-loops.scm:
* module/language/cps/rotate-loops.scm:
* module/language/cps/self-references.scm:
* module/language/cps/simplify.scm:
* module/language/cps/slot-allocation.scm:
* module/language/cps/split-rec.scm:
* module/language/cps/type-fold.scm:
* module/language/cps/types.scm:
* module/language/cps/verify.scm: Adapt.
* module/language/cps/compile-bytecode.scm: Add support for new-style
  false? instruction for false? primcall.
2017-10-29 10:05:24 +01:00
Andy Wingo
c74b2257c7 Use new instructions for null?, nil?
* module/language/cps/compile-bytecode.scm (compile-function): Use new
  instructions for branches on null? and nil?.
2017-10-29 10:05:24 +01:00
Andy Wingo
e3c062dce6 Emit char? instead of br-if-char
* module/language/cps/compile-bytecode.scm (compile-function): Use new
  instructions for char? test.
2017-10-29 10:05:24 +01:00
Andy Wingo
29b8e32ffe Emit new instructions for heap object type tests
* module/language/cps/compile-bytecode.scm (compile-function): Compile
  heap object tests to use the new instructions.
2017-10-29 10:05:24 +01:00
Andy Wingo
1139c10e09 Heap type predicates preceded by heap-object?
* module/language/cps/compile-bytecode.scm (compile-function): Add
  support for heap-object? in test context.
* module/language/cps/primitives.scm (*immediate-predicates*):
  (*heap-type-predicates*, *comparisons*): New sets of predicates for
  which the VM has branching operations.
  (heap-type-predicate?): New predicate.
  (*branching-primcall-arities*): Make a hash table.
  (branching-primitive?, prim-arity): Adapt
  to *branching-primcall-arities* being a hash table.
* module/language/cps/type-fold.scm (heap-object?): Add folder.
* module/language/tree-il/compile-cps.scm (convert): Precede heap type
  checks with a heap-object? guard.
2017-10-29 10:05:24 +01:00
Andy Wingo
cd947a1161 Model all special immediates under one type bit (with range)
* module/language/cps/types.scm (&special-immediate): Model all special
  immediates (iflags) under this type bit.  This makes type analysis
  less precise on these values as we have to use ranges instead of sets
  to represent the values, but it frees up bits for other purposes,
  allowing us to totally model all types in Guile.
  (&eof): New &special-immediate value.
  (&other-heap-object): New type bit.
  Adapt inferrers.
* module/language/cps/type-fold.scm
  (define-special-immediate-predicate-folder): New helper, used for
  iflag comparisons.
  (local-type-fold): Adapt scalar-value for &special-immediate change.
  Delegate branch on $values to a primcall to `false?'.
2017-10-26 15:51:28 +02:00
Andy Wingo
2ca88789b1 Type inference distinguishes &fixnum and &bignum types
This will allow heap-object? / inum? predicates to do something useful.

* module/language/cps/types.scm (&fixnum, &bignum): Split &exact-integer
  into these types.  Keep &exact-integer as a union type.
  (type<=?): New helper.
  (constant-type): Return &fixnum or &bignum as appropriate.
  (define-exact-integer!): New helper, tries to make exact integer
  results be &fixnum if they are within range.  Adapt users.
  (restricted-comparison-ranges, define-binary-result!): Use type<=?
  instead of = for &exact-integer.
* module/language/cps/type-fold.scm (logtest, mul, logbit?): Use
  type<=?.
* module/language/cps/specialize-numbers.scm (inferred-sigbits):
  (specialize-operations): Use type<=?.
2017-10-26 15:23:16 +02:00
Andy Wingo
3d848f22f8 First step towards emitting new instructions: "j" instead of "br"
* module/language/cps/compile-bytecode.scm (compile-function): Emit "j"
  instructions instead of "br".
2017-10-25 16:53:18 +02:00
Andy Wingo
808000034e Add support for C16_C16 instruction words
* module/language/bytecode.scm (compute-instruction-arity):
* module/system/vm/assembler.scm (pack-u16-u16, expand):
* module/system/vm/disassembler.scm (disassembler):
* libguile/instructions.c (FOR_EACH_INSTRUCTION_WORD_TYPE): Add C16_C16.
2017-10-24 21:11:20 +02:00
Andy Wingo
dd11b82162 Use make-struct/no-tail instead of make-struct
* module/ice-9/boot-9.scm:
* module/language/cps/effects-analysis.scm:
* module/language/elisp/falias.scm:
* module/language/tree-il.scm:
* module/language/tree-il/primitives.scm:
* module/rnrs/records/procedural.scm:
* module/srfi/srfi-35.scm:
* module/system/base/syntax.scm: Change uses of make-struct to
  make-struct/no-tail.
2017-09-20 22:07:18 +02:00
Ian Price
05c57a6a66 Update Copyright Headers
* module/Makefile.am:
* module/language/cps/compile-js.scm:
* module/language/cps/spec.scm:
* module/language/javascript.scm:
* module/language/javascript/spec.scm:
* module/language/js-il.scm:
* module/language/js-il/compile-javascript.scm:
* module/language/js-il/inlining.scm:
* module/language/js-il/runtime.js: Update copyright headers
2017-08-28 14:08:31 +01:00
Ian Price
062e413cda Keywords cannot be both keyword and optional
* module/language/js-il/compile-javascript.scm
  (compile-jump-table, bind-opt-kw-args): Keywords should not be
  parsed as optional arguments when both are present.
2017-08-27 22:23:39 +01:00
Ian Price
4ef95dd74c Handle more JavaScript binary operators
* module/language/javascript.scm (print-binop): Handle `begin' & `instanceof'
2017-08-27 22:22:24 +01:00
Ian Price
d4ef33f6cf Add assignment js-type to (language javascript)
* module/language/javascript.scm
  (assign): new js-type
  (print-exp, unparse-js): Handle case.
* module/language/javascript/simplify.scm (flatten-blocks):  Handle case.
2017-08-27 22:18:40 +01:00
Ian Price
c5fa12f344 Implement variable-bound? builtin
* module/language/js-il/runtime.js(variable-bound?): Implement builtin
2017-08-17 00:06:12 +01:00
Ian Price
b84797947d pop-fluid uses field of frame not fluid
* module/language/js-il/runtime.js(pop-fluid): Fix primitive.
2017-08-17 00:06:12 +01:00
Ian Price
7e5d9d945e Argument to make-fluid is optional
* module/language/js-il/runtime.js(make-fluid): Supply default argument
2017-08-17 00:06:11 +01:00
Ian Price
fd2445fcf4 *features* is an empty list
* module/language/js-il/runtime.js(*features*): Stop stubbing
2017-08-17 00:06:11 +01:00
Ian Price
8321baee15 Implement list builtins
* module/language/js-il/runtime.js
  (cons, memq, member, delete!): Implement builtins
2017-08-17 00:06:11 +01:00
Ian Price
7ee8973df5 Implement Hook Builtins
* module/language/js-il/runtime.js:
  (scheme.Hook): new constructor
  (make-hook, run-hook): Implement builtins.
2017-08-17 00:06:11 +01:00
Ian Price
84aa3697cc Search for variables in imports.
* module/language/js-il/runtime.js:
  (scm_module_variable): Look in imports if not in obarray.
  (module_imported_variable): New procedure.
  (scm_module_index_obarray, scm_module_index_uses,
  scm_module_index_import_obarray): New variables.
2017-08-16 21:34:10 +01:00
Ian Price
d3dea512c9 Separate public / private module lookups
* module/language/js-il/runtime.js:
  (scm_public_variable, scm_module_public_interface,
  module_public_interface_var, scm_post_boot_init_modules):
  Implement Public Variable Lookup
  (scm_private_lookup, scm_private_variable): Implement Private Lookup
2017-08-16 21:30:28 +01:00
Ian Price
17e48e8641 scheme.HashTable uses ES6 Map objects
* module/language/js-il/runtime.js:
  (scheme.HashTable): Change object interface.
  (cached-module-box): Update primitive.
  (scm_module_ensure_local_variable, def_guile_val): Update helpers
  (scm_hash): Remove helper.
  (make-weak-key-hash-table, hash-clear!, hashq-remove! hashq-ref,
  hashq-set!, hash-for-each): Update builtins.
  (make-weak-value-hash-table, hash-map->list): New builtins.
2017-08-16 20:34:51 +01:00
Ian Price
e57f9bc06a Reimplement JS module system primitives.
* module/language/js-il/runtime.js
  (scm_hash, scheme.HashTable): moved for bootstrapping purposes.

  (define!, cached-toplevel-box, cached-module-box, current-module,
  resolve): Reimplement primitives.

  (define!, module-local-variable, module-variable,
  %get-pre-modules-obarray, set-current-module): Reimplement builtin
  procedures.

  (make-undefined-variable): New builtin procedure.

  (scm_pre_modules_obarray, the_root_module, scm_public_lookup,
  scm_public_variable, scm_private_lookup, scm_current_module,
  scm_lookup, scm_module_ensure_local_variable, scm_module_variable,
  scm_module_define, module_system_is_booted,
  module_make_local_var_x_var, the_module, k_ensure,
  resolve_module_var, scm_post_boot_init_modules): New helper
  variables and procedures, designed to resemble C versions.

  (scheme.call): New helper procedure

  (def_guile0, def_guile_val): Reimplement helper procedure.
2017-08-14 16:52:28 +01:00
Ian Price
166def2da0 Implement unboxed integer primitives.
* module/language/js-il/runtime.js (u64-=, u64->scm): New primitives.
2017-08-14 16:31:20 +01:00
Ian Price
3f9bc2dbb0 Implement basic `equal?' implementation
* module/language/js-il/runtime.js (equal?): Remove primitive.
  Implement as builtin procedure. This version Only handles pairs.
2017-08-14 16:26:39 +01:00
Ian Price
024bd93b0d modules should be passed current continuation
* module/language/js-il/runtime.js (primitive-load-path): modules
  should be passed the current continuation.
2017-08-11 14:02:13 +01:00
Ian Price
56439a88ae Add `guild jslink' to bundle JS programs
* module/Makefile.am (SOURCES): Install runtime.js and jslink.scm
* module/language/js-il/compile-javascript.scm (compile-exp):
  Compilation units take a continuation to facilitate linking.
* module/scripts/jslink.scm: New script.
2017-08-09 16:06:50 +01:00
Ian Price
7438a192f8 Unwind prompt frames
* module/language/js-il/runtime.js(unwind): Unwind prompts.
2017-08-03 00:26:02 +01:00
Ian Price
2da7a82d9d struct-set! primitive returns no values
* module/language/js-il/runtime.js (struct-set!): Don't return a value.
2017-08-03 00:23:45 +01:00