forge: first (too simple) version of iter:stream-iterator and forge:exec-stream
This commit is contained in:
parent
90a2f4db27
commit
fe63d977f6
3 changed files with 23 additions and 3 deletions
|
@ -9,7 +9,8 @@
|
|||
(:export #:forge-env #:vocabulary #:stack #:current-package
|
||||
#:*forge-env* #:*input* #:*code*
|
||||
#:word #:comp-word
|
||||
#:repl #:exec-list #:exec-string #:exec-input #:comp-input #:call
|
||||
#:repl #:exec-list #:exec-string #:exec-stream
|
||||
#:exec-input #:comp-input #:call
|
||||
#:comp-item
|
||||
#:next #:reg #:reg1 #:reg2 #:reg-code
|
||||
#:pushd #:popd #:peekd))
|
||||
|
@ -94,6 +95,10 @@
|
|||
(let ((*input* (iter:string-iterator s)))
|
||||
(exec-input)))
|
||||
|
||||
(defun exec-stream (s)
|
||||
(let ((*input* (iter:stream-iterator s)))
|
||||
(exec-input)))
|
||||
|
||||
(defun exec-input ()
|
||||
(iter:process *input* #'exec-item))
|
||||
|
||||
|
|
|
@ -31,7 +31,9 @@
|
|||
(forge:exec-list '(7 square))
|
||||
(== (forge:popd) 49)
|
||||
(forge:exec-string "8 square")
|
||||
(== (forge:popd) 64))
|
||||
(== (forge:popd) 64)
|
||||
(forge:exec-stream (make-string-input-stream "12 square"))
|
||||
(== (forge:popd) 144))
|
||||
|
||||
(deftest test-def ()
|
||||
(forge:exec-list '(<comp in <comp swp reg /> in <def reg))
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
(defpackage :scopes/util/iter
|
||||
(:use :common-lisp)
|
||||
(:export #:stop #:next #:value #:next-value #:process
|
||||
#:list-iterator #:string-iterator))
|
||||
#:list-iterator #:string-iterator #:stream-iterator))
|
||||
|
||||
(in-package :scopes/util/iter)
|
||||
|
||||
|
@ -72,3 +72,16 @@
|
|||
(value it) val)
|
||||
nil)
|
||||
t)))
|
||||
|
||||
;;;; stream iterator implementation
|
||||
|
||||
(defclass stream-iterator (iterator)
|
||||
((data :reader data :initarg :data :initform "")
|
||||
(value :accessor value :initform nil)))
|
||||
|
||||
(defun stream-iterator (s)
|
||||
(make-instance 'stream-iterator :data s))
|
||||
|
||||
(defmethod next ((it stream-iterator))
|
||||
(setf (value it) (read (data it) nil nil))
|
||||
(eql (value it) nil))
|
||||
|
|
Loading…
Add table
Reference in a new issue