mes/module/mes/type-0.mes

92 lines
2.2 KiB
Scheme

;;; -*-scheme-*-
;;; Mes --- Maxwell Equations of Software
;;; Copyright © 2016 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:
;;; type-0.mes - to be loaded after loop-0.mes if type.i is not
;;; included in core.
;;; This code is only loaded if environment variable TYPE0 is set.
;;; There are two copies of the type enum, with manual numbering. Not
;;; good.
;;; Code:
(define <char> 0)
(define <function> 1)
(define <macro> 2)
(define <number> 3)
(define <pair> 4)
(define <scm> 5)
(define <string> 6)
(define <symbol> 7)
(define <values> 8)
(define <vector> 9)
(define mes-type-alist
`((,<char> . <char>)
(,<function> . <function>)
(,<macro> . <macro>)
(,<number> . <number>)
(,<pair> . <pair>)
(,<scm> . <scm>)
(,<string> . <string>)
(,<symbol> . <symbol>)
(,<char> . <char>)
(,<values> . <values>)))
(define (class-of x)
(assq (mes-type-of x) mes-type-alist))
(define (atom? x)
(not (pair? x)))
(define (boolean? x)
(if (eq? x #f) #t
(if (eq? x #t) #t
#f)))
(define (char? x)
(eq? (mes-type-of x) <char>))
;; pair? is not needed as a primitive from C
;; but it gives a factor 2 speedup
;; (define (pair? x)
;; (eq? (mes-type-of x) <pair>))
(define (number? x)
(eq? (mes-type-of x) <number>))
(define (internal? x)
(eq? (mes-type-of x) <scm>))
(define (string? x)
(eq? (mes-type-of x) <string>))
(define (symbol? x)
(eq? (mes-type-of x) <symbol>))
(define (vector? x)
(eq? (mes-type-of x) <vector>))
(define (null? x)
(eq? x '()))