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

4452 commits

Author SHA1 Message Date
Andy Wingo
e94ecc68c2 Name anonymous let- or letrec-bound procedures
* module/language/scheme/compile-ghil.scm (let, letrec): Give names to
  procedures of the form (let ((foo (lambda ....)))).
2009-02-02 23:36:14 +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
Andy Wingo
8403b9f59b fix the disassembler for load-string, load-symbol et al
* module/language/assembly/decompile-bytecode.scm (decode-bytecode): Fix
  decoding of lengths in loader instructions.
2009-02-01 11:32:07 +01:00
Andy Wingo
ac47d5f639 avoid 8 words of allocation per lambda, whoooo
* libguile/objcodes.c (scm_bytecode_to_objcode): Check that the length of
  the vector matches the length embedded in the bytecode.

* libguile/programs.c (scm_program_meta): Call through to
  scm_objcode_meta, instead of looking in the object table. Avoids
  consing up a program+objcode slice for the meta until the meta is
  actually called.

* libguile/vm-i-loader.c (load-program): Step past the metadata too.

* module/language/glil/compile-assembly.scm (make-meta): Just return the
  load-program form, or #f.
  (assoc-ref-or-acons, object-index-and-alist, make-object-table): Don't
  write the meta into the object table.
  (glil->assembly): Instead write the meta into the load-program form.
2009-02-01 10:50:45 +01:00
Andy Wingo
1f1ec13b5c add code for writing out metadata to the end of a program
* libguile/objcodes.c (make_objcode_by_mmap, scm_c_make_objcode_slice):
  Verify the lengths with the meta-length.
  (scm_objcode_meta): New procedure, for getting at the meta-info of an
  objcode.
  (scm_objcode_to_bytecode):
  (scm_write_objcode): Write bytecode with the metadata too.

* module/system/vm/objcode.scm: Export object-meta.

* module/language/assembly.scm (byte-length):
* module/language/assembly/compile-bytecode.scm (write-bytecode):
* module/language/assembly/decompile-bytecode.scm (decode-load-program):
* module/language/assembly/disassemble.scm (disassemble-load-program):
* module/language/glil/compile-assembly.scm (glil->assembly):
* test-suite/tests/asm-to-bytecode.test ("compiler"): Change to
  load-program format to have meta-or-#f instead of meta-length, so that
  we can serialize the meta as objcode without a load-program byte. Add a
  test for writing out the meta.
2009-02-01 10:15:00 +01:00
Andy Wingo
9aeaabdc45 add metalen field to bytecode serialization
* libguile/objcodes.h (struct scm_objcode): Add a new field, metalen, in
  preparation for embedding metadata within a program.
  (SCM_OBJCODE_META_LEN, SCM_OBJCODE_TOTAL_LEN): New defines.

* libguile/vm.c (really_make_boot_program):
* module/language/assembly.scm (*program-header-len*, byte-length):
* module/language/assembly/compile-bytecode.scm (write-bytecode):
* module/language/assembly/decompile-bytecode.scm (decode-load-program):
* module/language/assembly/disassemble.scm (disassemble-load-program):
* module/language/glil/compile-assembly.scm (glil->assembly):
* test-suite/tests/asm-to-bytecode.test ("compiler"): Update for metalen
  addition.
2009-02-01 09:19:24 +01:00
Andy Wingo
9bb8012dd6 remove conv.scm, disasm.scm; objcode->bytecode rename
* module/system/vm/Makefile.am:
* module/system/vm/conv.scm:
* module/system/vm/disasm.scm: Remove these modules, as their
  functionality is now in (language ...).

* libguile/objcodes.h:
* libguile/objcodes.c:
* module/system/vm/objcode.scm: Rename objcode->u8vector to
  objcode->bytecode.

* module/system/vm/frame.scm:
* module/language/bytecode/spec.scm: Fix for objcode->bytecode.

* scripts/disassemble:
* testsuite/run-vm-tests.scm: Fix for (system vm disasm) removal.

* module/system/repl/command.scm: Use the right disassembler.
2009-01-30 14:36:49 +01:00
Andy Wingo
d7236899f5 add disassembler that fits in with old compiler tower
* module/language/assembly/Makefile.am:
* module/language/assembly/disassemble.scm: Add a disassembler, based on
  the old one but fitting in with the decompiler tower.

* module/language/objcode/spec.scm (decompile-value): When decompiling
  programs, shove all the metadata that we know about into the "env".

* module/system/base/compile.scm (decompile-fold, decompile): Return the
  env from `decompile' as a second value. Not sure if `compile' should do
  this too.
2009-01-30 14:12:57 +01:00
Andy Wingo
7b107cceb9 add decompilers that can take us back to assembly
* module/language/assembly/Makefile.am:
* module/language/assembly/spec.scm:
* module/language/assembly/decompile-bytecode.scm: Add a bytecode
  decompiler. Neat!

* module/language/bytecode/spec.scm (decompile-objcode):
* module/language/objcode/spec.scm (decompile-value): Add some
  "decompilers" here too.

* module/system/base/compile.scm (current-language): Since we can refer
  to languages by name, do so here -- removes the previous
  anti-circularity hack.
  (compile-file, compile): Refer to target languages by name.
  (decompile): New public function. Neat!

* module/system/base/language.scm (lookup-decompilation-order): Fix so we
  look for decompilers with the high-level language definition.
2009-01-30 12:59:29 +01:00
Andy Wingo
5d6fb8bbeb allow specification of languages by name; add decompilers to languages
* module/system/base/language.scm (lookup-decompilation-order): New
  function, like its compiling cousin, but backwards.
  (compute-translation-order): Rework so that languages can be specified
  either by name or by identity. Return a list of language - procedure
  pairs, without the "to" language in the list, instead of a list of
  languages.
  (invalidate-compilation-cache!): Invalidate the decompilation cache
  too.
  (<language>): Add a decompiler field.

* module/system/base/compile.scm (compile-passes): Much simpler now that
  lookup-compilation-order gives us the procedures directly.

* module/language/*/spec.scm: Specify compilers by name, so that we can
  avoid unnecessary module loads, and so that when we specify
  decompilers, we can avoid cycles.
2009-01-30 11:41:02 +01:00
Andy Wingo
4b31848284 remove glil->objcode path in favor of passing through assembly; refactorings.
* module/language/assembly.scm: Refactor a bit; remove the name "code"
  from the API, as it's too generic, and replace with "assembly".

* module/language/assembly/compile-bytecode.scm: Get byte lengths via,
  well, byte-length.

* module/language/glil/Makefile.am:
* module/language/glil/spec.scm:
* module/language/glil/compile-objcode.scm: Remove compile-objcode, as we
  just go through bytecode now.

* module/language/glil/compile-assembly.scm (glil->assembly)
  (dump-object): s/object->code/object->assembly/.
2009-01-30 11:02:01 +01:00
Andy Wingo
6f78702819 add new language between assembly and objcode: bytecode
* module/language/bytecode/Makefile.am:
* module/language/bytecode/spec.scm: Add another language to the stack,
  bytecode. Bytecode is the u8vector form of object code..

* configure.in:
* module/language/Makefile.am:
* module/language/assembly/Makefile.am:
* test-suite/tests/asm-to-bytecode.test:
* module/language/assembly/spec.scm:
* module/language/assembly/compile-bytecode.scm: Update to include the
  new pass.
2009-01-30 10:20:08 +01:00
Andy Wingo
bd02af8acf remove GPKG.def files
* module/language/ghil/GPKG.def:
* module/language/r5rs/GPKG.def: Reove these, they aren't used any more.
2009-01-29 21:12:00 +01:00
Andy Wingo
53e28ed9b2 static opcodes; refactor program/objcode division; use new assembly pipeline
* gdbinit: Untested attempts to get the stack fondling macros to deal
  with the new program representation.

* libguile/frames.c (scm_vm_frame_arguments, scm_vm_frame_source)
  (scm_vm_frame_local_ref, scm_vm_frame_local_set_x): SCM_PROGRAM_DATA is
  a struct scm_objcode*.

* libguile/instructions.h:
* libguile/instructions.c: Hide the instruction table and the struct
  scm_instruction structure; all access to instructions now goes through
  procedures. This is because instructions are no longer in a packed
  array indexed by opcode. Also, declare a mask that all instructions
  should fit in.

* libguile/objcodes.h:
* libguile/objcodes.c: Rewrite so that object code directly maps its
  arity and length from its bytecode. This makes it unnecessary to keep
  this information in programs, allowing programs to be simple conses
  between the code (objcodes) and data (the object table and the closure
  variables).

* libguile/programs.c (scm_make_program): Rework so that make-program
  takes objcode, an object table, and externals as arguments. It's much
  clearer this way, and we avoid malloc().

* libguile/stacks.c (is_vm_bootstrap_frame): Update for program/objcode
  changes.

* libguile/vm-engine.c (vm_run): Initialize the jump table on the first
  run, with the opcodes declared in the instruction sources, and with bad
  instructions raising an error instead of wandering off into the
  Unknown.

* libguile/vm-engine.h (FETCH_LENGTH): Always represent lengths as 3
  bytes. The old code was too error-prone.
  (NEXT_JUMP): Mask the instruction with SCM_VM_INSTRUCTION_MASK.
  (NEW_FRAME): Update for program/objcode changes.

* libguile/vm-expand.h (VM_DEFINE_FUNCTION, VM_DEFINE_INSTRUCTION)
  (VM_DEFINE_LOADER): Update so that we explicitly specify opcodes, so
  that we have a stable bytecode API.

* libguile/vm-i-loader.c: Update license to LGPLv2+. Explicitly declare
  opcodes.
  (load-integer): Use an int instead of a long as the accumulator; still
  need to revisit this code at some point, I think.
  (load-program): Simplify, thankfully!! Just creates the objcode slice
  and rolls with it.

* libguile/vm-i-scheme.c: Number the opcodes explicitly.

* libguile/vm-i-system.c: Update license to LGPLv2+. Explicitly declare
  opcodes.
  (make-closure): Update for new program API.

* libguile/vm.c (vm_make_boot_program): Update for new program/objcode
  API. Still a bit ugly.
  (scm_load_compiled_with_vm): Update for new program/objcode API.

* module/language/assembly.scm (byte-length): Fix byte-length calculation
  for loaders, and load-program.
  (code-pack, code-unpack): Start to move things from (system vm conv)
  here.
  (object->code, code->object): More things from conv.scm.

* module/language/glil.scm (<glil-program>): Add a new field,
  closure-level.
  (make-glil-program, compute-closure-level): Calculate the "closure
  level" when making a glil program. This is the maximum depth of
  external binding refs in this closure.
  (unparse-glil): Fix label serialization.

* module/language/glil/compile-assembly.scm (make-meta): Prepend #f for
  the meta's object table, though maybe in the future we can avoid
  creating assembly in the first place.
  (assoc-ref-or-acons, object-index-and-alist): GRRR! Caught again by the
  different sets of arguments to assoc and assoc-ref!
  (glil->assembly): Attempt to make the <glil-program> case more
  readable, and fix the bugs. Sorry I don't know how to comment this
  change any more than this.
  (glil->assembly): For <glil-module> serialize the whole key, not just
  the name.
  (dump-object): subprogram-code is already a list. Serialize integers as
  strings, not u8vectors. Fix the order of lists and vectors.

* module/language/glil/spec.scm (glil): Switch orders, so we prefer glil
  -> assembly -> objcode. Actually glil->objcode doesn't work any more,
  needs to be removed I think.

* module/language/objcode/spec.scm (objcode->value):
  s/objcode->program/make-program/.

* module/language/scheme/inline.scm: Add acons inline.

* module/system/vm/conv.scm (make-byte-decoder): Skip the first 8 bytes,
  they are header. Handle subprograms properly. Still needs help though.
  (decode-length): Lengths are always 3 bytes now.

* module/system/vm/disasm.scm: Superficial changes to keep things
  working. I'd like to fix this better in the future.

* module/system/vm/frame.scm (bootstrap-frame?): Fixes for
  program-bytecode.

* module/system/vm/program.scm: Export make-program. It's program-objcode
  now, no more program-bytecode.

* module/system/vm/vm.scm (vm-load): Use make-program.

* test-suite/tests/asm-to-bytecode.test: New test, very minimal.

* module/system/vm/objcode.scm: Export word-size, byte-order, and
  write-objcode.
2009-01-29 21:12:00 +01:00
Andy Wingo
f1d7723bb3 add assembly intermediate language
* configure.in:
* module/language/Makefile.am:
* module/language/assembly/Makefile.am: Automakery.

* module/language/assembly.scm:
* module/language/assembly/spec.scm: Add a new language, which is oddly
  even lower than GLIL. I got tired of GLIL's terrible
  compile-objcode.scm, and wanted a cleaner intermediate format.

* module/language/glil/compile-assembly.scm: A purely-functional
  assembler, that produces "assembly". Will document later.

* module/language/glil/spec.scm: Declare the compiler to assembly.
2009-01-19 00:06:49 +01:00
Andy Wingo
2fda024221 move module and meta inside programs' object tables
* libguile/programs.h (struct scm_program): Remove the module and meta
  fields.

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

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

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

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

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

* module/language/glil/compile-objcode.scm (codegen): Clarify.
2009-01-17 16:42:53 +01:00
Andy Wingo
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