forge/sf: simple repl
This commit is contained in:
parent
6eff29f62d
commit
62350964c6
1 changed files with 12 additions and 2 deletions
|
@ -9,7 +9,7 @@
|
||||||
(:export #:forge-env #:vocabulary #:stack #:current-package
|
(:export #:forge-env #:vocabulary #:stack #:current-package
|
||||||
#:*forge-env* #:*input* #:*code*
|
#:*forge-env* #:*input* #:*code*
|
||||||
#:word #:comp-word
|
#:word #:comp-word
|
||||||
#:exec-list #:exec-string #:exec-input #:comp-input #:call
|
#:repl #:exec-list #:exec-string #:exec-input #:comp-input #:call
|
||||||
#:comp-item
|
#:comp-item
|
||||||
#:next #:reg #:reg1 #:reg2 #:reg-code
|
#:next #:reg #:reg1 #:reg2 #:reg-code
|
||||||
#:pushd #:popd #:peekd))
|
#:pushd #:popd #:peekd))
|
||||||
|
@ -81,6 +81,11 @@
|
||||||
|
|
||||||
;;;; code compilation and execution
|
;;;; code compilation and execution
|
||||||
|
|
||||||
|
(defun repl ()
|
||||||
|
(do ((input (read-line) (read-line)))
|
||||||
|
((string= input "q") (stack *forge-env*))
|
||||||
|
(exec-string input)))
|
||||||
|
|
||||||
(defun exec-list (lst)
|
(defun exec-list (lst)
|
||||||
(let ((*input* (iter:list-iterator lst)))
|
(let ((*input* (iter:list-iterator lst)))
|
||||||
(exec-input)))
|
(exec-input)))
|
||||||
|
@ -139,7 +144,8 @@
|
||||||
(:local-nicknames (:f :scopes/forge/sf)
|
(:local-nicknames (:f :scopes/forge/sf)
|
||||||
(:iter :scopes/util/iter)
|
(:iter :scopes/util/iter)
|
||||||
(:util :scopes/util))
|
(:util :scopes/util))
|
||||||
(:export #:add #:mul #:dup #:swp
|
(:export #:add #:mul #:drop #:dup #:swp
|
||||||
|
#:? #:??
|
||||||
#:ptr #:get #:put
|
#:ptr #:get #:put
|
||||||
#:in #:next
|
#:in #:next
|
||||||
#:call #:call-if #:call-while #:comp
|
#:call #:call-if #:call-while #:comp
|
||||||
|
@ -167,6 +173,10 @@
|
||||||
|
|
||||||
(f:reg 'dup #'(lambda () (f:pushd (f:peekd))))
|
(f:reg 'dup #'(lambda () (f:pushd (f:peekd))))
|
||||||
(f:reg 'swp #'(lambda () (let ((a (f:popd)) (b (f:popd))) (f:pushd a) (f:pushd b))))
|
(f:reg 'swp #'(lambda () (let ((a (f:popd)) (b (f:popd))) (f:pushd a) (f:pushd b))))
|
||||||
|
(f:reg 'drop #'f:popd)
|
||||||
|
|
||||||
|
(f:reg '? #'(lambda () (format t "~a~%" (f:popd))))
|
||||||
|
(f:reg '?? #'(lambda () (format t "~a~%" (f:stack f:*forge-env*))))
|
||||||
|
|
||||||
(f:reg1 'ptr #'util:ptr)
|
(f:reg1 'ptr #'util:ptr)
|
||||||
(f:reg1 'get #'aref)
|
(f:reg1 'get #'aref)
|
||||||
|
|
Loading…
Add table
Reference in a new issue