| 1239 | |
| 1240 | // TBD: caching/reuse of thunks |
| 1241 | private static FnExpr buildThunk(C context, QualifiedMethodExpr qmexpr) { |
| 1242 | // When qualified symbol has param-tags: |
| 1243 | // (fn invoke__Class_meth ([this? args*] (methodSymbol this? args*))) |
| 1244 | // When no param-tags: |
| 1245 | // (fn invoke__Class_meth ([this?] (methodSymbol this?)) |
| 1246 | // ([this? arg1] (methodSymbol this? arg1)) ...) |
| 1247 | IPersistentCollection form = PersistentVector.EMPTY; |
| 1248 | Symbol instanceParam = qmexpr.kind == MethodKind.INSTANCE ? THIS : null; |
| 1249 | String thunkName = "invoke__" + qmexpr.c.getSimpleName() + "_" + qmexpr.methodSymbol.name; |
| 1250 | Set arities = (qmexpr.hintedSig != null) ? PersistentHashSet.create(qmexpr.hintedSig.size()) |
| 1251 | : aritySet(qmexpr.c, qmexpr.methodName, qmexpr.kind); |
| 1252 | |
| 1253 | for(Object a : arities) { |
| 1254 | int arity = (int) a; |
| 1255 | IPersistentVector params = buildParams(instanceParam, arity); |
| 1256 | ISeq body = RT.listStar(qmexpr.methodSymbol, params.seq()); |
| 1257 | form = RT.conj(form, RT.list(params, body)); |
| 1258 | } |
| 1259 | |
| 1260 | ISeq thunkForm = RT.listStar(Symbol.intern("fn"), Symbol.intern(thunkName), RT.seq(form)); |
| 1261 | return (FnExpr) analyzeSeq(context, thunkForm, thunkName); |
| 1262 | } |
| 1263 | |
| 1264 | private static IPersistentVector buildParams(Symbol instanceParam, int arity) { |
| 1265 | IPersistentVector params = PersistentVector.EMPTY; |