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.
2017-07-14 18:42:26 +00:00
|
|
|
;;; -*-scheme-*-
|
|
|
|
|
|
|
|
;;; Mes --- Maxwell Equations of Software
|
2017-11-21 18:22:26 +00:00
|
|
|
;;; Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
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.
2017-07-14 18:42:26 +00:00
|
|
|
;;;
|
|
|
|
;;; 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)
|
2017-07-14 19:26:35 +00:00
|
|
|
#:use-module (srfi srfi-9)
|
|
|
|
#:use-module (srfi srfi-9 gnu)
|
2018-05-04 18:45:27 +00:00
|
|
|
#:use-module (srfi srfi-26)
|
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.
2017-07-14 18:42:26 +00:00
|
|
|
#:export (<info>
|
|
|
|
make
|
2017-07-14 19:26:35 +00:00
|
|
|
make-<info>
|
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.
2017-07-14 18:42:26 +00:00
|
|
|
info?
|
|
|
|
|
|
|
|
.types
|
|
|
|
.constants
|
|
|
|
.functions
|
|
|
|
.globals
|
|
|
|
.locals
|
|
|
|
.function
|
2018-05-04 18:45:27 +00:00
|
|
|
.statics
|
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.
2017-07-14 18:42:26 +00:00
|
|
|
.text
|
2018-05-13 11:50:32 +00:00
|
|
|
.post
|
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.
2017-07-14 18:42:26 +00:00
|
|
|
.break
|
2017-07-15 08:40:31 +00:00
|
|
|
.continue
|
|
|
|
|
2018-05-04 11:58:27 +00:00
|
|
|
<type>
|
2017-07-15 09:24:14 +00:00
|
|
|
make-type
|
|
|
|
type?
|
2017-07-15 08:40:31 +00:00
|
|
|
type:type
|
|
|
|
type:size
|
|
|
|
type:pointer
|
2017-07-15 09:24:14 +00:00
|
|
|
type:description
|
|
|
|
|
2018-05-09 19:31:23 +00:00
|
|
|
<c-array>
|
|
|
|
make-c-array
|
|
|
|
c-array?
|
|
|
|
c-array:type
|
|
|
|
c-array:count
|
|
|
|
|
|
|
|
<pointer>
|
|
|
|
make-pointer
|
|
|
|
pointer?
|
|
|
|
pointer:type
|
|
|
|
pointer:rank
|
|
|
|
|
|
|
|
<var>
|
|
|
|
var:name
|
|
|
|
var:type
|
|
|
|
var:pointer
|
|
|
|
var:c-array
|
|
|
|
|
2018-05-04 11:58:27 +00:00
|
|
|
<global>
|
2017-07-15 09:24:14 +00:00
|
|
|
make-global
|
|
|
|
global?
|
2018-05-04 18:45:27 +00:00
|
|
|
global:name
|
2017-07-15 09:24:14 +00:00
|
|
|
global:type
|
|
|
|
global:pointer
|
2018-05-09 19:31:23 +00:00
|
|
|
global:c-array
|
|
|
|
global:var
|
2017-07-15 09:46:13 +00:00
|
|
|
global:value
|
2018-05-04 18:45:27 +00:00
|
|
|
global:function
|
|
|
|
global->string
|
2017-07-15 09:46:13 +00:00
|
|
|
|
2018-05-04 11:58:27 +00:00
|
|
|
<local>
|
2017-07-15 09:46:13 +00:00
|
|
|
make-local
|
|
|
|
local?
|
|
|
|
local:type
|
|
|
|
local:pointer
|
2018-05-09 19:31:23 +00:00
|
|
|
local:c-array
|
|
|
|
local:var
|
2018-05-04 11:58:27 +00:00
|
|
|
local:id
|
|
|
|
|
|
|
|
<function>
|
|
|
|
make-function
|
|
|
|
function?
|
|
|
|
function:name
|
|
|
|
function:type
|
2018-05-09 19:31:23 +00:00
|
|
|
function:text
|
2018-05-11 17:46:26 +00:00
|
|
|
function->string
|
2018-05-09 19:31:23 +00:00
|
|
|
|
2018-05-10 10:40:07 +00:00
|
|
|
->type
|
2018-05-09 19:31:23 +00:00
|
|
|
->rank
|
|
|
|
rank--
|
|
|
|
rank++
|
2018-05-10 15:11:21 +00:00
|
|
|
rank+=
|
2018-05-09 19:31:23 +00:00
|
|
|
structured-type?))
|
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.
2017-07-14 18:42:26 +00:00
|
|
|
|
|
|
|
(cond-expand
|
|
|
|
(guile-2)
|
|
|
|
(guile
|
2018-01-03 07:33:55 +00:00
|
|
|
(use-modules (ice-9 syncase))
|
|
|
|
(use-modules (ice-9 optargs)))
|
2018-01-01 21:21:15 +00:00
|
|
|
(mes
|
2018-01-02 20:35:55 +00:00
|
|
|
(mes-use-module (mes optargs))))
|
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.
2017-07-14 18:42:26 +00:00
|
|
|
|
2017-07-14 19:26:35 +00:00
|
|
|
(define-immutable-record-type <info>
|
2018-05-13 11:50:32 +00:00
|
|
|
(make-<info> types constants functions globals locals statics function text post break continue)
|
2017-07-14 19:26:35 +00:00
|
|
|
info?
|
|
|
|
(types .types)
|
|
|
|
(constants .constants)
|
|
|
|
(functions .functions)
|
|
|
|
(globals .globals)
|
|
|
|
(locals .locals)
|
2018-05-04 18:45:27 +00:00
|
|
|
(statics .statics)
|
2017-07-14 19:26:35 +00:00
|
|
|
(function .function)
|
|
|
|
(text .text)
|
2018-05-13 11:50:32 +00:00
|
|
|
(post .post)
|
2017-07-14 19:26:35 +00:00
|
|
|
(break .break)
|
|
|
|
(continue .continue))
|
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.
2017-07-14 18:42:26 +00:00
|
|
|
|
2018-05-13 11:50:32 +00:00
|
|
|
(define* (make o #:key (types '()) (constants '()) (functions '()) (globals '()) (locals '()) (statics '()) (function #f) (text '()) (post '()) (break '()) (continue '()))
|
|
|
|
(make-<info> types constants functions globals locals statics function text post break continue))
|
2017-07-15 08:40:31 +00:00
|
|
|
|
2018-05-09 19:31:23 +00:00
|
|
|
;; ("int" . ,(make-type 'builtin 4 #f 0 #f))
|
|
|
|
;; (make-type 'enum 4 0 fields)
|
|
|
|
;; (make-type 'struct (apply + (map field:size fields)) 0 fields)
|
|
|
|
|
2017-07-15 08:40:31 +00:00
|
|
|
(define-immutable-record-type <type>
|
2018-05-09 19:31:23 +00:00
|
|
|
(make-type type size description)
|
2017-07-15 08:40:31 +00:00
|
|
|
type?
|
|
|
|
(type type:type)
|
|
|
|
(size type:size)
|
|
|
|
(description type:description))
|
2017-07-15 09:24:14 +00:00
|
|
|
|
2018-05-09 19:31:23 +00:00
|
|
|
(define-immutable-record-type <c-array>
|
|
|
|
(make-c-array type count)
|
|
|
|
c-array?
|
|
|
|
(type c-array:type)
|
|
|
|
(count c-array:count))
|
|
|
|
|
|
|
|
(define-immutable-record-type <pointer>
|
|
|
|
(make-pointer type rank)
|
|
|
|
pointer?
|
|
|
|
(type pointer:type)
|
|
|
|
(rank pointer:rank))
|
|
|
|
|
|
|
|
(define-immutable-record-type <var>
|
|
|
|
(make-var name type function id value)
|
|
|
|
var?
|
|
|
|
(name var:name)
|
|
|
|
(type var:type) ; <type>
|
|
|
|
(function var:function)
|
|
|
|
(id var:id)
|
|
|
|
(value var:value))
|
|
|
|
|
2017-07-15 09:24:14 +00:00
|
|
|
(define-immutable-record-type <global>
|
2018-05-10 10:40:07 +00:00
|
|
|
(make-global- name type var value function)
|
2017-07-15 09:24:14 +00:00
|
|
|
global?
|
2018-05-04 18:45:27 +00:00
|
|
|
(name global:name)
|
2017-07-15 09:24:14 +00:00
|
|
|
(type global:type)
|
2018-05-09 19:31:23 +00:00
|
|
|
(var global:var) ; <var>
|
|
|
|
|
2018-05-04 18:45:27 +00:00
|
|
|
(value global:value)
|
|
|
|
(function global:function))
|
|
|
|
|
2018-05-10 10:40:07 +00:00
|
|
|
(define (make-global name type value function)
|
|
|
|
(make-global- name type (make-var name type function #f value) value function))
|
2018-05-09 19:31:23 +00:00
|
|
|
|
2018-05-04 18:45:27 +00:00
|
|
|
(define (global->string o)
|
|
|
|
(or (and=> (global:function o) (cut string-append <> "-" (global:name o)))
|
|
|
|
(global:name o)))
|
2017-07-15 09:46:13 +00:00
|
|
|
|
|
|
|
(define-immutable-record-type <local>
|
2018-05-10 10:40:07 +00:00
|
|
|
(make-local- type var id)
|
2017-07-15 09:46:13 +00:00
|
|
|
local?
|
|
|
|
(type local:type)
|
2018-05-09 19:31:23 +00:00
|
|
|
(var local:var) ; <var>
|
|
|
|
|
2018-05-10 10:40:07 +00:00
|
|
|
(id local:id))
|
2018-05-09 19:31:23 +00:00
|
|
|
|
2018-05-10 10:40:07 +00:00
|
|
|
(define (make-local name type id)
|
|
|
|
(make-local- type (make-var name type #f id #f) id))
|
2018-05-04 11:58:27 +00:00
|
|
|
|
|
|
|
(define-immutable-record-type <function>
|
|
|
|
(make-function name type text)
|
|
|
|
function?
|
|
|
|
(name function:name)
|
|
|
|
(type function:type)
|
|
|
|
(text function:text))
|
2018-05-09 19:31:23 +00:00
|
|
|
|
2018-05-11 17:46:26 +00:00
|
|
|
(define (function->string o)
|
|
|
|
(function:name o))
|
|
|
|
|
2018-05-09 19:31:23 +00:00
|
|
|
(define (structured-type? o)
|
|
|
|
(cond ((type? o) (memq (type:type o) '(struct union)))
|
|
|
|
((global? o) ((compose structured-type? global:type) o))
|
|
|
|
((local? o) ((compose structured-type? local:type) o))
|
|
|
|
((and (pair? o) (eq? (car o) 'tag))) ;; FIXME: enum?
|
|
|
|
(else #f)))
|
|
|
|
|
2018-05-10 10:40:07 +00:00
|
|
|
(define (->type o)
|
2018-05-09 19:31:23 +00:00
|
|
|
(cond ((type? o) o)
|
|
|
|
((pointer? o) (pointer:type o))
|
|
|
|
((c-array? o) (c-array:type o))
|
|
|
|
((and (pair? o) (eq? (car o) 'tag)) o)
|
|
|
|
;; FIXME
|
|
|
|
(#t
|
|
|
|
(format (current-error-port) "->type--: not a <type>: ~s\n" o)
|
|
|
|
(make-type 'builtin 4 #f))
|
2018-05-10 10:40:07 +00:00
|
|
|
(else (error "->type: not a <type>:" o))))
|
2018-05-09 19:31:23 +00:00
|
|
|
|
|
|
|
(define (->rank o)
|
|
|
|
(cond ((type? o) 0)
|
|
|
|
((pointer? o) (pointer:rank o))
|
2018-05-10 15:11:21 +00:00
|
|
|
((c-array? o) (1+ ((compose ->rank c-array:type) o)))
|
|
|
|
((local? o) ((compose ->rank local:type) o))
|
|
|
|
((global? o) ((compose ->rank global:type) o))
|
2018-05-09 19:31:23 +00:00
|
|
|
;; FIXME
|
|
|
|
(#t
|
2018-05-10 15:11:21 +00:00
|
|
|
(format (current-error-port) "->rank: not a type: ~s\n" o)
|
2018-05-09 19:31:23 +00:00
|
|
|
0)
|
|
|
|
(else (error "->rank: not a <type>:" o))))
|
|
|
|
|
|
|
|
(define (rank-- o)
|
2018-05-10 15:11:21 +00:00
|
|
|
(cond ((and (pointer? o) (= (pointer:rank o) 1)) (pointer:type o))
|
2018-05-09 19:31:23 +00:00
|
|
|
((pointer? o) (set-field o (pointer:rank) (1- (pointer:rank o))))
|
2018-05-10 15:11:21 +00:00
|
|
|
((c-array? o) (c-array:type o))
|
2018-05-09 19:31:23 +00:00
|
|
|
;; FIXME
|
|
|
|
(#t (format (current-error-port) "rank--: not a pointer: ~s\n" o)
|
|
|
|
o)
|
|
|
|
(else (error "rank--: not a pointer" o))))
|
|
|
|
|
2018-05-10 15:11:21 +00:00
|
|
|
(define (rank+= o i)
|
|
|
|
(cond ((pointer? o) (set-field o (pointer:rank) (+ i (pointer:rank o))))
|
|
|
|
(else (make-pointer o i))))
|
|
|
|
|
2018-05-09 19:31:23 +00:00
|
|
|
(define (rank++ o)
|
2018-05-10 15:11:21 +00:00
|
|
|
(rank+= o 1))
|