3 echo ' ()' | cat $(dirname $0)/../module/mes/base-0.mes $0 /dev/stdin | $(dirname $0)/../scripts/mes $MES_FLAGS "$@"
10 ;;; Mes --- Maxwell Equations of Software
11 ;;; Copyright © 2016 Jan Nieuwenhuizen <janneke@gnu.org>
13 ;;; This file is part of Mes.
15 ;;; Mes is free software; you can redistribute it and/or modify it
16 ;;; under the terms of the GNU General Public License as published by
17 ;;; the Free Software Foundation; either version 3 of the License, or (at
18 ;;; your option) any later version.
20 ;;; Mes is distributed in the hope that it will be useful, but
21 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
22 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 ;;; GNU General Public License for more details.
25 ;;; You should have received a copy of the GNU General Public License
26 ;;; along with Mes. If not, see <http://www.gnu.org/licenses/>.
28 (mes-use-module (mes base))
29 (mes-use-module (mes quasiquote))
30 (mes-use-module (mes let))
31 (mes-use-module (srfi srfi-0))
32 (mes-use-module (mes scm))
33 (mes-use-module (mes test))
35 (pass-if "first dummy" #t)
36 (pass-if-not "second dummy" #f)
39 (define the-cells (make-vector gc-size))
42 (define cell-type-alist
43 '((0 . c) (1 . m) (2 . n) (3 . p) (4 . i) (5 . $) (6 . s) (7 . r)))
45 (define (cell-index c)
49 (define (describe-cell c)
50 (cons (assoc-ref cell-type-alist (mes-type-of c)) c))
54 (append (iota (- n 1)) (list n))))
57 (display "\nfree:") (display gc-free) (newline)
58 (map (lambda (i) (display i) (display ": ") (display (describe-cell (vector-ref the-cells i))) (newline)) (iota (- gc-size 1))))
62 (map (lambda (i) (display i) (display ": ") (display (describe-cell (vector-ref new-cells i))) (newline)) (iota (- gc-size 1)))
71 (if (= gc-free gc-size) (gc))
73 (set! gc-free (+ gc-free 1))
77 (define (make-cell type . x)
78 (cons type (if (pair? x) (car x) '*)))
80 (define (cell-index c)
84 (define (make-number x)
86 (vector-set! the-cells (cell-index cell) x)
90 (define (make-symbol x)
92 (vector-set! the-cells (cell-index cell) x)
99 (vector-set! the-cells (cell-index cell) pair)
102 (cons *unspecified* *unspecified*))
106 ;; (define (gc-reg c)
107 ;; (vector-ref the-cells (cell-index c)))
109 (define gc-display display)
110 ;;(define (gc-display c) (display (gc-reg c)))
111 ;; (define (gc-car c) (car (gc-reg c)))
112 ;; (define (gc-cdr c) (cdr (gc-reg c)))
113 ;; (define (gc-pair? c) (pair? (gc-reg c)))
114 ;; (define (gc-null? c) (null? (gc-reg c)))
115 ;; (define (gc-display x . cont?)
116 ;; (if (gc-pair? x) (begin (if (null? cont?) (display "("))
117 ;; (gc-display (gc-reg x))
118 ;; (if (gc-pair? (gc-cdr x)) (display " "))
119 ;; (if (not (gc-null? (gc-cdr x)))
120 ;; (gc-display (gc-cdr x) #t))
121 ;; (if (null? cont?) (display ")")))
122 ;; (if (gc-null? x) (if (not cont?) (display "()"))
123 ;; (display (gc-reg x)))))
126 (define first (make-symbol 'F)) (newline)
128 (define one (make-number 1))
129 (display "one=") (display one) (newline)
130 (define two (make-number 2))
131 (define pair2-nil (gc-cons two gc-nil))
132 (display "pair2-nil=") (display pair2-nil) (newline)
135 (define list1-2 (gc-cons one pair2-nil))
136 (display "list1-2=") (display list1-2) (newline)
139 (define three (make-number 3))
140 (define four (make-number 4))
141 (define pair4-nil (gc-cons four gc-nil))
142 (define list3-4 (gc-cons three pair4-nil))
143 (define list1234 (gc-cons list1-2 list3-4))
146 (display "list1-2=") (display list1-2) (newline)
147 (display "list3-4=") (display list3-4) (newline)
148 (display "lst=") (display list1234) (newline)
151 (display "sicp-lst:") (gc-display list1234) (newline)
154 (display "\n**** trigger gc ****\n")
155 (define next (gc-list (make-symbol 'N) (make-symbol 'X)))
156 (set! list1234 '(p . 0))
157 (display "sicp-lst:") (gc-display list1234) (newline)
159 (display "next=") (display next) (newline)
160 (display "gc-next=") (gc-display next) (newline)