diff options
author | Darren Bane <darren.bane@gmail.com> | 2020-10-09 21:22:20 +0100 |
---|---|---|
committer | Darren Bane <darren.bane@gmail.com> | 2020-10-09 21:22:20 +0100 |
commit | b1f18384189e32fa29fadbb29d3043ade4aa67e5 (patch) | |
tree | 786194fc91812879634dc9bc5db9a828682f6d21 | |
parent | d34eb60916327589576143fa84c1a2468bee6cf3 (diff) | |
download | lsp-b1f18384189e32fa29fadbb29d3043ade4aa67e5.tar.gz |
Trying to debug abstract classes, WIP
-rw-r--r-- | cabs-syn.lisp | 5 | ||||
-rw-r--r-- | cbasic.lisp | 19 | ||||
-rw-r--r-- | cutil.lisp | 9 |
3 files changed, 27 insertions, 6 deletions
diff --git a/cabs-syn.lisp b/cabs-syn.lisp index 12b9fd4..2b6d30a 100644 --- a/cabs-syn.lisp +++ b/cabs-syn.lisp @@ -24,7 +24,10 @@ ;; But classes seem better for the associated data, in discriminated unions. (defclass <expression> () () (:metaclass <abstract-class>)) -(defclass <exp-int> (<expression>) ((int :accessor int))) + +(defclass <exp-int> (<expression>) ((my-int :accessor my-int))) +;; TODO: need another closer-mop:validate-superclass call here + (defclass <exp-var> (<expression>) ((var :accessor var))) (defclass <exp-str> (<expression>) ((str :accessor str))) (defclass <exp-unr> (<expression>) ((op :accessor op) (exp :accessor exp))) diff --git a/cbasic.lisp b/cbasic.lisp index 706c564..1085e16 100644 --- a/cbasic.lisp +++ b/cbasic.lisp @@ -1,11 +1,26 @@ ;;; I'm trying to write an interpreter for a BBC BASIC subset ;;; initially following the design of ;;; https://caml.inria.fr/pub/docs/oreilly-book/html/book-ora058.html -;;; and later I can Frankenstein it with -;;; https://github.com/Henry/BuddKaminInterpreters +;;; then later I can optimise following +;;; https://github.com/Henry/BuddKaminInterpreters and +;;; https://oleksandrmanzyuk.wordpress.com/2014/06/18/from-object-algebras-to-finally-tagless-interpreters-2/ +;;; +;;; A BASIC interpreter already exists at +;;; https://gitlab.com/com-informatimago/com-informatimago/-/tree/master/small-cl-pgms/basic +;;; but it is idiomatic CL, +;;; whereas I'm experimenting with a subset like ISLisp. +;; Because this is the main package, +;; 1) ql:quickload QuickLisp dependencies and +;; 2) load local dependencies here. (load "cutil.lisp") (load "cparse.lisp") +;; Use require & defpackage in each package from then on. +;; NB: must have no circular dependencies, and topologically sort the loads. +;; +;; TODO: it's easier to just get started with ASDF +;; ( https://lisp-lang.org/learn/writing-libraries ) + (require "cparse") (require "") (defpackage #:cbasic diff --git a/cutil.lisp b/cutil.lisp index 0b569e2..2f10099 100644 --- a/cutil.lisp +++ b/cutil.lisp @@ -1,11 +1,14 @@ (defpackage #:cutil - (:use #:common-lisp) + (:use #:common-lisp :closer-mop) (:export #:<abstract-class>)) (in-package #:cutil) -(defclass <abstract-class> () ()) +(defclass <abstract-class> (standard-class) ()) (defmethod make-instance ((self <abstract-class>) &key) - (error "Cannot instantiate abstract class ~A" (class-name c))) + (error "Cannot instantiate abstract class ~A" (class-name self))) +(defmethod closer-mop:validate-superclass ((class <abstract-class>) + (superclass standard-class)) + t) (provide "cutil") |