add static import of Opcodes.*

This commit is contained in:
Alex Tkachman
2012-08-28 14:30:37 +03:00
parent f1f22a15b0
commit 5b8492fd9f
10 changed files with 82 additions and 71 deletions
@@ -27,6 +27,8 @@ import org.jetbrains.jet.lang.resolve.java.JvmClassName;
import java.util.List; import java.util.List;
import static org.jetbrains.asm4.Opcodes.*;
/** /**
* @author yole * @author yole
* @author alex.tkacman * @author alex.tkacman
@@ -112,13 +114,13 @@ public class CallableMethod implements Callable {
v.iconst(mask); v.iconst(mask);
String desc = getSignature().getAsmMethod().getDescriptor().replace(")", "I)"); String desc = getSignature().getAsmMethod().getDescriptor().replace(")", "I)");
if ("<init>".equals(getSignature().getAsmMethod().getName())) { if ("<init>".equals(getSignature().getAsmMethod().getName())) {
v.visitMethodInsn(Opcodes.INVOKESPECIAL, defaultImplOwner.getInternalName(), "<init>", desc); v.visitMethodInsn(INVOKESPECIAL, defaultImplOwner.getInternalName(), "<init>", desc);
} }
else { else {
if (getInvokeOpcode() != Opcodes.INVOKESTATIC) { if (getInvokeOpcode() != INVOKESTATIC) {
desc = desc.replace("(", "(" + defaultImplParam.getDescriptor()); desc = desc.replace("(", "(" + defaultImplParam.getDescriptor());
} }
v.visitMethodInsn(Opcodes.INVOKESTATIC, defaultImplOwner.getInternalName(), v.visitMethodInsn(INVOKESTATIC, defaultImplOwner.getInternalName(),
getSignature().getAsmMethod().getName() + JvmAbi.DEFAULT_PARAMS_IMPL_SUFFIX, desc); getSignature().getAsmMethod().getName() + JvmAbi.DEFAULT_PARAMS_IMPL_SUFFIX, desc);
} }
} }
@@ -126,7 +126,7 @@ public abstract class ClassBodyCodegen {
private void generateStaticInitializer() { private void generateStaticInitializer() {
if (staticInitializerChunks.size() > 0) { if (staticInitializerChunks.size() > 0) {
final MethodVisitor mv = v.newMethod(null, ACC_PUBLIC | Opcodes.ACC_STATIC, "<clinit>", "()V", null, null); final MethodVisitor mv = v.newMethod(null, ACC_PUBLIC | ACC_STATIC, "<clinit>", "()V", null, null);
if (state.getClassBuilderMode() == ClassBuilderMode.FULL) { if (state.getClassBuilderMode() == ClassBuilderMode.FULL) {
mv.visitCode(); mv.visitCode();
@@ -136,7 +136,7 @@ public abstract class ClassBodyCodegen {
chunk.generate(v); chunk.generate(v);
} }
mv.visitInsn(Opcodes.RETURN); mv.visitInsn(RETURN);
FunctionCodegen.endVisit(v, "static initializer", myClass); FunctionCodegen.endVisit(v, "static initializer", myClass);
} }
} }
@@ -55,6 +55,7 @@ import org.jetbrains.jet.lexer.JetTokens;
import java.util.*; import java.util.*;
import static org.jetbrains.asm4.Opcodes.*;
import static org.jetbrains.jet.codegen.JetTypeMapper.*; import static org.jetbrains.jet.codegen.JetTypeMapper.*;
import static org.jetbrains.jet.codegen.context.CodegenBinding.*; import static org.jetbrains.jet.codegen.context.CodegenBinding.*;
import static org.jetbrains.jet.lang.resolve.BindingContext.*; import static org.jetbrains.jet.lang.resolve.BindingContext.*;
@@ -1244,7 +1245,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
v.areturn(returnType); v.areturn(returnType);
} }
else { else {
v.visitInsn(Opcodes.RETURN); v.visitInsn(RETURN);
} }
return StackValue.none(); return StackValue.none();
} }
@@ -1405,7 +1406,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
if (value instanceof StackValue.FieldForSharedVar) { if (value instanceof StackValue.FieldForSharedVar) {
StackValue.FieldForSharedVar fieldForSharedVar = (StackValue.FieldForSharedVar) value; StackValue.FieldForSharedVar fieldForSharedVar = (StackValue.FieldForSharedVar) value;
Type sharedType = StackValue.sharedTypeForType(value.type); Type sharedType = StackValue.sharedTypeForType(value.type);
v.visitFieldInsn(Opcodes.GETFIELD, fieldForSharedVar.owner.getInternalName(), fieldForSharedVar.name, v.visitFieldInsn(GETFIELD, fieldForSharedVar.owner.getInternalName(), fieldForSharedVar.name,
sharedType.getDescriptor()); sharedType.getDescriptor());
} }
@@ -1558,9 +1559,9 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
if (isInsideClass || isStatic || propertyDescriptor.getGetter() == null) { if (isInsideClass || isStatic || propertyDescriptor.getGetter() == null) {
owner = ownerParam = typeMapper.getOwner(propertyDescriptor, contextKind()); owner = ownerParam = typeMapper.getOwner(propertyDescriptor, contextKind());
isInterface = overridesTrait; isInterface = overridesTrait;
invokeOpcode = isStatic ? Opcodes.INVOKESTATIC : invokeOpcode = isStatic ? INVOKESTATIC :
overridesTrait ? Opcodes.INVOKEINTERFACE overridesTrait ? INVOKEINTERFACE
: Opcodes.INVOKEVIRTUAL; : INVOKEVIRTUAL;
} }
else { else {
isInterface = CodegenUtil.isInterface(containingDeclaration) || overridesTrait; isInterface = CodegenUtil.isInterface(containingDeclaration) || overridesTrait;
@@ -3520,7 +3521,7 @@ The "returned" value of try expression with no finally is either the last expres
throw new UnsupportedOperationException("tuple too large"); throw new UnsupportedOperationException("tuple too large");
} }
if (entries.size() == 0) { if (entries.size() == 0) {
v.visitFieldInsn(Opcodes.GETSTATIC, "jet/Tuple0", "INSTANCE", "Ljet/Tuple0;"); v.visitFieldInsn(GETSTATIC, "jet/Tuple0", "INSTANCE", "Ljet/Tuple0;");
return StackValue.onStack(JET_TUPLE0_TYPE); return StackValue.onStack(JET_TUPLE0_TYPE);
} }
@@ -559,8 +559,8 @@ public class JetTypeMapper {
ownerForDefaultParam.getInternalName() + (originalIsInterface ? JvmAbi.TRAIT_IMPL_SUFFIX : "")); ownerForDefaultParam.getInternalName() + (originalIsInterface ? JvmAbi.TRAIT_IMPL_SUFFIX : ""));
invokeOpcode = isInterface invokeOpcode = isInterface
? (superCall ? Opcodes.INVOKESTATIC : Opcodes.INVOKEINTERFACE) ? (superCall ? INVOKESTATIC : INVOKEINTERFACE)
: (isAccessor ? Opcodes.INVOKESTATIC : (superCall ? Opcodes.INVOKESPECIAL : Opcodes.INVOKEVIRTUAL)); : (isAccessor ? INVOKESTATIC : (superCall ? INVOKESPECIAL : INVOKEVIRTUAL));
if (isInterface && superCall) { if (isInterface && superCall) {
descriptor = mapSignature(functionDescriptor, false, OwnerKind.TRAIT_IMPL); descriptor = mapSignature(functionDescriptor, false, OwnerKind.TRAIT_IMPL);
owner = JvmClassName.byInternalName(owner.getInternalName() + JvmAbi.TRAIT_IMPL_SUFFIX); owner = JvmClassName.byInternalName(owner.getInternalName() + JvmAbi.TRAIT_IMPL_SUFFIX);
@@ -40,6 +40,7 @@ import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
import java.util.BitSet; import java.util.BitSet;
import static org.jetbrains.asm4.Opcodes.*;
import static org.jetbrains.jet.lang.resolve.BindingContextUtils.*; import static org.jetbrains.jet.lang.resolve.BindingContextUtils.*;
/** /**
@@ -73,9 +74,9 @@ public class PropertyCodegen {
generateSetter(p, propertyDescriptor); generateSetter(p, propertyDescriptor);
} }
else if (kind instanceof OwnerKind.DelegateKind) { else if (kind instanceof OwnerKind.DelegateKind) {
generateDefaultGetter(propertyDescriptor, Opcodes.ACC_PUBLIC, p); generateDefaultGetter(propertyDescriptor, ACC_PUBLIC, p);
if (propertyDescriptor.isVar()) { if (propertyDescriptor.isVar()) {
generateDefaultSetter(propertyDescriptor, Opcodes.ACC_PUBLIC, p); generateDefaultSetter(propertyDescriptor, ACC_PUBLIC, p);
} }
} }
} }
@@ -98,16 +99,16 @@ public class PropertyCodegen {
} }
int modifiers; int modifiers;
if (kind == OwnerKind.NAMESPACE) { if (kind == OwnerKind.NAMESPACE) {
modifiers = Opcodes.ACC_STATIC; modifiers = ACC_STATIC;
} }
else { else {
modifiers = Opcodes.ACC_PRIVATE; modifiers = ACC_PRIVATE;
} }
if (!propertyDescriptor.isVar()) { if (!propertyDescriptor.isVar()) {
modifiers |= Opcodes.ACC_FINAL; modifiers |= ACC_FINAL;
} }
if (JetStandardLibrary.getInstance().isVolatile(propertyDescriptor)) { if (JetStandardLibrary.getInstance().isVolatile(propertyDescriptor)) {
modifiers |= Opcodes.ACC_VOLATILE; modifiers |= ACC_VOLATILE;
} }
Type type = state.getInjector().getJetTypeMapper().mapType(propertyDescriptor.getType(), MapTypeMode.VALUE); Type type = state.getInjector().getJetTypeMapper().mapType(propertyDescriptor.getType(), MapTypeMode.VALUE);
FieldVisitor fieldVisitor = v.newField(p, modifiers, propertyDescriptor.getName().getName(), type.getDescriptor(), null, value); FieldVisitor fieldVisitor = v.newField(p, modifiers, propertyDescriptor.getName().getName(), type.getDescriptor(), null, value);
@@ -163,8 +164,8 @@ public class PropertyCodegen {
assert propertyDescriptor != null; assert propertyDescriptor != null;
int flags = JetTypeMapper.getAccessModifiers(propertyDescriptor, 0) | int flags = JetTypeMapper.getAccessModifiers(propertyDescriptor, 0) |
(propertyDescriptor.getModality() == Modality.ABSTRACT (propertyDescriptor.getModality() == Modality.ABSTRACT
? Opcodes.ACC_ABSTRACT ? ACC_ABSTRACT
: (propertyDescriptor.getModality() == Modality.FINAL ? Opcodes.ACC_FINAL : 0)); : (propertyDescriptor.getModality() == Modality.FINAL ? ACC_FINAL : 0));
generateDefaultGetter(propertyDescriptor, flags, p); generateDefaultGetter(propertyDescriptor, flags, p);
} }
@@ -178,17 +179,17 @@ public class PropertyCodegen {
} }
if (kind == OwnerKind.NAMESPACE) { if (kind == OwnerKind.NAMESPACE) {
flags |= Opcodes.ACC_STATIC; flags |= ACC_STATIC;
} }
PsiElement psiElement = descriptorToDeclaration(state.getBindingContext(), propertyDescriptor.getContainingDeclaration()); PsiElement psiElement = descriptorToDeclaration(state.getBindingContext(), propertyDescriptor.getContainingDeclaration());
boolean isTrait = psiElement instanceof JetClass && ((JetClass) psiElement).isTrait(); boolean isTrait = psiElement instanceof JetClass && ((JetClass) psiElement).isTrait();
if (isTrait && !(kind instanceof OwnerKind.DelegateKind)) { if (isTrait && !(kind instanceof OwnerKind.DelegateKind)) {
flags |= Opcodes.ACC_ABSTRACT; flags |= ACC_ABSTRACT;
} }
if (propertyDescriptor.getModality() == Modality.FINAL) { if (propertyDescriptor.getModality() == Modality.FINAL) {
flags |= Opcodes.ACC_FINAL; flags |= ACC_FINAL;
} }
JvmPropertyAccessorSignature signature = state.getInjector().getJetTypeMapper().mapGetterSignature(propertyDescriptor, kind); JvmPropertyAccessorSignature signature = state.getInjector().getJetTypeMapper().mapGetterSignature(propertyDescriptor, kind);
@@ -232,7 +233,7 @@ public class PropertyCodegen {
} }
else { else {
iv.visitFieldInsn( iv.visitFieldInsn(
kind == OwnerKind.NAMESPACE ? Opcodes.GETSTATIC : Opcodes.GETFIELD, kind == OwnerKind.NAMESPACE ? GETSTATIC : GETFIELD,
state.getInjector().getJetTypeMapper().getOwner(propertyDescriptor, kind).getInternalName(), state.getInjector().getJetTypeMapper().getOwner(propertyDescriptor, kind).getInternalName(),
propertyDescriptor.getName().getName(), propertyDescriptor.getName().getName(),
type.getDescriptor()); type.getDescriptor());
@@ -270,7 +271,7 @@ public class PropertyCodegen {
int modifiers = JetTypeMapper.getAccessModifiers(propertyDescriptor, 0); int modifiers = JetTypeMapper.getAccessModifiers(propertyDescriptor, 0);
PropertySetterDescriptor setter = propertyDescriptor.getSetter(); PropertySetterDescriptor setter = propertyDescriptor.getSetter();
int flags = setter == null ? modifiers : JetTypeMapper.getAccessModifiers(setter, modifiers); int flags = setter == null ? modifiers : JetTypeMapper.getAccessModifiers(setter, modifiers);
flags |= (propertyDescriptor.getModality() == Modality.ABSTRACT ? Opcodes.ACC_ABSTRACT : 0); flags |= (propertyDescriptor.getModality() == Modality.ABSTRACT ? ACC_ABSTRACT : 0);
generateDefaultSetter(propertyDescriptor, flags, p); generateDefaultSetter(propertyDescriptor, flags, p);
} }
@@ -284,17 +285,17 @@ public class PropertyCodegen {
} }
if (kind == OwnerKind.NAMESPACE) { if (kind == OwnerKind.NAMESPACE) {
flags |= Opcodes.ACC_STATIC; flags |= ACC_STATIC;
} }
PsiElement psiElement = descriptorToDeclaration(state.getBindingContext(), propertyDescriptor.getContainingDeclaration()); PsiElement psiElement = descriptorToDeclaration(state.getBindingContext(), propertyDescriptor.getContainingDeclaration());
boolean isTrait = psiElement instanceof JetClass && ((JetClass) psiElement).isTrait(); boolean isTrait = psiElement instanceof JetClass && ((JetClass) psiElement).isTrait();
if (isTrait && !(kind instanceof OwnerKind.DelegateKind)) { if (isTrait && !(kind instanceof OwnerKind.DelegateKind)) {
flags |= Opcodes.ACC_ABSTRACT; flags |= ACC_ABSTRACT;
} }
if (propertyDescriptor.getModality() == Modality.FINAL) { if (propertyDescriptor.getModality() == Modality.FINAL) {
flags |= Opcodes.ACC_FINAL; flags |= ACC_FINAL;
} }
JvmPropertyAccessorSignature signature = state.getInjector().getJetTypeMapper().mapSetterSignature(propertyDescriptor, kind); JvmPropertyAccessorSignature signature = state.getInjector().getJetTypeMapper().mapSetterSignature(propertyDescriptor, kind);
@@ -339,13 +340,13 @@ public class PropertyCodegen {
} }
else { else {
iv.load(paramCode, type); iv.load(paramCode, type);
iv.visitFieldInsn(kind == OwnerKind.NAMESPACE ? Opcodes.PUTSTATIC : Opcodes.PUTFIELD, iv.visitFieldInsn(kind == OwnerKind.NAMESPACE ? PUTSTATIC : PUTFIELD,
state.getInjector().getJetTypeMapper().getOwner(propertyDescriptor, kind).getInternalName(), state.getInjector().getJetTypeMapper().getOwner(propertyDescriptor, kind).getInternalName(),
propertyDescriptor.getName().getName(), propertyDescriptor.getName().getName(),
type.getDescriptor()); type.getDescriptor());
} }
iv.visitInsn(Opcodes.RETURN); iv.visitInsn(RETURN);
} }
} }
FunctionCodegen.endVisit(mv, "setter", origin); FunctionCodegen.endVisit(mv, "setter", origin);
@@ -38,6 +38,7 @@ import org.jetbrains.jet.lang.resolve.java.JvmClassName;
import javax.inject.Inject; import javax.inject.Inject;
import java.util.List; import java.util.List;
import static org.jetbrains.asm4.Opcodes.*;
import static org.jetbrains.jet.codegen.JetTypeMapper.OBJECT_TYPE; import static org.jetbrains.jet.codegen.JetTypeMapper.OBJECT_TYPE;
import static org.jetbrains.jet.codegen.context.CodegenBinding.*; import static org.jetbrains.jet.codegen.context.CodegenBinding.*;
@@ -102,8 +103,8 @@ public class ScriptCodegen {
ClassBuilder classBuilder = classFileFactory.newVisitor(className.getInternalName() + ".class"); ClassBuilder classBuilder = classFileFactory.newVisitor(className.getInternalName() + ".class");
classBuilder.defineClass(scriptDeclaration, classBuilder.defineClass(scriptDeclaration,
Opcodes.V1_6, V1_6,
Opcodes.ACC_PUBLIC, ACC_PUBLIC,
className.getInternalName(), className.getInternalName(),
null, null,
"java/lang/Object", "java/lang/Object",
@@ -129,7 +130,7 @@ public class ScriptCodegen {
Type blockType = jetTypeMapper.mapType(scriptDescriptor.getReturnType(), MapTypeMode.VALUE); Type blockType = jetTypeMapper.mapType(scriptDescriptor.getReturnType(), MapTypeMode.VALUE);
classBuilder.newField(null, Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL, ScriptNameUtil.LAST_EXPRESSION_VALUE_FIELD_NAME, classBuilder.newField(null, ACC_PUBLIC | ACC_FINAL, ScriptNameUtil.LAST_EXPRESSION_VALUE_FIELD_NAME,
blockType.getDescriptor(), null, null); blockType.getDescriptor(), null, null);
JvmMethodSignature jvmSignature = jetTypeMapper.mapScriptSignature(scriptDescriptor, importedScripts); JvmMethodSignature jvmSignature = jetTypeMapper.mapScriptSignature(scriptDescriptor, importedScripts);
@@ -137,7 +138,7 @@ public class ScriptCodegen {
state.setScriptConstructorMethod(jvmSignature.getAsmMethod()); state.setScriptConstructorMethod(jvmSignature.getAsmMethod());
MethodVisitor mv = classBuilder.newMethod( MethodVisitor mv = classBuilder.newMethod(
scriptDeclaration, Opcodes.ACC_PUBLIC, jvmSignature.getAsmMethod().getName(), jvmSignature.getAsmMethod().getDescriptor(), scriptDeclaration, ACC_PUBLIC, jvmSignature.getAsmMethod().getName(), jvmSignature.getAsmMethod().getDescriptor(),
null, null); null, null);
mv.visitCode(); mv.visitCode();
@@ -208,13 +209,13 @@ public class ScriptCodegen {
for (ScriptDescriptor earlierScript : earlierScripts) { for (ScriptDescriptor earlierScript : earlierScripts) {
JvmClassName earlierClassName; JvmClassName earlierClassName;
earlierClassName = classNameForScriptDescriptor(bindingContext, earlierScript); earlierClassName = classNameForScriptDescriptor(bindingContext, earlierScript);
int access = Opcodes.ACC_PRIVATE | Opcodes.ACC_FINAL; int access = ACC_PRIVATE | ACC_FINAL;
classBuilder.newField(null, access, getScriptFieldName(earlierScript), earlierClassName.getDescriptor(), null, null); classBuilder.newField(null, access, getScriptFieldName(earlierScript), earlierClassName.getDescriptor(), null, null);
} }
for (ValueParameterDescriptor parameter : script.getValueParameters()) { for (ValueParameterDescriptor parameter : script.getValueParameters()) {
Type parameterType = jetTypeMapper.mapType(parameter.getType(), MapTypeMode.VALUE); Type parameterType = jetTypeMapper.mapType(parameter.getType(), MapTypeMode.VALUE);
int access = Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL; int access = ACC_PUBLIC | ACC_FINAL;
classBuilder.newField(null, access, parameter.getName().getIdentifier(), parameterType.getDescriptor(), null, null); classBuilder.newField(null, access, parameter.getName().getIdentifier(), parameterType.getDescriptor(), null, null);
} }
} }
@@ -35,6 +35,7 @@ import org.jetbrains.jet.lexer.JetTokens;
import java.util.List; import java.util.List;
import static org.jetbrains.asm4.Opcodes.*;
import static org.jetbrains.jet.codegen.JetTypeMapper.OBJECT_TYPE; import static org.jetbrains.jet.codegen.JetTypeMapper.OBJECT_TYPE;
/** /**
@@ -302,7 +303,7 @@ public abstract class StackValue {
} }
public static void putTuple0Instance(InstructionAdapter v) { public static void putTuple0Instance(InstructionAdapter v) {
v.visitFieldInsn(Opcodes.GETSTATIC, "jet/Tuple0", "INSTANCE", "Ljet/Tuple0;"); v.visitFieldInsn(GETSTATIC, "jet/Tuple0", "INSTANCE", "Ljet/Tuple0;");
} }
protected void putAsBoolean(InstructionAdapter v) { protected void putAsBoolean(InstructionAdapter v) {
@@ -494,22 +495,22 @@ public abstract class StackValue {
public void condJump(Label label, boolean jumpIfFalse, InstructionAdapter v) { public void condJump(Label label, boolean jumpIfFalse, InstructionAdapter v) {
int opcode; int opcode;
if (opToken == JetTokens.EQEQ) { if (opToken == JetTokens.EQEQ) {
opcode = jumpIfFalse ? Opcodes.IFNE : Opcodes.IFEQ; opcode = jumpIfFalse ? IFNE : IFEQ;
} }
else if (opToken == JetTokens.EXCLEQ) { else if (opToken == JetTokens.EXCLEQ) {
opcode = jumpIfFalse ? Opcodes.IFEQ : Opcodes.IFNE; opcode = jumpIfFalse ? IFEQ : IFNE;
} }
else if (opToken == JetTokens.GT) { else if (opToken == JetTokens.GT) {
opcode = jumpIfFalse ? Opcodes.IFLE : Opcodes.IFGT; opcode = jumpIfFalse ? IFLE : IFGT;
} }
else if (opToken == JetTokens.GTEQ) { else if (opToken == JetTokens.GTEQ) {
opcode = jumpIfFalse ? Opcodes.IFLT : Opcodes.IFGE; opcode = jumpIfFalse ? IFLT : IFGE;
} }
else if (opToken == JetTokens.LT) { else if (opToken == JetTokens.LT) {
opcode = jumpIfFalse ? Opcodes.IFGE : Opcodes.IFLT; opcode = jumpIfFalse ? IFGE : IFLT;
} }
else if (opToken == JetTokens.LTEQ) { else if (opToken == JetTokens.LTEQ) {
opcode = jumpIfFalse ? Opcodes.IFGT : Opcodes.IFLE; opcode = jumpIfFalse ? IFGT : IFLE;
} }
else { else {
throw new UnsupportedOperationException("don't know how to generate this condjump"); throw new UnsupportedOperationException("don't know how to generate this condjump");
@@ -526,7 +527,7 @@ public abstract class StackValue {
v.lcmp(); v.lcmp();
} }
else { else {
opcode += (Opcodes.IF_ICMPEQ - Opcodes.IFEQ); opcode += (IF_ICMPEQ - IFEQ);
} }
v.visitJumpInsn(opcode, label); v.visitJumpInsn(opcode, label);
} }
@@ -541,10 +542,10 @@ public abstract class StackValue {
public void condJump(Label label, boolean jumpIfFalse, InstructionAdapter v) { public void condJump(Label label, boolean jumpIfFalse, InstructionAdapter v) {
int opcode; int opcode;
if (opToken == JetTokens.EQEQEQ) { if (opToken == JetTokens.EQEQEQ) {
opcode = jumpIfFalse ? Opcodes.IF_ACMPNE : Opcodes.IF_ACMPEQ; opcode = jumpIfFalse ? IF_ACMPNE : IF_ACMPEQ;
} }
else if (opToken == JetTokens.EXCLEQEQEQ) { else if (opToken == JetTokens.EXCLEQEQEQ) {
opcode = jumpIfFalse ? Opcodes.IF_ACMPEQ : Opcodes.IF_ACMPNE; opcode = jumpIfFalse ? IF_ACMPEQ : IF_ACMPNE;
} }
else { else {
throw new UnsupportedOperationException("don't know how to generate this condjump"); throw new UnsupportedOperationException("don't know how to generate this condjump");
@@ -879,7 +880,7 @@ public abstract class StackValue {
@Override @Override
public void put(Type type, InstructionAdapter v) { public void put(Type type, InstructionAdapter v) {
v.visitFieldInsn(isStatic ? Opcodes.GETSTATIC : Opcodes.GETFIELD, owner.getInternalName(), name, this.type.getDescriptor()); v.visitFieldInsn(isStatic ? GETSTATIC : GETFIELD, owner.getInternalName(), name, this.type.getDescriptor());
coerce(type, v); coerce(type, v);
} }
@@ -898,7 +899,7 @@ public abstract class StackValue {
@Override @Override
public void store(Type topOfStackType, InstructionAdapter v) { public void store(Type topOfStackType, InstructionAdapter v) {
coerce(topOfStackType, this.type, v); coerce(topOfStackType, this.type, v);
v.visitFieldInsn(isStatic ? Opcodes.PUTSTATIC : Opcodes.PUTFIELD, owner.getInternalName(), name, this.type.getDescriptor()); v.visitFieldInsn(isStatic ? PUTSTATIC : PUTFIELD, owner.getInternalName(), name, this.type.getDescriptor());
} }
} }
@@ -943,12 +944,12 @@ public abstract class StackValue {
public void put(Type type, InstructionAdapter v) { public void put(Type type, InstructionAdapter v) {
if (isSuper && isInterface) { if (isSuper && isInterface) {
assert getter != null; assert getter != null;
v.visitMethodInsn(Opcodes.INVOKESTATIC, methodOwner.getInternalName(), getter.getName(), v.visitMethodInsn(INVOKESTATIC, methodOwner.getInternalName(), getter.getName(),
getter.getDescriptor().replace("(", "(" + methodOwnerParam.getDescriptor())); getter.getDescriptor().replace("(", "(" + methodOwnerParam.getDescriptor()));
} }
else { else {
if (getter == null) { if (getter == null) {
v.visitFieldInsn(isStatic ? Opcodes.GETSTATIC : Opcodes.GETFIELD, methodOwner.getInternalName(), name, v.visitFieldInsn(isStatic ? GETSTATIC : GETFIELD, methodOwner.getInternalName(), name,
this.type.getDescriptor()); this.type.getDescriptor());
} }
else { else {
@@ -962,11 +963,11 @@ public abstract class StackValue {
public void store(Type topOfStackType, InstructionAdapter v) { public void store(Type topOfStackType, InstructionAdapter v) {
if (isSuper && isInterface) { if (isSuper && isInterface) {
assert setter != null; assert setter != null;
v.visitMethodInsn(Opcodes.INVOKESTATIC, methodOwner.getInternalName(), setter.getName(), v.visitMethodInsn(INVOKESTATIC, methodOwner.getInternalName(), setter.getName(),
setter.getDescriptor().replace("(", "(" + methodOwnerParam.getDescriptor())); setter.getDescriptor().replace("(", "(" + methodOwnerParam.getDescriptor()));
} }
else if (setter == null) { else if (setter == null) {
v.visitFieldInsn(isStatic ? Opcodes.PUTSTATIC : Opcodes.PUTFIELD, methodOwner.getInternalName(), name, v.visitFieldInsn(isStatic ? PUTSTATIC : PUTFIELD, methodOwner.getInternalName(), name,
this.type.getDescriptor()); this.type.getDescriptor());
} }
else { else {
@@ -1025,7 +1026,7 @@ public abstract class StackValue {
v.load(index, OBJECT_TYPE); v.load(index, OBJECT_TYPE);
Type refType = refType(this.type); Type refType = refType(this.type);
Type sharedType = sharedTypeForType(this.type); Type sharedType = sharedTypeForType(this.type);
v.visitFieldInsn(Opcodes.GETFIELD, sharedType.getInternalName(), "ref", refType.getDescriptor()); v.visitFieldInsn(GETFIELD, sharedType.getInternalName(), "ref", refType.getDescriptor());
coerce(refType, this.type, v); coerce(refType, this.type, v);
coerce(this.type, type, v); coerce(this.type, type, v);
if (isReleaseOnPut) { if (isReleaseOnPut) {
@@ -1040,7 +1041,7 @@ public abstract class StackValue {
v.swap(); v.swap();
Type refType = refType(this.type); Type refType = refType(this.type);
Type sharedType = sharedTypeForType(this.type); Type sharedType = sharedTypeForType(this.type);
v.visitFieldInsn(Opcodes.PUTFIELD, sharedType.getInternalName(), "ref", refType.getDescriptor()); v.visitFieldInsn(PUTFIELD, sharedType.getInternalName(), "ref", refType.getDescriptor());
} }
} }
@@ -1111,7 +1112,7 @@ public abstract class StackValue {
public void put(Type type, InstructionAdapter v) { public void put(Type type, InstructionAdapter v) {
Type sharedType = sharedTypeForType(this.type); Type sharedType = sharedTypeForType(this.type);
Type refType = refType(this.type); Type refType = refType(this.type);
v.visitFieldInsn(Opcodes.GETFIELD, sharedType.getInternalName(), "ref", refType.getDescriptor()); v.visitFieldInsn(GETFIELD, sharedType.getInternalName(), "ref", refType.getDescriptor());
StackValue.onStack(refType).coerce(this.type, v); StackValue.onStack(refType).coerce(this.type, v);
StackValue.onStack(this.type).coerce(type, v); StackValue.onStack(this.type).coerce(type, v);
} }
@@ -1119,7 +1120,7 @@ public abstract class StackValue {
@Override @Override
public void store(Type topOfStackType, InstructionAdapter v) { public void store(Type topOfStackType, InstructionAdapter v) {
coerce(topOfStackType, v); coerce(topOfStackType, v);
v.visitFieldInsn(Opcodes.PUTFIELD, sharedTypeForType(type).getInternalName(), "ref", refType(type).getDescriptor()); v.visitFieldInsn(PUTFIELD, sharedTypeForType(type).getInternalName(), "ref", refType(type).getDescriptor());
} }
} }
@@ -27,6 +27,8 @@ import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
import java.util.List; import java.util.List;
import static org.jetbrains.asm4.Opcodes.*;
public class TraitImplBodyCodegen extends ClassBodyCodegen { public class TraitImplBodyCodegen extends ClassBodyCodegen {
public TraitImplBodyCodegen(JetClassOrObject aClass, CodegenContext context, ClassBuilder v, GenerationState state) { public TraitImplBodyCodegen(JetClassOrObject aClass, CodegenContext context, ClassBuilder v, GenerationState state) {
super(aClass, context, v, state); super(aClass, context, v, state);
@@ -44,8 +46,8 @@ public class TraitImplBodyCodegen extends ClassBodyCodegen {
@Override @Override
protected void generateDeclaration() { protected void generateDeclaration() {
v.defineClass(myClass, Opcodes.V1_6, v.defineClass(myClass, V1_6,
Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL/*| Opcodes.ACC_SUPER*/, ACC_PUBLIC | ACC_FINAL/*| Opcodes.ACC_SUPER*/,
jvmName(), jvmName(),
null, null,
"java/lang/Object", "java/lang/Object",
@@ -29,6 +29,8 @@ import org.jetbrains.jet.lang.psi.JetExpression;
import java.util.List; import java.util.List;
import static org.jetbrains.asm4.Opcodes.*;
/** /**
* @author yole * @author yole
*/ */
@@ -73,6 +75,6 @@ public class BinaryOp implements IntrinsicMethod {
} }
private boolean shift() { private boolean shift() {
return opcode == Opcodes.ISHL || opcode == Opcodes.ISHR || opcode == Opcodes.IUSHR; return opcode == ISHL || opcode == ISHR || opcode == IUSHR;
} }
} }
@@ -35,6 +35,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import static org.jetbrains.asm4.Opcodes.*;
import static org.jetbrains.jet.lang.resolve.DescriptorUtils.getClassObjectName; import static org.jetbrains.jet.lang.resolve.DescriptorUtils.getClassObjectName;
/** /**
@@ -96,17 +97,17 @@ public class IntrinsicMethods {
declareIntrinsicFunction(typeName, Name.identifier("equals"), 1, EQUALS); declareIntrinsicFunction(typeName, Name.identifier("equals"), 1, EQUALS);
} }
declareBinaryOp(Name.identifier("plus"), Opcodes.IADD); declareBinaryOp(Name.identifier("plus"), IADD);
declareBinaryOp(Name.identifier("minus"), Opcodes.ISUB); declareBinaryOp(Name.identifier("minus"), ISUB);
declareBinaryOp(Name.identifier("times"), Opcodes.IMUL); declareBinaryOp(Name.identifier("times"), IMUL);
declareBinaryOp(Name.identifier("div"), Opcodes.IDIV); declareBinaryOp(Name.identifier("div"), IDIV);
declareBinaryOp(Name.identifier("mod"), Opcodes.IREM); declareBinaryOp(Name.identifier("mod"), IREM);
declareBinaryOp(Name.identifier("shl"), Opcodes.ISHL); declareBinaryOp(Name.identifier("shl"), ISHL);
declareBinaryOp(Name.identifier("shr"), Opcodes.ISHR); declareBinaryOp(Name.identifier("shr"), ISHR);
declareBinaryOp(Name.identifier("ushr"), Opcodes.IUSHR); declareBinaryOp(Name.identifier("ushr"), IUSHR);
declareBinaryOp(Name.identifier("and"), Opcodes.IAND); declareBinaryOp(Name.identifier("and"), IAND);
declareBinaryOp(Name.identifier("or"), Opcodes.IOR); declareBinaryOp(Name.identifier("or"), IOR);
declareBinaryOp(Name.identifier("xor"), Opcodes.IXOR); declareBinaryOp(Name.identifier("xor"), IXOR);
declareIntrinsicFunction(Name.identifier("Boolean"), Name.identifier("not"), 0, new Not()); declareIntrinsicFunction(Name.identifier("Boolean"), Name.identifier("not"), 0, new Not());