Browse Source

- CodePosition now stores source file references rather than source file names, allowing easier matching

- Starting work on error recording and display
- Fixed compilation of modules with dependencies
- Added a couple improvements to code typing for matching brackets
- Fixed java source compilation of abstract classes and methods
Stan Hebben 6 years ago
parent
commit
0ff6adff2e
41 changed files with 501 additions and 153 deletions
  1. 4
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/DefinitionMember.java
  2. 2
    1
      Constructor/src/main/java/org/openzen/zenscript/constructor/module/DirectoryModuleReference.java
  3. 0
    22
      Constructor/src/main/java/org/openzen/zenscript/constructor/module/SourceFile.java
  4. 3
    1
      Constructor/src/main/java/org/openzen/zenscript/constructor/module/SourcePackage.java
  5. 25
    0
      IDE/src/main/java/org/openzen/zenscript/ide/codemodel/IDECodeError.java
  6. 41
    0
      IDE/src/main/java/org/openzen/zenscript/ide/codemodel/IDECodeSpace.java
  7. 6
    0
      IDE/src/main/java/org/openzen/zenscript/ide/host/IDEModule.java
  8. 2
    3
      IDE/src/main/java/org/openzen/zenscript/ide/host/IDESourceFile.java
  9. 10
    0
      IDE/src/main/java/org/openzen/zenscript/ide/host/local/LocalModule.java
  10. 3
    2
      IDE/src/main/java/org/openzen/zenscript/ide/host/local/LocalPackage.java
  11. 12
    13
      IDE/src/main/java/org/openzen/zenscript/ide/host/local/LocalSourceFile.java
  12. 5
    5
      IDE/src/main/java/org/openzen/zenscript/ide/host/local/LocalTarget.java
  13. 48
    0
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/editor/PathGenerator.java
  14. 39
    24
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/editor/SourceEditor.java
  15. 6
    4
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/editor/TokenModel.java
  16. 5
    4
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/editor/TokenRelexer.java
  17. 47
    0
      IDE/src/main/java/org/openzen/zenscript/ide/ui/view/editor/WavyLine.java
  18. 1
    1
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaCompiler.java
  19. 2
    0
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/BaseMemberCompiler.java
  20. 2
    2
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaDefinitionVisitor.java
  21. 2
    2
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceCompiler.java
  22. 0
    1
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceTypeVisitor.java
  23. 24
    1
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/prepare/JavaSourcePrepareDefinitionVisitor.java
  24. 11
    3
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/prepare/JavaSourcePrepareExpansionMethodVisitor.java
  25. 20
    0
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/tags/JavaSourceImplementation.java
  26. 6
    5
      Parser/src/main/java/org/openzen/zenscript/lexer/CountingCharReader.java
  27. 7
    6
      Parser/src/main/java/org/openzen/zenscript/lexer/TokenParser.java
  28. 7
    6
      Parser/src/main/java/org/openzen/zenscript/lexer/ZSTokenParser.java
  29. 14
    17
      Parser/src/main/java/org/openzen/zenscript/parser/ParsedFile.java
  30. 7
    5
      Shared/src/main/java/org/openzen/zencode/shared/CodePosition.java
  31. 42
    0
      Shared/src/main/java/org/openzen/zencode/shared/FileSourceFile.java
  32. 34
    0
      Shared/src/main/java/org/openzen/zencode/shared/LiteralSourceFile.java
  33. 6
    9
      Shared/src/main/java/org/openzen/zencode/shared/SourceFile.java
  34. 31
    0
      Shared/src/main/java/org/openzen/zencode/shared/VirtualSourceFile.java
  35. 11
    0
      Shared/src/main/java/stdlib/Arrays.java
  36. 2
    2
      Shared/src/main/java/stdlib/Assoc.java
  37. 4
    4
      Shared/src/main/java/stdlib/Result.java
  38. 4
    2
      Shared/src/main/java/zsynthetic/Function10.java
  39. 2
    2
      Shared/src/main/java/zsynthetic/Function7.java
  40. 2
    4
      Shared/src/main/java/zsynthetic/Function8.java
  41. 2
    2
      Shared/src/main/java/zsynthetic/Function9.java

+ 4
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/DefinitionMember.java View File

43
 	public boolean isExtern() {
43
 	public boolean isExtern() {
44
 		return Modifiers.isExtern(modifiers);
44
 		return Modifiers.isExtern(modifiers);
45
 	}
45
 	}
46
+	
47
+	public boolean isPrivate() {
48
+		return Modifiers.isPrivate(modifiers);
49
+	}
46
 }
50
 }

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

14
 import org.json.JSONArray;
14
 import org.json.JSONArray;
15
 import org.json.JSONObject;
15
 import org.json.JSONObject;
16
 import org.openzen.zencode.shared.CompileException;
16
 import org.openzen.zencode.shared.CompileException;
17
+import org.openzen.zencode.shared.FileSourceFile;
17
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
18
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
18
 import org.openzen.zenscript.compiler.CompilationUnit;
19
 import org.openzen.zenscript.compiler.CompilationUnit;
19
 import org.openzen.zenscript.constructor.ConstructorException;
20
 import org.openzen.zenscript.constructor.ConstructorException;
112
 			if (file.isDirectory()) {
113
 			if (file.isDirectory()) {
113
 				pkg.addPackage(loadPackage(file.getName(), file));
114
 				pkg.addPackage(loadPackage(file.getName(), file));
114
 			} else if (file.isFile() && file.getName().toLowerCase().endsWith(".zs")) {
115
 			} else if (file.isFile() && file.getName().toLowerCase().endsWith(".zs")) {
115
-				pkg.addFile(new SourceFile(file.getName(), file));
116
+				pkg.addFile(new FileSourceFile(file.getName(), file));
116
 			}
117
 			}
117
 		}
118
 		}
118
 		
119
 		

+ 0
- 22
Constructor/src/main/java/org/openzen/zenscript/constructor/module/SourceFile.java View File

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.module;
7
-
8
-import java.io.File;
9
-
10
-/**
11
- *
12
- * @author Hoofdgebruiker
13
- */
14
-public class SourceFile {
15
-	public final String name;
16
-	public final File file;
17
-	
18
-	public SourceFile(String name, File file) {
19
-		this.name = name;
20
-		this.file = file;
21
-	}
22
-}

+ 3
- 1
Constructor/src/main/java/org/openzen/zenscript/constructor/module/SourcePackage.java View File

8
 import java.io.File;
8
 import java.io.File;
9
 import java.util.HashMap;
9
 import java.util.HashMap;
10
 import java.util.Map;
10
 import java.util.Map;
11
+import org.openzen.zencode.shared.FileSourceFile;
12
+import org.openzen.zencode.shared.SourceFile;
11
 
13
 
12
 /**
14
 /**
13
  *
15
  *
29
 	}
31
 	}
30
 	
32
 	
31
 	public void addFile(SourceFile file) {
33
 	public void addFile(SourceFile file) {
32
-		sourceFiles.put(file.name, file);
34
+		sourceFiles.put(file.getFilename(), file);
33
 	}
35
 	}
34
 }
36
 }

+ 25
- 0
IDE/src/main/java/org/openzen/zenscript/ide/codemodel/IDECodeError.java View File

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.codemodel;
7
+
8
+import org.openzen.zencode.shared.CodePosition;
9
+import org.openzen.zenscript.ide.host.IDESourceFile;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public class IDECodeError {
16
+	public final IDESourceFile file;
17
+	public final CodePosition position;
18
+	public final String message;
19
+	
20
+	public IDECodeError(IDESourceFile file, CodePosition position, String message) {
21
+		this.file = file;
22
+		this.position = position;
23
+		this.message = message;
24
+	}
25
+}

+ 41
- 0
IDE/src/main/java/org/openzen/zenscript/ide/codemodel/IDECodeSpace.java View File

5
  */
5
  */
6
 package org.openzen.zenscript.ide.codemodel;
6
 package org.openzen.zenscript.ide.codemodel;
7
 
7
 
8
+import java.io.File;
9
+import java.util.ArrayList;
10
+import java.util.Collections;
11
+import java.util.HashMap;
12
+import java.util.HashSet;
13
+import java.util.List;
14
+import java.util.Map;
15
+import java.util.Set;
16
+import java.util.function.Consumer;
17
+import org.openzen.zenscript.compiler.CompilationUnit;
18
+import org.openzen.zenscript.compiler.SemanticModule;
19
+import org.openzen.zenscript.compiler.ZenCodeCompiler;
20
+import org.openzen.zenscript.constructor.Library;
21
+import org.openzen.zenscript.constructor.ModuleLoader;
22
+import org.openzen.zenscript.constructor.module.DirectoryModuleReference;
23
+import org.openzen.zenscript.constructor.module.ModuleReference;
8
 import org.openzen.zenscript.ide.host.DevelopmentHost;
24
 import org.openzen.zenscript.ide.host.DevelopmentHost;
25
+import org.openzen.zenscript.ide.host.IDEModule;
9
 import org.openzen.zenscript.ide.host.IDESourceFile;
26
 import org.openzen.zenscript.ide.host.IDESourceFile;
27
+import org.openzen.zenscript.ide.ui.view.output.ErrorOutputSpan;
28
+import org.openzen.zenscript.ide.ui.view.output.OutputLine;
29
+import org.openzen.zenscript.validator.ValidationLogEntry;
30
+import stdlib.Strings;
10
 
31
 
11
 /**
32
 /**
12
  *
33
  *
14
  */
35
  */
15
 public class IDECodeSpace {
36
 public class IDECodeSpace {
16
 	private final DevelopmentHost host;
37
 	private final DevelopmentHost host;
38
+	private final Map<IDESourceFile, List<IDECodeError>> sourceFileErrors = new HashMap<>();
17
 	
39
 	
18
 	public IDECodeSpace(DevelopmentHost host) {
40
 	public IDECodeSpace(DevelopmentHost host) {
19
 		this.host = host;
41
 		this.host = host;
42
+		
43
+		ModuleLoader loader = new ModuleLoader(new CompilationUnit(), exception -> {
44
+			
45
+		});
46
+		for (IDEModule module : host.getModules()) {
47
+			module.prebuild(loader, this::addError);
48
+		}
20
 	}
49
 	}
21
 	
50
 	
22
 	public void onSaved(IDESourceFile file) {
51
 	public void onSaved(IDESourceFile file) {
23
 		
52
 		
24
 	}
53
 	}
54
+	
55
+	public List<IDECodeError> getErrors(IDESourceFile file) {
56
+		return sourceFileErrors.getOrDefault(file, Collections.emptyList());
57
+	}
58
+	
59
+	private void addError(IDECodeError error) {
60
+		if (error.file == null)
61
+			return;
62
+		if (!sourceFileErrors.containsKey(error.file))
63
+			sourceFileErrors.put(error.file, new ArrayList<>());
64
+		sourceFileErrors.get(error.file).add(error);
65
+	}
25
 }
66
 }

+ 6
- 0
IDE/src/main/java/org/openzen/zenscript/ide/host/IDEModule.java View File

5
  */
5
  */
6
 package org.openzen.zenscript.ide.host;
6
 package org.openzen.zenscript.ide.host;
7
 
7
 
8
+import java.util.function.Consumer;
9
+import org.openzen.zenscript.constructor.ModuleLoader;
10
+import org.openzen.zenscript.ide.codemodel.IDECodeError;
11
+
8
 /**
12
 /**
9
  *
13
  *
10
  * @author Hoofdgebruiker
14
  * @author Hoofdgebruiker
13
 	public String getName();
17
 	public String getName();
14
 	
18
 	
15
 	public IDEPackage getRootPackage();
19
 	public IDEPackage getRootPackage();
20
+	
21
+	void prebuild(ModuleLoader loader, Consumer<IDECodeError> errors);
16
 }
22
 }

+ 2
- 3
IDE/src/main/java/org/openzen/zenscript/ide/host/IDESourceFile.java View File

5
  */
5
  */
6
 package org.openzen.zenscript.ide.host;
6
 package org.openzen.zenscript.ide.host;
7
 
7
 
8
-import java.io.IOException;
9
-import java.io.Reader;
10
 import org.openzen.drawablegui.live.LiveString;
8
 import org.openzen.drawablegui.live.LiveString;
9
+import org.openzen.zencode.shared.SourceFile;
11
 
10
 
12
 /**
11
 /**
13
  *
12
  *
16
 public interface IDESourceFile {
15
 public interface IDESourceFile {
17
 	public LiveString getName();
16
 	public LiveString getName();
18
 	
17
 	
19
-	public Reader read() throws IOException;
18
+	public SourceFile getFile();
20
 	
19
 	
21
 	public void update(String content);
20
 	public void update(String content);
22
 }
21
 }

+ 10
- 0
IDE/src/main/java/org/openzen/zenscript/ide/host/local/LocalModule.java View File

5
  */
5
  */
6
 package org.openzen.zenscript.ide.host.local;
6
 package org.openzen.zenscript.ide.host.local;
7
 
7
 
8
+import java.util.function.Consumer;
9
+import org.openzen.zenscript.compiler.SemanticModule;
10
+import org.openzen.zenscript.constructor.ModuleLoader;
8
 import org.openzen.zenscript.constructor.module.ModuleReference;
11
 import org.openzen.zenscript.constructor.module.ModuleReference;
12
+import org.openzen.zenscript.ide.codemodel.IDECodeError;
9
 import org.openzen.zenscript.ide.host.IDEModule;
13
 import org.openzen.zenscript.ide.host.IDEModule;
10
 import org.openzen.zenscript.ide.host.IDEPackage;
14
 import org.openzen.zenscript.ide.host.IDEPackage;
11
 
15
 
31
 	public IDEPackage getRootPackage() {
35
 	public IDEPackage getRootPackage() {
32
 		return rootPackage;
36
 		return rootPackage;
33
 	}
37
 	}
38
+	
39
+	@Override
40
+	public void prebuild(ModuleLoader loader, Consumer<IDECodeError> errors) {
41
+		SemanticModule module = loader.getModule(this.module.getName());
42
+		module.validate(entry -> errors.accept(new IDECodeError(null, entry.position, entry.message)));
43
+	}
34
 }
44
 }

+ 3
- 2
IDE/src/main/java/org/openzen/zenscript/ide/host/local/LocalPackage.java View File

12
 import org.openzen.drawablegui.live.LiveList;
12
 import org.openzen.drawablegui.live.LiveList;
13
 import org.openzen.drawablegui.live.MutableLiveList;
13
 import org.openzen.drawablegui.live.MutableLiveList;
14
 import org.openzen.drawablegui.live.SortedLiveList;
14
 import org.openzen.drawablegui.live.SortedLiveList;
15
-import org.openzen.zenscript.constructor.module.SourceFile;
15
+import org.openzen.zencode.shared.FileSourceFile;
16
+import org.openzen.zencode.shared.SourceFile;
16
 import org.openzen.zenscript.constructor.module.SourcePackage;
17
 import org.openzen.zenscript.constructor.module.SourcePackage;
17
 import org.openzen.zenscript.ide.host.IDEPackage;
18
 import org.openzen.zenscript.ide.host.IDEPackage;
18
 import org.openzen.zenscript.ide.host.IDESourceFile;
19
 import org.openzen.zenscript.ide.host.IDESourceFile;
87
 			ex.printStackTrace(); // TODO
88
 			ex.printStackTrace(); // TODO
88
 		}
89
 		}
89
 		
90
 		
90
-		SourceFile sourceFile = new SourceFile(name, file);
91
+		FileSourceFile sourceFile = new FileSourceFile(name, file);
91
 		IDESourceFile localSourceFile = new LocalSourceFile(sourceFile);
92
 		IDESourceFile localSourceFile = new LocalSourceFile(sourceFile);
92
 		this.pkg.sourceFiles.put(name, sourceFile);
93
 		this.pkg.sourceFiles.put(name, sourceFile);
93
 		sourceFiles.add(localSourceFile);
94
 		sourceFiles.add(localSourceFile);

+ 12
- 13
IDE/src/main/java/org/openzen/zenscript/ide/host/local/LocalSourceFile.java View File

5
  */
5
  */
6
 package org.openzen.zenscript.ide.host.local;
6
 package org.openzen.zenscript.ide.host.local;
7
 
7
 
8
-import java.io.BufferedInputStream;
9
 import java.io.BufferedOutputStream;
8
 import java.io.BufferedOutputStream;
10
-import java.io.FileInputStream;
11
 import java.io.FileOutputStream;
9
 import java.io.FileOutputStream;
12
 import java.io.IOException;
10
 import java.io.IOException;
13
-import java.io.InputStreamReader;
14
 import java.io.OutputStreamWriter;
11
 import java.io.OutputStreamWriter;
15
-import java.io.Reader;
16
 import java.io.Writer;
12
 import java.io.Writer;
17
 import java.nio.charset.StandardCharsets;
13
 import java.nio.charset.StandardCharsets;
18
 import org.openzen.drawablegui.live.LiveString;
14
 import org.openzen.drawablegui.live.LiveString;
19
 import org.openzen.drawablegui.live.MutableLiveString;
15
 import org.openzen.drawablegui.live.MutableLiveString;
20
 import org.openzen.drawablegui.live.SimpleLiveString;
16
 import org.openzen.drawablegui.live.SimpleLiveString;
21
-import org.openzen.zenscript.constructor.module.SourceFile;
17
+import org.openzen.zencode.shared.FileSourceFile;
18
+import org.openzen.zencode.shared.SourceFile;
22
 import org.openzen.zenscript.ide.host.IDESourceFile;
19
 import org.openzen.zenscript.ide.host.IDESourceFile;
23
 
20
 
24
 /**
21
 /**
31
 	
28
 	
32
 	public LocalSourceFile(SourceFile file) {
29
 	public LocalSourceFile(SourceFile file) {
33
 		this.file = file;
30
 		this.file = file;
34
-		this.name = new SimpleLiveString(file.name);
31
+		this.name = new SimpleLiveString(file.getFilename());
35
 	}
32
 	}
36
 
33
 
37
 	@Override
34
 	@Override
40
 	}
37
 	}
41
 
38
 
42
 	@Override
39
 	@Override
43
-	public Reader read() throws IOException {
44
-		return new InputStreamReader(
45
-				new BufferedInputStream(new FileInputStream(file.file)),
46
-				StandardCharsets.UTF_8);
40
+	public SourceFile getFile() {
41
+		return file;
47
 	}
42
 	}
48
 
43
 
49
 	@Override
44
 	@Override
50
 	public void update(String content) {
45
 	public void update(String content) {
51
 		try {
46
 		try {
52
-			Writer writer = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(file.file)), StandardCharsets.UTF_8);
53
-			writer.write(content);
54
-			writer.close();
47
+			if (file instanceof FileSourceFile) {
48
+				Writer writer = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(((FileSourceFile)file).file)), StandardCharsets.UTF_8);
49
+				writer.write(content);
50
+				writer.close();
51
+			} else {
52
+				throw new UnsupportedOperationException("Cannot write to a non-file source file!");
53
+			}
55
 		} catch (IOException ex) {
54
 		} catch (IOException ex) {
56
 			ex.printStackTrace();
55
 			ex.printStackTrace();
57
 		}
56
 		}

+ 5
- 5
IDE/src/main/java/org/openzen/zenscript/ide/host/local/LocalTarget.java View File

133
 				continue;
133
 				continue;
134
 			
134
 			
135
 			SemanticModule dependencyModule = loader.getModule(dependency);
135
 			SemanticModule dependencyModule = loader.getModule(dependency);
136
-			module = module.normalize();
137
-			module.validate(logger);
138
-			if (!module.isValid())
136
+			dependencyModule = dependencyModule.normalize();
137
+			dependencyModule.validate(logger);
138
+			if (!dependencyModule.isValid())
139
 				return false;
139
 				return false;
140
 			
140
 			
141
 			if (!compileDependencies(loader, compiler, compiledModules, dependencyModule, logger))
141
 			if (!compileDependencies(loader, compiler, compiledModules, dependencyModule, logger))
142
 				return false;
142
 				return false;
143
 			
143
 			
144
-			module.compile(compiler);
145
-			compiledModules.add(module.name);
144
+			dependencyModule.compile(compiler);
145
+			compiledModules.add(dependencyModule.name);
146
 		}
146
 		}
147
 		
147
 		
148
 		return true;
148
 		return true;

+ 48
- 0
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/editor/PathGenerator.java View File

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.ui.view.editor;
7
+
8
+import org.openzen.drawablegui.DPath;
9
+
10
+/**
11
+ *
12
+ * @author Hoofdgebruiker
13
+ */
14
+public class PathGenerator {
15
+	private PathGenerator() {}
16
+	
17
+	public static class CubicBezierCurve {
18
+		public final float p1x;
19
+		public final float p1y;
20
+		public final float p2x;
21
+		public final float p2y;
22
+		public final float p3x;
23
+		public final float p3y;
24
+		public final float p4x;
25
+		public final float p4y;
26
+		
27
+		public CubicBezierCurve(float p1x, float p1y, float p2x, float p2y, float p3x, float p3y, float p4x, float p4y) {
28
+			this.p1x = p1x;
29
+			this.p1y = p1y;
30
+			this.p2x = p2x;
31
+			this.p2y = p2y;
32
+			this.p3x = p3x;
33
+			this.p3y = p3y;
34
+			this.p4x = p4x;
35
+			this.p4y = p4y;
36
+		}
37
+		
38
+		public void cut(float t0, float t1) {
39
+			// https://stackoverflow.com/questions/11703283/cubic-bezier-curve-segment
40
+			// P'1 = u0u0u0 P1 + (t0u0u0 + u0t0u0 + u0u0t0) P2 + (t0t0u0 + u0t0t0 + t0u0t0) P3 + t0t0t0 P4
41
+			// P'2 = u0u0u1 P1 + (t0u0u1 + u0t0u1 + u0u0t1) P2 + (t0t0u1 + u0t0t1 + t0u0t1) P3 + t0t0t1 P4
42
+			// P'3 = u0u1u1 P1 + (t0u1u1 + u0t1u1 + u0u1t1) P2 + (t0t1u1 + u0t1t1 + t0u1t1) P3 + t0t1t1 P4
43
+			// P'4 = u1u1u1 P1 + (t1u1u1 + u1t1u1 + u1u1t1) P2 + (t1t1u1 + u1t1t1 + t1u1t1) P3 + t1t1t1 P4
44
+			// u0 = 1 − t0 and u1 = 1 − t1
45
+			
46
+		}
47
+	}
48
+}

+ 39
- 24
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/editor/SourceEditor.java View File

6
 package org.openzen.zenscript.ide.ui.view.editor;
6
 package org.openzen.zenscript.ide.ui.view.editor;
7
 
7
 
8
 import java.io.IOException;
8
 import java.io.IOException;
9
+import java.io.Reader;
9
 import java.util.ArrayList;
10
 import java.util.ArrayList;
10
 import java.util.List;
11
 import java.util.List;
11
 import org.openzen.drawablegui.DComponent;
12
 import org.openzen.drawablegui.DComponent;
29
 import org.openzen.zenscript.lexer.ZSTokenParser;
30
 import org.openzen.zenscript.lexer.ZSTokenParser;
30
 import org.openzen.zenscript.lexer.ZSTokenType;
31
 import org.openzen.zenscript.lexer.ZSTokenType;
31
 import org.openzen.drawablegui.DUIContext;
32
 import org.openzen.drawablegui.DUIContext;
33
+import org.openzen.drawablegui.Destructible;
32
 import org.openzen.drawablegui.draw.DDrawSurface;
34
 import org.openzen.drawablegui.draw.DDrawSurface;
33
 import org.openzen.drawablegui.draw.DDrawnRectangle;
35
 import org.openzen.drawablegui.draw.DDrawnRectangle;
34
 import org.openzen.drawablegui.draw.DDrawnShape;
36
 import org.openzen.drawablegui.draw.DDrawnShape;
95
 	private final List<DDrawnText> lineNumbers = new ArrayList<>();
97
 	private final List<DDrawnText> lineNumbers = new ArrayList<>();
96
 	private final List<List<DDrawnText>> drawnTokens = new ArrayList<>();
98
 	private final List<List<DDrawnText>> drawnTokens = new ArrayList<>();
97
 	
99
 	
100
+	//private DDrawnShape test;
101
+	
98
 	public SourceEditor(DStyleClass styleClass, IDEWindow window, IDESourceFile sourceFile) {
102
 	public SourceEditor(DStyleClass styleClass, IDEWindow window, IDESourceFile sourceFile) {
99
 		this.styleClass = styleClass;
103
 		this.styleClass = styleClass;
100
 		this.window = window;
104
 		this.window = window;
101
 		this.sourceFile = sourceFile;
105
 		this.sourceFile = sourceFile;
102
 		
106
 		
103
-		tokens = new TokenModel(sourceFile.getName().getValue(), tab.length());
107
+		tokens = new TokenModel(sourceFile.getFile(), tab.length());
104
 		tokenListener = tokens.addListener(new TokenListener());
108
 		tokenListener = tokens.addListener(new TokenListener());
105
 		
109
 		
106
 		editToolbar.controls.add(() -> new IconButtonControl(DStyleClass.EMPTY, ShadedSaveIcon.PURPLE, SaveIcon.GREY, unchanged, new ImmutableLiveString("Save file"), e -> save()));
110
 		editToolbar.controls.add(() -> new IconButtonControl(DStyleClass.EMPTY, ShadedSaveIcon.PURPLE, SaveIcon.GREY, unchanged, new ImmutableLiveString("Save file"), e -> save()));
107
 		updated = new InverseLiveBool(unchanged);
111
 		updated = new InverseLiveBool(unchanged);
108
 		
112
 		
109
 		try {
113
 		try {
114
+			Reader reader = sourceFile.getFile().open();
110
 			TokenParser<ZSToken, ZSTokenType> parser = ZSTokenParser.createRaw(
115
 			TokenParser<ZSToken, ZSTokenType> parser = ZSTokenParser.createRaw(
111
-					sourceFile.getName().getValue(),
112
-					new ReaderCharReader(sourceFile.read()),
116
+					sourceFile.getFile(),
117
+					new ReaderCharReader(reader),
113
 					tab.length());
118
 					tab.length());
114
 			tokens.set(parser);
119
 			tokens.set(parser);
120
+			reader.close();
115
 		} catch (IOException ex) {
121
 		} catch (IOException ex) {
116
 			ex.printStackTrace();
122
 			ex.printStackTrace();
117
 		}
123
 		}
188
 			cursor = null;
194
 			cursor = null;
189
 		}
195
 		}
190
 		
196
 		
197
+		/*if (test != null) {
198
+			test.close();
199
+			test = null;
200
+		}*/
201
+		
191
 		if (blinkTimer != null)
202
 		if (blinkTimer != null)
192
 			blinkTimer.close();
203
 			blinkTimer.close();
193
 		
204
 		
251
 					bounds.y + style.selectionPaddingTop + i * fullLineHeight + fontMetrics.getAscent());
262
 					bounds.y + style.selectionPaddingTop + i * fullLineHeight + fontMetrics.getAscent());
252
 		}
263
 		}
253
 		
264
 		
265
+		//test = surface.strokePath(z + 4, new WavyLine(bounds.x + 50, bounds.y + 50, 100, surface.getContext().dp(2), surface.getContext().dp(3)), DTransform2D.IDENTITY, IDEStyling.ERROR_RED, surface.getScale());
266
+		
254
 		layoutLines(0);
267
 		layoutLines(0);
255
 	}
268
 	}
256
 	
269
 	
287
 		}
300
 		}
288
 	}
301
 	}
289
 	
302
 	
303
+	private void setCursor(SourcePosition position) {
304
+		setCursor(position, position);
305
+	}
306
+	
290
 	private void setCursor(SourcePosition start, SourcePosition end) {
307
 	private void setCursor(SourcePosition start, SourcePosition end) {
291
 		cursorStart = start;
308
 		cursorStart = start;
292
 		cursorEnd = end;
309
 		cursorEnd = end;
563
 		if (value.equals("{")) {
580
 		if (value.equals("{")) {
564
 			String indent = tokens.getLine(cursorEnd.line).getIndent();
581
 			String indent = tokens.getLine(cursorEnd.line).getIndent();
565
 			tokens.insert(cursorEnd, "{\n" + indent + "\t\n" + indent + "}");
582
 			tokens.insert(cursorEnd, "{\n" + indent + "\t\n" + indent + "}");
566
-			
567
-			SourcePosition position = new SourcePosition(tokens, cursorEnd.line + 1, indent.length() + 1);
568
-			setCursor(position, position);
569
-		} else if (value.equals(";")) {
570
-			String indent = tokens.getLine(cursorEnd.line).getIndent();
571
-			tokens.insert(cursorEnd, ";\n" + indent);
572
-			
573
-			SourcePosition position = new SourcePosition(tokens, cursorEnd.line + 1, indent.length());
574
-			setCursor(position, position);
583
+			setCursor(new SourcePosition(tokens, cursorEnd.line + 1, indent.length() + 1));
584
+		} else if (value.equals("\"")) {
585
+			if (!tokens.extract(cursorEnd, cursorEnd.advance(1)).equals("\""))
586
+				tokens.insert(cursorEnd, "\"\"");
587
+			setCursor(cursorEnd.advance(1));
588
+		} else if (value.equals("(")) {
589
+			tokens.insert(cursorEnd, "()");
590
+			setCursor(cursorEnd.advance(1));
591
+		} else if (value.equals(")") && tokens.extract(cursorEnd, cursorEnd.advance(1)).equals(")")){
592
+			setCursor(cursorEnd.advance(1));
593
+		} else if (value.equals("[")) {
594
+			tokens.insert(cursorEnd, "[]");
595
+			setCursor(cursorEnd.advance(1));
596
+		} else if (value.equals("]") && tokens.extract(cursorEnd, cursorEnd.advance(1)).equals("]")) {
597
+			setCursor(cursorEnd.advance(1));
575
 		} else {
598
 		} else {
576
 			tokens.insert(cursorEnd, value);
599
 			tokens.insert(cursorEnd, value);
577
-			
578
-			SourcePosition position = new SourcePosition(tokens, cursorEnd.line, cursorEnd.offset + value.length());
579
-			setCursor(position, position);
600
+			setCursor(cursorEnd.advance(value.length()));
580
 		}
601
 		}
581
 		
602
 		
582
 		unchanged.setValue(false);
603
 		unchanged.setValue(false);
734
 		@Override
755
 		@Override
735
 		public void onLineChanged(int index) {
756
 		public void onLineChanged(int index) {
736
 			if (bounds != null) {
757
 			if (bounds != null) {
737
-				removeLineTokens(drawnTokens.get(index));
738
-				drawnTokens.get(index).clear();
739
-				drawnTokens.get(index).addAll(lineToTokens(tokens.getLine(index)));
758
+				Destructible.close(drawnTokens.get(index));
759
+				drawnTokens.set(index, lineToTokens(tokens.getLine(index)));
740
 				layoutLine(index);
760
 				layoutLine(index);
741
 			}
761
 			}
742
 		}
762
 		}
750
 			
770
 			
751
 			if (bounds != null) {
771
 			if (bounds != null) {
752
 				lineNumbers.remove(lineNumbers.size() - 1).close();
772
 				lineNumbers.remove(lineNumbers.size() - 1).close();
753
-				removeLineTokens(drawnTokens.remove(index));
773
+				Destructible.close(drawnTokens.remove(index));
754
 				layoutLines(index);
774
 				layoutLines(index);
755
 			}
775
 			}
756
 		}
776
 		}
757
-		
758
-		private void removeLineTokens(List<DDrawnText> tokens) {
759
-			for (DDrawnText token : tokens)
760
-				token.close();
761
-		}
762
 	}
777
 	}
763
 	
778
 	
764
 	private enum TokenClass {
779
 	private enum TokenClass {

+ 6
- 4
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/editor/TokenModel.java View File

13
 import java.util.Set;
13
 import java.util.Set;
14
 import org.openzen.drawablegui.listeners.ListenerHandle;
14
 import org.openzen.drawablegui.listeners.ListenerHandle;
15
 import org.openzen.drawablegui.listeners.ListenerList;
15
 import org.openzen.drawablegui.listeners.ListenerList;
16
+import org.openzen.zencode.shared.SourceFile;
16
 import org.openzen.zenscript.lexer.ZSToken;
17
 import org.openzen.zenscript.lexer.ZSToken;
17
 import org.openzen.zenscript.lexer.ZSTokenType;
18
 import org.openzen.zenscript.lexer.ZSTokenType;
18
 
19
 
23
 public class TokenModel {
24
 public class TokenModel {
24
 	private final ListenerList<Listener> listeners = new ListenerList<>();
25
 	private final ListenerList<Listener> listeners = new ListenerList<>();
25
 	
26
 	
26
-	private final String filename;
27
+	private final SourceFile file;
27
 	private final int spacesPerTab;
28
 	private final int spacesPerTab;
28
 	private final List<TokenLine> lines = new ArrayList<>();
29
 	private final List<TokenLine> lines = new ArrayList<>();
29
 	private long version = 0;
30
 	private long version = 0;
30
 	
31
 	
31
-	public TokenModel(String filename, int spacesPerTab) {
32
-		this.filename = filename;
32
+	public TokenModel(SourceFile file, int spacesPerTab) {
33
+		this.file = file;
33
 		this.spacesPerTab = spacesPerTab;
34
 		this.spacesPerTab = spacesPerTab;
34
 	}
35
 	}
35
 	
36
 	
210
 	}
211
 	}
211
 	
212
 	
212
 	private void relex(int fromLine, int fromToken, int toLine, int toToken) {
213
 	private void relex(int fromLine, int fromToken, int toLine, int toToken) {
213
-		TokenRelexer reparser = new TokenRelexer(filename, lines, fromLine, fromToken, toLine, toToken, spacesPerTab);
214
+		TokenRelexer reparser = new TokenRelexer(file, lines, fromLine, fromToken, toLine, toToken, spacesPerTab);
214
 		List<ZSToken> tokens = reparser.relex();
215
 		List<ZSToken> tokens = reparser.relex();
215
 		replaceTokens(fromLine, fromToken, reparser.getLine(), reparser.getToken(), tokens);
216
 		replaceTokens(fromLine, fromToken, reparser.getLine(), reparser.getToken(), tokens);
216
 	}
217
 	}
257
 		TokenLine currentLine = lines.get(line);
258
 		TokenLine currentLine = lines.get(line);
258
 		Set<Integer> insertedLines = new HashSet<>();
259
 		Set<Integer> insertedLines = new HashSet<>();
259
 		Set<Integer> modifiedLines = new HashSet<>();
260
 		Set<Integer> modifiedLines = new HashSet<>();
261
+		modifiedLines.add(line);
260
 		while (tokens.hasNext()) {
262
 		while (tokens.hasNext()) {
261
 			ZSToken token = tokens.next();
263
 			ZSToken token = tokens.next();
262
 			if (token.type.multiline && token.content.indexOf('\n') >= 0) {
264
 			if (token.type.multiline && token.content.indexOf('\n') >= 0) {

+ 5
- 4
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/editor/TokenRelexer.java View File

8
 import java.io.IOException;
8
 import java.io.IOException;
9
 import java.util.ArrayList;
9
 import java.util.ArrayList;
10
 import java.util.List;
10
 import java.util.List;
11
+import org.openzen.zencode.shared.SourceFile;
11
 import org.openzen.zenscript.lexer.CharReader;
12
 import org.openzen.zenscript.lexer.CharReader;
12
 import org.openzen.zenscript.lexer.TokenParser;
13
 import org.openzen.zenscript.lexer.TokenParser;
13
 import org.openzen.zenscript.lexer.ZSToken;
14
 import org.openzen.zenscript.lexer.ZSToken;
20
  */
21
  */
21
 public class TokenRelexer {
22
 public class TokenRelexer {
22
 	private final List<TokenLine> lines;
23
 	private final List<TokenLine> lines;
23
-	private final String filename;
24
+	private final SourceFile file;
24
 	private final int toLine;
25
 	private final int toLine;
25
 	private final int toToken;
26
 	private final int toToken;
26
 	private final int spacesPerTab;
27
 	private final int spacesPerTab;
28
 	private int lineIndex;
29
 	private int lineIndex;
29
 	private int token;
30
 	private int token;
30
 	
31
 	
31
-	public TokenRelexer(String filename, List<TokenLine> lines, int fromLine, int fromToken, int toLine, int toToken, int spacesPerTab) {
32
+	public TokenRelexer(SourceFile file, List<TokenLine> lines, int fromLine, int fromToken, int toLine, int toToken, int spacesPerTab) {
32
 		if (fromToken < 0 || toToken < 0)
33
 		if (fromToken < 0 || toToken < 0)
33
 			throw new IllegalArgumentException("fromToken or toToken cannot be < 0");
34
 			throw new IllegalArgumentException("fromToken or toToken cannot be < 0");
34
 		
35
 		
35
 		this.lines = lines;
36
 		this.lines = lines;
36
-		this.filename = filename;
37
+		this.file = file;
37
 		this.toLine = toLine;
38
 		this.toLine = toLine;
38
 		this.toToken = toToken;
39
 		this.toToken = toToken;
39
 		
40
 		
44
 	
45
 	
45
 	public List<ZSToken> relex() {
46
 	public List<ZSToken> relex() {
46
 		RelexCharReader reader = new RelexCharReader();
47
 		RelexCharReader reader = new RelexCharReader();
47
-		TokenParser<ZSToken, ZSTokenType> reparser = ZSTokenParser.createRaw(filename, reader, spacesPerTab);
48
+		TokenParser<ZSToken, ZSTokenType> reparser = ZSTokenParser.createRaw(file, reader, spacesPerTab);
48
 		List<ZSToken> result = new ArrayList<>();
49
 		List<ZSToken> result = new ArrayList<>();
49
 		while ((lineIndex < toLine || token < toToken || !reader.isAtTokenBoundary()) && reparser.hasNext())
50
 		while ((lineIndex < toLine || token < toToken || !reader.isAtTokenBoundary()) && reparser.hasNext())
50
 			result.add(reparser.next());
51
 			result.add(reparser.next());

+ 47
- 0
IDE/src/main/java/org/openzen/zenscript/ide/ui/view/editor/WavyLine.java View File

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.ui.view.editor;
7
+
8
+import org.openzen.drawablegui.DPath;
9
+import org.openzen.drawablegui.DPathTracer;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public class WavyLine implements DPath {
16
+	private final int x;
17
+	private final int y;
18
+	private final int width;
19
+	private final int height;
20
+	private final float stride;
21
+	
22
+	public WavyLine(int x, int y, int width, int height, float stride) {
23
+		this.x = x;
24
+		this.y = y;
25
+		this.width = width;
26
+		this.height = height;
27
+		this.stride = stride;
28
+	}
29
+	
30
+	@Override
31
+	public void trace(DPathTracer tracer) {
32
+		tracer.moveTo(x, y);
33
+		for (int i = 0; i < (width / stride); i++) {
34
+			if ((i % 2) == 0) {
35
+				tracer.bezierCubic(
36
+						x + (i + 0.5f) * stride, y,
37
+						x + (i + 0.5f) * stride, y + height,
38
+						x + (i + 1) * stride, y + height);
39
+			} else {
40
+				tracer.bezierCubic(
41
+						x + (i + 0.5f) * stride, y + height,
42
+						x + (i + 0.5f) * stride, y,
43
+						x + (i + 1) * stride, y);
44
+			}
45
+		}
46
+	}
47
+}

+ 1
- 1
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaCompiler.java View File

56
 	@Override
56
 	@Override
57
 	public void addScriptBlock(ScriptBlock script) {
57
 	public void addScriptBlock(ScriptBlock script) {
58
 		final SourceFile sourceFile = script.getTag(SourceFile.class);
58
 		final SourceFile sourceFile = script.getTag(SourceFile.class);
59
-		final String className = getClassName(sourceFile == null ? null : sourceFile.filename);
59
+		final String className = getClassName(sourceFile == null ? null : sourceFile.getFilename());
60
 		JavaScriptFile scriptFile = getScriptFile(className);
60
 		JavaScriptFile scriptFile = getScriptFile(className);
61
 		
61
 		
62
 		String methodName = scriptFile.scriptMethods.isEmpty() ? "run" : "run" + scriptFile.scriptMethods.size();
62
 		String methodName = scriptFile.scriptMethods.isEmpty() ? "run" : "run" + scriptFile.scriptMethods.size();

+ 2
- 0
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/BaseMemberCompiler.java View File

75
 			output.append("protected ");
75
 			output.append("protected ");
76
 		if (Modifiers.isPrivate(modifiers))
76
 		if (Modifiers.isPrivate(modifiers))
77
 			output.append("private ");
77
 			output.append("private ");
78
+		if (Modifiers.isAbstract(modifiers))
79
+			output.append("abstract ");
78
 		if (Modifiers.isStatic(modifiers))
80
 		if (Modifiers.isStatic(modifiers))
79
 			output.append("static ");
81
 			output.append("static ");
80
 		if (Modifiers.isFinal(modifiers))
82
 		if (Modifiers.isFinal(modifiers))

+ 2
- 2
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaDefinitionVisitor.java View File

86
 		}
86
 		}
87
 		
87
 		
88
 		if (mergedImplementations.size() > 0) {
88
 		if (mergedImplementations.size() > 0) {
89
-			output.append("implements ");
89
+			output.append(" implements ");
90
 			for (int i = 0; i < mergedImplementations.size(); i++) {
90
 			for (int i = 0; i < mergedImplementations.size(); i++) {
91
 				if (i > 0)
91
 				if (i > 0)
92
 					output.append(", ");
92
 					output.append(", ");
289
 			output.append("static ");
289
 			output.append("static ");
290
 		if (Modifiers.isAbstract(modifiers))
290
 		if (Modifiers.isAbstract(modifiers))
291
 			output.append("abstract ");
291
 			output.append("abstract ");
292
-		if (!Modifiers.isVirtual(modifiers))
292
+		if (!Modifiers.isVirtual(modifiers) && !Modifiers.isAbstract(modifiers))
293
 			output.append("final ");
293
 			output.append("final ");
294
 	}
294
 	}
295
 	
295
 	

+ 2
- 2
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceCompiler.java View File

93
 	private String getFilename(HighLevelDefinition definition) {
93
 	private String getFilename(HighLevelDefinition definition) {
94
 		SourceFile source = definition.getTag(SourceFile.class);
94
 		SourceFile source = definition.getTag(SourceFile.class);
95
 		if (source != null) {
95
 		if (source != null) {
96
-			int slash = Math.max(source.filename.lastIndexOf('/'), source.filename.lastIndexOf('\\'));
97
-			String filename = source.filename.substring(slash < 0 ? 0 : slash + 1);
96
+			int slash = Math.max(source.getFilename().lastIndexOf('/'), source.getFilename().lastIndexOf('\\'));
97
+			String filename = source.getFilename().substring(slash < 0 ? 0 : slash + 1);
98
 			filename = filename.substring(0, filename.lastIndexOf('.'));
98
 			filename = filename.substring(0, filename.lastIndexOf('.'));
99
 			return filename;
99
 			return filename;
100
 		} else {
100
 		} else {

+ 0
- 1
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceTypeVisitor.java View File

21
 import org.openzen.zenscript.codemodel.type.OptionalTypeID;
21
 import org.openzen.zenscript.codemodel.type.OptionalTypeID;
22
 import org.openzen.zenscript.codemodel.type.RangeTypeID;
22
 import org.openzen.zenscript.codemodel.type.RangeTypeID;
23
 import org.openzen.zenscript.javasource.tags.JavaSourceClass;
23
 import org.openzen.zenscript.javasource.tags.JavaSourceClass;
24
-import org.openzen.zenscript.javasource.tags.JavaSourceMethod;
25
 
24
 
26
 /**
25
 /**
27
  *
26
  *

+ 24
- 1
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/prepare/JavaSourcePrepareDefinitionVisitor.java View File

22
 import org.openzen.zenscript.codemodel.expression.CastExpression;
22
 import org.openzen.zenscript.codemodel.expression.CastExpression;
23
 import org.openzen.zenscript.codemodel.expression.Expression;
23
 import org.openzen.zenscript.codemodel.expression.Expression;
24
 import org.openzen.zenscript.codemodel.member.IDefinitionMember;
24
 import org.openzen.zenscript.codemodel.member.IDefinitionMember;
25
-import org.openzen.zenscript.codemodel.type.ArrayTypeID;
26
 import org.openzen.zenscript.formattershared.ExpressionString;
25
 import org.openzen.zenscript.formattershared.ExpressionString;
27
 import org.openzen.zenscript.javasource.JavaOperator;
26
 import org.openzen.zenscript.javasource.JavaOperator;
28
 import org.openzen.zenscript.javasource.tags.JavaSourceClass;
27
 import org.openzen.zenscript.javasource.tags.JavaSourceClass;
168
 			cls.addConstructor("constructorWithCause", "");
167
 			cls.addConstructor("constructorWithCause", "");
169
 			nativeClasses.put("stdlib::Exception", cls);
168
 			nativeClasses.put("stdlib::Exception", cls);
170
 		}
169
 		}
170
+		
171
+		{
172
+			JavaNativeClass cls = new JavaNativeClass(new JavaSourceClass("java.io", "IOException"));
173
+			cls.addConstructor("constructor", "");
174
+			nativeClasses.put("io::IOException", cls);
175
+		}
176
+		
177
+		{
178
+			JavaNativeClass cls = new JavaNativeClass(new JavaSourceClass("java.io", "Reader"));
179
+			cls.addInstanceMethod("destruct", "close");
180
+			cls.addInstanceMethod("readCharacter", "read");
181
+			cls.addInstanceMethod("readArray", "read");
182
+			cls.addInstanceMethod("readArraySlice", "read");
183
+			nativeClasses.put("io::Reader", cls);
184
+		}
185
+		
186
+		{
187
+			JavaNativeClass cls = new JavaNativeClass(new JavaSourceClass("java.io", "StringReader"));
188
+			cls.addInstanceMethod("constructor", "");
189
+			cls.addInstanceMethod("destructor", "close");
190
+			cls.addInstanceMethod("readCharacter", "read");
191
+			cls.addInstanceMethod("readSlice", "read");
192
+			nativeClasses.put("io::StringReader", cls);
193
+		}
171
 	}
194
 	}
172
 	
195
 	
173
 	private final String filename;
196
 	private final String filename;

+ 11
- 3
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/prepare/JavaSourcePrepareExpansionMethodVisitor.java View File

17
 import org.openzen.zenscript.codemodel.member.DestructorMember;
17
 import org.openzen.zenscript.codemodel.member.DestructorMember;
18
 import org.openzen.zenscript.codemodel.member.FieldMember;
18
 import org.openzen.zenscript.codemodel.member.FieldMember;
19
 import org.openzen.zenscript.codemodel.member.GetterMember;
19
 import org.openzen.zenscript.codemodel.member.GetterMember;
20
+import org.openzen.zenscript.codemodel.member.IDefinitionMember;
20
 import org.openzen.zenscript.codemodel.member.ImplementationMember;
21
 import org.openzen.zenscript.codemodel.member.ImplementationMember;
21
 import org.openzen.zenscript.codemodel.member.InnerDefinitionMember;
22
 import org.openzen.zenscript.codemodel.member.InnerDefinitionMember;
22
 import org.openzen.zenscript.codemodel.member.MemberVisitor;
23
 import org.openzen.zenscript.codemodel.member.MemberVisitor;
27
 import org.openzen.zenscript.javasource.JavaSourceTypeNameVisitor;
28
 import org.openzen.zenscript.javasource.JavaSourceTypeNameVisitor;
28
 import org.openzen.zenscript.javasource.tags.JavaSourceClass;
29
 import org.openzen.zenscript.javasource.tags.JavaSourceClass;
29
 import org.openzen.zenscript.javasource.tags.JavaSourceField;
30
 import org.openzen.zenscript.javasource.tags.JavaSourceField;
31
+import org.openzen.zenscript.javasource.tags.JavaSourceImplementation;
30
 import org.openzen.zenscript.javasource.tags.JavaSourceMethod;
32
 import org.openzen.zenscript.javasource.tags.JavaSourceMethod;
31
 
33
 
32
 /**
34
 /**
54
 	public Void visitField(FieldMember member) {
56
 	public Void visitField(FieldMember member) {
55
 		// TODO: expansion fields
57
 		// TODO: expansion fields
56
 		member.setTag(JavaSourceField.class, new JavaSourceField(cls, member.name));
58
 		member.setTag(JavaSourceField.class, new JavaSourceField(cls, member.name));
57
-		cls.empty = false;
59
+		if (member.hasAutoGetter() || member.hasAutoSetter())
60
+			cls.empty = false;
58
 		return null;
61
 		return null;
59
 	}
62
 	}
60
 
63
 
66
 
69
 
67
 	@Override
70
 	@Override
68
 	public Void visitDestructor(DestructorMember member) {
71
 	public Void visitDestructor(DestructorMember member) {
69
-		throw new UnsupportedOperationException("Destructors not allowed on expansions");
72
+		visitFunctional(member, "");
73
+		return null;
70
 	}
74
 	}
71
 
75
 
72
 	@Override
76
 	@Override
114
 	@Override
118
 	@Override
115
 	public Void visitImplementation(ImplementationMember member) {
119
 	public Void visitImplementation(ImplementationMember member) {
116
 		// TODO: implementation merge check
120
 		// TODO: implementation merge check
117
-		cls.empty = false;
121
+		//cls.empty = false; -> TODO: 
122
+		member.setTag(JavaSourceImplementation.class, new JavaSourceImplementation(false));
123
+		for (IDefinitionMember implementedMember : member.members)
124
+			implementedMember.accept(this);
125
+		
118
 		return null;
126
 		return null;
119
 	}
127
 	}
120
 
128
 

+ 20
- 0
JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/tags/JavaSourceImplementation.java View File

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.tags;
7
+
8
+/**
9
+ *
10
+ * @author Hoofdgebruiker
11
+ */
12
+public class JavaSourceImplementation {
13
+	public boolean inline = true;
14
+	
15
+	public JavaSourceImplementation() {}
16
+	
17
+	public JavaSourceImplementation(boolean inline) {
18
+		this.inline = inline;
19
+	}
20
+}

+ 6
- 5
Parser/src/main/java/org/openzen/zenscript/lexer/CountingCharReader.java View File

2
 
2
 
3
 import java.io.IOException;
3
 import java.io.IOException;
4
 import org.openzen.zencode.shared.CodePosition;
4
 import org.openzen.zencode.shared.CodePosition;
5
+import org.openzen.zencode.shared.SourceFile;
5
 
6
 
6
 /*
7
 /*
7
  * To change this license header, choose License Headers in Project Properties.
8
  * To change this license header, choose License Headers in Project Properties.
15
  */
16
  */
16
 public class CountingCharReader implements CharReader {
17
 public class CountingCharReader implements CharReader {
17
 	private final CharReader reader;
18
 	private final CharReader reader;
18
-	private final String filename;
19
+	private final SourceFile file;
19
 	private final int tabSize;
20
 	private final int tabSize;
20
 	
21
 	
21
 	private int line;
22
 	private int line;
22
 	private int lineOffset;
23
 	private int lineOffset;
23
-
24
-	public CountingCharReader(CharReader reader, String filename, int tabSize)
24
+	
25
+	public CountingCharReader(CharReader reader, SourceFile file, int tabSize)
25
 	{
26
 	{
26
 		this.reader = reader;
27
 		this.reader = reader;
27
-		this.filename = filename;
28
+		this.file = file;
28
 		this.tabSize = tabSize;
29
 		this.tabSize = tabSize;
29
 		
30
 		
30
 		line = 1;
31
 		line = 1;
32
 	}
33
 	}
33
 	
34
 	
34
 	public CodePosition getPosition() {
35
 	public CodePosition getPosition() {
35
-		return new CodePosition(filename, line, lineOffset, line, lineOffset);
36
+		return new CodePosition(file, line, lineOffset, line, lineOffset);
36
 	}
37
 	}
37
 
38
 
38
 	@Override
39
 	@Override

+ 7
- 6
Parser/src/main/java/org/openzen/zenscript/lexer/TokenParser.java View File

6
 import org.openzen.zencode.shared.CodePosition;
6
 import org.openzen.zencode.shared.CodePosition;
7
 import org.openzen.zencode.shared.CompileException;
7
 import org.openzen.zencode.shared.CompileException;
8
 import org.openzen.zencode.shared.CompileExceptionCode;
8
 import org.openzen.zencode.shared.CompileExceptionCode;
9
+import org.openzen.zencode.shared.SourceFile;
9
 
10
 
10
 /**
11
 /**
11
  * Represents a token stream. A token stream reads characters from a reader and
12
  * Represents a token stream. A token stream reads characters from a reader and
28
     /**
29
     /**
29
      * Creates a token stream using the specified reader and DFA.
30
      * Creates a token stream using the specified reader and DFA.
30
      *
31
      *
31
-	 * @param filename filename
32
+	 * @param file filename
32
      * @param reader reader to read characters from
33
      * @param reader reader to read characters from
33
      * @param dfa DFA to tokenize the stream
34
      * @param dfa DFA to tokenize the stream
34
 	 * @param eof end of file token type
35
 	 * @param eof end of file token type
35
      */
36
      */
36
     public TokenParser(
37
     public TokenParser(
37
-			String filename,
38
+			SourceFile file,
38
 			CharReader reader, 
39
 			CharReader reader, 
39
 			CompiledDFA<TT> dfa,
40
 			CompiledDFA<TT> dfa,
40
 			TT eof,
41
 			TT eof,
44
 		if (eof.isWhitespace()) // important for the advance() method
45
 		if (eof.isWhitespace()) // important for the advance() method
45
 			throw new IllegalArgumentException("EOF cannot be whitespace");
46
 			throw new IllegalArgumentException("EOF cannot be whitespace");
46
 		
47
 		
47
-        this.reader = new CountingCharReader(reader, filename, 4);
48
+        this.reader = new CountingCharReader(reader, file, 4);
48
         this.dfa = dfa;
49
         this.dfa = dfa;
49
 		this.eof = eof;
50
 		this.eof = eof;
50
 		this.invalid = invalid;
51
 		this.invalid = invalid;
54
     /**
55
     /**
55
      * Creates a token stream which reads data from the specified string.
56
      * Creates a token stream which reads data from the specified string.
56
      *
57
      *
57
-	 * @param filename filename
58
+	 * @param file filename
58
      * @param data data to read
59
      * @param data data to read
59
      * @param dfa DFA to tokenize the stream
60
      * @param dfa DFA to tokenize the stream
60
 	 * @param eof end of file token type
61
 	 * @param eof end of file token type
61
      */
62
      */
62
-    public TokenParser(String filename, String data, CompiledDFA<TT> dfa, TT eof, TT invalid, TokenFactory<T, TT> factory)
63
+    public TokenParser(SourceFile file, String data, CompiledDFA<TT> dfa, TT eof, TT invalid, TokenFactory<T, TT> factory)
63
 	{
64
 	{
64
-        this(filename, new StringCharReader(data), dfa, eof, invalid, factory);
65
+        this(file, new StringCharReader(data), dfa, eof, invalid, factory);
65
     }
66
     }
66
 	
67
 	
67
 	@Override
68
 	@Override

+ 7
- 6
Parser/src/main/java/org/openzen/zenscript/lexer/ZSTokenParser.java View File

7
 
7
 
8
 import java.io.IOException;
8
 import java.io.IOException;
9
 import java.io.Reader;
9
 import java.io.Reader;
10
+import org.openzen.zencode.shared.SourceFile;
10
 import org.openzen.zenscript.codemodel.WhitespaceInfo;
11
 import org.openzen.zenscript.codemodel.WhitespaceInfo;
11
 
12
 
12
 /**
13
 /**
16
 public class ZSTokenParser extends LLParserTokenStream<ZSTokenType, ZSToken> {
17
 public class ZSTokenParser extends LLParserTokenStream<ZSTokenType, ZSToken> {
17
 	private static final CompiledDFA DFA = CompiledDFA.createLexerDFA(ZSTokenType.values(), ZSTokenType.class);
18
 	private static final CompiledDFA DFA = CompiledDFA.createLexerDFA(ZSTokenType.values(), ZSTokenType.class);
18
 	
19
 	
19
-	public static TokenParser<ZSToken, ZSTokenType> createRaw(String filename, CharReader reader, int spacesPerTab) {
20
+	public static TokenParser<ZSToken, ZSTokenType> createRaw(SourceFile file, CharReader reader, int spacesPerTab) {
20
 		return new TokenParser<>(
21
 		return new TokenParser<>(
21
-				filename,
22
+				file,
22
 				reader,
23
 				reader,
23
 				DFA,
24
 				DFA,
24
 				ZSTokenType.EOF,
25
 				ZSTokenType.EOF,
26
 				new ZSTokenFactory(spacesPerTab));
27
 				new ZSTokenFactory(spacesPerTab));
27
 	}
28
 	}
28
 	
29
 	
29
-	public static ZSTokenParser create(String filename, Reader reader, int spacesPerTab) throws IOException {
30
-		return new ZSTokenParser(createRaw(filename, new ReaderCharReader(reader), spacesPerTab));
30
+	public static ZSTokenParser create(SourceFile file, int spacesPerTab) throws IOException {
31
+		return new ZSTokenParser(createRaw(file, new ReaderCharReader(file.open()), spacesPerTab));
31
 	}
32
 	}
32
 	
33
 	
33
 	public ZSTokenParser(TokenStream<ZSTokenType, ZSToken> parser) {
34
 	public ZSTokenParser(TokenStream<ZSTokenType, ZSToken> parser) {
34
 		super(parser);
35
 		super(parser);
35
 	}
36
 	}
36
 	
37
 	
37
-	public String getFilename() {
38
-		return getPosition().filename;
38
+	public SourceFile getFile() {
39
+		return getPosition().file;
39
 	}
40
 	}
40
 	
41
 	
41
 	public WhitespaceInfo collectWhitespaceInfo(String whitespace, boolean skipLineBefore) {
42
 	public WhitespaceInfo collectWhitespaceInfo(String whitespace, boolean skipLineBefore) {

+ 14
- 17
Parser/src/main/java/org/openzen/zenscript/parser/ParsedFile.java View File

8
 import java.io.File;
8
 import java.io.File;
9
 import java.io.FileReader;
9
 import java.io.FileReader;
10
 import java.io.IOException;
10
 import java.io.IOException;
11
-import java.io.Reader;
12
-import java.io.StringReader;
13
 import java.util.ArrayList;
11
 import java.util.ArrayList;
14
 import java.util.List;
12
 import java.util.List;
15
 import java.util.Map;
13
 import java.util.Map;
16
 import org.openzen.zencode.shared.CodePosition;
14
 import org.openzen.zencode.shared.CodePosition;
17
 import org.openzen.zencode.shared.CompileException;
15
 import org.openzen.zencode.shared.CompileException;
18
 import org.openzen.zencode.shared.CompileExceptionCode;
16
 import org.openzen.zencode.shared.CompileExceptionCode;
17
+import org.openzen.zencode.shared.FileSourceFile;
18
+import org.openzen.zencode.shared.LiteralSourceFile;
19
 import org.openzen.zencode.shared.SourceFile;
19
 import org.openzen.zencode.shared.SourceFile;
20
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
20
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
21
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
21
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
42
  */
42
  */
43
 public class ParsedFile {
43
 public class ParsedFile {
44
 	public static ParsedFile parse(ZSPackage pkg, File file) throws IOException {
44
 	public static ParsedFile parse(ZSPackage pkg, File file) throws IOException {
45
-		String filename = file.toString();
46
-		try (FileReader reader = new FileReader(file)) {
47
-			return parse(pkg, filename, reader);
48
-		}
45
+		return parse(pkg, new FileSourceFile(file.getName(), file));
49
 	}
46
 	}
50
 	
47
 	
51
 	public static ParsedFile parse(ZSPackage pkg, String filename, String content) {
48
 	public static ParsedFile parse(ZSPackage pkg, String filename, String content) {
52
-		try (StringReader reader = new StringReader(content)) {
53
-			return parse(pkg, filename, reader);
49
+		try {
50
+			return parse(pkg, new LiteralSourceFile(filename, content));
54
 		} catch (IOException ex) {
51
 		} catch (IOException ex) {
55
-			throw new AssertionError(); // supposed to never happen in a StringReader
52
+			throw new AssertionError(); // shouldn't happen
56
 		}
53
 		}
57
 	}
54
 	}
58
 	
55
 	
59
-	public static ParsedFile parse(ZSPackage pkg, String filename, Reader reader) throws IOException {
60
-		ZSTokenParser tokens = ZSTokenParser.create(filename, reader, 4);
56
+	public static ParsedFile parse(ZSPackage pkg, SourceFile file) throws IOException {
57
+		ZSTokenParser tokens = ZSTokenParser.create(file, 4);
61
 		return parse(pkg, tokens);
58
 		return parse(pkg, tokens);
62
 	}
59
 	}
63
 	
60
 	
64
 	public static ParsedFile parse(ZSPackage pkg, ZSTokenParser tokens) {
61
 	public static ParsedFile parse(ZSPackage pkg, ZSTokenParser tokens) {
65
-		ParsedFile result = new ParsedFile(tokens.getFilename());
62
+		ParsedFile result = new ParsedFile(tokens.getFile());
66
 		ZSToken eof = null;
63
 		ZSToken eof = null;
67
 
64
 
68
 		while (true) {
65
 		while (true) {
124
 		return result;
121
 		return result;
125
 	}
122
 	}
126
 	
123
 	
127
-	public final String filename;
124
+	public final SourceFile file;
128
 	
125
 	
129
 	private final List<ParsedImport> imports = new ArrayList<>();
126
 	private final List<ParsedImport> imports = new ArrayList<>();
130
 	private final List<ParsedDefinition> definitions = new ArrayList<>();
127
 	private final List<ParsedDefinition> definitions = new ArrayList<>();
131
 	private final List<ParsedStatement> statements = new ArrayList<>();
128
 	private final List<ParsedStatement> statements = new ArrayList<>();
132
 	private WhitespacePostComment postComment = null;
129
 	private WhitespacePostComment postComment = null;
133
 	
130
 	
134
-	public ParsedFile(String filename) {
135
-		this.filename = filename;
131
+	public ParsedFile(SourceFile file) {
132
+		this.file = file;
136
 	}
133
 	}
137
 	
134
 	
138
 	public boolean hasErrors() {
135
 	public boolean hasErrors() {
145
 	
142
 	
146
 	public void listDefinitions(PackageDefinitions definitions) {
143
 	public void listDefinitions(PackageDefinitions definitions) {
147
 		for (ParsedDefinition definition : this.definitions) {
144
 		for (ParsedDefinition definition : this.definitions) {
148
-			definition.getCompiled().setTag(SourceFile.class, new SourceFile(filename));
145
+			definition.getCompiled().setTag(SourceFile.class, file);
149
 			definitions.add(definition.getCompiled());
146
 			definitions.add(definition.getCompiled());
150
 			definition.linkInnerTypes();
147
 			definition.linkInnerTypes();
151
 		}
148
 		}
204
 			}
201
 			}
205
 			
202
 			
206
 			ScriptBlock block = new ScriptBlock(statements);
203
 			ScriptBlock block = new ScriptBlock(statements);
207
-			block.setTag(SourceFile.class, new SourceFile(filename));
204
+			block.setTag(SourceFile.class, file);
208
 			block.setTag(WhitespacePostComment.class, postComment);
205
 			block.setTag(WhitespacePostComment.class, postComment);
209
 			scripts.add(block);
206
 			scripts.add(block);
210
 		}
207
 		}

+ 7
- 5
Shared/src/main/java/org/openzen/zencode/shared/CodePosition.java View File

3
 import org.openzen.zencode.shared.CodePosition;
3
 import org.openzen.zencode.shared.CodePosition;
4
 
4
 
5
 public final class CodePosition {
5
 public final class CodePosition {
6
-	public static final CodePosition BUILTIN = new CodePosition("builtin", 0, 0, 0, 0);
7
-	public static final CodePosition NATIVE = new CodePosition("native", 0, 0, 0, 0);
6
+	public static final CodePosition BUILTIN = new CodePosition(new VirtualSourceFile("builtin"), 0, 0, 0, 0);
7
+	public static final CodePosition NATIVE = new CodePosition(new VirtualSourceFile("native"), 0, 0, 0, 0);
8
 	public final String filename;
8
 	public final String filename;
9
+	public final SourceFile file;
9
 	public final int fromLine;
10
 	public final int fromLine;
10
 	public final int fromLineOffset;
11
 	public final int fromLineOffset;
11
 	public final int toLine;
12
 	public final int toLine;
12
 	public final int toLineOffset;
13
 	public final int toLineOffset;
13
 	
14
 	
14
-	public CodePosition(String filename, int fromLine, int fromLineOffset, int toLine, int toLineOffset) {
15
-	    this.filename = filename;
15
+	public CodePosition(SourceFile file, int fromLine, int fromLineOffset, int toLine, int toLineOffset) {
16
+		this.file = file;
17
+	    this.filename = file.getFilename();
16
 	    this.fromLine = fromLine;
18
 	    this.fromLine = fromLine;
17
 	    this.fromLineOffset = fromLineOffset;
19
 	    this.fromLineOffset = fromLineOffset;
18
 	    this.toLine = toLine;
20
 	    this.toLine = toLine;
30
 	public CodePosition until(CodePosition to) {
32
 	public CodePosition until(CodePosition to) {
31
 	    if (!filename.equals(to.filename))
33
 	    if (!filename.equals(to.filename))
32
 	        throw new AssertionError("From and to positions must be in the same file!");
34
 	        throw new AssertionError("From and to positions must be in the same file!");
33
-	    return new CodePosition(filename, fromLine, fromLineOffset, to.toLine, to.toLineOffset);
35
+	    return new CodePosition(file, fromLine, fromLineOffset, to.toLine, to.toLineOffset);
34
 	}
36
 	}
35
 	
37
 	
36
 	public String toString() {
38
 	public String toString() {

+ 42
- 0
Shared/src/main/java/org/openzen/zencode/shared/FileSourceFile.java View File

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.zencode.shared;
7
+
8
+import java.io.BufferedInputStream;
9
+import java.io.BufferedReader;
10
+import java.io.File;
11
+import java.io.FileInputStream;
12
+import java.io.FileReader;
13
+import java.io.IOException;
14
+import java.io.InputStreamReader;
15
+import java.io.Reader;
16
+import java.nio.charset.StandardCharsets;
17
+
18
+/**
19
+ *
20
+ * @author Hoofdgebruiker
21
+ */
22
+public class FileSourceFile implements SourceFile {
23
+	public final String name;
24
+	public final File file;
25
+	
26
+	public FileSourceFile(String name, File file) {
27
+		this.name = name;
28
+		this.file = file;
29
+	}
30
+
31
+	@Override
32
+	public String getFilename() {
33
+		return name;
34
+	}
35
+
36
+	@Override
37
+	public Reader open() throws IOException {
38
+		return new InputStreamReader(
39
+				new BufferedInputStream(new FileInputStream(file)),
40
+				StandardCharsets.UTF_8);
41
+	}
42
+}

+ 34
- 0
Shared/src/main/java/org/openzen/zencode/shared/LiteralSourceFile.java View File

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.zencode.shared;
7
+
8
+import java.io.IOException;
9
+import java.io.Reader;
10
+import java.io.StringReader;
11
+
12
+/**
13
+ *
14
+ * @author Hoofdgebruiker
15
+ */
16
+public class LiteralSourceFile implements SourceFile {
17
+	private final String filename;
18
+	private final String contents;
19
+	
20
+	public LiteralSourceFile(String filename, String contents) {
21
+		this.filename = filename;
22
+		this.contents = contents;
23
+	}
24
+
25
+	@Override
26
+	public String getFilename() {
27
+		return filename;
28
+	}
29
+
30
+	@Override
31
+	public Reader open() throws IOException {
32
+		return new StringReader(contents);
33
+	}
34
+}

+ 6
- 9
Shared/src/main/java/org/openzen/zencode/shared/SourceFile.java View File

1
 package org.openzen.zencode.shared;
1
 package org.openzen.zencode.shared;
2
 
2
 
3
-public final class SourceFile {
4
-	public final String filename;
5
-	
6
-	public SourceFile(String filename) {
7
-	    this.filename = filename;
8
-	}
3
+import java.io.IOException;
4
+import java.io.Reader;
5
+
6
+public interface SourceFile {
7
+	String getFilename();
9
 	
8
 	
10
-	public String getFilename() {
11
-	    return filename;
12
-	}
9
+	Reader open() throws IOException;
13
 }
10
 }

+ 31
- 0
Shared/src/main/java/org/openzen/zencode/shared/VirtualSourceFile.java View File

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.zencode.shared;
7
+
8
+import java.io.IOException;
9
+import java.io.Reader;
10
+
11
+/**
12
+ *
13
+ * @author Hoofdgebruiker
14
+ */
15
+public class VirtualSourceFile implements SourceFile {
16
+	private final String filename;
17
+	
18
+	public VirtualSourceFile(String filename) {
19
+		this.filename = filename;
20
+	}
21
+
22
+	@Override
23
+	public String getFilename() {
24
+		return filename;
25
+	}
26
+
27
+	@Override
28
+	public Reader open() throws IOException {
29
+		throw new UnsupportedOperationException("Cannot open virtual source files");
30
+	}
31
+}

+ 11
- 0
Shared/src/main/java/stdlib/Arrays.java View File

2
 
2
 
3
 import java.lang.reflect.Array;
3
 import java.lang.reflect.Array;
4
 import java.util.ArrayList;
4
 import java.util.ArrayList;
5
+import java.util.HashMap;
5
 import java.util.List;
6
 import java.util.List;
7
+import java.util.Map;
6
 import zsynthetic.Function1;
8
 import zsynthetic.Function1;
7
 import zsynthetic.Function2;
9
 import zsynthetic.Function2;
8
 import zsynthetic.Function3;
10
 import zsynthetic.Function3;
9
 import zsynthetic.Function4;
11
 import zsynthetic.Function4;
10
 import zsynthetic.Function5;
12
 import zsynthetic.Function5;
11
 import zsynthetic.Function6;
13
 import zsynthetic.Function6;
14
+import zsynthetic.Function7;
12
 
15
 
13
 public final class Arrays {
16
 public final class Arrays {
14
     private Arrays() {}
17
     private Arrays() {}
170
 	    }
173
 	    }
171
 	    return result;
174
 	    return result;
172
 	}
175
 	}
176
+	
177
+	public static <K, T> Map<K, T> index(Class<T> typeOfT, T[] self, Class<K> typeOfK, Function7<K, T> key) {
178
+	    Map<K, T> result = new HashMap<>();
179
+	    for (T value : self)
180
+	        
181
+	        result.put(key.invoke(value), value);
182
+	    return result;
183
+	}
173
 }
184
 }

+ 2
- 2
Shared/src/main/java/stdlib/Assoc.java View File

2
 
2
 
3
 import java.util.HashMap;
3
 import java.util.HashMap;
4
 import java.util.Map;
4
 import java.util.Map;
5
-import zsynthetic.Function7;
5
+import zsynthetic.Function8;
6
 
6
 
7
 public final class Assoc {
7
 public final class Assoc {
8
     private Assoc() {}
8
     private Assoc() {}
9
-	static <W, K, V> Map<K, W> mapValues(Class<K> typeOfK, Class<V> typeOfV, Map<K, V> self, Class<W> typeOfW, Function7<W, V> projection) {
9
+	static <W, K, V> Map<K, W> mapValues(Class<K> typeOfK, Class<V> typeOfV, Map<K, V> self, Class<W> typeOfW, Function8<W, V> projection) {
10
 	    Map<K, W> result = new HashMap<>();
10
 	    Map<K, W> result = new HashMap<>();
11
 	    for (Map.Entry<K, V> temp1 : self.entrySet()) {
11
 	    for (Map.Entry<K, V> temp1 : self.entrySet()) {
12
 	        K k = temp1.getKey();
12
 	        K k = temp1.getKey();

+ 4
- 4
Shared/src/main/java/stdlib/Result.java View File

4
 import stdlib.Result.Error;
4
 import stdlib.Result.Error;
5
 import stdlib.Result.Ok;
5
 import stdlib.Result.Ok;
6
 import zsynthetic.Function10;
6
 import zsynthetic.Function10;
7
-import zsynthetic.Function8;
7
+import zsynthetic.Function11;
8
 import zsynthetic.Function9;
8
 import zsynthetic.Function9;
9
 
9
 
10
 public abstract class Result<T, E> {
10
 public abstract class Result<T, E> {
11
-	public <R> Result<R, E> then(Class<R> typeOfR, Function8<R, E, T> fn) {
11
+	public <R> Result<R, E> then(Class<R> typeOfR, Function9<R, E, T> fn) {
12
 	    Result<R, E> temp1;
12
 	    Result<R, E> temp1;
13
 	    switch (this.getDiscriminant()) {
13
 	    switch (this.getDiscriminant()) {
14
 	        case Ok:
14
 	        case Ok:
25
 	    return temp1;
25
 	    return temp1;
26
 	}
26
 	}
27
 	
27
 	
28
-	public <X> Result<T, X> handle(Class<X> typeOfX, Function9<T, X, E> handler) {
28
+	public <X> Result<T, X> handle(Class<X> typeOfX, Function10<T, X, E> handler) {
29
 	    Result<T, X> temp1;
29
 	    Result<T, X> temp1;
30
 	    switch (this.getDiscriminant()) {
30
 	    switch (this.getDiscriminant()) {
31
 	        case Ok:
31
 	        case Ok:
75
 	    return temp1;
75
 	    return temp1;
76
 	}
76
 	}
77
 	
77
 	
78
-	public T orElse(Function10<T, E> other) {
78
+	public T orElse(Function11<T, E> other) {
79
 	    T temp1;
79
 	    T temp1;
80
 	    switch (this.getDiscriminant()) {
80
 	    switch (this.getDiscriminant()) {
81
 	        case Ok:
81
 	        case Ok:

+ 4
- 2
Shared/src/main/java/zsynthetic/Function10.java View File

1
 package zsynthetic;
1
 package zsynthetic;
2
+import stdlib.Result;
3
+
2
 
4
 
3
 @FunctionalInterface
5
 @FunctionalInterface
4
-public interface Function10<T, E>  {
5
-    T invoke(E error);
6
+public interface Function10<T, X, E>  {
7
+    Result<T, X> invoke(E error);
6
 }
8
 }

+ 2
- 2
Shared/src/main/java/zsynthetic/Function7.java View File

1
 package zsynthetic;
1
 package zsynthetic;
2
 
2
 
3
 @FunctionalInterface
3
 @FunctionalInterface
4
-public interface Function7<W, V>  {
5
-    W invoke(V value);
4
+public interface Function7<K, T>  {
5
+    K invoke(T value);
6
 }
6
 }

+ 2
- 4
Shared/src/main/java/zsynthetic/Function8.java View File

1
 package zsynthetic;
1
 package zsynthetic;
2
-import stdlib.Result;
3
-
4
 
2
 
5
 @FunctionalInterface
3
 @FunctionalInterface
6
-public interface Function8<R, E, T>  {
7
-    Result<R, E> invoke(T result);
4
+public interface Function8<W, V>  {
5
+    W invoke(V value);
8
 }
6
 }

+ 2
- 2
Shared/src/main/java/zsynthetic/Function9.java View File

3
 
3
 
4
 
4
 
5
 @FunctionalInterface
5
 @FunctionalInterface
6
-public interface Function9<T, X, E>  {
7
-    Result<T, X> invoke(E error);
6
+public interface Function9<R, E, T>  {
7
+    Result<R, E> invoke(T result);
8
 }
8
 }

Loading…
Cancel
Save