Skip to content

Commit 2e0bc34

Browse files
committed
Repair correct closing order of configuration tree.
1 parent 1dc3c03 commit 2e0bc34

File tree

6 files changed

+42
-7
lines changed

6 files changed

+42
-7
lines changed

hello.csk

-3
This file was deleted.

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

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.byteskript.skript.compiler.structure.*;
1313
import org.byteskript.skript.error.ScriptCompileError;
1414
import org.byteskript.skript.lang.handler.StandardHandlers;
15+
import org.byteskript.skript.runtime.data.ScriptData;
1516
import org.byteskript.skript.runtime.internal.CompiledScript;
1617

1718
import java.lang.reflect.Method;
@@ -42,6 +43,7 @@ public class FileContext extends Context {
4243
protected ClassBuilder writer;
4344
protected FieldBuilder field;
4445
protected MethodBuilder method;
46+
protected String sourceFile;
4547
LanguageElement expected;
4648
SyntaxElement currentEffect;
4749
private HandlerType mode = StandardHandlers.GET;
@@ -52,6 +54,7 @@ public FileContext(Type type) {
5254

5355
public FileContext(Type type, int computation) {
5456
this.type = type;
57+
this.sourceFile = type.getTypeName().replace('.', '/') + ".bsk";
5558
this.state = CompileState.ROOT;
5659
this.writer = new ClassBuilder(type, SkriptLangSpec.JAVA_VERSION)
5760
.addModifiers(Modifier.PUBLIC)
@@ -81,6 +84,7 @@ public List<ProgrammaticSplitTree> getTrees() {
8184
}
8285

8386
public PostCompileClass[] compile() {
87+
this.writer.addAnnotation(ScriptData.class).addValue("sourceFile", sourceFile);
8488
for (List<PropertyAccessGenerator> value : usedProperties.values()) {
8589
for (PropertyAccessGenerator generator : value) {
8690
generator.compile(this);

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

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public void branch(Context context) {
4343
public void close(Context context) {
4444
if (end.uses.size() > 0)
4545
context.getMethod().writeCode(end.instruction());
46+
context.removeTree(this);
4647
}
4748

4849
@Override

src/main/java/org/byteskript/skript/lang/syntax/config/ConfigFile.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,16 @@ public void compile(Context context, Pattern.Match match) throws Throwable {
9090

9191
@Override
9292
public void onSectionExit(Context context, SectionMeta meta) {
93-
final ConfigTree tree = context.findTree(ConfigTree.class);
93+
final ConfigTree current;
94+
if (context.getTree(context.getSection()) instanceof ConfigTree found) current = found;
95+
else if (context.getCurrentTree() instanceof ConfigTree found) current = found;
96+
else return;
9497
final MethodBuilder method = context.getMethod();
95-
if (tree == null) return;
96-
final int slot = context.slotOf(tree.variable);
98+
final int slot = context.slotOf(current.variable);
9799
method.writeCode(WriteInstruction.loadObject(slot));
98100
final Method target = this.findMethod(ConfigMap.class, "save");
99101
method.writeCode(WriteInstruction.invoke(target));
102+
current.close(context);
100103
}
101104

102105
@Override
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright (c) 2021 ByteSkript org (Moderocky)
3+
* View the full licence information and permissions:
4+
* https://github.com/Moderocky/ByteSkript/blob/master/LICENSE
5+
*/
6+
7+
package org.byteskript.skript.runtime.data;
8+
9+
import mx.kenzie.autodoc.api.note.Ignore;
10+
11+
import java.lang.annotation.ElementType;
12+
import java.lang.annotation.Retention;
13+
import java.lang.annotation.RetentionPolicy;
14+
import java.lang.annotation.Target;
15+
16+
@Ignore
17+
@Target(ElementType.TYPE)
18+
@Retention(RetentionPolicy.RUNTIME)
19+
public @interface ScriptData {
20+
21+
String sourceFile();
22+
23+
}

src/main/java/org/byteskript/skript/runtime/threading/ScriptExceptionHandler.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
package org.byteskript.skript.runtime.threading;
88

99
import org.byteskript.skript.error.ScriptParseError;
10+
import org.byteskript.skript.runtime.Skript;
11+
import org.byteskript.skript.runtime.data.ScriptData;
1012

1113
import static org.byteskript.skript.runtime.internal.ConsoleColour.*;
1214

@@ -88,7 +90,12 @@ public void uncaughtException(Thread source, Throwable throwable) {
8890

8991
private String getScriptName(final StackTraceElement element) {
9092
final String location = element.getClassName();
91-
return location.replace('.', '/') + ".bsk";
93+
try {
94+
final Class<?> owner = Skript.localInstance().getClass(location);
95+
return owner.getAnnotation(ScriptData.class).sourceFile();
96+
} catch (Throwable ex) {
97+
return location.replace('.', '/') + ".bsk";
98+
}
9299
}
93100

94101
}

0 commit comments

Comments
 (0)