|
7091 | 7091 | (. proxy (_update-proxy-mappings mappings)) |
7092 | 7092 | proxy))) |
7093 | 7093 |
|
7094 | | -;; TODO: how to handle multi-arity fns |
7095 | 7094 | ;; TODO: kwargs on supertypes |
| 7095 | +;; TODO: check interface/superclass method membership |
| 7096 | +;; TODO: check if duplicate methods |
7096 | 7097 | (defmacro proxy |
| 7098 | + "Create a new proxy class instance. |
| 7099 | + |
| 7100 | + The proxy class may implement 0 or more interface (or subclass 0 or more classes), |
| 7101 | + which are given as the vector ``class-and-interfaces``. If 0 such supertypes are |
| 7102 | + provided, Python's ``object`` type will be used. |
| 7103 | + |
| 7104 | + If the supertype constructors take arguments, those arguments are given in the |
| 7105 | + potentially empty vector ``args``. |
| 7106 | + |
| 7107 | + The remaining forms (if any) should be method overrides for any methods of the |
| 7108 | + declared classes and interfaces. Not every method needs to be overridden. Override |
| 7109 | + declarations may be multi-arity to simulate multi-arity methods. Overrides need |
| 7110 | + not include ``this``, as it will be automatically added and is available within |
| 7111 | + all proxy methods. Proxy methods may access the proxy superclass using the |
| 7112 | + :lpy:fn:`proxy-super` macro. |
| 7113 | + |
| 7114 | + Overrides take the following form:: |
| 7115 | + |
| 7116 | + (single-arity [] |
| 7117 | + ...) |
| 7118 | + |
| 7119 | + (multi-arity |
| 7120 | + ([] ...) |
| 7121 | + ([arg1] ...) |
| 7122 | + ([arg1 & others] ...))" |
7097 | 7123 | [class-and-interfaces args & fs] |
7098 | 7124 | (let [formatted-arity (fn [method-name [arg-vec & body]] |
7099 | | - [(name method-name) |
| 7125 | + [(munge method-name) |
7100 | 7126 | (apply list 'fn method-name (vec (concat ['this] arg-vec)) body)]) |
7101 | 7127 | methods (mapcat (fn [[method-name & body]] |
7102 | 7128 | (if (vector? (first body)) |
7103 | 7129 | (formatted-arity method-name body) |
7104 | | - (map (partial formatted-arity method-name) body))) |
| 7130 | + (mapcat (partial formatted-arity method-name) body))) |
7105 | 7131 | fs)] |
7106 | 7132 | #_(println methods) |
7107 | 7133 | `((get-proxy-class ~@class-and-interfaces) ~(apply hash-map methods) ~@args))) |
|
0 commit comments