cv.visitField(ACC_PUBLIC + ACC_FINAL + ACC_STATIC, munge(v.sym.toString()),
VAR_TYPE.getDescriptor(), null, null);
}
*/
//static init for constants, keywords and vars
GeneratorAdapter clinitgen = new GeneratorAdapter(ACC_PUBLIC + ACC_STATIC,
Method.getMethod("void <clinit> ()"),
null,
null,
cv);
clinitgen.visitCode();
clinitgen.visitLineNumber(line, clinitgen.mark());
// Label begin = clinitgen.newLabel();
// Label end = clinitgen.newLabel();
if(constants.count() > 0)
{
// clinitgen.mark(begin);
clinitgen.visitLdcInsn(fntype);
clinitgen.invokeVirtual(CLASS_TYPE, getClassLoaderMethod);
clinitgen.checkCast(DYNAMIC_CLASSLOADER_TYPE);
clinitgen.push(constantsID);
clinitgen.invokeVirtual(DYNAMIC_CLASSLOADER_TYPE, getConstantsMethod);
for(int i = 0; i < constants.count(); i++)
{
clinitgen.dup();
clinitgen.push(i);
clinitgen.arrayLoad(OBJECT_TYPE);
clinitgen.checkCast(constantType(i));
clinitgen.putStatic(fntype, constantName(i), constantType(i));
}
}
// for(ISeq s = RT.keys(keywords); s != null; s = s.rest())
// {
// Keyword k = (Keyword) s.first();
// clinitgen.push(k.sym.ns);
// clinitgen.push(k.sym.name);
// clinitgen.invokeStatic(KEYWORD_TYPE, kwintern);
// clinitgen.putStatic(fntype, munge(k.sym.toString()), KEYWORD_TYPE);
// }
// for(ISeq s = RT.keys(vars); s != null; s = s.rest())
// {
// Var v = (Var) s.first();
// clinitgen.push(v.ns.name.name);
// clinitgen.invokeStatic(SYMBOL_TYPE, symcreate);
// clinitgen.push(v.sym.name);
// clinitgen.invokeStatic(SYMBOL_TYPE, symcreate);
// clinitgen.invokeStatic(VAR_TYPE, varintern);
// clinitgen.putStatic(fntype, munge(v.sym.toString()), VAR_TYPE);
// }
// clinitgen.mark(end);
// clinitgen.visitLocalVariable("constants", "[Ljava/lang/Object;", null, begin, end, 0);
clinitgen.returnValue();
clinitgen.endMethod();
// clinitgen.visitMaxs(1, 1);
//instance fields for closed-overs
for(ISeq s = RT.keys(closes); s != null; s = s.rest())
{
LocalBinding lb = (LocalBinding) s.first();
if(lb.getPrimitiveType() != null)
cv.visitField(ACC_PUBLIC + ACC_FINAL, lb.name, Type.getType(lb.getPrimitiveType()).getDescriptor(),
null, null);
else
cv.visitField(ACC_PUBLIC + ACC_FINAL, lb.name, OBJECT_TYPE.getDescriptor(), null, null);
}
//ctor that takes closed-overs and inits base + fields
// Method m = new Method("<init>", Type.VOID_TYPE, ARG_TYPES[closes.count()]);
Method m = new Method("<init>", Type.VOID_TYPE, ctorTypes());
GeneratorAdapter ctorgen = new GeneratorAdapter(ACC_PUBLIC,
m,
null,
null,
cv);
Label start = ctorgen.newLabel();
Label end = ctorgen.newLabel();
ctorgen.visitCode();
ctorgen.visitLineNumber(line, ctorgen.mark());
ctorgen.visitLabel(start);
ctorgen.loadThis();
if(isVariadic()) //RestFn ctor takes reqArity arg
{
ctorgen.push(variadicMethod.reqParms.count());
ctorgen.invokeConstructor(restFnType, restfnctor);
}
else
ctorgen.invokeConstructor(aFnType, afnctor);
int a = 1;
for(ISeq s = RT.keys(closes); s != null; s = s.rest(), ++a)
{
LocalBinding lb = (LocalBinding) s.first();
ctorgen.loadThis();
Class primc = lb.getPrimitiveType();
if(primc != null)
{
ctorgen.visitVarInsn(Type.getType(primc).getOpcode(Opcodes.ILOAD), a);
ctorgen.putField(fntype, lb.name, Type.getType(primc));
if(primc == Long.TYPE || primc == Double.TYPE)
++a;
}
else
{
ctorgen.visitVarInsn(OBJECT_TYPE.getOpcode(Opcodes.ILOAD), a);
ctorgen.putField(fntype, lb.name, OBJECT_TYPE);
}
}
ctorgen.visitLabel(end);
// a = 1;
// for(ISeq s = RT.keys(closes); s != null; s = s.rest(), ++a)
// {
// LocalBinding lb = (LocalBinding) s.first();
// Class primc = lb.getPrimitiveType();
// if(primc != null)
// {
// ctorgen.visitLocalVariable(lb.name, Type.getDescriptor(primc), null, start, end, a);
// if(primc == Long.TYPE || primc == Double.TYPE)
// ++a;
// }
// else
// {
// ctorgen.visitLocalVariable(lb.name, "Ljava/lang/Object;", null, start, end, a);
// }
// }
ctorgen.returnValue();
// ctorgen.visitMaxs(1, 1);
ctorgen.endMethod();
//override of invoke/doInvoke for each method
for(ISeq s = RT.seq(methods); s != null; s = s.rest())
{
FnMethod method = (FnMethod) s.first();