mescc: Use records for Guile: preparation.
* module/language/c99/info.mes: New file. * module/mes/M1.mes: Use it. * scripts/mescc.mes: Use it. * module/language/c99/compiler.mes: Use it. (<info>, <types>, <constants>, <functions>, <globals>, <locals>, <function>, <text>, <break>, <continue>, make, info?, .info, .types, .constants, .functions, .globals, .locals, .function, .text, .break, .continue): Remove. * module/language/c99/info.scm: New file. * module/language/c99/compiler.scm: Use it. * guile/mescc.scm: Use it. * module/mes/M1.scm: Use it.
This commit is contained in:
parent
81f3fb0ecf
commit
52b09c5f17
|
@ -35,6 +35,7 @@ GUILE='~/src/guile-1.8/build/pre-inst-guile --debug -q' guile/mescc.scm
|
|||
!#
|
||||
|
||||
(define-module (mescc)
|
||||
#:use-module (language c99 info)
|
||||
#:use-module (language c99 compiler)
|
||||
#:use-module (mes elf)
|
||||
#:use-module (mes M1)
|
||||
|
|
3
make.scm
3
make.scm
|
@ -14,6 +14,7 @@ exec ${GUILE-guile} --no-auto-compile -L . -L guile -C . -C guile -s "$0" ${1+"$
|
|||
"guix/records.scm"
|
||||
"guix/shell-utils.scm"
|
||||
"language/c99/compiler.scm"
|
||||
"language/c99/info.scm"
|
||||
"mes/as-i386.scm"
|
||||
"mes/as.scm"
|
||||
"mes/bytevectors.scm"
|
||||
|
@ -371,6 +372,8 @@ exec ${GUILE-guile} --no-auto-compile -L . -L guile -C . -C guile -s "$0" ${1+"$
|
|||
((install-dir #:dir (string-append %module-dir)) f))
|
||||
'("module/language/c99/compiler.mes"
|
||||
"module/language/c99/compiler.scm"
|
||||
"module/language/c99/info.mes"
|
||||
"module/language/c99/info.scm"
|
||||
"module/language/paren.mes"
|
||||
"module/mes/M1.mes"
|
||||
"module/mes/M1.scm"
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
(guile-2)
|
||||
(guile)
|
||||
(mes
|
||||
(mes-use-module (srfi srfi-1))
|
||||
(mes-use-module (srfi srfi-26))
|
||||
(mes-use-module (mes pmatch))
|
||||
(mes-use-module (nyacc lang c99 parser))
|
||||
|
@ -36,7 +37,8 @@
|
|||
(mes-use-module (mes as))
|
||||
(mes-use-module (mes as-i386))
|
||||
(mes-use-module (mes M1))
|
||||
(mes-use-module (mes optargs))))
|
||||
(mes-use-module (mes optargs))
|
||||
(mes-use-module (language c99 info))))
|
||||
|
||||
(define (logf port string . rest)
|
||||
(apply format (cons* port string rest))
|
||||
|
@ -135,69 +137,6 @@
|
|||
((fctn-defn _ (ptr-declr (pointer (pointer)) (ftn-declr (ident ,name) _)) (compd-stmt (block-item-list . ,statements))) statements)
|
||||
(_ (error ".statements: unsupported: " o))))
|
||||
|
||||
(define <info> '<info>)
|
||||
(define <types> '<types>)
|
||||
(define <constants> '<constants>)
|
||||
(define <functions> '<functions>)
|
||||
(define <globals> '<globals>)
|
||||
(define <locals> '<locals>)
|
||||
(define <function> '<function>)
|
||||
(define <text> '<text>)
|
||||
(define <break> '<break>)
|
||||
(define <continue> '<continue>)
|
||||
|
||||
(define* (make o #:key (types '()) (constants '()) (functions '()) (globals '()) (locals '()) (function #f) (text '()) (break '()) (continue '()))
|
||||
(pmatch o
|
||||
(<info> (list <info>
|
||||
(cons <types> types)
|
||||
(cons <constants> constants)
|
||||
(cons <functions> functions)
|
||||
(cons <globals> globals)
|
||||
(cons <locals> locals)
|
||||
(cons <function> function)
|
||||
(cons <text> text)
|
||||
(cons <break> break)
|
||||
(cons <continue> continue)))))
|
||||
|
||||
(define (.types o)
|
||||
(pmatch o
|
||||
((<info> . ,alist) (assq-ref alist <types>))))
|
||||
|
||||
(define (.constants o)
|
||||
(pmatch o
|
||||
((<info> . ,alist) (assq-ref alist <constants>))))
|
||||
|
||||
(define (.functions o)
|
||||
(pmatch o
|
||||
((<info> . ,alist) (assq-ref alist <functions>))))
|
||||
|
||||
(define (.globals o)
|
||||
(pmatch o
|
||||
((<info> . ,alist) (assq-ref alist <globals>))))
|
||||
|
||||
(define (.locals o)
|
||||
(pmatch o
|
||||
((<info> . ,alist) (assq-ref alist <locals>))))
|
||||
|
||||
(define (.function o)
|
||||
(pmatch o
|
||||
((<info> . ,alist) (assq-ref alist <function>))))
|
||||
|
||||
(define (.text o)
|
||||
(pmatch o
|
||||
((<info> . ,alist) (assq-ref alist <text>))))
|
||||
|
||||
(define (.break o)
|
||||
(pmatch o
|
||||
((<info> . ,alist) (assq-ref alist <break>))))
|
||||
|
||||
(define (.continue o)
|
||||
(pmatch o
|
||||
((<info> . ,alist) (assq-ref alist <continue>))))
|
||||
|
||||
(define (info? o)
|
||||
(and (pair? o) (eq? (car o) <info>)))
|
||||
|
||||
(define (clone o . rest)
|
||||
(cond ((info? o)
|
||||
(let ((types (.types o))
|
||||
|
@ -222,6 +161,9 @@
|
|||
(continue continue))
|
||||
(make <info> #:types types #:constants constants #:functions functions #:globals globals #:locals locals #:function function #:text text #:break break #:continue continue))))))
|
||||
|
||||
(define (append-text info text)
|
||||
(clone info #:text (append (.text info) text)))
|
||||
|
||||
(define (push-global globals)
|
||||
(lambda (o)
|
||||
(list (i386:push-label-mem `(#:address ,o)))))
|
||||
|
@ -863,9 +805,6 @@
|
|||
(info ((expr->base info) b)))
|
||||
(append-text info (wrap-as c)))))
|
||||
|
||||
(define (append-text info text)
|
||||
(clone info #:text (append (.text info) text)))
|
||||
|
||||
(define (wrap-as o . annotation)
|
||||
`(,@annotation ,o))
|
||||
|
||||
|
|
|
@ -35,11 +35,13 @@
|
|||
#:use-module (mes as-i386)
|
||||
#:use-module (mes elf)
|
||||
#:use-module (mes M1)
|
||||
#:use-module (language c99 info)
|
||||
#:export (c99-ast->info
|
||||
c99-input->ast
|
||||
c99-input->elf
|
||||
c99-input->info
|
||||
c99-input->object
|
||||
clone
|
||||
info->object))
|
||||
|
||||
(cond-expand
|
||||
|
|
96
module/language/c99/info.mes
Normal file
96
module/language/c99/info.mes
Normal file
|
@ -0,0 +1,96 @@
|
|||
;;; -*-scheme-*-
|
||||
|
||||
;;; Mes --- Maxwell Equations of Software
|
||||
;;; Copyright © 2016,2017 Jan Nieuwenhuizen <janneke@gnu.org>
|
||||
;;;
|
||||
;;; This file is part of Mes.
|
||||
;;;
|
||||
;;; Mes 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 3 of the License, or (at
|
||||
;;; your option) any later version.
|
||||
;;;
|
||||
;;; Mes 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 Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
;;; Commentary:
|
||||
|
||||
;;; info.mes defines a record-interface to simplistic list data
|
||||
;;; structures.
|
||||
|
||||
;;; Code:
|
||||
|
||||
(cond-expand
|
||||
(guile-2)
|
||||
(guile)
|
||||
(mes
|
||||
(mes-use-module (mes optargs))
|
||||
(mes-use-module (mes pmatch))))
|
||||
|
||||
(define <info> '<info>)
|
||||
(define <types> '<types>)
|
||||
(define <constants> '<constants>)
|
||||
(define <functions> '<functions>)
|
||||
(define <globals> '<globals>)
|
||||
(define <locals> '<locals>)
|
||||
(define <function> '<function>)
|
||||
(define <text> '<text>)
|
||||
(define <break> '<break>)
|
||||
(define <continue> '<continue>)
|
||||
|
||||
(define (.types o)
|
||||
(pmatch o
|
||||
((<info> . ,alist) (assq-ref alist <types>))))
|
||||
|
||||
(define (.constants o)
|
||||
(pmatch o
|
||||
((<info> . ,alist) (assq-ref alist <constants>))))
|
||||
|
||||
(define (.functions o)
|
||||
(pmatch o
|
||||
((<info> . ,alist) (assq-ref alist <functions>))))
|
||||
|
||||
(define (.globals o)
|
||||
(pmatch o
|
||||
((<info> . ,alist) (assq-ref alist <globals>))))
|
||||
|
||||
(define (.locals o)
|
||||
(pmatch o
|
||||
((<info> . ,alist) (assq-ref alist <locals>))))
|
||||
|
||||
(define (.function o)
|
||||
(pmatch o
|
||||
((<info> . ,alist) (assq-ref alist <function>))))
|
||||
|
||||
(define (.text o)
|
||||
(pmatch o
|
||||
((<info> . ,alist) (assq-ref alist <text>))))
|
||||
|
||||
(define (.break o)
|
||||
(pmatch o
|
||||
((<info> . ,alist) (assq-ref alist <break>))))
|
||||
|
||||
(define (.continue o)
|
||||
(pmatch o
|
||||
((<info> . ,alist) (assq-ref alist <continue>))))
|
||||
|
||||
(define (info? o)
|
||||
(and (pair? o) (eq? (car o) <info>)))
|
||||
|
||||
(define* (make o #:key (types '()) (constants '()) (functions '()) (globals '()) (locals '()) (function #f) (text '()) (break '()) (continue '()))
|
||||
(pmatch o
|
||||
(<info> (list <info>
|
||||
(cons <types> types)
|
||||
(cons <constants> constants)
|
||||
(cons <functions> functions)
|
||||
(cons <globals> globals)
|
||||
(cons <locals> locals)
|
||||
(cons <function> function)
|
||||
(cons <text> text)
|
||||
(cons <break> break)
|
||||
(cons <continue> continue)))))
|
122
module/language/c99/info.scm
Normal file
122
module/language/c99/info.scm
Normal file
|
@ -0,0 +1,122 @@
|
|||
;;; -*-scheme-*-
|
||||
|
||||
;;; Mes --- Maxwell Equations of Software
|
||||
;;; Copyright © 2016,2017 Jan Nieuwenhuizen <janneke@gnu.org>
|
||||
;;;
|
||||
;;; This file is part of Mes.
|
||||
;;;
|
||||
;;; Mes 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 3 of the License, or (at
|
||||
;;; your option) any later version.
|
||||
;;;
|
||||
;;; Mes 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 Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
;;; info.scm defines [Guile] record data types for compiler.mes
|
||||
|
||||
;;; Code:
|
||||
|
||||
(define-module (language c99 info)
|
||||
#:use-module (ice-9 optargs)
|
||||
#:use-module (system base pmatch)
|
||||
#:export (<info>
|
||||
;; <types>
|
||||
;; <constants>
|
||||
;; <functions>
|
||||
;; <globals>
|
||||
;; <locals>
|
||||
;; <function>
|
||||
;; <text>
|
||||
;; <break>
|
||||
;; <continue>
|
||||
|
||||
make
|
||||
info?
|
||||
|
||||
.info
|
||||
.types
|
||||
.constants
|
||||
.functions
|
||||
.globals
|
||||
.locals
|
||||
.function
|
||||
.text
|
||||
.break
|
||||
.continue))
|
||||
|
||||
(cond-expand
|
||||
(guile-2)
|
||||
(guile
|
||||
(use-modules (ice-9 syncase)))
|
||||
(mes))
|
||||
|
||||
;;(include-from-path "language/c99/info.mes")
|
||||
|
||||
(define <info> '<info>)
|
||||
(define <types> '<types>)
|
||||
(define <constants> '<constants>)
|
||||
(define <functions> '<functions>)
|
||||
(define <globals> '<globals>)
|
||||
(define <locals> '<locals>)
|
||||
(define <function> '<function>)
|
||||
(define <text> '<text>)
|
||||
(define <break> '<break>)
|
||||
(define <continue> '<continue>)
|
||||
|
||||
(define* (make o #:key (types '()) (constants '()) (functions '()) (globals '()) (locals '()) (function #f) (text '()) (break '()) (continue '()))
|
||||
(pmatch o
|
||||
(<info> (list <info>
|
||||
(cons <types> types)
|
||||
(cons <constants> constants)
|
||||
(cons <functions> functions)
|
||||
(cons <globals> globals)
|
||||
(cons <locals> locals)
|
||||
(cons <function> function)
|
||||
(cons <text> text)
|
||||
(cons <break> break)
|
||||
(cons <continue> continue)))))
|
||||
|
||||
(define (.types o)
|
||||
(pmatch o
|
||||
((<info> . ,alist) (assq-ref alist <types>))))
|
||||
|
||||
(define (.constants o)
|
||||
(pmatch o
|
||||
((<info> . ,alist) (assq-ref alist <constants>))))
|
||||
|
||||
(define (.functions o)
|
||||
(pmatch o
|
||||
((<info> . ,alist) (assq-ref alist <functions>))))
|
||||
|
||||
(define (.globals o)
|
||||
(pmatch o
|
||||
((<info> . ,alist) (assq-ref alist <globals>))))
|
||||
|
||||
(define (.locals o)
|
||||
(pmatch o
|
||||
((<info> . ,alist) (assq-ref alist <locals>))))
|
||||
|
||||
(define (.function o)
|
||||
(pmatch o
|
||||
((<info> . ,alist) (assq-ref alist <function>))))
|
||||
|
||||
(define (.text o)
|
||||
(pmatch o
|
||||
((<info> . ,alist) (assq-ref alist <text>))))
|
||||
|
||||
(define (.break o)
|
||||
(pmatch o
|
||||
((<info> . ,alist) (assq-ref alist <break>))))
|
||||
|
||||
(define (.continue o)
|
||||
(pmatch o
|
||||
((<info> . ,alist) (assq-ref alist <continue>))))
|
||||
|
||||
(define (info? o)
|
||||
(and (pair? o) (eq? (car o) <info>)))
|
|
@ -32,7 +32,8 @@
|
|||
(mes-use-module (mes as))
|
||||
(mes-use-module (mes elf))
|
||||
(mes-use-module (mes optargs))
|
||||
(mes-use-module (mes pmatch))))
|
||||
(mes-use-module (mes pmatch))
|
||||
(mes-use-module (language c99 info))))
|
||||
|
||||
(define (logf port string . rest)
|
||||
(apply format (cons* port string rest))
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#:use-module (mes guile)
|
||||
#:use-module (mes as)
|
||||
#:use-module (mes elf)
|
||||
#:use-module (language c99 info)
|
||||
#:export (object->M1
|
||||
objects->M1
|
||||
object->elf
|
||||
|
|
|
@ -40,6 +40,7 @@ exit $r
|
|||
(mes-use-module (mes guile))
|
||||
(mes-use-module (mes getopt-long))
|
||||
(mes-use-module (mes pretty-print))
|
||||
(mes-use-module (language c99 info))
|
||||
(mes-use-module (language c99 compiler))
|
||||
(mes-use-module (mes elf))
|
||||
(mes-use-module (mes M1))
|
||||
|
|
Loading…
Reference in a new issue