forge/sf: simple repl

This commit is contained in:
Helmut Merz 2024-09-16 11:09:31 +02:00
parent 6eff29f62d
commit 62350964c6

View file

@ -9,7 +9,7 @@
(:export #:forge-env #:vocabulary #:stack #:current-package
#:*forge-env* #:*input* #:*code*
#:word #:comp-word
#:exec-list #:exec-string #:exec-input #:comp-input #:call
#:repl #:exec-list #:exec-string #:exec-input #:comp-input #:call
#:comp-item
#:next #:reg #:reg1 #:reg2 #:reg-code
#:pushd #:popd #:peekd))
@ -81,6 +81,11 @@
;;;; 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)
(let ((*input* (iter:list-iterator lst)))
(exec-input)))
@ -139,7 +144,8 @@
(:local-nicknames (:f :scopes/forge/sf)
(:iter :scopes/util/iter)
(:util :scopes/util))
(:export #:add #:mul #:dup #:swp
(:export #:add #:mul #:drop #:dup #:swp
#:? #:??
#:ptr #:get #:put
#:in #:next
#:call #:call-if #:call-while #:comp
@ -167,6 +173,10 @@
(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 '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 'get #'aref)