Sfoglia il codice sorgente

- Improving compilation system to have compilation targets

- Added run & build functionality to the IDE
- Fixed an error in match expressions
- WIP on compiling to Java source files
Stan Hebben 6 anni fa
parent
commit
4987a05c10
53 ha cambiato i file con 1523 aggiunte e 54 eliminazioni
  1. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/FunctionHeader.java
  2. 7
    3
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/ZSPackage.java
  3. 20
    0
      CompilerShared/build.gradle
  4. 24
    0
      CompilerShared/src/main/java/org/openzen/zenscript/compiler/CompilerOutput.java
  5. 3
    6
      CompilerShared/src/main/java/org/openzen/zenscript/compiler/SemanticModule.java
  6. 22
    0
      CompilerShared/src/main/java/org/openzen/zenscript/compiler/Target.java
  7. 17
    0
      CompilerShared/src/main/java/org/openzen/zenscript/compiler/TargetType.java
  8. 23
    0
      CompilerShared/src/main/java/org/openzen/zenscript/compiler/ZenCodeCompiler.java
  9. 3
    0
      Constructor/build.gradle
  10. 3
    3
      Constructor/libraries/stdlib/src/Arrays.zs
  11. 37
    0
      Constructor/src/main/java/org/openzen/zenscript/constructor/ConstructorRegistry.java
  12. 1
    1
      Constructor/src/main/java/org/openzen/zenscript/constructor/Module.java
  13. 1
    1
      Constructor/src/main/java/org/openzen/zenscript/constructor/ModuleLoader.java
  14. 21
    0
      Constructor/src/main/java/org/openzen/zenscript/constructor/Project.java
  15. 2
    1
      Constructor/src/main/java/org/openzen/zenscript/constructor/module/DirectoryModuleLoader.java
  16. 2
    0
      Constructor/src/main/java/org/openzen/zenscript/constructor/module/ModuleReference.java
  17. 4
    3
      Constructor/src/main/java/org/openzen/zenscript/constructor/module/ModuleSpace.java
  18. 38
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/DCompositeIcon.java
  19. 82
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/DInputField.java
  20. 45
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/DInputFieldStyle.java
  21. 7
    5
      DrawableGui/src/main/java/org/openzen/drawablegui/DUIWindow.java
  22. 110
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/form/DForm.java
  23. 22
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/form/DFormComponent.java
  24. 41
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/form/DFormStyle.java
  25. 24
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/live/LiveString.java
  26. 40
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/live/SimpleLiveString.java
  27. 14
    0
      DrawableGui/src/main/java/org/openzen/drawablegui/swing/SwingWindow.java
  28. 1
    1
      IDE/src/main/java/org/openzen/zenscript/ide/Main.java
  29. 2
    0
      IDE/src/main/java/org/openzen/zenscript/ide/host/DevelopmentHost.java
  30. 22
    0
      IDE/src/main/java/org/openzen/zenscript/ide/host/IDETarget.java
  31. 12
    0
      IDE/src/main/java/org/openzen/zenscript/ide/host/local/LocalProjectDevelopmentHost.java
  32. 90
    0
      IDE/src/main/java/org/openzen/zenscript/ide/host/local/LocalTarget.java
  33. 22
    6
      IDE/src/main/java/org/openzen/zenscript/ide/ui/IDEWindow.java
  34. 2
    2
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/TabbedView.java
  35. 1
    11
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/TabbedViewStyle.java
  36. 1
    1
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/TabbedViewTabStyle.java
  37. 1
    0
      JavaBytecodeCompiler/build.gradle
  38. 51
    0
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaBytecodeJarTarget.java
  39. 26
    0
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaBytecodeJarTargetType.java
  40. 51
    0
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaBytecodeRunTarget.java
  41. 26
    0
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaBytecodeRunTargetType.java
  42. 19
    2
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaCompiler.java
  43. 19
    0
      JavaSourceCompiler/build.gradle
  44. 148
    0
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaDefinitionVisitor.java
  45. 84
    0
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceCompiler.java
  46. 79
    0
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceFile.java
  47. 41
    0
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceObjectTypeVisitor.java
  48. 53
    0
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceTarget.java
  49. 26
    0
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceTargetType.java
  50. 125
    0
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceTypeVisitor.java
  51. 1
    1
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedMatchExpression.java
  52. 2
    2
      ScriptingExample/src/main/java/org/openzen/zenscript/scriptingexample/GlobalRegistry.java
  53. 4
    4
      ScriptingExample/src/main/java/org/openzen/zenscript/scriptingexample/Main.java

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/FunctionHeader.java Vedi File

@@ -265,7 +265,7 @@ public class FunctionHeader {
265 265
 	@Override
266 266
 	public String toString() {
267 267
 		StringBuilder result = new StringBuilder();
268
-		if (typeParameters.length > 0) {
268
+		if (typeParameters != null && typeParameters.length > 0) {
269 269
 			result.append("<");
270 270
 			for (int i = 0; i < typeParameters.length; i++) {
271 271
 				if (i > 0)

+ 7
- 3
CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/ZSPackage.java Vedi File

@@ -25,10 +25,14 @@ import org.openzen.zenscript.codemodel.scope.TypeScope;
25 25
  * @author Hoofdgebruiker
26 26
  */
27 27
 public class ZSPackage {
28
+	public final String name;
28 29
 	public final String fullName;
30
+	public final ZSPackage parent;
29 31
 	
30
-	public ZSPackage(String fullName) {
31
-		this.fullName = fullName;
32
+	public ZSPackage(ZSPackage parent, String name) {
33
+		this.parent = parent;
34
+		this.name = name;
35
+		this.fullName = parent == null ? name : parent.fullName + "." + name;
32 36
 	}
33 37
 	
34 38
 	private final Map<String, ZSPackage> subPackages = new HashMap<>();
@@ -116,7 +120,7 @@ public class ZSPackage {
116 120
 		if (subPackages.containsKey(name))
117 121
 			return subPackages.get(name);
118 122
 		
119
-		ZSPackage result = new ZSPackage(fullName.isEmpty() ? name : fullName + '.' + name);
123
+		ZSPackage result = new ZSPackage(this, name);
120 124
 		subPackages.put(name, result);
121 125
 		return result;
122 126
 	}

+ 20
- 0
CompilerShared/build.gradle Vedi File

@@ -0,0 +1,20 @@
1
+// Note: "common.gradle" in the root project contains additional initialization
2
+//   for this project. This initialization is applied in the "build.gradle"
3
+//   of the root project.
4
+
5
+// NetBeans will automatically add "run" and "debug" tasks relying on the
6
+// "mainClass" property. You may however define the property prior executing
7
+// tasks by passing a "-PmainClass=<QUALIFIED_CLASS_NAME>" argument.
8
+//
9
+// Note however, that you may define your own "run" and "debug" task if you
10
+// prefer. In this case NetBeans will not add these tasks but you may rely on
11
+// your own implementation.
12
+if (!hasProperty('mainClass')) {
13
+    ext.mainClass = ''
14
+}
15
+
16
+dependencies {
17
+	compile 'org.json:json:20180130'
18
+	compile project(':CodeModel')
19
+	compile project(':Linker')
20
+}

+ 24
- 0
CompilerShared/src/main/java/org/openzen/zenscript/compiler/CompilerOutput.java Vedi File

@@ -0,0 +1,24 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.compiler;
7
+
8
+import org.openzen.zenscript.shared.CodePosition;
9
+
10
+/**
11
+ *
12
+ * @author Hoofdgebruiker
13
+ */
14
+public interface CompilerOutput {
15
+	void info(String message);
16
+	
17
+	void warning(String message);
18
+	
19
+	void warning(CodePosition position, String message);
20
+	
21
+	void error(String message);
22
+	
23
+	void error(CodePosition position, String message);
24
+}

Constructor/src/main/java/org/openzen/zenscript/constructor/module/SemanticModule.java → CompilerShared/src/main/java/org/openzen/zenscript/compiler/SemanticModule.java Vedi File

@@ -3,7 +3,7 @@
3 3
  * To change this template file, choose Tools | Templates
4 4
  * and open the template in the editor.
5 5
  */
6
-package org.openzen.zenscript.constructor.module;
6
+package org.openzen.zenscript.compiler;
7 7
 
8 8
 import java.util.HashMap;
9 9
 import java.util.List;
@@ -12,8 +12,6 @@ import org.openzen.zenscript.codemodel.HighLevelDefinition;
12 12
 import org.openzen.zenscript.codemodel.PackageDefinitions;
13 13
 import org.openzen.zenscript.codemodel.ScriptBlock;
14 14
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
15
-import org.openzen.zenscript.javabytecode.JavaCompiler;
16
-import org.openzen.zenscript.javabytecode.JavaModule;
17 15
 import org.openzen.zenscript.linker.symbol.ISymbol;
18 16
 
19 17
 /**
@@ -34,14 +32,13 @@ public class SemanticModule {
34 32
 		this.scripts = scripts;
35 33
 	}
36 34
 	
37
-	public JavaModule compileToJava() {
38
-		JavaCompiler compiler = new JavaCompiler(false);
35
+	public void compile(ZenCodeCompiler compiler) {
39 36
 		for (HighLevelDefinition definition : definitions.getAll()) {
40 37
 			compiler.addDefinition(definition);
41 38
 		}
42 39
 		for (ScriptBlock script : scripts) {
43 40
 			compiler.addScriptBlock(script);
44 41
 		}
45
-		return compiler.finish();
42
+		compiler.finish();
46 43
 	}
47 44
 }

+ 22
- 0
CompilerShared/src/main/java/org/openzen/zenscript/compiler/Target.java Vedi File

@@ -0,0 +1,22 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.compiler;
7
+
8
+/**
9
+ *
10
+ * @author Hoofdgebruiker
11
+ */
12
+public interface Target {
13
+	public ZenCodeCompiler createCompiler(SemanticModule module);
14
+	
15
+	public String getModule();
16
+	
17
+	public String getName();
18
+	
19
+	public boolean canRun();
20
+	
21
+	public boolean canBuild();
22
+}

+ 17
- 0
CompilerShared/src/main/java/org/openzen/zenscript/compiler/TargetType.java Vedi File

@@ -0,0 +1,17 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.compiler;
7
+
8
+import java.io.File;
9
+import org.json.JSONObject;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public interface TargetType {
16
+	public Target create(File projectDir, JSONObject definition);
17
+}

+ 23
- 0
CompilerShared/src/main/java/org/openzen/zenscript/compiler/ZenCodeCompiler.java Vedi File

@@ -0,0 +1,23 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.compiler;
7
+
8
+import org.openzen.zenscript.codemodel.HighLevelDefinition;
9
+import org.openzen.zenscript.codemodel.ScriptBlock;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public interface ZenCodeCompiler {
16
+	void addDefinition(HighLevelDefinition definition);
17
+	
18
+	void addScriptBlock(ScriptBlock script);
19
+	
20
+	void finish();
21
+	
22
+	void run();
23
+}

+ 3
- 0
Constructor/build.gradle Vedi File

@@ -17,6 +17,9 @@ dependencies {
17 17
 	compile 'org.json:json:20180130'
18 18
 	compile project(':CodeModel')
19 19
 	compile project(':Parser')
20
+	compile project(':Linker')
20 21
 	compile project(':Validator')
22
+	compile project(':CompilerShared')
21 23
 	compile project(':JavaBytecodeCompiler')
24
+	compile project(':JavaSourceCompiler')
22 25
 }

+ 3
- 3
Constructor/libraries/stdlib/src/Arrays.zs Vedi File

@@ -104,10 +104,10 @@ export expand <T> T[] {
104 104
 		return null;
105 105
 	}
106 106
 	
107
-	public last(predicate as function(value as T) as bool) as T? {
107
+	public last(predicate as function(index as int, value as T) as bool) as T? {
108 108
 		for i, value in this.reversed
109
-			if predicate(value)
110
-				return value
109
+			if predicate(i, value)
110
+				return value;
111 111
 		
112 112
 		return null;
113 113
 	}

+ 37
- 0
Constructor/src/main/java/org/openzen/zenscript/constructor/ConstructorRegistry.java Vedi File

@@ -0,0 +1,37 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.constructor;
7
+
8
+import java.util.HashMap;
9
+import java.util.Map;
10
+import org.openzen.zenscript.compiler.TargetType;
11
+import org.openzen.zenscript.javabytecode.JavaBytecodeJarTargetType;
12
+import org.openzen.zenscript.javabytecode.JavaBytecodeRunTargetType;
13
+import org.openzen.zenscript.javasource.JavaSourceTargetType;
14
+
15
+/**
16
+ *
17
+ * @author Hoofdgebruiker
18
+ */
19
+public class ConstructorRegistry {
20
+	private static final Map<String, TargetType> targetTypes = new HashMap<>();
21
+	
22
+	static {
23
+		registerTargetType("javaSource", JavaSourceTargetType.INSTANCE);
24
+		registerTargetType("javaBytecodeJar", JavaBytecodeJarTargetType.INSTANCE);
25
+		registerTargetType("javaBytecodeRun", JavaBytecodeRunTargetType.INSTANCE);
26
+	}
27
+	
28
+	public static void registerTargetType(String name, TargetType type) {
29
+		targetTypes.put(name, type);
30
+	}
31
+	
32
+	public static TargetType getTargetType(String name) {
33
+		return targetTypes.get(name);
34
+	}
35
+
36
+	private ConstructorRegistry() {}
37
+}

+ 1
- 1
Constructor/src/main/java/org/openzen/zenscript/constructor/Module.java Vedi File

@@ -21,7 +21,7 @@ import org.openzen.zenscript.codemodel.ScriptBlock;
21 21
 import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
22 22
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
23 23
 import org.openzen.zenscript.constructor.module.ModuleSpace;
24
-import org.openzen.zenscript.constructor.module.SemanticModule;
24
+import org.openzen.zenscript.compiler.SemanticModule;
25 25
 import org.openzen.zenscript.linker.symbol.ISymbol;
26 26
 import org.openzen.zenscript.parser.ParsedFile;
27 27
 import org.openzen.zenscript.shared.CompileException;

+ 1
- 1
Constructor/src/main/java/org/openzen/zenscript/constructor/ModuleLoader.java Vedi File

@@ -10,7 +10,7 @@ import java.util.HashSet;
10 10
 import java.util.Map;
11 11
 import java.util.Stack;
12 12
 import org.openzen.zenscript.constructor.module.ModuleReference;
13
-import org.openzen.zenscript.constructor.module.SemanticModule;
13
+import org.openzen.zenscript.compiler.SemanticModule;
14 14
 
15 15
 /**
16 16
  *

+ 21
- 0
Constructor/src/main/java/org/openzen/zenscript/constructor/Project.java Vedi File

@@ -7,21 +7,28 @@ package org.openzen.zenscript.constructor;
7 7
 
8 8
 import java.io.File;
9 9
 import java.io.IOException;
10
+import java.util.ArrayList;
11
+import java.util.List;
10 12
 import org.json.JSONArray;
11 13
 import org.json.JSONObject;
12 14
 import org.openzen.zenscript.constructor.module.DirectoryModuleLoader;
13 15
 import org.openzen.zenscript.constructor.module.ModuleReference;
16
+import org.openzen.zenscript.compiler.Target;
17
+import org.openzen.zenscript.compiler.TargetType;
14 18
 
15 19
 /**
16 20
  *
17 21
  * @author Hoofdgebruiker
18 22
  */
19 23
 public class Project {
24
+	public final File directory;
20 25
 	public final String name;
21 26
 	public final ModuleReference[] modules;
22 27
 	public final Library[] libraries;
28
+	public final Target[] targets;
23 29
 	
24 30
 	public Project(ModuleLoader loader, File directory) throws IOException {
31
+		this.directory = directory;
25 32
 		name = directory.getName();
26 33
 		
27 34
 		if (!directory.exists())
@@ -61,5 +68,19 @@ public class Project {
61 68
 				}
62 69
 			}
63 70
 		}
71
+		
72
+		JSONArray jsonTargets = json.getJSONArray("targets");
73
+		List<Target> targetList = new ArrayList<>();
74
+		for (int i = 0; i < jsonTargets.length(); i++) {
75
+			JSONObject jsonTarget = jsonTargets.getJSONObject(i);
76
+			TargetType targetType = ConstructorRegistry.getTargetType(jsonTarget.getString("type"));
77
+			if (targetType == null) {
78
+				System.out.println("Unknown target type: " + jsonTarget.getString("type"));
79
+				continue;
80
+			}
81
+			
82
+			targetList.add(targetType.create(directory, jsonTarget));
83
+		}
84
+		targets = targetList.toArray(new Target[targetList.size()]);
64 85
 	}
65 86
 }

+ 2
- 1
Constructor/src/main/java/org/openzen/zenscript/constructor/module/DirectoryModuleLoader.java Vedi File

@@ -5,6 +5,7 @@
5 5
  */
6 6
 package org.openzen.zenscript.constructor.module;
7 7
 
8
+import org.openzen.zenscript.compiler.SemanticModule;
8 9
 import java.io.File;
9 10
 import java.io.IOException;
10 11
 import java.util.ArrayList;
@@ -70,7 +71,7 @@ public class DirectoryModuleLoader implements ModuleReference {
70 71
 				space.addModule(dependencyName, loader.getModule(dependencyName));
71 72
 
72 73
 			Module module = new Module(moduleName, directory, jsonFile);
73
-			ZSPackage pkg = new ZSPackage(module.packageName);
74
+			ZSPackage pkg = new ZSPackage(null, module.packageName);
74 75
 
75 76
 			ParsedFile[] parsedFiles = module.parse(pkg);
76 77
 			SemanticModule result = Module.compileSyntaxToSemantic(pkg, parsedFiles, space);

+ 2
- 0
Constructor/src/main/java/org/openzen/zenscript/constructor/module/ModuleReference.java Vedi File

@@ -5,6 +5,8 @@
5 5
  */
6 6
 package org.openzen.zenscript.constructor.module;
7 7
 
8
+import org.openzen.zenscript.compiler.SemanticModule;
9
+
8 10
 /**
9 11
  *
10 12
  * @author Hoofdgebruiker

+ 4
- 3
Constructor/src/main/java/org/openzen/zenscript/constructor/module/ModuleSpace.java Vedi File

@@ -5,6 +5,7 @@
5 5
  */
6 6
 package org.openzen.zenscript.constructor.module;
7 7
 
8
+import org.openzen.zenscript.compiler.SemanticModule;
8 9
 import java.util.ArrayList;
9 10
 import java.util.HashMap;
10 11
 import java.util.List;
@@ -20,10 +21,10 @@ import org.openzen.zenscript.linker.symbol.ISymbol;
20 21
  * @author Hoofdgebruiker
21 22
  */
22 23
 public class ModuleSpace {
23
-	private final ZSPackage rootPackage = new ZSPackage("");
24
-	private final ZSPackage stdlib = new ZSPackage("");
24
+	private final ZSPackage rootPackage = new ZSPackage(null, "");
25
+	private final ZSPackage stdlib = new ZSPackage(null, "stdlib");
25 26
 	public final GlobalTypeRegistry typeRegistry = new GlobalTypeRegistry(stdlib);
26
-	public final ZSPackage globalsPackage = new ZSPackage("");
27
+	public final ZSPackage globalsPackage = new ZSPackage(null, "");
27 28
 	private final List<ExpansionDefinition> expansions = new ArrayList<>();
28 29
 	private final Map<String, ISymbol> globals = new HashMap<>();
29 30
 	

+ 38
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/DCompositeIcon.java Vedi File

@@ -0,0 +1,38 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.drawablegui;
7
+
8
+/**
9
+ *
10
+ * @author Hoofdgebruiker
11
+ */
12
+public class DCompositeIcon implements DColorableIcon {
13
+	private final DColorableIcon base;
14
+	private final DColorableIcon addition;
15
+	private final DTransform2D additionTransform;
16
+	
17
+	public DCompositeIcon(DColorableIcon base, DColorableIcon addition, DTransform2D additionTransform) {
18
+		this.base = base;
19
+		this.addition = addition;
20
+		this.additionTransform = additionTransform;
21
+	}
22
+
23
+	@Override
24
+	public void draw(DCanvas canvas, DTransform2D transform, int color) {
25
+		base.draw(canvas, transform, color);
26
+		addition.draw(canvas, transform.mul(additionTransform), color);
27
+	}
28
+
29
+	@Override
30
+	public float getNominalWidth() {
31
+		return base.getNominalWidth();
32
+	}
33
+
34
+	@Override
35
+	public float getNominalHeight() {
36
+		return base.getNominalHeight();
37
+	}
38
+}

+ 82
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/DInputField.java Vedi File

@@ -0,0 +1,82 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.drawablegui;
7
+
8
+import org.openzen.drawablegui.listeners.ListenerHandle;
9
+import org.openzen.drawablegui.live.LiveObject;
10
+import org.openzen.drawablegui.live.LiveString;
11
+import org.openzen.drawablegui.live.SimpleLiveObject;
12
+import org.openzen.drawablegui.style.DStyleClass;
13
+import org.openzen.drawablegui.style.DStylePath;
14
+
15
+/**
16
+ *
17
+ * @author Hoofdgebruiker
18
+ */
19
+public class DInputField implements DComponent {
20
+	public final LiveString value;
21
+	private final ListenerHandle<LiveString.Listener> valueListener;
22
+	
23
+	private final DStyleClass styleClass;
24
+	private final LiveObject<DDimensionPreferences> dimensionPreferences = new SimpleLiveObject<>(DDimensionPreferences.EMPTY);
25
+	private DIRectangle bounds = DIRectangle.EMPTY;
26
+	
27
+	private DUIContext context;
28
+	private DInputFieldStyle style;
29
+	private DFontMetrics fontMetrics;
30
+	private int cursorFrom = -1;
31
+	private int cursorTo = -1;
32
+	
33
+	public DInputField(DStyleClass styleClass, LiveString value) {
34
+		this.styleClass = styleClass;
35
+		this.value = value;
36
+		valueListener = value.addListener((oldValue, newValue) -> handleValueUpdated(newValue));
37
+	}
38
+
39
+	@Override
40
+	public void setContext(DStylePath parent, DUIContext context) {
41
+		this.context = context;
42
+		
43
+		DStylePath path = parent.getChild("input", styleClass);
44
+		style = new DInputFieldStyle(context.getStylesheets().get(context, path));
45
+		fontMetrics = context.getFontMetrics(style.font);
46
+	}
47
+
48
+	@Override
49
+	public LiveObject<DDimensionPreferences> getDimensionPreferences() {
50
+		return dimensionPreferences;
51
+	}
52
+
53
+	@Override
54
+	public DIRectangle getBounds() {
55
+		return bounds;
56
+	}
57
+
58
+	@Override
59
+	public void setBounds(DIRectangle bounds) {
60
+		this.bounds = bounds;
61
+	}
62
+
63
+	@Override
64
+	public void paint(DCanvas canvas) {
65
+		canvas.fillRectangle(bounds.x, bounds.y, bounds.width, bounds.height, style.backgroundColor);
66
+		canvas.drawText(style.font, style.color, bounds.x + style.paddingLeft, bounds.y + style.paddingBottom, value.getValue());
67
+	}
68
+
69
+	@Override
70
+	public void close() {
71
+		valueListener.close();
72
+	}
73
+	
74
+	@Override
75
+	public void onMouseClick(DMouseEvent e) {
76
+		context.focus(this);
77
+	}
78
+	
79
+	private void handleValueUpdated(String newValue) {
80
+		
81
+	}
82
+}

+ 45
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/DInputFieldStyle.java Vedi File

@@ -0,0 +1,45 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.drawablegui;
7
+
8
+import org.openzen.drawablegui.style.DDpDimension;
9
+import org.openzen.drawablegui.style.DStyleDefinition;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public class DInputFieldStyle {
16
+	public final int backgroundColor;
17
+	public final int paddingTop;
18
+	public final int paddingLeft;
19
+	public final int paddingRight;
20
+	public final int paddingBottom;
21
+	
22
+	public final int color;
23
+	public final DFont font;
24
+	
25
+	public final int cursorColor;
26
+	public final int cursorWidth;
27
+	
28
+	public final int selectionColor;
29
+	
30
+	public DInputFieldStyle(DStyleDefinition style) {
31
+		backgroundColor = style.getColor("backgroundColor", 0);
32
+		paddingTop = style.getDimension("paddingTop", new DDpDimension(2));
33
+		paddingBottom = style.getDimension("paddingBottom", new DDpDimension(2));
34
+		paddingLeft = style.getDimension("paddingLeft", new DDpDimension(2));
35
+		paddingRight = style.getDimension("paddingRight", new DDpDimension(2));
36
+		
37
+		color = style.getColor("color", 0xFF000000);
38
+		font = style.getFont("font", context -> new DFont(DFontFamily.UI, false, false, false, (int)(14 * context.getScale())));
39
+		
40
+		cursorColor = style.getColor("cursorColor", 0xFF000000);
41
+		cursorWidth = style.getDimension("cursorWidth", new DDpDimension(1));
42
+		
43
+		selectionColor = style.getColor("selectionColor", 0xFFB0C5E3);
44
+	}
45
+}

+ 7
- 5
DrawableGui/src/main/java/org/openzen/drawablegui/DUIWindow.java Vedi File

@@ -13,20 +13,22 @@ import org.openzen.drawablegui.live.LiveObject;
13 13
  * @author Hoofdgebruiker
14 14
  */
15 15
 public interface DUIWindow {
16
-	public boolean hasTitleBar();
16
+	boolean hasTitleBar();
17 17
 	
18
-	public void close();
18
+	void close();
19 19
 	
20
-	public void maximize();
20
+	void maximize();
21 21
 	
22
-	public void restore();
22
+	void restore();
23 23
 	
24
-	public void minimize();
24
+	void minimize();
25 25
 	
26 26
 	LiveObject<State> getWindowState();
27 27
 	
28 28
 	LiveBool getActive();
29 29
 	
30
+	DUIWindow openModal(String title, DComponent root);
31
+	
30 32
 	enum State {
31 33
 		NORMAL,
32 34
 		MAXIMIZED,

+ 110
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/form/DForm.java Vedi File

@@ -0,0 +1,110 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.drawablegui.form;
7
+
8
+import org.openzen.drawablegui.DCanvas;
9
+import org.openzen.drawablegui.DComponent;
10
+import org.openzen.drawablegui.DDimensionPreferences;
11
+import org.openzen.drawablegui.DFontMetrics;
12
+import org.openzen.drawablegui.DIRectangle;
13
+import org.openzen.drawablegui.DUIContext;
14
+import org.openzen.drawablegui.live.LiveObject;
15
+import org.openzen.drawablegui.live.SimpleLiveObject;
16
+import org.openzen.drawablegui.style.DStyleClass;
17
+import org.openzen.drawablegui.style.DStylePath;
18
+
19
+/**
20
+ *
21
+ * @author Hoofdgebruiker
22
+ */
23
+public class DForm implements DComponent {
24
+	private final DFormComponent[] components;
25
+	private final DStyleClass styleClass;
26
+	private final LiveObject<DDimensionPreferences> preferences = new SimpleLiveObject<>(DDimensionPreferences.EMPTY);
27
+	
28
+	private DIRectangle bounds;
29
+	private DUIContext context;
30
+	private DFormStyle style;
31
+	private DFontMetrics fontMetrics;
32
+	
33
+	public DForm(DStyleClass styleClass, DFormComponent... components) {
34
+		this.styleClass = styleClass;
35
+		this.components = components;
36
+	}
37
+
38
+	@Override
39
+	public void setContext(DStylePath parent, DUIContext context) {
40
+		this.context = context;
41
+		
42
+		DStylePath path = parent.getChild("form", styleClass);
43
+		style = new DFormStyle(context.getStylesheets().get(context, path));
44
+		fontMetrics = context.getFontMetrics(style.labelFont);
45
+		for (DFormComponent component : components)
46
+			component.component.setContext(path, context);
47
+		
48
+		int height = style.paddingBottom + style.paddingTop;
49
+		int maxTextWidth = style.minimumLabelSize;
50
+		int maxComponentWidth = style.minimumFieldSize;
51
+		
52
+		for (DFormComponent component : components) {
53
+			maxTextWidth = Math.max(maxTextWidth, fontMetrics.getWidth(component.label));
54
+			int componentWidth = component.component.getDimensionPreferences().getValue().preferredWidth;
55
+			maxComponentWidth = Math.max(maxComponentWidth, componentWidth);
56
+		}
57
+		
58
+		for (DFormComponent component : components) {
59
+			height += component.component.getDimensionPreferences().getValue().preferredHeight;
60
+			height += style.spacing;
61
+		}
62
+		
63
+		preferences.setValue(new DDimensionPreferences(maxTextWidth + maxComponentWidth, height));
64
+	}
65
+
66
+	@Override
67
+	public LiveObject<DDimensionPreferences> getDimensionPreferences() {
68
+		return preferences;
69
+	}
70
+
71
+	@Override
72
+	public DIRectangle getBounds() {
73
+		return bounds;
74
+	}
75
+
76
+	@Override
77
+	public void setBounds(DIRectangle bounds) {
78
+		this.bounds = bounds;
79
+		layout();
80
+	}
81
+
82
+	@Override
83
+	public void paint(DCanvas canvas) {
84
+		for (DFormComponent component : components) {
85
+			
86
+		}
87
+	}
88
+
89
+	@Override
90
+	public void close() {
91
+		
92
+	}
93
+	
94
+	private void layout() {
95
+		int x = bounds.x + style.paddingLeft;
96
+		int y = bounds.y + style.paddingBottom;
97
+		int maxTextWidth = style.minimumLabelSize;
98
+		
99
+		for (DFormComponent component : components)
100
+			maxTextWidth = Math.max(maxTextWidth, fontMetrics.getWidth(component.label));
101
+		
102
+		for (DFormComponent component : components) {
103
+			int preferredHeight = component.component.getDimensionPreferences().getValue().preferredHeight;
104
+			DIRectangle componentBounds = new DIRectangle(x + maxTextWidth, y, bounds.width - maxTextWidth, preferredHeight);
105
+			component.component.setBounds(componentBounds);
106
+			
107
+			y += preferredHeight + style.spacing;
108
+		}
109
+	}
110
+}

+ 22
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/form/DFormComponent.java Vedi File

@@ -0,0 +1,22 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.drawablegui.form;
7
+
8
+import org.openzen.drawablegui.DComponent;
9
+
10
+/**
11
+ *
12
+ * @author Hoofdgebruiker
13
+ */
14
+public class DFormComponent {
15
+	public final String label;
16
+	public final DComponent component;
17
+	
18
+	public DFormComponent(String label, DComponent component) {
19
+		this.label = label;
20
+		this.component = component;
21
+	}
22
+}

+ 41
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/form/DFormStyle.java Vedi File

@@ -0,0 +1,41 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.drawablegui.form;
7
+
8
+import org.openzen.drawablegui.DFont;
9
+import org.openzen.drawablegui.DFontFamily;
10
+import org.openzen.drawablegui.style.DDpDimension;
11
+import org.openzen.drawablegui.style.DStyleDefinition;
12
+
13
+/**
14
+ *
15
+ * @author Hoofdgebruiker
16
+ */
17
+public class DFormStyle {
18
+	public final int paddingLeft;
19
+	public final int paddingTop;
20
+	public final int paddingRight;
21
+	public final int paddingBottom;
22
+	public final int spacing;
23
+	
24
+	public final int labelColor;
25
+	public final DFont labelFont;
26
+	public final int minimumLabelSize;
27
+	public final int minimumFieldSize;
28
+	
29
+	public DFormStyle(DStyleDefinition style) {
30
+		paddingLeft = style.getDimension("paddingLeft", new DDpDimension(16));
31
+		paddingTop = style.getDimension("paddingTop", new DDpDimension(16));
32
+		paddingRight = style.getDimension("paddingRight", new DDpDimension(16));
33
+		paddingBottom = style.getDimension("paddingBottom", new DDpDimension(16));
34
+		spacing = style.getDimension("spacing", new DDpDimension(8));
35
+		
36
+		labelColor = style.getColor("labelColor", 0xFF000000);
37
+		labelFont = style.getFont("labelFont", context -> new DFont(DFontFamily.UI, false, false, false, (int)(16 * context.getScale())));
38
+		minimumLabelSize = style.getDimension("minimumLabelSize", new DDpDimension(150));
39
+		minimumFieldSize = style.getDimension("minimumFieldSize", new DDpDimension(150));
40
+	}
41
+}

+ 24
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/live/LiveString.java Vedi File

@@ -0,0 +1,24 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.drawablegui.live;
7
+
8
+import org.openzen.drawablegui.listeners.ListenerHandle;
9
+
10
+/**
11
+ *
12
+ * @author Hoofdgebruiker
13
+ */
14
+public interface LiveString {
15
+	ListenerHandle<Listener> addListener(Listener listener);
16
+	
17
+	String getValue();
18
+	
19
+	void setValue(String value);
20
+	
21
+	interface Listener {
22
+		void onChanged(String oldValue, String newValue);
23
+	}
24
+}

+ 40
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/live/SimpleLiveString.java Vedi File

@@ -0,0 +1,40 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.drawablegui.live;
7
+
8
+import org.openzen.drawablegui.listeners.ListenerHandle;
9
+import org.openzen.drawablegui.listeners.ListenerList;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public class SimpleLiveString implements LiveString {
16
+	private final ListenerList<Listener> listeners = new ListenerList<>();
17
+	
18
+	private String value;
19
+	
20
+	public SimpleLiveString(String value) {
21
+		this.value = value;
22
+	}
23
+
24
+	@Override
25
+	public ListenerHandle<Listener> addListener(Listener listener) {
26
+		return listeners.add(listener);
27
+	}
28
+
29
+	@Override
30
+	public String getValue() {
31
+		return value;
32
+	}
33
+
34
+	@Override
35
+	public void setValue(String value) {
36
+		String oldValue = this.value;
37
+		this.value = value;
38
+		listeners.accept(listener -> listener.onChanged(oldValue, value));
39
+	}
40
+}

+ 14
- 0
DrawableGui/src/main/java/org/openzen/drawablegui/swing/SwingWindow.java Vedi File

@@ -12,6 +12,7 @@ import java.awt.event.WindowListener;
12 12
 import java.awt.event.WindowStateListener;
13 13
 import javax.swing.JFrame;
14 14
 import org.openzen.drawablegui.DComponent;
15
+import org.openzen.drawablegui.DDimensionPreferences;
15 16
 import org.openzen.drawablegui.DUIContext;
16 17
 import org.openzen.drawablegui.DUIWindow;
17 18
 import org.openzen.drawablegui.border.DCustomWindowBorder;
@@ -87,6 +88,19 @@ public final class SwingWindow extends JFrame implements WindowListener, WindowS
87 88
 	public LiveBool getActive() {
88 89
 		return active;
89 90
 	}
91
+	
92
+	@Override
93
+	public DUIWindow openModal(String title, DComponent component) {
94
+		SwingWindow result = new SwingWindow(title, component, false);
95
+		result.setResizable(false);
96
+		
97
+		DDimensionPreferences size = component.getDimensionPreferences().getValue();
98
+		result.setLocation(
99
+				getX() + (getWidth() - size.preferredWidth) / 2,
100
+				getY() + (getHeight() - size.preferredHeight) / 2);
101
+		result.setSize(size.preferredWidth, size.preferredHeight);
102
+		return result;
103
+	}
90 104
 
91 105
 	@Override
92 106
 	public void windowOpened(WindowEvent e) {

+ 1
- 1
IDE/src/main/java/org/openzen/zenscript/ide/Main.java Vedi File

@@ -24,7 +24,7 @@ public class Main {
24 24
 		
25 25
 		int pixelPerInch = java.awt.Toolkit.getDefaultToolkit().getScreenResolution();
26 26
 		
27
-		IDEWindow window = new IDEWindow();
27
+		IDEWindow window = new IDEWindow(host);
28 28
 		WindowView root = new WindowView(window, host);
29 29
 		
30 30
 		SwingWindow swingWindow = new SwingWindow("ZenCode IDE - " + host.getName(), root, false);

+ 2
- 0
IDE/src/main/java/org/openzen/zenscript/ide/host/DevelopmentHost.java Vedi File

@@ -17,4 +17,6 @@ public interface DevelopmentHost {
17 17
 	public LiveList<IDEModule> getModules();
18 18
 	
19 19
 	public LiveList<IDELibrary> getLibraries();
20
+	
21
+	public LiveList<IDETarget> getTargets();
20 22
 }

+ 22
- 0
IDE/src/main/java/org/openzen/zenscript/ide/host/IDETarget.java Vedi File

@@ -0,0 +1,22 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.ide.host;
7
+
8
+/**
9
+ *
10
+ * @author Hoofdgebruiker
11
+ */
12
+public interface IDETarget {
13
+	String getName();
14
+	
15
+	boolean canBuild();
16
+	
17
+	boolean canRun();
18
+	
19
+	void build();
20
+	
21
+	void run();
22
+}

+ 12
- 0
IDE/src/main/java/org/openzen/zenscript/ide/host/local/LocalProjectDevelopmentHost.java Vedi File

@@ -11,9 +11,11 @@ import org.openzen.drawablegui.live.LiveList;
11 11
 import org.openzen.zenscript.constructor.Library;
12 12
 import org.openzen.zenscript.constructor.Project;
13 13
 import org.openzen.zenscript.constructor.module.ModuleReference;
14
+import org.openzen.zenscript.compiler.Target;
14 15
 import org.openzen.zenscript.ide.host.DevelopmentHost;
15 16
 import org.openzen.zenscript.ide.host.IDEModule;
16 17
 import org.openzen.zenscript.ide.host.IDELibrary;
18
+import org.openzen.zenscript.ide.host.IDETarget;
17 19
 
18 20
 /**
19 21
  *
@@ -23,6 +25,7 @@ public class LocalProjectDevelopmentHost implements DevelopmentHost {
23 25
 	private final Project project;
24 26
 	private final LiveList<IDEModule> modules;
25 27
 	private final LiveList<IDELibrary> libraries;
28
+	private final LiveList<IDETarget> targets;
26 29
 	
27 30
 	public LocalProjectDevelopmentHost(Project project) {
28 31
 		this.project = project;
@@ -34,6 +37,10 @@ public class LocalProjectDevelopmentHost implements DevelopmentHost {
34 37
 		libraries = new LiveArrayList<>();
35 38
 		for (Library library : project.libraries)
36 39
 			libraries.add(new LocalLibrary(library));
40
+		
41
+		targets = new LiveArrayList<>();
42
+		for (Target target : project.targets)
43
+			targets.add(new LocalTarget(project, target));
37 44
 	}
38 45
 	
39 46
 	@Override
@@ -50,4 +57,9 @@ public class LocalProjectDevelopmentHost implements DevelopmentHost {
50 57
 	public LiveList<IDELibrary> getLibraries() {
51 58
 		return libraries;
52 59
 	}
60
+
61
+	@Override
62
+	public LiveList<IDETarget> getTargets() {
63
+		return targets;
64
+	}
53 65
 }

+ 90
- 0
IDE/src/main/java/org/openzen/zenscript/ide/host/local/LocalTarget.java Vedi File

@@ -0,0 +1,90 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.ide.host.local;
7
+
8
+import java.io.File;
9
+import java.io.IOException;
10
+import org.openzen.zenscript.codemodel.HighLevelDefinition;
11
+import org.openzen.zenscript.codemodel.ScriptBlock;
12
+import org.openzen.zenscript.compiler.Target;
13
+import org.openzen.zenscript.compiler.ZenCodeCompiler;
14
+import org.openzen.zenscript.constructor.Library;
15
+import org.openzen.zenscript.constructor.ModuleLoader;
16
+import org.openzen.zenscript.constructor.Project;
17
+import org.openzen.zenscript.constructor.module.DirectoryModuleLoader;
18
+import org.openzen.zenscript.constructor.module.ModuleReference;
19
+import org.openzen.zenscript.compiler.SemanticModule;
20
+import org.openzen.zenscript.ide.host.IDETarget;
21
+
22
+/**
23
+ *
24
+ * @author Hoofdgebruiker
25
+ */
26
+public class LocalTarget implements IDETarget {
27
+	private final Project project;
28
+	private final Target target;
29
+	
30
+	public LocalTarget(Project project, Target target) {
31
+		this.project = project;
32
+		this.target = target;
33
+	}
34
+
35
+	@Override
36
+	public String getName() {
37
+		return target.getName();
38
+	}
39
+
40
+	@Override
41
+	public boolean canBuild() {
42
+		return target.canBuild();
43
+	}
44
+
45
+	@Override
46
+	public boolean canRun() {
47
+		return target.canRun();
48
+	}
49
+
50
+	@Override
51
+	public void build() {
52
+		buildInternal();
53
+	}
54
+
55
+	@Override
56
+	public void run() {
57
+		ZenCodeCompiler compiler = buildInternal();
58
+		if (compiler != null)
59
+			compiler.run();
60
+	}
61
+	
62
+	private ZenCodeCompiler buildInternal() {
63
+		ModuleLoader moduleLoader = new ModuleLoader();
64
+		moduleLoader.register("stdlib", new DirectoryModuleLoader(moduleLoader, "stdlib", new File("../Constructor/libraries/stdlib"), true));
65
+		
66
+		try {
67
+			Project project = new Project(moduleLoader, this.project.directory);
68
+			for (Library library : project.libraries) {
69
+				for (ModuleReference module : library.modules)
70
+					moduleLoader.register(module.getName(), module);
71
+			}
72
+			for (ModuleReference module : project.modules) {
73
+				moduleLoader.register(module.getName(), module);
74
+			}
75
+
76
+			SemanticModule module = moduleLoader.getModule(target.getModule());
77
+			ZenCodeCompiler compiler = target.createCompiler(module);
78
+			for (HighLevelDefinition definition : module.definitions.getAll())
79
+				compiler.addDefinition(definition);
80
+			for (ScriptBlock script : module.scripts)
81
+				compiler.addScriptBlock(script);
82
+			
83
+			compiler.finish();
84
+			return compiler;
85
+		} catch (IOException ex) {
86
+			ex.printStackTrace();
87
+			return null;
88
+		}
89
+	}
90
+}

+ 22
- 6
IDE/src/main/java/org/openzen/zenscript/ide/ui/IDEWindow.java Vedi File

@@ -5,13 +5,13 @@
5 5
  */
6 6
 package org.openzen.zenscript.ide.ui;
7 7
 
8
-import org.openzen.drawablegui.live.SimpleLiveBool;
9 8
 import org.openzen.drawablegui.style.DStyleClass;
9
+import org.openzen.zenscript.ide.host.DevelopmentHost;
10 10
 import org.openzen.zenscript.ide.host.IDESourceFile;
11
+import org.openzen.zenscript.ide.host.IDETarget;
11 12
 import org.openzen.zenscript.ide.ui.icons.AddBoxIcon;
12 13
 import org.openzen.zenscript.ide.ui.icons.BuildIcon;
13 14
 import org.openzen.zenscript.ide.ui.icons.PlayIcon;
14
-import org.openzen.zenscript.ide.ui.icons.ProjectIcon;
15 15
 import org.openzen.zenscript.ide.ui.icons.SettingsIcon;
16 16
 import org.openzen.zenscript.ide.ui.icons.ShadedProjectIcon;
17 17
 import org.openzen.zenscript.ide.ui.view.IconButtonControl;
@@ -21,20 +21,26 @@ import org.openzen.zenscript.ide.ui.view.IconButtonControl;
21 21
  * @author Hoofdgebruiker
22 22
  */
23 23
 public class IDEWindow {
24
+	private final DevelopmentHost host;
25
+	
24 26
 	public final IDEAspectBar aspectBar;
25 27
 	public final IDEDockWindow dockWindow;
26 28
 	public final IDEStatusBar statusBar;
27 29
 	
28 30
 	public IDEAspectToolbar projectToolbar;
29 31
 	
30
-	public IDEWindow() {
32
+	public IDEWindow(DevelopmentHost host) {
33
+		this.host = host;
34
+		
31 35
 		aspectBar = new IDEAspectBar();
32 36
 		dockWindow = new IDEDockWindow();
33 37
 		statusBar = new IDEStatusBar();
34 38
 		init();
35 39
 	}
36 40
 	
37
-	public IDEWindow(IDEAspectBar aspectBar, IDEDockWindow dockWindow, IDEStatusBar statusBar) {
41
+	public IDEWindow(DevelopmentHost host, IDEAspectBar aspectBar, IDEDockWindow dockWindow, IDEStatusBar statusBar) {
42
+		this.host = host;
43
+		
38 44
 		this.aspectBar = aspectBar;
39 45
 		this.dockWindow = dockWindow;
40 46
 		this.statusBar = statusBar;
@@ -49,8 +55,18 @@ public class IDEWindow {
49 55
 		projectToolbar = new IDEAspectToolbar(0, ShadedProjectIcon.PURPLE, "Project", "Project management");
50 56
 		projectToolbar.controls.add(() -> new IconButtonControl(DStyleClass.EMPTY, AddBoxIcon.ORANGE, e -> {}));
51 57
 		projectToolbar.controls.add(() -> new IconButtonControl(DStyleClass.EMPTY, SettingsIcon.PURPLE, e -> {}));
52
-		projectToolbar.controls.add(() -> new IconButtonControl(DStyleClass.EMPTY, BuildIcon.BLUE, e -> {}));
53
-		projectToolbar.controls.add(() -> new IconButtonControl(DStyleClass.EMPTY, PlayIcon.GREEN, e -> {}));
58
+		projectToolbar.controls.add(() -> new IconButtonControl(DStyleClass.EMPTY, BuildIcon.BLUE, e -> {
59
+			for (IDETarget target : host.getTargets()) {
60
+				if (target.canBuild())
61
+					target.build();
62
+			}
63
+		}));
64
+		projectToolbar.controls.add(() -> new IconButtonControl(DStyleClass.EMPTY, PlayIcon.GREEN, e -> {
65
+			for (IDETarget target : host.getTargets()) {
66
+				if (target.canRun())
67
+					target.run();
68
+			}
69
+		}));
54 70
 		aspectBar.toolbars.add(projectToolbar);
55 71
 	}
56 72
 }

+ 2
- 2
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/TabbedView.java Vedi File

@@ -13,8 +13,6 @@ import org.openzen.drawablegui.DComponent;
13 13
 import org.openzen.drawablegui.DDimensionPreferences;
14 14
 import org.openzen.drawablegui.DFontMetrics;
15 15
 import org.openzen.drawablegui.DIRectangle;
16
-import org.openzen.drawablegui.DPath;
17
-import org.openzen.drawablegui.DTransform2D;
18 16
 import org.openzen.drawablegui.DUIContext;
19 17
 import org.openzen.drawablegui.live.ImmutableLiveObject;
20 18
 import org.openzen.drawablegui.live.LiveArrayList;
@@ -65,6 +63,8 @@ public class TabbedView extends BaseComponentGroup {
65 63
 					bounds.width, bounds.height - totalTabHeight);
66 64
 				newValue.content.setBounds(contentBounds);
67 65
 			}
66
+			if (newValue == null && context != null && bounds != null)
67
+				context.repaint(bounds);
68 68
 		});
69 69
 	}
70 70
 	

+ 1
- 11
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/TabbedViewStyle.java Vedi File

@@ -20,11 +20,6 @@ public class TabbedViewStyle {
20 20
 	public final DFont tabFont;
21 21
 	public final int tabFontColor;
22 22
 	
23
-	public final int tabColorNormal;
24
-	public final int tabColorHover;
25
-	public final int tabColorPress;
26
-	public final int tabColorActive;
27
-	
28 23
 	public final int paddingTop;
29 24
 	public final int paddingBottom;
30 25
 	public final int paddingLeft;
@@ -38,14 +33,9 @@ public class TabbedViewStyle {
38 33
 	
39 34
 	public TabbedViewStyle(DStyleDefinition style) {
40 35
 		backgroundColor = style.getColor("backgroundColor", 0xFFEEEEEE);
41
-		tabFont = style.getFont("tabFont", context -> new DFont(DFontFamily.CODE, false, false, false, (int)(12 * context.getScale())));
36
+		tabFont = style.getFont("tabFont", context -> new DFont(DFontFamily.UI, false, false, false, (int)(12 * context.getScale())));
42 37
 		tabFontColor = style.getColor("tabFontColor", 0xFF000000);
43 38
 		
44
-		tabColorNormal = style.getColor("tabColorNormal", 0xFFEEEEEE);
45
-		tabColorHover = style.getColor("tabColorHover", 0xFFFFFFFF);
46
-		tabColorPress = style.getColor("tabColorPress", 0xFFF0F0F0);
47
-		tabColorActive = style.getColor("tabColorActive", 0xFFFFFFFF);
48
-		
49 39
 		paddingTop = style.getDimension("paddingTop", new DDpDimension(4));
50 40
 		paddingBottom = style.getDimension("paddingTop", new DDpDimension(4));
51 41
 		paddingLeft = style.getDimension("paddingLeft", new DDpDimension(4));

+ 1
- 1
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/TabbedViewTabStyle.java Vedi File

@@ -36,7 +36,7 @@ public class TabbedViewTabStyle {
36 36
 	public final int closeIconPadding;
37 37
 	
38 38
 	public TabbedViewTabStyle(DStyleDefinition style) {
39
-		tabFont = style.getFont("tabFont", context -> new DFont(DFontFamily.CODE, false, false, false, (int)(12 * context.getScale())));
39
+		tabFont = style.getFont("tabFont", context -> new DFont(DFontFamily.UI, false, false, false, (int)(12 * context.getScale())));
40 40
 		tabFontColor = style.getColor("tabFontColor", 0xFF000000);
41 41
 		
42 42
 		tabColorNormal = style.getColor("tabColorNormal", 0xFFEEEEEE);

+ 1
- 0
JavaBytecodeCompiler/build.gradle Vedi File

@@ -16,4 +16,5 @@ if (!hasProperty('mainClass')) {
16 16
 dependencies {
17 17
 	compile 'org.ow2.asm:asm-debug-all:6.0_BETA'
18 18
 	compile project(':CodeModel')
19
+	compile project(':CompilerShared')
19 20
 }

+ 51
- 0
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaBytecodeJarTarget.java Vedi File

@@ -0,0 +1,51 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.javabytecode;
7
+
8
+import org.json.JSONObject;
9
+import org.openzen.zenscript.compiler.SemanticModule;
10
+import org.openzen.zenscript.compiler.Target;
11
+
12
+/**
13
+ *
14
+ * @author Hoofdgebruiker
15
+ */
16
+public class JavaBytecodeJarTarget implements Target {
17
+	private final String module;
18
+	private final String name;
19
+	private final boolean debugCompiler;
20
+	
21
+	public JavaBytecodeJarTarget(JSONObject definition) {
22
+		module = definition.getString("module");
23
+		name = definition.optString("name", "Java Bytecode: " + module);
24
+		debugCompiler = definition.optBoolean("debugCompiler", false);
25
+	}
26
+	
27
+	@Override
28
+	public JavaCompiler createCompiler(SemanticModule module) {
29
+		return new JavaCompiler(debugCompiler);
30
+	}
31
+
32
+	@Override
33
+	public String getModule() {
34
+		return module;
35
+	}
36
+
37
+	@Override
38
+	public String getName() {
39
+		return name;
40
+	}
41
+
42
+	@Override
43
+	public boolean canRun() {
44
+		return true;
45
+	}
46
+
47
+	@Override
48
+	public boolean canBuild() {
49
+		return true;
50
+	}
51
+}

+ 26
- 0
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaBytecodeJarTargetType.java Vedi File

@@ -0,0 +1,26 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.javabytecode;
7
+
8
+import java.io.File;
9
+import org.json.JSONObject;
10
+import org.openzen.zenscript.compiler.Target;
11
+import org.openzen.zenscript.compiler.TargetType;
12
+
13
+/**
14
+ *
15
+ * @author Hoofdgebruiker
16
+ */
17
+public class JavaBytecodeJarTargetType implements TargetType {
18
+	public static final JavaBytecodeJarTargetType INSTANCE = new JavaBytecodeJarTargetType();
19
+	
20
+	private JavaBytecodeJarTargetType() {}
21
+
22
+	@Override
23
+	public Target create(File projectDir, JSONObject definition) {
24
+		return new JavaBytecodeJarTarget(definition);
25
+	}
26
+}

+ 51
- 0
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaBytecodeRunTarget.java Vedi File

@@ -0,0 +1,51 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.javabytecode;
7
+
8
+import org.json.JSONObject;
9
+import org.openzen.zenscript.compiler.SemanticModule;
10
+import org.openzen.zenscript.compiler.Target;
11
+
12
+/**
13
+ *
14
+ * @author Hoofdgebruiker
15
+ */
16
+public class JavaBytecodeRunTarget implements Target {
17
+	private final String module;
18
+	private final String name;
19
+	private final boolean debugCompiler;
20
+	
21
+	public JavaBytecodeRunTarget(JSONObject definition) {
22
+		module = definition.getString("module");
23
+		name = definition.optString("name", "Java Run: " + module);
24
+		debugCompiler = definition.optBoolean("debugCompiler", false);
25
+	}
26
+	
27
+	@Override
28
+	public JavaCompiler createCompiler(SemanticModule module) {
29
+		return new JavaCompiler(debugCompiler);
30
+	}
31
+
32
+	@Override
33
+	public String getModule() {
34
+		return module;
35
+	}
36
+
37
+	@Override
38
+	public String getName() {
39
+		return name;
40
+	}
41
+
42
+	@Override
43
+	public boolean canRun() {
44
+		return true;
45
+	}
46
+
47
+	@Override
48
+	public boolean canBuild() {
49
+		return true;
50
+	}
51
+}

+ 26
- 0
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaBytecodeRunTargetType.java Vedi File

@@ -0,0 +1,26 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.javabytecode;
7
+
8
+import java.io.File;
9
+import org.json.JSONObject;
10
+import org.openzen.zenscript.compiler.Target;
11
+import org.openzen.zenscript.compiler.TargetType;
12
+
13
+/**
14
+ *
15
+ * @author Hoofdgebruiker
16
+ */
17
+public class JavaBytecodeRunTargetType implements TargetType {
18
+	public static final JavaBytecodeRunTargetType INSTANCE = new JavaBytecodeRunTargetType();
19
+	
20
+	private JavaBytecodeRunTargetType() {}
21
+
22
+	@Override
23
+	public Target create(File projectDir, JSONObject definition) {
24
+		return new JavaBytecodeRunTarget(definition);
25
+	}
26
+}

+ 19
- 2
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaCompiler.java Vedi File

@@ -22,12 +22,13 @@ import org.openzen.zenscript.javabytecode.compiler.definitions.JavaDefinitionVis
22 22
 import org.openzen.zenscript.javabytecode.compiler.JavaStatementVisitor;
23 23
 import org.openzen.zenscript.javabytecode.compiler.JavaWriter;
24 24
 import org.openzen.zenscript.shared.SourceFile;
25
+import org.openzen.zenscript.compiler.ZenCodeCompiler;
25 26
 
26 27
 /**
27 28
  *
28 29
  * @author Hoofdgebruiker
29 30
  */
30
-public class JavaCompiler {
31
+public class JavaCompiler implements ZenCodeCompiler {
31 32
 	static {
32 33
 		JavaClassInfo jInteger = new JavaClassInfo("java/lang/Integer");
33 34
 		JavaClassInfo jLong = new JavaClassInfo("java/lang/Long");
@@ -136,6 +137,7 @@ public class JavaCompiler {
136 137
 	private final JavaClassWriter scriptsClassWriter;
137 138
 	private int generatedScriptBlockCounter = 0;
138 139
 	private boolean finished = false;
140
+	private JavaModule compiled = null;
139 141
 	
140 142
 	public JavaCompiler() {
141 143
 		this(false);
@@ -148,12 +150,14 @@ public class JavaCompiler {
148 150
 		scriptsClassWriter.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC, "Scripts", null, "java/lang/Object", null);
149 151
 	}
150 152
 	
153
+	@Override
151 154
 	public void addDefinition(HighLevelDefinition definition) {
152 155
 		String className = getClassName(definition.position.filename);
153 156
 		JavaScriptFile scriptFile = getScriptFile(className);
154 157
 		target.register(definition.name, definition.accept(new JavaDefinitionVisitor(scriptFile.classWriter)));
155 158
 	}
156 159
 	
160
+	@Override
157 161
 	public void addScriptBlock(ScriptBlock script) {
158 162
 		final SourceFile sourceFile = script.getTag(SourceFile.class);
159 163
 		final String className = getClassName(sourceFile == null ? null : sourceFile.filename);
@@ -196,7 +200,20 @@ public class JavaCompiler {
196 200
 		return scriptBlocks.get(className);
197 201
 	}
198 202
 	
199
-	public JavaModule finish() {
203
+	@Override
204
+	public void finish() {
205
+		finishAndGetModule();
206
+	}
207
+	
208
+	@Override
209
+	public void run() {
210
+		if (compiled == null)
211
+			throw new IllegalStateException("Not yet built!");
212
+		
213
+		
214
+	}
215
+	
216
+	public JavaModule finishAndGetModule() {
200 217
 		if (finished)
201 218
 			throw new IllegalStateException("Already finished!");
202 219
 		finished = true;

+ 19
- 0
JavaSourceCompiler/build.gradle Vedi File

@@ -0,0 +1,19 @@
1
+// Note: "common.gradle" in the root project contains additional initialization
2
+//   for this project. This initialization is applied in the "build.gradle"
3
+//   of the root project.
4
+
5
+// NetBeans will automatically add "run" and "debug" tasks relying on the
6
+// "mainClass" property. You may however define the property prior executing
7
+// tasks by passing a "-PmainClass=<QUALIFIED_CLASS_NAME>" argument.
8
+//
9
+// Note however, that you may define your own "run" and "debug" task if you
10
+// prefer. In this case NetBeans will not add these tasks but you may rely on
11
+// your own implementation.
12
+if (!hasProperty('mainClass')) {
13
+    ext.mainClass = ''
14
+}
15
+
16
+dependencies {
17
+    compile project(':CodeModel')
18
+	compile project(':CompilerShared')
19
+}

+ 148
- 0
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaDefinitionVisitor.java Vedi File

@@ -0,0 +1,148 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.javasource;
7
+
8
+import java.util.ArrayList;
9
+import java.util.List;
10
+import org.openzen.zenscript.codemodel.Modifiers;
11
+import org.openzen.zenscript.codemodel.definition.AliasDefinition;
12
+import org.openzen.zenscript.codemodel.definition.ClassDefinition;
13
+import org.openzen.zenscript.codemodel.definition.DefinitionVisitor;
14
+import org.openzen.zenscript.codemodel.definition.EnumDefinition;
15
+import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
16
+import org.openzen.zenscript.codemodel.definition.FunctionDefinition;
17
+import org.openzen.zenscript.codemodel.definition.InterfaceDefinition;
18
+import org.openzen.zenscript.codemodel.definition.StructDefinition;
19
+import org.openzen.zenscript.codemodel.definition.VariantDefinition;
20
+import org.openzen.zenscript.codemodel.member.IDefinitionMember;
21
+import org.openzen.zenscript.codemodel.member.ImplementationMember;
22
+
23
+/**
24
+ *
25
+ * @author Hoofdgebruiker
26
+ */
27
+public class JavaDefinitionVisitor implements DefinitionVisitor<Void> {
28
+	private final JavaSourceFile file;
29
+	private final StringBuilder output;
30
+	
31
+	public JavaDefinitionVisitor(JavaSourceFile file, StringBuilder output) {
32
+		this.file = file;
33
+		this.output = output;
34
+	}
35
+
36
+	@Override
37
+	public Void visitClass(ClassDefinition definition) {
38
+		convertModifiers(definition.modifiers);
39
+		output.append("class ").append(definition.name);
40
+		if (definition.superType != null) {
41
+			output.append(" extends ");
42
+			output.append(definition.superType.accept(new JavaSourceTypeVisitor(file)));
43
+		}
44
+		List<ImplementationMember> mergedImplementations = new ArrayList<>();
45
+		for (IDefinitionMember member : definition.members) {
46
+			if (member instanceof ImplementationMember) {
47
+				if (isImplementationMergable((ImplementationMember)member))
48
+					mergedImplementations.add((ImplementationMember)member);
49
+			}
50
+		}
51
+		
52
+		if (mergedImplementations.size() > 0) {
53
+			output.append("implements ");
54
+			for (int i = 0; i < mergedImplementations.size(); i++) {
55
+				if (i > 0)
56
+					output.append(", ");
57
+				
58
+				ImplementationMember implementation = mergedImplementations.get(i);
59
+				output.append(implementation.type.accept(new JavaSourceTypeVisitor(file)));
60
+			}
61
+		}
62
+		
63
+		output.append(" {\n");
64
+		
65
+		
66
+		
67
+		output.append("}\n");
68
+		return null;
69
+	}
70
+
71
+	@Override
72
+	public Void visitInterface(InterfaceDefinition definition) {
73
+		convertModifiers(definition.modifiers);
74
+		output.append("interface ").append(definition.name);
75
+		output.append(" {\n");
76
+		
77
+		
78
+		
79
+		output.append("}\n");
80
+		return null;
81
+	}
82
+
83
+	@Override
84
+	public Void visitEnum(EnumDefinition definition) {
85
+		convertModifiers(definition.modifiers);
86
+		output.append("enum ").append(definition.name);
87
+		
88
+		output.append(" {\n");
89
+		
90
+		
91
+		
92
+		output.append("}\n");
93
+		return null;
94
+	}
95
+
96
+	@Override
97
+	public Void visitStruct(StructDefinition definition) {
98
+		convertModifiers(definition.modifiers | Modifiers.FINAL);
99
+		output.append("class ").append(definition.name);
100
+		output.append(" {\n");
101
+		
102
+		
103
+		
104
+		output.append("}\n");
105
+		return null;
106
+	}
107
+
108
+	@Override
109
+	public Void visitFunction(FunctionDefinition definition) {
110
+		convertModifiers(definition.modifiers | Modifiers.STATIC);
111
+		return null;
112
+	}
113
+
114
+	@Override
115
+	public Void visitExpansion(ExpansionDefinition definition) {
116
+		convertModifiers(definition.modifiers);
117
+		return null;
118
+	}
119
+
120
+	@Override
121
+	public Void visitAlias(AliasDefinition definition) {
122
+		throw new UnsupportedOperationException("Should not arrive here");
123
+	}
124
+
125
+	@Override
126
+	public Void visitVariant(VariantDefinition variant) {
127
+		return null;
128
+	}
129
+	
130
+	private void convertModifiers(int modifiers) {
131
+		if (Modifiers.isExport(modifiers) || Modifiers.isPublic(modifiers))
132
+			output.append("public ");
133
+		if (Modifiers.isPrivate(modifiers))
134
+			output.append("private ");
135
+		if (Modifiers.isProtected(modifiers))
136
+			output.append("protected ");
137
+		if (Modifiers.isStatic(modifiers))
138
+			output.append("static ");
139
+		if (Modifiers.isAbstract(modifiers))
140
+			output.append("abstract ");
141
+		if (!Modifiers.isVirtual(modifiers))
142
+			output.append("final ");
143
+	}
144
+	
145
+	private boolean isImplementationMergable(ImplementationMember implementation) {
146
+		return true; // TODO: check merging conflicts
147
+	}
148
+}

+ 84
- 0
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceCompiler.java Vedi File

@@ -0,0 +1,84 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.javasource;
7
+
8
+import java.io.File;
9
+import java.util.HashMap;
10
+import java.util.Map;
11
+import org.openzen.zenscript.codemodel.HighLevelDefinition;
12
+import org.openzen.zenscript.codemodel.ScriptBlock;
13
+import org.openzen.zenscript.codemodel.definition.FunctionDefinition;
14
+import org.openzen.zenscript.codemodel.definition.ZSPackage;
15
+import org.openzen.zenscript.compiler.ZenCodeCompiler;
16
+import org.openzen.zenscript.shared.SourceFile;
17
+
18
+/**
19
+ *
20
+ * @author Hoofdgebruiker
21
+ */
22
+public class JavaSourceCompiler implements ZenCodeCompiler {
23
+	private final File directory;
24
+	private final ZSPackage pkg;
25
+	private final Map<File, JavaSourceFile> sourceFiles = new HashMap<>();
26
+	
27
+	public JavaSourceCompiler(File directory, ZSPackage pkg) {
28
+		if (!directory.exists())
29
+			directory.mkdirs();
30
+		
31
+		this.directory = directory;
32
+		this.pkg = pkg;
33
+	}
34
+	
35
+	@Override
36
+	public void addDefinition(HighLevelDefinition definition) {
37
+		File file = new File(getDirectory(definition.pkg), definition.name + ".java");
38
+		if (definition.name == null || definition instanceof FunctionDefinition) {
39
+			SourceFile source = definition.getTag(SourceFile.class);
40
+			if (source != null) {
41
+				int slash = Math.max(source.filename.lastIndexOf('/'), source.filename.lastIndexOf('\\'));
42
+				String filename = source.filename.substring(slash < 0 ? 0 : slash);
43
+				filename = filename.substring(0, filename.lastIndexOf('.'));
44
+				file = new File(getDirectory(definition.pkg), filename + ".java");
45
+			}
46
+		}
47
+		
48
+		JavaSourceFile sourceFile = sourceFiles.get(file);
49
+		if (sourceFile == null)
50
+			sourceFiles.put(file, sourceFile = new JavaSourceFile(this, file, definition.pkg.fullName));
51
+		
52
+		sourceFile.add(definition);
53
+	}
54
+	
55
+	@Override
56
+	public void addScriptBlock(ScriptBlock script) {
57
+		
58
+	}
59
+	
60
+	@Override
61
+	public void finish() {
62
+		for (JavaSourceFile sourceFile : sourceFiles.values())
63
+			sourceFile.write();
64
+	}
65
+	
66
+	@Override
67
+	public void run() {
68
+		throw new UnsupportedOperationException("Cannot run this target");
69
+	}
70
+	
71
+	public String getFullName(HighLevelDefinition definition) {
72
+		return definition.pkg.fullName + "." + definition.name;
73
+	}
74
+	
75
+	private File getDirectory(ZSPackage pkg) {
76
+		if (pkg == null)
77
+			throw new RuntimeException("Package not in the package directory");
78
+		if (pkg == this.pkg)
79
+			return directory;
80
+		
81
+		File base = getDirectory(pkg.parent);
82
+		return new File(base, pkg.name);
83
+	}
84
+}

+ 79
- 0
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceFile.java Vedi File

@@ -0,0 +1,79 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.javasource;
7
+
8
+import java.io.BufferedOutputStream;
9
+import java.io.File;
10
+import java.io.FileOutputStream;
11
+import java.io.IOException;
12
+import java.io.OutputStreamWriter;
13
+import java.io.Writer;
14
+import java.nio.charset.StandardCharsets;
15
+import java.util.Arrays;
16
+import java.util.HashMap;
17
+import java.util.Map;
18
+import org.openzen.zenscript.codemodel.HighLevelDefinition;
19
+
20
+/**
21
+ *
22
+ * @author Hoofdgebruiker
23
+ */
24
+public class JavaSourceFile {
25
+	private final JavaSourceCompiler compiler;
26
+	private final File file;
27
+	private final String packageName;
28
+	private final Map<String, String> imports = new HashMap<>();
29
+	private final StringBuilder contents = new StringBuilder();
30
+	
31
+	public JavaSourceFile(JavaSourceCompiler compiler, File file, String packageName) {
32
+		this.compiler = compiler;
33
+		this.packageName = packageName;
34
+		this.file = file;
35
+	}
36
+	
37
+	public String importType(HighLevelDefinition definition) {
38
+		return importType(compiler.getFullName(definition));
39
+	}
40
+	
41
+	public String importType(String fullName) {
42
+		String name = fullName.substring(fullName.lastIndexOf('.') + 1);
43
+		if (imports.containsKey(name))
44
+			return fullName;
45
+		
46
+		imports.put(name, fullName);
47
+		return name;
48
+	}
49
+	
50
+	public void add(HighLevelDefinition definition) {
51
+		JavaDefinitionVisitor visitor = new JavaDefinitionVisitor(this, contents);
52
+		definition.accept(visitor);
53
+	}
54
+	
55
+	public void write() {
56
+		try (Writer writer = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(file)), StandardCharsets.UTF_8)) {
57
+			writer.write("package ");
58
+			writer.write(packageName);
59
+			writer.write(";\n\n");
60
+			
61
+			if (this.imports.size() > 0) {
62
+				String[] imports = this.imports.values().toArray(new String[this.imports.size()]);
63
+				Arrays.sort(imports);
64
+
65
+				for (String importName : imports) {
66
+					writer.write("import ");
67
+					writer.write(importName);
68
+					writer.write(";");
69
+				}
70
+
71
+				writer.write("\n\n");
72
+			}
73
+			
74
+			writer.write(contents.toString());
75
+		} catch (IOException ex) {
76
+			ex.printStackTrace();
77
+		}
78
+	}
79
+}

+ 41
- 0
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceObjectTypeVisitor.java Vedi File

@@ -0,0 +1,41 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.javasource;
7
+
8
+import org.openzen.zenscript.codemodel.type.BasicTypeID;
9
+
10
+/**
11
+ *
12
+ * @author Hoofdgebruiker
13
+ */
14
+public class JavaSourceObjectTypeVisitor extends JavaSourceTypeVisitor {
15
+	public JavaSourceObjectTypeVisitor(JavaSourceFile file) {
16
+		super(file);
17
+	}
18
+	
19
+	@Override
20
+	public String visitBasic(BasicTypeID basic) {
21
+		switch (basic) {
22
+			case VOID: return "Void";
23
+			case ANY: return "Any";
24
+			case BOOL: return "Boolean";
25
+			case BYTE: return "Byte";
26
+			case SBYTE: return "Byte";
27
+			case SHORT: return "Short";
28
+			case USHORT: return "Short";
29
+			case INT: return "Integer";
30
+			case UINT: return "Integer";
31
+			case LONG: return "Long";
32
+			case ULONG: return "Long";
33
+			case FLOAT: return "Float";
34
+			case DOUBLE: return "Double";
35
+			case CHAR: return "Character";
36
+			case STRING: return "String";
37
+			default:
38
+				throw new IllegalArgumentException("Unknown basic type: " + basic);
39
+		}
40
+	}
41
+}

+ 53
- 0
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceTarget.java Vedi File

@@ -0,0 +1,53 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.javasource;
7
+
8
+import java.io.File;
9
+import org.json.JSONObject;
10
+import org.openzen.zenscript.compiler.SemanticModule;
11
+import org.openzen.zenscript.compiler.Target;
12
+import org.openzen.zenscript.compiler.ZenCodeCompiler;
13
+
14
+/**
15
+ *
16
+ * @author Hoofdgebruiker
17
+ */
18
+public class JavaSourceTarget implements Target {
19
+	private final String module;
20
+	private final String name;
21
+	private final File output;
22
+	
23
+	public JavaSourceTarget(File projectDir, JSONObject definition) {
24
+		module = definition.getString("module");
25
+		name = definition.optString("name", "Java Source: " + module);
26
+		output = new File(projectDir, definition.getString("output"));
27
+	}
28
+
29
+	@Override
30
+	public ZenCodeCompiler createCompiler(SemanticModule module) {
31
+		return new JavaSourceCompiler(output, module.pkg);
32
+	}
33
+
34
+	@Override
35
+	public String getModule() {
36
+		return module;
37
+	}
38
+
39
+	@Override
40
+	public String getName() {
41
+		return name;
42
+	}
43
+
44
+	@Override
45
+	public boolean canRun() {
46
+		return false;
47
+	}
48
+
49
+	@Override
50
+	public boolean canBuild() {
51
+		return true;
52
+	}
53
+}

+ 26
- 0
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceTargetType.java Vedi File

@@ -0,0 +1,26 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.javasource;
7
+
8
+import java.io.File;
9
+import org.json.JSONObject;
10
+import org.openzen.zenscript.compiler.Target;
11
+import org.openzen.zenscript.compiler.TargetType;
12
+
13
+/**
14
+ *
15
+ * @author Hoofdgebruiker
16
+ */
17
+public class JavaSourceTargetType implements TargetType {
18
+	public static final JavaSourceTargetType INSTANCE = new JavaSourceTargetType();
19
+	
20
+	private JavaSourceTargetType() {}
21
+
22
+	@Override
23
+	public Target create(File projectDir, JSONObject definition) {
24
+		return new JavaSourceTarget(projectDir, definition);
25
+	}
26
+}

+ 125
- 0
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceTypeVisitor.java Vedi File

@@ -0,0 +1,125 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.javasource;
7
+
8
+import org.openzen.zenscript.codemodel.type.ArrayTypeID;
9
+import org.openzen.zenscript.codemodel.type.AssocTypeID;
10
+import org.openzen.zenscript.codemodel.type.BasicTypeID;
11
+import org.openzen.zenscript.codemodel.type.ConstTypeID;
12
+import org.openzen.zenscript.codemodel.type.DefinitionTypeID;
13
+import org.openzen.zenscript.codemodel.type.FunctionTypeID;
14
+import org.openzen.zenscript.codemodel.type.GenericMapTypeID;
15
+import org.openzen.zenscript.codemodel.type.GenericTypeID;
16
+import org.openzen.zenscript.codemodel.type.ITypeVisitor;
17
+import org.openzen.zenscript.codemodel.type.IteratorTypeID;
18
+import org.openzen.zenscript.codemodel.type.OptionalTypeID;
19
+import org.openzen.zenscript.codemodel.type.RangeTypeID;
20
+
21
+/**
22
+ *
23
+ * @author Hoofdgebruiker
24
+ */
25
+public class JavaSourceTypeVisitor implements ITypeVisitor<String> {
26
+	private final JavaSourceFile file;
27
+	
28
+	public JavaSourceTypeVisitor(JavaSourceFile file) {
29
+		this.file = file;
30
+	}
31
+
32
+	@Override
33
+	public String visitBasic(BasicTypeID basic) {
34
+		switch (basic) {
35
+			case VOID: return "void";
36
+			case ANY: return "Any";
37
+			case BOOL: return "boolean";
38
+			case BYTE: return "byte";
39
+			case SBYTE: return "byte";
40
+			case SHORT: return "short";
41
+			case USHORT: return "ushort";
42
+			case INT: return "int";
43
+			case UINT: return "int";
44
+			case LONG: return "long";
45
+			case ULONG: return "long";
46
+			case FLOAT: return "float";
47
+			case DOUBLE: return "double";
48
+			case CHAR: return "char";
49
+			case STRING: return "String";
50
+			default:
51
+				throw new IllegalArgumentException("Unknown basic type: " + basic);
52
+		}
53
+	}
54
+
55
+	@Override
56
+	public String visitArray(ArrayTypeID array) {
57
+		StringBuilder result = new StringBuilder();
58
+		result.append(array.elementType.accept(this));
59
+		for (int i = 0; i < array.dimension; i++)
60
+			result.append("[]");
61
+		
62
+		return result.toString();
63
+	}
64
+
65
+	@Override
66
+	public String visitAssoc(AssocTypeID assoc) {
67
+		String map = file.importType("java.util.Map");
68
+		return map + "<" + assoc.keyType.accept(new JavaSourceObjectTypeVisitor(file)) + ", " + assoc.valueType.accept(new JavaSourceObjectTypeVisitor(file)) + ">";
69
+	}
70
+
71
+	@Override
72
+	public String visitGenericMap(GenericMapTypeID map) {
73
+		String javaMap = file.importType("java.util.Map");
74
+		if (map.keys.length > 1)
75
+			throw new UnsupportedOperationException("Not yet supported");
76
+		
77
+		return javaMap + "<Class<?>, " + map.value.accept(this) + ">";
78
+	}
79
+
80
+	@Override
81
+	public String visitIterator(IteratorTypeID iterator) {
82
+		throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
83
+	}
84
+
85
+	@Override
86
+	public String visitFunction(FunctionTypeID function) {
87
+		throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
88
+	}
89
+
90
+	@Override
91
+	public String visitDefinition(DefinitionTypeID definition) {
92
+		String javaType = file.importType(definition.definition);
93
+		StringBuilder result = new StringBuilder(javaType);
94
+		if (definition.typeParameters != null && definition.typeParameters.length > 0) {
95
+			result.append("<");
96
+			for (int i = 0; i < definition.typeParameters.length; i++) {
97
+				if (i > 0)
98
+					result.append(", ");
99
+				result.append(definition.typeParameters[i].accept(this));
100
+			}
101
+			result.append(">");
102
+		}
103
+		return result.toString();
104
+	}
105
+
106
+	@Override
107
+	public String visitGeneric(GenericTypeID generic) {
108
+		throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
109
+	}
110
+
111
+	@Override
112
+	public String visitRange(RangeTypeID range) {
113
+		throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
114
+	}
115
+
116
+	@Override
117
+	public String visitConst(ConstTypeID type) {
118
+		return type.baseType.accept(this);
119
+	}
120
+
121
+	@Override
122
+	public String visitOptional(OptionalTypeID optional) {
123
+		return optional.baseType.accept(new JavaSourceObjectTypeVisitor(file));
124
+	}
125
+}

+ 1
- 1
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedMatchExpression.java Vedi File

@@ -43,7 +43,7 @@ public class ParsedMatchExpression extends ParsedExpression {
43 43
 
44 44
 	@Override
45 45
 	public IPartialExpression compile(ExpressionScope scope) {
46
-		Expression cValue = value.compileKey(scope);
46
+		Expression cValue = value.compile(scope).eval();
47 47
 		MatchExpression.Case[] cCases = new MatchExpression.Case[cases.size()];
48 48
 		for (int i = 0; i < cases.size(); i++) {
49 49
 			Case matchCase = cases.get(i);

+ 2
- 2
ScriptingExample/src/main/java/org/openzen/zenscript/scriptingexample/GlobalRegistry.java Vedi File

@@ -40,8 +40,8 @@ import org.openzen.zenscript.shared.CodePosition;
40 40
  * @author Hoofdgebruiker
41 41
  */
42 42
 public class GlobalRegistry {
43
-	public final ZSPackage globals = new ZSPackage("");
44
-	private final ZSPackage rootPackage = new ZSPackage("");
43
+	public final ZSPackage globals = new ZSPackage(null, "");
44
+	private final ZSPackage rootPackage = new ZSPackage(null, "");
45 45
 	private final ZSPackage javaIo = rootPackage.getOrCreatePackage("java").getOrCreatePackage("io");
46 46
 	private final ZSPackage javaLang = rootPackage.getOrCreatePackage("java").getOrCreatePackage("lang");
47 47
 	

+ 4
- 4
ScriptingExample/src/main/java/org/openzen/zenscript/scriptingexample/Main.java Vedi File

@@ -34,10 +34,10 @@ public class Main {
34 34
 		File inputDirectory = new File("scripts");
35 35
 		File[] inputFiles = Optional.ofNullable(inputDirectory.listFiles((dir, name) -> name.endsWith(".zs"))).orElseGet(() -> new File[0]);
36 36
 		
37
-		ZSPackage pkg = new ZSPackage("");
37
+		ZSPackage pkg = new ZSPackage(null, "");
38 38
 		ParsedFile[] parsedFiles = parse(pkg, inputFiles);
39 39
 		
40
-		ZSPackage global = new ZSPackage("");
40
+		ZSPackage global = new ZSPackage(null, "");
41 41
 		GlobalRegistry registry = new GlobalRegistry(global);
42 42
 		SemanticModule module = compileSyntaxToSemantic(parsedFiles, registry);
43 43
 		
@@ -95,7 +95,7 @@ public class Main {
95 95
 	}
96 96
 	
97 97
 	private static SemanticModule compileSyntaxToSemantic(ParsedFile[] files, GlobalRegistry registry) {
98
-		ZSPackage modulePackage = new ZSPackage(null);
98
+		ZSPackage modulePackage = new ZSPackage(null, "");
99 99
 		
100 100
 		// We are considering all these files to be in the same package, so make
101 101
 		// a single PackageDefinition instance. If these files were in multiple
@@ -156,6 +156,6 @@ public class Main {
156 156
 		for (ScriptBlock script : module.scripts) {
157 157
 			compiler.addScriptBlock(script);
158 158
 		}
159
-		return compiler.finish();
159
+		return compiler.finishAndGetModule();
160 160
 	}
161 161
 }

Loading…
Annulla
Salva