This repository was archived by the owner on Dec 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstruction.lisp
101 lines (82 loc) · 2.94 KB
/
instruction.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
(in-package :cl-lsystem)
(defclass instruction (standard-class)
((constructor :initform nil
:initarg :constructor
:reader constructor
:documentation "The lambda list of the constructor to be found in the :turtle field of a L-system definition. E.g.: (defclass myinst ... (:constructor (a &key b))) matches (myinst 12 :b 13).")))
(defclass singleton-instruction (instruction)
((instance :initform nil)))
(defmethod sb-mop:validate-superclass ((class instruction) (superclass standard-class))
t)
(defmethod make-instance ((class singleton-instruction) &key)
(or (slot-value class 'instance)
(let ((instance (call-next-method)))
(setf (slot-value class 'instance) instance)
instance)))
;; FIXME class not finalized and closer mop doesn't work
;; (defmethod initialize-instance :after ((class instruction) &key)
;; (let* ((slots (sb-mop:class-slots class))
;; (slot-names (mapcar #'sb-mop:slot-definition-name slots))
;; (cons-lambda-list (second (constructor class))))
;; (break)
;; (when-let (diff (set-difference slot-names cons-lambda-list))
;; (error "missing slots in constrcutor lambda list: ~{~S~^ ~}" diff))))
(defclass noop ()
()
(:metaclass singleton-instruction))
(defclass jump ()
(delta)
(:metaclass instruction)
(:constructor (delta)))
(defclass forward (jump)
((delta :type real))
(:metaclass instruction)
(:constructor (delta)))
(defclass rotate ()
((theta :type real))
(:metaclass instruction)
(:documentation "2D rotation")
(:constructor (theta)))
(defclass roll ()
((theta :type real))
(:metaclass instruction)
(:documentation "3D X rotation")
(:constructor (theta)))
(defclass pitch ()
((theta :type real))
(:metaclass instruction)
(:documentation "3D Y rotation")
(:constructor (theta)))
(defclass yaw ()
((theta :type real))
(:metaclass instruction)
(:documentation "3D Z rotation")
(:constructor (theta)))
(defclass stack ()
()
(:metaclass singleton-instruction))
(defclass unstack ()
()
(:metaclass singleton-instruction))
(defclass begin-fill ()
()
(:metaclass singleton-instruction)
(:documentation "Starts recording vertices on top of a new stacked polygon (cf. `3d-environment/fill-stack'."))
(defclass end-fill ()
()
(:metaclass singleton-instruction)
(:documentation "Pops the polygon on top of `3d-environment/fill-stack' and fills it."))
(defclass apply-material ()
((material :type material))
(:metaclass instruction)
(:constructor (material))
(:documentation "Uses the given `material' for faces until `pop-material' is encountered."))
(defclass pop-material ()
()
(:metaclass singleton-instruction)
(:documentation "Removes the last `material' applied by `apply-ametrial'."))
(defclass lisp ()
((procedure :type cl:function))
(:metaclass instruction)
(:documentation "Applies the given function. Its argument is the environment.")
(:constructor (procedure)))