3 ;; Copyright (C) 2001 Free Software Foundation, Inc.
5 ;; This program is free software; you can redistribute it and/or modify
6 ;; it under the terms of the GNU General Public License as published by
7 ;; the Free Software Foundation; either version 2, or (at your option)
10 ;; This program is distributed in the hope that it will be useful,
11 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ;; GNU General Public License for more details.
15 ;; You should have received a copy of the GNU General Public License
16 ;; along with this program; see the file COPYING. If not, write to
17 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 ;; Boston, MA 02111-1307, USA.
22 (define-module (system il macros)
23 :use-module (ice-9 match))
25 (define (make-label) (gensym ":L"))
26 (define (make-sym) (gensym "_"))
35 ;; (@if X (@and Y...) #f)
40 ((x . rest) `(@if ,x (@and ,@rest) #f))))
44 ;; (@let ((@_ X)) (@if @_ @_ (@or Y...)))
50 (let ((sym (make-sym)))
51 `(@let ((,sym ,x)) (@if ,sym ,sym (@or ,@rest)))))))
53 ;; (@while TEST BODY...) =>
57 ;; L1: (@if TEST (@goto L0) (@void))
59 (define (@while test . body)
60 (let ((L0 (make-label)) (L1 (make-label)))
64 (@label ,L1) (@if ,test (@goto ,L0) (@void)))))
66 ;; (@cond (TEST BODY...) ...) =>
71 (define (@cond . clauses)
72 (cond ((null? clauses) (error "missing clauses"))
73 ((pair? (car clauses))
74 (let ((c (car clauses)) (l (cdr clauses)))
75 (let ((rest (if (null? l) '(@void) `(@cond ,@l))))
76 (cond ((eq? (car c) '@else) `(@begin (@void) ,@(cdr c)))
77 ((null? (cdr c)) `(@or ,(car c) ,rest))
78 (else `(@if ,(car c) (@begin ,@(cdr c)) ,rest))))))
79 (else (error "bad clause:" (car clauses)))))
81 (define (@let* binds . body)
84 `(@let (,(car binds)) (@let* ,(cdr binds) ,@body))))
91 ;; 6. Standard procedures
93 ;;; 6.1 Equivalence predicates
95 (define (@eq? x y) `(@@ eq? ,x ,y))
96 (define (@eqv? x y) `(@@ eqv? ,x ,y))
97 (define (@equal? x y) `(@@ equal? ,x ,y))
101 (define (@number? x) `(@@ number? ,x))
102 (define (@complex? x) `(@@ complex? ,x))
103 (define (@real? x) `(@@ real? ,x))
104 (define (@rational? x) `(@@ rational? ,x))
105 (define (@integer? x) `(@@ integer? ,x))
107 (define (@exact? x) `(@@ exact? ,x))
108 (define (@inexact? x) `(@@ inexact? ,x))
110 (define (@= x y) `(@@ ee? ,x ,y))
111 (define (@< x y) `(@@ lt? ,x ,y))
112 (define (@> x y) `(@@ gt? ,x ,y))
113 (define (@<= x y) `(@@ le? ,x ,y))
114 (define (@>= x y) `(@@ ge? ,x ,y))
116 (define (@zero? x) `(@= ,x 0))
117 (define (@positive? x) `(@> ,x 0))
118 (define (@negative? x) `(@< ,x 0))
119 (define (@odd? x) `(@= (@modulo ,x 2) 1))
120 (define (@even? x) `(@= (@modulo ,x 2) 0))
122 (define (@max . args) `(@@ max ,@args))
123 (define (@min . args) `(@@ min ,@args))
129 ((x y) `(@@ add ,x ,y))
130 ((x y . rest) `(@@ add ,x (@+ ,y ,@rest)))))
136 ((x y) `(@@ mul ,x ,y))
137 ((x y . rest) `(@@ mul ,x (@* ,y ,@rest)))))
142 ((x y) `(@@ sub ,x ,y))
143 ((x y . rest) `(@@ sub ,x (@+ ,y ,@rest)))))
148 ((x y) `(@@ div ,x ,y))
149 ((x y . rest) `(@@ div ,x (@* ,y ,@rest)))))
151 (define (@abs x) `(@if (@< x 0) (@- x) x))
153 (define (@quotient x y) `(@@ quotient ,x ,y))
154 (define (@remainder x y) `(@@ remainder ,x ,y))
155 (define (@modulo x y) `(@@ modulo ,x ,y))
195 ;;; 6.3 Other data types
199 (define (@not x) `(@@ not ,x))
200 (define (@boolean? x) `(@@ boolean? ,x))
202 ;;;; 6.3.2 Pairs and lists
204 (define (@pair? x) `(@@ pair? ,x))
205 (define (@cons x y) `(@@ cons ,x ,y))
207 (define (@car x) `(@@ car ,x))
208 (define (@cdr x) `(@@ cdr ,x))
209 (define (@set-car! x) `(@@ set-car! ,x))
210 (define (@set-cdr! x) `(@@ set-cdr! ,x))
212 (define (@caar x) `(@@ car (@@ car ,x)))
213 (define (@cadr x) `(@@ car (@@ cdr ,x)))
214 (define (@cdar x) `(@@ cdr (@@ car ,x)))
215 (define (@cddr x) `(@@ cdr (@@ cdr ,x)))
216 (define (@caaar x) `(@@ car (@@ car (@@ car ,x))))
217 (define (@caadr x) `(@@ car (@@ car (@@ cdr ,x))))
218 (define (@cadar x) `(@@ car (@@ cdr (@@ car ,x))))
219 (define (@caddr x) `(@@ car (@@ cdr (@@ cdr ,x))))
220 (define (@cdaar x) `(@@ cdr (@@ car (@@ car ,x))))
221 (define (@cdadr x) `(@@ cdr (@@ car (@@ cdr ,x))))
222 (define (@cddar x) `(@@ cdr (@@ cdr (@@ car ,x))))
223 (define (@cdddr x) `(@@ cdr (@@ cdr (@@ cdr ,x))))
224 (define (@caaaar x) `(@@ car (@@ car (@@ car (@@ car ,x)))))
225 (define (@caaadr x) `(@@ car (@@ car (@@ car (@@ cdr ,x)))))
226 (define (@caadar x) `(@@ car (@@ car (@@ cdr (@@ car ,x)))))
227 (define (@caaddr x) `(@@ car (@@ car (@@ cdr (@@ cdr ,x)))))
228 (define (@cadaar x) `(@@ car (@@ cdr (@@ car (@@ car ,x)))))
229 (define (@cadadr x) `(@@ car (@@ cdr (@@ car (@@ cdr ,x)))))
230 (define (@caddar x) `(@@ car (@@ cdr (@@ cdr (@@ car ,x)))))
231 (define (@cadddr x) `(@@ car (@@ cdr (@@ cdr (@@ cdr ,x)))))
232 (define (@cdaaar x) `(@@ cdr (@@ car (@@ car (@@ car ,x)))))
233 (define (@cdaadr x) `(@@ cdr (@@ car (@@ car (@@ cdr ,x)))))
234 (define (@cdadar x) `(@@ cdr (@@ car (@@ cdr (@@ car ,x)))))
235 (define (@cdaddr x) `(@@ cdr (@@ car (@@ cdr (@@ cdr ,x)))))
236 (define (@cddaar x) `(@@ cdr (@@ cdr (@@ car (@@ car ,x)))))
237 (define (@cddadr x) `(@@ cdr (@@ cdr (@@ car (@@ cdr ,x)))))
238 (define (@cdddar x) `(@@ cdr (@@ cdr (@@ cdr (@@ car ,x)))))
239 (define (@cddddr x) `(@@ cdr (@@ cdr (@@ cdr (@@ cdr ,x)))))
241 (define (@null? x) `(@@ null? ,x))
242 (define (@list? x) `(@@ list? ,x))
243 (define (@list . args) `(@@ list ,@args))
265 ;;;; 6.3.4 Characters
327 ;;;; 6.4 Control features
329 (define (@procedure? x) `(@@ procedure? x))
331 ;; (define (@apply proc . args) ...)
336 ;;; (define (@force promise) `(@@ force promise))
338 ;;; (define (@call-with-current-continuation proc) `(@@ call/cc proc))
340 ;;; (define @call/cc @call-with-current-continuation)
349 ;;; scheme-report-environment
351 ;;; interaction-environment
353 ;;; 6.6 Input and output
357 ;;; call-with-input-file
358 ;;; call-with-output-file
362 ;;; current-input-port
363 ;;; current-output-port
365 ;;; with-input-from-file
366 ;;; with-output-to-file
371 ;;; close-output-port
388 ;;;; 6.6.4 System interface
396 ;;; Non-R5RS Procedures
402 ((x y) `(@cons ,x ,y))
403 ((x y . rest) `(@cons ,x (@cons* ,y ,@rest)))))
405 (define (@error . args) `(@@ display ,@args))
407 (define (@current-module)
408 `((@ System::Base::module::current-module)))