3 MES=${MES-$(dirname $0)/../scripts/mes}
4 echo ' ()' | cat $(dirname $0)/../module/mes/base-0.mes $0 /dev/stdin | $MES $MES_FLAGS "$@"
11 ;;; Mes --- Maxwell Equations of Software
12 ;;; Copyright © 2016 Jan Nieuwenhuizen <janneke@gnu.org>
14 ;;; This file is part of Mes.
16 ;;; Mes is free software; you can redistribute it and/or modify it
17 ;;; under the terms of the GNU General Public License as published by
18 ;;; the Free Software Foundation; either version 3 of the License, or (at
19 ;;; your option) any later version.
21 ;;; Mes is distributed in the hope that it will be useful, but
22 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
23 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 ;;; GNU General Public License for more details.
26 ;;; You should have received a copy of the GNU General Public License
27 ;;; along with Mes. If not, see <http://www.gnu.org/licenses/>.
29 (mes-use-module (mes base))
30 (mes-use-module (mes quasiquote))
31 (mes-use-module (mes let))
32 (mes-use-module (srfi srfi-0))
33 (mes-use-module (mes scm))
34 (mes-use-module (mes test))
36 (pass-if "first dummy" #t)
37 (pass-if-not "second dummy" #f)
40 (define the-cells (make-vector gc-size))
43 (define cell-type-alist
44 '((0 . c) (1 . m) (2 . n) (3 . p) (4 . i) (5 . $) (6 . s) (7 . r)))
46 (define (cell-index c)
50 (define (describe-cell c)
51 (cons (assoc-ref cell-type-alist (mes-type-of c)) c))
55 (append (iota (- n 1)) (list n))))
58 (display "\nfree:") (display gc-free) (newline)
59 (map (lambda (i) (display i) (display ": ") (display (describe-cell (vector-ref the-cells i))) (newline)) (iota (- gc-size 1))))
63 (map (lambda (i) (display i) (display ": ") (display (describe-cell (vector-ref new-cells i))) (newline)) (iota (- gc-size 1)))
72 (if (= gc-free gc-size) (gc))
74 (set! gc-free (+ gc-free 1))
75 (core:make-cell 'p index))
78 (define (core:make-cell type . x)
79 (cons type (if (pair? x) (car x) '*)))
81 (define (cell-index c)
85 (define (make-number x)
87 (vector-set! the-cells (cell-index cell) x)
91 (define (make-symbol x)
93 (vector-set! the-cells (cell-index cell) x)
100 (vector-set! the-cells (cell-index cell) pair)
103 (cons *unspecified* *unspecified*))
107 ;; (define (gc-reg c)
108 ;; (vector-ref the-cells (cell-index c)))
110 (define gc-display display)
111 ;;(define (gc-display c) (display (gc-reg c)))
112 ;; (define (gc-car c) (car (gc-reg c)))
113 ;; (define (gc-cdr c) (cdr (gc-reg c)))
114 ;; (define (gc-pair? c) (pair? (gc-reg c)))
115 ;; (define (gc-null? c) (null? (gc-reg c)))
116 ;; (define (gc-display x . cont?)
117 ;; (if (gc-pair? x) (begin (if (null? cont?) (display "("))
118 ;; (gc-display (gc-reg x))
119 ;; (if (gc-pair? (gc-cdr x)) (display " "))
120 ;; (if (not (gc-null? (gc-cdr x)))
121 ;; (gc-display (gc-cdr x) #t))
122 ;; (if (null? cont?) (display ")")))
123 ;; (if (gc-null? x) (if (not cont?) (display "()"))
124 ;; (display (gc-reg x)))))
127 (define first (make-symbol 'F)) (newline)
129 (define one (make-number 1))
130 (display "one=") (display one) (newline)
131 (define two (make-number 2))
132 (define pair2-nil (gc-cons two gc-nil))
133 (display "pair2-nil=") (display pair2-nil) (newline)
136 (define list1-2 (gc-cons one pair2-nil))
137 (display "list1-2=") (display list1-2) (newline)
140 (define three (make-number 3))
141 (define four (make-number 4))
142 (define pair4-nil (gc-cons four gc-nil))
143 (define list3-4 (gc-cons three pair4-nil))
144 (define list1234 (gc-cons list1-2 list3-4))
147 (display "list1-2=") (display list1-2) (newline)
148 (display "list3-4=") (display list3-4) (newline)
149 (display "lst=") (display list1234) (newline)
152 (display "sicp-lst:") (gc-display list1234) (newline)
155 (display "\n**** trigger gc ****\n")
156 (define next (gc-list (make-symbol 'N) (make-symbol 'X)))
157 (set! list1234 '(p . 0))
158 (display "sicp-lst:") (gc-display list1234) (newline)
160 (display "next=") (display next) (newline)
161 (display "gc-next=") (gc-display next) (newline)