* 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.
* gdbinit: Untested attempts to get the stack fondling macros to deal
with the new program representation.
* libguile/frames.c (scm_vm_frame_arguments, scm_vm_frame_source)
(scm_vm_frame_local_ref, scm_vm_frame_local_set_x): SCM_PROGRAM_DATA is
a struct scm_objcode*.
* libguile/instructions.h:
* libguile/instructions.c: Hide the instruction table and the struct
scm_instruction structure; all access to instructions now goes through
procedures. This is because instructions are no longer in a packed
array indexed by opcode. Also, declare a mask that all instructions
should fit in.
* libguile/objcodes.h:
* libguile/objcodes.c: Rewrite so that object code directly maps its
arity and length from its bytecode. This makes it unnecessary to keep
this information in programs, allowing programs to be simple conses
between the code (objcodes) and data (the object table and the closure
variables).
* libguile/programs.c (scm_make_program): Rework so that make-program
takes objcode, an object table, and externals as arguments. It's much
clearer this way, and we avoid malloc().
* libguile/stacks.c (is_vm_bootstrap_frame): Update for program/objcode
changes.
* libguile/vm-engine.c (vm_run): Initialize the jump table on the first
run, with the opcodes declared in the instruction sources, and with bad
instructions raising an error instead of wandering off into the
Unknown.
* libguile/vm-engine.h (FETCH_LENGTH): Always represent lengths as 3
bytes. The old code was too error-prone.
(NEXT_JUMP): Mask the instruction with SCM_VM_INSTRUCTION_MASK.
(NEW_FRAME): Update for program/objcode changes.
* libguile/vm-expand.h (VM_DEFINE_FUNCTION, VM_DEFINE_INSTRUCTION)
(VM_DEFINE_LOADER): Update so that we explicitly specify opcodes, so
that we have a stable bytecode API.
* libguile/vm-i-loader.c: Update license to LGPLv2+. Explicitly declare
opcodes.
(load-integer): Use an int instead of a long as the accumulator; still
need to revisit this code at some point, I think.
(load-program): Simplify, thankfully!! Just creates the objcode slice
and rolls with it.
* libguile/vm-i-scheme.c: Number the opcodes explicitly.
* libguile/vm-i-system.c: Update license to LGPLv2+. Explicitly declare
opcodes.
(make-closure): Update for new program API.
* libguile/vm.c (vm_make_boot_program): Update for new program/objcode
API. Still a bit ugly.
(scm_load_compiled_with_vm): Update for new program/objcode API.
* module/language/assembly.scm (byte-length): Fix byte-length calculation
for loaders, and load-program.
(code-pack, code-unpack): Start to move things from (system vm conv)
here.
(object->code, code->object): More things from conv.scm.
* module/language/glil.scm (<glil-program>): Add a new field,
closure-level.
(make-glil-program, compute-closure-level): Calculate the "closure
level" when making a glil program. This is the maximum depth of
external binding refs in this closure.
(unparse-glil): Fix label serialization.
* module/language/glil/compile-assembly.scm (make-meta): Prepend #f for
the meta's object table, though maybe in the future we can avoid
creating assembly in the first place.
(assoc-ref-or-acons, object-index-and-alist): GRRR! Caught again by the
different sets of arguments to assoc and assoc-ref!
(glil->assembly): Attempt to make the <glil-program> case more
readable, and fix the bugs. Sorry I don't know how to comment this
change any more than this.
(glil->assembly): For <glil-module> serialize the whole key, not just
the name.
(dump-object): subprogram-code is already a list. Serialize integers as
strings, not u8vectors. Fix the order of lists and vectors.
* module/language/glil/spec.scm (glil): Switch orders, so we prefer glil
-> assembly -> objcode. Actually glil->objcode doesn't work any more,
needs to be removed I think.
* module/language/objcode/spec.scm (objcode->value):
s/objcode->program/make-program/.
* module/language/scheme/inline.scm: Add acons inline.
* module/system/vm/conv.scm (make-byte-decoder): Skip the first 8 bytes,
they are header. Handle subprograms properly. Still needs help though.
(decode-length): Lengths are always 3 bytes now.
* module/system/vm/disasm.scm: Superficial changes to keep things
working. I'd like to fix this better in the future.
* module/system/vm/frame.scm (bootstrap-frame?): Fixes for
program-bytecode.
* module/system/vm/program.scm: Export make-program. It's program-objcode
now, no more program-bytecode.
* module/system/vm/vm.scm (vm-load): Use make-program.
* test-suite/tests/asm-to-bytecode.test: New test, very minimal.
* module/system/vm/objcode.scm: Export word-size, byte-order, and
write-objcode.
* gdbinit (pp, inst): New commands.
* libguile/vm-engine.c (vm_error_not_a_pair): New error case.
* libguile/vm-i-scheme.c (VM_VALIDATE_CONS): New macro -- use this
instead of SCM_VALIDATE_* because SCM_VALIDATE will exit nonlocally
before we have a chance to sync the regs.
(car, cdr, set-car, set-cdr): Use VM_VALIDATE_CONS.
* libguile/vm-i-system.c (goto/args): Bugfix: when doing a
self-tail-recursion, allocate fresh externals. Fixes use of match.go.
* module/system/vm/assemble.scm (dump-object!): Add some checks that we
aren't dumping out values that the VM can't handle.
* module/system/vm/disasm.scm (disassemble-externals): Fix rotten call to
`print-info'.
* oop/goops/dispatch.scm: Add a FIXME.
* testsuite/Makefile.am (vm_test_files):
* testsuite/t-closure4.scm (extract-symbols): New test, distilled with
much effort out of match.scm.
* ice-9/Makefile.am (NOCOMP_SOURCES): Re-enable compilation of match.scm.
Yay!
* libguile/vm-engine.h (CHECK_STACK_LEAK, NULLSTACK): Add a new mode,
VM_ENABLE_STACK_NULLING, that tries to ensure that all stack data past
the top of the stack is NULL. This helps to verify the VM's
consistency. If VM_ENABLE_STACK_NULLING is not defined, there is no
overhead.
(DROP, DROPN): Hook into NULLSTACK.
(POP_LIST): Hoo, fix a good bug: if CONS triggered a GC, the elements
of the list that had not yet been consed would not be marked, because
the sp was already below them.
(NEXT): Hook into CHECK_STACK_LEAK.
(INIT_ARGS): Add a note that consing the rest arg can cause GC.
(NEW_FRAME): Cons up the external data after initializing the frame, so
that if GC is triggered, the precise marker sees a well-formed frame.
* libguile/vm-i-loader.c (load-program): In the four-integers case, use
the POP macro so that we can hook into NULLSTACK (if necessary).
* libguile/vm-i-scheme.c (ARGS2, ARGS3): Hook into NULLSTACK.
* libguile/vm-i-system.c (halt): Null the nvalues. Rework some asserts
into using ASSERT, and null the stack when we free the frame.
(variable-set): Use DROPN instead of sp -= 2.
(BR): Hook into NULLSTACK.
(goto/args): Hook into NULLSTACK. In the non-self case, delay updating
the frame until after INIT_ARGS so that GC sees a well-formed frame.
Delay consing the externals until after the frame is set up, as in
NEW_FRAME.
(call/cc): Add some asserts.
(return): Rework some asserts into ASSERT, and hook into NULLSTACK.
(return/values): Hook into NULLSTACK, and use ASSERT.
(return/values*) Use ASSERT.
* libguile/vm.c (VM_ENABLE_ASSERTIONS, VM_ENABLE_STACK_NULLING): These
are the variables that control assertions and nulling. Perhaps we can
do these per-engine when we start compiling the debug engine separate
from a speedy engine.
(vm_mark_stack): Add a precise stack marker. Yay!
(vm_cont_mark): Mark the continuation stack precisely.
(capture_vm_cont): Record the difference from the vp's stack_base too,
so that we can translate the dynamic links when marking the
continuation stack. Memset the stack to NULL if we are doing nulling.
(reinstate_vm_cont): If we are nulling, null out the relevant part
of the stack.
(vm_reset_stack): When resetting sp due to a nonlocal exit, null out
the stack too.
(vm_mark): If we are nulling, assert that there are no extra values on
the stack. Mark the stack precisely.
* libguile/vm-i-scheme.c (FUNC1): Remove, cause it's not used.
(FUNC2): Don't assume an inum can fit into an int, use scm_bits_t
instead. In reality though we should probably do use different checks,
i.e. for multiplication probably we overflow. (That would be a bug.)
Based on a patch by C. K. Jester-Young <cky944 <at> gmail.com>.
* ice-9/boot-9.scm: Only define load-compiled as #f if it's not already
defined, which won't normally be the case.
* libguile/guile-vm.c: Removed, there's no more guile-vm binary.
* libguile/frames.c: (with change frame? -> heap-frame?)
* 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: (was bootstrap.h)
* libguile/vm-engine.c: (was vm_engine.c)
* libguile/vm-engine.h: (was vm_engine.h)
* libguile/vm-expand.h: (was vm_expand.h)
* libguile/vm-i-loader.c: (was vm_loader.c)
* libguile/vm-i-scheme.c: (was vm_scheme.c)
* libguile/vm-i-system.c: (was vm_system.c)
* libguile/vm.c:
* libguile/vm.h: These files moved here from src/, as guile-vm is now a
part of libguile.
* libguile/init.c: Bootstrap the VM. Yay!
* libguile/Makefile.am: The necessary chicanery here.
* module/system/vm/Makefile.am:
* module/system/vm/bootstrap.scm:
* module/system/vm/frame.scm:
* module/system/vm/instruction.scm:
* module/system/vm/objcode.scm:
* module/system/vm/program.scm:
* module/system/vm/vm.scm:
* pre-inst-guile-env.in: Add builddirs to the load path; add module/ to
the path in the empty-$GUILE_LOAD_PATH case as well.
* src/Makefile.am: Moved out everything except guilec and guile-disasm,
which probably should be moved to the scripts directory?
* testsuite/Makefile.am: Update to find guile-vm in the right place.
* module/system/vm/Makefile.am:
* module/system/vm/bootstrap.scm: Removed bootstrap.scm, scm_init_guile
handles the bootstrapping for us.
* module/system/vm/frame.scm:
* module/system/vm/instruction.scm:
* module/system/vm/objcode.scm:
* module/system/vm/program.scm:
* module/system/vm/vm.scm: Call the init functions in libguile; should
fix at some point to avoid the dlopen?