Skip to content

Commit

Permalink
Add define-interface
Browse files Browse the repository at this point in the history
  • Loading branch information
yitzchak committed Apr 30, 2024
1 parent 605af02 commit d51deaf
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 29 deletions.
9 changes: 2 additions & 7 deletions code/extrinsic/interface.lisp
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
(in-package #:invistra-extrinsic)

(defun format (destination control-string &rest args)
(apply #'invistra:format incless-extrinsic:*client* destination control-string args))
(invistra:define-interface (incless-extrinsic:*client* incless-extrinsic:extrinsic-client))

(defmacro formatter (control-string)
(invistra:formatter incless-extrinsic:*client* control-string))

(define-compiler-macro format (&whole form destination control-string &rest args)
(invistra:format-compiler-macro incless-extrinsic:*client* form destination control-string args))
(initialize-invistra)
3 changes: 2 additions & 1 deletion code/extrinsic/packages.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
#:formatter)
(:export #:*client*
#:format
#:formatter))
#:formatter
#:initialize-invistra))
21 changes: 21 additions & 0 deletions code/interface.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
(in-package #:invistra)

(defun ensure-symbol (name &optional (package *package*))
(intern (string name) package))

(defmacro define-interface ((client-var client-class &optional intrinsic) &body body)
(let* ((intrinsic-pkg (if intrinsic (find-package '#:common-lisp) *package*))
(format-func (ensure-symbol '#:format intrinsic-pkg))
(initialize-func (ensure-symbol '#:initialize-invistra)))
`(progn
(defun ,format-func (destination control-string &rest args)
(apply #'format ,client-var destination control-string args))

(defmacro ,(ensure-symbol '#:formatter intrinsic-pkg) (control-string)
(formatter ,client-var control-string))

(define-compiler-macro ,format-func (&whole form destination control-string &rest args)
(format-compiler-macro ,client-var form destination control-string args))

(defun ,initialize-func ()
,@body))))
9 changes: 1 addition & 8 deletions code/intrinsic/interface.lisp
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
(in-package #:invistra-intrinsic)

(defun format (destination control-string &rest args)
(apply #'invistra:format incless-intrinsic:*client* destination control-string args))

(defmacro formatter (control-string)
(invistra:formatter incless-intrinsic:*client* control-string))

(define-compiler-macro format (&whole form destination control-string &rest args)
(invistra:format-compiler-macro incless-intrinsic:*client* form destination control-string args))
(invistra:define-interface (incless-intrinsic:*client* incless-intrinsic:intrinsic-client t))
3 changes: 2 additions & 1 deletion code/intrinsic/packages.lisp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
(defpackage #:invistra-intrinsic
(:use #:common-lisp)
(:export #:*client*))
(:export #:*client*
#:initialize-invistra))
7 changes: 4 additions & 3 deletions code/packages.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
#:formatter)
#+sicl
(:local-nicknames (:trivial-gray-streams :cyclosis))
(:export #:*roman-digits*
#:*destination*
#:consume-next-argument
(:export #:*destination*
#:*roman-digits*
#:at-sign-p
#:check-directive-syntax
#:coerce-function-designator
#:colon-p
#:compile-item
#:consume-next-argument
#:define-interface
#:directive
#:format
#:format-compiler-macro
Expand Down
9 changes: 2 additions & 7 deletions code/shim/interface.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@
#+sbcl (setf (sb-c::fun-info-transforms (sb-c::fun-info-or-lose 'format)) nil)

(trivial-package-locks:with-unlocked-system-packages
(defun format (destination control-string &rest args)
(apply #'invistra:format *client* destination control-string args))
(invistra:define-interface (*client* shim-client t)))

(defmacro formatter (control-string)
(invistra:formatter *client* control-string))

(define-compiler-macro format (&whole form destination control-string &rest args)
(invistra:format-compiler-macro *client* form destination control-string args)))
(initialize-invistra)
3 changes: 2 additions & 1 deletion code/shim/packages.lisp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
(defpackage #:invistra-shim
(:use #:common-lisp)
(:export #:*client*))
(:export #:*client*
#:initialize-invistra))
3 changes: 2 additions & 1 deletion invistra.asd
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@
(:file "control-flow-operations")
(:file "miscellaneous-operations")
(:file "miscellaneous-pseudo-operations")
(:file "condition-reporters-en")))))
(:file "condition-reporters-en")
(:file "interface")))))

0 comments on commit d51deaf

Please sign in to comment.