Skip to content

Commit

Permalink
Tidy up code.
Browse files Browse the repository at this point in the history
  • Loading branch information
Moderocky committed Aug 22, 2022
1 parent 768d0e7 commit 65b14fe
Show file tree
Hide file tree
Showing 57 changed files with 199 additions and 219 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>9.2</version>
<version>9.3</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/byteskript/skript/api/SyntaxElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ default boolean isDelay() {
default boolean requiresMainThread() {
return false;
}*/

@Ignore
default void addSkipInstruction(Context context, Consumer<Context> consumer) {
context.addSkipInstruction(consumer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ public GeneratedEntryNode(Library provider, final RecordComponent target, String
super(provider, StandardElements.NODE, patterns);
this.target = target;
}

@Override
public Type getReturnType() {
return CommonTypes.VOID;
}

@Override
public void preCompile(Context context, Pattern.Match match) throws Throwable {
final ElementTree tree = context.getCompileCurrent().nested()[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ public GeneratedEntrySection(Library provider, final Class<Record> target, Strin
super(provider, StandardElements.SECTION, patterns);
this.target = target;
}

@Override
public Type getReturnType() {
return CommonTypes.VOID;
}

@Override
public void compile(Context context, Pattern.Match match) throws Throwable {
context.setState(CompileState.AREA_BODY);
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/org/byteskript/skript/api/syntax/Effect.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,7 @@ public abstract class Effect extends Element implements SyntaxElement {
public Effect(final Library provider, final LanguageElement type, final String... patterns) {
super(provider, type, patterns);
}

@Override
public Type getReturnType() {
return CommonTypes.VOID;
}


@Override
public CompileState getSubState() {
return CompileState.STATEMENT; // looking for expressions here
Expand All @@ -42,6 +37,11 @@ public boolean allowAsInputFor(Type type) {
return true; // support meta-effects
}

@Override
public Type getReturnType() {
return CommonTypes.VOID;
}

@Override
public void preCompile(Context context, Pattern.Match match) throws Throwable {
final Method target = handlers.get(StandardHandlers.RUN);
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/org/byteskript/skript/api/syntax/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ public void onSectionExit(Context context, SectionMeta meta) {
context.setField(null);
context.setState(CompileState.ROOT);
}

@Override
public Type getReturnType() {
return CommonTypes.VOID;
}


@Override
public boolean allowAsInputFor(Type type) {
return false;
}

@Override
public Type getReturnType() {
return CommonTypes.VOID;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ public SectionEntry(Library provider, LanguageElement type, String... patterns)
public CompileState getSubState() {
return CompileState.MEMBER_BODY;
}

@Override
public Type getReturnType() {
return CommonTypes.VOID;
}

@Override
public boolean allowedIn(State state, Context context) {
return state == CompileState.MEMBER_BODY;
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/org/byteskript/skript/api/syntax/SimpleEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ public Pattern.Match match(String thing, Context context) {
public CompileState getSubState() {
return CompileState.MEMBER_BODY;
}

@Override
public Type getReturnType() {
return CommonTypes.VOID;
}


@Override
public boolean allowAsInputFor(Type type) {
return false;
}

@Override
public Type getReturnType() {
return CommonTypes.VOID;
}

@Override
public boolean allowedIn(State state, Context context) {
return state == CompileState.MEMBER_BODY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,6 @@ public MethodErasure useHandle(String property, HandlerType type) {
final List<PropertyAccessGenerator> list = this.usedProperties.get(type);
boolean unused = true;
for (Library library : this.libraries) {
sub:
for (PropertyHandler handler : library.getProperties()) {
if (!handler.name().equals(property)) continue;
if (!handler.type().equals(type)) continue;
Expand Down Expand Up @@ -389,7 +388,7 @@ public MethodErasure useHandle(String property, HandlerType type) {
list.add(generator);
}
final Type ret = type.expectReturn() ? CommonTypes.OBJECT : new Type(void.class);
final Type[] params = type.expectInputs() ? new Type[]{CommonTypes.OBJECT, CommonTypes.OBJECT} : new Type[]{CommonTypes.OBJECT};
final Type[] params = type.expectInputs() ? new Type[] {CommonTypes.OBJECT, CommonTypes.OBJECT} : new Type[] {CommonTypes.OBJECT};
return new MethodErasure(ret, "property_" + type.name() + "$" + property, params);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ public ElementTree assembleStatement(final String statement, final FileContext c
context.setState(handler.getSubState()); // move state change to syntax
context.currentEffect = handler;
details.lineMatched = handler;
inner:
for (int i = 0; i < types.length; i++) {
final String input = inputs[i];
final Type type = types[i];
Expand Down Expand Up @@ -268,7 +267,6 @@ public ElementTree assembleExpression(String expression, final Type expected, fi
if (inputs.length < types.length) continue;
context.setState(handler.getSubState()); // anticipate inner-effect state change
details.expressionMatched = handler;
inner:
for (int i = 0; i < types.length; i++) {
final String input = inputs[i];
final Type type = types[i];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ public void compile(Context context) {
else method.writeCode(WriteInstruction.returnEmpty()); // return empty
method.writeCode((writer, visitor) -> visitor.visitLabel(jump)); // end
}
field_property:
{
if (this.type == StandardHandlers.GET) method.writeCode((writer, visitor) -> {
visitor.visitVarInsn(25, 0); // load holder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ public Type getHolderType() {
public boolean allowAsInputFor(Type type) {
return super.allowAsInputFor(type) || CommonTypes.REFERENT.equals(type);
}

@Override
public Type getReturnType() {
return CommonTypes.OBJECT;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ public Pattern.Match match(String thing, Context context) {
public boolean allowAsInputFor(Type type) {
return false;
}

@Override
public Type getReturnType() {
return CommonTypes.VOID;
}

@Override
public boolean allowedIn(State state, Context context) {
return context.getState() == CompileState.ROOT && context.hasFlag(AreaFlag.IN_TYPE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ public Pattern.Match match(String thing, Context context) {
public boolean allowAsInputFor(Type type) {
return false;
}

@Override
public Type getReturnType() {
return CommonTypes.VOID;
}

@Override
public boolean allowedIn(State state, Context context) {
return super.allowedIn(state, context) && context.hasFlag(AreaFlag.IN_FUNCTION);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,33 @@ public EntryVerifySection() {
super(SkriptLangSpec.LIBRARY, StandardElements.SECTION, "verify");
}

@Override
public void onSectionExit(Context context, SectionMeta meta) {
final MethodBuilder method = context.getMethod();
assert method != null;
context.closeAllTrees();
if (method.getErasure().returnType().equals(new Type(void.class))) {
method.writeCode(WriteInstruction.returnEmpty());
} else {
method.writeCode(WriteInstruction.pushNull());
method.writeCode(WriteInstruction.returnObject());
}
context.emptyVariables();
context.removeFlag(AreaFlag.IN_TRIGGER);
context.removeFlag(AreaFlag.IN_VERIFIER);
context.setState(CompileState.MEMBER_BODY);
}

@Override
public boolean allowAsInputFor(Type type) {
return false;
}

@Override
public Type getReturnType() {
return CommonTypes.VOID;
}

@Override
public void compile(Context context, Pattern.Match match) {
final MethodBuilder target = context.getMethod();
Expand Down Expand Up @@ -76,31 +103,4 @@ private WriteInstruction prepareVariables(VerifyTree context) {
};
}

@Override
public void onSectionExit(Context context, SectionMeta meta) {
final MethodBuilder method = context.getMethod();
assert method != null;
context.closeAllTrees();
if (method.getErasure().returnType().equals(new Type(void.class))) {
method.writeCode(WriteInstruction.returnEmpty());
} else {
method.writeCode(WriteInstruction.pushNull());
method.writeCode(WriteInstruction.returnObject());
}
context.emptyVariables();
context.removeFlag(AreaFlag.IN_TRIGGER);
context.removeFlag(AreaFlag.IN_VERIFIER);
context.setState(CompileState.MEMBER_BODY);
}

@Override
public boolean allowAsInputFor(Type type) {
return false;
}

@Override
public Type getReturnType() {
return CommonTypes.VOID;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void onSectionExit(Context context, SectionMeta meta) {
final AnnotationBuilder<?> builder = context.getMethod().addAnnotation(handler.type().annotation)
.setVisible(true);
if (handler.type() != SyntaxTree.Type.PROPERTY) {
builder.addValue("value", new String[]{handler.pattern()});
builder.addValue("value", new String[] {handler.pattern()});
} else {
builder.addValue("value", handler.pattern());
builder.addValue("type", mode == null ? StandardHandlers.GET : mode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ public Pattern.Match match(String thing, Context context) {
if (!thing.startsWith("else if ")) return null;
return super.match(thing, context);
}

@Override
public Type getReturnType() {
return CommonTypes.VOID;
}

@Override
public void compile(Context context, Pattern.Match match) throws Throwable {
if (!(context.getTree(context.getSection(1)) instanceof IfElseTree tree))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ public Pattern.Match match(String thing, Context context) {
if (!thing.equals("else")) return null;
return super.match(thing, context);
}

@Override
public Type getReturnType() {
return CommonTypes.VOID;
}

@Override
public void compile(Context context, Pattern.Match match) {
if (!(context.getTree(context.getSection(1)) instanceof IfElseTree tree))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ public Pattern.Match match(String thing, Context context) {
if (!thing.startsWith("if ")) return null;
return super.match(thing, context);
}

@Override
public Type getReturnType() {
return CommonTypes.VOID;
}

@Override
public void compile(Context context, Pattern.Match match) throws Throwable {
final IfElseTree tree = new IfElseTree(context.getSection(1), new MultiLabel());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ public Pattern.Match match(String thing, Context context) {
if (!thing.startsWith("catch ")) return null;
return super.match(thing, context);
}

@Override
public Type getReturnType() {
return CommonTypes.VOID;
}

@Override
public void preCompile(Context context, Pattern.Match match) throws Throwable {
final ElementTree holder = context.getCompileCurrent().nested()[0];
Expand All @@ -72,7 +72,6 @@ public boolean allowedIn(State state, Context context) {
public void compileTogether(Context context, Pattern.Match match, TryCatchTree tree) throws Throwable {
final ElementTree holder = context.getCompileCurrent().nested()[0];
tree.branch(context);
store:
{
holder.type = StandardHandlers.SET;
holder.compile = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ public Pattern.Match match(String thing, Context context) {
if (!thing.startsWith("try")) return null;
return super.match(thing, context);
}

@Override
public Type getReturnType() {
return CommonTypes.VOID;
}

@Override
public void compile(Context context, Pattern.Match match) throws Throwable {
final TryCatchTree tree = new TryCatchTree(context.getSection(1), new MultiLabel());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ public Pattern.Match match(String thing, Context context) {
if (!thing.startsWith("monitor ")) return null;
return super.match(thing, context);
}

@Override
public Type getReturnType() {
return CommonTypes.VOID;
}

@Override
public void compile(Context context, Pattern.Match match) throws Throwable {
final MonitorTree tree = new MonitorTree(context.getSection(1));
Expand Down
Loading

0 comments on commit 65b14fe

Please sign in to comment.