Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Shrink codegen for tuple generation

  • Loading branch information...
commit ea0960b68b859a35e0145a75d2170fc75f7e7aec 1 parent 1d4c4bb
@krestenkrab krestenkrab authored
View
20 src/main/java/erjang/ETuple.java
@@ -234,6 +234,8 @@ private static ETuple make_big(int size) {
// create copy
create_tuple_copy(num_cells, cw, this_class_name, super_class_name);
+ create_tuple_make(num_cells, cw, this_class_name, super_class_name);
+
// create nth
create_tuple_nth(num_cells, cw, this_class_name);
@@ -267,6 +269,24 @@ private static void create_tuple_copy(int i, ClassVisitor cw,
mv.visitEnd();
}
+ private static void create_tuple_make(int i, ClassVisitor cw,
+ String this_class_name, String super_class_name) {
+ MethodVisitor mv;
+
+ mv = cw.visitMethod(Opcodes.ACC_PUBLIC|Opcodes.ACC_STATIC, "create", "()L"
+ + this_class_name + ";", null, null);
+ mv.visitCode();
+ mv.visitTypeInsn(Opcodes.NEW, this_class_name);
+ mv.visitInsn(Opcodes.DUP);
+ mv.visitMethodInsn(Opcodes.INVOKESPECIAL, this_class_name, "<init>",
+ "()V");
+
+ mv.visitInsn(Opcodes.ARETURN);
+
+ mv.visitMaxs(3, 3);
+ mv.visitEnd();
+ }
+
private static void make_blank_bridge(ClassVisitor cw,
String this_class_name, String super_class_name) {
MethodVisitor mv;
View
4 src/main/java/erjang/ETuple0.java
@@ -35,6 +35,10 @@ public ETuple0 blank() {
return new ETuple0();
}
+ public static ETuple0 create() {
+ return new ETuple0();
+ }
+
@Override
public int arity() {
return 0;
View
4 src/main/java/erjang/ETuple1.java
@@ -44,6 +44,10 @@ public ETuple1 blank() {
return res;
}
+ public static ETuple1 create() {
+ return new ETuple1();
+ }
+
@Override
public int arity() {
return 1;
View
4 src/main/java/erjang/ETuple2.java
@@ -54,6 +54,10 @@ public ETuple2 blank() {
return res;
}
+ public static ETuple2 create() {
+ return new ETuple2();
+ }
+
@Override
public int arity() {
return 2;
View
4 src/main/java/erjang/ETuple3.java
@@ -35,6 +35,10 @@ public ETuple3 blank() {
return res;
}
+ public static ETuple3 create() {
+ return new ETuple3();
+ }
+
@Override
public int arity() {
return 3;
View
4 src/main/java/erjang/ETuple4.java
@@ -41,6 +41,10 @@ public ETuple4 blank() {
return res;
}
+ public static ETuple4 create() {
+ return new ETuple4();
+ }
+
@Override
public int arity() {
return 4;
View
10 src/main/java/erjang/beam/CompilerVisitor.java
@@ -2124,12 +2124,11 @@ public void visitInsn(BeamOpcode insn) {
public void visitInsn(BeamOpcode opcode, int val, Arg out) {
switch (opcode) {
case put_tuple:
- mv.visitTypeInsn(NEW, out.type.getInternalName());
- mv.visitInsn(DUP);
- mv.visitMethodInsn(INVOKESPECIAL,
- out.type.getInternalName(), "<init>", "()V");
+ {
+ String name = out.type.getInternalName();
+ mv.visitMethodInsn(INVOKESTATIC, name, "create", "()L" + name + ";");
pop(out, out.type);
-
+ }
return;
case wait_timeout: {
@@ -2670,7 +2669,6 @@ public void visitInsn(BeamOpcode opcode, Arg[] ys) {
for (int i = 0; i < ys.length; i++) {
if (i != (ys.length - 1))
mv.visitInsn(DUP);
- mv.visitInsn(NOP);
pop(ys[i], ENIL_TYPE);
}
Please sign in to comment.
Something went wrong with that request. Please try again.