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

203 commits

Author SHA1 Message Date
Andy Wingo
9355985154 Remove integer->char op
* libguile/vm-engine.c (integer->char): Remove unused op.
* module/language/cps/types.scm:
* module/language/cps/effects-analysis.scm:
* module/language/cps/compile-bytecode.scm (compile-function): Remove
  integer->char cases.
* module/system/vm/assembler.scm: Remove emit-integer->char.
2018-04-10 13:33:13 +02:00
Andy Wingo
2964abad05 Explode "string-set!"
* module/language/cps/effects-analysis.scm (string-ref): Remove effects
  declaration, given that the primitive is exploded now.
* module/language/cps/reify-primitives.scm (compute-known-primitives):
  Add string-set!.
* libguile/vm-engine.c (string-set!): Disable opcode.
* module/language/cps/types.scm (string-ref, string-set!): Remove type
  checker and inferrers for string-ref and string-set!, as both are
  exploded.  In the case of string-set! there are still type-check
  effects in the intrinsic call but they can't be elided by the checker,
  as we don't track when strings are read-only.
* module/language/tree-il/compile-cps.scm (ensure-char): New helper.
  (string-set!): New primcall exploded converter.
2018-04-10 12:14:47 +02:00
Andy Wingo
0ae1e943d8 Add string-set! intrinsic
* libguile/intrinsics.c (string_set_x): New intrinsic.
  (scm_bootstrap_intrinsics): Initialize intrinsic.
* libguile/intrinsics.h: Add string-set! intrinsic.
* libguile/vm-engine.c (call-scm-u64-u64): New intrinsic trampoline.
* module/system/vm/assembler.scm (encode-X8_S8_S8_S8-C32!/shuffle): New
  shuffling encoder.
  (define-scm-u64-u64-intrinsic): New helper.
2018-04-10 11:57:40 +02:00
Andy Wingo
33b038bfa9 Remove now-unused string-length, string-ref
* libguile/vm-engine.c (string-length, string-ref): Remove
  instructions.
* module/system/vm/assembler.scm: Remove assembler exports as well.
2018-04-09 10:22:35 +02:00
Andy Wingo
91d0db1bf7 Add VM ops needed for string-ref
* libguile/vm-engine.c (tail-pointer-ref/immediate, tag-char)
  (untag-char): New instructions.
* module/language/cps/compile-bytecode.scm (compile-function): Add
  support for new instructions.
* module/language/cps/cse.scm (compute-equivalent-subexpressions): CSE
  cases for tag-char / untag-char.
* module/language/cps/effects-analysis.scm:
* module/language/cps/types.scm: Add cases for new primcalls.
* module/language/cps/reify-primitives.scm (reify-primitives): Update
  comment.
* module/language/cps/slot-allocation.scm (compute-var-representations):
  Add cases for untag-char, tail-pointer-ref/immediate.
* module/language/cps/specialize-primcalls.scm (specialize-primcalls):
  Add untag-char case, and add FIXME comment for tag-char.
* module/system/vm/assembler.scm: Export new assemblers.
2018-04-08 21:26:46 +02:00
Andy Wingo
1f6f282f16 Compile some generic arithmetic to intrinsic calls
* libguile/intrinsics.h: Rename intrinsic types added in previous
  commit.
* libguile/vm-engine.c (call-scm<-scm-scm, call-scm<-scm-uimm): New
  instructions.
* libguile/vm.c: Include intrinsics.h.
* module/language/bytecode.scm
* module/language/bytecode.scm (*intrinsic-codes*, *intrinsic-names*):
  New internal definitions.
  (intrinsic-name->index, intrinsic-index->name): New exported
  definitions.
* module/system/vm/assembler.scm (encode-X8_S8_S8_S8-C32<-/shuffle):
  (encode-X8_S8_S8_C8-C32<-/shuffle): New shuffling encoders.
  (shuffling-encoder-name): Add case for new shuffling encoders.
  (define-scm<-scm-scm-intrinsic, define-scm<-scm-uimm-intrinsic): New
  helpers.  Define encoders for "add", etc.
2018-03-30 22:11:18 +02:00
Andy Wingo
3f736c4781 Remove unneeded assembly shuffle routines.
* module/system/vm/assembler.scm (encode-X8_S12_S12-X8_C24!/shuffle)
  (encode-X8_S12_S12-X8_C24<-/shuffle): Remove now-unneeded shufflers.
2018-01-22 07:55:06 +01:00
Andy Wingo
b09bbfe3c0 Remove free-ref, free-set!
* libguile/vm-engine.c (free-ref, free-set!): Remove ops.
* module/language/cps/effects-analysis.scm:
* module/system/vm/assembler.scm:
* module/system/vm/disassembler.scm (code-annotation):
* module/language/cps/compile-bytecode.scm (compile-function): Remove
  support for free-ref / free-set!.
2018-01-22 07:51:36 +01:00
Andy Wingo
dd203e5d7d Remove optimizer and backend support for struct ops
* module/language/cps/compile-bytecode.scm:
* module/language/cps/cse.scm:
* module/language/cps/effects-analysis.scm:
* module/language/cps/reify-primitives.scm:
* module/language/cps/specialize-primcalls.scm:
* module/language/cps/types.scm:
* module/language/tree-il/cps-primitives.scm:
* module/system/vm/assembler.scm: Remove support for struct-ref,
  struct-set!, allocate-struct, struct-vtable CPS primcalls and bytecode
  instructions.
2018-01-22 07:51:08 +01:00
Andy Wingo
8573d94404 Remove optimizer and backend support for bv-u8-ref et al
* module/language/cps/compile-bytecode.scm (compile-function):
* module/language/cps/effects-analysis.scm:
* module/language/cps/slot-allocation.scm (compute-var-representations):
* module/language/cps/types.scm:
* module/system/vm/assembler.scm: Remove optimizer and backend support
  for bv- ops.
2018-01-16 16:43:25 +01:00
Andy Wingo
73f55cb9ae Rename gc-pointer-ref to pointer-ref
The pointer dereferencing instructions will keep the pointer alive by
referencing a containing object.

* module/language/cps/compile-bytecode.scm:
* libguile/vm-engine.c:
* module/language/cps/cse.scm:
* module/language/cps/effects-analysis.scm:
* module/language/cps/reify-primitives.scm:
* module/language/cps/slot-allocation.scm:
* module/language/cps/specialize-primcalls.scm:
* module/language/cps/types.scm:
* module/system/vm/assembler.scm:
* module/system/vm/debug.scm: Rename instructions.
2018-01-14 13:40:05 +01:00
Andy Wingo
13cafca168 Add raw u8-ref, etc instructions
* libguile/vm-engine.c (PTR_REF, PTR_SET): New helper macros.
  (u8-ref, u16-ref, u32-ref, u64-ref, s8-ref, s16-ref, s32-ref, s64-ref)
  (u8-set!, u16-set!, u32-set!, u64-set!, s8-set!, s16-set!, s32-set!, s64-set!)
  (f32-ref, f64-ref, f32-set!, f64-set!): New instructions.
* module/system/vm/assembler.scm:
* module/language/cps/compile-bytecode.scm (compile-function):
* module/language/cps/slot-allocation.scm (compute-var-representations):
* module/language/cps/types.scm: Add optimizer and backend support for
  the new instructions.
2018-01-14 12:59:02 +01:00
Andy Wingo
d355b42a3e Add optimizer and backend support for gc-pointer-ref
* 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/reify-primitives.scm (reify-primitives):
* module/language/cps/slot-allocation.scm (compute-var-representations):
* module/language/cps/specialize-primcalls.scm (specialize-primcalls):
* module/language/cps/types.scm (gc-pointer-ref/immediate):
  (gc-pointer-set!/immediate):
* module/system/vm/assembler.scm: Add support for pointer-ref.
2018-01-10 21:58:24 +01:00
Andy Wingo
9222e4df4b Add support for raw gc-managed pointer locals
* libguile/vm-engine.c (gc-pointer-ref/immediate)
  (gc-pointer-set!/immediate): New instructions.
  (SP_REF_PTR, SP_SET_PTR): New helper definitions.
* libguile/vm.c (SLOT_DESC_LIVE_GC): Rename from SLOT_DESC_LIVE_SCM, as
  it can indicate GC-protected raw pointers also.
  (scm_i_vm_mark_stack): Adapt.
* module/system/vm/assembler.scm (write-arities):
* module/system/vm/debug.scm (arity-definitions): Add gcptr
  representation.  This is a binary-incompatible change!
2018-01-10 21:05:16 +01:00
Andy Wingo
02e52a4118 Remove box instructions
* libguile/vm-engine.c (box, box-ref, box-set!): Remove these
  instructions.
* module/system/vm/assembler.scm: Remove assemblers for box-ref et al.
* libguile/vm.c (vm_error_not_a_variable): Remove unused function.
2018-01-10 07:59:21 +01:00
Andy Wingo
abfe04835b Remove special optimizer and backend support for pairs
* module/language/cps/compile-bytecode.scm (compile-function):
* module/language/cps/cse.scm (compute-equivalent-subexpressions):
* module/language/cps/dce.scm (compute-live-code):
* module/language/cps/effects-analysis.scm:
* module/language/cps/types.scm: Remove support for cons, car, etc
  primcalls.
* module/language/cps/effects-analysis.scm (&car, &cdr): Remove
  undefined exports.
* module/system/vm/assembler.scm: Remove emit-cons, etc exports.
2018-01-07 18:44:53 +01:00
Andy Wingo
8ed5d9f237 Re-add compiler backend support for immutable vectors
* module/language/cps/compile-bytecode.scm (compile-function): Add cases
  for mutable-vector? and immutable-vector?.
* module/system/vm/assembler.scm: Export emit-mutable-vector? and
  emit-immutable-vector?.
2018-01-07 17:37:16 +01:00
Andy Wingo
5dde0e48e7 Remove "ash" instruction.
* libguile/vm-engine.c (ash): Remove instruction, which hasn't been
  emitted for a long time.
* module/system/vm/assembler.scm (emit-ash): Remove export.
2018-01-07 16:25:09 +01:00
Andy Wingo
6e100c9ba6 CPS pass now expects exploded vector primitives
* module/language/cps/closure-conversion.scm (convert-one): Reify
  make-vector inline, without field initialization.
* module/language/cps/cse.scm (compute-equivalent-subexpressions):
* module/language/cps/dce.scm (compute-live-code):
* module/language/cps/effects-analysis.scm:
* module/language/cps/reify-primitives.scm (reify-primitives):
* module/language/cps/slot-allocation.scm (compute-var-representations):
* module/language/cps/specialize-primcalls.scm (specialize-primcalls):
* module/language/cps/types.scm:
* module/language/cps/compile-bytecode.scm (compile-function): Remove
  cases for make-vector, vector-ref, etc.
* module/system/vm/assembler.scm: Remove make-vector, vector-ref etc
  exports.
2018-01-07 16:14:09 +01:00
Andy Wingo
f75d0adc3f Fix mismatch between CPS and Scheme "complex?" predicate
* module/system/base/types/internal.scm (heap-tags): Rename complex and
  fraction predicates to "compnum?" and "fracnum?", as they aren't the
  same as the Scheme predicates "complex?" and "fraction?".
2017-12-27 15:46:31 +01:00
Andy Wingo
315dd366ee Add scm-ref, etc instructions for generic heap object field access
* libguile/vm-engine.c (allocate-words, allocate-words/immediate)
  (scm-ref, scm-set!, scm-ref/tag, scm-set!/tag, scm-ref/immediate)
  (scm-set!/immediate): New instructions for generic access to fields in
  heap objects.
* module/language/cps/cse.scm (compute-equivalent-subexpressions):
* module/language/cps/effects-analysis.scm:
* module/language/cps/reify-primitives.scm (reify-primitives):
* module/language/cps/specialize-primcalls.scm (specialize-primcalls):
* module/language/cps/types.scm (allocate-words)
  (allocate-words/immediate, scm-ref, scm-ref/immediate, scm-ref/tag)
  (scm-set!/tag, scm-set!, scm-set!/immediate, word-ref)
  (word-ref/immediate, word-set!, word-set!/immediate):
* module/system/vm/assembler.scm:
* module/language/cps/compile-bytecode.scm (compile-function): Add
  support for the new instructions.
2017-12-06 11:13:29 +01:00
Andy Wingo
7d71d9b945 Optimize check-urange in assembler.scm
* module/system/vm/assembler.scm (check-urange): Hoist exact-integer?
  check so that the side effect is entirely in this function and not in
  `logand'.  Allows devirtualize-integers to peel off a nice straight
  trace.
2017-11-24 11:03:46 +01:00
Andy Wingo
294dbaad35 Add support for comparisons against integer immediates
* libguile/vm-engine.c (s64-imm=?, u64-imm<?, imm-u64<?, s64-imm<?)
  (imm-s64<?): New instructions.
* libguile/instructions.c (FOR_EACH_INSTRUCTION_WORD_TYPE): Add new
  X8_S12_Z12 word type used by the new S64/immediate instructions.  A
  Z12 is a 12-bit signed integer immediate.
* module/system/vm/assembler.scm: Export new instructions, and add
  X8_S12_Z12 support.  Also, add missing shufflers for X8_S12_C12.
* module/language/bytecode.scm (compute-instruction-arity):
* module/system/vm/disassembler.scm (unpack-s12, disassembler): Add
  support for X8_S12_Z12.
* module/language/cps/types.scm (define-predicate-inferrer/param): New
  helper.
  (u64-=, u64-<, s64-<): Remove type checkers; this procedure does not
  cause &type-check.
  (u64-imm=?, s64-imm=?, u64-imm<?, imm-u64<?, s64-imm<?, imm-s64<?):
  New type inferrers.
* module/language/cps/type-fold.scm (define-unary-branch-folder*): New
  helper.
  (u64-imm=?, s64-imm=?, u64-imm<?, imm-u64<?, s64-imm<?, imm-s64<?):
  New branch folders.
* module/language/cps/reify-primitives.scm (reify-primitives): Reify
  constants for new immediate branching primcalls if values out of
  range.
* module/language/cps/effects-analysis.scm: Add support for new
  primcalls.
* module/language/cps/compile-bytecode.scm (compile-function): Add
  support for new primcalls and instructions.  Compile u64-imm-= to
  s64-imm=?.
2017-11-15 14:18:39 +01:00
Andy Wingo
b97321dbfd Add srsh, srsh/immediate instructions
* libguile/vm-engine.c (srsh, srsh/immediate): New instructions.
* module/language/cps/compile-bytecode.scm (compile-function):
* module/language/cps/effects-analysis.scm:
* module/language/cps/reify-primitives.scm (reify-primitives):
* module/language/cps/slot-allocation.scm (compute-var-representations):
* module/language/cps/specialize-primcalls.scm (specialize-primcalls):
* module/language/cps/types.scm (srsh, srsh/immediate):
* module/system/vm/assembler.scm: Add support for new instructions.

* module/language/cps/types.scm (ulsh, ursh): Remove type checkers, as
  these are effect-free.  Limit range of ursh count.
2017-11-13 10:25:20 +01:00
Andy Wingo
8b5f9648ff Add tag-fixnum instruction
* libguile/vm-engine.c (tag-fixnum): New instruction.
* 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/types.scm (&min/fixnum, &max/fixnum, tag-fixnum):
* module/system/vm/assembler.scm: Add support for the new instruction.
2017-11-11 22:08:14 +01:00
Andy Wingo
f96a670332 Add new "throw" VM ops
* libguile/throw.h (scm_ithrow, scm_throw): Mark as SCM_NORETURN.
* libguile/throw.c (scm_throw, scm_ithrow): Adapt to not return.
* libguile/vm-engine.c (throw, throw/value, throw/value+data): New
  instructions.
* libguile/vm.c (vm_throw, vm_throw_with_value)
  (vm_throw_with_value_and_data): New helpers.
* module/language/cps/compile-bytecode.scm (compile-function): Add cases
  for new instructions.
* module/language/cps/prune-bailouts.scm (prune-bailouts): More simple,
  now that there are no $kreceives in play.
* module/language/cps/reify-primitives.scm (reify-clause): Update
  reification of no-clause functions to use new throw op.
* module/language/tree-il/compile-cps.scm (convert): Convert invocations
  of the variable-arity 'throw primitive from Tree-IL to the new
  fixed-arity CPS instructions.
* module/system/vm/assembler.scm (emit-throw/value*)
  (emit-throw/value+data*, emit-throw): Export new instructions.
* module/system/vm/disassembler.scm (code-annotation): Add annotation.
2017-11-05 15:00:16 +01:00
Andy Wingo
17bd5a8938 Add lsh, rsh instructions
* libguile/vm-engine.c (lsh, rsh, lsh/immediate, rsh/immediate): New
  instructions taking unboxed bit counts.
* module/language/cps/compile-bytecode.scm (compile-function):
* module/language/cps/effects-analysis.scm:
* module/language/cps/specialize-numbers.scm (specialize-f64-unop):
  (specialize-u64-unop): Add ability to specialize add/immediate, etc,
  and add lsh/immediate as well.
  (specialize-u64-binop, specialize-u64-shift): Move rsh/lsh
  specialization to its own procedure, given that the bit count is
  already unboxed.
  (specialize-operations): Adapt to support more /immediate
  instructions.
* module/language/cps/type-fold.scm (mul): Reify an lsh/immediate
  instead of an ash.
* module/language/cps/types.scm (compute-ash-range): Add type inferrers
  for lsh, rsh, and their immediate variants.
* module/system/vm/assembler.scm: Export emit-lsh and so on.
* module/language/tree-il/compile-cps.scm (convert): Convert "ash" on
  immediates to rsh/immediate or lsh/immediate.
2017-11-05 15:00:16 +01:00
Andy Wingo
c92b80be2d Emit new instructions in function preludes
* module/system/vm/assembler.scm (standard-prelude, opt-prelude):
  (kw-prelude): Emit new instructions in function preludes.  Now all
  branches are via the new instructions.  Remove exports for old
  branches.
2017-10-30 12:06:07 +01:00
Andy Wingo
5fb9b7d542 Remove assembler exports for old-style predicates and branches
* module/system/vm/assembler.scm: Remove emit-br, emit-br-if-true, etc,
  as these all now use new-style instructions.
2017-10-30 11:55:27 +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
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
b4db70854b Rename "number" tag to "heap-number"
* module/system/base/types/internal.scm (heap-tags): Rename number to
  heap-number.
* module/system/vm/assembler.scm: Adapt for emit-heap-number?.
* module/system/base/types.scm (%tc7-heap-number): Rename from
  %tc7-number.
2017-10-29 14:07:25 +01:00
Andy Wingo
6dd30920eb Use tag visitors to generate assemblers, disassembly annotations
* module/system/vm/disassembler.scm (immediate-tag-annotations)
  (heap-tag-annotations): Generate using tag visitors.
* module/system/vm/assembler.scm
  (define-immediate-tag=?-macro-assembler)
  (define-heap-tag=?-macro-assembler): New helpers.  Use these to
  generate immediate-tag=? and heap-tag=? macro assemblers.
2017-10-29 10:05:24 +01:00
Andy Wingo
258c59b4cc Add assembler and disassembler support for new instructions
* module/system/vm/assembler.scm: Export assemblers for the new
  instructions.
* module/system/vm/disassembler.scm (immediate-tag-annotations)
  (heap-tag-annotations, code-annotation): Add support for disassembling
  the new instructions, with good annotations.
  (compute-labels, instruction-has-fallthrough?, define-jump-parser):
  Add support for new branching instructions.
2017-10-25 16:53:14 +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
b2c0e01bb4 Update effective version to 3.0
* GUILE-VERSION: Bump version to 2.3.0, and effective version to 3.0.
* .gitignore:
* README:
* doc/guile.1:
* doc/ref/api-evaluation.texi:
* doc/ref/api-options.texi:
* doc/ref/guile-invoke.texi:
* doc/ref/libguile-foreign-objects.texi:
* doc/ref/libguile-parallel.texi:
* doc/ref/srfi-modules.texi: Update to 3.0.
* libguile/_scm.h (SCM_OBJCODE_MAJOR_VERSION):
(SCM_OBJCODE_MINIMUM_MINOR_VERSION, SCM_OBJCODE_MINOR_VERSION): Bump
bytecode version for fallback path.
* libguile/loader.c: Update to avoid loading version 2.2 bytecode
files.
* meta/guile-3.0-uninstalled.pc.in:
* meta/guile-3.0.pc.in: Rename.
* module/system/vm/assembler.scm (*bytecode-major-version*):
(*bytecode-minor-version*): Write the new bytecode version.
2017-05-22 14:15:40 +02:00
Andy Wingo
e0502f3c77 Bump objcode version in a compatible way
* libguile/_scm.h (SCM_OBJCODE_MINIMUM_MINOR_VERSION): New definition,
  indicating the oldest objcode version that we support.
  (SCM_OBJCODE_MINOR_VERSION): Bump.
* libguile/loader.c (process_dynamic_segment): Support a range of
  versions.
* module/system/vm/assembler.scm (*bytecode-minor-version*): Bump.
2017-04-18 21:37:36 +02:00
Andy Wingo
7ed54fd36d All literal constants are read-only
* libguile/array-handle.c (initialize_vector_handle): Add mutable_p
  argument.  Unless the vector handle is mutable, null out its
  writable_elements member.
  (scm_array_get_handle): Adapt to determine mutability of the various
  arrays.
  (scm_array_handle_elements, scm_array_handle_writable_elements):
  Reverse the sense: instead of implementing read-only in terms of
  read-write, go the other way around, adding an assertion in the
  read-write case that the array handle is mutable.
* libguile/array-map.c (racp): Assert that the destination is mutable.
* libguile/bitvectors.c (SCM_F_BITVECTOR_IMMUTABLE, IS_BITVECTOR):
  (IS_MUTABLE_BITVECTOR): Add a flag to indicate immutability.
  (scm_i_bitvector_bits): Fix indentation.
  (scm_i_is_mutable_bitvector): New helper.
  (scm_array_handle_bit_elements)
  ((scm_array_handle_bit_writable_elements): Build writable_elements in
  terms of elements.
  (scm_bitvector_elements, scm_bitvector_writable_elements): Likewise.
  (scm_c_bitvector_set_x): Require a mutable bitvector for the
  fast-path.
  (scm_bitvector_to_list, scm_bit_count): Use read-only elements()
  function.
* libguile/bitvectors.h (scm_i_is_mutable_bitvector): New decl.
* libguile/bytevectors.c (INTEGER_ACCESSOR_PROLOGUE):
  (INTEGER_GETTER_PROLOGUE, INTEGER_SETTER_PROLOGUE):
  (INTEGER_REF, INTEGER_NATIVE_REF, INTEGER_SET, INTEGER_NATIVE_SET):
  (GENERIC_INTEGER_ACCESSOR_PROLOGUE):
  (GENERIC_INTEGER_GETTER_PROLOGUE, GENERIC_INTEGER_SETTER_PROLOGUE):
  (LARGE_INTEGER_NATIVE_REF, LARGE_INTEGER_NATIVE_SET):
  (IEEE754_GETTER_PROLOGUE, IEEE754_SETTER_PROLOGUE):
  (IEEE754_REF, IEEE754_NATIVE_REF, IEEE754_SET, IEEE754_NATIVE_SET):
  Setters require a mutable bytevector.
  (SCM_BYTEVECTOR_SET_FLAG): New helper.
  (SCM_BYTEVECTOR_SET_CONTIGUOUS_P, SCM_BYTEVECTOR_SET_ELEMENT_TYPE):
  Remove helpers.
  (SCM_VALIDATE_MUTABLE_BYTEVECTOR): New helper.
  (make_bytevector, make_bytevector_from_buffer): Use
  SCM_SET_BYTEVECTOR_FLAGS.
  (scm_c_bytevector_set_x, scm_bytevector_fill_x)
  (scm_bytevector_copy_x): Require a mutable bytevector.
* libguile/bytevectors.h (SCM_F_BYTEVECTOR_CONTIGUOUS)
  (SCM_F_BYTEVECTOR_IMMUTABLE, SCM_MUTABLE_BYTEVECTOR_P): New
  definitions.
* libguile/bytevectors.h (SCM_BYTEVECTOR_CONTIGUOUS_P): Just access one
  bit.
* libguile/srfi-4.c (DEFINE_SRFI_4_C_FUNCS): Implement
  writable_elements() in terms of elements().
* libguile/strings.c (scm_i_string_is_mutable): New helper.
* libguile/uniform.c (scm_array_handle_uniform_elements):
  (scm_array_handle_uniform_writable_elements): Implement
  writable_elements in terms of elements.
* libguile/vectors.c (SCM_VALIDATE_MUTABLE_VECTOR): New helper.
  (scm_vector_elements, scm_vector_writable_elements): Implement
  writable_elements in terms of elements.
  (scm_c_vector_set_x): Require a mutable vector.
* libguile/vectors.h (SCM_F_VECTOR_IMMUTABLE, SCM_I_IS_MUTABLE_VECTOR):
  New definitions.
* libguile/vm-engine.c (VM_VALIDATE_MUTABLE_BYTEVECTOR):
  (VM_VALIDATE_MUTABLE_VECTOR, vector-set!, vector-set!/immediate)
  (BV_BOUNDED_SET, BV_SET): Require mutable bytevector/vector.
* libguile/vm.c (vm_error_not_a_mutable_bytevector):
  (vm_error_not_a_mutable_vector): New definitions.
* module/system/vm/assembler.scm (link-data): Mark residualized vectors,
  bytevectors, and bitvectors as being read-only.
2017-04-18 21:27:45 +02:00
Andy Wingo
64c5cc58fc Add disjoint syntax object type
* libguile/Makefile.am (libguile_@GUILE_EFFECTIVE_VERSION@_la_SOURCES):
  (DOT_X_FILES, DOT_DOC_FILES, noinst_HEADERS): Add syntax.c and
  syntax.h.
* libguile/evalext.c (scm_self_evaluating_p):
* libguile/goops.c (class_syntax, scm_class_of, scm_goops_early_init):
* libguile/init.c (scm_init_guile):
* libguile/print.c (iprin1):
* libguile/tags.h (scm_tc7_syntax):
* module/oop/goops.scm (<syntax>):
* module/system/base/types.scm (%tc7-syntax, cell->object):
* module/system/vm/disassembler.scm (code-annotation): Wire up the new
  data type.
* libguile/syntax.c:
* libguile/syntax.h: New files.
* module/ice-9/boot-9.scm: Move new definitions to (system syntax
  internal).
* module/system/syntax.scm (print-syntax): New helper.
* module/system/vm/assembler.scm (statically-allocatable?)
  (intern-constant, link-data): Arrange to be able to write syntax
  objects into images.
* module/language/cps/types.scm (&syntax): New type.  Remove
  &hash-table; it was never detected, an internal binding, and we need
  the bit to avoid going into bignum territory.
2017-03-28 19:23:13 +02:00
Andy Wingo
c525aa6d95 VM support for string-set!; slimmer read-string
* doc/ref/vm.texi (Inlined Scheme Instructions): Add string-set!.
* libguile/vm-engine.c (string-set!): New opcode.
* module/ice-9/rdelim.scm (read-string): Reimplement in terms of a
  geometrically growing list of strings, to reduce total heap usage when
  reading big files.
* module/language/cps/compile-bytecode.scm (compile-function): Add
  string-set! support.
* module/language/cps/types.scm (string-set!): Update for &u64 index.
* module/language/tree-il/compile-cps.scm (convert): Unbox index to
  string-set!.
* module/system/vm/assembler.scm (system): Export string-set!.
2017-03-09 17:24:06 +01:00
Andy Wingo
d0934df1f2 Stringbufs immutable by default
* libguile/snarf.h (SCM_IMMUTABLE_STRINGBUF): Remove shared flag.
  Stringbufs are immutable by default.
* libguile/strings.c: Rewrite blurb.  Change to have stringbufs be
  immutable by default and mutable only when marked as such.  Going
  mutable means making a private copy.
  (STRINGBUF_MUTABLE, STRINGBUF_F_MUTABLE): New definitions.
  (SET_STRINGBUF_SHARED): Remove.
  (scm_i_print_stringbuf): Simplify to just alias the stringbuf as-is.
  (substring_with_immutable_stringbuf): New helper.
  (scm_i_substring, scm_i_substring_read_only, scm_i_substring_copy):
  use new helper.
  (scm_i_string_ensure_mutable_x): New helper.
  (scm_i_substring_shared): Use scm_i_string_ensure_mutable_x.
  (stringbuf_write_mutex): Remove; yaaaaaaaay.
  (scm_i_string_start_writing): Use scm_i_string_ensure_mutable_x.  No
  more mutex.
  (scm_i_string_stop_writing): Now a no-op.
  (scm_i_make_symbol): Use substring/copy.
  (scm_sys_string_dump, scm_sys_symbol_dump): Update.
* libguile/strings.h (SCM_I_STRINGBUF_F_SHARED): Remove.
  (SCM_I_STRINGBUF_F_MUTABLE): Add.
* module/system/vm/assembler.scm (link-data): Don't add shared flag any
  more.  Existing compiled flags are harmless tho.
* test-suite/tests/strings.test ("string internals"): Update.
2017-02-16 13:11:29 +01:00
David Thompson
35a9059250 Add unboxed floating point comparison instructions.
* libguile/vm-engine.c (BR_F64_ARITHMETIC): New preprocessor macro.
(br_if_f64_ee, br_if_f64_lt, br_if_f64_le, br_if_f64_gt, br_if_f64_ge):
New VM instructions.
* doc/ref/vm.texi ("Unboxed Floating-Point Arithmetic"): Document them.
* module/language/cps/compile-bytecode.scm (compile-function): Emit f64
comparison instructions.
* module/language/cps/effects-analysis.scm: Define effects for f64
primcalls.
* module/language/cps/primitives.scm (*branching-primcall-arities*): Add
arities for f64 primcalls.
* module/language/cps/specialize-numbers.scm (specialize-f64-comparison):
New procedure.
(specialize-operations): Specialize f64 comparisons.
* module/system/vm/assembler.scm (emit-br-if-f64-=, emit-br-if-f64-<)
(emit-br-if-f64-<=, emit-br-if-f64->, emit-br-if-f64->=): Export.
* module/system/vm/disassembler.scm (code-annotation): Add annotations
for f64 comparison instructions.
2017-01-12 09:27:43 -05:00
Andy Wingo
7184c176b4 with-dynamic-state compiler and VM support
* libguile/dynstack.h (SCM_DYNSTACK_TYPE_DYNAMIC_STATE):
* libguile/dynstack.c (DYNAMIC_STATE_WORDS, DYNAMIC_STATE_STATE_BOX):
  (scm_dynstack_push_dynamic_state):
  (scm_dynstack_unwind_dynamic_state): New definitions.
  (scm_dynstack_unwind_1, scm_dynstack_wind_1): Add with-dynamic-state
  cases.
* libguile/memoize.c (push_dynamic_state, pop_dynamic_state)
  (do_push_dynamic_state, do_pop_dynamic_state): New definitions.
  (memoize, scm_init_memoize): Handle push-dynamic-state and
  pop-dynamic-state.
* libguile/vm-engine.c (push-dynamic-state, pop-dynamic-state): New
  opcodes.
* module/ice-9/boot-9.scm (with-dynamic-state): New definition in Scheme
  so that the push-dynamic-state and pop-dynamic-state always run in the
  VM.
* module/language/cps/compile-bytecode.scm (compile-function):
* module/language/cps/effects-analysis.scm:
* module/language/cps/types.scm:
* module/language/tree-il/effects.scm (make-effects-analyzer):
* module/language/tree-il/peval.scm (peval):
* module/language/tree-il/primitives.scm (*interesting-primitive-names*):
* module/system/vm/assembler.scm: Add support for with-dynamic-state to
  the compiler.
* test-suite/tests/fluids.test ("dynamic states"): Add basic tests.
* doc/ref/vm.texi (Dynamic Environment Instructions): Update.
2016-12-05 22:57:29 +01:00
Andy Wingo
8bd5dae8c3 Compile fluid-set! to VM opcode
* libguile/vm-engine.c (fluid-set!): Fix name of opcode to correspond
  with name of Tree-IL primitive.  Fixes compilation of fluid-set! to
  actually use the fluid-set! opcode.
* doc/ref/vm.texi (Dynamic Environment Instructions): Update.
* module/language/cps/compile-bytecode.scm (compile-function): Add
  fluid-set! case.
* module/system/vm/assembler.scm: Update export name for
  emit-fluid-set!.
2016-11-27 21:55:42 +01:00
Daniel Llorens
d236d4d33f Fix compilation of rank 0 typed array literals
* module/system/vm/assembler.scm (simple-uniform-vector?): array-length
  fails for rank 0 arrays; fix the shape condition.

* test-suite/tests/arrays.test: Test reading of #0f64(x) in compilation
  context.
2016-11-23 11:49:35 +01:00
Andy Wingo
ca74e3fae5 Add handle-interrupts inst and compiler pass
* libguile/vm-engine.c (vm_engine): Remove initial VM_HANDLE_INTERRUPTS
  call; surely our caller already handled interrupts.  Add
  handle-interrupts opcode.
* am/bootstrap.am (SOURCES):
* module/Makefile.am (SOURCES): Add handle-interrupts.scm.
* module/system/vm/assembler.scm (system):
* module/language/cps/compile-bytecode.scm (compile-function):
  (lower-cps): Add handle-interrupts support.
* module/language/cps/handle-interrupts.scm: New file.
2016-11-16 22:55:45 +01:00
Andy Wingo
5f4a2ac3e7 Fix cross-compilation of negative fixnums
* module/system/vm/assembler.scm (encoder): Use immediate-bits instead
  of object-address, to fix cross-compilation.
2016-09-06 21:03:36 +02:00
Andy Wingo
32f309d5ce Compiler support for atomics
* doc/ref/vm.texi (Inlined Atomic Instructions): New section.
* libguile/vm-engine.c (VM_VALIDATE_ATOMIC_BOX, make-atomic-box)
  (atomic-box-ref, atomic-box-set!, atomic-box-swap!)
  (atomic-box-compare-and-swap!): New instructions.
* libguile/vm.c: Include atomic and atomics-internal.h.
  (vm_error_not_a_atomic_box): New function.
* module/ice-9/atomic.scm: Register primitives with the compiler.
* module/language/cps/compile-bytecode.scm (compile-function): Add
  support for atomic ops.
* module/language/cps/effects-analysis.scm: Add comment about why no
  effects analysis needed.
* module/language/cps/reify-primitives.scm (primitive-module): Add case
  for (ice-9 atomic).
* module/language/tree-il/primitives.scm (*effect-free-primitives*):
  (*effect+exception-free-primitives*): Add atomic-box?.
* module/system/vm/assembler.scm: Add new instructions.

* test-suite/tests/atomic.test: Test with compilation and
  interpretation.
2016-09-06 12:18:35 +02:00
Andy Wingo
73efa8fb06 Fix fixnum min/max for assembler
* module/system/vm/assembler.scm (immediate-bits): I am a complete and
  total idiot and got the fixnum mins and maxes swapped.
2016-09-06 12:05:21 +02:00