hello world can be compiled
This commit is contained in:
@@ -5,6 +5,8 @@ import org.jetbrains.jet.lang.psi.*;
|
|||||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||||
import org.jetbrains.jet.lang.types.DeclarationDescriptor;
|
import org.jetbrains.jet.lang.types.DeclarationDescriptor;
|
||||||
import org.jetbrains.jet.lang.types.FunctionDescriptor;
|
import org.jetbrains.jet.lang.types.FunctionDescriptor;
|
||||||
|
import org.jetbrains.jet.lang.types.JetStandardClasses;
|
||||||
|
import org.jetbrains.jet.lang.types.JetType;
|
||||||
import org.objectweb.asm.Label;
|
import org.objectweb.asm.Label;
|
||||||
import org.objectweb.asm.MethodVisitor;
|
import org.objectweb.asm.MethodVisitor;
|
||||||
import org.objectweb.asm.Opcodes;
|
import org.objectweb.asm.Opcodes;
|
||||||
@@ -291,14 +293,17 @@ public class ExpressionCodegen extends JetVisitor {
|
|||||||
PsiMethod method = (PsiMethod) declarationPsiElement;
|
PsiMethod method = (PsiMethod) declarationPsiElement;
|
||||||
if (method.hasModifierProperty(PsiModifier.STATIC)) {
|
if (method.hasModifierProperty(PsiModifier.STATIC)) {
|
||||||
v.visitMethodInsn(Opcodes.INVOKESTATIC,
|
v.visitMethodInsn(Opcodes.INVOKESTATIC,
|
||||||
|
jvmName(method.getContainingClass()),
|
||||||
|
method.getName(),
|
||||||
|
getMethodDescriptor(method));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
v.visitMethodInsn(Opcodes.INVOKEVIRTUAL,
|
||||||
jvmName(method.getContainingClass()),
|
jvmName(method.getContainingClass()),
|
||||||
method.getName(),
|
method.getName(),
|
||||||
getMethodDescriptor(method));
|
getMethodDescriptor(method));
|
||||||
boxIfNeeded(method.getReturnType());
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw new UnsupportedOperationException("don't know how to generate instance method calls");
|
|
||||||
}
|
}
|
||||||
|
boxIfNeeded(method.getReturnType());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -315,14 +320,16 @@ public class ExpressionCodegen extends JetVisitor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void boxIfNeeded(PsiType type) {
|
private void boxIfNeeded(PsiType type) {
|
||||||
if (type == PsiType.LONG) {
|
if (type instanceof PsiPrimitiveType && type != PsiType.VOID) {
|
||||||
v.invokestatic("java/lang/Long", "valueOf", "(J)Ljava/lang/Long;");
|
if (type == PsiType.LONG) {
|
||||||
}
|
v.invokestatic("java/lang/Long", "valueOf", "(J)Ljava/lang/Long;");
|
||||||
else if (type == PsiType.INT) {
|
}
|
||||||
v.invokestatic("java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;");
|
else if (type == PsiType.INT) {
|
||||||
}
|
v.invokestatic("java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;");
|
||||||
else {
|
}
|
||||||
throw new UnsupportedOperationException("Don't know how to box type " + type);
|
else {
|
||||||
|
throw new UnsupportedOperationException("Don't know how to box type " + type);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -360,8 +367,40 @@ public class ExpressionCodegen extends JetVisitor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visitDotQualifiedExpression(JetDotQualifiedExpression expression) {
|
public void visitDotQualifiedExpression(JetDotQualifiedExpression expression) {
|
||||||
// gen(expression.getReceiverExpression());
|
JetExpression receiver = expression.getReceiverExpression();
|
||||||
expression.getSelectorExpression().accept(this);
|
if (!resolvesToClassOrPackage(receiver)) {
|
||||||
|
gen(expression.getReceiverExpression());
|
||||||
|
}
|
||||||
|
gen(expression.getSelectorExpression());
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean resolvesToClassOrPackage(JetExpression receiver) {
|
||||||
|
if (receiver instanceof JetReferenceExpression) {
|
||||||
|
DeclarationDescriptor declaration = bindingContext.resolveReferenceExpression((JetReferenceExpression) receiver);
|
||||||
|
PsiElement declarationElement = bindingContext.getDeclarationPsiElement(declaration);
|
||||||
|
if (declarationElement instanceof PsiClass) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visitSafeQualifiedExpression(JetSafeQualifiedExpression expression) {
|
||||||
|
gen(expression.getReceiverExpression());
|
||||||
|
Label ifnull = new Label();
|
||||||
|
Label end = new Label();
|
||||||
|
v.dup();
|
||||||
|
v.ifnull(ifnull);
|
||||||
|
gen(expression.getSelectorExpression());
|
||||||
|
v.goTo(end);
|
||||||
|
v.mark(ifnull);
|
||||||
|
// null is already on stack here after the dup
|
||||||
|
JetType expressionType = bindingContext.getExpressionType(expression);
|
||||||
|
if (expressionType.equals(JetStandardClasses.getUnitType())) {
|
||||||
|
v.pop();
|
||||||
|
}
|
||||||
|
v.mark(end);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
fun f() { System.out?.println("Hello World"); }
|
||||||
@@ -96,6 +96,16 @@ public class NamespaceGenTest extends LightCodeInsightFixtureTestCase {
|
|||||||
assertEquals(returnValue, System.out);
|
assertEquals(returnValue, System.out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testHelloWorld() throws Exception {
|
||||||
|
loadFile("helloWorld.jet");
|
||||||
|
|
||||||
|
final String text = generateToText();
|
||||||
|
System.out.println(text);
|
||||||
|
|
||||||
|
final Class aClass = generateToClass();
|
||||||
|
final Method main = firstMethod(aClass);
|
||||||
|
}
|
||||||
|
|
||||||
private void loadFile(final String name) {
|
private void loadFile(final String name) {
|
||||||
myFixture.configureByFile(JetParsingTest.getTestDataDir() + "/codegen/" + name);
|
myFixture.configureByFile(JetParsingTest.getTestDataDir() + "/codegen/" + name);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user