mes: Support srfi-9-gnu.

* module/srfi/srfi-9/gnu.mes: New file.  Support srfi-9-gnu.
* tests/srfi-9.test: Test it.
* tests/srfi-9.test-guile:
This commit is contained in:
Jan Nieuwenhuizen 2018-05-04 12:44:05 +02:00
parent 7b476693c2
commit 10bd43d222
No known key found for this signature in database
GPG Key ID: F3C1A0D9C1D65273
8 changed files with 80 additions and 9 deletions

View File

@ -31,6 +31,7 @@ mes/as.scm
mes/bytevectors.scm
mes/elf.scm
mes/guile.scm
mes/test.scm
mes/M1.scm"
export srcdir=.

View File

@ -41,13 +41,13 @@ tests/cwv.test
tests/math.test
tests/vector.test
tests/srfi-1.test
tests/srfi-9.test
tests/srfi-13.test
tests/srfi-14.test
tests/srfi-43.test
tests/optargs.test
tests/fluids.test
tests/catch.test
tests/record.test
tests/getopt-long.test
tests/guile.test
tests/syntax.test

View File

@ -25,7 +25,11 @@
;;; Code:
(mes-use-module (mes base))
(cond-expand
(mes
(mes-use-module (mes base)))
(else))
(cond-expand
(mes
(define mes? #t)

22
module/mes/test.scm Normal file
View File

@ -0,0 +1,22 @@
;;; -*-scheme-*-
;;; Mes --- Maxwell Equations of Software
;;; Copyright © 2018 Jan (janneke) 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/>.
(define-module (mes test))
(include-from-path "mes/test.mes")

View File

@ -53,9 +53,10 @@
(define (record-getter type field)
(let ((i (record-field-index type field)))
(lambda (o)
(lambda (o . field?)
(if (not (eq? (record-type o) type)) (error "record getter: record expected" type o)
(vector-ref o i)))))
(if (pair? field?) field
(vector-ref o i))))))
(define (record-setter type field)
(let ((i (record-field-index type field)))

View File

@ -0,0 +1,37 @@
;;; -*-scheme-*-
;;; Mes --- Maxwell Equations of Software
;;; Copyright © 2017,2018 Jan (janneke) 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:
;;; srfi-9.mes - GNU immutable records.
(define-macro (define-immutable-record-type type constructor+params predicate . fields)
`(define-record-type ,type ,constructor+params ,predicate ,@(map (lambda (f) (list-head f 2)) fields)))
(define-macro (set-field o getters value)
`(let ((getter ,(car getters)))
(let ((type (record-type ,o))
(set (getter ,o #t)))
(define (field->value field)
(if (eq? set field) ,value
((record-getter type field) ,o)))
(let* ((fields (record-fields type))
(values (map field->value fields)))
(apply (record-constructor type fields) values)))))

View File

@ -25,14 +25,16 @@ exit $?
;;; You should have received a copy of the GNU General Public License
;;; along with Mes. If not, see <http://www.gnu.org/licenses/>.
(mes-use-module (srfi srfi-0))
(mes-use-module (srfi srfi-9))
(mes-use-module (mes test))
(cond-expand
(mes
(mes-use-module (srfi srfi-9))
(mes-use-module (srfi srfi-9 gnu))
(mes-use-module (mes test)))
(guile
(use-modules (srfi srfi-9)))
(mes))
(use-modules (srfi srfi-9))
(use-modules (srfi srfi-9 gnu))
(use-modules (mes test))))
(pass-if "first dummy" #t)
(pass-if-not "second dummy" #f)
@ -47,4 +49,8 @@ exit $?
(pass-if "record"
(lexical-token? (make-lexical-token 'x 'y 'z)))
(pass-if-equal "set-field" "baar"
(let ((token (make-lexical-token 'foo "bar" 'baz)))
(lexical-token-category (set-field token (lexical-token-category) "baar"))))
(result 'report)