From 52b09c5f1729e7df7ea5080f671402d7cb6f3b1e Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Fri, 14 Jul 2017 20:42:26 +0200 Subject: [PATCH] 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. (, , , , , , , , , , 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. --- guile/mescc.scm | 1 + make.scm | 3 + module/language/c99/compiler.mes | 73 ++---------------- module/language/c99/compiler.scm | 2 + module/language/c99/info.mes | 96 ++++++++++++++++++++++++ module/language/c99/info.scm | 122 +++++++++++++++++++++++++++++++ module/mes/M1.mes | 3 +- module/mes/M1.scm | 1 + scripts/mescc.mes | 1 + 9 files changed, 234 insertions(+), 68 deletions(-) create mode 100644 module/language/c99/info.mes create mode 100644 module/language/c99/info.scm diff --git a/guile/mescc.scm b/guile/mescc.scm index 357ec3f4..5981509d 100755 --- a/guile/mescc.scm +++ b/guile/mescc.scm @@ -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) diff --git a/make.scm b/make.scm index df00bf19..4e94f636 100755 --- a/make.scm +++ b/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" diff --git a/module/language/c99/compiler.mes b/module/language/c99/compiler.mes index 4850b310..0e667ff1 100644 --- a/module/language/c99/compiler.mes +++ b/module/language/c99/compiler.mes @@ -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 ') -(define ') -(define ') -(define ') -(define ') -(define ') -(define ') -(define ') -(define ') -(define ') - -(define* (make o #:key (types '()) (constants '()) (functions '()) (globals '()) (locals '()) (function #f) (text '()) (break '()) (continue '())) - (pmatch o - ( (list - (cons types) - (cons constants) - (cons functions) - (cons globals) - (cons locals) - (cons function) - (cons text) - (cons break) - (cons continue))))) - -(define (.types o) - (pmatch o - (( . ,alist) (assq-ref alist )))) - -(define (.constants o) - (pmatch o - (( . ,alist) (assq-ref alist )))) - -(define (.functions o) - (pmatch o - (( . ,alist) (assq-ref alist )))) - -(define (.globals o) - (pmatch o - (( . ,alist) (assq-ref alist )))) - -(define (.locals o) - (pmatch o - (( . ,alist) (assq-ref alist )))) - -(define (.function o) - (pmatch o - (( . ,alist) (assq-ref alist )))) - -(define (.text o) - (pmatch o - (( . ,alist) (assq-ref alist )))) - -(define (.break o) - (pmatch o - (( . ,alist) (assq-ref alist )))) - -(define (.continue o) - (pmatch o - (( . ,alist) (assq-ref alist )))) - -(define (info? o) - (and (pair? o) (eq? (car o) ))) - (define (clone o . rest) (cond ((info? o) (let ((types (.types o)) @@ -222,6 +161,9 @@ (continue continue)) (make #: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)) diff --git a/module/language/c99/compiler.scm b/module/language/c99/compiler.scm index 49509b97..a6750dfe 100644 --- a/module/language/c99/compiler.scm +++ b/module/language/c99/compiler.scm @@ -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 diff --git a/module/language/c99/info.mes b/module/language/c99/info.mes new file mode 100644 index 00000000..9c8354cb --- /dev/null +++ b/module/language/c99/info.mes @@ -0,0 +1,96 @@ +;;; -*-scheme-*- + +;;; Mes --- Maxwell Equations of Software +;;; Copyright © 2016,2017 Jan Nieuwenhuizen +;;; +;;; 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 . + +;;; 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 ') +(define ') +(define ') +(define ') +(define ') +(define ') +(define ') +(define ') +(define ') +(define ') + +(define (.types o) + (pmatch o + (( . ,alist) (assq-ref alist )))) + +(define (.constants o) + (pmatch o + (( . ,alist) (assq-ref alist )))) + +(define (.functions o) + (pmatch o + (( . ,alist) (assq-ref alist )))) + +(define (.globals o) + (pmatch o + (( . ,alist) (assq-ref alist )))) + +(define (.locals o) + (pmatch o + (( . ,alist) (assq-ref alist )))) + +(define (.function o) + (pmatch o + (( . ,alist) (assq-ref alist )))) + +(define (.text o) + (pmatch o + (( . ,alist) (assq-ref alist )))) + +(define (.break o) + (pmatch o + (( . ,alist) (assq-ref alist )))) + +(define (.continue o) + (pmatch o + (( . ,alist) (assq-ref alist )))) + +(define (info? o) + (and (pair? o) (eq? (car o) ))) + +(define* (make o #:key (types '()) (constants '()) (functions '()) (globals '()) (locals '()) (function #f) (text '()) (break '()) (continue '())) + (pmatch o + ( (list + (cons types) + (cons constants) + (cons functions) + (cons globals) + (cons locals) + (cons function) + (cons text) + (cons break) + (cons continue))))) diff --git a/module/language/c99/info.scm b/module/language/c99/info.scm new file mode 100644 index 00000000..c5bab0dd --- /dev/null +++ b/module/language/c99/info.scm @@ -0,0 +1,122 @@ +;;; -*-scheme-*- + +;;; Mes --- Maxwell Equations of Software +;;; Copyright © 2016,2017 Jan Nieuwenhuizen +;;; +;;; 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 . + +;;; 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 ( + ;; + ;; + ;; + ;; + ;; + ;; + ;; + ;; + ;; + + 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 ') +(define ') +(define ') +(define ') +(define ') +(define ') +(define ') +(define ') +(define ') +(define ') + +(define* (make o #:key (types '()) (constants '()) (functions '()) (globals '()) (locals '()) (function #f) (text '()) (break '()) (continue '())) + (pmatch o + ( (list + (cons types) + (cons constants) + (cons functions) + (cons globals) + (cons locals) + (cons function) + (cons text) + (cons break) + (cons continue))))) + +(define (.types o) + (pmatch o + (( . ,alist) (assq-ref alist )))) + +(define (.constants o) + (pmatch o + (( . ,alist) (assq-ref alist )))) + +(define (.functions o) + (pmatch o + (( . ,alist) (assq-ref alist )))) + +(define (.globals o) + (pmatch o + (( . ,alist) (assq-ref alist )))) + +(define (.locals o) + (pmatch o + (( . ,alist) (assq-ref alist )))) + +(define (.function o) + (pmatch o + (( . ,alist) (assq-ref alist )))) + +(define (.text o) + (pmatch o + (( . ,alist) (assq-ref alist )))) + +(define (.break o) + (pmatch o + (( . ,alist) (assq-ref alist )))) + +(define (.continue o) + (pmatch o + (( . ,alist) (assq-ref alist )))) + +(define (info? o) + (and (pair? o) (eq? (car o) ))) diff --git a/module/mes/M1.mes b/module/mes/M1.mes index 8ca27a63..14e1c48b 100644 --- a/module/mes/M1.mes +++ b/module/mes/M1.mes @@ -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)) diff --git a/module/mes/M1.scm b/module/mes/M1.scm index 12a4c153..43813e6b 100644 --- a/module/mes/M1.scm +++ b/module/mes/M1.scm @@ -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 diff --git a/scripts/mescc.mes b/scripts/mescc.mes index cd5403d9..16df5339 100755 --- a/scripts/mescc.mes +++ b/scripts/mescc.mes @@ -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))