From 2c9dbfde3ed0511e9fedf0509d66a61ce2d88872 Mon Sep 17 00:00:00 2001 From: Helmut Merz Date: Mon, 9 Sep 2024 13:09:55 +0200 Subject: [PATCH] forge/sf, work in progress: generic functions for execution and compiling --- forge/sf.lisp | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/forge/sf.lisp b/forge/sf.lisp index 8186fe8..a1d9a51 100644 --- a/forge/sf.lisp +++ b/forge/sf.lisp @@ -17,7 +17,21 @@ ;;;; 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) ()) @@ -28,14 +42,9 @@ (defun exec-input () (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) - (setf (symbol-value sym) fn)) + (setf (symbol-value sym) (make-instance 'word :func fn))) + ;(setf (symbol-value sym) fn)) (defun reg2 (sym fn) (reg sym #'(lambda () (pushd (funcall fn (popd) (popd))))))