Skip to content

Commit 3da1c90

Browse files
committed
Flag triggers correctly.
1 parent c085bd0 commit 3da1c90

File tree

12 files changed

+94
-93
lines changed

12 files changed

+94
-93
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>org.byteskript</groupId>
88
<artifactId>byteskript</artifactId>
9-
<version>1.0.9</version>
9+
<version>1.0.10</version>
1010
<name>ByteSkript</name>
1111
<description>A compiled JVM implementation of the Skript language.</description>
1212

src/main/java/org/byteskript/skript/api/ModifiableLibrary.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,16 @@ public Type registerType(Class<?> cls) {
5555
return type;
5656
}
5757

58-
public void registerSyntax(State state, SyntaxElement element) {
59-
this.syntax.putIfAbsent(state, new ArrayList<>());
60-
this.syntax.get(state).add(element);
61-
}
62-
6358
public void registerEvent(EventHolder event) {
6459
this.registerSyntax(CompileState.ROOT, event);
6560
this.registerValues(event);
6661
}
6762

63+
public void registerSyntax(State state, SyntaxElement element) {
64+
this.syntax.putIfAbsent(state, new ArrayList<>());
65+
this.syntax.get(state).add(element);
66+
}
67+
6868
public void registerProperty(String name, HandlerType type, Method handler) {
6969
this.properties.add(new PropertyHandler(type, handler, name));
7070
}

src/main/java/org/byteskript/skript/api/syntax/Element.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,18 @@ public final Pattern getPattern() {
3333
}
3434

3535
@Override
36-
public String[] getPatterns() {
37-
return pattern.getPatterns();
36+
public Library getProvider() {
37+
return provider;
3838
}
3939

4040
@Override
41-
public Library getProvider() {
42-
return provider;
41+
public Method getHandler(HandlerType type) {
42+
return handlers.get(type);
4343
}
4444

4545
@Override
46-
public LanguageElement getType() {
47-
return type;
46+
public void setHandler(HandlerType type, Method method) {
47+
this.handlers.put(type, method);
4848
}
4949

5050
@Override
@@ -53,13 +53,13 @@ public boolean hasHandler(HandlerType type) {
5353
}
5454

5555
@Override
56-
public Method getHandler(HandlerType type) {
57-
return handlers.get(type);
56+
public LanguageElement getType() {
57+
return type;
5858
}
5959

6060
@Override
61-
public void setHandler(HandlerType type, Method method) {
62-
this.handlers.put(type, method);
61+
public String[] getPatterns() {
62+
return pattern.getPatterns();
6363
}
6464

6565
}

src/main/java/org/byteskript/skript/api/syntax/EventHolder.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,6 @@ public void onSectionExit(Context context, SectionMeta meta) {
3131
super.onSectionExit(context, meta);
3232
}
3333

34-
@Override
35-
public Type returnType(Context context, Pattern.Match match) {
36-
return new Type(void.class);
37-
}
38-
39-
@Override
40-
public Type[] parameters(Context context, Pattern.Match match) {
41-
return new Type[0];
42-
}
43-
44-
@Override
45-
public String callSiteName(Context context, Pattern.Match match) {
46-
return null;
47-
}
48-
4934
@Override
5035
public void compile(Context context, Pattern.Match match) {
5136
final Class<? extends Event> eventClass = eventClass();
@@ -69,5 +54,20 @@ public void compile(Context context, Pattern.Match match) {
6954
context.addFlag(AreaFlag.IN_EVENT);
7055
}
7156

57+
@Override
58+
public String callSiteName(Context context, Pattern.Match match) {
59+
return null;
60+
}
61+
62+
@Override
63+
public Type returnType(Context context, Pattern.Match match) {
64+
return new Type(void.class);
65+
}
66+
67+
@Override
68+
public Type[] parameters(Context context, Pattern.Match match) {
69+
return new Type[0];
70+
}
71+
7272
public abstract Class<? extends Event> eventClass();
7373
}

src/main/java/org/byteskript/skript/app/SkriptApp.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,20 @@
2323
import java.util.jar.JarFile;
2424

2525
public abstract class SkriptApp {
26-
protected static final File ROOT;
27-
28-
static {
26+
protected static final File ROOT = getRoot();
27+
protected static final File SOURCE = new File(ROOT, "skript/");
28+
protected static final File RESOURCES = new File(ROOT, "resources/");
29+
protected static final File LIBRARIES = new File(ROOT, "libraries/");
30+
protected static final File OUTPUT = new File(ROOT, "compiled/");
31+
32+
private static File getRoot() {
2933
try {
30-
ROOT = new File(SkriptApp.class.getProtectionDomain().getCodeSource().getLocation()
34+
return new File(SkriptApp.class.getProtectionDomain().getCodeSource().getLocation()
3135
.toURI()).getParentFile();
3236
} catch (URISyntaxException e) {
3337
throw new IllegalStateException("Unable to get root file.", e);
3438
}
3539
}
36-
protected static final File SOURCE = new File(ROOT, "skript/");
37-
protected static final File RESOURCES = new File(ROOT, "resources/");
38-
protected static final File LIBRARIES = new File(ROOT, "libraries/");
39-
protected static final File OUTPUT = new File(ROOT, "compiled/");
4040

4141
protected static void registerLibraries(final Skript skript) {
4242
final List<File> files = getFiles(new ArrayList<>(), LIBRARIES.toPath());
@@ -65,8 +65,7 @@ protected static void callLibrary(final File file, final String main, final Skri
6565
final LibraryClassLoader child = new LibraryClassLoader(file, SkriptApp.class.getClassLoader());
6666
final Class<?> target = Class.forName(main, true, child);
6767
try {
68-
target.getMethod("load", Skript.class)
69-
.invoke(null, skript);
68+
target.getMethod("load", Skript.class).invoke(null, skript);
7069
} catch (Throwable ex) {
7170
throw new ScriptLibraryError("Library '" + file.getName() + "' main class is missing load method:\n" +
7271
"static void load(Skript skript)");

src/main/java/org/byteskript/skript/compiler/AreaFlag.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
public enum AreaFlag implements Flag {
1212
IN_SYNTAX,
1313
IN_FUNCTION,
14+
IN_VERIFIER,
1415
IN_TRIGGER,
1516
IN_PROPERTY,
1617
IN_TYPE,

src/main/java/org/byteskript/skript/compiler/structure/ExtractionTree.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,12 @@ public SectionMeta owner() {
3838
return owner;
3939
}
4040

41-
public MultiLabel getEnd() {
42-
return end;
43-
}
44-
4541
public Label getNext() {
4642
return next;
4743
}
4844

49-
public void setNext(Label next) {
50-
this.next = next;
45+
public MultiLabel getEnd() {
46+
return end;
5147
}
5248

5349
@Override
@@ -79,4 +75,8 @@ public boolean isOpen() {
7975
return open;
8076
}
8177

78+
public void setNext(Label next) {
79+
this.next = next;
80+
}
81+
8282
}

src/main/java/org/byteskript/skript/compiler/structure/IfElseTree.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,12 @@ public SectionMeta owner() {
3232
return owner;
3333
}
3434

35-
public MultiLabel getEnd() {
36-
return end;
37-
}
38-
3935
public Label getNext() {
4036
return next;
4137
}
4238

43-
public void setNext(Label next) {
44-
this.next = next;
39+
public MultiLabel getEnd() {
40+
return end;
4541
}
4642

4743
@Override
@@ -73,4 +69,8 @@ public boolean isOpen() {
7369
return open;
7470
}
7571

72+
public void setNext(Label next) {
73+
this.next = next;
74+
}
75+
7676
}

src/main/java/org/byteskript/skript/lang/syntax/entry/Trigger.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ public class Trigger extends SectionEntry {
4040

4141
private final WriteInstruction wrap = WriteInstruction
4242
.invokeStatic(new Type(AtomicVariable.class), new Type(AtomicVariable.class), "wrap", CommonTypes.OBJECT);
43-
private final WriteInstruction unwrap = WriteInstruction
44-
.invokeStatic(new Type(AtomicVariable.class), CommonTypes.OBJECT, "unwrap", CommonTypes.OBJECT);
4543

4644
public Trigger() {
4745
super(SkriptLangSpec.LIBRARY, StandardElements.SECTION, "trigger");
@@ -56,6 +54,7 @@ public Pattern.Match match(String thing, Context context) {
5654
public void compile(Context context, Pattern.Match match) {
5755
final TriggerTree tree = new TriggerTree(context.getSection(1), context.getVariables());
5856
context.createTree(tree);
57+
context.addFlag(AreaFlag.IN_TRIGGER);
5958
context.setState(CompileState.CODE_BODY);
6059
final MethodBuilder method = context.getMethod();
6160
method.removeModifiers(0x0400); // not abstract
@@ -83,7 +82,7 @@ private WriteInstruction prepareVariables(TriggerTree context) {
8382
}
8483
};
8584
}
86-
85+
8786
@Override
8887
public boolean allowedIn(State state, Context context) {
8988
return super.allowedIn(state, context) && context.getParent() instanceof TriggerHolder;
@@ -101,6 +100,7 @@ public void onSectionExit(Context context, SectionMeta meta) {
101100
method.writeCode(WriteInstruction.returnObject());
102101
}
103102
context.emptyVariables();
103+
context.removeFlag(AreaFlag.IN_TRIGGER);
104104
context.setState(CompileState.MEMBER_BODY);
105105
}
106106

src/main/java/org/byteskript/skript/lang/syntax/entry/Verify.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@
1313
import org.byteskript.skript.api.note.Documentation;
1414
import org.byteskript.skript.api.syntax.Section;
1515
import org.byteskript.skript.api.syntax.TriggerHolder;
16-
import org.byteskript.skript.compiler.CompileState;
17-
import org.byteskript.skript.compiler.Context;
18-
import org.byteskript.skript.compiler.Pattern;
19-
import org.byteskript.skript.compiler.SkriptLangSpec;
16+
import org.byteskript.skript.compiler.*;
2017
import org.byteskript.skript.compiler.structure.PreVariable;
2118
import org.byteskript.skript.compiler.structure.SectionMeta;
2219
import org.byteskript.skript.compiler.structure.VerifyTree;
@@ -49,6 +46,8 @@ public void compile(Context context, Pattern.Match match) {
4946
final MethodBuilder target = context.getMethod();
5047
final VerifyTree tree = new VerifyTree(context.getSection(1), target, context.getVariables());
5148
context.createTree(tree);
49+
context.addFlag(AreaFlag.IN_TRIGGER); // technically a trigger section
50+
context.addFlag(AreaFlag.IN_VERIFIER);
5251
context.setState(CompileState.CODE_BODY);
5352
final MethodBuilder method = context.getBuilder()
5453
.addMethod(target.getErasure().name() + "_verify")
@@ -89,6 +88,8 @@ public void onSectionExit(Context context, SectionMeta meta) {
8988
method.writeCode(WriteInstruction.returnObject());
9089
}
9190
context.emptyVariables();
91+
context.removeFlag(AreaFlag.IN_TRIGGER);
92+
context.removeFlag(AreaFlag.IN_VERIFIER);
9293
context.setState(CompileState.MEMBER_BODY);
9394
}
9495

0 commit comments

Comments
 (0)