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

134 commits

Author SHA1 Message Date
Ludovic Courtès
7f991c7d32 Fix C99-style declarations after statements.
* libguile/eval.i.c (ceval): Move declarations before statements.

* libguile/read.c (scm_read_extended_symbol): Likewise.

* libguile/struct.c (scm_make_struct_layout): Likewise.

* libguile/threads.c (fat_mutex_unlock): Likewise.

* libguile/vm-i-system.c (br_if_nargs_ne, br_if_nargs_lt): Likewise.

* libguile/vm.c (make_vm): Likewise.
2009-11-17 23:13:58 +01:00
Andy Wingo
ff74e44ecb with a rest arg, allow for keywords anywhere
* libguile/vm-i-system.c (br-if-nargs-gt): Fix variable declaration
  placement.
  (bind-kwargs): Patch mostly by Ludovic: it seems that in the mode in
  which we have rest args, the keywords can appear anywhere. Bummer.
  Change to allow for this.

* module/ice-9/optargs.scm (parse-lambda-case): Same, add a
  permissive-keys clause that handles the case in which there's a rest
  argument.
2009-11-16 22:32:54 +01:00
Andy Wingo
521ac49bde SCM_GENERIC_METHOD_CACHE macro splits from SCM_ENTITY_PROCEDURE
* libguile/goops.h (SCM_GENERIC_METHOD_CACHE)
  (SCM_SET_GENERIC_METHOD_CACHE): Two new macros; the same as
  SCM_[SET_]ENTITY_PROCEDURE, but more reflecting the reality of the
  generic hack.

* libguile/eval.i.c:
* libguile/goops.c:
* libguile/objects.c:
* libguile/vm-i-system.c: Use the new macros when it is appropriate to
  do so.
2009-11-15 20:28:11 +01:00
Andy Wingo
352c87d7e4 generic dispatch in the vm (sorta)
* libguile/vm-i-system.c (call, goto/args, mv-call): Add a case for
  generics, so we can avoid the evaluator in that case. Still have to
  cons up a list -- the real solution comes later.
2009-11-15 20:28:11 +01:00
Mark H Weaver
b02b05332f fix nil handling in the vm
* libguile/vm-i-scheme.c (not, not-not): Treat nil as false.
  (null?, not-null?): Treat nil as null.

* libguile/vm-i-system.c (br-if, br-if-not): Treat nil as false.
  (br-if-null, br-if-not-null): Treat nil as null.
2009-10-27 23:26:30 +01:00
Andy Wingo
3092a14d67 vm support for optional/kwarg init code, and bugfixes
* libguile/vm-i-system.c (local-bound?, long-local-bound?)
  (variable-bound?): New instructions, push #f unless the local is
  bound. You can get unbound locals from optional arguments.
  (bind-optionals/shuffle): A number of bugfixes.
  (bind-kwargs): Bugfixes. If we enocunter an improper kwarg list but
  the procedure has a rest argument, just stop kwarg processing, but
  without an error.
  Renumbered ops.

* libguile/_scm.h (SCM_OBJCODE_MAJOR_VERSION): Bump.
2009-10-23 15:59:07 +02:00
Andy Wingo
899d37a6cf more work towards compiling and interpreting keyword args
* libguile/_scm.h (SCM_OBJCODE_MINOR_VERSION): Bumparoo
* libguile/vm-i-system.c (push-rest, bind-rest): Logically there are
  actually two rest binders -- one that pops, conses, and pushes, and
  one that pops, conses, and local-sets. The latter is used on keyword
  arguments, because the keyword arguments themselves have been shuffled
  up on the stack. Renumber ops again.

* module/language/tree-il/compile-glil.scm (flatten): Attempt to handle
  compilation of lambda-case with keyword arguments. Might need some
  help.

* module/ice-9/psyntax.scm (build-lambda-case): An attempt to handle the
  interpreted case correctly. This might need a couple iterations, but
  at least it looks like the compile-glil code.

* module/ice-9/psyntax-pp.scm: Regenerated.

* module/language/glil.scm (<glil>): Rename "rest?" to "rest" in
  <glil-opt-prelude> and <glil-kw-prelude>, as it is no longer a simple
  boolean, but if true is an integer: the index of the local variable to
  which the rest should be bound.

* module/language/glil/compile-assembly.scm (glil->assembly): Adapt to
  "rest" vs "rest?". In the keyword case, use "bind-rest" instead of
  "push-rest".

* test-suite/tests/tree-il.test: Update for opt-prelude change.
2009-10-23 15:20:22 +02:00
Andy Wingo
7e01997e88 finish support for optional & keyword args; update ecmascript compiler
* libguile/_scm.h (SCM_OBJCODE_MINOR_VERSION): Bump.
* libguile/vm-i-system.c (br-if-nargs-ne, br-if-args-lt)
  (br-if-nargs-gt): New instructions, for use by different lambda cases.
  (bind-optionals, bind-optionals/shuffle, bind-kwargs): New
  instructions, for binding optional and keyword arguments. Renumber
  other ops.

* module/language/ecmascript/compile-tree-il.scm (comp, comp-body):
  Update for new tree-il. Use the new optional argument mechanism
  instead of emulating it with rest arguments.

* module/language/glil/compile-assembly.scm (glil->assembly): Tweaks for
  optional and keyword argument compilation.

* module/language/tree-il.scm (parse-tree-il, unparse-tree-il): Make the
  else case optional, in the s-expression serialization of tree-il.

* module/language/tree-il/compile-glil.scm (flatten): Handle all of the
  lambda-case capabilities.
2009-10-23 15:10:25 +02:00
Andy Wingo
258344b4db flesh out glil support for optional and keyword arguments
* libguile/vm-i-system.c (bind-rest): Renamed from push-rest-list.
  (reserve-locals): Change so that instead of reserving space for some
  additional number of locals, reserve-locals takes the absolute number
  of locals, including the arguments.

* module/language/glil.scm (<glil-std-prelude>, <glil-opt-prelude>)
  (<glil-kw-prelude>): New GLIL constructs, to replace <glil-arity>.

* module/language/glil/compile-assembly.scm (glil->assembly): Compile
  the new preludes. Some instructions are not yet implemented, though.

* module/language/tree-il/analyze.scm (analyze-lexicals): The nlocs for
  a lambda will now be the total number of locals, including arguments.

* module/language/tree-il/compile-glil.scm (flatten-lambda): Update to
  write the new prelude.

* module/system/vm/program.scm (program-bindings-for-ip): If a given
  index doesn't have a binding at the ip given, don't cons it on the
  resulting list.

* test-suite/tests/tree-il.test: Update for GLIL changes.
2009-10-23 14:51:19 +02:00
Andy Wingo
a6f15a1eba callees now check their args, cons rest list, reserve locals
* gdbinit: Ignore SIGPWR and SIGXCPU, which the BDW GC seems to use.

* libguile/vm-engine.h (FETCH_WIDTH): Remove unused macro.
  (INIT_ARGS, INIT_FRAME): Remove; callees now check their args and
  reserve space for their locals.

* libguile/vm-engine.c:
* libguile/vm-i-system.c: Turn on callee arg checking and local
  reservation. Seems to work!
2009-10-23 14:51:18 +02:00
Andy Wingo
55d9bc947e callees reserve their own local vars
* libguile/_scm.h (SCM_OBJCODE_MINOR_VERSION): Bump.
* libguile/vm-i-system.c (reserve-locals): New instruction, to reserve
  space for local vars. Other ops renumbered.

* module/language/tree-il/compile-glil.scm (flatten-lambda): Emit
  reserve-locals instructions as necessary.

* test-suite/tests/tree-il.test: Update to expect reserve-locals as
  appropriate.
2009-10-23 14:51:18 +02:00
Andy Wingo
6c6a44390b runtime and debugging support for callee-parsed procedure args
* libguile/objcodes.h: Bump for metadata format change.

* libguile/frames.h: Rework so we don't frob the program's nargs, nlocs,
  etc at runtime. Instead we don't really know what's a local var, an
  argument, or an intermediate value. It's a little unfortunate, but
  this will allow for case-lambda, and eventually for good polymorphic
  generic dispatch; and the nlocs etc can be heuristically
  reconstructed. Such a reconstruction would be better done at the
  Scheme level, though.
  (SCM_FRAME_STACK_ADDRESS): New macro, the pointer to the base of the
  stack elements (not counting the program).
  (SCM_FRAME_UPPER_ADDRESS): Repurpose to be the address of the last
  element in the bookkeeping part of the stack -- i.e. to point to the
  return address.

* libguile/vm-engine.h:
* libguile/vm-i-system.c: Adapt to removal of stack_base. Though we
  still detect stack-smashing underflow, we don't do so as precisely as
  we did before, because now we only detect overwriting of the frame
  metadata.

* libguile/vm-engine.c (vm_engine): Remove the stack_base variable. It
  is unnecessary, and difficult to keep track of in the face of
  case-lambda. Also fix miscommented "ra" and "mvra" pushes. Push the
  vp->ip as the first ra...
* libguile/vm-i-system.c (halt): ...because here we can restore the
  vp->ip instead of setting ip to 0. Allows us to introspect ips all
  down the stack, including in recursive VM invocations.

* libguile/frames.h:
* libguile/frames.c (scm_vm_frame_stack): Removed, because it's getting
  more difficult to tell what's an argument and what's a temporary stack
  element.
  (scm_vm_frame_num_locals): New accessor.
  (scm_vm_frame_instruction_pointer): New accessor.
  (scm_vm_frame_arguments): Defer to an implementation in Scheme.
  (scm_vm_frame_num_locals scm_vm_frame_local_ref)
  (scm_vm_frame_local_set_x): Since we can get not-yet-active frames on
  the stack now, with our current calling convention, we have to add a
  heuristic here to jump over those frames -- because frames have
  pointers in them, not Scheme values.

* libguile/programs.h:
* libguile/programs.c (scm_program_arity): Remove, in favor of..
  (scm_program_arities): ...this, which a list of arities, in a new
  format, occupying a slot in the metadata.

* module/language/assembly/decompile-bytecode.scm (decode-load-program):
  Fix mv-call decompilation.

* module/system/vm/frame.scm (vm-frame-bindings, vm-frame-binding-ref)
  (vm-frame-binding-set!): New functions, to access bindings by name in
  a frame.
  (vm-frame-arguments): Function now implemented in Scheme. Commented
  fairly extensively.

* module/system/vm/program.scm (program-bindings-by-index)
  (program-bindings-for-ip): New accessors, parsing the program bindings
  metadata into something more useful.
  (program-arities, program-arguments): In a case-lambda world, we have
  to assume that programs can have multiple arities. But it's tough to
  detect this algorithmically; instead we're going to require that the
  program metadata include information about the arities, and the parts
  of the program that that metadata applies to.
  (program-lambda-list): New accessor.
  (write-program): Show multiple arities.

* module/language/glil/compile-assembly.scm (glil->assembly): Add
  "arities" to the state of the compiler, and add arities entries as
  appropriate.
2009-10-23 14:51:17 +02:00
Andy Wingo
1e2a8c266d steps on the way to have the callee check the number of arguments
* libguile/_scm.h (SCM_OBJCODE_MINOR_VERSION): Bump.

* libguile/vm-i-system.c (assert-nargs-ee, assert-nargs-ge)
  (push-rest-list): New instructions, which for now don't actually do
  anything. Renumber the rest of the ops in this file.

* module/language/glil.scm (<glil-arity>): New GLIL type, an entity that
  checks the number of args for a block, optionally consing a rest list,
  and either branching or erroring if the arity doesn't match.

* module/language/glil/compile-assembly.scm (glil->assembly): Compile
  <glil-arity> to assembly. Some of these VM ops are not implemented --
  notably the branching case.

* module/language/tree-il/compile-glil.scm (flatten-lambda): Emit
  <glil-arity>.

* test-suite/tests/tree-il.test: Update.
2009-10-23 14:51:17 +02:00
Andy Wingo
97fcf583b7 jumps encoded using 24 bits, not 19; blocks no longer aligned
* libguile/_scm.h (SCM_OBJCODE_MINOR_VERSION): Bump.
* libguile/vm-i-system.c (FETCH_OFFSET, BR): Labels are no longer 8-byte
  aligned; instead, jumps are encoded into 3 bytes instead of 2.
  (br, br-if, br-if-not, br-if-eq, br-if-not-eq, br-if-null)
  (br-if-not-null, mv-call): Adapt for new length of br instructions (3
  bytes instead of 2).

* libguile/vm.c (really_make_boot_program): Adapt hand-coded bytecode
  for new offset regime.

* module/language/assembly.scm (align-block): No alignment necessary.

* module/language/assembly/compile-bytecode.scm (write-bytecode): Write
  out breaks as 24-bit relative jumps.
* module/language/assembly/decompile-bytecode.scm (decode-load-program):
  Decompile break instructions.
2009-10-16 15:56:11 +02:00
Daniel Kraft
ff81007918 Merge branch 'master' of git://git.savannah.gnu.org/guile into elisp 2009-08-27 19:26:04 +02:00
Andy Wingo
2fb924f64f programs have their own tc7 now
* libguile/tags.h (scm_tc7_program):
* libguile/programs.h: Programs now have their own tc7 code. Fix up the
  macros appropriately.

* libguile/programs.c: Remove smobby bits, leaving marking, printing,
  and application for other parts of Guile.

* libguile/debug.c (scm_procedure_source):
* libguile/eval.c (scm_trampoline_0, scm_trampoline_1)
  (scm_trampoline_2): Add cases for tc7_program.
* libguile/eval.i.c (CEVAL, SCM_APPLY):
* libguile/evalext.c (scm_self_evaluating_p):
* libguile/gc-card.c (scm_i_sweep_card, scm_i_tag_name):
* libguile/gc-mark.c (1):
* libguile/print.c (iprin1):
* libguile/procs.c (scm_procedure_p, scm_thunk_p)
* libguile/vm-i-system.c (make-closure): Adapt to new procedure
  representation.

* libguile/procprop.c (scm_i_procedure_arity): Do the right thing for
  programs.
* test-suite/tests/procprop.test ("procedure-arity"): Arity test now
  succeeds.

* libguile/goops.c (scm_class_of): Programs now belong to the class
  <procedure>, not a smob class.

* libguile/vm.h (struct vm, struct vm_cont):
* libguile/vm-engine.c (vm_engine):
* libguile/frames.h (SCM_FRAME_BYTE_CAST, struct vm_frame):
* libguile/frames.c (scm_c_make_vm_frame): Fix usages of scm_byte_t,
  changing them to scm_t_uint8.
2009-08-20 18:52:51 +02:00
Andy Wingo
b7946e9ec6 push new frame on stack before procedure & args
* libguile/_scm.h (SCM_OBJCODE_MINOR_VERSION): Bump

* libguile/vm-engine.c (vm_engine): Push a frame corresponding to the
  mv-call.

* libguile/vm-i-system.c: Renumber ops.
  (new-frame): New op, pushes a frame.
  (call, mv-call): No need to shuffle args, though we do need to pop the
  frame in the non-vm call case.
  (goto/args): Inconsequential tweaks.
  (call/cc): Push a frame if needed.

* module/language/tree-il/compile-glil.scm (flatten): Emit `new-frame'
  as appropriate.

* test-suite/tests/tree-il.test: Fix to expect new-frame.
2009-08-20 18:52:50 +02:00
Andy Wingo
03e6c16596 reorder frame layout
* libguile/frames.h: Reorder the frame layout so the return address
  comes below the arguments.working
  (SCM_FRAME_SET_RETURN_ADDRESS, SCM_FRAME_SET_MV_RETURN_ADDRESS): New
  macros.

* libguile/frames.c (scm_vm_frame_arguments): Use the macros to access
  the arguments.

* libguile/vm-engine.c (vm_engine): Fix for new calling convention.

* libguile/vm-engine.h (INIT_FRAME): New macro. Does part of what
  NEW_FRAME used to do.

* libguile/vm-i-system.c (call, mv-call): Shuffle args up to make room
  for the stack, and adapt to new calling convention.
  (goto/args): Shuffling down is easier now.
  (return, return/args): Adapt to new frame layout.

* libguile/vm.c (vm_mark_stack): Adapt to new frame layout, and the
  possibility of there being crap on the stack.
  (really_make_boot_program): Remove extraneous comment.
2009-08-20 18:52:49 +02:00
Andy Wingo
d94be25f72 remove dead weight from vm-i-system.c
* libguile/vm-i-system.c: Remove mark, list-mark, cons-mark,
  vector-mark, and list-break, as they are no longer used.
  (call, goto/args, mv-call): Remove bits about trampolines, which was
  slower, and VM continuations, which are not used (we use Guile's
  continuations as the applicable objects).

  Renumber ops.

* libguile/_scm.h (SCM_OBJCODE_MINOR_VERSION): Bump.
2009-08-20 18:52:49 +02:00
Andy Wingo
94ff26b96b rework the vm support for wide strings
* libguile/_scm.h (SCM_OBJCODE_MINOR_VERSION): Bump.

* libguile/vm-engine.c (vm_error_bad_wide_string_length): New error
  case.

* libguile/vm-i-loader.c (load-unsigned-integer, load-integer)
  (load-keyword): Remove these instructions. The former two are
  obsoleted by make-int64/make-uint64, the latter via make-keyword.
  (load-string): Only handle narrow strings.
  (load-symbol): Only handle narrow symbols. The wide case is handled
  via make-symbol.
  (load-wide-string): New instruction, for wide strings.

* libguile/vm-i-system.c (define): Move here from loaders.c, as now it
  just takes a sym on the stack.
  (make-keyword, make-symbol): New instructions.

* module/language/assembly.scm: Remove removed instructions. No more
  width byte in load-string etc.

* module/language/assembly/compile-bytecode.scm (write-bytecode): Adapt
  to change in instruction set.

* module/language/glil/compile-assembly.scm (glil->assembly): Compile
  define by pushing the sym then emitting (define).
  (dump-object): Dump narrow and wide strings differently. Use
  make-keyword and make-symbol as appropriate.

* module/language/tree-il/compile-glil.scm (flatten): When compiling a
  ref to a primitive (not a call), first see if the primitive is
  actually bound in the root module. (That's not the case with e.g.
  bytevector-u8-ref).

* module/system/xref.scm (program-callee-rev-vars): Don't parse out
  "nexts".

* test-suite/tests/asm-to-bytecode.test ("compiler"): Adapt to bytecode
  format change.
2009-08-12 16:34:05 +02:00
Andy Wingo
c21c89b138 add <fix> tree-il construct, and compile it
* libguile/vm-i-system.c (fix-closure): New instruction, for wiring
  together fixpoint procedures.

* module/Makefile.am (TREE_IL_LANG_SOURCES): Add fix-letrec.scm.

* module/language/glil/compile-assembly.scm (glil->assembly): Reindent
  the <glil-lexical> case, and handle 'fix for locally-bound vars.

* module/language/tree-il.scm (<fix>): Add the <fix> tree-il type and
  accessors, for fixed-point bindings. This IL construct is taken from
  the Waddell paper.
  (parse-tree-il, unparse-tree-il, tree-il->scheme, tree-il-fold)
  (pre-order!, post-order!): Update for <fix>.

* module/language/tree-il/analyze.scm (analyze-lexicals): Update for
  <fix>. The difference here is that the bindings may not be assigned,
  and are not marked as such. They are not boxed.
  (report-unused-variables): Update for <fix>.

* module/language/tree-il/compile-glil.scm (flatten): Compile <fix> to
  GLIL.

* module/language/tree-il/fix-letrec.scm: A stub implementation of
  fixing letrec -- will flesh out in a separate commit.

* module/language/tree-il/inline.scm: Fix license, it was mistakenly
  added with LGPL v2.1+.

* module/language/tree-il/optimize.scm (optimize!): Run the fix-letrec!
  pass.
2009-08-05 17:52:27 +02:00
Daniel Kraft
157ffbd797 Merge branch 'master' of git://git.savannah.gnu.org/guile into elisp 2009-08-04 09:37:50 +02:00
Michael Gran
4c402b889e Don't use GNU extensions for SCM_MAKE_CHAR macro
Since the contents of SCM_MAKE_CHAR are evaluated more than once,
don't use it in situations where this could cause side-effects.

        * libguile/vm-i-system.c (make-char8): avoid side-effects with
        SCM_MAKE_CHAR call

        * libguile/chars.h (SCM_MAKE_CHAR): modified
2009-08-01 10:15:20 -07:00
Daniel Kraft
a43df0ae47 Merge branch 'master' of git://git.savannah.gnu.org/guile into elisp 2009-07-31 17:18:34 +02:00
Michael Gran
904a78f11d Add 32-bit characters
This adds the 32-bit standalone characters.  Strings are still
8-bit.  Characters larger than 8-bit can only be entered or
displayed in octal format at this point.  At this point, the
terminal's display encoding is expected to be Latin-1.

        * module/language/assembly/compile-bytecode.scm (write-bytecode):
        add 32-bit char

        * module/language/assembly.scm (object->assembly): add 32-bit char
        (assembly->object): add 32-bit char

        * libguile/vm-i-system.c (make-char32): new op

        * libguile/print.c (iprin1): print 32-bit char

        * libguile/numbers.h: add type scm_t_wchar

        * libguile/numbers.c: add type scm_t_wchar

        * libguile/chars.h: new type scm_t_wchar
        (SCM_CODEPOINT_MAX): new
        (SCM_IS_UNICODE_CHAR): new
        (SCM_MAKE_CHAR): operate on 32-bit char

        * libguile/chars.c: comparison operators now use Unicode
        codepoints
        (scm_c_upcase): now receives and returns scm_t_wchar
        (scm_c_downcase): now receives and returns scm_t_wchar
2009-07-29 06:38:32 -07:00
Andy Wingo
e5dc27b86d increase range of relative jumps by aligning blocks to 8-byte boundaries
* libguile/objcodes.c (OBJCODE_COOKIE): Bump again, as our jump offsets
  are now multiplied by 8.

* libguile/vm-i-system.c (BR): Interpret the 16-bit offset as a relative
  jump to the nearest 8-byte-aligned block -- increasing relative jump
  range from +/-32K to +/-240K.
  (mvra): Do the same for the mvra jump.

* libguile/vm.c (really_make_boot_program): Align the mvra.

* module/language/assembly.scm (align-block): New export, for aligning
  blocks.

* module/language/assembly/compile-bytecode.scm (write-bytecode): Emit
  jumps to the nearest 8-byte-aligned block. Effectively our range is 18
  bits in either direction. I would like to do this differently -- have
  long-br and long-br-if, and all the other br instructions go to 8 bits
  only. But the assembler doesn't have an appropriate representation to
  allow me to do this yet, so for now this is what we have.

* module/language/assembly/decompile-bytecode.scm (decode-load-program):
  Decode the 19-bit jumps.
2009-07-26 14:01:56 +02: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
80545853d5 compiler support for nlocs >= 256
* libguile/vm-i-system.c (long-local-ref, long-local-set)
  (make-variable): New intructions, for handling nlocs >= 256.
* module/language/glil/compile-assembly.scm (glil->assembly): Compile
  <glil-lexical> with support for nlocs >= 256.
2009-07-24 11:00:32 +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
a5cfddd560 renumber vm ops (objcode cookie bumped)
* 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.
2009-07-21 22:22:38 +02:00
Daniel Kraft
4530432e01 Added make-nil instruction to VM and use it for Emacs' nil in the compiler.
* doc/ref/vm.texi: Document new instruction.
* libguile/vm-i-system.c: Add it to the VM.
* module/language/assembly.scm: Compile (const %nil) to (make-nil) assembly.
* module/language/glil/decompile-assembly.scm: Handle (make-nil)
* module/language/elisp/compile-tree-il.scm: Use (const %nil) for nil.
2009-06-29 13:16:27 +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
586cfdecfa new instructions: make-int64, make-uint64
* doc/ref/vm.texi (Loading Instructions): Remove references to
  load-integer and load-unsigned-integer -- they're still in the VM but
  will be removed at some point.
  (Data Control Instructions): Add make-int64 and make-uint64.

* libguile/vm-i-loader.c (load-unsigned-integer): Allow 8-byte values.
  But this instruction is on its way out, yo.

* libguile/vm-i-system.c (make-int64, make-uint64): New instructions.

* module/language/assembly.scm (object->assembly): Write out make-int64
  and make-uint64 instructions, using bytevectors to do the endianness
  conversion.
  (assembly->object): And pretty-print them back, for disassembly.

* module/language/glil/compile-assembly.scm: Don't generate load-integer
  / load-unsigned-integer instructions.
2009-06-07 00:53:48 +02:00
Andy Wingo
a9b0f876c1 add long-object-ref, long-toplevel-ref, long-toplevel-set
* libguile/vm-i-system.c (long-object-ref, long-toplevel-ref)
  (long-toplevel-set): Add new instructions, for accessing the object
  table with a 16-bit offset. HTMLprag defines a test program that has
  more than 256 constants, necessitating this addition.

* doc/ref/vm.texi: Mention the new instructions.

* module/language/glil/compile-assembly.scm: Emit long refs for object
  tables bigger than 256 entries.
2009-06-05 12:08:02 +02:00
Andy Wingo
b7393ea123 refactoring for toplevel-ref, toplevel-set, link-now
* libguile/vm-i-system.c (toplevel-ref, toplevel-set)
* libguile/vm-i-loader.c (link-now):
* libguile/vm.c (resolve_variable): Factor out common code to a static
  method. The compiler can still inline it, so it shouldn't have a
  significant performance effect.

* libguile/vm-engine.c (vm_error_no_such_module): Remove now-unused
  label.
2009-06-05 11:47:19 +02:00
Andy Wingo
81fd315299 update docs, clean up VM vestiges, macro docs, fix (/ a b c)
* doc/ref/api-procedures.texi (Compiled Procedures): Fix for API changes.

* doc/ref/compiler.texi (Compiling to the Virtual Machine): Replace GHIL
  docs with Tree-IL docs. Update the bits about the Scheme compiler to
  talk about Tree-IL and the expander instead of GHIL. Remove
  <glil-argument>. Add placeholder sections for assembly and bytecode.

* doc/ref/vm.texi: Update examples with what currently happens. Reword
  some things. Fix a couple errors.

* libguile/vm-i-system.c (externals): Remove this instruction, it's not
  used.

* module/ice-9/documentation.scm (object-documentation): If the object is
  a macro, try to return documentation on the macro transformer.

* module/language/assembly/disassemble.scm (disassemble-load-program):
  Fix problem in which we skipped the first element of the object vector,
  because of changes to procedure layouts a few months ago.

* module/language/scheme/spec.scm (read-file): Remove read-file
  definition.

* module/language/tree-il.scm: Reorder exports. Remove <lexical>, it was
  a compat shim to something that was never released. Fix `location'.

* module/language/tree-il/primitives.scm (/): Fix expander for more than
  two args to /.

* module/system/base/compile.scm (read-file-in): Remove unused
  definition.

* module/system/base/language.scm (system): Remove language-read-file.

* module/language/ecmascript/spec.scm (ecmascript): Remove read-file
  definition.
2009-05-24 13:09:01 +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
196b40932e fix handling of pre-modules errors in the vm
* libguile/vm-i-system.c (toplevel-ref, toplevel-set): Correct situation
  whereby we would not throw when toplevel vars were unbound, before
  modules had booted.
2009-04-17 15:20:18 +02:00
Ludovic Courtès
da8b47478e Avoid uses of deprecated forms in the VM code.
Reported by Daniel Kraft <d@domob.eu>.

* libguile/frames.c, libguile/vm.c: Include <stdlib.h>, use `size_t'
  instead of `scm_sizet'.

* libguile/objcodes.c, libguile/programs.c, libguile/vm-engine.c,
  libguile/vm-i-loader.c, libguile/vm-i-system.c: Use `scm_list_X ()'
  instead of the deprecated `SCM_LISTX ()'.
2009-04-05 20:15:11 +02:00
Andy Wingo
2c0f99a28b fix nondeterminism in vm-i-system.c
* libguile/vm-i-system.c (br-if-eq, br-if-not-eq): Fix some
  nondeterminism caught by GCC 4.4.
2009-04-04 11:36:18 -07:00
Andy Wingo
4054d93183 fix variable not initialized spurious warnings
* libguile/vm-i-system.c: Work around some spurious "variable not
  initialized" messages on Etch's gcc.
2009-02-25 00:21:03 +01:00
Andy Wingo
81d677eb12 implement break and continue, work around overly recursive pmatch expansion
* libguile/vm-i-system.c (goto/args): On a tail call to a different
  procedure, init the locals to valid scheme values. Shouldn't matter for
  well-compiled scheme, but inspecting uninitialized locals could give
  garbage, or badly-compiled code could cause a crash.

* module/language/Makefile.am (NOCOMP_SOURCES): For the moment, don't
  compile compile-ghil.scm. I need to fix this.

* module/language/ecmascript/compile-ghil.scm (load-toplevel): Sigh, and
  disable stack checking in the evaluator too. Grr.
  (comp): Implement (unnamed) break and continue.

* module/language/ecmascript/parse.scm (parse-ecmascript): Fix var
  statements in `for' -- though it still doesn't work.
2009-02-21 20:28:28 +01:00
Andy Wingo
131f7d6c71 further ecmascript work
* libguile/vm-i-system.c (drop, return): Declare drop and return as
  popping one arg from the stack.

* module/language/ghil/compile-glil.scm:
* module/language/glil/compile-assembly.scm (make-meta): Adjust so that
  we declare 'drop and 'return calls as popping one arg from the stack.

* module/language/ecmascript/compile-ghil.scm (comp, comp-body): Flesh
  out a bit more. Most significantly, scoping within functions obeys
  javascript semantics better, modulo bits about with() forms.

* module/language/ecmascript/impl.scm: Define some runtime helper
  routines.
* module/language/Makefile.am (SOURCES): Add impl.scm.

* module/language/ecmascript/parse.scm (parse-ecmascript): Minor tweaks.

* module/language/ecmascript/tokenize.scm (read-identifier): Identifiers
  now read as symbols, not strings.
2009-02-19 13:55:55 +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
747a163532 make catch cache and restore vm regs, not the vm itself -- speedy speedy
* libguile/throw.c (scm_c_catch): Stash away the current vm's regs, and
  restore them if there's a nonlocal exit. There is a terrible case we
  have to handle if we catch from when the vm smob type isn't registered
  but the throw has the vm registered, but I think we handle this fine.

* libguile/vm-engine.c (vm_run):
* libguile/vm-i-system.c (halt): Don't make a dynwind context, so that
  entering the VM doesn't cons at all, except for the arg list. Maybe we
  can fix that bit too.

* libguile/vm.c (vm_reset_stack): Remove, as there is no more dynwind.
  (make_vm): Return #f if the tc16 hasn't yet been registered.
2009-02-04 00:09:38 +01:00
Andy Wingo
ef7e18683c inline dispatch to program cmethods, tick in return, remove old goops methods
* libguile/objects.c (scm_apply_generic): Inline the case when the
  generic is a program.

* libguile/vm-i-system.c (return): Tick when functions return.

* module/oop/goops.scm (object-eqv?, object-equal?): Remove these
  historical methods.
2009-02-03 21:13:01 +01:00
Andy Wingo
e311f5fa04 tick in calls, procedure-name works on compiled procedures
* module/system/vm/program.scm:
* libguile/programs.h:
* libguile/programs.c (scm_program_bindings, scm_program_bindings)
  (scm_program_properties, scm_program_name): Unfortunately, implement
  more procs in C, so that C can use them more easily.

* libguile/debug.c (scm_procedure_name): Dispatch to scm_program_name as
  appropriate.

* libguile/vm-i-system.c (call): Tick in a call.
2009-02-02 23:00:36 +01:00