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

63 commits

Author SHA1 Message Date
Andy Wingo
594d9d4c48 be smarter about allocating local variables, reusing slots if possible
* module/language/Makefile.am: OK, we can compile compile-ghil.scm now,
  thankfully.

* module/language/ecmascript/compile-ghil.scm (ormatch): New macro, a
  wrapper around pmatch to avoid some of the more egregious
  non-tail recursiveness.
  (comp): Use ormatch.

* module/language/ghil.scm (unparse-ghil): The body of bind and mv-bind
  is a single expression, not a list of expressions.

* module/language/ghil/compile-glil.scm (codegen): Be more clever when
  allocating "local" variables -- if a variable goes out of scope, its
  index can be re-used later.

* module/language/glil.scm (parse-glil, unparse-ghil): The "rest" of a
  mv-bind is a flag, not a list. The "ra" of an mv-call is a label, not a
  GLIL expression.

* module/language/objcode/spec.scm (collapse-locals, decompile-value):
  When decompiling a value, process the bindings list differently.
  Comments in the code.

* module/language/scheme/compile-ghil.scm (define-scheme-translator): Fix
  the generated error procedure.
  (let): Re-indent.
  (letrec): Re-indent.

* module/system/base/syntax.scm (record-case): If the body of a clause is
  null, fill it with the unspecified value.
2009-02-21 20:28:29 +01:00
Ludovic Courtès
b912a1cd6b Add `load-unsigned-integer' instruction.
* libguile/vm-i-loader.c (load_unsigned_integer): New loader.

* module/language/assembly.scm (byte-length): Handle
  `load-unsigned-integer'.

* module/language/assembly/compile-bytecode.scm (write-bytecode):
  Likewise.

* module/language/glil/compile-assembly.scm (dump-object): Emit a
  `load-unsigned-integer' instruction for positive integers.  This fixes
  loading of integers greater than 2^31 - 1.

* testsuite/Makefile.am (vm_test_files): Add `t-literal-integers.scm'.

* doc/ref/vm.texi (Loading Instructions): Add `load-unsigned-integer'.
2009-02-18 00:54:05 +01:00
Andy Wingo
3928db0087 lengths written out in native endianness
* module/language/assembly/compile-bytecode.scm (write-bytecode): Write
  out the lengths that are mapped to struct scm_objcode using native
  endianness.
2009-02-17 23:32:39 +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
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
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
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