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

29 commits

Author SHA1 Message Date
Andy Wingo
17aab66e75 Fix bug in eq-constant? propagation in CSE if kf == kt
* module/language/cps/cse.scm (compute-out-edges): Only propagate
constant to successor if successor not kf.
* test-suite/tests/compiler.test ("cse auxiliary definitions"):
("closure conversion"): Refactor.
("constant propagation"): New test.

Fixes #48368.
2021-05-24 11:09:24 +02:00
Leo Prikler
5c6a944173 bug#45131: [PATCH] Compile directly to target language if no joint is found.
This enables the compilation from "manually" written Tree-IL to
bytecode.  See also <https://bugs.gnu.org/45131>.

* system/base/compile.scm (read-and-compile)[(joint #f)]<? eof-object?>:
Join exps using the default joiner for to.
<exp>: Compute compiler for to.
* test-suite/test/compiler.test ("read-and-compile tree-il"): New test.
2021-05-10 10:16:10 +02:00
Andy Wingo
12fa7d115d Fix closure-conversion bug for SCC with all free vars pruned
* module/language/cps/closure-conversion.scm (convert-one): Fix bug when
getting value of SCC whose free variables have been elided.  Thanks to
abcdw for the report!
* test-suite/tests/compiler.test ("cse auxiliary definitions"): Remove
spurious newline.
("closure conversion"): New test.
2021-04-27 14:51:38 +02:00
Andy Wingo
a2f5f9eda4 Fix bug in CSE auxiliary definitions
* module/language/cps/cse.scm (compute-equivalent-subexpressions): When
  CSE sees a definition like `(cons a b)', it will also record an
  "auxiliary definition" for `(car x)', where x is the variable defined
  by the cons, whereby calling `(car x)' can reduce to `a' if there is
  no intervening effect that clobbers the definitions.  However, when
  the successor of the cons is a control-flow join, then any variables
  defined there have multiple definitions.  It's incorrect to add the
  aux definition in that case.
* test-suite/tests/compiler.test ("cse auxiliary definitions"): New
  test.
2019-08-28 10:44:44 +02:00
Mark H Weaver
0e750990dd Add tests for type inferencing for 'nil?' and 'null?' predicates.
These tests come from a fix for <https://bugs.gnu.org/33036>, which was
fixed already in the 2.9.x branch.

* test-suite/tests/compiler.test: Add tests.
2019-05-23 16:59:54 +02:00
Andy Wingo
d0811644f6 Fix flonum/complex type inference.
* module/language/cps/types.scm (define-binary-result!): Arithmetic
  where one argument is a flonum may produce a complex.
* test-suite/tests/compiler.test: Add test.
2017-02-19 12:11:07 +01:00
Andy Wingo
8622344a6b Fix slot allocation for prompts
* module/language/cps/slot-allocation.scm
  (add-prompt-control-flow-edges): Fix to add links from prompt bodies
  to handlers, even in cases where the handler can reach the body but
  the body can't reach the handler.
* test-suite/tests/compiler.test ("prompt body slot allocation"): Add
  test case.
2016-10-11 23:01:38 +02:00
Andy Wingo
0472af4c58 Fix (< 'foo) compilation
* module/language/tree-il/primitives.scm (expand-chained-comparisons):
  Fix (< 'foo) compilation.
* test-suite/tests/compiler.test ("regression tests"): Add test case.
2016-06-21 23:17:25 +02:00
Andy Wingo
f1c0434403 `define!' instruction returns the variable
* doc/ref/vm.texi (Top-Level Environment Instructions): Update
  documentation.
* libguile/_scm.h (SCM_OBJCODE_MINOR_VERSION): Bump, sadly.
* module/system/vm/assembler.scm (*bytecode-minor-version*): Bump.
* libguile/vm-engine.c (define!): Change to store variable in dst slot.
* module/language/tree-il/compile-cps.scm (convert):
* module/language/cps/compile-bytecode.scm (compile-function): Adapt to
  define! change.
* module/language/cps/effects-analysis.scm (current-module): Fix define!
  effects.  Incidentally here was the bug: in Guile 2.2 you can't have
  effects on different object kinds in one instruction, without
  reverting to &unknown-memory-kinds.
* test-suite/tests/compiler.test ("regression tests"): Add a test.
2016-06-21 22:40:31 +02:00
Andy Wingo
d38ca16e2c Add make-vector opcode
* libguile/vm-engine.c (make-vector): New opcode.
* module/language/cps/compile-bytecode.scm (compile-fun):
* module/system/vm/assembler.scm (system): Support the new opcode.
  (*bytecode-minor-version*): Bump.

* libguile/_scm.h (SCM_OBJCODE_MINOR_VERSION): Bump.

* test-suite/tests/compiler.test ("limits"): Add vector test.
2014-04-21 22:47:33 +02:00
Andy Wingo
d4b3a36d42 Operations on 8-bit and 12-bit operands shuffle args into range
* module/language/cps/slot-allocation.scm (allocate-slots): Avoid
  allocating locals in the range [253,255].

* module/system/vm/assembler.scm: List exports explicitly.  For
  operations with limited-range operands, export wrapper assemblers that
  handle shuffling their operands into and out of their range.
  (define-assembler): Get rid of enclosing begin.
  (shuffling-assembler, define-shuffling-assembler): New helpers to
  define shuffling wrapper assemblers.
  (emit-mov*, emit-receive*): New functions.
  (shuffle-up-args): New helper.
  (standard-prelude, opt-prelude, kw-prelude): Call shuffle-up-args
  after finishing.

* test-suite/tests/compiler.test ("limits"): Add test cases.
2014-04-21 22:47:28 +02:00
Andy Wingo
4cbc95f150 Rename objcodes?.{scm,c,h} to loader.{scm,c,h}
* libguile/loader.c:
* libguile/loader.h: Rename from objcodes.[ch].
* module/system/vm/loader.scm: Rename from objcode.scm.

* libguile/Makefile.am:
* libguile/gsubr.c:
* libguile/init.c:
* libguile/procs.c:
* libguile/vm.c:
* module/Makefile.am:
* module/ice-9/eval-string.scm:
* module/language/rtl/spec.scm:
* module/system/base/target.scm:
* module/system/repl/command.scm:
* module/system/repl/common.scm:
* module/system/vm/debug.scm:
* module/system/vm/disassembler.scm:
* module/system/vm/objcode.scm:
* test-suite/tests/compiler.test:
* test-suite/tests/dwarf.test:
* test-suite/tests/rtl-compilation.test:
* test-suite/tests/rtl.test: Adapt.
2013-11-19 21:45:07 +01:00
Andy Wingo
111a305be8 compiler.test fix for rtl compilation
* test-suite/tests/compiler.test ("current-reader"): Fix the way we make
  programs from objcode.
2013-11-05 21:33:00 +01:00
Andy Wingo
d10f7b572c move (test-suite lib) to lower dir; cleans up uninstalled paths.
* check-guile.in:
* test-suite/Makefile.am:
* test-suite/test-suite/lib.scm:

* benchmark-guile.in:
* benchmark-suite/Makefile.am:
* benchmark-suite/benchmark-suite/lib.scm: Lower the lib modules in the
  source tree.  This lets us remove top_srcdir and top_builddir from the
  uninstalled paths.

* test-suite/tests/asm-to-bytecode.test:
* test-suite/tests/brainfuck.test:
* test-suite/tests/compiler.test:
* test-suite/tests/ftw.test:
* test-suite/tests/gc.test:
* test-suite/tests/match.test:
* test-suite/tests/rnrs-libraries.test:
* test-suite/tests/rnrs-test-a.scm:
* test-suite/tests/sxml.match.test: Adapt to not expect that module
  names be prefixed with "test-suite".
2012-04-23 21:46:06 +02:00
Andy Wingo
0083cb5ec4 fix self tail recursion to different case-lambda clauses
http://savannah.gnu.org/bugs/?33362

* module/language/tree-il/compile-glil.scm (flatten-lambda-case): Rename
  from flatten, as it really just takes a particular case.  Instead of
  iteratively compiling lambda cases through `comp', tail-call through
  flatten-lambda-case.  This allows code to see which case it's being
  compiled in.  Take advantage of that to limit the self-tail-call
  optimization to self-calls to the same case -- otherwise we might be
  jumping to a label without having reserved the right number of
  locals.
  (flatten-lambda): Adapt the caller.

* test-suite/tests/compiler.test ("case-lambda"): Add a test.
2011-06-17 17:08:06 +02:00
Andy Wingo
ea9f4f4b15 add call-with-vm; remove thread-vm bits; remove vm-apply; engines settable.
* libguile/vm.h (scm_c_vm_run): Make internal.
* libguile/vm.c (vm_default_engine): New static global variable.
  (make_vm): Set vp->engine based on
  (scm_vm_apply): Remove in favor of call-with-vm.
  (scm_thread_vm, scm_set_thread_vm_x): Remove these, as they did not
  have a well-defined meaning, and were dangerous to call on other
  threads.
  (scm_the_vm): Reinstate previous definition.
  (symbol_to_vm_engine, vm_engine_to_symbol)
  (vm_has_pending_computation): New helpers.
  (scm_vm_engine, scm_set_vm_engine_x, scm_c_set_vm_engine_x): New
  accessors for VM engines.
  (scm_c_set_default_vm_engine_x, scm_set_default_vm_engine_x): New
  setters for the default VM engine.
  (scm_call_with_vm): New function, applies a procedure to arguments in
  a context in which a given VM is current.

* libguile/eval.c (eval, scm_apply): VM dispatch goes through
  scm_call_with_vm.

* test-suite/tests/control.test ("the-vm"):
* module/system/vm/coverage.scm (with-code-coverage): Use call-with-vm.

* module/system/vm/vm.scm: Update exports.

* test-suite/vm/run-vm-tests.scm (run-vm-program):
* test-suite/tests/compiler.test ("current-reader"): Just rely on the
  result of make-program being an applicable.

* test-suite/tests/eval.test ("stack overflow"): Add a note that this
  test does not test what it should.
2010-09-27 21:12:29 +02:00
Andy Wingo
038cb3428f remove vm-version, vm options
* libguile/vm.h (struct scm_vm): Remove "options" member.
* libguile/vm.c (scm_vm_version, scm_vm_option, scm_set_vm_option_x):
  Remove.

* module/system/vm/vm.scm (vm-version, vm-option, set-vm-option!):
  Remove.
  (vms:time, vms:clock): Remove these unused definitions.
  (vm-load): Remove. "Load" should be reserved for things that exist on
  disk, methinks.
2010-09-25 12:16:05 +02:00
Ludovic Courtès
8c65549416 Add tests for `program-sources' (bug #29817).
* test-suite/tests/compiler.test ("program-sources"): New test prefix.
2010-06-06 16:59:01 +02:00
Ludovic Courtès
44ffcae006 Add tests for `procedure-name'.
This is a followup to 22cf27c815 ("fix
procedure naming").

* test-suite/tests/compiler.test ("procedure-name"): New test prefix.
2010-06-06 16:59:01 +02:00
Ludovic Courtès
1ebe6a6368 Document the interaction of the "compilee" with the compiler's current module.
This is a followup to 87c595c757 ("Compile
in a fresh module by default.") and
f65e2b1ec5 ("Honor and confine
expansion-time side-effects to `current-reader'.").

* doc/ref/api-evaluation.texi (Loading): Explain how to change
  `current-reader' in a compiler-friendly way.

* doc/ref/compiler.texi (The Scheme Compiler): Explain use of a fresh
  compilation module and separate `current-reader' fluid.

* test-suite/tests/compiler.test ("current-reader")["with eval-when"]:
  New test.
2009-10-15 21:29:42 +02:00
Ludovic Courtès
f65e2b1ec5 Honor and confine expansion-time side-effects to `current-reader'.
* module/language/scheme/spec.scm (scheme)[#:reader]: Honor the
  compilation environment's `current-reader'.

* module/system/base/compile.scm (*compilation-environment*): New
  fluid.
  (current-compilation-environment): New procedure.
  (make-compilation-module): Provide a fresh `current-reader' fluid.
  (read-and-compile): Set `*compilation-environment*' appropriately.
  (compile): Likewise.

* test-suite/tests/compiler.test (read-and-compile): New.
  ("current-reader"): New test prefix.
2009-09-20 22:29:47 +02:00
Ludovic Courtès
87c595c757 Compile in a fresh module by default.
* module/system/base/compile.scm (make-compilation-module,
  language-default-environment): New procedures.
  (read-and-compile, compile): Have ENV default to
  `(language-default-environment from)'.
  (compile-and-load): Compile in `(current-module)'.

* module/system/repl/common.scm (repl-compile): Explicitly compile in
  the current module so that macro definitions are visible.

* libguile/load.c (kw_env): New variable.
  (do_try_autocompile): Call `compile-file' with `#:env (current-module)'.

* test-suite/tests/compiler.test ("psyntax")["compile uses a fresh module by
  default", "compile-time definitions are isolated"]: New tests.
  ["compile in current module"]: Specify `#:env (current-module)'.
  ["redefinition"]: Adjust.

* test-suite/tests/bytevectors.test (c&e): Explicitly compile in the
  current module so that its imports are visible.
2009-09-20 21:54:41 +02:00
Ludovic Courtès
d785171115 compiler.test: Enforce evaluation order.
* test-suite/tests/compiler.test ("psyntax")["redefinition", "compile in
  current module", "compile in fresh module"]: Use `begin' to enforce
  evaluation order.  Thanks Andy!
2009-08-13 16:16:08 +02:00
Ludovic Courtès
16f451f308 Allow fresh modules to be passed to `compile'.
* module/ice-9/boot-9.scm (module-name): When making MOD non-anonymous,
  bind it in the `(%app modules)' name space.

* test-suite/tests/compiler.test ("psyntax")["compile in current
  module", "compile in fresh module"]: New tests.

* test-suite/tests/modules.test ("foundations")["modules don't remain
  anonymous"]: New test.
2009-08-13 15:57:01 +02:00
Ludovic Courtès
b9434165b6 Allow redefinitions in compiled code as in `(define round round)'.
* module/ice-9/psyntax-pp.scm: Regenerate.

* module/ice-9/psyntax.scm (chi-top)[define-form]: If a same-named
  imported variable exists, take its value instead of `#f'.

* test-suite/tests/compiler.test ("psyntax")["redefinition"]: New tests.
2009-08-13 15:50:37 +02:00
Neil Jerram
53befeb700 Change Guile license to LGPLv3+
(Not quite finished, the following will be done tomorrow.
   module/srfi/*.scm
   module/rnrs/*.scm
   module/scripts/*.scm
   testsuite/*.scm
   guile-readline/*
)
2009-06-17 00:22:09 +01:00
Andy Wingo
68623e8e78 remove compile-time-environment
* module/ice-9/boot-9.scm (guile-user): Move the `compile' autoload to
  the guile-user module. Remove reference to compile-time-environment.

* module/language/scheme/compile-ghil.scm:
* module/language/tree-il/compile-glil.scm:
* module/language/tree-il/optimize.scm:
* module/system/base/compile.scm:
* test-suite/tests/compiler.test: Remove definition of and references to
  compile-time-environment. While I do think that recompilation based on
  a lexical environment can be useful, I think it needs to be implemented
  differently. So for now we've lost nothing if we take it away, as it
  doesn't work with syncase anyway.
2009-05-20 17:41:21 +02: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
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