* libguile/vm-i-scheme.c (VM_VALIDATE_STRUCT): Fix the error message if
the value was not a struct.
* module/system/base/compile.scm (find-language-joint): Default to
joining at the target language.
(default-language-joiner): Allow sequences of one compiled expression
to pass through. Otherwise error as before.
(read-and-parse): New helper; actually parses.
(read-and-compile): Use read-and-parse, and fall back to
default-language-joiner.
Thanks to Nala Ginrut for the report.
* libguile/vm.c:
(vm_error):
(vm_error_bad_instruction):
(vm_error_unbound):
(vm_error_unbound_fluid):
(vm_error_not_a_variable):
(vm_error_not_a_thunk):
(vm_error_apply_to_non_list):
(vm_error_kwargs_length_not_even):
(vm_error_kwargs_invalid_keyword):
(vm_error_kwargs_unrecognized_keyword):
(vm_error_too_many_args):
(vm_error_wrong_num_args):
(vm_error_wrong_type_apply):
(vm_error_stack_overflow):
(vm_error_stack_underflow):
(vm_error_improper_list):
(vm_error_not_a_pair):
(vm_error_not_a_bytevector):
(vm_error_not_a_struct):
(vm_error_no_values):
(vm_error_not_enough_values):
(vm_error_continuation_not_rewindable):
(vm_error_bad_wide_string_length):
(vm_error_invalid_address):
(vm_error_object):
(vm_error_free_variable): New internal helpers, implementing VM error
handling.
* libguile/vm-engine.h (VM_ASSERT): New helper macro.
(ASSERT, CHECK_OBJECT, CHECK_FREE_VARIABLE):
(PRE_CHECK_UNDERFLOW, PUSH_LIST): Use the new helper.
* libguile/vm-i-loader.c:
* libguile/vm-i-scheme.c:
* libguile/vm-i-system.c: Use VM_ASSERT and the out-of-line error
handlers.
* libguile/vm-engine.c (vm_engine): Remove inline error handlers, and
remove a couple of local vars. Use VM_ASSERT. Have halt handle the
return itself.
* libguile/vm-engine.h (DEAD): New macro, nulls out a value.
* libguile/vm-i-system.c:
* libguile/vm-i-loader.c:
* libguile/vm-i-scheme.c: Use DEAD when variables become dead.
Later we can #ifdef this out, but I want to give the buildbots a try
with this patch to make sure it's correct.
* libguile/foreign.c: Use `alignof_type' instead of `alignof'; the
latter was removed from Gnulib's <alignof.h> in
408e170e3ae81f73fb65686c5834693d89a96594 (Nov. 1 2011).
* libguile/vm-i-scheme.c: Likewise.
* libguile/vm-engine.c (VM_CHECK_OBJECT, VM_CHECK_FREE_VARIABLES): Set
to 0 for both engines. These are really internal debugging variables,
which don't affect user-visible features, provided that the compiler
is correct of course.
(VM_CHECK_UNDERFLOW): New var, also off by default: whether to check
for stack underflow when popping values.
(vm_engine): Don't declare object_count if we are not checking object
table accesses.
* libguile/vm-engine.h (CACHE_PROGRAM): Don't muck with object_count
if we are not checking object table accesses.
(CHECK_UNDERFLOW, PRE_CHECK_UNDERFLOW): Nop out if we are not checking
underflow.
(POP2, POP3): New macros which check for underflow before popping more
than one value.
* libguile/vm-i-loader.c (load_array):
* libguile/vm-i-scheme.c (set_car, set_cdr, vector_set, slot_set)
(BV_SET_WITH_ENDIANNESS, BV_FIXABLE_INT_SET, BV_INT_SET)
(BV_FLOAT_SET):
* libguile/vm-i-system.c (partial_cont_call, fix_closure, prompt)
(fluid_set): Use POP2 / POP3.
(local_set, long_local_set): Pop to locals instead of using values on
the stack then dropping; allows for underflow to be checked before the
value is accessed.
(BR): Don't NULLSTACK or DROP after the operation.
(br_if, br_if_not, br_if_eq, br_if_not_eq, br_if_null)
(br_if_not_null): Pop to locals before doing the compare and jump.
* libguile/bytevectors.c:
* libguile/goops.c:
* libguile/instructions.c:
* libguile/numbers.c:
* libguile/random.c:
* libguile/read.c:
* libguile/vm-i-scheme.c: Fix a number of assumptions that a long could
hold an inum. This is not the case on platforms whose void* is larger
than their long.
* libguile/numbers.c (scm_i_inum2big): New helper, only implemented for
sizeof(void*) == sizeof(long); produces a compile error on other
platforms. Basically gmp doesn't have a nice interface for converting
between mpz values and intmax_t.
This results in a 17% improvement in the execution time of the "+" and
"-" benchmarks for fixnums.
* libguile/vm-i-scheme.c (ASM_ADD, ASM_SUB)[defined __x86_64__ &&
SCM_GNUC_PREREQ (4, 5)]: New macros.
(add)[defined ASM_ADD]: Use `ASM_ADD' for the fast path.
(sub)[defined ASM_SUB]: Use `ASM_SUB' for the fast path.
* test-suite/tests/numbers.test ("+")["fixnum + fixnum = bignum
(32-bit)", "fixnum + fixnum = bignum (64-bit)", "bignum + fixnum =
fixnum", "wrong type"]: New tests.
("-")["fixnum - fixnum = bignum (32-bit)", "fixnum - fixnum = bignum
(64-bit)", "bignum - fixnum = fixnum", "wrong type"]: New tests.
* test-suite/tests/00-initial-env.test ("goopsless")["+ wrong type
argument"]: Use `with-test-prefix/c&e' instead of `with-test-prefix'.
["- wrong type argument"]: New test prefix.
* libguile/vm-i-scheme.c (INUM_MAX, INUM_MIN): New macros.
(add1, sub1): Add/subtract without untagging the operand. This leads
to a 44% run time improvement compared to the previous
implementation.
* libguile/vm.c: Include <stdint.h>.
* test-suite/tests/numbers.test ("1+", "1-"): Add tests for
MOST-POSITIVE-FIXNUM, resp. MOST-NEGATIVE-FIXNUM, for 32-bit and
34-bit values thereof.
* benchmark-suite/benchmarks/arithmetic.bm: New file.
* benchmark-suite/Makefile.am (SCM_BENCHMARKS): Add it.
* libguile/vm-i-scheme.c (symbol?, vector?): New
instructions. Renumbered the rest.
* libguile/vm-i-system.c: Renumber instructions.
* libguile/_scm.h (SCM_OBJCODE_MINOR_VERSION): Bump.
* module/ice-9/psyntax.scm (binding-type, binding-value): Define using
macros so that we inline to car and cdr opcodes. Oh, for an inliner :)
* module/language/tree-il/compile-glil.scm (*primcall-ops*)
* module/language/tree-il/primitives.scm
(*interesting-primitive-names*, *effect-free-primitives*)
(*effect+exception-free-primitives*): Add symbol? and vector?
inlines.
* libguile/vm-engine.c: Add func_name local, for error reporting.
(vm_error_apply_to_non_list): New error case.
(vm_error_wrong_type_arg): Remove this generic error case.
(vm_error_wrong_type_apply): Remove FUNC_NAME -- no sense in seeing
"vm-debug-engine" in the error report.
(vm_error_not_a_pair, vm_error_not_a_bytevector)
(vm_error_not_a_struct, vm_error_not_a_thunk): Use func_name instead
of FUNC_NAME, so we can indicate what caused the error.
* libguile/vm-i-scheme.c (VM_VALIDATE_CONS, car, cdr, set-car!)
(set-cdr!): Indicate provenance of errors.
(VM_VALIDATE_STRUCT, struct-vtable):
(VM_VALIDATE_BYTEVECTOR, BV_FIXABLE_INT_REF, BV_INT_REF)
(BV_FLOAT_REF, BV_FIXABLE_INT_SET, BV_INT_SET, BV_FLOAT_SET): Same.
* libguile/vm-i-system.c (apply, tail-apply): Use
vm_error_apply_to_non_list.
* libguile/vm-i-scheme.c (ALIGNED_P): New macro.
(BV_FIXABLE_INT_REF, BV_INT_REF, BV_FLOAT_REF, BV_FIXABLE_INT_SET,
BV_INT_SET, BV_FLOAT_SET): Check the alignment of the pointer instead
of checking "i % size == 0". This fixes bus errors on
`sparc64-linux-gnu'.
* libguile/vm.c: Include <alignof.h>.
* libguile/_scm.h (SCM_OBJCODE_MINOR_VERSION): Bump for make-struct
change.
* libguile/struct.c (scm_i_alloc_struct): Use scm_words instead of
scm_gc_malloc to simplify the code and inline the call to GC_MALLOC.
* module/language/tree-il/compile-glil.scm (*primcall-ops*): Compile
make-struct/no-tail to make-struct.
* module/language/tree-il/primitives.scm (define-primitive-expander):
Allow a conditional branch of #f to aboirt inlining.
(make-struct): Expand into make-struct/no-tail in the case that
tail-size is 0.
* libguile/vm-i-scheme.c (make-struct): Adapt to always assume tail-size
is 0. Inline allocation if possible. Don't decrement the SP past live
objects on the stack, which could cause GC to miss references. Use the
NULLSTACK macro.
* libguile/pairs.h (scm_is_null): Nil is also null.
* libguile/vm-i-scheme.c (not, not-not, null?, not-null?):
* libguile/vm-i-system.c (br-if-null, br-if-not-null): Remove some more
nil special cases.
Thanks to Andy for noticing this.
* libguile/vm-engine.h (SYNC_REGISTER, CACHE_REGISTER): Add comment.
* libguile/vm-i-scheme.c (make_struct): Call `SYNC_REGISTER ()' in all
cases since the GC is going to run.
(struct_ref, struct_set): Call `SYNC_REGISTER ()' on the slow path.
(BV_REF_WITH_ENDIANNESS, BV_FIXABLE_INT_REF, BV_INT_REF): Likewise.
(BV_FLOAT_REF): Always `SYNC_REGISTER ()'.
* libguile/arrays.h:
* libguile/arrays.c (scm_from_contiguous_array): New public function,
like scm_from_contiguous_typed_array but for arrays of generic Scheme
values.
* libguile/vm-i-scheme.c (make-struct): Sync regs before making the
struct, so if we get a GC the regs are on the heap.
(make-array): New instruction, makes an generic (untyped) Scheme
array.
* module/language/glil/compile-assembly.scm (dump-object): Correctly
compile arrays.
* libguile/frames.c, libguile/instructions.c, libguile/objcodes.c,
libguile/programs.c, libguile/throw.c, libguile/vm-i-scheme.c,
libguile/vm.c: Replace uses of discouraged constructs by their
current counterparts.
This should also fix "condition is always true" warnings.
* libguile/vm-i-scheme.c (bv_u32_native_ref, bv_s32_native_ref,
bv_u32_native_set, bv_s32_native_set): Conditionalize use of
`BV_FIXABLE_INT_REF' vs. `BV_INT_REF' based on `SIZEOF_VOID_P'.
* libguile/vm-i-scheme.c (vector-ref, vector-set): Sync registers if we
call out to C.
* module/language/tree-il/compile-glil.scm (flatten-lambda): Add an
extra argument, the self-label, which should be the gensym under which
the procedure is bound in a <fix> expression.
(flatten): If we see a call to a lexical ref to the self-label in a
tail position, rename and goto instead of goto/args, which will tear
down the frame -- or will, in the future. It's a primitive form of
loop detection.
* module/language/tree-il/primitives.scm (zero?): Expand to (= x 0).
* libguile/vm-i-scheme.c: Add add1 and sub1 instructions.
* module/language/tree-il/compile-glil.scm: Compile 1+ and 1- to add1
and sub1.
* module/language/tree-il/primitives.scm (define-primitive-expander):
Add support for `if' statements in the consequent.
(+, -): Compile (- x 1), (+ x 1), and (+ 1 x) to 1- or 1+ as
appropriate.
(1-): Remove this one. Seems we forgot 1+ before, but we weren't
compiling it nicely anyway.
* test-suite/tests/tree-il.test ("void"): Fix expected compilation of (+
(void) 1) to allow for add1.
* libguile/objcodes.c (OBJCODE_COOKIE): Bump.
* libguile/vm-i-loader.c:
* libguile/vm-i-scheme.c:
* libguile/vm-i-system.c: Renumber instructions, so I can have a bit
more space to work.
* libguile/vm-i-scheme.c (BV_FIXABLE_INT_REF, BV_INT_REF):
(BV_FLOAT_REF, BV_FIXABLE_INT_SET, BV_INT_SET, BV_FLOAT_SET): Fix the
bounds check for the last element.
* libguile/vm-i-scheme.c (vector_ref, vector_set, BV_FIXABLE_INT_REF,
BV_INT_REF, BV_FLOAT_REF, BV_FIXABLE_INT_SET, BV_INT_SET,
BV_FLOAT_SET): Explicitly initialize all locals, to make some versions
of GCC happier. Patch by Dale P. Smith <dsmich@roadrunner.com>.
* libguile/instructions.c (scm_instruction_list): Fix a longstanding bug
in this humble function.
* libguile/vm-i-scheme.c (BV_FIXABLE_INT_SET, BV_INT_SET, BV_FLOAT_SET):
Fix some bugs in these macros -- now the bytevector ops work.
* module/language/tree-il/compile-glil.scm (*primcall-ops*): Compile
bytevector calls to VM ops.
* module/language/tree-il/primitives.scm
(*interesting-primitive-names*): Resolve bytevector calls to primitive
calls.
* module/language/tree-il/primitives.scm
(*interesting-primitive-names*): Resolve vector-ref and vector-set!.
* module/language/tree-il/compile-glil.scm (*primcall-ops*): And compile
vector-ref and vector-set! to their opcodes.
* libguile/vm-i-scheme.c (vector-ref, vector-set): New opcodes, placed
before the bytevector ops. The renumbering shouldn't affect anyone,
given that the bytevector ops were not yet used. Fix a few bugs in the
bytevector ops.
* libguile/instructions.h (SCM_VM_NUM_INSTRUCTIONS): Enlarge to 255. Not
sure what performance effects this will have.
* libguile/vm-engine.c: Add new error case, vm_error_not_a_bytevector.
* libguile/vm-engine.h: Don't assign specific registers for i386. Having
added the new VM vector ops, GCC 4.4 is erroring for me now.
* libguile/vm-i-scheme.c: Add bytevector-specific ops to the VM.
We don't actually use them yet, though.
* libguile/objcodes.c (OBJCODE_COOKIE): Bump the objcode cookie. We'll
be doing this on incompatible changes until 2.0.
* libguile/vm-i-scheme.c (set_car, set_cdr, slot_set): These
instructions don't have natural return values -- so declare them that
way, that they push 0 values.
* module/language/tree-il/compile-glil.scm (flatten): When compiling
primitive calls, check `(instruction-pushes op)' to see how many
values that instruction will push, and do something appropriate,
instead of just assuming that all primcall ops push 1 value.
* libguile/vm-i-scheme.c (FUNC2): Use a signed value for the intermediate
result here. Not sure what the effect is, though.
* module/ice-9/psyntax.scm (chi-top): Toplevel definitions ensure that
variables are defined in the current module. Fixes the specific case of
guile-lib's md5.scm, which redefines + -- this code is needed so that
we don't incorrectly open-code +.
* module/language/tree-il/primitives.scm (resolve-primitives!): I think
there were some cases in which vars and names would not resolve
properly here. Fix those.
* libguile/frames.c:
* libguile/frames.h:
* libguile/instructions.c:
* libguile/instructions.h:
* libguile/objcodes.c:
* libguile/objcodes.h:
* libguile/programs.c:
* libguile/programs.h:
* libguile/vm-bootstrap.h:
* libguile/vm-engine.c:
* libguile/vm-engine.h:
* libguile/vm-expand.h:
* libguile/vm-i-scheme.c:
* libguile/vm.c:
* libguile/vm.h: Update to use SCM_API and SCM_INTERNAL correctly. Adjust
copyright to be the same as the copyright of Guile itself, which should
be fine given that the FSF holds the whole thing.
* libguile/vm-engine.c (VM_PUSH_DEBUG_FRAMES): New knob, if true we much
with the scm_i_last_debug_frame when entering the VM, because sometimes
the evaluator doesn't do it for us.
(VM_ENGINE): Plug through debug frame fondling. Now, program exit comes
back to the main text. Rename err_args to finish_args, and reuse for
the return value.
* libguile/vm-engine.h (PUSH_LIST):
* libguile/vm-i-loader.c:
* libguile/vm-i-scheme.c:
* libguile/vm-i-system.c: Update for finish_args.
(halt): goto vm_done, now, instead of returning directly.