Skip to content

Commit 63187e3

Browse files
committed
Centralise application and better internals for detailing.
Some new hints for the syntax checker.
1 parent ebdde76 commit 63187e3

31 files changed

+321
-103
lines changed

CONTRIBUTING.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Contributing
22

3-
Please see the contributing guidelines and guide [here](https://docs.byteskript.org/tutorials/contributing-to-byteskript).
3+
Please see the contributing guidelines and
4+
guide [here](https://docs.byteskript.org/tutorials/contributing-to-byteskript).
45

5-
Please also refer to the contributors licensing [instructions](https://docs.byteskript.org/readme/licence-information#contributing-to-byteskript).
6+
Please also refer to the contributors
7+
licensing [instructions](https://docs.byteskript.org/readme/licence-information#contributing-to-byteskript).

TODO.md

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ Tasks are categorised by importance and marked by difficulty.
2020

2121
### Medium Importance
2222

23-
- Move some common syntax to the runtime. \
24-
A lot of extracted syntax should be in the runtime. \
25-
This would reduce the size of the output files. \
26-
Difficulty: easy
2723
- Create a library for Java GUIs. \
2824
This will probably need to interact with JavaFX. \
2925
This should be handled by somebody with experience using Java front-end. \
@@ -35,13 +31,9 @@ Tasks are categorised by importance and marked by difficulty.
3531

3632
### Least Important
3733

38-
- Convert function verifiers to `invokedynamic` call-site binders. \
39-
The first function call from a location can be verified and bound to the constant call-site for the function. \
40-
This can be used to type-verify a parameter set. \
41-
Difficulty: hard
4234
- Create a library for web-servers. \
4335
Support opening a web-server and receiving requests. \
4436
Support sending HTTP requests to a web-server. \
4537
Difficulty: medium
4638
- Create a library for Discord bots. \
47-
Difficulty: medium
39+
Difficulty: easy

pom.xml

Lines changed: 4 additions & 46 deletions
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.4</version>
9+
<version>1.0.5</version>
1010
<name>ByteSkript</name>
1111

1212
<properties>
@@ -23,7 +23,7 @@
2323
<artifactId>maven-assembly-plugin</artifactId>
2424
<executions>
2525
<execution>
26-
<id>build-loader</id>
26+
<id>build-app</id>
2727
<phase>package</phase>
2828
<goals>
2929
<goal>single</goal>
@@ -32,56 +32,14 @@
3232
<archive>
3333
<manifest>
3434
<mainClass>
35-
org.byteskript.skript.app.ScriptLoader
35+
org.byteskript.skript.app.ByteSkriptApp
3636
</mainClass>
3737
</manifest>
3838
</archive>
3939
<descriptorRefs>
4040
<descriptorRef>jar-with-dependencies</descriptorRef>
4141
</descriptorRefs>
42-
<finalName>ScriptLoader</finalName>
43-
<appendAssemblyId>false</appendAssemblyId>
44-
</configuration>
45-
</execution>
46-
<execution>
47-
<id>build-jar</id>
48-
<phase>package</phase>
49-
<goals>
50-
<goal>single</goal>
51-
</goals>
52-
<configuration>
53-
<archive>
54-
<manifest>
55-
<mainClass>
56-
org.byteskript.skript.app.ScriptJarBuilder
57-
</mainClass>
58-
</manifest>
59-
</archive>
60-
<descriptorRefs>
61-
<descriptorRef>jar-with-dependencies</descriptorRef>
62-
</descriptorRefs>
63-
<finalName>ScriptJarBuilder</finalName>
64-
<appendAssemblyId>false</appendAssemblyId>
65-
</configuration>
66-
</execution>
67-
<execution>
68-
<id>build-compiler</id>
69-
<phase>package</phase>
70-
<goals>
71-
<goal>single</goal>
72-
</goals>
73-
<configuration>
74-
<archive>
75-
<manifest>
76-
<mainClass>
77-
org.byteskript.skript.app.ScriptCompiler
78-
</mainClass>
79-
</manifest>
80-
</archive>
81-
<descriptorRefs>
82-
<descriptorRef>jar-with-dependencies</descriptorRef>
83-
</descriptorRefs>
84-
<finalName>ScriptClassCompiler</finalName>
42+
<finalName>ByteSkript</finalName>
8543
<appendAssemblyId>false</appendAssemblyId>
8644
</configuration>
8745
</execution>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ public void compile(Context context, Pattern.Match match) {
4444
context.setState(CompileState.MEMBER_BODY);
4545
method
4646
.addAnnotation(SourceData.class).setVisible(true)
47+
.addValue("name", name())
48+
.addValue("type", "event")
4749
.addValue("line", context.lineNumber())
4850
.addValue("compiled", Instant.now().getEpochSecond());
4951
method

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@
1313
import org.byteskript.skript.compiler.CompileState;
1414
import org.byteskript.skript.compiler.Context;
1515
import org.byteskript.skript.compiler.Pattern;
16-
import org.byteskript.skript.runtime.data.SourceData;
1716

1817
import java.lang.reflect.Modifier;
19-
import java.time.Instant;
2018

2119
public abstract class TriggerHolder extends Member {
2220
public TriggerHolder(Library provider, LanguageElement type, String... patterns) {
@@ -38,10 +36,6 @@ public void compile(Context context, Pattern.Match match) {
3836
.addParameter(parameters(context, match));
3937
context.setMethod(method);
4038
context.setState(CompileState.MEMBER_BODY);
41-
method
42-
.addAnnotation(SourceData.class).setVisible(true)
43-
.addValue("line", context.lineNumber())
44-
.addValue("compiled", Instant.now().getEpochSecond());
4539
}
4640

4741
}
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
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.app;
8+
9+
import mx.kenzie.foundation.language.PostCompileClass;
10+
import org.byteskript.skript.runtime.Skript;
11+
12+
import java.io.File;
13+
import java.io.FileInputStream;
14+
import java.io.InputStream;
15+
import java.util.ArrayList;
16+
import java.util.List;
17+
18+
import static org.byteskript.skript.app.ByteSkriptApp.Colour.*;
19+
20+
public class ByteSkriptApp extends SkriptApp {
21+
protected static final Skript SKRIPT = new Skript();
22+
23+
public static void main(String... args) throws Throwable {
24+
if (args.length < 1) {
25+
makeFiles();
26+
System.out.println(RESET + "Welcome to " + MAGENTA_BRIGHT + "ByteSkript" + RESET + "!");
27+
System.out.println(RESET + "Available arguments:");
28+
System.out.println(RESET + "\trun | " + CYAN + "Run scripts in the " + CYAN_UNDERLINED + "skripts/" + CYAN + " directory.");
29+
System.out.println(RESET + "\trun <file> | " + CYAN + "Run a single script in isolation.");
30+
System.out.println(RESET + "\tcompile | " + CYAN + "Compile library class files for all scripts.");
31+
System.out.println(RESET + "\t | " + CYAN + "Syntax-providing classes can be moved to the " + CYAN_UNDERLINED + "libraries/" + CYAN + " folder.");
32+
System.out.println(RESET + "\tjar <name> | " + CYAN + "Build a Jar file in " + CYAN_UNDERLINED + "compiled/" + CYAN + " from all your scripts.");
33+
System.out.println(RESET + "\t | " + CYAN + "This will include files in " + CYAN_UNDERLINED + "resources/" + CYAN);
34+
System.out.println(RESET + "\tclean | " + CYAN + "Cleans the " + CYAN_UNDERLINED + "compiled/" + CYAN + " folder.");
35+
System.out.print(RESET);
36+
System.out.println("Visit https://docs.byteskript.org for help and tutorials.");
37+
} else if (args[0].equalsIgnoreCase("clean")) {
38+
final List<File> files = getFiles(new ArrayList<>(), OUTPUT.toPath());
39+
int i = 50;
40+
while (!files.isEmpty() && i > 0) {
41+
files.removeIf(File::delete);
42+
i--;
43+
}
44+
if (!OUTPUT.exists()) OUTPUT.mkdirs();
45+
} else if (args[0].equalsIgnoreCase("run") && args.length < 2) {
46+
ScriptLoader.main();
47+
} else if (args[0].equalsIgnoreCase("run")) {
48+
final String name = args[1];
49+
final File file = new File(name);
50+
registerLibraries(SKRIPT);
51+
try (final InputStream stream = new FileInputStream(file)) {
52+
final PostCompileClass[] classes = SKRIPT.compileComplexScript(stream, "skript." + file.getName());
53+
for (final PostCompileClass type : classes) {
54+
SKRIPT.loadScript(type);
55+
}
56+
}
57+
new SimpleThrottleController(SKRIPT).run();
58+
} else if (args[0].equalsIgnoreCase("jar")) {
59+
final String[] arguments;
60+
if (args.length > 1) {
61+
arguments = new String[args.length - 1];
62+
System.arraycopy(args, 1, arguments, 0, arguments.length);
63+
} else arguments = new String[0];
64+
ScriptJarBuilder.main(arguments);
65+
} else if (args[0].equalsIgnoreCase("compile")) {
66+
ScriptCompiler.main();
67+
}
68+
}
69+
70+
static void makeFiles() {
71+
if (!SOURCE.exists()) SOURCE.mkdirs();
72+
if (!OUTPUT.exists()) OUTPUT.mkdirs();
73+
if (!LIBRARIES.exists()) LIBRARIES.mkdirs();
74+
if (!RESOURCES.exists()) RESOURCES.mkdirs();
75+
}
76+
77+
enum Colour {
78+
RESET("\033[0m"),
79+
BLACK("\033[0;30m"),
80+
RED("\033[0;31m"),
81+
GREEN("\033[0;32m"),
82+
YELLOW("\033[0;33m"),
83+
BLUE("\033[0;34m"),
84+
PURPLE("\033[0;35m"),
85+
CYAN("\033[0;36m"),
86+
WHITE("\033[0;37m"),
87+
88+
// Bold
89+
BLACK_BOLD("\033[1;30m"), // BLACK
90+
RED_BOLD("\033[1;31m"), // RED
91+
GREEN_BOLD("\033[1;32m"), // GREEN
92+
YELLOW_BOLD("\033[1;33m"), // YELLOW
93+
BLUE_BOLD("\033[1;34m"), // BLUE
94+
MAGENTA_BOLD("\033[1;35m"), // MAGENTA
95+
CYAN_BOLD("\033[1;36m"), // CYAN
96+
WHITE_BOLD("\033[1;37m"), // WHITE
97+
98+
// Underline
99+
BLACK_UNDERLINED("\033[4;30m"), // BLACK
100+
RED_UNDERLINED("\033[4;31m"), // RED
101+
GREEN_UNDERLINED("\033[4;32m"), // GREEN
102+
YELLOW_UNDERLINED("\033[4;33m"), // YELLOW
103+
BLUE_UNDERLINED("\033[4;34m"), // BLUE
104+
MAGENTA_UNDERLINED("\033[4;35m"), // MAGENTA
105+
CYAN_UNDERLINED("\033[4;36m"), // CYAN
106+
WHITE_UNDERLINED("\033[4;37m"), // WHITE
107+
108+
// Background
109+
BLACK_BACKGROUND("\033[40m"), // BLACK
110+
RED_BACKGROUND("\033[41m"), // RED
111+
GREEN_BACKGROUND("\033[42m"), // GREEN
112+
YELLOW_BACKGROUND("\033[43m"), // YELLOW
113+
BLUE_BACKGROUND("\033[44m"), // BLUE
114+
MAGENTA_BACKGROUND("\033[45m"), // MAGENTA
115+
CYAN_BACKGROUND("\033[46m"), // CYAN
116+
WHITE_BACKGROUND("\033[47m"), // WHITE
117+
118+
// High Intensity
119+
BLACK_BRIGHT("\033[0;90m"), // BLACK
120+
RED_BRIGHT("\033[0;91m"), // RED
121+
GREEN_BRIGHT("\033[0;92m"), // GREEN
122+
YELLOW_BRIGHT("\033[0;93m"), // YELLOW
123+
BLUE_BRIGHT("\033[0;94m"), // BLUE
124+
MAGENTA_BRIGHT("\033[0;95m"), // MAGENTA
125+
CYAN_BRIGHT("\033[0;96m"), // CYAN
126+
WHITE_BRIGHT("\033[0;97m"), // WHITE
127+
128+
// Bold High Intensity
129+
BLACK_BOLD_BRIGHT("\033[1;90m"), // BLACK
130+
RED_BOLD_BRIGHT("\033[1;91m"), // RED
131+
GREEN_BOLD_BRIGHT("\033[1;92m"), // GREEN
132+
YELLOW_BOLD_BRIGHT("\033[1;93m"), // YELLOW
133+
BLUE_BOLD_BRIGHT("\033[1;94m"), // BLUE
134+
MAGENTA_BOLD_BRIGHT("\033[1;95m"), // MAGENTA
135+
CYAN_BOLD_BRIGHT("\033[1;96m"), // CYAN
136+
WHITE_BOLD_BRIGHT("\033[1;97m"), // WHITE
137+
138+
// High Intensity backgrounds
139+
BLACK_BACKGROUND_BRIGHT("\033[0;100m"), // BLACK
140+
RED_BACKGROUND_BRIGHT("\033[0;101m"), // RED
141+
GREEN_BACKGROUND_BRIGHT("\033[0;102m"), // GREEN
142+
YELLOW_BACKGROUND_BRIGHT("\033[0;103m"), // YELLOW
143+
BLUE_BACKGROUND_BRIGHT("\033[0;104m"), // BLUE
144+
MAGENTA_BACKGROUND_BRIGHT("\033[0;105m"), // MAGENTA
145+
CYAN_BACKGROUND_BRIGHT("\033[0;106m"), // CYAN
146+
WHITE_BACKGROUND_BRIGHT("\033[0;107m"); // WHITE
147+
148+
private final String code;
149+
150+
Colour(String code) {
151+
this.code = code;
152+
}
153+
154+
@Override
155+
public String toString() {
156+
if (System.console() == null || System.getenv().get("TERM") != null) {
157+
return code;
158+
} else {
159+
return "";
160+
}
161+
}
162+
}
163+
164+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
public final class ScriptCompiler extends SkriptApp {
1414
private static final Skript SKRIPT = new Skript();
1515

16-
public static void main(String[] args) throws IOException {
16+
public static void main(String... args) throws IOException {
1717
registerLibraries(SKRIPT);
1818
SKRIPT.compileScripts(SOURCE, OUTPUT);
1919
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public final class ScriptLoader extends SkriptApp {
1919

2020
static final List<Script> SCRIPTS = new ArrayList<>();
2121

22-
public static void main(String[] args) throws IOException {
22+
public static void main(String... args) throws IOException {
2323
registerLibraries(SKRIPT);
2424
final Collection<Script> scripts = SKRIPT.compileLoadScripts(SOURCE);
2525
new SimpleThrottleController(SKRIPT).run();

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

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

2424
static final List<Script> SCRIPTS = new ArrayList<>();
2525

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

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public abstract class SkriptApp {
3030
ROOT = new File(SkriptApp.class.getProtectionDomain().getCodeSource().getLocation()
3131
.toURI()).getParentFile();
3232
} catch (URISyntaxException e) {
33-
throw new IllegalStateException("Unable to get root file.");
33+
throw new IllegalStateException("Unable to get root file.", e);
3434
}
3535
}
3636

@@ -39,13 +39,6 @@ public abstract class SkriptApp {
3939
protected static final File LIBRARIES = new File(ROOT, "libraries/");
4040
protected static final File OUTPUT = new File(ROOT, "compiled/");
4141

42-
static {
43-
if (!SOURCE.exists()) SOURCE.mkdirs();
44-
if (!OUTPUT.exists()) OUTPUT.mkdirs();
45-
if (!LIBRARIES.exists()) LIBRARIES.mkdirs();
46-
if (!RESOURCES.exists()) RESOURCES.mkdirs();
47-
}
48-
4942
protected static void registerLibraries(final Skript skript) {
5043
final List<File> files = getFiles(new ArrayList<>(), LIBRARIES.toPath());
5144
for (final File file : files) {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,11 +303,11 @@ public ProgrammaticSplitTree getCurrentTree() {
303303
}
304304

305305
@Override
306-
public void closeAllTrees() {
307-
for (ProgrammaticSplitTree tree : trees) {
306+
public synchronized void closeAllTrees() {
307+
for (ProgrammaticSplitTree tree : trees.toArray(new ProgrammaticSplitTree[0])) {
308308
tree.close(this);
309309
}
310-
trees.clear();
310+
this.trees.clear();
311311
}
312312

313313
@Override

0 commit comments

Comments
 (0)