add vocabulary to forge-env, with searching in chained vocabulary entries
This commit is contained in:
parent
dcb5208a25
commit
3cfb89d9fd
1 changed files with 10 additions and 2 deletions
|
@ -13,7 +13,9 @@
|
|||
(defclass forge-env ()
|
||||
((data-stack :initform nil
|
||||
:reader data-stack
|
||||
:accessor data-stack!)))
|
||||
:accessor data-stack!)
|
||||
(vocabulary :initform (list *builtins*)
|
||||
:accessor vocabulary)))
|
||||
|
||||
(defun forge-env ()
|
||||
(make-instance 'forge-env))
|
||||
|
@ -21,12 +23,18 @@
|
|||
(defun exec (fe code)
|
||||
(dolist (x code)
|
||||
(if (symbolp x)
|
||||
(funcall (gethash (string-downcase (symbol-name x)) *builtins*) fe)
|
||||
(funcall (find-word (vocabulary fe) x) fe)
|
||||
(pushd fe x))))
|
||||
|
||||
(defun register (voc key fn)
|
||||
(setf (gethash (string-downcase (symbol-name key)) voc) fn))
|
||||
|
||||
(defun find-word (vocab key)
|
||||
(let ((k (string-downcase (symbol-name key))) (result nil))
|
||||
(dolist (voc vocab)
|
||||
(let ((v (gethash k voc)))
|
||||
(if v (return v))))))
|
||||
|
||||
; built-in primitives
|
||||
|
||||
(defun reg-b (key fn) (register *builtins* key fn))
|
||||
|
|
Loading…
Add table
Reference in a new issue