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

1105 commits

Author SHA1 Message Date
Andy Wingo
efbd589204 compile call-with-values, woot!
* libguile/vm-engine.c (vm_run): Add another byte onto the bootstrap
  program, as the offset passed to mv-call now takes two bytes.

* module/system/vm/frame.scm (bootstrap-frame?): Update for the new
  bootstrap length. Really we should just check for 'halt though.

* libguile/vm-i-system.c (FETCH_OFFSET): New helper, used in BR().
  (goto/nargs, call/nargs): Versions of goto/args and call, respectively,
  that take the number of arguments from a value on the top of the stack.
  (mv-call): Call FETCH_OFFSET to get the offset.

* module/language/scheme/translate.scm (custom-transformer-table):
  Compile call-with-values to <ghil-mv-call>. There is some trickery
  because of the r4rs.scm call-with-values trampolines.

* module/system/il/ghil.scm: Add <ghil-mv-call> and accessors.

* module/system/il/compile.scm (codegen): Compile <ghil-mv-call>.

* module/system/il/glil.scm: Add <glil-mv-call>, which needs some special
  assembly because of the label. Fix some typos.

* module/system/vm/assemble.scm (byte-length): New helper, factored out
  and made more general.
  (codegen): Assemble mv-call, including the label.
  (check-length): New helper, makes sure that the addressing is
  consistent within the produced object code.
  (stack->bytes): Rewrite to be more generic -- now `br' instructions
  aren't the only ones jumping around in the instruction stream.

* module/system/vm/conv.scm (make-byte-decoder): Return two values in the
  #f case.

* module/system/vm/disasm.scm (disassemble-bytecode): Rewrite, because
  the previous implementation depended on a guile interpreter quirk:
  namely, that multiple values could be represented within one value, and
  destructured later.
2008-09-16 00:26:22 +02:00
Andy Wingo
ef24c01bff add special case for (apply values ...)
* libguile/vm-engine.c (vm_run): Move nvalues to the top level, to avoid
  (spurious, it seems) gcc warnings about it being used uninitialized.

* libguile/vm-i-system.c (halt, return/values): Adapt to gcc silliness.
  Deindent some of return/values.
  (return/values*): New instruction, does what (apply values . args)
  would do.

* module/language/scheme/translate.scm (custom-transformer-table): Move
  the apply and @apply cases here from inline.scm, because we need some
  more cleverness when dealing with cases like (apply values . args).
  (lookup-apply-transformer): Define an eval transformer for `values',
  turning it into ghil-values*.

* module/system/il/compile.scm (codegen): Compile <ghil-values*> into
  return/values*.

* module/system/il/ghil.scm: Add <ghil-values*> and accessors.
  (ghil-lookup): Add optional argument, define?, which if false tells us
  not to actually cache the binding if it is not found in the toplevel.

* module/system/il/inline.scm: Remove apply clauses.

* module/system/vm/frame.scm (bootstrap-frame?): Update heuristic for
  bootstrap-frame?, as the bootstrap frame is now 5 bytes since it
  accepts multiple values.
2008-09-15 00:04:34 +02:00
Andy Wingo
a222b0fa91 add multiple values support to the vm
* libguile/vm-engine.c (vm_run): The bootstrap program now uses mv_call,
  so as to allow multiple values out of the VM. (It did before, because
  multiple values were represented internally as single scm_values
  objects, but now that values go on the stack, we need to note the boot
  frame as accepting multiple values.)
  (vm_error_no_values): New error, happens if you pass no values into a
  single-value continuation. Passing more than one is OK though, it just
  takes the first one.

* libguile/vm-i-system.c (halt): Assume that someone has pushed the
  number of values onto the stack, and package up that number of values
  as a scm_values() object, for communication with the interpreter.
  (mv-call): New instruction, calls a procedure with a multiple-value
  continuation, even handling calls out to the interpreter.
  (return/values): New instruction, returns multiple values to the
  continuation. If the continuation is single-valued, takes the first
  value or errors if there are no values. Otherwise it returns to the
  multiple-value return address, pushing the number of values on top of
  the values.

* module/system/il/compile.scm (codegen): Compile <ghil-values> forms.

* module/system/il/ghil.scm (<ghil-values>) Add new GHIL data structure
  and associated procedures.

* module/language/scheme/translate.scm (custom-transformer-table):
  Compile (values .. ) forms into <ghil-values>.
2008-09-14 17:06:52 +02:00
Andy Wingo
f03c31dbad rename tail-call to goto/args, add some more tail instructions
* libguile/vm-i-system.c (call): Rename continuation invocation from
  `vm_call_cc' to `vm_call_continuation', because that's what it really
  does. Add a note that it doesn't handle multiple values at the moment.
  (goto/arg): Renamed from tail-call, in deference to the progenitors, on
  Dale Smith's suggestion.
  (goto/apply): New instruction, for `apply' in a tail context. Not yet
  used, or vetted for that matter.
  (call/cc): No need to pop the program, I don't think; although this
  isn't tested either.
  (goto/cc): New instruction, for call/cc in a tail context.

* module/language/scheme/translate.scm (*forbidden-primitives*): Rename
  from %forbidden-primitives.

* module/system/il/compile.scm (codegen): Adapt to goto/args instead of
  tail-call.

* module/system/il/inline.scm: Start inlining some macros used in
  r4rs.scm -- not yet fully tested.

* ice-9/boot-9.scm: Allow load of a compiled r4rs file.
2008-09-13 19:24:03 +02:00
Andy Wingo
0ba8bb7143 tweaks for printing programs
* module/system/vm/program.scm (program-bindings-as-lambda-list): Handle
  the bindings-is-null case too -- not sure how it comes about, though. A
  thunk with no let, perhaps.
  (write-program): Another default for the name: the source location at
  which it was defined.

* libguile/programs.c (program_print): Add some "logic" to stop doing
  detailed prints if one print had a nonlocal exit -- preventing
  exceptions in backtraces.
2008-09-13 14:19:30 +02:00
Andy Wingo
e6fea61823 programs can now get at their names, and print nicely
* module/system/vm/frame.scm (frame-call-representation)
  (frame-program-name): Rename program-name to frame-program-name, and
  use the program-name if it is available.

* module/system/vm/program.scm (program-bindings): Return #f if there are
  no bindings.
  (program-name): New public procedure.
  (program-bindings-as-lambda-list, write-program): A more useful writer
  for programs.

* libguile/programs.c (scm_bootstrap_programs, program_print): Add a smob
  printer for programs, which dispatches to `write-program'.
2008-09-13 14:19:30 +02:00
Andy Wingo
6cdcb824f0 fix confusion in disassemble-bindings
* module/system/vm/disasm.scm (disassemble-bindings): Fix external/local
  confusion when printing args and locals.
2008-09-13 14:19:20 +02:00
Andy Wingo
535ed4d041 fix *another* bug in compiling `or'. incredible.
* module/system/il/compile.scm (codegen): Fix *another* bug in compiling
  `or' -- in the case in which the value was being discarded, as in `or'
  used as a control structure, we were sometimes leaving a value on the
  stack.

* testsuite/t-or.scm: Add another test case for `or'.
2008-09-13 14:19:20 +02:00
Andy Wingo
709f95afcd correctly disassemble program bindings (arguments, locals, externals)
* module/system/vm/disasm.scm (disassemble-bindings): New function,
  properly disassembles the bindings data. Neat!
2008-09-12 18:01:02 +02:00
Andy Wingo
e91e07811a really newline on eof
* module/system/repl/repl.scm (next-char): Another newline-on-eof case.
2008-09-09 08:33:53 +02:00
Andy Wingo
624e533f4f fix program disassembly for meta-in-a-thunk
* module/system/vm/disasm.scm (disassemble-program): Fix for recent
  meta-in-a-thunk change.
2008-09-09 08:27:49 +02:00
Andy Wingo
6a01fabfd0 run the vm repl instead of the scm-style-repl
* ice-9/boot-9.scm (@, @@): Note that these don't work with the compiler.
  Damn.
  (top-repl): Run the VM repl. Whooo!

* module/system/repl/repl.scm (start-repl): Catch 'quit, as the
  scm-style-repl does. Newline after input EOF's, so that we don't leave
  the user's shell messed up.
2008-09-09 08:23:10 +02:00
Andy Wingo
02ed0d3df2 add repl option to interpret rather than compile
* module/language/scheme/spec.scm (scheme): Specify an evaluator, `eval'.

* module/system/repl/common.scm (repl-default-options): Add option,
  `interp', specifying that, if possible, the repl should interpret its
  expressions rather than compile them. Defaults to #f.
2008-09-09 07:54:23 +02:00
Andy Wingo
8e3670748f rework late binding resolution to be simpler and more efficient
* libguile/programs.h (struct scm_program):
* libguile/programs.c (scm_c_make_program): Record the current module
  when making a program. This replaces the per-late binding recorded
  module in the generated code, which should be more efficient, both in
  terms of garbage, and in not calling resolve-module.
  (program-module): New accessor.

* module/system/vm/program.scm: Add program-module to exports.

* libguile/vm-i-loader.c (link-later): Remove this instruction, since now
  the entry in the object table is just a symbol, and can be loaded with
  load-symbol.

* libguile/vm-i-system.c (late-variable-ref, late-variable-set): Rework
  so as to look up in the module of the current program. The logic could
  be condensed quite a bit if scm_module_lookup () knew what to do with
  mod==#f.

* module/system/vm/assemble.scm (dump-object!): Dump <vlink-later> just
  as load-symbol, as mentioned in the note on link-later.

* module/system/il/ghil.scm: Update comment to reflect the new reality.
2008-09-09 07:15:01 +02:00
Andy Wingo
1a1a10d3a5 use #:keywords in module/*.scm, not :keywords
* module/system/base/syntax.scm (keywords): Don't enable :keywords, it
  breaks code that may assume that ':foo is a symbol, like boot-9.

* module/*.scm: Don't use :keywords, use #:keywords. The user can decide
  if she wants #:keywords in their .guile, and :keywords might make us
  compile modules differently.
2008-09-09 06:58:25 +02:00
Andy Wingo
13906f976e lazily load meta info, for less consage
* module/system/vm/assemble.scm (make-meta, codegen): Hide the "meta"
  information -- the names of the bindings, source info, procedure
  properties, etc -- behind a lambda. This way, loading up a program
  conses less, because the metadata stays as mmap'd code until it is
  needed.

* libguile/vm-i-loader.c (load-program): Adjust load-program to expect
  the metadata to be a program.

* module/system/vm/program.scm (program-bindings, program-sources)
  (program-properties): Adjust to new meta format.
2008-09-08 01:03:34 +02:00
Andy Wingo
1b79210aa2 better diagnostics on quasiquote errors
* module/system/il/compile.scm (constant?, codegen): Add some diagnostics
  so that we can get decent error reporting if we accidentally unquote an
  unreadable value into the compiled output.
2008-09-07 22:27:18 +02:00
Andy Wingo
2e7e6969bd allow multiple modules in one compilation unit
* module/system/il/ghil.scm (<ghil-env>, <ghil-toplevel-env>): Refactor
  so that all environments point (eventually) at one toplevel
  environment. Instead of having potentially multiple toplevel
  environments, each noting the module against which its bindings are
  resolved, have each binding in the toplevel record what module it
  should be resolved in. Should fix compilation units that define
  multiple modules.
  (ghil-lookup, ghil-define): Reworked to not be destructive. Module
  variables now have the module name as their "env", and are keyed as
  `(MODNAME . SYM)' in the var table.
  (call-with-ghil-environment): Reindented.

* module/system/il/inline.scm (try-inline-with-env): Adapt to
  env/toplevel changes.

* module/system/vm/assemble.scm (dump-object!): A vlink-later now holds
  the module name, not the module itself.

* module/system/il/compile.scm (make-glil-var): The "env" of a "module"
  var is now the module name, not the module.

* module/language/scheme/translate.scm (primitive-syntax-table): Update
  the way we test for toplevel environments. Reindent the lambda
  translator.
  (lookup-transformer, trans): lookup-transformer now has 2 args, not 3.
  (translate): Update the way we make toplevel environments.
2008-09-07 22:27:08 +02:00
Andy Wingo
b5c46470a5 improve backtraces
* module/system/vm/frame.scm (frame-call-representation): Show more of
  lists.
  (program-name): Avoid a traceback if (frame-address link) is #f. Not
  sure when this can happen, but it does, and since this is already in
  the backtrace function, there be badness there.
2008-09-07 22:15:25 +02:00
Andy Wingo
97f1153a86 superstition with no important effect
* module/system/vm/assemble.scm (dump-object!): Some superstition, use
  bit arithmetic instead of int arithmetic. Makes me happier.
2008-09-02 11:00:32 -07:00
Andy Wingo
5c4926209f ditch the 8-bit compiled form of program parameters
* libguile/vm-i-loader.c (load-program):
* module/system/vm/assemble.scm (dump-object!): There are cases in which
  we use the 16-bit representation for program params (nargs, nexts,
  etc), but the actual 16-bit number actually fits into 8 bits -- which
  is then misinterpreted by the loader as the 8-bit form. So ditch the
  8-bit form entirely (it was never much of an optimization), and just
  use the 16-bit form. Make sure to clear out all your .go files before
  recompiling this one!
2008-09-02 10:30:39 -07:00
Andy Wingo
75a09d5ae6 module compilation fixen, post-integration
Thanks to Dale Smith.

* guilec.mk: Rework to expect the includer to define $(modpath), then
  make $(moddir) from that.

* module/language/Makefile.am:
* module/language/scheme/Makefile.am:
* module/system/base/Makefile.am:
* module/system/il/Makefile.am:
* module/system/repl/Makefile.am:
* module/system/vm/Makefile.am: Define modpath instead.

* src/guilec.in: Don't import (system vm bootstrap), it is no more.
2008-08-25 13:05:16 -07: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
Andy Wingo
22e95889ff remove unused "envs" code from guile-vm
* src/Makefile.am:
* src/envs.c:
* src/envs.h: Remove the envs code, which was historically used to
  implement modules. But since we use Guile's modules, these aren't
  necessary.

* src/vm.c:
* src/vm_loader.c:
* module/system/vm/assemble.scm: Remove code bits that trafficked in yon
  deprecation.
2008-08-20 14:11:35 -07:00
Andy Wingo
b9d8ed0502 make ,stats work
* module/system/repl/command.scm (display-time-stat, display-mips-stat):
  Always convert to float.

* module/system/vm/frame.scm (print-frame): Write the args, don't display them.

* module/system/repl/command.scm (statistics): gc-sweep-time is no more.
2008-08-11 19:51:33 +02:00
Andy Wingo
482015afec ease-of-use improvement to ,m; catch read errors at the repl
* module/system/repl/command.scm (module): Accept e.g. `,m ice-9 popen'
  in addition to `,m (ice-9 popen)'.

* module/system/repl/repl.scm (start-repl): Call read with a backtrace
  handler too.
2008-08-11 19:27:23 +02:00
Andy Wingo
7e4760e413 fix bug in compilation of and' and or'; more robust underflow detection.
* module/system/il/compile.scm (codegen): Rewrite handling of `and' and
  `or' ghil compilation, because it was broken if drop was #t. Tricky
  bug, this one! Took me days to track down!

* module/system/repl/repl.scm: Export call-with-backtrace, which probably
  should go in some other file.

* src/vm.c (scm_vm_save_stack): Handle the fp==0 case for errors before
  we have a frame.

* src/vm_engine.h (NEW_FRAME, FREE_FRAME): Stricter underflow checking,
  raising the stack base to the return address, in an attempt to prevent
  inadvertant stack smashing (the symptom of the and/or miscompilation
  bug).
  (CHECK_IP): A check that the current IP is within the bounds of the
  current program. Not normally compiled in. Perhaps it should be?

* src/vm_system.c (halt): Set vp->ip to NULL. Paranoia, I know.
  (return): Call CHECK_IP(), if such a thing is compiled in.

* testsuite/Makefile.am (vm_test_files):
* testsuite/t-catch.scm:
* testsuite/t-map.scm:
* testsuite/t-or.scm: New tests.
2008-08-11 18:35:58 +02:00
Andy Wingo
67c4505e7a backtraces on meta-commands too
* module/system/repl/repl.scm (call-with-backtrace): New helper.
  (start-repl): Use the helper, for normal expressions *and* for
  meta-commands.
2008-08-09 14:30:52 +02:00
Andy Wingo
e6d4e05cbd don't truncate .go files, do an atomic rename to prevent SIGBUS
* module/system/base/compile.scm (call-with-output-file/atomic): New
  proc, outputs to a tempfile then does an atomic rename. Prevents SIGBUS
  if a compiled file is truncated and rewritten, as the file's objcode is
  mmap'd in.
  (compile-file): Use the new helper.
2008-08-09 14:11:35 +02:00
Andy Wingo
fbea69ad42 fix source location reporting for compiled code
* module/system/repl/repl.scm (default-catch-handler): Cosmetic
  improvements on VM error backtraces.

* module/system/vm/frame.scm (print-frame): Cosmetic improvements.
  (frame-line-number): source:line operates on the handle, not the cdr.
  (print-frame-chain-as-backtrace): Cosmetic improvements.
2008-08-09 13:41:23 +02:00
Andy Wingo
29711eb918 heapify the bootstrap program
* src/vm_engine.c (vm_run):
* src/programs.c (scm_c_make_program): If the holder is #f, malloc *and*
  copy the bytecode.

* module/system/vm/frame.scm (bootstrap-frame?): Now that we actually
  heapify the bootstrap program, we can check for `halt' in the bytecode.
2008-08-08 17:05:41 +02:00
Andy Wingo
e15f47740b More relevant VM backtrace
* module/system/repl/repl.scm: Remove a useless print in the backtrace
  handler.

* module/system/vm/debug.scm (vm-backtrace): s/reverse!/reverse/

* module/system/vm/frame.scm (bootstrap-frame?): A heuristic to see if a
  frame is a bootstrap frame, the one allocated on the stack in
  vm_engine.c; need to have a better solution for this.
  (make-frame-chain): Don't include bootstrap frames, they add no
  information.
  (print-frame-chain-as-backtrace): Remove a pk.

* src/vm_engine.c (vm_run): Add a fixme about the bootstrap prograp.
2008-08-08 13:19:49 +02:00
Andy Wingo
d0168f3da8 improve source loc info in nonlocal exits and backtraces
* module/system/il/compile.scm (codegen): The currently-executing
  instruction is actually the one right before the instruction pointer;
  so for purposes of assv to find a source location for an ip, put the
  source after the code, as it was before.

* module/system/vm/debug.scm (vm-backtrace): Move more code to frame.scm.

* module/system/vm/frame.scm (make-frame-chain): Include all frames, even
  the bootstrap one. For a reentrant backtrace we'll have boostrap
  programs anyway. Probably should check for objcode[2] == scm_op_halt,
  to not show those frames in the trace.
  (frame-line-number, frame-file): New helpers.
  (print-frame): Print out the line number too.
  (frame-call-representation): Code from print-frame-call moved here.
  (print-frame-chain-as-backtrace): A backtrace printer, yays.
  (program-name): Check link validity before calling frame-address on it.

* module/system/vm/program.scm (source:addr, source:line, source:column)
  (source:file): New accessors for the elements of program-sources.

* module/system/vm/vm.scm (vm:last-ip): New export.
  (vm-last-frame-chain): Use vm:last-ip in making the frame chain.

* src/vm.h (struct scm_vm):
* src/vm.c (make_vm, scm_vm_last_ip, scm_vm_save_stack): Save the last
  instruction pointer when saving the stack. Really though, we should be
  saving all of the stack data on a spaghetti stack.

* src/vm_system.c (late-variable-ref): Pointless s/REGISTER/BEFORE_GC/.
2008-08-08 12:55:57 +02:00
Andy Wingo
81aae20202 fix bug in variable-set instruction; ,x prints out program metadata
* module/system/vm/disasm.scm (disassemble-program, disassemble-meta):
  Disassemble program meta information too, if it's there.

* src/vm_system.c (variable-set): Don't try to proxy name information;
  maybe we can do this later, but the code as it was was calling SCM_CAR
  on a variable, which is for the lose.
2008-08-08 00:26:17 +02:00
Andy Wingo
17d1b4bffd fix stack corruption on vm-save-stack; more robust with nonlocal exits
* module/system/repl/command.scm: Coerce rationals to floats.

* module/system/vm/program.scm (program-documentation): Fix a typo, doh!

* src/vm.c (vm_reset_stack, struct vm_unwind_data): Add unwind handler to
  reset vp->sp, vp->fp, and vp->this_frame when performing a nonlocal
  exit from a vm_run.
  (vm_heapify_frames_1): Don't repack the stack, it causes stack
  corruption. I think we need spaghetti stacks to handle continuations,
  not separate heap frames. I don't think call/cc is working now.
  (vm-save-stack): Don't call heapify_frames, that modifies the stack
  that we're copying. Instead call its helper, heapify_1.

* src/vm_engine.c (vm_run): Set up the vm_reset_stack unwind handler.

* src/vm_engine.h (IP_REG, SP_REG, FP_REG): If we got through all of the
  checks without having these macros defined, define them as empty.
  Happens on x86-64.

* src/vm_system.c (halt): End the dynwind before we return from the VM.

* src/vm_scheme.c (REL): Sync the regs before calling scm_lt_p et al,
  cause they can do a nonlocal exit.
2008-08-07 19:04:25 +02:00
Andy Wingo
68a2e18a04 vm backtrace improvements
* module/system/repl/repl.scm (default-pre-unwind-handler): Save the VM
  stack in addition to the interpreter stack. At some point these
  functions should know about each other, I guess.
  (default-catch-handler): Show the VM stack too. Needs a bit of work.

* module/system/vm/frame.scm: Export make-frame-chain.

* module/system/vm/vm.scm: Export vm-save-stack.

* src/vm.c (scm_vm_save_stack): New function, heapifies the current
  stack, saving it to vm->last_frame.

* src/vm_engine.c (vm_run:vm_error): Don't heapify frames here, because
  nonlocal exits avoid this code entirely. Instead rely on the user
  saving the stack with a pre-unwind handler, as the repl does.
2008-08-07 13:51:45 +02:00
Andy Wingo
d0927dde97 build fixes
* benchmark/measure.scm: Update for module changes.

* module/system/vm/Makefile.am: Update the set of modules needing
  compilation.

* src/guile-vm.c: Bootstrap the VM, now that we have a function for it.

* testsuite/Makefile.am:
* testsuite/run-vm-tests.scm: Update to fix make check, broken since we
  merged with Guile.
2008-08-07 13:29:15 +02:00
Andy Wingo
07e56b27a1 big reorg of scheme modules -- e.g. programs.c -> (system vm program)
This reorganization kills the ugly module-export-all hacks in
bootstrap.scm and core.scm. In fact, it gets rid of core.scm entirely,
breaking out its functionality into separate files.

* module/system/vm/trace.scm:
* module/system/vm/profile.scm:
* module/system/vm/disasm.scm:
* module/system/vm/debug.scm:
* module/system/vm/conv.scm:
* module/system/vm/assemble.scm:
* module/system/repl/repl.scm:
* module/system/repl/common.scm:
* module/system/base/compile.scm:
* module/system/repl/command.scm: Update for changes, and fix a bug in
  procedure-documentation.

* module/system/vm/bootstrap.scm: Just call scm_bootstrap_vm, which
  handles setting load-compiled for us.

* module/system/vm/core.scm: Removed, functionality folded into other
  modules.

* module/system/vm/frame.scm: Export the C frame procedures here; also
  move scheme functions from core.scm here.

* module/system/vm/instruction.scm: New file, exports procedures from
  instructions.c.

* module/system/vm/objcode.scm: New file, exports procedures from
  objcodes.c.

* module/system/vm/program.scm: New file, exports procedures from
  programs.c, and some scheme functions originally from core.scm.

* module/system/vm/vm.scm: New file, from vm.c and core.scm.

* src/Makefile.am (libguile_vm_la_SOURCES): Add bootstrap.h.

* src/bootstrap.h: New file, prototypes scm_bootstrap_vm (), which the
  scm_init_* functions call.

* src/frames.h:
* src/frames.c (scm_init_frames):
* src/frames.c (scm_bootstrap_frames):

* src/vm.h:
* src/instructions.h:
* src/instructions.c (scm_init_instructions):
* src/instructions.c (scm_bootstrap_instructions):
* src/objcodes.h:
* src/objcodes.c (scm_bootstrap_objcodes):
* src/objcodes.c (scm_init_objcodes):
* src/programs.h:
* src/programs.c (scm_bootstrap_programs):
* src/programs.c (scm_init_programs):
* src/vm.c (scm_bootstrap_vm):
* src/vm.c (scm_init_vm): Call scm_bootstrap_vm() before doing anything
  in an init function. Bootstrap_vm will call bootstrap_instructions(),
  etc to initialize types, then set load-compiled to point to
  load-compiled/vm.

* src/vm.c (scm_load_compiled_with_vm): Code to load .go files, if
  they're present.
2008-08-07 13:11:27 +02:00
Andy Wingo
659b4611b6 re-enable computed goto; fix ,help in the repl; subr dispatch optimizations
* m4/labels-as-values.m4: New file, checks for computed goto.

* configure.in: Use AC_C_LABELS_AS_VALUES.

* module/system/repl/command.scm (procedure-documentation): Extend the
  core's procedure-documentation in an ad-hoc way, so that ,help works.

* module/system/vm/core.scm (program-properties): New function.
  (program-documentation): New function.

* src/vm_engine.h (DROP, DROPN): Decrement sp before checking for
  underflow.

* src/vm_system.c (call, tail-call): Add some optimized dispatch for some
  C functions, so that we can avoid consing and the interpreter if
  possible. However currently it seems that I'm always getting the
  scm_call_* trampolines back.
2008-08-05 01:03:17 +02:00
Andy Wingo
fbde2b915b Add docstring support
* module/language/scheme/translate.scm (translate): Adapt to lambda
  having a `meta' slot now.
  (primitive-syntax-table, parse-lambda-meta): Parse out a docstring from
  lambda forms, putting in the <ghil-lambda>'s meta slot.

* module/system/il/compile.scm (optimize, codegen): Passthrough for the
  `meta' slot to the <glil-asm> object.

* module/system/il/ghil.scm (<ghil-lambda>): Add meta slot.

* module/system/il/glil.scm (<glil-asm>): Add meta slot.
  (unparse): Unparse meta.

* module/system/vm/assemble.scm (preprocess): Pass through the meta slot.
  (codegen): So, set the bytespec's meta slot as a list: bindings, source
  info, then the tail is the meta-info, which should be an alist.
  Currently the only defined key is `documentation', but `name' could
  come in the future.

* module/system/vm/core.scm (program-sources): Sources are now in the
  cadr...
  (program-property): And here we have access to the cddr.
2008-08-03 14:33:02 +02:00
Andy Wingo
96969dc1d6 fix recording of source locations
* module/language/scheme/translate.scm (translate, trans)
  (make-pmatch-transformers): When recursing into subexpressions, get the
  appropriate source location information.
  (location): Include the source filename in the location information.

* module/system/il/compile.scm (codegen): Record source locations in more
  cases. (This information ends up being part of the procedure metadata,
  not the actual codepath.)

* module/system/il/glil.scm (unparse): Don't destructure the source
  locations (it's a vector now).
2008-08-03 14:03:47 +02:00
Andy Wingo
6cc3f99e83 add inline macros for zero? and 1-
* module/system/il/inline.scm (zero?, 1-): New inlines. Neat :) The loop
  benchmark speedup is now up to 5x.
2008-05-25 13:38:17 +02:00
Andy Wingo
22bcbe8cc9 enable inlining; speed!
* module/system/il/inline.scm: New module, implements generic inlining of
  scheme functions. It even does the right thing regarding (define
  arity:nopt caddr) and such. So now there are many more inlines: the
  arithmetics, `apply', the caddr family, etc. This makes the benchmarks
  *much* faster.

* module/language/scheme/translate.scm (trans): Remove the
  %scheme-primitives code in favor of the generic (scheme il inline)
  code. Adds inlining for +, -, =, etc.

* src/vm.c (vm_puts): Fix to work.

* module/system/base/compile.scm (system): Export load/compile also.

* module/system/il/compile.scm (optimize): Further debitrotting, but I
  haven't tried this function yet. It seems that <ghil-inst> was what
  <ghil-inline> is.

* module/system/il/ghil.scm (*core-primitives*, *macro-module*)
  (ghil-primitive-macro?, ghil-macro-expander, ghil-primitive?): Remove
  these unused things.

* module/system/il/macros.scm: Removed, replaced with inline.scm.

* module/system/vm/assemble.scm (stack->bytes): Before, the final
  serialization code did an (apply u8vector (apply append (map
  u8vector->list ...))). Aside from the misspelling of append-map, this
  ends up pushing all elements of the u8vector on the stack -- assuredly
  not what you want. But besides even that, I think that pushing more
  than 32k arguments on the stack brings out some other bug that I think
  was hidden before, because now we actually use the `apply' VM
  instruction. Further testing is needed here, I think. Fixed the code to
  be more efficient, which fixes the manifestation of this particular
  bug: a failure to self-compile after inlining was enabled.

* module/system/vm/bootstrap.scm: New module, serves to bootstrap
  boot-9's `load-compiled'. That way when we load (system vm core), we're
  loading compiled code already.

* module/system/vm/core.scm: Use (system vm bootstrap).

* src/guilec.in: Use the bootstrap code, so that we really are compiling
  with an entirely compiled compiler.

* module/system/repl/repl.scm (default-catch-handler): An attempt at
  making the repl print a backtrace; more work needed here.

* module/system/vm/frame.scm (make-frame-chain): Fix some misspellings --
  I think, anyway.
2008-05-25 13:13:15 +02:00
Andy Wingo
51f6b8f377 distcheck works now
* guilec.mk: New file, to be included when building .go files.

* module/language/scheme/Makefile.am:
* module/system/base/Makefile.am:
* module/system/il/Makefile.am:
* module/system/repl/Makefile.am:
* module/system/vm/Makefile.am: Use guilec.mk.

* module/system/base/compile.scm (compiled-file-name): Work on the
  basename of a file, so that we always create files in the directory
  where we run. Perhaps should add a -o option to guilec in the future.

* Makefile.am: Actually recurse into module/ in a normal build.
2008-05-20 12:54:14 +02:00
Andy Wingo
d79d908ef0 guile-vm is completely self-compiling now!
* module/language/scheme/translate.scm (*the-compile-toplevel-symbol*):
  Reset to compile-toplevel, which requires a patch to guile.

* module/system/base/compile.scm (compile-file): Some foo so that we load
  up the scheme language before call-with-output-file. Fixes compilation
  of (language scheme) modules.

* module/system/base/language.scm (define-language): Don't unquote in
  make-language; refer to it by name instead, and export it.

* module/system/repl/Makefile.am (vm_DATA): Don't compile describe.scm,
  because we really can't deal with goops yet.

* module/system/repl/repl.scm (compile-toplevel): If we're compiling, put
  in a stub definition of start-stack, which is closely tied to the
  interpreter.

* src/vm_loader.c (load-program): Fix a very tricky corruption bug!
2008-05-20 11:33:28 +02:00
Andy Wingo
5163e95138 fix syntax error in describe.scm
* module/system/repl/describe.scm (format-documentation): Remove bad
  string syntax. This file doesn't compile though, due to define-macro
  being a procedure->syntax macro.
2008-05-19 21:38:09 +02:00
Andy Wingo
9246a48606 fix immediate linkage, some other fixes to allow vm/ to compile
* module/language/scheme/translate.scm (lookup-transformer): Allow for
  undefined variables when doing the transformation -- it's possible that
  they come from a module definition's forward declaration.

* module/system/repl/command.scm (import): Make into legal Scheme, caught
  by the compiler :-)

* module/system/vm/assemble.scm (<vlink-now>): Remove the module field.
  Immediate bindings will now always be relative to the current module.
  Fixes some mess about process-define-module not being defined when
  loading modules, probably because we destructively modified the
  ghil-env.
  (codegen, dump-object!): Don't dump a module name.

* src/vm_loader.c (link-now): Just use scm_lookup.
2008-05-19 21:29:18 +02:00
Andy Wingo
6297d22907 bind all module-level variables lazily
comments in ghil-lookup are pertinent.

* module/system/il/compile.scm (make-glil-var): Require that ghil vars
  have environments. Remove the 'unresolved case -- we'll treat all
  module-level variables as late bound.

* module/system/il/ghil.scm (ghil-lookup): Treat all module level vars as
  late bound.

* module/system/vm/assemble.scm: Instead of vlink and vlate-bound, have
  vlink-now and vlink-later.
  (codegen): Add a bunch of crap to get the various cases right.
  (object-assoc, dump-object!): Handle the new cases, remove the old
  cases.

* src/vm_loader.c (link-now, link-later): Change from link and lazy-bind.
  Include the module in which the link is to be done, so that callers
  from other modules get the right behavior.

* src/vm_system.c (late-variable-ref, late-variable-set): Instead of a
  sym, the unbound representation is a module name / symbol pair.

* testsuite/run-vm-tests.scm (run-vm-tests): Remove some debugging.
2008-05-19 19:37:39 +02:00
Andy Wingo
9cc649b880 Add instructions for doing very late binding
Fixes the mutually-recursive toplevel definitions case. This could be
fixed by rewriting bodies as letrecs, as r6 does, but that's not really
repl-compatible.

* module/system/il/ghil.scm (ghil-lookup): Ok, if we can't locate a
  variable, mark it as unresolved.

* module/system/il/compile.scm (make-glil-var): Compile unresolved
  variables as <glil-late-bound> objects.

* module/system/il/glil.scm: Add <glil-late-bound> definition.

* module/system/vm/assemble.scm (codegen): And, finally, when we see a
  <vlate-bound> object, allocate a slot for it in the object vector,
  setting it to a symbol. Add a new pair of instructions to resolve that
  symbol to a variable at the last minute.

* src/vm_loader.c (load-number): Bugfix: the radix argument should be
  SCM_UNDEFINED in order to default to 10.
  (late-bind): Add an unresolved symbol to the object vector. Could be
  replaced with load-symbol I guess.

* src/vm_system.c (late-variable-ref, late-variable-set): New
  instructions to do late symbol binding.

* testsuite/Makefile.am (vm_test_files):
* testsuite/t-mutual-toplevel-defines.scm: New test, failing for some
  reason involving the core even? and odd? definitions.
2008-05-19 17:46:05 +02:00
Andy Wingo
1b8abe5514 compile all of base/; some arbitrary changes; more "fixes" to `link'
* module/language/scheme/translate.scm (lookup-transformer): When
  expanding syncase macros, use the eval closure from the ghil-env.
  Probably doesn't make any difference whatsoever.

* module/system/base/Makefile.am (SOURCES): Compile pmatch.scm, now that
  it works :-))

* module/system/base/compile.scm (compile-in): Compile inside a
  save-module-excursion, so that side effects of evaluation don't leak
  out.

* module/system/base/pmatch.scm: Change from :use-syntax/:export-syntax
  to simply :use-modules/:export. Also probably has no effect.

* module/system/il/ghil.scm (fix-ghil-mod!): Suppress warnings resulting
  from compilation of define-module.

* src/vm_loader.c (link): So, referencing variables defined but not
  exported from the current module didn't work. Fixed that, but it's
  hacky. There are still some uncaught cases.
2008-05-19 12:57:48 +02:00