Skip to content

Commit 7e6f912

Browse files
committed
Tidying up multiple compiler structures.
1 parent 22e131f commit 7e6f912

File tree

6 files changed

+17
-42
lines changed

6 files changed

+17
-42
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class ScriptRunner {
2525

2626
public static void main(String... args) throws IOException, ClassNotFoundException {
2727
final Class<?>[] classes = findClasses("skript/");
28-
for (Class<?> source : classes) {
28+
for (final Class<?> source : classes) {
2929
final Script script = SKRIPT.loadScript(source);
3030
SCRIPTS.add(script);
3131
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,14 @@ public Library[] getLibraries() {
109109
return libraries.toArray(new Library[0]);
110110
}
111111

112+
@Override
113+
public SimpleSkriptCompiler clone() {
114+
final SimpleSkriptCompiler compiler = new SimpleSkriptCompiler();
115+
compiler.libraries.clear();
116+
compiler.libraries.addAll(this.libraries);
117+
return compiler;
118+
}
119+
112120
protected void compileLine(final String line, final FileContext context) {
113121
final ElementTree tree = parseLine(line, context);
114122
if (tree == null) return;

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,8 @@ public SkriptLangSpec getLanguage() {
3737

3838
public abstract PostCompileClass[] compile(String file, Type path);
3939

40+
@Override
41+
public SkriptCompiler clone() {
42+
return this; // non-cloneable implementation
43+
}
4044
}

src/main/java/org/byteskript/skript/runtime/Skript.java

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import java.nio.file.Path;
3131
import java.util.*;
3232
import java.util.concurrent.*;
33-
import java.util.concurrent.atomic.AtomicInteger;
3433

3534
@Description("""
3635
This class is the entry-point for any program or library using ByteSkript.
@@ -593,44 +592,6 @@ public PostCompileClass[] compileScripts(final File root) throws IOException {
593592
return scripts.toArray(new PostCompileClass[0]);
594593
}
595594

596-
@Description("""
597-
Compiles all scripts in the root file to code representations.
598-
These representations may be loaded, written to files or otherwise used.
599-
""")
600-
@GenerateExample
601-
@CompilerDependent
602-
public Promise<PostCompileClass[]> compileScriptsAsync(final File root) throws IOException {
603-
if (!root.exists()) throw new ScriptLoadError("Root folder does not exist.");
604-
if (!root.isDirectory()) throw new ScriptLoadError("Root must be a folder.");
605-
final List<File> files = getFiles(new ArrayList<>(), root.toPath());
606-
final CompletableFuture<PostCompileClass[]> future = new CompletableFuture<>();
607-
final Promise<PostCompileClass[]> promise = new Promise<>(future);
608-
final Collection<PostCompileClass> scripts = Collections.synchronizedCollection(new ArrayList<>());
609-
final AtomicInteger integer = new AtomicInteger();
610-
for (final File file : files) {
611-
if (file == null) continue;
612-
if (!file.getName().endsWith(".bsk")) continue;
613-
try (final InputStream stream = new FileInputStream(file)) {
614-
final String name = this.getClassName(file, root);
615-
this.compileComplexScriptAsync(stream, name)
616-
.whenComplete(output -> {
617-
scripts.addAll(Arrays.asList(output));
618-
integer.incrementAndGet();
619-
});
620-
}
621-
}
622-
final int expected = files.size();
623-
future.completeAsync(() -> {
624-
while (integer.get() < expected) {
625-
try {
626-
Thread.sleep(5);
627-
} catch (InterruptedException e) {}
628-
}
629-
return scripts.toArray(new PostCompileClass[0]);
630-
}, this.executor);
631-
return promise;
632-
}
633-
634595
@Description("""
635596
Compiles a single script to its class files.
636597
This method may be unavailable in some distributions.

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
2727
Compilers will already have to implement the majority of these methods from the Compiler interface.
2828
""")
29-
public interface ModifiableCompiler {
29+
public interface ModifiableCompiler extends Cloneable {
3030

3131
Class<?> load(byte[] bytecode, String name);
3232

@@ -69,4 +69,6 @@ default Promise<PostCompileClass[]> compileAsync(String file, Type path, Skript
6969

7070
PostCompileClass[] compile(String file, Type path);
7171

72+
ModifiableCompiler clone();
73+
7274
}

src/test/java/org/byteskript/skript/test/PropertiesTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class PropertiesTest extends SkriptTest {
2222
public static void start() throws Throwable {
2323
final PostCompileClass[] classes = skript.compileComplexScript(TypesTest.class.getClassLoader()
2424
.getResourceAsStream("properties.bsk"), "skript.properties");
25-
for (PostCompileClass cls : classes) {
25+
for (final PostCompileClass cls : classes) {
2626
if (script == null)
2727
script = skript.loadScript(cls);
2828
else skript.loadScript(cls);

0 commit comments

Comments
 (0)