3 ;;; Mes --- Maxwell Equations of Software
4 ;;; Copyright © 2016,2017,2018 Jan Nieuwenhuizen <janneke@gnu.org>
6 ;;; This file is part of Mes.
8 ;;; Mes is free software; you can redistribute it and/or modify it
9 ;;; under the terms of the GNU General Public License as published by
10 ;;; the Free Software Foundation; either version 3 of the License, or (at
11 ;;; your option) any later version.
13 ;;; Mes is distributed in the hope that it will be useful, but
14 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;;; GNU General Public License for more details.
18 ;;; You should have received a copy of the GNU General Public License
19 ;;; along with Mes. If not, see <http://www.gnu.org/licenses/>.
23 ;;; Implement core functionality that depends on implementation
24 ;;; specifics of Mes cell types.
28 (define <cell:char> 0)
29 (define <cell:closure> 1)
30 (define <cell:continuation> 2)
31 (define <cell:function> 3)
32 (define <cell:keyword> 4)
33 (define <cell:macro> 5)
34 (define <cell:number> 6)
35 (define <cell:pair> 7)
37 (define <cell:special> 9)
38 (define <cell:string> 10)
39 (define <cell:symbol> 11)
40 (define <cell:values> 12)
41 (define <cell:vector> 13)
42 (define <cell:broken-heart> 14)
44 (define cell:type-alist
45 (list (cons <cell:char> (quote <cell:char>))
46 (cons <cell:closure> (quote <cell:closure>))
47 (cons <cell:continuation> (quote <cell:continuation>))
48 (cons <cell:function> (quote <cell:function>))
49 (cons <cell:keyword> (quote <cell:keyword>))
50 (cons <cell:macro> (quote <cell:macro>))
51 (cons <cell:number> (quote <cell:number>))
52 (cons <cell:pair> (quote <cell:pair>))
53 (cons <cell:ref> (quote <cell:ref>))
54 (cons <cell:special> (quote <cell:special>))
55 (cons <cell:string> (quote <cell:string>))
56 (cons <cell:symbol> (quote <cell:symbol>))
57 (cons <cell:values> (quote <cell:values>))
58 (cons <cell:vector> (quote <cell:vector>))
59 (cons <cell:broken-heart> (quote <cell:broken-heart>))))
61 (define (cell:type-name x)
62 (cond ((assq (core:type x) cell:type-alist) => cdr)))
65 (and (eq? (core:type x) <cell:char>)
66 (>= (char->integer x) 0)))
68 (define (eof-object? x)
69 (and (eq? (core:type x) <cell:char>)
70 (= (char->integer x) -1)))
73 (eq? (core:type x) <cell:closure>))
75 (define (continuation? x)
76 (eq? (core:type x) <cell:continuation>))
79 (eq? (core:type x) <cell:function>))
81 (define builtin? function?)
84 (eq? (core:type x) <cell:keyword>))
87 (eq? (core:type x) <cell:macro>))
90 (eq? (core:type x) <cell:number>))
93 (eq? (core:type x) <cell:pair>))
96 (eq? (core:type x) <cell:pair>))
99 (eq? (core:type x) <cell:special>))
102 (eq? (core:type x) <cell:string>))
105 (eq? (core:type x) <cell:symbol>))
109 (eq? (core:type x) <cell:values>))
112 (eq? (core:type x) <cell:vector>))
123 (or (eq? x #f) (eq? x #t)))
127 (define (string . lst)
128 (core:make-cell <cell:string> lst 0))
130 (define (string->symbol s)
131 (if (not (pair? (core:car s))) '()
132 (core:lookup-symbol (core:car s))))
134 (define (symbol->list s)
137 (define (keyword->list s)
140 (define (integer->char x)
141 (core:make-cell <cell:character> 0 x))
143 (define (char->integer x)
144 (core:make-cell <cell:number> 0 x))