// otherwise, use normal args compiler
conditionals.add(getArgsCallback(whenNode.getExpressionNodes()));
}
public void compileClass(Node node, BodyCompiler context, boolean expr) {
final ClassNode classNode = (ClassNode) node;
final Node superNode = classNode.getSuperNode();
final Node cpathNode = classNode.getCPath();
CompilerCallback superCallback = new CompilerCallback() {
public void call(BodyCompiler context) {
compile(superNode, context, true);
}
};
if (superNode == null) {
superCallback = null;
}
CompilerCallback bodyCallback = new CompilerCallback() {
public void call(BodyCompiler context) {
boolean oldIsAtRoot = isAtRoot;
isAtRoot = false;
if (classNode.getBodyNode() != null) {
compile(classNode.getBodyNode(), context, true);
} else {
context.loadNil();
}
isAtRoot = oldIsAtRoot;
}
};
CompilerCallback pathCallback = new CompilerCallback() {
public void call(BodyCompiler context) {
if (cpathNode instanceof Colon2Node) {
Node leftNode = ((Colon2Node) cpathNode).getLeftNode();
if (leftNode != null) {
if (leftNode instanceof NilNode) {
context.raiseTypeError("No outer class");
} else {
compile(leftNode, context, true);
}
} else {
context.loadNil();
}
} else if (cpathNode instanceof Colon3Node) {
context.loadObject();
} else {
context.loadNil();
}
}
};
ASTInspector inspector = new ASTInspector();
inspector.inspect(classNode.getBodyNode());
context.defineClass(classNode.getCPath().getName(), classNode.getScope(), superCallback, pathCallback, bodyCallback, null, inspector);
// TODO: don't require pop
if (!expr) context.consumeCurrentValue();
}