Skip to content

Commit 1f63013

Browse files
authored
Add files via upload
1 parent afcbfc8 commit 1f63013

7 files changed

Lines changed: 445 additions & 71 deletions

File tree

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.devkev.devscript.raw;
2+
3+
import java.io.IOException;
4+
import java.io.InputStream;
5+
6+
public abstract class ApplicationInput extends InputStream {
7+
8+
private volatile boolean inputReqested = false;
9+
10+
private String data = "";
11+
private int index = 0;
12+
13+
@Override
14+
public int read() throws IOException {
15+
if(!inputReqested) {
16+
inputReqested = true;
17+
System.out.println("Awaiting input...");
18+
awaitInput();
19+
synchronized (this) {
20+
try {
21+
wait();
22+
} catch (InterruptedException e) {
23+
e.printStackTrace();
24+
}
25+
}
26+
}
27+
index++;
28+
if(index < data.length() && !data.isEmpty()) {
29+
System.out.println("Fetching data... " + data.getBytes()[index-1]);
30+
return data.getBytes()[index-1];
31+
} else {
32+
data = "";
33+
index = 0;
34+
return -1;
35+
}
36+
}
37+
38+
/**This function is called, before */
39+
public abstract void awaitInput();
40+
41+
public synchronized boolean inputRequested() {
42+
return inputReqested;
43+
}
44+
45+
public void flush(String data) {
46+
if(inputReqested) {
47+
this.data = data == null ? "" : data;
48+
synchronized (this) {
49+
notify();
50+
}
51+
}
52+
}
53+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.devkev.devscript.raw;
2+
3+
public interface ApplicationListener {
4+
/**Exit codes are: <br>{@link Block#DONE}<br> {@link Block#ERROR}*/
5+
public void done(int exitCode);
6+
}
Lines changed: 67 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,67 @@
1-
package com.devkev.devscript.raw;
2-
3-
import java.util.ArrayList;
4-
5-
import com.devkev.devscript.raw.ApplicationBuilder.Type;
6-
7-
public class Array { //For dataContainers
8-
private final ArrayList<Object> indexes = new ArrayList<Object>(2);
9-
public DataType arrayType;
10-
11-
public Array(Object... indexes) {
12-
for(Object d : indexes) this.indexes.add(d);
13-
updateArraytype();
14-
}
15-
16-
public Array() {
17-
updateArraytype();
18-
}
19-
20-
public void push(Object container) {
21-
indexes.add(container);
22-
updateArraytype();
23-
}
24-
25-
public void push(Object container, int index) {
26-
indexes.add(index, container);
27-
updateArraytype();
28-
}
29-
30-
public void pop(int index) {
31-
indexes.remove(index);
32-
updateArraytype();
33-
}
34-
35-
public void pop(Object container) {
36-
indexes.remove(container);
37-
updateArraytype();
38-
}
39-
40-
public ArrayList<Object> getIndexes() {
41-
return indexes;
42-
}
43-
44-
public void updateArraytype() {
45-
Type type = Type.NULL;
46-
for(int j = 0; j < indexes.size(); j++) {
47-
DataType containerType = ApplicationBuilder.toDataType(indexes.get(j));
48-
if(j > 0) {
49-
DataType indexType = ApplicationBuilder.toDataType(indexes.get(j-1));
50-
if(indexType.type != containerType.type && type != Type.ANY) {
51-
type = Type.ANY;
52-
break;
53-
}
54-
} else if(j == 0) {
55-
type = containerType.type;
56-
}
57-
}
58-
arrayType = new DataType(type, true);
59-
}
60-
61-
public String toString() {
62-
String s = "ARRAY:{";
63-
for(int i = 0; i < indexes.size()-1; i++) s += indexes.get(i) + ",";
64-
if(indexes.size() > 0) s += indexes.get(indexes.size()-1);
65-
return s + "}";
66-
}
67-
}
1+
package com.devkev.devscript.raw;
2+
3+
import java.util.ArrayList;
4+
5+
import com.devkev.devscript.raw.ApplicationBuilder.Type;
6+
7+
public class Array { //For dataContainers
8+
private final ArrayList<Object> indexes = new ArrayList<Object>(2);
9+
public DataType arrayType;
10+
11+
public Array(Object... indexes) {
12+
for(Object d : indexes) this.indexes.add(d);
13+
updateArraytype();
14+
}
15+
16+
public Array() {
17+
updateArraytype();
18+
}
19+
20+
public void push(Object container) {
21+
indexes.add(container);
22+
updateArraytype();
23+
}
24+
25+
public void push(Object container, int index) {
26+
indexes.add(index, container);
27+
updateArraytype();
28+
}
29+
30+
public void pop(int index) {
31+
indexes.remove(index);
32+
updateArraytype();
33+
}
34+
35+
public void pop(Object container) {
36+
indexes.remove(container);
37+
updateArraytype();
38+
}
39+
40+
public ArrayList<Object> getIndexes() {
41+
return indexes;
42+
}
43+
44+
public void updateArraytype() {
45+
Type type = Type.NULL;
46+
for(int j = 0; j < indexes.size(); j++) {
47+
DataType containerType = ApplicationBuilder.toDataType(indexes.get(j));
48+
if(j > 0) {
49+
DataType indexType = ApplicationBuilder.toDataType(indexes.get(j-1));
50+
if(indexType.type != containerType.type && type != Type.ANY) {
51+
type = Type.ANY;
52+
break;
53+
}
54+
} else if(j == 0) {
55+
type = containerType.type;
56+
}
57+
}
58+
arrayType = new DataType(type, true);
59+
}
60+
61+
public String toString() {
62+
String s = "ARRAY:{";
63+
for(int i = 0; i < indexes.size()-1; i++) s += indexes.get(i) + ",";
64+
if(indexes.size() > 0) s += indexes.get(indexes.size()-1);
65+
return s + "}";
66+
}
67+
}

com/devkev/devscript/raw/Block.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
public class Block { //So stupid...
66

7+
public static final byte DONE = 0;
8+
public static final byte ERROR = 1;
9+
710
public final StringBuilder blockCode;
811
public int executeIndex = 0; //The current char index, that is executed or compiled. 0 < ExecuteIndex < blockCode.length()
912
String currentCommand = "";
@@ -20,7 +23,7 @@ public class Block { //So stupid...
2023

2124
public boolean loop = false;
2225
ArrayList<Command> cached = new ArrayList<Command>(0);
23-
26+
int exitCode = DONE;
2427

2528
Block(StringBuilder blockCode, Block parent) {
2629
this.blockCode = blockCode;

com/devkev/devscript/raw/ConsoleMain.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import java.io.InputStreamReader;
77
import java.net.URLDecoder;
88

9+
import com.devkev.gui.Window;
10+
911
/**@author Philipp Gersch
1012
* @version 1.8.2 (stable)
1113
* Valid arguments are: <br>-e or --execute [some code] - Executes the String<br>
@@ -46,6 +48,8 @@ public static void main(String[] args) throws IOException {
4648
System.exit(-1);
4749
}
4850
p.execute(new File(args[1]), true);
49-
}
51+
} else if(args[0].equals("--gui") || args[0].equals("-g")) {
52+
new Window();
53+
}
5054
}
5155
}

com/devkev/devscript/raw/Process.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public class Process {
1717
private ArrayList<GeneratedLibrary> libraries = new ArrayList<GeneratedLibrary>();
1818
private ArrayList<Output> output = new ArrayList<Output>(1);
1919
private ArrayList<Variable> variables = new ArrayList<Variable>(5);
20+
private ApplicationListener listener;
2021

2122
private static final boolean False = false;
2223
private static final boolean True = true;
@@ -104,6 +105,7 @@ public Thread execute(String script, boolean newThread) {
104105
}
105106

106107
script = script.replaceAll("\t", "");
108+
script = script.replaceAll("\r", "");
107109

108110
main = new Block(new StringBuilder(script), null);
109111
main.thread = null;
@@ -165,6 +167,7 @@ private void start(Block block) {
165167
//char[] arr = block.blockCode.toCharArray();
166168
StringBuilder command = new StringBuilder();
167169

170+
block.exitCode = Block.DONE;
168171
block.alive = true;
169172
block.interrupted = false;
170173
if(!checkForInterrupt(block)) return;
@@ -250,6 +253,7 @@ else if(c == Alphabet.COMMENT && inComment && !inQuote) {
250253
}
251254

252255
block.alive = false;
256+
if(block.equals(main) && listener != null) listener.done(main.exitCode);
253257
aliveBlocks.remove(block);
254258
}
255259

@@ -650,10 +654,9 @@ public GeneratedLibrary getLibrary(String name) {
650654
return null;
651655
}
652656

653-
/***/
654657
public synchronized void kill(Block block, String errorMessage) {
655658
if(block == null) {
656-
error("Error in JVM> " + errorMessage);
659+
error("Java Error> " + errorMessage);
657660
return;
658661
} else {
659662
if (block.currentCommand.length() > 30) {
@@ -671,6 +674,7 @@ public synchronized void kill(Block block, String errorMessage) {
671674
block.currentCommand = "";
672675
}
673676

677+
block.exitCode = Block.ERROR;
674678
aliveBlocks.clear();
675679
garbageCollection(main);
676680
System.gc();
@@ -768,6 +772,14 @@ public void breakLoop() {
768772
breakRequested = true;
769773
}
770774

775+
public void setApplicationListener(ApplicationListener listener) {
776+
this.listener = listener;
777+
}
778+
779+
public ApplicationListener getApplicationListener() {
780+
return listener;
781+
}
782+
771783
public static String findMatching(String string, int start, int skip, char openChar, char closeChar, char escapeChar, boolean removeEscape) {
772784
char[] arr = string.toCharArray();
773785
int wrap = 0;

0 commit comments

Comments
 (0)