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

361 commits

Author SHA1 Message Date
Andy Wingo
b9f7621e13 Add scm->f64 intrinsic
* libguile/vm-engine.c (call-f64<-scm): New intrinsic kind.
  (scm->f64): Disable instruction.
* libguile/intrinsics.h (SCM_FOR_ALL_VM_INTRINSICS):
* libguile/intrinsics.c (scm_bootstrap_intrinsics):
* module/language/cps/reify-primitives.scm (compute-known-primitives):
* module/system/vm/assembler.scm (define-f64<-scm-intrinsic): Add scm->f64.
2018-04-10 19:39:50 +02:00
Andy Wingo
59f1f5a6a7 Remove load-typed-array, make-array opcodes
* libguile/vm-engine.c (load-typed-array, make-array): Remove these
  apparently unused opcodes.  Yay!
2018-04-10 19:14:15 +02:00
Andy Wingo
3073199264 Remove class-of opcode
* libguile/vm-engine.c (class-of): Remove unused opcode.
2018-04-10 18:35:23 +02:00
Andy Wingo
954bfad262 Class-of is intrinsic
* libguile/vm-engine.c (class-of): Disable.
* module/language/cps/reify-primitives.scm (compute-known-primitives):
  Add class-of as macro-instruction.
* libguile/intrinsics.c (scm_bootstrap_intrinsics): Add class-of.
* libguile/intrinsics.h (SCM_FOR_ALL_VM_INTRINSICS): Add class-of.
* module/system/vm/assembler.scm (class-of): Define as intrinsic.
2018-04-10 18:32:31 +02:00
Andy Wingo
51736fd66c Remove string->number, etc opcodes
* libguile/vm-engine.c (string->number, string->symbol)
  (symbol->keyword): Remove unused instructions.
2018-04-10 18:00:23 +02:00
Andy Wingo
1c49c1407b string->number, etc intrinsics
* libguile/intrinsics.c (string_to_number): New helper.
  (scm_bootstrap_intrinsics): Init new intrinsics.
* libguile/intrinsics.h (string->number, string->symbol)
  (symbol->keyword): Add new intrinsics.
* libguile/vm-engine.c (call-scm<-scm): New intrinsic dispatcher.
  (string->number, string->symbol, symbol->keyword): Disable these
  instructions.
* module/system/vm/assembler.scm (encode-X8_S12_S12-C32<-/shuffle):
  (define-scm<-scm-intrinsic): Enable scm<-scm intrinsics.
  (string->number, string->symbol, symbol->keyword): New intrinsic
  assemblers.
2018-04-10 17:56:08 +02:00
Andy Wingo
b0641783c9 Remove unused make-closure opcode.
* libguile/vm-engine.c (make-closure): Remove opcode.
2018-04-10 17:55:18 +02:00
Andy Wingo
70e3a4a311 Add load-label instruction
* libguile/vm-engine.c (load-label): New instruction.
* module/system/vm/assembler.scm: Add emit-load-label.
* module/system/vm/disassembler.scm (code-annotation):
  (fold-code-range): Add load-label support.
2018-04-10 14:36:15 +02:00
Andy Wingo
644875cf0e Remove char->integer from VM
* libguile/vm-engine.c (VM_VALIDATE_CHAR, VM_VALIDATE_STRING)
  (VM_VALIDATE_INDEX): Remove now-unused helpers.
  (vm_engine): Fix position of intrinsics declaration.
  (char->integer): Remove unused opcode.
* libguile/vm.c (vm_error_not_a_char, vm_error_not_a_string)
  (vm_error_out_of_range_uint64): Remove unused decls.
2018-04-10 13:50:28 +02:00
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
f1fe5219de Remove string-set! VM op
* libguile/vm-engine.c (string-set!): Remove now-unused VM op.
2018-04-10 12:21:23 +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
bb1ff0e78a Remove specific instructions for add, etc from VM
* module/language/cps/reify-primitives.scm (compute-known-primitives):
  Treat add, sub, and so on as known primitives.
* libguile/vm-engine.c: Remove code for now-unused instructions.
2018-03-31 01:40:47 +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
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
fcea9eeabd Remove VM struct-ref, etc instructions
* libguile/vm-engine.c (VM_VALIDATE_STRUCT)
  (VM_VALIDATE_BOXED_STRUCT_FIELD, VM_VALIDATE_UNBOXED_STRUCT_FIELD)
  (struct-ref, struct-set!, struct-vtable, allocate-struct)
  (allocate-struct/immediate, struct-ref/immediate)
  (struct-set!/immediate): Remove these opcodes.
* libguile/vm.c: Remove error cases for struct ops.
2018-01-22 07:51:17 +01:00
Andy Wingo
310c34e112 Remove bytevector instructions from the VM.
* libguile/vm-engine.c: Remove bv-u8-ref et al, along with bv-length.
* libguile/vm.c (vm_error_not_a_bytevector)
  (vm_error_not_a_mutable_bytevector, vm_error_out_of_range_int64):
  Remove unused procedures.
2018-01-16 16:43:29 +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
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
b294a1e7d7 Sync IP before allocating closures
* libguile/vm-engine.c (vm_engine): Sync IP before allocating closures.
2018-01-08 15:19:45 +01:00
Andy Wingo
798f633624 Remove pair-related instructions
* libguile/vm-engine.c (VM_VALIDATE_PAIR, VM_VALIDATE_MUTABLE_PAIR):
  Remove these now-unused definitions.
  (VM_VALIDATE_VECTOR, VM_VALIDATE_MUTABLE_VECTOR): Likewise.
  (cons, car, cdr, set-car!, set-cdr!): Remove instructions.
* libguile/vm.c (vm_error_not_a_pair, vm_error_not_a_mutable_pair):
  Remove unused error cases.
2018-01-07 18:44:53 +01:00
Andy Wingo
94f8f70b22 Remove now-unused make-vector et al instructions
* libguile/vm-engine.c (make-vector, make-vector/immediate)
  (vector-ref, vector-ref/immediate, vector-set!)
  (vector-set!/immediate): Remove these now-unused instructions.
* libguile/vm.c (vm_error_not_a_vector, vm_error_not_a_mutable_vector):
  Remove.
2018-01-07 16:34:13 +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
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
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
4267a8b6d5 Remove old branching instructions from VM
* libguile/vm-engine.c: Remove old branching instructions.
2017-10-30 12:23:12 +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
7aff0fff22 Fix argument type of arguments<=? instruction
* libguile/vm-engine.c (arguments<=?): Take an immediate argument.
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
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
a7f9c32816 Add new-style test and branch instructions
* libguile/vm-engine.c (UNPACK_16_16): New definition.
  (u64=?, u64<?, s64=?, s64<?, f64=?, f64<?, =?, <?, arguments<?)
  (positional-arguments<=?, immediate-tag=?, heap-tag=?, eq?): New
  comparison instructions.
  (j, jl, je, jnl, jne, jge, jnge): New branch instructions.
2017-10-24 21:12:19 +02:00
Andy Wingo
214e887dbd Struct vtables store bitmask of unboxed fields
* libguile/struct.h (scm_vtable_index_unboxed_fields): Allocate slot for
  bitmask of which fields are unboxed.
  (SCM_VTABLE_FLAG_SIMPLE, SCM_VTABLE_FLAG_SIMPLE_RW): Remove flags.
  Renumber other flags.
  (SCM_VTABLE_SIZE, SCM_STRUCT_SIZE): New helpers; long overdue.
  (SCM_VTABLE_UNBOXED_FIELDS, SCM_VTABLE_FIELD_IS_UNBOXED):
  (SCM_STRUCT_FIELD_IS_UNBOXED): New macros.
* libguile/struct.c (set_vtable_access_fields): Rename from
  set_vtable_layout_flags, and initialize the unboxed flags bitmask
  instead of computing vtable flags.
  (scm_struct_init, scm_c_make_structv, scm_allocate_struct): Simplify.
  (scm_i_make_vtable_vtable): Adapt.
  (scm_i_struct_equalp, scm_struct_ref, scm_struct_set_x)
  (scm_struct_ref_unboxed, scm_struct_set_x_unboxed): Simplify.
* libguile/vm-engine.c (VM_VALIDATE_BOXED_STRUCT_FIELD):
  (VM_VALIDATE_UNBOXED_STRUCT_FIELD): Adapt definitions.
  (struct-ref, struct-set!, struct-ref/immediate)
  (struct-set!/immediate): Simplify definitions.
* libguile/hash.c (scm_i_struct_hash): Simplify.
* libguile/goops.c (scm_sys_clear_fields_x): Simplify.
* libguile/foreign-object.c (scm_make_foreign_object_n):
  (scm_foreign_object_unsigned_ref, scm_foreign_object_unsigned_set_x):
  Simplify.
2017-09-26 21:56:31 +02:00
Andy Wingo
760662f7f1 Remove unboxed case from vm struct accessors
* libguile/vm.c (vm_error_boxed_struct_field):
  (vm_error_unboxed_struct_field): New helpers.
* libguile/vm-engine.c (VM_VALIDATE_BOXED_STRUCT_FIELD):
  (VM_VALIDATE_UNBOXED_STRUCT_FIELD): New helpers.
  (struct-ref, struct-set!, struct-ref/immediate)
  (struct-set!/immediate): Remove unboxed case.
2017-09-25 22:35:42 +02:00
Andy Wingo
9211981524 Inline struct-ref etc definitions in the VM.
* libguile/vm-engine.c (struct-ref, struct-set!, struct-ref/immediate)
  (struct-set!/immediate): Inline definitions.  Still a ways to go
  before no function calls though.
2017-09-23 15:51:50 +02:00
Andy Wingo
4898959901 Implement class redefinition on top of fixed structs
* libguile/struct.h: Steal another flag for GOOPS.
* libguile/goops.h (SCM_VTABLE_FLAG_GOOPS_INDIRECT)
  (SCM_VTABLE_FLAG_GOOPS_NEEDS_MIGRATION): New flags.
  (SCM_CLASSF_GOOPS_VALID, SCM_CLASSF_GOOPS_OR_VALID): Remove obsolete
  definitions.
  (SCM_IS_A_P): Use the scm_class_of function.
* libguile/goops.c (var_class_of_obsolete_indirect_instance): Rename
  from var_migrate_instance.
  (scm_is_generic, scm_is_method, scm_sys_init_layout_x): Use
  scm_class_of instead of the SCM_CLASS_OF macro.
  (get_indirect_slots): New helper.
  (scm_class_of): This patch moves us in a direction where we won't be
  able to separately address a struct's data and its identity.
  Therefore to check whether a class needs migration, we check an
  embedded pointer from a slot instead of the vtable data.
  (scm_sys_struct_data): Remove this temporary function.
  (scm_sys_modify_instance): Update to swap slot values instead of the
  data pointers themselves.
  (scm_sys_modify_class): Use scm_sys_modify_instance.
  (scm_sys_goops_loaded): Capture class-of-obsolete-indirect-instance
  instead of migrate-instance.
  (scm_init_goops_builtins): Don't export the "valid" flag any more;
  export instead the "indirect" and "needs-migration" flags.
* libguile/foreign-object.c (scm_assert_foreign_object_type): Add a
  FIXME.
* libguile/vm-engine.c (class-of): Take away fast path for the time
  being.
* module/oop/goops.scm (class-has-indirect-instances?)
  (indirect-slots-need-migration?): New helpers.
  (<class>, <slot>, %class-slot-definition, initialize): Remove use of
  vtable-flag-goops-valid.
  (define-class): Always push redefined values through
  `class-redefinition'.
  (<redefinable-class>): New public definition.  Use it as a metaclass
  for redefinable classes.  Provide a compute-slots function that
  declares the indirect slots mechanism.  Add the "indirect" flag to
  instances of <redefinable-class>.  Create indirect-slots objects for
  instances of those classes as part of their allocate-instance.
  (change-object-class, class-of-obsolete-indirect-instance): Update for
  new representation change.
* test-suite/tests/goops.test ("object update"): Add #:metaclass
  <redefinable-class> to all redefinable classes.  For the "hell" test,
  make the new classes with class-direct-slots, not class-slots; this
  was an error in the test.
2017-09-14 09:44:30 +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
6e573a0885 Attempt to mutate residualized literal pair throws exception
* libguile/validate.h (SCM_VALIDATE_MUTABLE_PAIR):
* libguile/pairs.h (scm_is_mutable_pair): New internal definitions.
* libguile/pairs.c (scm_set_car_x, scm_set_cdr_x): Validate mutable
  pairs.
* libguile/alist.c (scm_assq_set_x, scm_assv_set_x, scm_assoc_set_x):
* libguile/list.c (scm_reverse_x, scm_list_set_x, scm_list_cdr_set_x):
* libguile/srcprop.c (scm_make_srcprops):
* libguile/srfi-1.c (scm_srfi1_append_reverse_x)
  (scm_srfi1_delete_duplicates_x):
* libguile/symbols.c (scm_symbol_fset_x, scm_symbol_pset_x):
* libguile/sort.c (scm_merge_list_x): Use scm_set_car_x / scm_set_cdr_x
  instead of the macros, so as to check for mutable pairs.
  (SCM_VALIDATE_MUTABLE_LIST): New internal helper macro.
  (scm_sort_x, scm_stable_sort_x, scm_sort_list_x): Use
  SCM_VALIDATE_MUTABLE_LIST.
* libguile/vm-engine.c (VM_VALIDATE_MUTABLE_PAIR): New definition.
  (set-car!, set-cdr!): Use VM_VALIDATE_MUTABLE_PAIR.  Fix error message
  for set-cdr!.
2017-04-18 21:27:45 +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
68f13adaaf Better errors for odd-length keyword args
* libguile/vm-engine.c (bind-kwargs):
* libguile/vm.c (vm_error_kwargs_missing_value):
* libguile/eval.c (error_missing_value)
  (prepare_boot_closure_env_for_apply): Adapt to mirror VM behavior.
* libguile/keywords.c (scm_c_bind_keyword_arguments): Likewise.
* module/ice-9/eval.scm (primitive-eval): Update to error on (foo #:kw)
  with a "Keyword argument has no value" instead of the horrible "odd
  argument list length".  Also adapts to the expected args format for
  the keyword-argument-error exception printer in all cases.  Matches
  1.8 optargs behavior also.
* test-suite/standalone/test-scm-c-bind-keyword-arguments.c (test_missing_value):
  (missing_value_error_handler): Update test.
* test-suite/tests/optargs.test: Add tests.
2017-02-28 22:01:20 +01:00
Daniel Llorens
a0028723da Fix bug #25492
* libguile/vm-engine.c (BR_F64_ARITHMETIC): Fix type.
2017-02-07 12:16:16 +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