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

28 commits

Author SHA1 Message Date
Michael Gran
9c44cd4559 Add Unicode strings and symbols
This adds full Unicode strings as a datatype, and it adds some
minimal functionality.  The terminal and port encoding is assumed
to be ISO-8859-1.  Non-ISO-8859-1 characters are written or
input as string character escapes.

The string character escapes now have 3 forms: \xXX \uXXXX and
\UXXXXXX, for unprintable characters that have 2, 4 or 6 hex digits.

The process for writing to strings has been modified.  There is now a
function scm_i_string_start_writing that does the copy-on-write
conversion if necessary.

To compile strings that may be wide, the VM storage of strings and
string-likes has changed.

Most string-using functions have not yet been updated and may break
when used with wide strings.


        * module/language/assembly/compile-bytecode.scm (write-bytecode):
        use variable width string bytecode format

        * module/language/assembly.scm (byte-length): use variable width
        bytecode format

        * libguile/vm-i-loader.c (load-string, load-symbol):
        (load-keyword, define): use variable-width bytecode format

        * libguile/vm-engine.h (FETCH_WIDTH): new macro

        * libguile/strings.h: new declarations

        * libguile/strings.c (make_wide_stringbuf): new function
        (widen_stringbuf): new function
        (scm_i_make_wide_string): new function
        (scm_i_is_narrow_string): new function
        (scm_i_string_wide_chars): new function
        (scm_i_string_start_writing): new function
        (scm_i_string_ref): new function
        (scm_i_string_set_x): new function
        (scm_i_is_narrow_symbol): new function
        (scm_i_symbol_wide_chars, scm_i_symbol_ref): new function
        (scm_string_width): new function
        (unistring_escapes_to_guile_escapes): new function
        (scm_to_stringn): new function
        (scm_i_stringbuf_free): modify for wide strings
        (scm_i_substring_copy): modify for wide strings
        (scm_i_string_chars, scm_string_append): modify for wide strings
        (scm_i_make_symbol, scm_to_locale_stringn): modify for wide strings
        (scm_string_dump, scm_symbol_dump, scm_to_locale_stringbuf):
        (scm_string, scm_i_deprecated_string_chars): modify for wide strings
        (scm_from_locale_string, scm_from_locale_stringn): add null test

        * libguile/srfi-13.c: add calls for scm_i_string_start_writing for
        each call of scm_i_string_stop_writing
        (scm_string_for_each): modify for wide strings

        * libguile/socket.c: add calls for scm_i_string_start_writing for each
        call of scm_i_string_stop_writing

        * libguile/rw.c: add calls for scm_i_string_start_writing for each
        call of scm_i_string_stop_writing

        * libguile/read.c (scm_read_string): allow reading of wide strings

        * libguile/print.h: add declaration for scm_charprint

        * libguile/print.c (iprin1): print wide strings and add new string
        escapes
        (scm_charprint): new function

        * libguile/ports.h: new declarations for scm_lfwrite_substr and
        scm_lfwrite_str

        * libguile/ports.c (update_port_lf): new function
        (scm_lfwrite): use update_port_lf
        (scm_lfwrite_substr): new function
        (scm_lfwrite_str): new function

        * test-suite/tests/asm-to-bytecode.test ("compiler"): add string
        width byte to sting-like asm tests
2009-08-08 02:35:00 -07:00
Andy Wingo
28b119ee3d make sure all programs are 8-byte aligned
* libguile/objcodes.c (OBJCODE_COOKIE): Bump objcode cookie, as we added
  to struct scm_objcode.
* libguile/objcodes.h (struct scm_objcode): Add a uint32 after metalen
  and before base, so that if the structure has 8-byte alignment, base
  will have 8-byte alignment too. (Before, base was 12 bytes from the
  start of the structure, now it's 16 bytes.)

* libguile/vm-engine.h (ASSERT_ALIGNED_PROCEDURE): Add a check that can
  be turned on with VM_ENABLE_PARANOID_ASSERTIONS.
  (CACHE_PROGRAM): Call ASSERT_ALIGNED_PROCEDURE.

* libguile/vm-i-system.c (long-local-ref): Add a missing semicolon.

* libguile/vm.c (really_make_boot_program): Rework to operate directly
  on a malloc'd buffer, so that the program will be 8-byte aligned.

* module/language/assembly.scm (*program-header-len*): Add another 4 for
  the padding.
  (object->assembly): Fix case in which we would return (make-int8 0)
  instead of (make-int8:0). This would throw off compile-assembly.scm's
  use of addr+.

* module/language/assembly/compile-bytecode.scm (write-bytecode): Write
  out the padding int.

* module/language/assembly/decompile-bytecode.scm (decode-load-program):
  And pop off the padding int too.

* module/language/glil/compile-assembly.scm (glil->assembly): Don't pack
  the assembly, assume that assembly.scm has done it for us. If a
  program has a meta, pad out the program so that meta will be aligned.

* test-suite/tests/asm-to-bytecode.test: Adapt to expect programs to
  have the extra 4-byte padding int.
2009-07-26 12:57:11 +02:00
Andy Wingo
57ab0671d7 rename "closure-ref" to "free-ref"; s/vars/variables/ in some names
* libguile/programs.h:
* libguile/programs.c: (SCM_PROGRAM_FREE_VARIABLES): Rename from
  SCM_PROGRAM_FREE_VARS. Callers changed.
* libguile/programs.c (scm_make_program): Rename arg to
  "free_variables".
  (scm_program_free_variables): Rename from program-free-vars.

* libguile/vm-engine.h:
* libguile/vm-engine.c (VM_CHECK_FREE_VARIABLES): Rename from
  VM_CHECK_CLOSURE.
  (vm_engine, CACHE_PROGRAM): Rename closure and closure_count to free_vars and
  free_vars_vount.

* libguile/vm-i-system.c (FREE_VARIABLE_REF): Rename from CLOSURE_REF.
  (free-ref, free-boxed-ref, free-boxed-set): Rename from closure-ref,
  closure-boxed-ref, closure-boxed-set.
  (make-closure): Renamed from make-closure2.

* module/language/glil/compile-assembly.scm (glil->assembly): Hack to
  never write out the the old "make-closure" instruction. Will fix
  better later. Change to emit free-ref etc instead of closure-ref.

* module/language/tree-il/compile-glil.scm (flatten): Emit make-closure
  instead of make-closure2, now that the old make-closure is gone.

* module/system/vm/program.scm (system): Rename program-free-vars to
  program-free-variables.

* test-suite/tests/tree-il.test ("lambda"): Update for make-closure.
2009-07-23 17:15:17 +02:00
Andy Wingo
20d47c3915 remove "externals" from the vm
* libguile/frames.c (scm_frame_external_link): Removed.
* libguile/frames.h: No need to have the "external link" in the stack
  frame -- update macros to take the new situation into account.

* libguile/objcodes.h (struct scm_objcode): Rename the nexts field to
  "unused". In the future we can use it for nlocs, I think.
  (SCM_OBJCODE_NEXTS): removed.

* libguile/programs.h:
* libguile/programs.c (scm_make_program): Expect the third argument to
  be a vector of free variables, not a list of free variables.
  SCM_BOOL_F indicates no free variables, not SCM_EOL.
  (program_mark): Adapt.
  (scm_program_arity): No more nexts.
  (scm_program_free_vars): Replaces scm_program_externals.

* libguile/vm-engine.c (VM_CHECK_EXTERNAL)
  (vm_engine): No need for the "external" var.
* libguile/vm-engine.h (CACHE_PROGRAM): Update for SCM_PROGRAM_FREE_VARS
  instead of SCM_PROGRAM_EXTERNALS.
  (NEW_FRAME): Update for new frame size, and no need to cons up
  externals. Yay :)

* libguile/vm-i-loader.c (load-program): Update for scm_make_program.

* libguile/vm-i-system.c (external-ref, external-set): No more.
  (make-closure): No more.
  (goto/args): No need to re-cons externals here. Update for new stack
  frame size.
  (mv-call, return, return/values): Update for new frame size. No need
  to reinstate externals on return.

* libguile/vm.c (really_make_boot_program, scm_load_compiled_with_vm):
  Update for scm_make_program.
* module/language/objcode/spec.scm (objcode-env-externals): Treat '() as
  #f, for the externals. Need to clean this up later...
* module/system/vm/program.scm (arity:nexts): Remove. Rename
  program-external to program-free-vars.
2009-07-23 17:15:13 +02:00
Andy Wingo
8d90b35656 vm support for display closures
* libguile/vm-i-system.c (box, empty-box): Boxing values and storing
  them in local variables.
  (local-boxed-ref, local-boxed-set): A combination of local-ref then
  variable-ref/set.
  (make-closure2, closure-ref, closure-boxed-ref, closure-boxed-set):
  New ops. The idea is to migrate Guile over to using flat dispay
  closures. See the paper "Three Implementation Models for Scheme" by
  Kent Dybvig for more details; this is the "stack-based" model.

* libguile/vm-engine.c:
* libguile/vm-engine.h: Add the necessary infrastructure to keep track
  of a "closure" variable, like our "externals" in semantics, but
  minimal, flat, and O(1) in implementation.
2009-07-22 00:13:52 +02:00
Andy Wingo
e6eb246716 add bytevector ops to the vm
* 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.
2009-06-26 12:42:10 +02:00
Neil Jerram
53befeb700 Change Guile license to LGPLv3+
(Not quite finished, the following will be done tomorrow.
   module/srfi/*.scm
   module/rnrs/*.scm
   module/scripts/*.scm
   testsuite/*.scm
   guile-readline/*
)
2009-06-17 00:22:09 +01:00
Andy Wingo
560b9c256d adjust VM copyright notices to LGPL, use SCM_INTERNAL/API properly
* 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.
2009-05-26 22:23:44 +02:00
Andy Wingo
a1a482e0e9 and, or, cond etc use syntax-rules, compile scheme through tree-il
* libguile/vm-i-system.c:
* libguile/vm-engine.h (ASSERT_BOUND): New assertion, that a value is
  bound. Used by local-ref and external-ref in paranoid mode.

* module/ice-9/boot-9.scm (and, or, cond, case, do): Since we are
  switching to use psyntax as the first pass of the compiler, and perhaps
  soon of the interpreter too, we need to make sure it expands out all
  forms to primitive expressions. So define expanders for these derived
  syntax forms, as in the R5RS report.

* module/ice-9/psyntax-pp.scm: Regenerate, with core forms fully
  expanded.

* module/ice-9/psyntax.scm (build-void): New constructor, for making
  undefined values.
  (build-primref): Add in a hack so that primitive refs in the boot
  module expand out to toplevel refs, not module refs.
  (chi-void): Use build-void.
  (if): Define an expander for if that calls build-conditional.

* module/language/scheme/compile-tree-il.scm (compile-tree-il): Use let*
  so as not to depend on binding order for the result of
  (current-module).

* module/language/scheme/spec.scm (scheme): Switch over to tree-il as the
  primary intermediate language. Not yet fully tested, but at least it
  can compile psyntax-pp.scm.

* module/language/tree-il/analyze.scm (analyze-lexicals): Arguments don't
  count towards a function's nlocs.

* module/language/tree-il/compile-glil.scm (*comp-module*, compile-glil):
  Define a "compilation module" fluid.
  (flatten-lambda): Fix a call to make-glil-argument. Fix bug in
  heapifying arguments.
  (flatten): Fix number of arguments passed to apply instruction. Add a
  special case for `(values ...)'. If inlining primitive-refs fails,
  try expanding into toplevel-refs if the comp-module's variable is the
  same as the root variable.

* module/language/tree-il/optimize.scm (resolve-primitives!): Add missing
  src variable for <module-ref>.

* test-suite/tests/tree-il.test ("lambda"): Fix nlocs counts. Add a
  closure test case.
2009-05-20 11:15:22 +02:00
Andy Wingo
893be93f58 don't crash etch's gcc
* libguile/vm-engine.h: Don't allocate registers in registers if we're on
  Etch's GCC.
2009-02-25 00:16:26 +01:00
Andy Wingo
e06e857c8d in debug mode, make sure that calls to the vm can be captured via make-stack
* 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.
2009-02-05 12:28:19 +01:00
Andy Wingo
7edf200127 inline call to scm_make_program when making closures
* libguile/programs.c (scm_make_program): Add a comment.

* libguile/vm-engine.h (INIT_ARGS): Add a couple of UNLIKELY notes.

* libguile/vm-i-system.c (make-closure): Inline the call to
  scm_make_program, which avoids some redundant checks.
2009-02-05 00:20:51 +01:00
Andy Wingo
6d14383e86 enable multiple vm engines (regular, debug, ...)
* libguile/vm-engine.c (VM_USE_HOOKS, VM_USE_CLOCK, VM_CHECK_EXTERNAL)
  (VM_CHECK_OBJECT): Update to define these here, before including
  vm-engine.h.
  (vm_run): Change so that we can make different engines. Also, we take
  an array of arguments, and the struct scm_vm directly, so as to avoid
  any need to cons.

* libguile/vm-engine.h (CHECK_EXTERNAL, CHECK_OBJECT): Add some UNLIKELY
  bits; don't seem to help.

* libguile/vm.c (vm_dispatch_hook): Change to not pass the VP. This needs
  some love, and perhaps we revert to the old way.
  (VM_ENGINE): Actually make two engines, vm_regular_engine and
  vm_debug_engine. Probably there is room for improvement here. Actually
  their speeds are the same at the moment.
  (make_vm): Choose which engine to run; currently the debug engine by
  default.
  (scm_c_vm_run): A thin wrapper to invoke a VM without consing.
  (scm_vm_apply): Use scm_c_vm_run.
  (scm_load_compiled_with_vm): Use scm_c_vm_run.
2009-02-04 23:47:56 +01:00
Andy Wingo
53e28ed9b2 static opcodes; refactor program/objcode division; use new assembly pipeline
* 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.
2009-01-29 21:12:00 +01:00
Andy Wingo
2fda024221 move module and meta inside programs' object tables
* libguile/programs.h (struct scm_program): Remove the module and meta
  fields.

* libguile/programs.c (scm_c_make_program): Add a new argument, `objs'.
  If it's a vector, we'll look for the module and the metadata in there,
  instead of having them in the scm_program structure.
  (scm_c_make_closure, program_mark, scm_program_meta)
  (scm_c_program_source, scm_program_module): Adapt to the new program
  representation.

* libguile/objcodes.c (scm_objcode_to_program): Pass #f as the object
  table when making the program.

* libguile/vm-engine.h (CACHE_PROGRAM):
* libguile/vm-engine.c (vm_run): Rework to use the simple vector API for
  getting the current object table. Call the helper,
  vm_make_boot_program, to make the boot program.

* libguile/vm-i-loader.c (load-program): Set the current module and the
  meta in the object vector, which we pass to scm_c_make_program.

* libguile/vm-i-system.c (toplevel-ref, toplevel-set): Adapt to the new
  program representation.

* module/language/glil/compile-objcode.scm (codegen): Clarify.
2009-01-17 16:42:53 +01:00
Andy Wingo
fb10a0084e allow `apply' on %nil-terminated lists
* libguile/vm-engine.h (PUSH_LIST): Add a parameter to check that the
  list was proper.

* libguile/vm-i-system.c: Adapt PUSH_LIST callsites to pass SCM_NULLP or
  SCM_NULL_OR_NIL_P, as appropriate. Add a check to return/values*.

* libguile/vm.c: Add lang.h header for SCM_NULL_OR_NIL_P.

* test-suite/tests/elisp.test: Fix XFAIL for elisp + apply.
2009-01-04 14:06:52 +01:00
Andy Wingo
b1b942b74c remove heap links in VM frames, incorporate vm frames into normal backtraces
* doc/ref/vm.texi (Stack Layout): Update to remove references to the
  "heap link".

* gdbinit: Update for "heap link" removal.

* libguile/frames.c:
* libguile/frames.h: Update macros and diagram for removal of "heap
  link". As part of this, we also remove "heap frames", replacing them
  with "vm frames", which are much like the interpreter's debug objects,
  but for VM stacks. That is to say, they don't actually hold the stack
  themselves, just the pointers into stack that's held by a continuation
  (either captured or current).

* libguile/stacks.c (stack_depth, read_frames): Since a "stack" object is
  really a copy of information that comes from somewhere else, it makes
  sense to copy over info from the VM, just as `make-stack' does from the
  evaluator. The tricky bit is to figure out how to interleave VM and
  interpreter frames. We do that by starting in the interpreter, and
  whenever the current frame's procedure is actually a program, we switch
  to the VM stack, switching back when we reach a "bootstrap frame". The
  last bit is hacky, but it does work...
  (is_vm_bootstrap_frame): Hacky predicate to see if a VM frame is a
  bootstrap frame.
  (scm_make_stack): Accept a VM frame in addition to debug frames.
  Probably has some bugs in this case. But in the case that the arg is
  #t (a common case), do the right thing, capturing the top VM frame as
  well, and interleaving those frames appropriately on the stack.

  As an accident, we lost the ability to limit the number of frames in
  the backtrace. We could add that back, but personally I always want
  *all* frames in the trace... Narrowing still works fine, though there
  are some hiccups sometimes -- e.g. an outer cut to a procedure that
  does a tail-call in VM code will never find the cut, as it no longer
  exists in the continuation.

* libguile/vm.h (struct scm_vm): So! Now that we have switched to save
  stacks in the normal make-stack, there's no more need for `this_frame'
  or `last_frame'. On the other hand, we can take this opportunity to fix
  tracing: when we're in a trace hook, we set `trace_frame' on the VM,
  so we know not to fire hooks when we're already in a hook.
  (struct scm_vm_cont): Expose this, as make-stack needs it to make VM
  frames from VM continuations.

* libguile/vm.c (scm_vm_trace_frame): New function, gets the current
  trace frame.
  (vm_mark, make_vm): Hook up the trace frame.
  (vm_dispatch_hook): New hook dispatcher, with a dynwind so it does the
  right thing if the hook exits nonlocally.

* libguile/vm-engine.c (vm_run): No more this_frame in the wind data.

* libguile/vm-engine.h (RUN_HOOK): Run hooks through the dispatcher.
  (ALIGN_AS_NON_IMMEDIATE, POP_LIST_ON_STACK): Remove unused code.
  (NEW_FRAME): Adapt for no HL in the frame.

* libguile/vm-i-system.c (goto/args, mv-call, return, return/values):
  Adapt for no HL in the frame.

* module/system/vm/frame.scm:
* module/system/vm/vm.scm: Beginnings of some reworkings, needs more
  thought.
2008-12-26 18:07:20 +01:00
Andy Wingo
1f40459f5c ensure that lists pushed onto the stack are proper
I saw this problem when running elisp.test -- it tries to apply a
function to an arglist ending in nil, which obviously is not null.

* libguile/vm-engine.h (PUSH_LIST): New helper macro, pushes the elements
  of a list onto the stack. Checks to make sure that the list is proper.

* libguile/vm-i-system.c (list-break, mv-call, apply, goto/apply)
  (goto/cc): Use LIST_BREAK.

* libguile/vm-engine.c (vm_error_improper_list): New error case.
2008-10-16 13:24:39 +02:00
Andy Wingo
66db076ae1 NULLSTACK fixes for nonlocal exits in reentrant pre-wind handlers
* libguile/vm-i-system.c (goto/cc): Add some asserts here.

* libguile/vm.c (capture_vm_cont): Add some asserts here too.
  (reinstate_vm_cont): Null the correct number of bytes. Add a FIXME.
  (vm_reset_stack): Make the code a bit clearer. Null the correct number
  of bytes.

* libguile/vm-engine.h (NULLSTACK_FOR_NONLOCAL_EXIT): New macro, handles
  a very tricky case that took me days to find! Amply commented. Expands
  to nothing in the normal case.

* libguile/vm-i-system.c (call, goto/args, mv-call): Call
  NULLSTACK_FOR_NONLOCAL_EXIT in the right places. Fixes
  continuations.test.
2008-10-09 14:44:43 +02:00
Andy Wingo
11ea1aba9e precise stack marking, fix some missed references, still imperfect
* 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.
2008-10-03 16:00:30 +02:00
Andy Wingo
9a8cc8e7f7 be more like the interpreter in signalling wrong-num-args
* libguile/vm-engine.c: Call scm_wrong_num_args in the wrong-num-args
  case, to be more like the interpreter.

* libguile/vm-engine.h (ASSERT): New macro.

* libguile/vm-i-system.c (apply, goto/apply): Assert that nargs >= 2,
  because the compiler should always feed us correct instructions.
  (call/cc): If no values are returned to the continuation, signal
  no_values instead of wrong_num_args.
2008-10-02 11:00:55 +02:00
Andy Wingo
2bd859c81a fix compilation of quasiquote with splicing and improper lists
* libguile/vm-engine.h (POP_CONS_MARK): New macro, analagous to
  POP_LIST_MARK; used in quasiquote on improper lists.

* libguile/vm-i-system.c (cons-mark): New instruction. You know the
  drill, remove all your .go files please.

* module/system/il/compile.scm (codegen): Compile quasiquoted improper
  lists with splices correctly. Additionally check that we don't have
  slices in the CDR of an improper list.

* testsuite/t-quasiquote.scm: Add a test for unquote-splicing in improper
  lists.
2008-09-30 23:41:16 +02:00
Andy Wingo
da320011a3 add a multiple values return address to stack frames
* libguile/frames.c (frame-mv-return-address): New accessor.

* libguile/frames.h: Update frame diagram.
  (SCM_FRAME_UPPER_ADDRESS): Update for data area
  growing by one pointer.
  (SCM_FRAME_MV_RETURN_ADDRESS): New macro.

* libguile/vm-engine.h (NEW_FRAME): Update for frame getting bigger by a
  pointer. In a normal NEW_FRAME, set the MV return address to NULL, to
  indicate that this continuation does not accept multiple values.

* libguile/vm-i-system.c (tail-call): Update frame replacement code to
  understand the MV return address.
  (return): Make room for the MVRA.
2008-09-13 19:22:28 +02:00
Andy Wingo
28106f547d inline frame replacement in tail-call
* libguile/programs.c (program_print): Only try to lookup write-program
  if the module system is booted.

* libguile/vm-engine.h (FREE_FRAME): Remove, it's now inlined everywhere.

* libguile/vm-i-system.c (tail-call): Inline FREE_FRAME, and implement
  the calling bits here. Will make things more hackable.
2008-09-13 15:41:43 +02:00
Andy Wingo
f13c269b7f inline FREE_FRAME in return, sync stack_base in CACHE_REGISTER
* libguile/vm-engine.h (CACHE_REGISTER): Sync stack_base too.

* libguile/vm-i-system.c (return): Inline FREE_FRAME here,
  micro-optimizing a wee bit. Sounds silly, but it's to enable some
  refactoring.
2008-09-13 14:30:57 +02:00
Andy Wingo
2cdb8cdc0d clean up NEW_FRAME macro
* libguile/vm-engine.h (NEW_FRAME): Clean up this macro.
2008-09-13 14:19:30 +02:00
Andy Wingo
93d197be98 readability improvement in vm-i-scheme
* libguile/vm-engine.h:
* libguile/vm-i-scheme.c: Move some helper macros closer to their use
  sites.
2008-09-13 14:19:30 +02:00
Andy Wingo
83495480e8 merge guile-vm into libguile itself
* 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?
2008-08-21 18:39:30 -07:00
Renamed from src/vm_engine.h (Browse further)