public void compile(ByteCompiler context)
{
_types.put(_constructor.getName(), _constructor);
ClassRoom clazz = context.getClassRoom().createClass(_descriptor, "z_"+_name);
clazz.setAccessFlags(Code.ACC_PUBLIC);
ConstantPool pool = clazz.getPool();
context.pushClass(clazz);
Field typefield1 = clazz.createField("_class", "Lanvil/script/compiler/CompiledClassType;", Code.ACC_PUBLIC|Code.ACC_STATIC);
Field typefield2 = clazz.createField("_type", "Lanvil/core/Any;", Code.ACC_PUBLIC|Code.ACC_STATIC);
ClassType base = getBaseClass();
if (base != Any.__class__) {
clazz.setSuperClassname(base.getDescriptor());
} else {
clazz.setSuperClassname("anvil/core/AnyClass");
}
clazz.setAccessFlags(Code.ACC_SUPER|Code.ACC_PUBLIC);
Field bases = clazz.createField("_bases", "[Ljava/lang/String;", Code.ACC_PUBLIC|Code.ACC_STATIC);
Code code = clazz.getStatic().getCode();
context.pushCode(code);
code.getstatic(pool.addFieldRef(_parent.getDescriptor(), "_members", "[Ljava/lang/Object;"));
code.pop();
compileConstructors(context, typefield1);
compileMembers(context, _types.size(), _types.elements());
int n = _interfaces.length;
code.iconst(n);
code.anewarray("java/lang/String");
for(int i=0; i<n; i++) {
InterfaceType interfacetype = _interfaces[i].getInterfaceType();
code.dup();
code.iconst(i);
code.astring(interfacetype.getDescriptor().replace('/', '.'));
code.aastore();
}
code.putstatic(bases);
Enumeration e = _types.elements();
while(e.hasMoreElements()) {
Type type = (Type)e.nextElement();
if (type.getType() == CLASS) {
code.getstatic(pool.addFieldRef(type.getTypeRef(pool),
"_members", "[Ljava/lang/Object;"));
code.pop();
}
}
code.vreturn();
context.popCode();
super.compile(context);
compileMemberCallback(context);
MethodStatement method = getMethod("clone");
if (method != null) {
compileCallback(context, method, clazz.createMethod(
"clone", "()Ljava/lang/Object;", Code.ACC_PUBLIC), true, 0, EMPTY, 0, 2);
} else {
compileCopyMethod(context, method, false, typefield1);
}
method = getMethod("copy");
if (method != null) {
compileCallback(context, method, clazz.createMethod(
"copy", "()Lanvil/core/Any;", Code.ACC_PUBLIC), true, 0, EMPTY, 0, 2);
} else {
compileCopyMethod(context, method, true, typefield1);
}
method = getMethod("toBoolean");
if (method != null) {
compileCallback(context, method,
clazz.createMethod("toBoolean", "()Z", Code.ACC_PUBLIC), true, 0, EMPTY,
pool.addMethodRef(context.TYPE_ANY, "toBoolean", "()Z"), 1);
}
method = getMethod("toString");
if (method != null) {
compileCallback(context, method,
clazz.createMethod("toString", "()Ljava/lang/String;", Code.ACC_PUBLIC), true, 0, EMPTY,
pool.addMethodRef(context.TYPE_ANY, "toString", "()Ljava/lang/String;"), 2);
}
method = getMethod("sizeOf");
if (method != null) {
compileCallback(context, method,
clazz.createMethod("sizeOf", "()I", Code.ACC_PUBLIC), true, 0, EMPTY,
pool.addMethodRef(context.TYPE_ANY, "toInt", "()I"), 1);
}
method = getMethod("hashCode");
if (method != null) {
compileCallback(context, method,
clazz.createMethod("hashCode", "()I", Code.ACC_PUBLIC), true, 0, EMPTY,
pool.addMethodRef(context.TYPE_ANY, "toInt", "()I"), 1);
}
method = getMethod("equals");
if (method != null) {
compileEqualsMethod(context, method);
}
method = getMethod("compareTo");
if (method != null) {
compileCallback(context, method,
clazz.createMethod("compare", "(Lanvil/core/Any;)I", Code.ACC_PUBLIC), true, 1, CAST_P1_NODE,
pool.addMethodRef(context.TYPE_ANY, "toInt", "()I"), 1);
}
method = getMethod("_get");
if (method != null) {
compileCallback(context, method,
clazz.createMethod("getReference", "(Lanvil/script/Context;Lanvil/core/Any;)Lanvil/core/Any;", Code.ACC_PUBLIC),
false, 2, P2_NODE, 0, 2);
}
method = getMethod("_check");
if (method != null) {
compileCallback(context, method,
clazz.createMethod("checkReference", "(Lanvil/script/Context;Lanvil/core/Any;)Lanvil/core/Any;", Code.ACC_PUBLIC),
false, 2, P2_NODE, 0, 2);
}
method = getMethod("_delete");
if (method != null) {
compileCallback(context, method,
clazz.createMethod("deleteReference", "(Lanvil/script/Context;Lanvil/core/Any;)Z", Code.ACC_PUBLIC),
false, 2, P2_NODE, pool.addMethodRef(context.TYPE_ANY, "toBoolean", "()Z"), 1);
}
method = getMethod("_append");
if (method != null) {
compileCallback(context, method,
clazz.createMethod("setReference", "(Lanvil/script/Context;Lanvil/core/Any;)Lanvil/core/Any;", Code.ACC_PUBLIC),
false, 2, P2_NODE, 0, 2);
}
method = getMethod("_set");
if (method != null) {
compileCallback(context, method, clazz.createMethod("setReference",
"(Lanvil/script/Context;Lanvil/core/Any;Lanvil/core/Any;)Lanvil/core/Any;", Code.ACC_PUBLIC),
false, 3, P_Q_NODE, 0, 2);
}
method = getMethod("_fetch");
MethodStatement[] methods = getMethodsStartingWith("_fetch_");
if (method != null || methods != null) {
Method target = clazz.createMethod("getAttribute", "(Lanvil/script/Context;Ljava/lang/String;)Lanvil/core/Any;", Code.ACC_PUBLIC);
compileAttributeCallback(context, target, 7, false, methods, EMPTY, method, P_S2A_NODE, false);
}
method = getMethod("_defined");
methods = getMethodsStartingWith("_defined_");
if (method != null || methods != null) {
Method target = clazz.createMethod("checkAttribute", "(Lanvil/script/Context;Ljava/lang/String;)Lanvil/core/Any;", Code.ACC_PUBLIC);
compileAttributeCallback(context, target, 9, false, methods, EMPTY, method, P_S2A_NODE, false);
}
method = getMethod("_dispose");
methods = getMethodsStartingWith("_dispose_");
if (method != null || methods != null) {
Method target = clazz.createMethod("deleteAttribute", "(Lanvil/script/Context;Ljava/lang/String;)Z", Code.ACC_PUBLIC);
compileAttributeCallback(context, target, 9, false, methods, EMPTY, method, P_S2A_NODE, true);
}
method = getMethod("_store");
methods = getMethodsStartingWith("_store_");
if (method != null || methods != null) {
Method target = clazz.createMethod("setAttribute", "(Lanvil/script/Context;Ljava/lang/String;Lanvil/core/Any;)Lanvil/core/Any;", Code.ACC_PUBLIC);
compileAttributeCallback(context, target, 7, true, methods, P3_NODE, method, P_S2A_Q_NODE, false);
}
method = getMethod("_enumeration");
if (method != null) {
compileCallback(context, method, clazz.createMethod("enumeration",
"()Lanvil/java/util/BindingEnumeration;", Code.ACC_PUBLIC),
true, 0, EMPTY, -pool.addMethodRef(context.TYPE_COMPILED_SCRIPT,
"enumerate", "(Lanvil/core/Any;)Lanvil/java/util/BindingEnumeration;"), 2);
}
method = getMethod("_in");
if (method != null) {
compileCallback(context, method,
clazz.createMethod("contains", "(Lanvil/core/Any;)Z", Code.ACC_PUBLIC),
true, 1, P1_NODE, pool.addMethodRef(context.TYPE_ANY, "toBoolean", "()Z"), 1);
}
method = getMethod("_has");
if (method != null) {
compileCallback(context, method,
clazz.createMethod("has", "(Ljava/lang/String;)Z", Code.ACC_PUBLIC),
true, 1, P1_S2A_NODE, pool.addMethodRef(context.TYPE_ANY, "toBoolean", "()Z"), 1);
}
method = getMethod("_invoke");
if (method != null) {
compileInvokeMethod(context, clazz, method);
}
method = getMethod("_execute");
if (method != null) {
compileExecuteMethod(context, clazz, method);
}
method = getMethod("_getRef");
if (method != null) {
compileCallback(context, method,
clazz.createMethod("getRef", "()Lanvil/core/Any;", Code.ACC_PUBLIC), true, 0, EMPTY, 0, 2);
}
method = getMethod("_setRef");
if (method != null) {
compileCallback(context, method,
clazz.createMethod("setRef", "(Lanvil/core/Any;)V", Code.ACC_PUBLIC), true, 1, P1_NODE, 0, 0);
}
compileAux(context);
//compileInvoker(context);