|
6998 | 6998 |
|
6999 | 6999 | ;; TODO: kwargs on supertypes
|
7000 | 7000 | ;; TODO: check interface/superclass method membership
|
7001 |
| -;; TODO: check if duplicate methods |
7002 | 7001 | (defmacro proxy
|
7003 | 7002 | "Create a new proxy class instance.
|
7004 | 7003 |
|
|
7034 | 7033 | (let [formatted-single (fn [method-name [arg-vec & body]]
|
7035 | 7034 | [(munge method-name)
|
7036 | 7035 | (apply list 'fn method-name (vec (concat ['this] arg-vec)) body)])
|
7037 |
| - formatted-multi (fn [method-name & arities] |
7038 |
| - [(munge method-name) |
7039 |
| - (apply list |
7040 |
| - 'fn |
7041 |
| - method-name |
7042 |
| - (map (fn [[arg-vec & body]] |
7043 |
| - (apply list (vec (concat ['this] arg-vec)) body)) |
7044 |
| - arities))]) |
7045 |
| - methods (mapcat (fn [[method-name & body]] |
7046 |
| - (if (vector? (first body)) |
7047 |
| - (formatted-single method-name body) |
7048 |
| - (apply formatted-multi method-name body))) |
7049 |
| - fs)] |
| 7036 | + formatted-multi (fn [method-name & arities] |
| 7037 | + [(munge method-name) |
| 7038 | + (apply list |
| 7039 | + 'fn |
| 7040 | + method-name |
| 7041 | + (map (fn [[arg-vec & body]] |
| 7042 | + (apply list (vec (concat ['this] arg-vec)) body)) |
| 7043 | + arities))]) |
| 7044 | + methods (map (fn [[method-name & body]] |
| 7045 | + (if (vector? (first body)) |
| 7046 | + (formatted-single method-name body) |
| 7047 | + (apply formatted-multi method-name body))) |
| 7048 | + fs) |
| 7049 | + method-map (reduce* (fn [m [method-name method]] |
| 7050 | + (if-let [existing-method (get m method-name)] |
| 7051 | + (throw |
| 7052 | + (ex-info "Cannot define proxy class with duplicate method" |
| 7053 | + {:method-name method-name |
| 7054 | + :impls [existing-method method]})) |
| 7055 | + (assoc m method-name method))) |
| 7056 | + {} |
| 7057 | + methods)] |
7050 | 7058 | #_(println methods)
|
7051 |
| - `((get-proxy-class ~@class-and-interfaces) ~(apply hash-map methods) ~@args))) |
| 7059 | + `((get-proxy-class ~@class-and-interfaces) ~method-map ~@args))) |
7052 | 7060 |
|
7053 | 7061 | (defmacro proxy-super
|
7054 | 7062 | "Macro which expands to a call to the method named ``meth`` on the superclass
|
|
0 commit comments