forge/sf: define current-package in forge-env, use for registering and finding words
This commit is contained in:
parent
ee2acbe1b9
commit
66bc23c97a
1 changed files with 11 additions and 8 deletions
|
@ -6,7 +6,7 @@
|
||||||
(:use :common-lisp)
|
(:use :common-lisp)
|
||||||
(:local-nicknames (:iter :scopes/util/iter)
|
(:local-nicknames (:iter :scopes/util/iter)
|
||||||
(:util :scopes/util))
|
(:util :scopes/util))
|
||||||
(:export #:forge-env #:vocabulary #:stack
|
(:export #:forge-env #:vocabulary #:stack #:current-package
|
||||||
#:*forge-env* #:*input* #:*code*
|
#:*forge-env* #:*input* #:*code*
|
||||||
#:word #:comp-word
|
#:word #:comp-word
|
||||||
#:exec-list #:exec-input #:comp-input #:call
|
#:exec-list #:exec-input #:comp-input #:call
|
||||||
|
@ -21,7 +21,8 @@
|
||||||
(defclass forge-env ()
|
(defclass forge-env ()
|
||||||
((vocabulary :reader vocabulary :initform (make-hash-table))
|
((vocabulary :reader vocabulary :initform (make-hash-table))
|
||||||
(func-index :reader func-index :initform (make-hash-table))
|
(func-index :reader func-index :initform (make-hash-table))
|
||||||
(stack :accessor stack :initform nil)))
|
(stack :accessor stack :initform nil)
|
||||||
|
(current-package :accessor current-package :initform :sf-builtin)))
|
||||||
|
|
||||||
(defvar *forge-env* (make-instance 'forge-env))
|
(defvar *forge-env* (make-instance 'forge-env))
|
||||||
|
|
||||||
|
@ -54,10 +55,11 @@
|
||||||
(comp-item v)))))
|
(comp-item v)))))
|
||||||
|
|
||||||
(defun find-word (sym)
|
(defun find-word (sym)
|
||||||
(multiple-value-bind (val found) (gethash sym (vocabulary *forge-env*))
|
(let ((sym (find-symbol (symbol-name sym) (current-package *forge-env*))))
|
||||||
(when (not found)
|
(multiple-value-bind (val found) (gethash sym (vocabulary *forge-env*))
|
||||||
(util:lgw "not found" sym))
|
(when (not found)
|
||||||
val))
|
(util:lgw "not found" sym))
|
||||||
|
val)))
|
||||||
|
|
||||||
;;;; class word
|
;;;; class word
|
||||||
|
|
||||||
|
@ -99,8 +101,9 @@
|
||||||
(funcall fn))))
|
(funcall fn))))
|
||||||
|
|
||||||
(defun reg (sym fn &optional (cls 'word))
|
(defun reg (sym fn &optional (cls 'word))
|
||||||
(setf (gethash sym (vocabulary *forge-env*)) (make-instance cls :func fn))
|
(let ((sym (intern (symbol-name sym) (current-package *forge-env*))))
|
||||||
(setf (gethash fn (func-index *forge-env*)) sym))
|
(setf (gethash sym (vocabulary *forge-env*)) (make-instance cls :func fn))
|
||||||
|
(setf (gethash fn (func-index *forge-env*)) sym)))
|
||||||
|
|
||||||
(defun reg1 (sym fn)
|
(defun reg1 (sym fn)
|
||||||
(reg sym #'(lambda () (pushd (funcall fn (popd))))))
|
(reg sym #'(lambda () (pushd (funcall fn (popd))))))
|
||||||
|
|
Loading…
Add table
Reference in a new issue