Changeset 4907
- Timestamp:
- Jul 24, 2006, 3:55:14 AM (18 years ago)
- File:
-
- 1 edited
-
trunk/ccl/level-1/l1-streams.lisp (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ccl/level-1/l1-streams.lisp
r4901 r4907 33 33 ()) 34 34 35 35 36 (defclass input-stream (stream) 36 ((shared-resource :initform nil :accessor input-stream-shared-resource))) 37 ()) 38 37 39 38 40 (defclass output-stream (stream) ()) … … 1084 1086 (declare (dynamic-extent initargs)) 1085 1087 (let* ((class (find-class class-name)) 1086 (s (apply #'make-instance class :allow-other-keys t initargs))) 1088 (s 1089 (if (subtypep class (find-class 'basic-stream)) 1090 (apply #'make-basic-stream-instance class :allow-other-keys t initargs) 1091 (apply #'make-instance class :allow-other-keys t initargs)))) 1087 1092 (apply #'init-stream-ioblock s initargs) 1088 1093 s)) 1089 1094 1095 1090 1096 1091 1097 … … 1098 1104 (defmethod select-stream-class ((s standard-class) in-p out-p char-p) 1099 1105 (select-stream-class (class-prototype s) in-p out-p char-p)) 1106 1100 1107 1101 1108 … … 1106 1113 (element-type 'character) 1107 1114 (class 'fd-stream) 1108 (sharing :private)) 1115 (sharing :private) 1116 (basic nil)) 1117 (when basic 1118 (setq class (map-to-basic-stream-class-name class)) 1119 (setq basic (subtypep (find-class class) 'basic-stream))) 1109 1120 (let* ((in-p (member direction '(:io :input))) 1110 1121 (out-p (member direction '(:io :output))) … … 1119 1130 :element-type element-type 1120 1131 :advance-function (if in-p 1121 (select-stream-advance-function class)) 1132 (if basic 1133 'fd-stream-advance 1134 (select-stream-advance-function class))) 1122 1135 :listen-function (if in-p 'fd-stream-listen) 1123 1136 :eofp-function (if in-p 'fd-stream-eofp) 1124 1137 :force-output-function (if out-p 1125 (select-stream-force-output-function class)) 1138 (if basic 1139 'fd-stream-force-output 1140 (select-stream-force-output-function class))) 1126 1141 :close-function 'fd-stream-close 1127 1142 :sharing sharing … … 1134 1149 1135 1150 (defclass fundamental-input-stream (fundamental-stream input-stream) 1136 ( ))1151 ((shared-resource :initform nil :accessor input-stream-shared-resource))) 1137 1152 1138 1153 (defclass fundamental-output-stream (fundamental-stream output-stream) … … 1224 1239 binary-output-stream) 1225 1240 ()) 1241 1226 1242 1227 1243 … … 1321 1337 (return i) 1322 1338 (setf (uvref vector i) b))))) 1339 1340 1341 1342 ;;; File streams, in the abstract. 1343 1344 (defclass file-stream (stream) 1345 ()) 1346 1347 1348 1349 ;;; "Basic" (non-extensible) streams. 1350 1351 1352 (defun basic-stream-p (x) 1353 (= (the fixnum (typecode x)) target::subtag-basic-stream)) 1354 1355 (setf (type-predicate 'basic-stream) 'basic-stream-p) 1356 1357 (make-built-in-class 'basic-stream 'stream) 1358 (make-built-in-class 'basic-file-stream 'basic-stream 'file-stream) 1359 (make-built-in-class 'basic-character-stream 'basic-stream 'character-stream) 1360 (make-built-in-class 'basic-binary-stream 'basic-stream 'binary-stream) 1361 1362 (make-built-in-class 'basic-input-stream 'basic-stream 'input-stream) 1363 (make-built-in-class 'basic-output-stream 'basic-stream 'input-stream) 1364 (make-built-in-class 'basic-character-input-stream 'basic-input-stream 'basic-character-stream) 1365 (make-built-in-class 'basic-character-output-stream 'basic-output-stream 'basic-character-stream) 1366 (make-built-in-class 'basic-character-io-stream 'basic-character-input-stream 'basic-character-output-stream) 1367 (make-built-in-class 'basic-binary-input-stream 'basic-input-stream 'basic-binary-stream) 1368 (make-built-in-class 'basic-binary-output-stream 'basic-output-stream 'basic-binary-stream) 1369 (make-built-in-class 'basic-binary-io-stream 'basic-binary-input-stream 'basic-binary-output-stream) 1370 1371 1372 (defmethod select-stream-class ((s (eql 'basic-stream)) in-p out-p char-p) 1373 (if char-p 1374 (if in-p 1375 (if out-p 1376 'basic-character-io-stream 1377 'basic-character-input-stream) 1378 'basic-character-output-stream) 1379 (if in-p 1380 (if out-p 1381 'basic-binary-io-stream 1382 'basic-binary-input-stream) 1383 'basic-binary-output-stream))) 1384 1385 1386 (defmethod map-to-basic-stream-class-name (name) 1387 name) 1388 1389 (defmethod map-to-basic-stream-class-name ((name (eql 'fd-stream))) 1390 'basic-stream) 1391 1392 (defun allocate-basic-stream (class) 1393 (if (subtypep class 'basic-file-stream) 1394 (gvector :basic-stream class 0 nil nil nil nil) 1395 (gvector :basic-stream class 0 nil nil))) 1396 1397 (defmethod initialize-basic-stream ((s basic-stream) &key &allow-other-keys) 1398 ) 1399 1400 (defmethod initialize-basic-stream :after ((s basic-input-stream) &key &allow-other-keys) 1401 (setf (basic-stream.flags s) 1402 (logior (ash 1 basic-stream-flag.open-input) (basic-stream.flags s)))) 1403 1404 (defmethod initialize-basic-stream :after ((s basic-output-stream) &key &allow-other-keys) 1405 (setf (basic-stream.flags s) 1406 (logior (ash 1 basic-stream-flag.open-output) (basic-stream.flags s)))) 1407 1408 (defmethod initialize-basic-stream :after ((s basic-binary-stream) &key &allow-other-keys) 1409 (setf (basic-stream.flags s) 1410 (logior (ash 1 basic-stream-flag.open-binary) (basic-stream.flags s)))) 1411 1412 (defun make-basic-stream-instance (class &rest initargs) 1413 (let* ((s (allocate-basic-stream class))) 1414 (apply #'initialize-basic-stream s initargs) 1415 s)) 1416 1417 (defmethod %stream-ioblock ((s basic-stream)) 1418 (basic-stream.state s)) 1419 1420 (defmethod (setf stream-ioblock) (ioblock (s basic-stream)) 1421 (setf (basic-stream.state s) ioblock)) 1422 1423 (defmethod stream-create-ioblock ((stream basic-stream) &rest args &key) 1424 (declare (dynamic-extent args)) 1425 (apply #'make-ioblock :stream stream args)) 1426 1427 (defmethod stream-read-char ((s basic-character-input-stream)) 1428 (let* ((ioblock (basic-stream.state s))) 1429 (if ioblock 1430 (funcall (ioblock-read-char-function ioblock) ioblock) 1431 (error "~s is closed" s)))) 1432 1433 1434 1323 1435 1324 1436 ;;; Synonym streams. … … 1941 2053 1942 2054 (defun stream-ioblock (stream error-if-nil) 1943 (with-slots (ioblock) stream 1944 (or ioblock 1945 (when error-if-nil 1946 (error "~s is closed" stream))))) 2055 (or (%stream-ioblock stream) 2056 (when error-if-nil 2057 (error "~s is closed" stream)))) 1947 2058 1948 2059 (defmethod stream-device ((s buffered-stream-mixin) direction) … … 2379 2490 'fd-stream-advance) 2380 2491 2492 2381 2493 (defmethod select-stream-force-output-function ((s symbol)) 2382 2494 (select-stream-force-output-function (find-class s))) … … 2574 2686 2575 2687 ;;;File streams. 2576 (defparameter *use-new-file-streams* t)2577 2578 (defparameter *default-file-stream-class* 'file-stream)2579 2688 2580 2689 (defun open (filename &key (direction :input) … … 2589 2698 (t :create))) 2590 2699 (external-format :default) 2591 (class *default-file-stream-class*)2700 (class 'file-stream) 2592 2701 (elements-per-buffer *elements-per-buffer*) 2593 2702 (sharing :private))
Note:
See TracChangeset
for help on using the changeset viewer.
