forge/sf, work in progress: generic functions for execution and compiling

This commit is contained in:
Helmut Merz 2024-09-09 13:09:55 +02:00
parent ae4495e939
commit 2c9dbfde3e

View file

@ -17,7 +17,21 @@
;;;; core definitions ;;;; core definitions
(defclass word () ()) (defgeneric exec-item (it)
(:method ((it t))
(pushd it))
(:method ((it symbol))
(funcall (func (symbol-value it)))))
(defgeneric comp-item (it))
(defgeneric call-item (it))
(defclass word ()
((func :reader func :initarg :func)))
(defmethod call-item ((it word))
(funcall (func it)))
(defclass comp-word (word) ()) (defclass comp-word (word) ())
@ -28,14 +42,9 @@
(defun exec-input () (defun exec-input ()
(iter:process *input* #'exec-item)) (iter:process *input* #'exec-item))
(defun exec-item (item)
(typecase item
(function (funcall item))
(symbol (funcall (symbol-value item)))
(t (pushd item))))
(defun reg (sym fn) (defun reg (sym fn)
(setf (symbol-value sym) fn)) (setf (symbol-value sym) (make-instance 'word :func fn)))
;(setf (symbol-value sym) fn))
(defun reg2 (sym fn) (defun reg2 (sym fn)
(reg sym #'(lambda () (pushd (funcall fn (popd) (popd)))))) (reg sym #'(lambda () (pushd (funcall fn (popd) (popd))))))