compile code in def
This commit is contained in:
parent
df88bec20a
commit
27fb32feb2
2 changed files with 21 additions and 8 deletions
|
@ -28,9 +28,10 @@
|
||||||
|
|
||||||
(defun exec (fe code)
|
(defun exec (fe code)
|
||||||
(dolist (x code)
|
(dolist (x code)
|
||||||
(if (symbolp x)
|
(typecase x
|
||||||
(funcall (find-word (vocabulary fe) x) fe)
|
(symbol (funcall (find-word (vocabulary fe) x) fe))
|
||||||
(pushd fe x))))
|
(compiled-function (funcall x fe))
|
||||||
|
(t (pushd fe x)))))
|
||||||
|
|
||||||
(defun register (voc key fn)
|
(defun register (voc key fn)
|
||||||
(let ((k (if (symbolp key) (symbol-name key) key)))
|
(let ((k (if (symbolp key) (symbol-name key) key)))
|
||||||
|
@ -46,6 +47,18 @@
|
||||||
(do ((input (read-line) (read-line))) ((string= input "q") nil)
|
(do ((input (read-line) (read-line))) ((string= input "q") nil)
|
||||||
(exec-str fe input)))
|
(exec-str fe input)))
|
||||||
|
|
||||||
|
(defun comp (fe inp)
|
||||||
|
(let ((code nil))
|
||||||
|
(dolist (item inp)
|
||||||
|
(setf code (cons (comp1 fe item) code)))
|
||||||
|
(reverse code)))
|
||||||
|
|
||||||
|
(defun comp1 (fe item)
|
||||||
|
(format t "~%item: ~a" item)
|
||||||
|
(typecase item
|
||||||
|
(symbol (find-word (vocabulary fe) item))
|
||||||
|
(t item)))
|
||||||
|
|
||||||
; built-in primitives
|
; built-in primitives
|
||||||
|
|
||||||
(defun reg-b (key fn) (register *builtins* key fn))
|
(defun reg-b (key fn) (register *builtins* key fn))
|
||||||
|
@ -59,8 +72,8 @@
|
||||||
(reg-b "??" #'(lambda (fe) (format t "~a~%" (data-stack fe))))
|
(reg-b "??" #'(lambda (fe) (format t "~a~%" (data-stack fe))))
|
||||||
|
|
||||||
(reg-b "def" #'(lambda (fe)
|
(reg-b "def" #'(lambda (fe)
|
||||||
(let ((name (popd fe))
|
(let* ((name (popd fe))
|
||||||
(code (popd fe)))
|
(code (comp fe (popd fe))))
|
||||||
(register (voc fe) name #'(lambda (fe) (exec fe code))))))
|
(register (voc fe) name #'(lambda (fe) (exec fe code))))))
|
||||||
|
|
||||||
(reg-b "const" #'(lambda (fe)
|
(reg-b "const" #'(lambda (fe)
|
||||||
|
|
|
@ -20,13 +20,13 @@
|
||||||
(package-name (symbol-package y)))))))
|
(package-name (symbol-package y)))))))
|
||||||
|
|
||||||
(defun x-make-var (value)
|
(defun x-make-var (value)
|
||||||
#'(lambda (&optional (nv nil))
|
#'(lambda (nv)
|
||||||
(if (eq nv nil)
|
(if (null nv)
|
||||||
value
|
value
|
||||||
(setf value nv))))
|
(setf value nv))))
|
||||||
|
|
||||||
(defun x-get-var (vf)
|
(defun x-get-var (vf)
|
||||||
(funcall vf))
|
(funcall vf nil))
|
||||||
|
|
||||||
(defun x-put-var (vf value)
|
(defun x-put-var (vf value)
|
||||||
(funcall vf value))
|
(funcall vf value))
|
||||||
|
|
Loading…
Add table
Reference in a new issue