|
7055 | 7055 |
|
7056 | 7056 | ;; TODO: kwargs on supertypes |
7057 | 7057 | ;; TODO: check interface/superclass method membership |
7058 | | -;; TODO: check if duplicate methods |
7059 | 7058 | (defmacro proxy |
7060 | 7059 | "Create a new proxy class instance. |
7061 | 7060 |
|
|
7091 | 7090 | (let [formatted-single (fn [method-name [arg-vec & body]] |
7092 | 7091 | [(munge method-name) |
7093 | 7092 | (apply list 'fn method-name (vec (concat ['this] arg-vec)) body)]) |
7094 | | - formatted-multi (fn [method-name & arities] |
7095 | | - [(munge method-name) |
7096 | | - (apply list |
7097 | | - 'fn |
7098 | | - method-name |
7099 | | - (map (fn [[arg-vec & body]] |
7100 | | - (apply list (vec (concat ['this] arg-vec)) body)) |
7101 | | - arities))]) |
7102 | | - methods (mapcat (fn [[method-name & body]] |
7103 | | - (if (vector? (first body)) |
7104 | | - (formatted-single method-name body) |
7105 | | - (apply formatted-multi method-name body))) |
7106 | | - fs)] |
| 7093 | + formatted-multi (fn [method-name & arities] |
| 7094 | + [(munge method-name) |
| 7095 | + (apply list |
| 7096 | + 'fn |
| 7097 | + method-name |
| 7098 | + (map (fn [[arg-vec & body]] |
| 7099 | + (apply list (vec (concat ['this] arg-vec)) body)) |
| 7100 | + arities))]) |
| 7101 | + methods (map (fn [[method-name & body]] |
| 7102 | + (if (vector? (first body)) |
| 7103 | + (formatted-single method-name body) |
| 7104 | + (apply formatted-multi method-name body))) |
| 7105 | + fs) |
| 7106 | + method-map (reduce* (fn [m [method-name method]] |
| 7107 | + (if-let [existing-method (get m method-name)] |
| 7108 | + (throw |
| 7109 | + (ex-info "Cannot define proxy class with duplicate method" |
| 7110 | + {:method-name method-name |
| 7111 | + :impls [existing-method method]})) |
| 7112 | + (assoc m method-name method))) |
| 7113 | + {} |
| 7114 | + methods)] |
7107 | 7115 | #_(println methods) |
7108 | | - `((get-proxy-class ~@class-and-interfaces) ~(apply hash-map methods) ~@args))) |
| 7116 | + `((get-proxy-class ~@class-and-interfaces) ~method-map ~@args))) |
7109 | 7117 |
|
7110 | 7118 | (defmacro proxy-super |
7111 | 7119 | "Macro which expands to a call to the method named ``meth`` on the superclass |
|
0 commit comments