X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Finternal%2Fcodegen%2Futils%2FMethodBuilderBase.java;h=bd1a911a15f4ec4fe2342284baec23414da7a1a2;hb=78f577368ba4c71ad6fb3d9f16c03c634585cf7b;hp=0f56aba8e2fbeae1c22c8b8893d3091a8921326c;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/utils/MethodBuilderBase.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/utils/MethodBuilderBase.java index 0f56aba8e..bd1a911a1 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/utils/MethodBuilderBase.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/utils/MethodBuilderBase.java @@ -25,6 +25,10 @@ public class MethodBuilderBase { } methodVisitor.visitCode(); } + + public LocalVariable getThis(TypeDesc type) { + return new LocalVariable(0, type); + } public void loadConstant(boolean value) { if(value) @@ -379,6 +383,7 @@ public class MethodBuilderBase { public void invokeInterface(String className, String methodName, TypeDesc ret, TypeDesc[] params) { checkClassName(className); + checkParameters(params); methodVisitor.visitMethodInsn(Opcodes.INVOKEINTERFACE, className, methodName, MethodDesc.forArguments(ret, params).getDescriptor(), true); } @@ -391,6 +396,7 @@ public class MethodBuilderBase { public void invokeVirtual(String className, String methodName, TypeDesc ret, TypeDesc[] params) { checkClassName(className); + checkParameters(params); methodVisitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, className, methodName, MethodDesc.forArguments(ret, params).getDescriptor(), false); } @@ -402,6 +408,7 @@ public class MethodBuilderBase { public void invokeConstructor(String className, TypeDesc[] params) { checkClassName(className); + checkParameters(params); methodVisitor.visitMethodInsn(Opcodes.INVOKESPECIAL, className, "", MethodDesc.forArguments(TypeDesc.VOID, params).getDescriptor(), false); } @@ -417,6 +424,7 @@ public class MethodBuilderBase { public void invokeStatic(String className, String methodName, TypeDesc ret, TypeDesc[] params) { checkClassName(className); + checkParameters(params); methodVisitor.visitMethodInsn(Opcodes.INVOKESTATIC, className, methodName, MethodDesc.forArguments(ret, params).getDescriptor(), false); } @@ -429,6 +437,10 @@ public class MethodBuilderBase { public void newObject(TypeDesc type) { methodVisitor.visitTypeInsn(Opcodes.NEW, getClassName(type)); } + + public void newObject(String type) { + methodVisitor.visitTypeInsn(Opcodes.NEW, type); + } public void newObject(TypeDesc type, int dimensions) { methodVisitor.visitMultiANewArrayInsn(type.getDescriptor(), dimensions); @@ -576,4 +588,36 @@ public class MethodBuilderBase { public static String getClassName(Class clazz) { return clazz.getName().replace('.', '/'); } + + public void switch_(int[] values, Label[] labels, Label defaultLabel) { + int lo = values[0]; + int hi = values[values.length-1]; + long table_space_cost = 4 + ((long) hi - lo + 1); // words + long table_time_cost = 3; // comparisons + long lookup_space_cost = 3 + 2 * (long) values.length; + long lookup_time_cost = values.length; + if(values.length > 0 && + table_space_cost + 3 * table_time_cost <= + lookup_space_cost + 3 * lookup_time_cost) { + Label[] table = new Label[hi - lo + 1]; + for(int i=0,j=0;i