mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-04-30 11:50:28 +02:00
* 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!
96 lines
2.9 KiB
Scheme
96 lines
2.9 KiB
Scheme
;;; run-vm-tests.scm -- Run Guile-VM's test suite.
|
||
;;;
|
||
;;; Copyright 2005 Ludovic Courtès <ludovic.courtes@laas.fr>
|
||
;;;
|
||
;;;
|
||
;;; This program is free software; you can redistribute it and/or modify
|
||
;;; it under the terms of the GNU General Public License as published by
|
||
;;; the Free Software Foundation; either version 2 of the License, or
|
||
;;; (at your option) any later version.
|
||
;;;
|
||
;;; This program is distributed in the hope that it will be useful,
|
||
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
;;; GNU General Public License for more details.
|
||
;;;
|
||
;;; You should have received a copy of the GNU General Public License
|
||
;;; along with this program; if not, write to the Free Software
|
||
;;; Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||
|
||
|
||
(use-modules (system vm vm)
|
||
(system vm disasm)
|
||
(system base compile)
|
||
(system base language)
|
||
(language scheme spec)
|
||
(language objcode spec)
|
||
(srfi srfi-1)
|
||
(ice-9 r5rs))
|
||
|
||
|
||
(define (fetch-sexp-from-file file)
|
||
(with-input-from-file file
|
||
(lambda ()
|
||
(let loop ((sexp (read))
|
||
(result '()))
|
||
(if (eof-object? sexp)
|
||
(cons 'begin (reverse result))
|
||
(loop (read) (cons sexp result)))))))
|
||
|
||
(define (compile-to-objcode sexp)
|
||
"Compile the expression @var{sexp} into a VM program and return it."
|
||
(compile sexp #:from scheme #:to objcode))
|
||
|
||
(define (run-vm-program objcode)
|
||
"Run VM program contained into @var{objcode}."
|
||
(vm-load (the-vm) objcode))
|
||
|
||
(define (compile/run-test-from-file file)
|
||
"Run test from source file @var{file} and return a value indicating whether
|
||
it succeeded."
|
||
(run-vm-program (compile-to-objcode (fetch-sexp-from-file file))))
|
||
|
||
|
||
(define-macro (watch-proc proc-name str)
|
||
`(let ((orig-proc ,proc-name))
|
||
(set! ,proc-name
|
||
(lambda args
|
||
(format #t (string-append ,str "... "))
|
||
(apply orig-proc args)))))
|
||
|
||
(watch-proc fetch-sexp-from-file "reading")
|
||
(watch-proc compile-to-objcode "compiling")
|
||
(watch-proc run-vm-program "running")
|
||
|
||
|
||
;; The program.
|
||
|
||
(define (run-vm-tests files)
|
||
"For each file listed in @var{files}, load it and run it through both the
|
||
interpreter and the VM (after having it compiled). Both results must be
|
||
equal in the sense of @var{equal?}."
|
||
(let* ((res (map (lambda (file)
|
||
(format #t "running `~a'... " file)
|
||
(if (catch #t
|
||
(lambda ()
|
||
(equal? (compile/run-test-from-file file)
|
||
(eval (fetch-sexp-from-file file)
|
||
(interaction-environment))))
|
||
(lambda (key . args)
|
||
(format #t "[~a/~a] " key args)
|
||
#f))
|
||
(format #t "ok~%")
|
||
(begin (format #t "FAILED~%") #f)))
|
||
files))
|
||
(total (length files))
|
||
(failed (length (filter not res))))
|
||
|
||
(if (= 0 failed)
|
||
(begin
|
||
(format #t "~%All ~a tests passed~%" total)
|
||
(exit 0))
|
||
(begin
|
||
(format #t "~%~a tests failed out of ~a~%"
|
||
failed total)
|
||
(exit failed)))))
|
||
|