Skip to content

Commit 4db98e4

Browse files
committed
Clean up bootstrapper.
1 parent 863230b commit 4db98e4

2 files changed

Lines changed: 10 additions & 18 deletions

File tree

src/main/java/org/byteskript/skript/lang/syntax/function/ExprFunction.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,7 @@ private Pattern.Match createMatch(String thing, Context context) {
5656
final Matcher dummy = java.util.regex.Pattern.compile(buildDummyPattern(name, count)).matcher(thing);
5757
dummy.find();
5858
final List<Type> types = new ArrayList<>();
59-
for (int i = 0; i < count; i++) {
60-
types.add(CommonTypes.OBJECT);
61-
}
59+
for (int i = 0; i < count; i++) types.add(CommonTypes.OBJECT);
6260
return new Pattern.Match(dummy, new FunctionDetails(name, count), types.toArray(new Type[0]));
6361
}
6462

src/main/java/org/byteskript/skript/runtime/internal/Bootstrapper.java

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,7 @@ private static Handle getHandle(final Method method) {
5353
private static String getDescriptor(final Type ret, final Type... params) {
5454
final StringBuilder builder = new StringBuilder();
5555
builder.append("(");
56-
for (Type type : params) {
57-
builder.append(type.descriptorString());
58-
}
56+
for (final Type type : params) builder.append(type.descriptorString());
5957
builder
6058
.append(")")
6159
.append(ret.descriptorString());
@@ -66,19 +64,17 @@ private static String getDescriptor(final Type ret, final Type... params) {
6664
Gets the handle for a regular method, used for writing a dynamic call-site.
6765
""")
6866
public static Handle getBootstrap(final boolean isDynamic, final boolean isPrivate) {
67+
final String target;
68+
if (isPrivate) target = isDynamic ? "bootstrapPrivateDynamic" : "bootstrapPrivate";
69+
else target = isDynamic ? "bootstrapDynamic" : "bootstrap";
70+
final Class<?>[] array = new Class[] {MethodHandles.Lookup.class, String.class, MethodType.class, Class.class};
71+
final Method method;
6972
try {
70-
if (isPrivate) {
71-
if (isDynamic)
72-
return getHandle(Bootstrapper.class.getMethod("bootstrapPrivateDynamic", MethodHandles.Lookup.class, String.class, MethodType.class, Class.class));
73-
return getHandle(Bootstrapper.class.getMethod("bootstrapPrivate", MethodHandles.Lookup.class, String.class, MethodType.class, Class.class));
74-
} else {
75-
if (isDynamic)
76-
return getHandle(Bootstrapper.class.getMethod("bootstrapDynamic", MethodHandles.Lookup.class, String.class, MethodType.class, Class.class));
77-
return getHandle(Bootstrapper.class.getMethod("bootstrap", MethodHandles.Lookup.class, String.class, MethodType.class, Class.class));
78-
}
73+
method = Bootstrapper.class.getMethod(target, array);
7974
} catch (Throwable ex) {
8075
throw new ScriptBootstrapError(ex);
8176
}
77+
return Bootstrapper.getHandle(method);
8278
}
8379

8480
@Description("""
@@ -90,9 +86,7 @@ public static CallSite bootstrapFunction(MethodHandles.Lookup caller, String nam
9086
throws Exception {
9187
final org.objectweb.asm.Type[] types = org.objectweb.asm.Type.getArgumentTypes(args);
9288
final Class<?>[] arguments = new Class[types.length];
93-
for (int i = 0; i < types.length; i++) {
94-
arguments[i] = getClass(types[i].getClassName());
95-
}
89+
for (int i = 0; i < types.length; i++) arguments[i] = getClass(types[i].getClassName());
9690
return Metafactory.createBridge(caller, name, type, source, owner, arguments);
9791
}
9892

0 commit comments

Comments
 (0)