Skip to content

Commit

Permalink
Repair correct closing order of configuration tree.
Browse files Browse the repository at this point in the history
  • Loading branch information
Moderocky committed Mar 16, 2022
1 parent 1dc3c03 commit 2e0bc34
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 7 deletions.
3 changes: 0 additions & 3 deletions hello.csk

This file was deleted.

4 changes: 4 additions & 0 deletions src/main/java/org/byteskript/skript/compiler/FileContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.byteskript.skript.compiler.structure.*;
import org.byteskript.skript.error.ScriptCompileError;
import org.byteskript.skript.lang.handler.StandardHandlers;
import org.byteskript.skript.runtime.data.ScriptData;
import org.byteskript.skript.runtime.internal.CompiledScript;

import java.lang.reflect.Method;
Expand Down Expand Up @@ -42,6 +43,7 @@ public class FileContext extends Context {
protected ClassBuilder writer;
protected FieldBuilder field;
protected MethodBuilder method;
protected String sourceFile;
LanguageElement expected;
SyntaxElement currentEffect;
private HandlerType mode = StandardHandlers.GET;
Expand All @@ -52,6 +54,7 @@ public FileContext(Type type) {

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

public PostCompileClass[] compile() {
this.writer.addAnnotation(ScriptData.class).addValue("sourceFile", sourceFile);
for (List<PropertyAccessGenerator> value : usedProperties.values()) {
for (PropertyAccessGenerator generator : value) {
generator.compile(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public void branch(Context context) {
public void close(Context context) {
if (end.uses.size() > 0)
context.getMethod().writeCode(end.instruction());
context.removeTree(this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,16 @@ public void compile(Context context, Pattern.Match match) throws Throwable {

@Override
public void onSectionExit(Context context, SectionMeta meta) {
final ConfigTree tree = context.findTree(ConfigTree.class);
final ConfigTree current;
if (context.getTree(context.getSection()) instanceof ConfigTree found) current = found;
else if (context.getCurrentTree() instanceof ConfigTree found) current = found;
else return;
final MethodBuilder method = context.getMethod();
if (tree == null) return;
final int slot = context.slotOf(tree.variable);
final int slot = context.slotOf(current.variable);
method.writeCode(WriteInstruction.loadObject(slot));
final Method target = this.findMethod(ConfigMap.class, "save");
method.writeCode(WriteInstruction.invoke(target));
current.close(context);
}

@Override
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/org/byteskript/skript/runtime/data/ScriptData.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright (c) 2021 ByteSkript org (Moderocky)
* View the full licence information and permissions:
* https://github.com/Moderocky/ByteSkript/blob/master/LICENSE
*/

package org.byteskript.skript.runtime.data;

import mx.kenzie.autodoc.api.note.Ignore;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Ignore
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface ScriptData {

String sourceFile();

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
package org.byteskript.skript.runtime.threading;

import org.byteskript.skript.error.ScriptParseError;
import org.byteskript.skript.runtime.Skript;
import org.byteskript.skript.runtime.data.ScriptData;

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

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

private String getScriptName(final StackTraceElement element) {
final String location = element.getClassName();
return location.replace('.', '/') + ".bsk";
try {
final Class<?> owner = Skript.localInstance().getClass(location);
return owner.getAnnotation(ScriptData.class).sourceFile();
} catch (Throwable ex) {
return location.replace('.', '/') + ".bsk";
}
}

}

0 comments on commit 2e0bc34

Please sign in to comment.