|
7104 | 7104 |
|
7105 | 7105 | ;; TODO: kwargs on supertypes
|
7106 | 7106 | ;; TODO: check interface/superclass method membership
|
7107 |
| -;; TODO: check if duplicate methods |
7108 | 7107 | (defmacro proxy
|
7109 | 7108 | "Create a new proxy class instance.
|
7110 | 7109 |
|
|
7140 | 7139 | (let [formatted-single (fn [method-name [arg-vec & body]]
|
7141 | 7140 | [(munge method-name)
|
7142 | 7141 | (apply list 'fn method-name (vec (concat ['this] arg-vec)) body)])
|
7143 |
| - formatted-multi (fn [method-name & arities] |
7144 |
| - [(munge method-name) |
7145 |
| - (apply list |
7146 |
| - 'fn |
7147 |
| - method-name |
7148 |
| - (map (fn [[arg-vec & body]] |
7149 |
| - (apply list (vec (concat ['this] arg-vec)) body)) |
7150 |
| - arities))]) |
7151 |
| - methods (mapcat (fn [[method-name & body]] |
7152 |
| - (if (vector? (first body)) |
7153 |
| - (formatted-single method-name body) |
7154 |
| - (apply formatted-multi method-name body))) |
7155 |
| - fs)] |
| 7142 | + formatted-multi (fn [method-name & arities] |
| 7143 | + [(munge method-name) |
| 7144 | + (apply list |
| 7145 | + 'fn |
| 7146 | + method-name |
| 7147 | + (map (fn [[arg-vec & body]] |
| 7148 | + (apply list (vec (concat ['this] arg-vec)) body)) |
| 7149 | + arities))]) |
| 7150 | + methods (map (fn [[method-name & body]] |
| 7151 | + (if (vector? (first body)) |
| 7152 | + (formatted-single method-name body) |
| 7153 | + (apply formatted-multi method-name body))) |
| 7154 | + fs) |
| 7155 | + method-map (reduce* (fn [m [method-name method]] |
| 7156 | + (if-let [existing-method (get m method-name)] |
| 7157 | + (throw |
| 7158 | + (ex-info "Cannot define proxy class with duplicate method" |
| 7159 | + {:method-name method-name |
| 7160 | + :impls [existing-method method]})) |
| 7161 | + (assoc m method-name method))) |
| 7162 | + {} |
| 7163 | + methods)] |
7156 | 7164 | #_(println methods)
|
7157 |
| - `((get-proxy-class ~@class-and-interfaces) ~(apply hash-map methods) ~@args))) |
| 7165 | + `((get-proxy-class ~@class-and-interfaces) ~method-map ~@args))) |
7158 | 7166 |
|
7159 | 7167 | (defmacro proxy-super
|
7160 | 7168 | "Macro which expands to a call to the method named ``meth`` on the superclass
|
|
0 commit comments