mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-19 03:00:25 +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!
158 lines
5.1 KiB
Scheme
158 lines
5.1 KiB
Scheme
;;; Guile Low Intermediate Language
|
||
|
||
;; Copyright (C) 2001 Free Software Foundation, Inc.
|
||
|
||
;; 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, 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; see the file COPYING. If not, write to
|
||
;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||
;; Boston, MA 02111-1307, USA.
|
||
|
||
;;; Code:
|
||
|
||
(define-module (system il glil)
|
||
#:use-module (system base syntax)
|
||
#:use-module (system base pmatch)
|
||
#:export
|
||
(<glil-vars> make-glil-vars
|
||
glil-vars-nargs glil-vars-nrest glil-vars-nlocs glil-vars-nexts
|
||
|
||
<glil-asm> make-glil-asm glil-asm?
|
||
glil-asm-vars glil-asm-meta glil-asm-body
|
||
|
||
<glil-bind> make-glil-bind glil-bind?
|
||
glil-bind-vars
|
||
|
||
<glil-mv-bind> make-glil-mv-bind glil-mv-bind?
|
||
glil-mv-bind-vars glil-mv-bind-rest
|
||
|
||
<glil-unbind> make-glil-unbind glil-unbind?
|
||
|
||
<glil-source> make-glil-source glil-source?
|
||
glil-source-loc
|
||
|
||
<glil-void> make-glil-void glil-void?
|
||
|
||
<glil-const> make-glil-const glil-const?
|
||
glil-const-obj
|
||
|
||
<glil-argument> make-glil-argument glil-argument?
|
||
glil-argument-op glil-argument-index
|
||
|
||
<glil-local> make-glil-local glil-local?
|
||
glil-local-op glil-local-index
|
||
|
||
<glil-external> make-glil-external glil-external?
|
||
glil-external-op glil-external-depth glil-external-index
|
||
|
||
<glil-toplevel> make-glil-toplevel glil-toplevel?
|
||
glil-toplevel-op glil-toplevel-name
|
||
|
||
<glil-module> make-glil-module glil-module?
|
||
glil-module-op glil-module-mod glil-module-name glil-module-public?
|
||
|
||
<glil-label> make-glil-label glil-label?
|
||
glil-label-label
|
||
|
||
<glil-branch> make-glil-branch glil-branch?
|
||
glil-branch-inst glil-branch-label
|
||
|
||
<glil-call> make-glil-call glil-call?
|
||
glil-call-inst glil-call-nargs
|
||
|
||
<glil-mv-call> make-glil-mv-call glil-mv-call?
|
||
glil-mv-call-nargs glil-mv-call-ra
|
||
|
||
parse-glil unparse-glil))
|
||
|
||
(define-record <glil-vars> nargs nrest nlocs nexts)
|
||
|
||
(define (print-glil x port)
|
||
(format port "#<glil ~s>" (unparse-glil x)))
|
||
|
||
(define-type (<glil> #:printer print-glil)
|
||
;; Meta operations
|
||
(<glil-asm> vars meta body)
|
||
(<glil-bind> vars)
|
||
(<glil-mv-bind> vars rest)
|
||
(<glil-unbind>)
|
||
(<glil-source> loc)
|
||
;; Objects
|
||
(<glil-void>)
|
||
(<glil-const> obj)
|
||
;; Variables
|
||
(<glil-argument> op index)
|
||
(<glil-local> op index)
|
||
(<glil-external> op depth index)
|
||
(<glil-toplevel> op name)
|
||
(<glil-module> op mod name public?)
|
||
;; Controls
|
||
(<glil-label> label)
|
||
(<glil-branch> inst label)
|
||
(<glil-call> inst nargs)
|
||
(<glil-mv-call> nargs ra))
|
||
|
||
|
||
(define (parse-glil x)
|
||
(pmatch x
|
||
((asm (,nargs ,nrest ,nlocs ,next) ,meta . ,body)
|
||
(make-glil-asm (make-glil-vars nargs nrest nlocs next)
|
||
meta (map parse-glil body)))
|
||
((bind . ,vars) (make-glil-bind vars))
|
||
((mv-bind ,vars . ,rest) (make-glil-mv-bind vars (map parse-glil rest)))
|
||
((unbind) (make-glil-unbind))
|
||
((source ,loc) (make-glil-source loc))
|
||
((void) (make-glil-void))
|
||
((const ,obj) (make-glil-const obj))
|
||
((argument ,op ,index) (make-glil-argument op index))
|
||
((local ,op ,index) (make-glil-local op index))
|
||
((external ,op ,depth ,index) (make-glil-external op depth index))
|
||
((toplevel ,op ,name) (make-glil-toplevel op name))
|
||
((module public ,op ,mod ,name) (make-glil-module op mod name #t))
|
||
((module private ,op ,mod ,name) (make-glil-module op mod name #f))
|
||
((label ,label) (make-label ,label))
|
||
((branch ,inst ,label) (make-glil-branch inst label))
|
||
((call ,inst ,nargs) (make-glil-call inst nargs))
|
||
((mv-call ,nargs ,ra) (make-glil-mv-call nargs ra))
|
||
(else (error "invalid glil" x))))
|
||
|
||
(define (unparse-glil glil)
|
||
(record-case glil
|
||
;; meta
|
||
((<glil-asm> vars meta body)
|
||
`(asm (,(glil-vars-nargs vars) ,(glil-vars-nrest vars)
|
||
,(glil-vars-nlocs vars) ,(glil-vars-nexts vars))
|
||
,meta
|
||
,@(map unparse-glil body)))
|
||
((<glil-bind> vars) `(bind ,@vars))
|
||
((<glil-mv-bind> vars rest) `(mv-bind ,vars ,@rest))
|
||
((<glil-unbind>) `(unbind))
|
||
((<glil-source> loc) `(source ,loc))
|
||
;; constants
|
||
((<glil-void>) `(void))
|
||
((<glil-const> obj) `(const ,obj))
|
||
;; variables
|
||
((<glil-argument> op index)
|
||
`(argument ,op ,index))
|
||
((<glil-local> op index)
|
||
`(local ,op ,index))
|
||
((<glil-external> op depth index)
|
||
`(external ,op ,depth ,index))
|
||
((<glil-toplevel> op name)
|
||
`(toplevel ,op ,name))
|
||
((<glil-module> op mod name public?)
|
||
`(module ,(if public? 'public 'private) ,op ,mod ,name))
|
||
;; controls
|
||
((<glil-label> label) (label ,label))
|
||
((<glil-branch> inst label) `(branch ,inst ,label))
|
||
((<glil-call> inst nargs) `(call ,inst ,nargs))
|
||
((<glil-mv-call> nargs ra) `(mv-call ,nargs ,(unparse-glil ra)))))
|