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

2036 commits

Author SHA1 Message Date
Andy Wingo
a72317988f placeholder for meta and module in a program's object table
* module/language/glil/compile-objcode.scm (codegen): If the generated
  objcode will have a meta or it has objects, prepend two cells to the
  object table: one for the meta, and one for the module. This is a
  placeholder for future work.
2009-01-17 15:08:05 +01:00
Andy Wingo
78bae3d6fa fix mismerge on srfi-19.scm
* module/srfi/srfi-19.scm (priv:locale-abbr-weekday->index): Whoops, fix
  broken manual merge on srfi-19.scm.
2009-01-12 21:45:37 +01:00
Andy Wingo
7bd5f2913d fix typo when compiling receive forms
* module/language/glil/compile-objcode.scm (codegen): Fix an embarassing
  typo, introduced in c2c82b62f4
2009-01-12 21:37:44 +01:00
Andy Wingo
c32929d14d Merge commit 'origin/master' into vm
Conflicts:

	.gitignore
	guile-tools.in
	srfi/srfi-19.scm
2009-01-12 21:36:39 +01:00
Andy Wingo
ff73ae34c3 finish compiler.texi, woo
* libguile/objcodes.c (do-pair): Removed unused debuging hack.

* module/language/glil/spec.scm (glil): Simplify a bit.

* module/system/repl/repl.scm (default-catch-handler): Don't catch
  vm-error, as vm-backtrace doesn't exist any more.

* doc/ref/compiler.texi: Finish documenting GLIL and object code.
2009-01-11 14:23:48 +01:00
Andy Wingo
c850030fdd rename <glil-asm> to <glil-program>
* module/language/glil.scm (<glil-program>): Rename from <glil-asm>.

* module/language/ghil/compile-glil.scm (codegen):
* module/language/glil.scm (parse-glil, unparse-glil):
* module/language/glil/compile-objcode.scm (preprocess, codegen): Adapt
  to naming change.
2009-01-11 12:14:07 +01:00
Andy Wingo
c2c82b62f4 remove useless <glil-vars> helper type, serialize GHIL more strictly
* module/language/ghil.scm (parse-ghil, unparse-ghil): Rework to make the
  parse format correspond more closely with the object representation, so
  that I only have to document it once in the manual. The salient change
  is that no expression is self-quoting, and that variable references
  should go through `(ref FOO)'. Rename `set!' to `set'.

* module/language/ghil/compile-glil.scm: Add a couple of compilers for
  unquote and unquote-splicing, that just raise an error. This way I can
  document unquote and unquote-splicing as normal ghil expressions,
  except that it's the compiler that catches them if they're outside a
  quasiquote.
  (codegen): Adapt to change in <glil-asm>.

* module/language/ghil/spec.scm (parse): Fix parser typo bug.

* module/language/glil.scm (<glil-asm>): Remove useless <glil-vars>
  structure, which also had a confusing name. Just put the nargs, nrest,
  nlocs, and nexts in the <glil-asm> directly.
  (parse-glil, unparse-glil): Serialize `asm' more straightforwardly.

* module/language/glil/compile-objcode.scm (<bytespec>): Remove
  <glil-vars>, as with <glil-asm>.
  (preprocess, make-meta, codegen, dump-object!): Adapt to change in
  <glil-asm>.
2009-01-11 12:09:19 +01:00
Andy Wingo
ca445ba5ec rename translate.scm to compile-ghil.scm, and more work on compiler.texi
* doc/ref/api-evaluation.texi: Fix some typos and xrefs.

* doc/ref/compiler.texi (The Scheme Compiler): Document the scheme
  compiler, and start documenting the GHIL language.

* doc/ref/guile.texi (Guile Implementation): Whoops, put autoconf after
  the implementation foo. Unless we want it before?

* doc/ref/history.texi (The Emacs Thesis): Fix typo.

* doc/ref/vm.texi (Environment Control Instructions): Rename offset to
  index.

* module/language/ghil.scm (parse-ghil): Fix what I think was a bug --
  the consumer in a mv-call shouldn't be a rest arg.

* module/language/scheme/Makefile.am (SOURCES):
* module/language/scheme/compile-ghil.scm: Rename this file from
  translate.scm.

* module/oop/goops.scm:
* module/language/scheme/spec.scm: Deal with renaming.
2009-01-09 17:49:09 +01:00
Andy Wingo
9ff56d9e65 (language ghil def) becomes (language ghil)
* module/language/Makefile.am:
* module/language/ghil/Makefile.am:
* module/language/ghil.scm:
* module/language/ghil/compile-glil.scm:
* module/language/ghil/spec.scm:
* module/language/glil/Makefile.am:
* module/language/glil.scm:
* module/language/glil/compile-objcode.scm:
* module/language/glil/spec.scm:
* module/language/scheme/inline.scm:
* module/language/scheme/translate.scm:
* module/oop/goops.scm: Rename (language ghil def) and (language glil
  def) to not have the "def". They're nicer names.
2009-01-08 19:25:38 +01:00
Andy Wingo
d9042285ba move lang-specific modules, e.g. (system il compile) to (language ghil compile-glil)
* configure.in: Remove module/system/il directory.

* module/language/ghil/Makefile.am (SOURCES):
* module/language/ghil/compile-glil.scm (system):
* module/language/ghil/def.scm (language):
* module/language/ghil/spec.scm (language, ghil):
* module/language/glil/Makefile.am (SOURCES):
* module/language/glil/compile-objcode.scm (language):
* module/language/glil/def.scm (language):
* module/language/glil/spec.scm (language, compile):
* module/language/scheme/Makefile.am (SOURCES):
* module/language/scheme/inline.scm (system, define-inline):
* module/language/scheme/translate.scm (language): Move files, renaming
  the modules.

* module/oop/goops.scm (load-toplevel): Unfortunately the GHIL name
  leaked here. Patch it up.

* module/system/vm/Makefile.am (SOURCES): Remove assemble.scm.
2009-01-08 12:18:34 +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
9f0e9918f4 repl.scm relies on `display-backtrace' to do everything, some naming tweaks
* module/ice-9/boot-9.scm (default-pre-unwind-handler): Rename from
  default-lazy-handler.
  (pre-unwind-handler-dispatch): Rename from lazy-hadler-dispatch.
  (error-catching-loop): Adjust caller.

* module/system/repl/repl.scm (default-pre-unwind-handler): Remove this
  definition, in favor of the default one in boot-9.
  (default-catch-handler): Don't do a vm-backtrace, as we will soon be
  relying on core machinery to do that for us.
  (call-with-backtrace): Start a new stack for the thunk.
  (with-backtrace): Macro version of call-with-backtrace.
  (start-repl): Use with-backtrace for brevity. Start a stack with #t as
  the tag instead of repl-eval, because all traces of repl-eval are gone
  after it does a tail-call.

* module/ice-9/debugger.scm:
* module/ice-9/debugging/traps.scm:
* module/ice-9/stack-catch.scm: Adapt to s/lazy/pre-unwind/ in
  boot-9.scm.
2008-12-26 18:07:20 +01:00
Andy Wingo
f7e5296e04 late-variable-{ref,set} -> toplevel-{ref,set}
* benchmark/lib.scm:
* libguile/vm-i-system.c (toplevel-ref, toplevel-set):
* module/system/vm/assemble.scm (codegen):
* module/system/vm/disasm.scm (code-annotation):
  s/late-variable/toplevel/. It's just a better name.
2008-11-20 13:45:27 +01:00
Andy Wingo
b0b180d522 nifty generic compiler infrastructure -- no more hardcoded passes
* module/system/base/language.scm (<language>): Rework so that instead of
  hardcoding passes in the language, we define compilers that translate
  from one language to another. Add `parser' to the language fields, a
  bit of a hack but useful for languages with s-expression external
  representations but with record internal representations.
  (define-language, *compilation-cache*, invalidate-compilation-cache!)
  (compute-compilation-order, lookup-compilation-order): Add an algorithm
  that does a depth-first search for a translation path from a source
  language to a target language, caching the result in a lookup table.

* module/language/scheme/spec.scm:
* module/language/ghil/spec.scm: Update to the new language format.

* module/language/glil/spec.scm: Add a language specification for GLIL,
  with a compiler to objcode. Also there are parsers and printers, for
  repl usage, but for some reason this doesn't work yet.

* module/language/objcode/spec.scm: Define a language specification for
  object code. There is some sleight of hand here, in the "compiler" to
  values; but there is method behind the madness, because this way we
  higher levels can pass environments (a module + externals pair) to
  objcode->program.

* module/language/value/spec.scm: Define a language specification for
  values. There is something intellectually dishonest about this, but it
  does serve its purpose as a foundation for the language hierarchy.

* configure.in:
* module/language/Makefile.am
* module/language/ghil/Makefile.am
* module/language/glil/Makefile.am
* module/language/objcode/Makefile.am
* module/language/value/Makefile.am:
  Autotomfoolery for the ghil, glil, objcode, and value languages.

* module/language/scheme/translate.scm (translate): Import the bits that
  understand `compile-time-environment' here, and pass on the relevant
  portions of the environment to the next compiler pass.

* module/system/base/compile.scm (current-language): New procedure, refs
  the current language fluid, or lazily sets it to scheme.
  (call-once, call-with-output-file/atomic): Refactor these bits to use
  with-throw-handler. No functional change.
  (compile-file, compile-and-load, compile-passes, compile-fold)
  (compile): Refactor the public interface of the compiler to be generic
  and simple. Uses `lookup-compilation-order' to find a path from the
  source language to the target language.

* module/system/base/syntax.scm (define-type): Adapt to changes in
  define-record.
  (define-record): Instead of expecting all slots in the first form,
  expect them in the body, and let the first form hold the options.

* module/system/il/compile.scm (compile): Adapt to the compilation pass
  API (three in and two out).

* module/system/il/ghil.scm (<ghil-var>, <ghil-env>)
  (<ghil-toplevel-env>): Adapt to define-record changes.

* module/system/il/glil.scm (<glil-vars>): Adapt to define-record
  changes.
  (<glil>, print-glil): Add a GLIL record printer that uses unparse.
  (parse-glil, unparse-glil): Update unparse (formerly known as pprint),
  and write a parse function.

* module/system/repl/common.scm (<repl>): Adapt to define-record changes.
  (repl-parse): New function, parses the read form using the current
  language. Something of a hack.
  (repl-compile): Adapt to changes in `compile'.
  (repl-eval): Fix up the does-the-language-have-a-compiler check for
  changes in <language>.

* module/system/repl/repl.scm (start-repl): Parse the form before eval.

* module/system/repl/command.scm (describe): Parse.
  (compile): Be more generic.
  (compile-file): Adapt to changes in compile-file.
  (disassemble, time, profile, trace): Parse.

* module/system/vm/debug.scm:
* module/system/vm/assemble.scm: Adapt to define-record changes.

* module/language/scheme/translate.scm (receive): Fix an important bug
  that gave `receive' letrec semantics instead of let semantics. Whoops!
2008-11-14 22:42:31 +01:00
Andy Wingo
7493339cfc more ghil parsing fixen
* module/system/il/ghil.scm (parse-ghil): Fix a typo for values*
  (unparse-ghil): Only output (quote foo) if the object is a symbol.
  (unparse-ghil): Fix some missing ,@.
2008-11-12 00:29:45 +01:00
Andy Wingo
7c29050660 fix unparse-ghil errors with quasiquote
* module/system/il/ghil.scm (unparse-ghil): Fix some issues with
  quasiquote and unquote[-splicing]. Doh!
2008-11-11 23:12:39 +01:00
Andy Wingo
f38624b349 add parsers and unparser for ghil; ,language ghil works now
* module/system/repl/common.scm (repl-print): Slightly refine the meaning
  of "language-printer": a language printer prints an expression of a
  language, not the result of evaluation. `write' prints values.

* module/language/ghil/spec.scm (ghil): Define a language printer, and a
  translator for turning s-expressions (not scheme, mind you) into GHIL.

* module/language/scheme/translate.scm (quote, quasiquote): Add some
  #:keyword action, so that we can (quote #:keywords).

* module/system/base/language.scm (<language>):
* module/system/base/compile.scm (read-file-in): Don't require that a
  language have a read-file; instead error when read-file is called.
  (compile-passes, compile-in): Refactor to call a helper method to turn
  the language + set of options into a set of compiler passes.

* module/system/base/syntax.scm (define-type): Allow the type to be a
  list, with the car being the name and the cdr being keyword options.
  Interpret #:printer as a printer, and pass it down to...
  (define-record): Here.

* module/system/il/ghil.scm (print-ghil, <ghil>): New printer for GHIL,
  yay!
  (parse-ghil, unparse-ghil): New lovely functions. Will document them in
  the manual.
2008-11-11 22:52:24 +01:00
Andy Wingo
f698d111b4 remove .cvsignore files 2008-11-10 12:17:18 +01:00
Andy Wingo
2651e3c412 proper printing of thunks, reduced disasm verbosity
* module/system/vm/disasm.scm (disassemble-program): Don't print the
  nargs= nrest= etc line, it's redundant.

* module/system/vm/program.scm (program-bindings-as-lambda-list): If the
  program bindings is null, then that's that.
2008-11-02 01:37:00 +01:00
Andy Wingo
6c3686ea14 define macros before functions using macros; more MV fixen in srfi-69
* module/srfi/srfi-69.scm: Move the macros up before the functions that
  use them, so that the compiler can do its job.
  (hash-table-walk): While it is true about what I said about R5RS
  before, it seems that for R6 this will have to change. Anyway. In the
  meantime, since the test suite checks that hash-table-walk procedures'
  return values and number of return values are ignored, call that
  procedure within a call-with-values.
2008-11-01 20:31:57 +01:00
Andy Wingo
0a283d1b0b avoid delivering 0 values to 1-valued continuations in srfi-19
* module/srfi/srfi-19.scm: Some parts of this code used a strange idiom,
  `(values)', to indicate that a procedure did nothing. However, quoth
  R5RS:

     Except for continuations created by the `call-with-values'
     procedure, all continuations take exactly one value.

  Indeed the VM indicated this error. I reworked the code to avoid these
  cases.
2008-11-01 14:28:24 +01:00
Andy Wingo
ea93465de7 move scm srfi files to module/srfi, and compile them.
* .gitignore: Add gdb-pre-inst-guile.

* configure.in: Add module/srfi/Makefile.

* module/Makefile.am: Add srfi/.

* module/srfi/: SRFI scheme files moved here, and compiled.

* srfi/Makefile.am: Remove the bits about the scheme files.
2008-11-01 13:49:23 +01:00
Andy Wingo
3f0bce1e14 move guilec.mk to am/guilec
* am/Makefile.am:
* am/guilec: guilec moved here from /guilec.mk.

All includers of guilec adapted.
2008-11-01 13:05:10 +01:00
Andy Wingo
00d0489205 move ice-9/ and oop/ under module/
Moved ice-9/ and oop/ under module/, with the idea being that we have
only scheme under module/. Adjusted configure.in and Makefile.am
appropriately. Put oop/ at the end of the compilation order.
2008-11-01 12:44:21 +01:00
Andy Wingo
eb5f05c320 fix bug in define-scheme-translator
* module/language/scheme/translate.scm (define-scheme-translator): Fix a
  bug in this macro for the syntax-error case.
2008-10-31 14:07:11 +01:00
Andy Wingo
03fa04dfe1 pass backtraces through the compiler
* module/system/base/compile.scm (call-with-nonlocal-exit-protect): New
  helper, like unwind-protect but only for nonlocal exits.
  (call-with-output-file/atomic): Use call-with-nonlocal-exit-protect so
  that we don't mess up backtraces by catching all and then rethrowing.
  Should fix this more comprehensively somewhere, though.
2008-10-31 13:28:06 +01:00
Andy Wingo
46ccd0bbf9 make define-inline more usable from external modules
* module/system/il/inline.scm (define-inline): Use @ when accessing
  module vars so that other modules don't need to import all of our
  modules. However case-lambda is still needed.
2008-10-31 13:26:48 +01:00
Andy Wingo
fd4da4fae6 rework the scheme translator so it's extensible by external modules
* module/language/scheme/translate.scm (*translate-table*)
  (define-scheme-translator): Rework the translator to have the clauses
  defined separately via the define-scheme-translator macro, so that
  external modules can define their own translators. Should be no
  functional change in this commit, though.
2008-10-31 13:25:11 +01:00
Andy Wingo
3de80ed52f recompiling with compile environments, fluid languages, cleanups
* ice-9/boot-9.scm (compile-time-environment): Remove definition from
  boot-9 -- instead, autoload it and `compile' from (system base
  compile).

* libguile/objcodes.h:
* libguile/objcodes.c (scm_objcode_to_program): Add an optional argument,
  `external', the external list to set on the returned program.

* libguile/vm-i-system.c (externals): New instruction, returns the
  external list. Only used by (compile-time-environment).

* libguile/vm.c (scm_load_compiled_with_vm): Adapt to
  scm_objcode_to_program change.

* module/language/scheme/translate.scm (translate): Actually pay
  attention to the environment passed as an argument.
  (custom-transformer-table): Expand out (compile-time-environment) to
  something that can be passed to `compile'.

* module/system/base/compile.scm (*current-language*): Instead of
  hard-coding `scheme' in various places, use a current language fluid,
  initialized to `scheme'.
  (compile-file, load-source-file): Adapt to *current-language*.
  (load-source-file): Ada
  (scheme-eval): Removed, no one used this.
  (compiled-file-name): Don't hard-code "scm" and "go"; instead use the
  %load-extensions and %load-compiled-extensions.
  (cenv-module, cenv-ghil-env, cenv-externals): Some accessors for
  compile-time environments.
  (compile-time-environment): Here we define (compile-time-environment)
  to something that will return #f; the compiler however produces
  different code as noted above.
  (compile): New function, compiles an expression into a thunk, then runs
  the thunk to get the value. Useful for procedures. The optional second
  argument can be either a module or a compile-time-environment; in the
  latter case, we can recompile even with lexical bindings.
  (compile-in): If the env specifies a module, set that module for the
  duration of the compilation.

* module/system/base/syntax.scm (%compute-initargs): Fix a bug where the
  default value for a field would always replace a user-supplied value.
  Whoops.

* module/system/il/ghil.scm (ghil-env-dereify): New function, takes the
  result of ghil-env-reify and turns it back into a GHIL environment.

* scripts/compile (compile): Remove some of the tricky error handling, as
  the library procedures handle this for us.

* test-suite/tests/compiler.test: Add a test for the dynamic compilation
  bits.
2008-10-30 10:57:36 +01:00
Andy Wingo
20bdc71054 add `compile-time-environment'
* ice-9/boot-9.scm (compile-time-environment): New function, with
  documentation. The trick is that the compiler recognizes calls to
  (compile-time-environment) and replaces it with a representation of the
  *available* lexicals. Note that this might not be all the lexicals;
  only the heap-allocated ones are returned.

* module/language/scheme/translate.scm (custom-transformer-table):
  Compile `compile-time-environment' to <ghil-reified-env>.

* module/system/il/compile.scm (codegen): Add <ghil-reified-env> clause,
  which calls ghil-env-reify.

* module/system/il/ghil.scm (ghil-env-reify): New procedure, returns a
  list of (NAME . EXTERNAL-INDEX).
  (<ghil>): Add <ghil-reified-env> object.
2008-10-25 22:58:48 +02:00
Andy Wingo
1086fabdc9 define-type no longer expects `|' subform
* module/system/base/syntax.scm (define-type): Rework to not require the
  `|', which confuses Emacs.

* module/system/il/ghil.scm (<ghil>):
* module/system/il/glil.scm (<glil>): Adapt to define-type changes.
2008-10-25 22:58:48 +02:00
Andy Wingo
6ce6dc03c1 fix typo in assembler
* module/system/vm/assemble.scm (dump-object!): Whoops, spell `nexts'
  correctly.
2008-10-18 19:42:37 +02:00
Andy Wingo
5e390de62f fix bug in self-tail-recursion with "external" variables; other sundries
* gdbinit (pp, inst): New commands.

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

* libguile/vm-i-scheme.c (VM_VALIDATE_CONS): New macro -- use this
  instead of SCM_VALIDATE_* because SCM_VALIDATE will exit nonlocally
  before we have a chance to sync the regs.
  (car, cdr, set-car, set-cdr): Use VM_VALIDATE_CONS.

* libguile/vm-i-system.c (goto/args): Bugfix: when doing a
  self-tail-recursion, allocate fresh externals. Fixes use of match.go.

* module/system/vm/assemble.scm (dump-object!): Add some checks that we
  aren't dumping out values that the VM can't handle.

* module/system/vm/disasm.scm (disassemble-externals): Fix rotten call to
  `print-info'.

* oop/goops/dispatch.scm: Add a FIXME.

* testsuite/Makefile.am (vm_test_files):
* testsuite/t-closure4.scm (extract-symbols): New test, distilled with
  much effort out of match.scm.

* ice-9/Makefile.am (NOCOMP_SOURCES): Re-enable compilation of match.scm.
  Yay!
2008-10-18 19:21:44 +02:00
Andy Wingo
b3b45ac15e bug fix to enable code "packing"
* module/system/vm/conv.scm (code-pack): Fix so that we actually
  recognize (make-int8 1) and turn it into (make-int8:1).
2008-10-18 16:06:43 +02:00
Andy Wingo
cc588f740f fix backtraces, broken since the program-bindings format change
* module/system/vm/frame.scm (frame-bindings): Fix for new binding
  format; actually use the bindings accessors.
  (frame-lookup-binding): Clarify.
2008-10-16 13:56:41 +02:00
Andy Wingo
f580ec0f56 fix use of `binding' data abstraction
* module/system/vm/assemble.scm (make-temp-binding, btemp:name)
  (btemp:extp, btemp:index): Don't abuse program.scm's make-binding to
  make something that actually isn't a binding.
  (codegen): Do use program.scm's make-binding to make something that
  actually is a binding.

* module/system/vm/program.scm (binding:start, binding:end): New
  accessors.
  (make-binding): Expand to have the start and end arguments in the
  constructor.
2008-10-16 13:49:57 +02:00
Andy Wingo
1a38597553 fix mv-call disasm bug
* module/system/vm/disasm.scm (code-annotation): Fix bug with mv-call.
2008-10-15 22:42:51 +02:00
Andy Wingo
8f64368ee5 fix disasm bugs, add some more instruction annotations
* module/system/vm/disasm.scm (disassemble-program): Fix misunderstanding
  of nlocs: the *actual* number of locals is nlocs + nargs, even if the
  arg is heap-allocated -- because our calling convention always puts the
  initial val on the stack. Also: don't disassemble the objects, they are
  now woven into the text.
  (code-annotation): Fix external-{ref,set} handling to allow for
  referencing externals from enclosed stack frames. Really this should be
  statically determined, though. Add late-variable-{ref,set} handling.
2008-10-15 22:30:47 +02:00
Andy Wingo
02b1883e56 make disassembly better -- a more woven text.
* module/system/vm/assemble.scm (pop): Define a pop here too.
  (codegen): Rework how bindings are represented in a program's
  meta-info, so they declare their range in the binding list instead of
  you having to figure out when they end.

* module/system/vm/conv.scm (make-byte-decoder): Return the end-address
  as well; requires a change to callers.

* module/system/vm/disasm.scm (disassemble-objcode, disassemble-program)
  (disassemble-bytecode, disassemble-objects, disassemble-externals)
  (disassemble-meta, source->string, make-int16, code-annotation)
  (print-info): Rework to display my domination of `format', and, more
  seriously, start to integrate the "subsections" of the disassembly into
  the main disassembly text.

* module/system/vm/program.scm (program-bindings-as-lambda-list): Update
  for new bindings format; should be more correct.
2008-10-12 22:49:24 +02:00
Andy Wingo
95b6ad34c3 simplify disassembly annotations a bit
* module/system/vm/disasm.scm (original-value): Simplify a bit to
  normally dispatch on the instruction, only trying code->object at the
  end.
2008-10-11 18:55:44 +02:00
Andy Wingo
2bbe1533e8 truly thread-local vms; don't compile popen.scm
* ice-9/Makefile.am: Don't compile popen.scm, its behaviour at runtime
  is not consistent -- seems to miss some GC references? I suspect a bug
  in the compiler. In any case without popen.scm being compiled,
  continuations.test, r4rs.tes, and r5rs_pitfall.test do pass.

* libguile/threads.h (scm_i_thread):
* libguile/threads.c (thread_mark, guilify_self_2): Add a field for the
  thread's vm. Previously I had this as a fluid, but it seems that newly
  created threads share their fluid values from the creator thread; as
  expected, I guess. In any case one VM should not be active in two
  threads.

* libguile/vm.c (scm_the_vm): Change to access the thread-local vm,
  instead of accessing a fluid.
  (scm_the_vm_fluid): Removed.

* module/system/vm/vm.scm: Removed *the-vm*.
2008-10-11 11:54:12 +02:00
Andy Wingo
0570c3f197 sundries: side effects in interpreted repl, wrong-num-args in vm, self-checks
* libguile/vm-engine.c (vm_error_wrong_num_args): Sync the registers
  before calling scm_wrong_num_args. (The other cases are handled more
  uniformly.)

* libguile/vm.c (vm_heapify_frames_1): Add a FIXME: I don't think we
  should be modifying the stack.
  (scm_vm_save_stack): If stack nulling is enabled, verify the stack here
  before reifying it.

* module/language/scheme/spec.scm (scheme): Use primitive-eval here
  instead of eval, because at the repl we do want to allow evaluations to
  have side effects like setting the current module.
2008-10-09 12:17:51 +02:00
Andy Wingo
1bb6b839ec handle throws to unknown keys in the repl
* module/system/repl/repl.scm (default-catch-handler): Don't rethrow if
  we don't know the key, just print an error.
2008-10-09 11:10:25 +02:00
Andy Wingo
edb1d1d78d remove repl.scm's start-stack definition
* module/system/repl/repl.scm: Now that we actually compile start-stack,
  no need to provide our own definition here.
2008-10-03 15:07:09 +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
fd3585753a compile @ and @@
* libguile/vm-engine.c (vm_run): Add new error case for resolving @ or @@
  references, but there is no such module. Possible if
  module-public-interface returns #f.

* libguile/vm-i-loader.c (link-now): Allow the stack arg to be a sym, as
  before, or a list, indicating an absolute reference. Could be two
  separate instructions, but I'm lazy.

* libguile/vm-i-system.c (late-variable-ref, late-variable-set): As in
  link-now, allow the lazy reference to be a list, for @ and @@.

* module/language/scheme/translate.scm (custom-transformer-table):
  Compile @ and @@, and set! forms for both of them. This will ease the
  non-hygienic pain for exported macros.

* module/system/il/compile.scm (make-glil-var): Translate public and
  private module variable references into glil-module variables.

* module/system/il/ghil.scm (ghil-var-at-module!): New function, resolves
  a variable for @ or @@.

* module/system/il/glil.scm (<glil-module>): Revival of <glil-module>,
  this time with the semantics that it really links to a particular
  module.

* module/system/vm/assemble.scm (<vlink-now>, <vlink-later>): Redefine as
  taking a "key" as the argument, which may be a sym or a list; see the
  notes on link-now for more details.
  (codegen): Compile <glil-module> appropriately. Some duplication here,
  probably could use some cleanup later.
2008-09-30 00:31:17 +02:00
Andy Wingo
a1122f8cba call toplevel variables "toplevel", not "module"
* module/system/il/ghil.scm (ghil-var-for-set!, ghil-var-for-ref!)
  (ghil-var-define!): ghil-var-kind of a toplevel var is now 'toplevel.

* module/system/il/glil.scm: Renamve <glil-module> to <glil-toplevel>.
  Remove the unused `module' field. Remove the unused <glil-late-bound>
  type.

* module/system/il/compile.scm (make-glil-var): s/toplevel/module/

* module/system/vm/assemble.scm (<vlink-later>, <vdefine>): Remove the
  unused `module' parameters from these two types.
  (codegen, dump-object!): Adapt to module/toplevel name changes.
2008-09-29 23:20:10 +02:00
Andy Wingo
48d0006409 remove type' and value' fields from <ghil-var>
* module/system/il/ghil.scm (<ghil-var>): Remove `type' and `value'
  fields, as they were not used.
2008-09-29 22:52:36 +02:00
Andy Wingo
46d2d6f80e allocate variables that are set! on the heap
* module/system/il/ghil.scm (ghil-lookup): So, it turns out this function
  needed to be split into three:
  (ghil-var-is-bound?, ghil-var-for-ref!, ghil-var-for-set!): The
  different facets of ghil-lookup. Amply commented in the source. The
  difference being that we now allocate variables that are set! on the
  heap, so that other continuations see their possibly-modified values.
  (force-heap-allocation!): New helper.

* testsuite/Makefile.am:
* testsuite/t-call-cc.scm: New test, that variables that are set! are
  allocated on the heap, so that subsequent modifications are still
  seen by the continuation. The test was distilled from test 7.3 in
  r5rs_pitfall.test.
2008-09-28 23:09:11 +02:00
Andy Wingo
107139eaad actually compile start-stack to something useful
* ice-9/boot-9.scm (start-stack): Define as a defmacro instead of an acro
  in C. We have a way to delay evaluation of the exp, after all: putting
  it in a thunk is sufficient.

* libguile/debug.h:
* libguile/debug.c (scm_sys_start_stack): Renamed from scm_start_stack,
  and exposed to the user. Takes a thunk instead of an expression +
  environment.
  (scm_m_start_stack): Remove this acro.

* module/language/scheme/translate.scm (custom-transformer-table): Remove
  the start-stack special case.
2008-09-26 12:03:36 +02:00