home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World of Computer Software
/
World_Of_Computer_Software-02-385-Vol-1of3.iso
/
s
/
s48.zip
/
VM
/
UTIL.SCM
< prev
next >
Wrap
Text File
|
1992-06-17
|
3KB
|
115 lines
; -*- Mode: Scheme; Syntax: Scheme; Package: Scheme; -*-
; Copyright (c) 1992 by Richard Kelsey and Jonathan Rees. See file COPYING.
; This is file util.scm
;;;; "Bare machine"
; Random things needed to build the datatypes and GC.
; error
(define unassigned
(let ((marker (list '<unassigned>)))
(lambda () marker)))
; Now defined in macros.scm
;(define (assert test)
; (if (not test) (error "assertion failed")))
(define (make-byte-vector-pointer vector offset)
offset)
(define byte-vector-pointer-ref byte-vector-ref)
(define byte-vector-pointer-set! byte-vector-set!)
(define byte-vector-pointer-word-ref byte-vector-word-ref)
(define byte-vector-pointer-word-set! byte-vector-word-set!)
(define (adjoin-bits high low k)
(+ (ashl high k) low))
(define (low-bits n k)
(bitwise-and n (- (ashl 1 k) 1)))
(define high-bits ashr)
(define (vm-read-char in char-cont eof-cont)
(let ((ch (read-char in)))
(if (eof-object? ch) (eof-cont) (char-cont ch))))
(define bits-per-io-byte 8)
(define (write-byte byte out)
(write-char (ascii->char (bitwise-and byte #xFF)) out))
(define (read-byte in char-cont eof-cont)
(let ((ch (read-char in)))
(if (eof-object? ch) (eof-cont) (char-cont (char->ascii ch)))))
(define (write-number num port)
(write num port)
(newline port))
(define (read-number port)
(read port))
(define (write-page port)
(write-char #\page port))
(define (read-page port)
(let loop ((ch (read-char port)))
(cond ((eof-object? ch)
(error "end of file while looking for page break"))
((not (char=? ch #\page))
(loop (read-char port))))))
;;;; Control primitives
(define *goto-tag* '#f)
(define *exit-status* '#f)
(define goto-token (list '<goto-token>))
(define halt-token (list '<halt-token>))
(define (run-machine start-tag)
(driver-loop start-tag))
(define (driver-loop start-tag)
(set! *goto-tag* start-tag)
(let loop ((token goto-token))
(cond ((eq? token goto-token)
(loop (*goto-tag*)))
((not (eq? token halt-token))
(error "funny label" token))
(else
*exit-status*))))
(define (halt-machine status)
(set! *exit-status* status)
halt-token)
(define (goto tag)
(set! *goto-tag* (label tag))
goto-token)
; Assigned goto (e.g. for return addresses)
(define (label tag)
tag) ; Declaration for (set! *finished* ...)
(define computed-goto goto)
; Dispatch
(define (dispatch table tag)
((vector-ref table tag)))
(define make-dispatch-table make-vector)
(define define-dispatch! vector-set!)