1 ;;;;------------------------------------------------------------------
3 ;;;; Copyright (C) 2001-2005,
4 ;;;; Department of Computer Science, University of Tromso, Norway.
6 ;;;; For distribution policy, see the accompanying file COPYING.
8 ;;;; Filename: stream-image.lisp
10 ;;;; Author: Frode Vatvedt Fjeld <frodef@acm.org>
11 ;;;; Created at: Mon Aug 27 14:46:50 2001
13 ;;;; $Id: stream-image.lisp,v 1.13 2005/05/03 20:12:42 ffjeld Exp $
15 ;;;;------------------------------------------------------------------
21 (defclass stream-image
(movitz-image)
27 :accessor image-stream-offset
)
29 :initarg
:start-address
31 :reader image-start-address
)
34 :initform
(if (boundp '*image
*)
35 (image-nil-word *image
*)
37 (format *query-io
* "~&Please enter the stream-images NIL value: ")
39 :reader image-nil-word
)
41 :initform
(make-movitz-nil)
42 :reader image-nil-object
)))
44 (defmethod image-register32 ((image stream-image
) register-name
)
45 (declare (ignorable image
) (ignore register-name
))
46 (error "A stream-image has no CPU state."))
48 (defmethod (setf image-stream-position
) (value (image stream-image
) &optional physicalp
)
49 (check-type value
(integer 0 *))
50 (assert (file-position (image-stream image
)
51 (+ (image-stream-offset image
)
52 (if physicalp
0 (image-ds-segment-base image
))
55 "Unable to set memory-stream's file-position to #x~X." value
))
57 (defmethod image-run-time-context ((image stream-image
))
58 (movitz-word (image-register32 image
:edi
)))
60 (defmethod movitz-word-by-image ((image stream-image
) word
)
61 (let ((object (case (extract-tag word
)
62 ((:even-fixnum
:odd-fixnum
)
63 (make-instance 'movitz-fixnum
:value
(ldb (byte 29 2) word
)))
65 (setf (image-stream-position image
) (extract-pointer word
))
66 (read-binary 'movitz-cons
(image-stream image
)))
68 (make-instance 'movitz-character
:char
(code-char (ldb (byte 8 8) word
))))
70 (image-nil-object image
))
72 ;; (warn "loading new symbol at ~S" word)
73 (if (= word
#x7fffffff
)
74 (make-instance 'movitz-unbound-value
)
76 (setf (image-stream-position image
)
77 (- word
(tag :symbol
)))
78 (read-binary 'movitz-symbol
(image-stream image
)))))
80 (setf (image-stream-position image
)
81 (+ 0 (extract-pointer word
)))
82 (let* ((type-code (read-binary 'u8
(image-stream image
)))
83 (type-tag (enum-symbolic-value 'other-type-byte type-code
)))
84 (setf (image-stream-position image
)
85 (extract-pointer word
))
88 (read-binary 'movitz-funobj
(image-stream image
)))
90 (read-binary 'movitz-basic-vector
(image-stream image
)))
92 (read-binary 'movitz-struct
(image-stream image
)))
94 (read-binary 'movitz-std-instance
(image-stream image
)))
96 (read-binary 'movitz-bignum
(image-stream image
)))
98 (read-binary 'movitz-run-time-context
(image-stream image
)))
99 (t (warn "unknown other object: #x~X: ~S code #x~X."
100 word type-tag type-code
)
101 (make-instance 'movitz-fixnum
:value
(truncate word
4))))))
102 (t (make-instance 'movitz-fixnum
:value
0)))))
103 (when (typep object
'movitz-heap-object
)
104 (setf (movitz-heap-object-word object
) word
))
107 (defmethod image-intern-object ((image stream-image
) object
&optional
(size (sizeof object
)))
108 (declare (ignore size
))
109 (movitz-heap-object-word object
))
111 (defmethod image-lisp-to-movitz-object ((image stream-image
) lisp-object
)
112 (etypecase lisp-object
114 (movitz-word-by-image image
(image-nil-word image
)))
116 (make-movitz-fixnum lisp-object
))))
118 (defmethod (setf image-lisp-to-movitz-object
) (movitz-object (image stream-image
) lisp-object
)
119 (declare (ignore lisp-object
))