Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Topic/support lambda expressions #325

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1517,6 +1517,7 @@ public static Instruction convert(ByteCode[] bcs, ByteCode i, OperandStack stack
case INVOKESPECIAL: //183
case INVOKESTATIC: //184
case INVOKEINTERFACE: //185
case INVOKEDYNAMIC: //186
{
MethodCall ji = (MethodCall) i;
ji.className = replaceTotalCrossLangToJavaLang(ji.className);
Expand Down Expand Up @@ -1575,7 +1576,7 @@ public static Instruction convert(ByteCode[] bcs, ByteCode i, OperandStack stack
}

OperandReg _this;
if (op == INVOKESTATIC) {
if (op == INVOKESTATIC || op == INVOKEDYNAMIC) {
_this = new OperandReg(TCConstants.opr_regO);
_this.index = 0;
} else {
Expand Down Expand Up @@ -1604,7 +1605,7 @@ public static Instruction convert(ByteCode[] bcs, ByteCode i, OperandStack stack
}
break;
}
case NEW: //187 (186 is not used)
case NEW: //187
{
BC187_new ji = (BC187_new) i;
ji.className = replaceTotalCrossLangToJavaLang(ji.className);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ public interface JConstants {
public static final int INVOKESPECIAL = 183;
public static final int INVOKESTATIC = 184;
public static final int INVOKEINTERFACE = 185;
public static final int INVOKEDYNAMIC = 186;
public static final int NEW = 187;
public static final int NEWARRAY = 188;
public static final int ANEWARRAY = 189;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package tc.tools.converter.bytecode;

public class BC186_invokedynamic extends MethodCall {
public BC186_invokedynamic() {
super(readUInt16(pc + 1));
pcInc = 5;
}

@Override
public void exec() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ public static void initClasses() throws ClassNotFoundException {
bcClasses[183] = tc.tools.converter.bytecode.BC183_invokespecial.class;
bcClasses[184] = tc.tools.converter.bytecode.BC184_invokestatic.class;
bcClasses[185] = tc.tools.converter.bytecode.BC185_invokeinterface.class;
bcClasses[186] = tc.tools.converter.bytecode.BC186_invokedynamic.class;
bcClasses[187] = tc.tools.converter.bytecode.BC187_new.class;
bcClasses[188] = tc.tools.converter.bytecode.BC188_newarray.class;
bcClasses[189] = tc.tools.converter.bytecode.BC189_anewarray.class;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public MethodCall(int idx) {
JavaConstantInfo jci = (JavaConstantInfo) cp.constants[idx];
int classIndex = jci.index1;
int nameAndTypeIndex = jci.index2;
className = cp.getString1(classIndex);
className = cp.getClassName(jci);
name = cp.getString1(nameAndTypeIndex);
parameters = cp.getString2(nameAndTypeIndex);
pcInc = 3;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,19 @@ public JavaConstantPool(DataStream ds) throws totalcross.io.IOException {
break;
case 7: // Class
case 8: // String
constants[i] = new JavaConstantInfo(b, ds.readUnsignedShort());
break;
case 16: // method type
constants[i] = new JavaConstantInfo(b, ds.readUnsignedShort());
break;
case 9: // field
case 10: // method
case 11: // interface method
case 12: // name and type
constants[i] = new JavaConstantInfo(b, ds.readUnsignedShort(), ds.readUnsignedShort());
break;
case 18: // invoke dynamic
constants[i] = new JavaConstantInfo(b, ds.readUnsignedShort(), ds.readUnsignedShort());
break;
case 15: // method handle
constants[i] = new JavaConstantInfo(b, ds.readByte(), ds.readUnsignedShort());
break;
}
}
}
Expand All @@ -71,4 +76,11 @@ public String getString2(int idx) {
JavaConstantInfo ci = (JavaConstantInfo) constants[idx];
return (String) constants[ci.index2];
}

public String getClassName(JavaConstantInfo jci) {
if (jci.type == 18) {
return String.valueOf(jci.index1);
}
return getString1(jci.index1);
}
}