aboutsummaryrefslogtreecommitdiffstats
path: root/scheme48.init
diff options
context:
space:
mode:
Diffstat (limited to 'scheme48.init')
-rw-r--r--scheme48.init316
1 files changed, 187 insertions, 129 deletions
diff --git a/scheme48.init b/scheme48.init
index 0640120..8f91d54 100644
--- a/scheme48.init
+++ b/scheme48.init
@@ -8,28 +8,42 @@
,config
,load =scheme48/misc/packages.scm
(define-structure slib-primitives
- (export s48-getenv
+ (export s48-modulo s48-atan s48-char->integer
+ s48-getenv s48-current-time s48-time-seconds
s48-system
s48-current-error-port
s48-force-output
s48-with-handler
s48-ascii->char
- s48-error)
- (open scheme signals ascii extended-ports i/o primitives handle
- unix-getenv ;Comment out for versions >= 0.54
-;;; posix ;Comment out for versions < 0.54
- )
- (begin
- (define s48-getenv
- getenv ;Comment out for versions >= 0.54
-;;; lookup-environment-variable ;Comment out for versions < 0.54
- )
- (define s48-system (lambda (c) (vm-extension 96 c)))
- (define s48-current-error-port current-error-port)
- (define s48-force-output force-output)
- (define s48-with-handler with-handler)
- (define s48-ascii->char ascii->char)
- (define s48-error error)))
+ s48-error s48-warn
+ s48-make-string-input-port
+ s48-make-string-output-port
+ s48-string-output-port-output
+ s48-exit)
+ (open (modify scheme
+ (rename (modulo s48-modulo) (atan s48-atan)
+ (char->integer s48-char->integer)))
+ ; primitives
+ (modify posix
+ (rename (current-time s48-current-time)
+ (time-seconds s48-time-seconds)
+ (lookup-environment-variable s48-getenv)))
+ (modify c-system-function (rename (system s48-system)))
+ (modify i/o
+ (rename (current-error-port s48-current-error-port)
+ (force-output s48-force-output)))
+ (modify handle (rename (with-handler s48-with-handler)))
+ (modify ascii (rename (ascii->char s48-ascii->char)))
+ (modify signals (rename (error s48-error) (warn s48-warn)))
+ (modify root-scheduler (rename (scheme-exit-now s48-exit)))
+ (modify extended-ports
+ (rename (make-string-input-port
+ s48-make-string-input-port)
+ (make-string-output-port
+ s48-make-string-output-port)
+ (string-output-port-output
+ s48-string-output-port-output))))
+ (begin #t))
,user
,open slib-primitives
@@ -71,33 +85,98 @@
;;; (home-vicinity) should return the vicinity of the user's HOME
;;; directory, the directory which typically contains files which
;;; customize a computer environment for a user.
+;;;
+;;; Ivan Shmakov points out that evaluating (getenv "HOME") when
+;;; compiling captures the installer's home directory. So delay until
+;;; HOME-VICINITY is called.
(define (home-vicinity)
(let ((home (getenv "HOME")))
(and home
+ (if (eqv? #\/ (string-ref home (+ -1 (string-length home))))
+ home
+ (string-append home "/")))))
+;@
+(define in-vicinity string-append)
+;@
+(define (user-vicinity)
+ (case (software-type)
+ ((VMS) "[.]")
+ (else "")))
+
+(define *load-pathname* #f)
+;@
+(define vicinity:suffix?
+ (let ((suffi
(case (software-type)
- ((UNIX COHERENT MS-DOS) ;V7 unix has a / on HOME
- (if (eqv? #\/ (string-ref home (+ -1 (string-length home))))
- home
- (string-append home "/")))
- (else home)))))
-
-(let* ((siv (scheme-implementation-version))
- (num-ver (and siv (string->number siv))))
- (cond ((not num-ver))
- ((>= num-ver 0.54)
- (set! system #f))))
-
-;;; *FEATURES* should be set to a list of symbols describing features
-;;; of this implementation. See Template.scm for the list of feature
-;;; names.
+ ((AMIGA) '(#\: #\/))
+ ((MACOS THINKC) '(#\:))
+ ((MS-DOS WINDOWS ATARIST OS/2) '(#\\ #\/))
+ ((NOSVE) '(#\: #\.))
+ ((UNIX COHERENT PLAN9) '(#\/))
+ ((VMS) '(#\: #\]))
+ (else
+ (slib:warn "require.scm" 'unknown 'software-type (software-type))
+ "/"))))
+ (lambda (chr) (and (memv chr suffi) #t))))
+;@
+(define (pathname->vicinity pathname)
+ (let loop ((i (- (string-length pathname) 1)))
+ (cond ((negative? i) "")
+ ((vicinity:suffix? (string-ref pathname i))
+ (substring pathname 0 (+ i 1)))
+ (else (loop (- i 1))))))
+(define (program-vicinity)
+ (if *load-pathname*
+ (pathname->vicinity *load-pathname*)
+ (slib:error 'program-vicinity " called; use slib:load to load")))
+;@
+(define sub-vicinity
+ (case (software-type)
+ ((VMS) (lambda
+ (vic name)
+ (let ((l (string-length vic)))
+ (if (or (zero? (string-length vic))
+ (not (char=? #\] (string-ref vic (- l 1)))))
+ (string-append vic "[" name "]")
+ (string-append (substring vic 0 (- l 1))
+ "." name "]")))))
+ (else (let ((*vicinity-suffix*
+ (case (software-type)
+ ((NOSVE) ".")
+ ((MACOS THINKC) ":")
+ ((MS-DOS WINDOWS ATARIST OS/2) "\\")
+ ((UNIX COHERENT PLAN9 AMIGA) "/"))))
+ (lambda (vic name)
+ (string-append vic name *vicinity-suffix*))))))
+;@
+(define (make-vicinity <pathname>) <pathname>)
+;@
+(define with-load-pathname
+ (let ((exchange
+ (lambda (new)
+ (let ((old *load-pathname*))
+ (set! *load-pathname* new)
+ old))))
+ (lambda (path thunk)
+ (let ((old #f))
+ (dynamic-wind
+ (lambda () (set! old (exchange path)))
+ thunk
+ (lambda () (exchange old)))))))
+
+;;@ *FEATURES* is a list of symbols naming the (SLIB) features
+;;; initially supported by this implementation.
(define *features*
'(
source ;can load scheme source files
- ;(slib:load-source "filename")
-; compiled ;can load compiled files
- ;(slib:load-compiled "filename")
+ ;(SLIB:LOAD-SOURCE "filename")
+;;; compiled ;can load compiled files
+ ;(SLIB:LOAD-COMPILED "filename")
+ vicinity
+ srfi-59
;; Scheme report features
+ ;; R5RS-compliant implementations should provide all 9 features.
r5rs ;conforms to
eval ;R5RS two-argument eval
@@ -107,59 +186,60 @@
delay ;has DELAY and FORCE
multiarg-apply ;APPLY can take more than 2 args.
char-ready?
+ rev4-optional-procedures ;LIST-TAIL, STRING-COPY,
+ ;STRING-FILL!, and VECTOR-FILL!
+
+ ;; These four features are optional in both R4RS and R5RS
+
+;;; multiarg/and- ;/ and - can take more than 2 args.
rationalize
- rev4-optional-procedures ;LIST-TAIL, STRING->LIST,
- ;LIST->STRING, STRING-COPY,
- ;STRING-FILL!, LIST->VECTOR,
- ;VECTOR->LIST, and VECTOR-FILL!
+;;; transcript ;TRANSCRIPT-ON and TRANSCRIPT-OFF
+ with-file ;has WITH-INPUT-FROM-FILE and
+ ;WITH-OUTPUT-TO-FILE
r4rs ;conforms to
ieee-p1178 ;conforms to
-; r3rs ;conforms to
+;;; r3rs ;conforms to
-; rev2-procedures ;SUBSTRING-MOVE-LEFT!,
+;;; rev2-procedures ;SUBSTRING-MOVE-LEFT!,
;SUBSTRING-MOVE-RIGHT!,
;SUBSTRING-FILL!,
;STRING-NULL?, APPEND!, 1+,
;-1+, <?, <=?, =?, >?, >=?
-; object-hash ;has OBJECT-HASH
+;;; object-hash ;has OBJECT-HASH
-; multiarg/and- ;/ and - can take more than 2 args.
- with-file ;has WITH-INPUT-FROM-FILE and
- ;WITH-OUTPUT-TO-FILE
-; transcript ;TRANSCRIPT-ON and TRANSCRIPT-OFF
-; ieee-floating-point ;conforms to IEEE Standard 754-1985
+ full-continuation ;can return multiple times
+;;; ieee-floating-point ;conforms to IEEE Standard 754-1985
;IEEE Standard for Binary
;Floating-Point Arithmetic.
- full-continuation ;can return multiple times
;; Other common features
-; srfi ;srfi-0, COND-EXPAND finds all srfi-*
-; sicp ;runs code from Structure and
+;;; srfi ;srfi-0, COND-EXPAND finds all srfi-*
+;;; sicp ;runs code from Structure and
;Interpretation of Computer
;Programs by Abelson and Sussman.
defmacro ;has Common Lisp DEFMACRO
-; record ;has user defined data structures
-; string-port ;has CALL-WITH-INPUT-STRING and
+;;; record ;has user defined data structures
+ string-port ;has CALL-WITH-INPUT-STRING and
;CALL-WITH-OUTPUT-STRING
-; sort
-; pretty-print
-; object->string
-; format ;Common-lisp output formatting
-; trace ;has macros: TRACE and UNTRACE
-; compiler ;has (COMPILER)
-; ed ;(ED) is editor
+;;; sort
+;;; pretty-print
+;;; object->string
+;;; format ;Common-lisp output formatting
+;;; trace ;has macros: TRACE and UNTRACE
+;;; compiler ;has (COMPILER)
+;;; ed ;(ED) is editor
+ system ;posix (system <string>)
getenv ;posix (getenv <string>)
-; program-arguments ;returns list of strings (argv)
-; current-time ;returns time in seconds since 1/1/1970
+;;; program-arguments ;returns list of strings (argv)
+ current-time ;returns time in seconds since 1/1/1970
+
;; Implementation Specific features
- ))
-(if system ;posix (system <string>)
- (set! *features* (cons 'system *features*)))
+ ))
;;; (OUTPUT-PORT-WIDTH <port>)
(define (output-port-width . arg) 79)
@@ -190,7 +270,7 @@
;;; (DELETE-FILE <string>)
(define (delete-file file-name)
- (s48-system (string-append "rm " file-name)))
+ (system (string-append "rm " file-name)))
;;; FORCE-OUTPUT flushes any pending output on optional arg output port
;;; use this definition if your system doesn't have such a procedure.
@@ -200,11 +280,19 @@
(define (make-exchanger obj)
(lambda (rep) (let ((old obj)) (set! obj rep) old)))
+
+;@
(define (open-file filename modes)
- (case modes
- ((r rb) (open-input-file filename))
- ((w wb) (open-output-file filename))
- (else (slib:error 'open-file 'mode? modes))))
+ (call-with-current-continuation
+ (lambda (k)
+ (s48-with-handler
+ (lambda (condition decline)
+ (k #f))
+ (case modes
+ ((r rb) (lambda () (open-input-file filename)))
+ ((w wb) (lambda () (open-output-file filename)))
+ (else (slib:error 'open-file 'mode? modes)))))))
+
(define (port? obj) (or (input-port? port) (output-port? port)))
(define (call-with-open-ports . ports)
(define proc (car ports))
@@ -238,36 +326,11 @@
;;; CHAR-CODE-LIMIT is one greater than the largest integer which can
;;; be returned by CHAR->INTEGER.
+(define char-code-limit 256)
(define integer->char s48-ascii->char)
(define char->integer
- (let ((char->integer char->integer)
- (code0 (char->integer (integer->char 0))))
- (lambda (char) (- (char->integer char) code0))))
-(define char-code-limit 256)
-
-;;; Workaround MODULO bug
-(define modulo
- (let ((modulo modulo))
- (lambda (n1 n2)
- (let ((ans (modulo n1 n2)))
- (if (= ans n2) (- ans ans) ans)))))
-
-;;; Workaround atan bug
-(define two-arg:atan atan)
-(define (atan y . x)
- (if (null? x) (two-arg:atan y 1) (two-arg:atan y (car x))))
-;;; asin is totally busted
-(define (asin y) (two-arg:atan y (sqrt (- 1 (* y y)))))
-
-;;; Workaround inexact->exact and exact->inexact bugs.
-(define inexact->exact
- (let ((i->e inexact->exact))
- (lambda (z)
- (if (exact? z) z (i->e z)))))
-(define exact->inexact
- (let ((e->i exact->inexact))
- (lambda (z)
- (if (inexact? z) z (e->i z)))))
+ (let ((code0 (s48-char->integer (integer->char 0))))
+ (lambda (char) (- (s48-char->integer char) code0))))
;;; MOST-POSITIVE-FIXNUM is used in modular.scm
(define most-positive-fixnum #x1FFFFFFF)
@@ -324,35 +387,15 @@
(define (defmacro:eval x) (base:eval (defmacro:expand* x)))
(define defmacro:load macro:load)
+;; slib:eval-load definition moved to "require.scm"
-(define (slib:eval-load <pathname> evl)
- (if (not (file-exists? <pathname>))
- (set! <pathname> (string-append <pathname> (scheme-file-suffix))))
- (call-with-input-file <pathname>
- (lambda (port)
- (let ((old-load-pathname *load-pathname*))
- (set! *load-pathname* <pathname>)
- (do ((o (read port) (read port)))
- ((eof-object? o))
- (evl o))
- (set! *load-pathname* old-load-pathname)))))
-
-(define slib:warn
- (lambda args
- (let ((cep (current-error-port)))
- (if (provided? 'trace) (print-call-stack cep))
- (display "Warn: " cep)
- (write (car args) cep)
- (newline cep)
- (for-each (lambda (x)
- (display " " cep)
- (write x cep)
- (newline cep))
- (cdr args)))))
+(define (slib:warn . args)
+ ;;(if (provided? 'trace) (print-call-stack cep))
+ (apply s48-warn args))
;;; define an error procedure for the library
(define (slib:error . args)
- (if (provided? 'trace) (print-call-stack (current-error-port)))
+ ;;(if (provided? 'trace) (print-call-stack (current-error-port)))
(apply s48-error args))
;;; define these as appropriate for your system.
@@ -371,11 +414,10 @@
(define (-1+ n) (+ n -1))
;(define 1- -1+)
-(define in-vicinity string-append)
-
;;; Define SLIB:EXIT to be the implementation procedure to exit or
-;;; return if exitting not supported.
-(define slib:exit (lambda args #f))
+;;; return if exiting not supported.
+(define (slib:exit . opt)
+ (s48-exit (if (pair? opt) (car opt) 0)))
;;; Here for backward compatability
(define scheme-file-suffix
@@ -385,7 +427,6 @@
;;; (SLIB:LOAD-SOURCE "foo") should load "foo.scm" or with whatever
;;; suffix all the module files in SLIB have. See feature 'SOURCE.
-
(define (slib:load-source f) (load (string-append f (scheme-file-suffix))))
;;; (SLIB:LOAD-COMPILED "foo") should load the file that was produced
@@ -425,9 +466,26 @@
(require 'defmacroexpand)
(define *args* '())
(define (program-arguments) (cons "scheme48" *args*))
-(set! *catalog* #f)
+
+;@
+(define (call-with-output-string proc)
+ (let ((port (s48-make-string-output-port)))
+ (proc port)
+ (s48-string-output-port-output port)))
+(define (call-with-input-string string proc)
+ (proc (s48-make-string-input-port string)))
+
+;@
+(define (current-time)
+ (s48-time-seconds (s48-current-time)))
+(define (difftime caltime1 caltime0)
+ (- caltime1 caltime0))
+(define (offset-time caltime offset)
+ (+ caltime offset))
+
+(require #f)
,collect
,batch off
-,dump slib.image "(slib 3a1)"
+,dump slib.image "(slib 3a2)"
,exit