mes/mes/module/mes/type-0.mes

141 lines
3.6 KiB
Scheme
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

;;; -*-scheme-*-
;;; Mes --- Maxwell Equations of Software
;;; Copyright © 2016,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:
;;; Implement core functionality that depends on implementation
;;; specifics of Mes cell types.
;;; Code:
(define cell:type-alist
(list (cons <cell:char> (quote <cell:char>))
(cons <cell:closure> (quote <cell:closure>))
(cons <cell:continuation> (quote <cell:continuation>))
(cons <cell:function> (quote <cell:function>))
(cons <cell:keyword> (quote <cell:keyword>))
(cons <cell:macro> (quote <cell:macro>))
(cons <cell:number> (quote <cell:number>))
(cons <cell:pair> (quote <cell:pair>))
(cons <cell:ref> (quote <cell:ref>))
(cons <cell:special> (quote <cell:special>))
(cons <cell:string> (quote <cell:string>))
(cons <cell:symbol> (quote <cell:symbol>))
(cons <cell:values> (quote <cell:values>))
(cons <cell:variable> (quote <cell:variable>))
(cons <cell:vector> (quote <cell:vector>))
(cons <cell:broken-heart> (quote <cell:broken-heart>))))
(define (cell:type-name x)
(cond ((assq (core:type x) cell:type-alist) => cdr)))
(define (char? x)
(and (eq? (core:type x) <cell:char>)
(> (char->integer x) -1)))
(define (eof-object? x)
(and (eq? (core:type x) <cell:char>)
(= (char->integer x) -1)))
(define (closure? x)
(eq? (core:type x) <cell:closure>))
(define (continuation? x)
(eq? (core:type x) <cell:continuation>))
(define (function? x)
(eq? (core:type x) <cell:function>))
(define builtin? function?)
(define (keyword? x)
(eq? (core:type x) <cell:keyword>))
(define (macro? x)
(eq? (core:type x) <cell:macro>))
(define (number? x)
(eq? (core:type x) <cell:number>))
(define (pair? x)
(eq? (core:type x) <cell:pair>))
(define (port? x)
(eq? (core:type x) <cell:port>))
(define (special? x)
(eq? (core:type x) <cell:special>))
(define (string? x)
(eq? (core:type x) <cell:string>))
(define (symbol? x)
(eq? (core:type x) <cell:symbol>))
(define (values? x)
(eq? (core:type x) <cell:values>))
(define (variable? x)
(eq? (core:type x) <cell:variable>))
(define (variable-global? x)
(core:cdr x))
(define (vector? x)
(eq? (core:type x) <cell:vector>))
;; Non-types
;; In core
;; (define (null? x)
;; (eq? x '()))
(define (atom? x)
(not (pair? x)))
(define (boolean? x)
(or (eq? x #f) (eq? x #t)))
;;; core: accessors
(define (string . lst)
(core:make-cell <cell:string> lst 0))
(define (string->symbol s)
(if (not (pair? (core:car s))) '()
(core:lookup-symbol (core:car s))))
(define (symbol->keyword s)
(core:make-cell <cell:keyword> (symbol->list s) 0))
(define (list->symbol lst)
(core:lookup-symbol lst))
(define (symbol->list s)
(core:car s))
(define (keyword->list s)
(core:car s))
(define (integer->char x)
(core:make-cell <cell:char> 0 x))
(define (char->integer x)
(core:make-cell <cell:number> 0 x))