Browse Source

- Changed the way types in the currently compiling module are resolved

- Updating Shared with a new compiled version
- Fixed some java source generation bugs
Stan Hebben 6 years ago
parent
commit
fcbeffd781
67 changed files with 1046 additions and 628 deletions
  1. 22
    3
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/context/CompilingPackage.java
  2. 5
    4
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/context/CompilingType.java
  3. 7
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/context/FileResolutionContext.java
  4. 3
    3
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/context/LocalTypeResolutionContext.java
  5. 18
    15
      Constructor/src/main/java/org/openzen/zenscript/constructor/Module.java
  6. 3
    3
      Constructor/src/main/java/org/openzen/zenscript/constructor/module/DirectoryModuleReference.java
  7. 1
    1
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaDefinitionVisitor.java
  8. 1
    1
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/prepare/JavaSourcePrepareDefinitionVisitor.java
  9. 3
    1
      Parser/src/main/java/org/openzen/zenscript/lexer/ZSTokenType.java
  10. 8
    5
      Parser/src/main/java/org/openzen/zenscript/parser/ParsedDefinition.java
  11. 31
    17
      Parser/src/main/java/org/openzen/zenscript/parser/ParsedFile.java
  12. 28
    12
      Parser/src/main/java/org/openzen/zenscript/parser/definitions/BaseParsedDefinition.java
  13. 27
    15
      Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedAlias.java
  14. 6
    6
      Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedClass.java
  15. 6
    7
      Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedEnum.java
  16. 6
    9
      Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedExpansion.java
  17. 23
    10
      Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedFunction.java
  18. 6
    6
      Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedInterface.java
  19. 6
    7
      Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedStruct.java
  20. 6
    6
      Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedVariant.java
  21. 19
    20
      Parser/src/main/java/org/openzen/zenscript/parser/member/ParsedDefinitionMember.java
  22. 2
    2
      Parser/src/main/java/org/openzen/zenscript/parser/member/ParsedInnerDefinition.java
  23. 2
    3
      ScriptingExample/src/main/java/org/openzen/zenscript/scriptingexample/Main.java
  24. 18
    0
      Shared/src/main/java/listeners/DummyListenerHandle.java
  25. 9
    0
      Shared/src/main/java/listeners/ListenerHandle.java
  26. 85
    0
      Shared/src/main/java/listeners/ListenerList.java
  27. 25
    0
      Shared/src/main/java/live/ImmutableLiveBool.java
  28. 22
    0
      Shared/src/main/java/live/ImmutableLiveObject.java
  29. 22
    0
      Shared/src/main/java/live/ImmutableLiveString.java
  30. 23
    0
      Shared/src/main/java/live/InverseLiveBool.java
  31. 88
    0
      Shared/src/main/java/live/LiveArrayList.java
  32. 10
    0
      Shared/src/main/java/live/LiveBool.java
  33. 12
    0
      Shared/src/main/java/live/LiveInt.java
  34. 23
    0
      Shared/src/main/java/live/LiveList.java
  35. 10
    0
      Shared/src/main/java/live/LiveObject.java
  36. 10
    0
      Shared/src/main/java/live/LiveString.java
  37. 19
    0
      Shared/src/main/java/live/MutableLiveList.java
  38. 15
    15
      Shared/src/main/java/org/openzen/zencode/shared/CharacterEntity.java
  39. 21
    21
      Shared/src/main/java/org/openzen/zencode/shared/CompileException.java
  40. 49
    48
      Shared/src/main/java/org/openzen/zencode/shared/ConcatMap.java
  41. 2
    15
      Shared/src/main/java/org/openzen/zencode/shared/StringExpansion.java
  42. 17
    17
      Shared/src/main/java/org/openzen/zencode/shared/Taggable.java
  43. 16
    26
      Shared/src/main/java/org/openzen/zencode/shared/VirtualSourceFile.java
  44. 159
    173
      Shared/src/main/java/stdlib/Arrays.java
  45. 2
    3
      Shared/src/main/java/stdlib/Assoc.java
  46. 3
    3
      Shared/src/main/java/stdlib/EnforcementLevel.java
  47. 2
    2
      Shared/src/main/java/stdlib/EqualsComparable.java
  48. 4
    4
      Shared/src/main/java/stdlib/Hashable.java
  49. 102
    103
      Shared/src/main/java/stdlib/Result.java
  50. 3
    3
      Shared/src/main/java/stdlib/StringBuildable.java
  51. 4
    4
      Shared/src/main/java/stdlib/StringBuilder.java
  52. 1
    1
      Shared/src/main/java/zsynthetic/ArrayHelpers.java
  53. 0
    8
      Shared/src/main/java/zsynthetic/Function10.java
  54. 0
    6
      Shared/src/main/java/zsynthetic/Function11.java
  55. 0
    6
      Shared/src/main/java/zsynthetic/Function7.java
  56. 0
    6
      Shared/src/main/java/zsynthetic/Function8.java
  57. 6
    0
      Shared/src/main/java/zsynthetic/FunctionBoolBoolToVoid.java
  58. 6
    0
      Shared/src/main/java/zsynthetic/FunctionIntIntToVoid.java
  59. 1
    1
      Shared/src/main/java/zsynthetic/FunctionIntTToBool.java
  60. 1
    1
      Shared/src/main/java/zsynthetic/FunctionIntTToU.java
  61. 1
    1
      Shared/src/main/java/zsynthetic/FunctionIntTToVoid.java
  62. 6
    0
      Shared/src/main/java/zsynthetic/FunctionStringStringToVoid.java
  63. 6
    0
      Shared/src/main/java/zsynthetic/FunctionTTToVoid.java
  64. 1
    1
      Shared/src/main/java/zsynthetic/FunctionTToBool.java
  65. 1
    1
      Shared/src/main/java/zsynthetic/FunctionTToResultWithUV.java
  66. 1
    1
      Shared/src/main/java/zsynthetic/FunctionTToU.java
  67. 1
    1
      Shared/src/main/java/zsynthetic/FunctionTToVoid.java

+ 22
- 3
CodeModel/src/main/java/org/openzen/zenscript/codemodel/context/CompilingPackage.java View File

9
 import java.util.List;
9
 import java.util.List;
10
 import java.util.Map;
10
 import java.util.Map;
11
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
11
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
12
+import org.openzen.zenscript.codemodel.definition.ZSPackage;
12
 import org.openzen.zenscript.codemodel.type.DefinitionTypeID;
13
 import org.openzen.zenscript.codemodel.type.DefinitionTypeID;
13
 import org.openzen.zenscript.codemodel.type.GenericName;
14
 import org.openzen.zenscript.codemodel.type.GenericName;
14
 import org.openzen.zenscript.codemodel.type.ITypeID;
15
 import org.openzen.zenscript.codemodel.type.ITypeID;
18
  * @author Hoofdgebruiker
19
  * @author Hoofdgebruiker
19
  */
20
  */
20
 public class CompilingPackage {
21
 public class CompilingPackage {
22
+	private final ZSPackage pkg;
21
 	private final Map<String, CompilingPackage> packages = new HashMap<>();
23
 	private final Map<String, CompilingPackage> packages = new HashMap<>();
22
 	private final Map<String, CompilingType> types = new HashMap<>();
24
 	private final Map<String, CompilingType> types = new HashMap<>();
23
 	
25
 	
26
+	public CompilingPackage(ZSPackage pkg) {
27
+		this.pkg = pkg;
28
+	}
29
+	
30
+	public ZSPackage getPackage() {
31
+		return pkg;
32
+	}
33
+	
34
+	public CompilingPackage getOrCreatePackage(String name) {
35
+		if (packages.containsKey(name))
36
+			return packages.get(name);
37
+		
38
+		CompilingPackage newPackage = new CompilingPackage(pkg.getOrCreatePackage(name));
39
+		packages.put(name, newPackage);
40
+		return newPackage;
41
+	}
42
+	
24
 	public void addPackage(String name, CompilingPackage package_) {
43
 	public void addPackage(String name, CompilingPackage package_) {
25
 		packages.put(name, package_);
44
 		packages.put(name, package_);
26
 	}
45
 	}
44
 	
63
 	
45
 	private HighLevelDefinition getImportType(TypeResolutionContext context, CompilingType type, List<String> name, int index) {
64
 	private HighLevelDefinition getImportType(TypeResolutionContext context, CompilingType type, List<String> name, int index) {
46
 		if (index == name.size())
65
 		if (index == name.size())
47
-			return type.load(context);
66
+			return type.load();
48
 		
67
 		
49
 		return getImportType(context, type.getInner(name.get(index)), name, index + 1);
68
 		return getImportType(context, type.getInner(name.get(index)), name, index + 1);
50
 	}
69
 	}
62
 		
81
 		
63
 		if (types.containsKey(name.get(index).name)) {
82
 		if (types.containsKey(name.get(index).name)) {
64
 			CompilingType type = types.get(name.get(index).name);
83
 			CompilingType type = types.get(name.get(index).name);
65
-			DefinitionTypeID result = context.getTypeRegistry().getForDefinition(type.load(context), name.get(index).arguments);
84
+			DefinitionTypeID result = context.getTypeRegistry().getForDefinition(type.load(), name.get(index).arguments);
66
 			return getInner(context, name, index + 1, type, result);
85
 			return getInner(context, name, index + 1, type, result);
67
 		}
86
 		}
68
 		
87
 		
77
 		if (innerType == null)
96
 		if (innerType == null)
78
 			return null;
97
 			return null;
79
 		
98
 		
80
-		DefinitionTypeID innerResult = context.getTypeRegistry().getForDefinition(innerType.load(context), name.get(index).arguments, result);
99
+		DefinitionTypeID innerResult = context.getTypeRegistry().getForDefinition(innerType.load(), name.get(index).arguments, result);
81
 		return getInner(context, name, index + 1, innerType, innerResult);
100
 		return getInner(context, name, index + 1, innerType, innerResult);
82
 	}
101
 	}
83
 }
102
 }

+ 5
- 4
CodeModel/src/main/java/org/openzen/zenscript/codemodel/context/CompilingType.java View File

9
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
9
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
10
 import org.openzen.zenscript.codemodel.type.DefinitionTypeID;
10
 import org.openzen.zenscript.codemodel.type.DefinitionTypeID;
11
 import org.openzen.zenscript.codemodel.type.GenericName;
11
 import org.openzen.zenscript.codemodel.type.GenericName;
12
+import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
12
 
13
 
13
 /**
14
 /**
14
  *
15
  *
17
 public interface CompilingType {
18
 public interface CompilingType {
18
 	CompilingType getInner(String name);
19
 	CompilingType getInner(String name);
19
 	
20
 	
20
-	HighLevelDefinition load(TypeResolutionContext context);
21
+	HighLevelDefinition load();
21
 	
22
 	
22
-	default DefinitionTypeID getInnerType(TypeResolutionContext context, List<GenericName> name, int index, DefinitionTypeID outer) {
23
-		DefinitionTypeID type = context.getTypeRegistry().getForDefinition(load(context), name.get(index).arguments, outer);
23
+	default DefinitionTypeID getInnerType(GlobalTypeRegistry registry, List<GenericName> name, int index, DefinitionTypeID outer) {
24
+		DefinitionTypeID type = registry.getForDefinition(load(), name.get(index).arguments, outer);
24
 		index++;
25
 		index++;
25
 		if (index == name.size())
26
 		if (index == name.size())
26
 			return type;
27
 			return type;
29
 		if (innerType == null)
30
 		if (innerType == null)
30
 			return null;
31
 			return null;
31
 		
32
 		
32
-		return innerType.getInnerType(context, name, index, type);
33
+		return innerType.getInnerType(registry, name, index, type);
33
 	}
34
 	}
34
 }
35
 }

+ 7
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/context/FileResolutionContext.java View File

21
  */
21
  */
22
 public class FileResolutionContext implements TypeResolutionContext {
22
 public class FileResolutionContext implements TypeResolutionContext {
23
 	private final ModuleTypeResolutionContext module;
23
 	private final ModuleTypeResolutionContext module;
24
+	private final CompilingPackage modulePackage;
24
 	private final Map<String, HighLevelDefinition> imports = new HashMap<>();
25
 	private final Map<String, HighLevelDefinition> imports = new HashMap<>();
25
 	
26
 	
26
-	public FileResolutionContext(ModuleTypeResolutionContext module) {
27
+	public FileResolutionContext(ModuleTypeResolutionContext module, CompilingPackage modulePackage) {
27
 		this.module = module;
28
 		this.module = module;
29
+		this.modulePackage = modulePackage;
28
 	}
30
 	}
29
 	
31
 	
30
 	public void addImport(String name, HighLevelDefinition definition) {
32
 	public void addImport(String name, HighLevelDefinition definition) {
51
 					1);
53
 					1);
52
 		}
54
 		}
53
 		
55
 		
56
+		ITypeID moduleType = modulePackage.getType(this, name);
57
+		if (moduleType != null)
58
+			return moduleType;
59
+		
54
 		return module.getType(position, name);
60
 		return module.getType(position, name);
55
 	}
61
 	}
56
 
62
 

+ 3
- 3
CodeModel/src/main/java/org/openzen/zenscript/codemodel/context/LocalTypeResolutionContext.java View File

44
 		if (type != null) {
44
 		if (type != null) {
45
 			CompilingType compiling = type.getInner(name.get(0).name);
45
 			CompilingType compiling = type.getInner(name.get(0).name);
46
 			if (compiling != null) {
46
 			if (compiling != null) {
47
-				DefinitionTypeID outer = getTypeRegistry().getForMyDefinition(type.load(this));
48
-				return compiling.getInnerType(this, name, 0, outer);
47
+				DefinitionTypeID outer = getTypeRegistry().getForMyDefinition(type.load());
48
+				return compiling.getInnerType(getTypeRegistry(), name, 0, outer);
49
 			}
49
 			}
50
 		}
50
 		}
51
 		
51
 		
60
 	
60
 	
61
 	@Override
61
 	@Override
62
 	public ITypeID getThisType() {
62
 	public ITypeID getThisType() {
63
-		return type == null ? null : getTypeRegistry().getForMyDefinition(type.load(this));
63
+		return type == null ? null : getTypeRegistry().getForMyDefinition(type.load());
64
 	}
64
 	}
65
 }
65
 }

+ 18
- 15
Constructor/src/main/java/org/openzen/zenscript/constructor/Module.java View File

64
 		}
64
 		}
65
 	}
65
 	}
66
 	
66
 	
67
-	public ParsedFile[] parse(ZSPackage pkg, CompilingPackage compilingPackage) throws IOException {
67
+	public ParsedFile[] parse(CompilingPackage compilingPackage) throws IOException {
68
 		// TODO: load bracket parsers from host plugins
68
 		// TODO: load bracket parsers from host plugins
69
 		List<ParsedFile> files = new ArrayList<>();
69
 		List<ParsedFile> files = new ArrayList<>();
70
-		parse(files, pkg, compilingPackage, null, sourceDirectory);
70
+		parse(files, compilingPackage, null, sourceDirectory);
71
 		return files.toArray(new ParsedFile[files.size()]);
71
 		return files.toArray(new ParsedFile[files.size()]);
72
 	}
72
 	}
73
 	
73
 	
74
-	private void parse(List<ParsedFile> files, ZSPackage pkg, CompilingPackage compilingPackage, BracketExpressionParser bracketParser, File directory) throws IOException {
74
+	private void parse(List<ParsedFile> files, CompilingPackage pkg, BracketExpressionParser bracketParser, File directory) throws IOException {
75
 		for (File file : directory.listFiles()) {
75
 		for (File file : directory.listFiles()) {
76
 			if (file.getName().endsWith(".zs")) {
76
 			if (file.getName().endsWith(".zs")) {
77
 				try {
77
 				try {
78
-					files.add(ParsedFile.parse(pkg, compilingPackage, bracketParser, file));
78
+					files.add(ParsedFile.parse(pkg, bracketParser, file));
79
 				} catch (CompileException ex) {
79
 				} catch (CompileException ex) {
80
 					exceptionLogger.accept(ex);
80
 					exceptionLogger.accept(ex);
81
 				}
81
 				}
82
 			} else if (file.isDirectory()) {
82
 			} else if (file.isDirectory()) {
83
-				CompilingPackage innerPackage = new CompilingPackage();
84
-				compilingPackage.addPackage(file.getName(), innerPackage);
85
-				parse(files, pkg.getOrCreatePackage(file.getName()), innerPackage, bracketParser, file);
83
+				CompilingPackage innerPackage = pkg.getOrCreatePackage(file.getName());
84
+				pkg.addPackage(file.getName(), innerPackage);
85
+				parse(files, innerPackage, bracketParser, file);
86
 			}
86
 			}
87
 		}
87
 		}
88
 	}
88
 	}
90
 	public static SemanticModule compileSyntaxToSemantic(
90
 	public static SemanticModule compileSyntaxToSemantic(
91
 			String name,
91
 			String name,
92
 			String[] dependencies,
92
 			String[] dependencies,
93
-			ZSPackage pkg,
94
-			CompilingPackage compilingPkg,
93
+			CompilingPackage pkg,
95
 			ParsedFile[] files,
94
 			ParsedFile[] files,
96
 			ModuleSpace registry,
95
 			ModuleSpace registry,
97
 			Consumer<CompileException> exceptionLogger) {
96
 			Consumer<CompileException> exceptionLogger) {
117
 				registry.compilationUnit.globalTypeRegistry,
116
 				registry.compilationUnit.globalTypeRegistry,
118
 				registry.getAnnotations(),
117
 				registry.getAnnotations(),
119
 				rootPackage,
118
 				rootPackage,
120
-				compilingPkg,
119
+				pkg,
121
 				globals);
120
 				globals);
122
 		
121
 		
122
+		for (ParsedFile file : files) {
123
+			file.registerTypes(moduleContext, rootPackage, pkg);
124
+		}
125
+		
123
 		for (ParsedFile file : files) {
126
 		for (ParsedFile file : files) {
124
 			// compileMembers will register all definition members to their
127
 			// compileMembers will register all definition members to their
125
 			// respective definitions, such as fields, constructors, methods...
128
 			// respective definitions, such as fields, constructors, methods...
126
 			// It doesn't yet compile the method contents.
129
 			// It doesn't yet compile the method contents.
127
 			try {
130
 			try {
128
-				file.compileTypes(moduleContext, rootPackage, compilingPkg);
131
+				file.compileTypes(moduleContext, rootPackage, pkg);
129
 			} catch (CompileException ex) {
132
 			} catch (CompileException ex) {
130
 				exceptionLogger.accept(ex);
133
 				exceptionLogger.accept(ex);
131
 				failed = true;
134
 				failed = true;
133
 		}
136
 		}
134
 		
137
 		
135
 		if (failed)
138
 		if (failed)
136
-			return new SemanticModule(name, dependencies, SemanticModule.State.INVALID, rootPackage, pkg, definitions, Collections.emptyList(), registry.compilationUnit, expansions, registry.getAnnotations());
139
+			return new SemanticModule(name, dependencies, SemanticModule.State.INVALID, rootPackage, pkg.getPackage(), definitions, Collections.emptyList(), registry.compilationUnit, expansions, registry.getAnnotations());
137
 		
140
 		
138
 		// scripts will store all the script blocks encountered in the files
141
 		// scripts will store all the script blocks encountered in the files
139
 		PrecompilationState precompiler = new PrecompilationState();
142
 		PrecompilationState precompiler = new PrecompilationState();
140
 		for (ParsedFile file : files) {
143
 		for (ParsedFile file : files) {
141
-			file.registerMembers(moduleContext, precompiler, rootPackage, compilingPkg, expansions, globals);
144
+			file.registerMembers(moduleContext, precompiler, rootPackage, pkg, expansions, globals);
142
 		}
145
 		}
143
 		
146
 		
144
 		List<ScriptBlock> scripts = new ArrayList<>();
147
 		List<ScriptBlock> scripts = new ArrayList<>();
147
 			// into semantic code. This semantic code can then be compiled
150
 			// into semantic code. This semantic code can then be compiled
148
 			// to various targets.
151
 			// to various targets.
149
 			try {
152
 			try {
150
-				file.compileCode(moduleContext, precompiler, rootPackage, compilingPkg, expansions, scripts, globals);
153
+				file.compileCode(moduleContext, precompiler, rootPackage, pkg, expansions, scripts, globals);
151
 			} catch (CompileException ex) {
154
 			} catch (CompileException ex) {
152
 				exceptionLogger.accept(ex);
155
 				exceptionLogger.accept(ex);
153
 				failed = true;
156
 				failed = true;
154
 			}
157
 			}
155
 		}
158
 		}
156
 		
159
 		
157
-		return new SemanticModule(name, dependencies, SemanticModule.State.ASSEMBLED, rootPackage, pkg, definitions, scripts, registry.compilationUnit, expansions, registry.getAnnotations());
160
+		return new SemanticModule(name, dependencies, SemanticModule.State.ASSEMBLED, rootPackage, pkg.getPackage(), definitions, scripts, registry.compilationUnit, expansions, registry.getAnnotations());
158
 	}
161
 	}
159
 }
162
 }

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

76
 
76
 
77
 			Module module = new Module(moduleName, directory, jsonFile, exceptionLogger);
77
 			Module module = new Module(moduleName, directory, jsonFile, exceptionLogger);
78
 			ZSPackage pkg = isStdlib ? unit.globalTypeRegistry.stdlib : new ZSPackage(null, module.packageName);
78
 			ZSPackage pkg = isStdlib ? unit.globalTypeRegistry.stdlib : new ZSPackage(null, module.packageName);
79
-			CompilingPackage compilingPackage = new CompilingPackage();
79
+			CompilingPackage compilingPackage = new CompilingPackage(pkg);
80
 			
80
 			
81
-			ParsedFile[] parsedFiles = module.parse(pkg, compilingPackage);
82
-			SemanticModule result = Module.compileSyntaxToSemantic(module.name, module.dependencies, pkg, compilingPackage, parsedFiles, space, exceptionLogger);
81
+			ParsedFile[] parsedFiles = module.parse(compilingPackage);
82
+			SemanticModule result = Module.compileSyntaxToSemantic(module.name, module.dependencies, compilingPackage, parsedFiles, space, exceptionLogger);
83
 			
83
 			
84
 			JSONObject globals = json.optJSONObject("globals");
84
 			JSONObject globals = json.optJSONObject("globals");
85
 			if (globals != null) {
85
 			if (globals != null) {

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

316
 				String name = option.types.length == 1 ? "value" : "value" + (i + 1);
316
 				String name = option.types.length == 1 ? "value" : "value" + (i + 1);
317
 				output.append(scope.type(option.types[i])).append(' ').append(name);
317
 				output.append(scope.type(option.types[i])).append(' ').append(name);
318
 			}
318
 			}
319
-			output.append("){\n");
319
+			output.append(") {\n");
320
 			for (int i = 0; i < option.types.length; i++) {
320
 			for (int i = 0; i < option.types.length; i++) {
321
 				if (i > 0)
321
 				if (i > 0)
322
 					output.append(indent).append(settings.indent).append(settings.indent).append(settings.indent).append(";\n");
322
 					output.append(indent).append(settings.indent).append(settings.indent).append(settings.indent).append(";\n");

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

202
 		
202
 		
203
 		{
203
 		{
204
 			JavaNativeClass cls = new JavaNativeClass(new JavaSourceClass("java.io", "StringReader"), true);
204
 			JavaNativeClass cls = new JavaNativeClass(new JavaSourceClass("java.io", "StringReader"), true);
205
-			cls.addInstanceMethod("constructor", "");
205
+			cls.addConstructor("constructor", "");
206
 			cls.addInstanceMethod("destructor", "close");
206
 			cls.addInstanceMethod("destructor", "close");
207
 			cls.addInstanceMethod("readCharacter", "read");
207
 			cls.addInstanceMethod("readCharacter", "read");
208
 			cls.addInstanceMethod("readSlice", "read");
208
 			cls.addInstanceMethod("readSlice", "read");

+ 3
- 1
Parser/src/main/java/org/openzen/zenscript/lexer/ZSTokenType.java View File

17
 	T_WHITESPACE_TAB(true, "\t", "\t"),
17
 	T_WHITESPACE_TAB(true, "\t", "\t"),
18
 	T_WHITESPACE_NEWLINE(true, "\n", "\n", true),
18
 	T_WHITESPACE_NEWLINE(true, "\n", "\n", true),
19
 	T_WHITESPACE_CARRIAGE_RETURN(true, "\r", "\r"),
19
 	T_WHITESPACE_CARRIAGE_RETURN(true, "\r", "\r"),
20
-	T_IDENTIFIER("[a-zA-Z_][a-zA-Z_0-9]*"),
20
+	T_IDENTIFIER("@?[a-zA-Z_][a-zA-Z_0-9]*"),
21
+	T_LOCAL_IDENTIFIER("$[a-zA-Z_][a-zA-Z_0-9]*"),
21
 	T_FLOAT("\\-?(0|[1-9][0-9]*)\\.[0-9]+([eE][\\+\\-]?[0-9]+)?"),
22
 	T_FLOAT("\\-?(0|[1-9][0-9]*)\\.[0-9]+([eE][\\+\\-]?[0-9]+)?"),
22
 	T_INT("\\-?(0|[1-9][0-9]*)"),
23
 	T_INT("\\-?(0|[1-9][0-9]*)"),
23
 	T_STRING_SQ("\"([^\"\\\\\\n]|\\\\([\'\"\\\\/bfnrt&]|u[0-9a-fA-F]{4}))*\""),
24
 	T_STRING_SQ("\"([^\"\\\\\\n]|\\\\([\'\"\\\\/bfnrt&]|u[0-9a-fA-F]{4}))*\""),
94
 	K_PRIVATE(true, "private"),
95
 	K_PRIVATE(true, "private"),
95
 	K_PUBLIC(true, "public"),
96
 	K_PUBLIC(true, "public"),
96
 	K_EXPORT(true, "export"),
97
 	K_EXPORT(true, "export"),
98
+	K_INTERNAL(true, "internal"),
97
 	K_STATIC(true, "static"),
99
 	K_STATIC(true, "static"),
98
 	K_PROTECTED(true, "protected"),
100
 	K_PROTECTED(true, "protected"),
99
 	K_IMPLICIT(true, "implicit"),
101
 	K_IMPLICIT(true, "implicit"),

+ 8
- 5
Parser/src/main/java/org/openzen/zenscript/parser/ParsedDefinition.java View File

5
  */
5
  */
6
 package org.openzen.zenscript.parser;
6
 package org.openzen.zenscript.parser;
7
 
7
 
8
-import java.util.Map;
9
 import org.openzen.zencode.shared.CodePosition;
8
 import org.openzen.zencode.shared.CodePosition;
10
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
9
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
10
+import org.openzen.zenscript.codemodel.context.CompilingPackage;
11
 import org.openzen.zenscript.codemodel.context.CompilingType;
11
 import org.openzen.zenscript.codemodel.context.CompilingType;
12
 import org.openzen.zenscript.codemodel.context.TypeResolutionContext;
12
 import org.openzen.zenscript.codemodel.context.TypeResolutionContext;
13
-import org.openzen.zenscript.codemodel.definition.ZSPackage;
14
 import org.openzen.zenscript.lexer.ZSTokenParser;
13
 import org.openzen.zenscript.lexer.ZSTokenParser;
15
 import static org.openzen.zenscript.lexer.ZSTokenType.*;
14
 import static org.openzen.zenscript.lexer.ZSTokenType.*;
16
 import org.openzen.zenscript.codemodel.scope.BaseScope;
15
 import org.openzen.zenscript.codemodel.scope.BaseScope;
27
  *
26
  *
28
  * @author Hoofdgebruiker
27
  * @author Hoofdgebruiker
29
  */
28
  */
30
-public abstract class ParsedDefinition implements CompilingType {
31
-	public static ParsedDefinition parse(ZSPackage pkg, CodePosition position, int modifiers, ParsedAnnotation[] annotations, ZSTokenParser tokens, HighLevelDefinition outerDefinition) {
29
+public abstract class ParsedDefinition {
30
+	public static ParsedDefinition parse(CompilingPackage pkg, CodePosition position, int modifiers, ParsedAnnotation[] annotations, ZSTokenParser tokens, HighLevelDefinition outerDefinition) {
32
 		if (tokens.optional(K_CLASS) != null) {
31
 		if (tokens.optional(K_CLASS) != null) {
33
 			return ParsedClass.parseClass(pkg, position, modifiers, annotations, tokens, outerDefinition);
32
 			return ParsedClass.parseClass(pkg, position, modifiers, annotations, tokens, outerDefinition);
34
 		} else if (tokens.optional(K_INTERFACE) != null) {
33
 		} else if (tokens.optional(K_INTERFACE) != null) {
54
 	public final CodePosition position;
53
 	public final CodePosition position;
55
 	public final int modifiers;
54
 	public final int modifiers;
56
 	public final ParsedAnnotation[] annotations;
55
 	public final ParsedAnnotation[] annotations;
56
+	public final CompilingPackage pkg;
57
 	
57
 	
58
-	public ParsedDefinition(CodePosition position, int modifiers, ParsedAnnotation[] annotations) {
58
+	public ParsedDefinition(CodePosition position, int modifiers, CompilingPackage pkg, ParsedAnnotation[] annotations) {
59
 		this.position = position;
59
 		this.position = position;
60
+		this.pkg = pkg;
60
 		this.modifiers = modifiers;
61
 		this.modifiers = modifiers;
61
 		this.annotations = annotations;
62
 		this.annotations = annotations;
62
 	}
63
 	}
73
 		return modifiers;
74
 		return modifiers;
74
 	}
75
 	}
75
 	
76
 	
77
+	public abstract CompilingType getCompiling(TypeResolutionContext context);
78
+	
76
 	public abstract HighLevelDefinition getCompiled();
79
 	public abstract HighLevelDefinition getCompiled();
77
 	
80
 	
78
 	public abstract void linkTypes(TypeResolutionContext context);
81
 	public abstract void linkTypes(TypeResolutionContext context);

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

16
 import org.openzen.zencode.shared.FileSourceFile;
16
 import org.openzen.zencode.shared.FileSourceFile;
17
 import org.openzen.zencode.shared.LiteralSourceFile;
17
 import org.openzen.zencode.shared.LiteralSourceFile;
18
 import org.openzen.zencode.shared.SourceFile;
18
 import org.openzen.zencode.shared.SourceFile;
19
-import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
20
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
19
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
21
 import org.openzen.zenscript.codemodel.Modifiers;
20
 import org.openzen.zenscript.codemodel.Modifiers;
22
 import org.openzen.zenscript.codemodel.PackageDefinitions;
21
 import org.openzen.zenscript.codemodel.PackageDefinitions;
28
 import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
27
 import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
29
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
28
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
30
 import org.openzen.zenscript.codemodel.statement.Statement;
29
 import org.openzen.zenscript.codemodel.statement.Statement;
31
-import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
32
 import org.openzen.zenscript.lexer.ZSTokenParser;
30
 import org.openzen.zenscript.lexer.ZSTokenParser;
33
 import static org.openzen.zenscript.lexer.ZSTokenType.*;
31
 import static org.openzen.zenscript.lexer.ZSTokenType.*;
34
 import org.openzen.zenscript.codemodel.scope.FileScope;
32
 import org.openzen.zenscript.codemodel.scope.FileScope;
42
  * @author Hoofdgebruiker
40
  * @author Hoofdgebruiker
43
  */
41
  */
44
 public class ParsedFile {
42
 public class ParsedFile {
45
-	public static ParsedFile parse(ZSPackage pkg, CompilingPackage compilingPackage, BracketExpressionParser bracketParser, File file) throws IOException {
46
-		return parse(pkg, compilingPackage, bracketParser, new FileSourceFile(file.getName(), file));
43
+	public static ParsedFile parse(CompilingPackage compilingPackage, BracketExpressionParser bracketParser, File file) throws IOException {
44
+		return parse(compilingPackage, bracketParser, new FileSourceFile(file.getName(), file));
47
 	}
45
 	}
48
 	
46
 	
49
-	public static ParsedFile parse(ZSPackage pkg, CompilingPackage compilingPackage, BracketExpressionParser bracketParser, String filename, String content) {
47
+	public static ParsedFile parse(CompilingPackage compilingPackage, BracketExpressionParser bracketParser, String filename, String content) {
50
 		try {
48
 		try {
51
-			return parse(pkg, compilingPackage, bracketParser, new LiteralSourceFile(filename, content));
49
+			return parse(compilingPackage, bracketParser, new LiteralSourceFile(filename, content));
52
 		} catch (IOException ex) {
50
 		} catch (IOException ex) {
53
 			throw new AssertionError(); // shouldn't happen
51
 			throw new AssertionError(); // shouldn't happen
54
 		}
52
 		}
55
 	}
53
 	}
56
 	
54
 	
57
-	public static ParsedFile parse(ZSPackage pkg, CompilingPackage compilingPackage, BracketExpressionParser bracketParser, SourceFile file) throws IOException {
55
+	public static ParsedFile parse(CompilingPackage compilingPackage, BracketExpressionParser bracketParser, SourceFile file) throws IOException {
58
 		ZSTokenParser tokens = ZSTokenParser.create(file, bracketParser, 4);
56
 		ZSTokenParser tokens = ZSTokenParser.create(file, bracketParser, 4);
59
-		return parse(pkg, compilingPackage, tokens);
57
+		return parse(compilingPackage, tokens);
60
 	}
58
 	}
61
 	
59
 	
62
-	public static ParsedFile parse(ZSPackage pkg, CompilingPackage compilingPackage, ZSTokenParser tokens) {
60
+	public static ParsedFile parse(CompilingPackage compilingPackage, ZSTokenParser tokens) {
63
 		ParsedFile result = new ParsedFile(tokens.getFile());
61
 		ParsedFile result = new ParsedFile(tokens.getFile());
64
 
62
 
65
 		while (true) {
63
 		while (true) {
106
 			} else if ((tokens.optional(EOF)) != null) {
104
 			} else if ((tokens.optional(EOF)) != null) {
107
 				break;
105
 				break;
108
 			} else {
106
 			} else {
109
-				ParsedDefinition definition = ParsedDefinition.parse(pkg, position, modifiers, annotations, tokens, null);
107
+				ParsedDefinition definition = ParsedDefinition.parse(compilingPackage, position, modifiers, annotations, tokens, null);
110
 				if (definition == null) {
108
 				if (definition == null) {
111
 					result.statements.add(ParsedStatement.parse(tokens, annotations));
109
 					result.statements.add(ParsedStatement.parse(tokens, annotations));
112
 				} else {
110
 				} else {
113
 					result.definitions.add(definition);
111
 					result.definitions.add(definition);
114
 					definition.getCompiled().setTag(SourceFile.class, tokens.getFile());
112
 					definition.getCompiled().setTag(SourceFile.class, tokens.getFile());
115
-					
116
-					if (definition.getName() != null)
117
-						compilingPackage.addType(definition.getName(), definition);
118
 				}
113
 				}
119
 			}
114
 			}
120
 		}
115
 		}
148
 		}
143
 		}
149
 	}
144
 	}
150
 	
145
 	
146
+	public void registerTypes(
147
+			ModuleTypeResolutionContext moduleContext,
148
+			ZSPackage rootPackage,
149
+			CompilingPackage modulePackage) {
150
+		FileResolutionContext context = new FileResolutionContext(moduleContext, modulePackage);
151
+		loadImports(context, rootPackage, modulePackage);
152
+		
153
+		for (ParsedDefinition definition : this.definitions) {
154
+			if (definition.getName() != null)
155
+				definition.pkg.addType(definition.getName(), definition.getCompiling(context));
156
+		}
157
+	}
158
+	
151
 	public void compileTypes(
159
 	public void compileTypes(
152
 			ModuleTypeResolutionContext moduleContext,
160
 			ModuleTypeResolutionContext moduleContext,
153
 			ZSPackage rootPackage,
161
 			ZSPackage rootPackage,
154
 			CompilingPackage modulePackage) {
162
 			CompilingPackage modulePackage) {
155
-		FileResolutionContext context = new FileResolutionContext(moduleContext);
163
+		FileResolutionContext context = new FileResolutionContext(moduleContext, modulePackage);
156
 		loadImports(context, rootPackage, modulePackage);
164
 		loadImports(context, rootPackage, modulePackage);
165
+		
166
+		for (ParsedDefinition definition : this.definitions) {
167
+			if (definition.getName() != null)
168
+				modulePackage.addType(definition.getName(), definition.getCompiling(context));
169
+		}
170
+		
157
 		for (ParsedDefinition definition : this.definitions) {
171
 		for (ParsedDefinition definition : this.definitions) {
158
-			definition.linkTypes(context);
172
+			definition.getCompiling(context).load();
159
 		}
173
 		}
160
 	}
174
 	}
161
 	
175
 	
166
 			CompilingPackage modulePackage,
180
 			CompilingPackage modulePackage,
167
 			List<ExpansionDefinition> expansions,
181
 			List<ExpansionDefinition> expansions,
168
 			Map<String, ISymbol> globals) {
182
 			Map<String, ISymbol> globals) {
169
-		FileResolutionContext context = new FileResolutionContext(moduleContext);
183
+		FileResolutionContext context = new FileResolutionContext(moduleContext, modulePackage);
170
 		loadImports(context, rootPackage, modulePackage);
184
 		loadImports(context, rootPackage, modulePackage);
171
 		
185
 		
172
 		FileScope scope = new FileScope(context, expansions, globals, precompiler);
186
 		FileScope scope = new FileScope(context, expansions, globals, precompiler);
183
 			List<ExpansionDefinition> expansions,
197
 			List<ExpansionDefinition> expansions,
184
 			List<ScriptBlock> scripts,
198
 			List<ScriptBlock> scripts,
185
 			Map<String, ISymbol> globals) {
199
 			Map<String, ISymbol> globals) {
186
-		FileResolutionContext context = new FileResolutionContext(moduleContext);
200
+		FileResolutionContext context = new FileResolutionContext(moduleContext, modulePackage);
187
 		loadImports(context, rootPackage, modulePackage);
201
 		loadImports(context, rootPackage, modulePackage);
188
 		
202
 		
189
 		FileScope scope = new FileScope(context, expansions, globals, precompiler);
203
 		FileScope scope = new FileScope(context, expansions, globals, precompiler);

+ 28
- 12
Parser/src/main/java/org/openzen/zenscript/parser/definitions/BaseParsedDefinition.java View File

11
 import java.util.Map;
11
 import java.util.Map;
12
 import org.openzen.zencode.shared.CodePosition;
12
 import org.openzen.zencode.shared.CodePosition;
13
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
13
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
14
+import org.openzen.zenscript.codemodel.context.CompilingPackage;
14
 import org.openzen.zenscript.codemodel.context.CompilingType;
15
 import org.openzen.zenscript.codemodel.context.CompilingType;
15
 import org.openzen.zenscript.codemodel.context.LocalTypeResolutionContext;
16
 import org.openzen.zenscript.codemodel.context.LocalTypeResolutionContext;
16
 import org.openzen.zenscript.codemodel.context.TypeResolutionContext;
17
 import org.openzen.zenscript.codemodel.context.TypeResolutionContext;
28
 public abstract class BaseParsedDefinition extends ParsedDefinition {
29
 public abstract class BaseParsedDefinition extends ParsedDefinition {
29
 	protected final List<ParsedDefinitionMember> members = new ArrayList<>();
30
 	protected final List<ParsedDefinitionMember> members = new ArrayList<>();
30
 	private boolean typesCompiled = false;
31
 	private boolean typesCompiled = false;
31
-	private final Map<String, CompilingType> innerTypes = new HashMap<>();
32
+	private final Map<String, ParsedDefinition> innerTypes = new HashMap<>();
32
 	private boolean isCompiled = false;
33
 	private boolean isCompiled = false;
33
 	
34
 	
34
-	public BaseParsedDefinition(CodePosition position, int modifiers, ParsedAnnotation[] annotations) {
35
-		super(position, modifiers, annotations);
35
+	public BaseParsedDefinition(CodePosition position, int modifiers, CompilingPackage pkg, ParsedAnnotation[] annotations) {
36
+		super(position, modifiers, pkg, annotations);
36
 	}
37
 	}
37
 	
38
 	
38
 	public void addMember(ParsedDefinitionMember member) {
39
 	public void addMember(ParsedDefinitionMember member) {
47
 		typesCompiled = true;
48
 		typesCompiled = true;
48
 		
49
 		
49
 		System.out.println("compileTypes " + getCompiled().name);
50
 		System.out.println("compileTypes " + getCompiled().name);
50
-		LocalTypeResolutionContext localContext = new LocalTypeResolutionContext(context, this, getCompiled().genericParameters);
51
-		linkTypesLocal(localContext);
51
+		linkTypesLocal(context);
52
 	}
52
 	}
53
 	
53
 	
54
 	protected void linkTypesLocal(TypeResolutionContext localContext) {
54
 	protected void linkTypesLocal(TypeResolutionContext localContext) {
79
 		for (ParsedDefinitionMember member : members)
79
 		for (ParsedDefinitionMember member : members)
80
 			member.compile(innerScope);
80
 			member.compile(innerScope);
81
 	}
81
 	}
82
-	
82
+
83
 	@Override
83
 	@Override
84
-	public HighLevelDefinition load(TypeResolutionContext context) {
85
-		linkTypes(context);
86
-		return getCompiled();
84
+	public CompilingType getCompiling(TypeResolutionContext context) {
85
+		return new Compiling(context);
87
 	}
86
 	}
88
 	
87
 	
89
-	@Override
90
-	public CompilingType getInner(String name) {
91
-		return innerTypes.get(name);
88
+	private class Compiling implements CompilingType {
89
+		private final TypeResolutionContext context;
90
+		
91
+		public Compiling(TypeResolutionContext context) {
92
+			this.context = new LocalTypeResolutionContext(context, this, getCompiled().genericParameters);
93
+		}
94
+		
95
+		@Override
96
+		public HighLevelDefinition load() {
97
+			linkTypes(context);
98
+			return getCompiled();
99
+		}
100
+
101
+		@Override
102
+		public CompilingType getInner(String name) {
103
+			if (!innerTypes.containsKey(name))
104
+				return null;
105
+			
106
+			return innerTypes.get(name).getCompiling(context);
107
+		}
92
 	}
108
 	}
93
 }
109
 }

+ 27
- 15
Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedAlias.java View File

8
 import java.util.List;
8
 import java.util.List;
9
 import org.openzen.zencode.shared.CodePosition;
9
 import org.openzen.zencode.shared.CodePosition;
10
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
10
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
11
+import org.openzen.zenscript.codemodel.context.CompilingPackage;
11
 import org.openzen.zenscript.codemodel.context.CompilingType;
12
 import org.openzen.zenscript.codemodel.context.CompilingType;
12
 import org.openzen.zenscript.codemodel.context.LocalTypeResolutionContext;
13
 import org.openzen.zenscript.codemodel.context.LocalTypeResolutionContext;
13
 import org.openzen.zenscript.codemodel.context.TypeResolutionContext;
14
 import org.openzen.zenscript.codemodel.context.TypeResolutionContext;
14
 import org.openzen.zenscript.codemodel.definition.AliasDefinition;
15
 import org.openzen.zenscript.codemodel.definition.AliasDefinition;
15
-import org.openzen.zenscript.codemodel.definition.ZSPackage;
16
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
16
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
17
 import org.openzen.zenscript.lexer.ZSTokenParser;
17
 import org.openzen.zenscript.lexer.ZSTokenParser;
18
 import org.openzen.zenscript.lexer.ZSTokenType;
18
 import org.openzen.zenscript.lexer.ZSTokenType;
27
  * @author Hoofdgebruiker
27
  * @author Hoofdgebruiker
28
  */
28
  */
29
 public class ParsedAlias extends ParsedDefinition {
29
 public class ParsedAlias extends ParsedDefinition {
30
-	public static ParsedAlias parseAlias(ZSPackage pkg, CodePosition position, int modifiers, ParsedAnnotation[] annotations, ZSTokenParser tokens, HighLevelDefinition outerDefinition) {
30
+	public static ParsedAlias parseAlias(CompilingPackage pkg, CodePosition position, int modifiers, ParsedAnnotation[] annotations, ZSTokenParser tokens, HighLevelDefinition outerDefinition) {
31
 		String name = tokens.required(ZSTokenType.T_IDENTIFIER, "identifier expected").content;
31
 		String name = tokens.required(ZSTokenType.T_IDENTIFIER, "identifier expected").content;
32
 		List<ParsedTypeParameter> parameters = ParsedTypeParameter.parseAll(tokens);
32
 		List<ParsedTypeParameter> parameters = ParsedTypeParameter.parseAll(tokens);
33
 		tokens.required(ZSTokenType.K_AS, "as expected");
33
 		tokens.required(ZSTokenType.K_AS, "as expected");
43
 	private final AliasDefinition compiled;
43
 	private final AliasDefinition compiled;
44
 	private boolean typesLinked = false;
44
 	private boolean typesLinked = false;
45
 	
45
 	
46
-	public ParsedAlias(ZSPackage pkg, CodePosition position, int modifiers, ParsedAnnotation[] annotations, String name, List<ParsedTypeParameter> parameters, IParsedType type, HighLevelDefinition outerDefinition) {
47
-		super(position, modifiers, annotations);
46
+	public ParsedAlias(CompilingPackage pkg, CodePosition position, int modifiers, ParsedAnnotation[] annotations, String name, List<ParsedTypeParameter> parameters, IParsedType type, HighLevelDefinition outerDefinition) {
47
+		super(position, modifiers, pkg, annotations);
48
 		
48
 		
49
 		this.name = name;
49
 		this.name = name;
50
 		this.parameters = parameters;
50
 		this.parameters = parameters;
51
 		this.type = type;
51
 		this.type = type;
52
 		
52
 		
53
-		compiled = new AliasDefinition(position, pkg, name, modifiers, outerDefinition);
53
+		compiled = new AliasDefinition(position, pkg.getPackage(), name, modifiers, outerDefinition);
54
 		
54
 		
55
 		if (parameters != null && parameters.size() > 0) {
55
 		if (parameters != null && parameters.size() > 0) {
56
 			TypeParameter[] typeParameters = new TypeParameter[parameters.size()];
56
 			TypeParameter[] typeParameters = new TypeParameter[parameters.size()];
67
 			return;
67
 			return;
68
 		typesLinked = true;
68
 		typesLinked = true;
69
 		
69
 		
70
-		LocalTypeResolutionContext localContext = new LocalTypeResolutionContext(context, this, compiled.genericParameters);
71
-		compiled.setType(type.compile(localContext));
70
+		compiled.setType(type.compile(context));
72
 		
71
 		
73
 		for (int i = 0; i < compiled.genericParameters.length; i++) {
72
 		for (int i = 0; i < compiled.genericParameters.length; i++) {
74
 			TypeParameter output = compiled.genericParameters[i];
73
 			TypeParameter output = compiled.genericParameters[i];
75
 			ParsedTypeParameter input = this.parameters.get(i);
74
 			ParsedTypeParameter input = this.parameters.get(i);
76
 			for (ParsedGenericBound bound : input.bounds) {
75
 			for (ParsedGenericBound bound : input.bounds) {
77
-				output.addBound(bound.compile(localContext));
76
+				output.addBound(bound.compile(context));
78
 			}
77
 			}
79
 		}
78
 		}
80
 	}
79
 	}
95
 	}
94
 	}
96
 
95
 
97
 	@Override
96
 	@Override
98
-	public CompilingType getInner(String name) {
99
-		// TODO: this should be possible too
100
-		return null;
97
+	public CompilingType getCompiling(TypeResolutionContext context) {
98
+		return new Compiling(context);
101
 	}
99
 	}
100
+	
101
+	private class Compiling implements CompilingType {
102
+		private final TypeResolutionContext context;
103
+		
104
+		public Compiling(TypeResolutionContext context) {
105
+			this.context = new LocalTypeResolutionContext(context, this, compiled.genericParameters);
106
+		}
107
+		
108
+		@Override
109
+		public CompilingType getInner(String name) {
110
+			// TODO: this should be possible too
111
+			return null;
112
+		}
102
 
113
 
103
-	@Override
104
-	public HighLevelDefinition load(TypeResolutionContext context) {
105
-		linkTypes(context);
106
-		return compiled;
114
+		@Override
115
+		public HighLevelDefinition load() {
116
+			linkTypes(context);
117
+			return compiled;
118
+		}
107
 	}
119
 	}
108
 }
120
 }

+ 6
- 6
Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedClass.java View File

8
 import java.util.List;
8
 import java.util.List;
9
 import org.openzen.zencode.shared.CodePosition;
9
 import org.openzen.zencode.shared.CodePosition;
10
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
10
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
11
+import org.openzen.zenscript.codemodel.context.CompilingPackage;
11
 import org.openzen.zenscript.codemodel.context.TypeResolutionContext;
12
 import org.openzen.zenscript.codemodel.context.TypeResolutionContext;
12
 import org.openzen.zenscript.codemodel.definition.ClassDefinition;
13
 import org.openzen.zenscript.codemodel.definition.ClassDefinition;
13
-import org.openzen.zenscript.codemodel.definition.ZSPackage;
14
 import org.openzen.zenscript.lexer.ZSTokenParser;
14
 import org.openzen.zenscript.lexer.ZSTokenParser;
15
 import org.openzen.zenscript.lexer.ZSTokenType;
15
 import org.openzen.zenscript.lexer.ZSTokenType;
16
 import org.openzen.zenscript.parser.ParsedAnnotation;
16
 import org.openzen.zenscript.parser.ParsedAnnotation;
22
  * @author Stan Hebben
22
  * @author Stan Hebben
23
  */
23
  */
24
 public class ParsedClass extends BaseParsedDefinition {
24
 public class ParsedClass extends BaseParsedDefinition {
25
-	public static ParsedClass parseClass(ZSPackage pkg, CodePosition position, int modifiers, ParsedAnnotation[] annotations, ZSTokenParser tokens, HighLevelDefinition outerDefinition) {
25
+	public static ParsedClass parseClass(CompilingPackage pkg, CodePosition position, int modifiers, ParsedAnnotation[] annotations, ZSTokenParser tokens, HighLevelDefinition outerDefinition) {
26
 		String name = tokens.required(ZSTokenType.T_IDENTIFIER, "identifier expected").content;
26
 		String name = tokens.required(ZSTokenType.T_IDENTIFIER, "identifier expected").content;
27
 		List<ParsedTypeParameter> genericParameters = ParsedTypeParameter.parseAll(tokens);
27
 		List<ParsedTypeParameter> genericParameters = ParsedTypeParameter.parseAll(tokens);
28
 		
28
 		
35
 		
35
 		
36
 		ParsedClass result = new ParsedClass(pkg, position, modifiers, annotations, name, genericParameters, superclass, outerDefinition);
36
 		ParsedClass result = new ParsedClass(pkg, position, modifiers, annotations, name, genericParameters, superclass, outerDefinition);
37
 		while (tokens.optional(ZSTokenType.T_ACLOSE) == null) {
37
 		while (tokens.optional(ZSTokenType.T_ACLOSE) == null) {
38
-			result.addMember(ParsedDefinitionMember.parse(tokens, result.compiled, null));
38
+			result.addMember(ParsedDefinitionMember.parse(tokens, result, null));
39
 		}
39
 		}
40
 		return result;
40
 		return result;
41
 	}
41
 	}
45
 	
45
 	
46
 	private final ClassDefinition compiled;
46
 	private final ClassDefinition compiled;
47
 	
47
 	
48
-	public ParsedClass(ZSPackage pkg, CodePosition position, int modifiers, ParsedAnnotation[] annotations, String name, List<ParsedTypeParameter> parameters, IParsedType superclass, HighLevelDefinition outerDefinition) {
49
-		super(position, modifiers, annotations);
48
+	public ParsedClass(CompilingPackage pkg, CodePosition position, int modifiers, ParsedAnnotation[] annotations, String name, List<ParsedTypeParameter> parameters, IParsedType superclass, HighLevelDefinition outerDefinition) {
49
+		super(position, modifiers, pkg, annotations);
50
 		
50
 		
51
 		this.parameters = parameters;
51
 		this.parameters = parameters;
52
 		this.superclass = superclass;
52
 		this.superclass = superclass;
53
 		
53
 		
54
-		compiled = new ClassDefinition(position, pkg, name, modifiers, outerDefinition);
54
+		compiled = new ClassDefinition(position, pkg.getPackage(), name, modifiers, outerDefinition);
55
 		compiled.setTypeParameters(ParsedTypeParameter.getCompiled(parameters));
55
 		compiled.setTypeParameters(ParsedTypeParameter.getCompiled(parameters));
56
 	}
56
 	}
57
 
57
 

+ 6
- 7
Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedEnum.java View File

9
 import java.util.List;
9
 import java.util.List;
10
 import org.openzen.zencode.shared.CodePosition;
10
 import org.openzen.zencode.shared.CodePosition;
11
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
11
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
12
+import org.openzen.zenscript.codemodel.context.CompilingPackage;
12
 import org.openzen.zenscript.codemodel.context.TypeResolutionContext;
13
 import org.openzen.zenscript.codemodel.context.TypeResolutionContext;
13
 import org.openzen.zenscript.codemodel.definition.EnumDefinition;
14
 import org.openzen.zenscript.codemodel.definition.EnumDefinition;
14
-import org.openzen.zenscript.codemodel.definition.ZSPackage;
15
 import org.openzen.zenscript.codemodel.type.DefinitionTypeID;
15
 import org.openzen.zenscript.codemodel.type.DefinitionTypeID;
16
 import org.openzen.zenscript.codemodel.type.ITypeID;
16
 import org.openzen.zenscript.codemodel.type.ITypeID;
17
 import org.openzen.zenscript.lexer.ZSTokenParser;
17
 import org.openzen.zenscript.lexer.ZSTokenParser;
19
 import org.openzen.zenscript.codemodel.scope.BaseScope;
19
 import org.openzen.zenscript.codemodel.scope.BaseScope;
20
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
20
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
21
 import org.openzen.zenscript.parser.ParsedAnnotation;
21
 import org.openzen.zenscript.parser.ParsedAnnotation;
22
-import org.openzen.zenscript.parser.PrecompilationState;
23
 import org.openzen.zenscript.parser.member.ParsedDefinitionMember;
22
 import org.openzen.zenscript.parser.member.ParsedDefinitionMember;
24
 
23
 
25
 /**
24
 /**
27
  * @author Hoofdgebruiker
26
  * @author Hoofdgebruiker
28
  */
27
  */
29
 public class ParsedEnum extends BaseParsedDefinition {
28
 public class ParsedEnum extends BaseParsedDefinition {
30
-	public static ParsedEnum parseEnum(ZSPackage pkg, CodePosition position, int modifiers, ParsedAnnotation[] annotations, ZSTokenParser tokens, HighLevelDefinition outerDefinition) {
29
+	public static ParsedEnum parseEnum(CompilingPackage pkg, CodePosition position, int modifiers, ParsedAnnotation[] annotations, ZSTokenParser tokens, HighLevelDefinition outerDefinition) {
31
 		String name = tokens.required(ZSTokenType.T_IDENTIFIER, "identifier expected").content;
30
 		String name = tokens.required(ZSTokenType.T_IDENTIFIER, "identifier expected").content;
32
 		tokens.required(ZSTokenType.T_AOPEN, "{ expected");
31
 		tokens.required(ZSTokenType.T_AOPEN, "{ expected");
33
 		
32
 		
41
 		
40
 		
42
 		if (tokens.optional(ZSTokenType.T_SEMICOLON) != null) {
41
 		if (tokens.optional(ZSTokenType.T_SEMICOLON) != null) {
43
 			while (tokens.optional(ZSTokenType.T_ACLOSE) == null) {
42
 			while (tokens.optional(ZSTokenType.T_ACLOSE) == null) {
44
-				result.addMember(ParsedDefinitionMember.parse(tokens, result.compiled, null));
43
+				result.addMember(ParsedDefinitionMember.parse(tokens, result, null));
45
 			}
44
 			}
46
 		} else {
45
 		} else {
47
 			tokens.required(ZSTokenType.T_ACLOSE, "} expected");
46
 			tokens.required(ZSTokenType.T_ACLOSE, "} expected");
53
 	
52
 	
54
 	private final EnumDefinition compiled;
53
 	private final EnumDefinition compiled;
55
 	
54
 	
56
-	public ParsedEnum(ZSPackage pkg, CodePosition position, int modifiers, ParsedAnnotation[] annotations, String name, HighLevelDefinition outerDefinition) {
57
-		super(position, modifiers, annotations);
55
+	public ParsedEnum(CompilingPackage pkg, CodePosition position, int modifiers, ParsedAnnotation[] annotations, String name, HighLevelDefinition outerDefinition) {
56
+		super(position, modifiers, pkg, annotations);
58
 		
57
 		
59
-		compiled = new EnumDefinition(position, pkg, name, modifiers, outerDefinition);
58
+		compiled = new EnumDefinition(position, pkg.getPackage(), name, modifiers, outerDefinition);
60
 	}
59
 	}
61
 	
60
 	
62
 	public void addEnumValue(ParsedEnumConstant value) {
61
 	public void addEnumValue(ParsedEnumConstant value) {

+ 6
- 9
Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedExpansion.java View File

10
 import org.openzen.zencode.shared.CompileException;
10
 import org.openzen.zencode.shared.CompileException;
11
 import org.openzen.zencode.shared.CompileExceptionCode;
11
 import org.openzen.zencode.shared.CompileExceptionCode;
12
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
12
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
13
-import org.openzen.zenscript.codemodel.context.LocalTypeResolutionContext;
13
+import org.openzen.zenscript.codemodel.context.CompilingPackage;
14
 import org.openzen.zenscript.codemodel.context.TypeResolutionContext;
14
 import org.openzen.zenscript.codemodel.context.TypeResolutionContext;
15
 import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
15
 import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
16
-import org.openzen.zenscript.codemodel.definition.ZSPackage;
17
 import org.openzen.zenscript.lexer.ZSTokenParser;
16
 import org.openzen.zenscript.lexer.ZSTokenParser;
18
 import org.openzen.zenscript.lexer.ZSTokenType;
17
 import org.openzen.zenscript.lexer.ZSTokenType;
19
-import org.openzen.zenscript.codemodel.scope.BaseScope;
20
-import org.openzen.zenscript.codemodel.scope.GenericFunctionScope;
21
 import org.openzen.zenscript.parser.ParsedAnnotation;
18
 import org.openzen.zenscript.parser.ParsedAnnotation;
22
 import org.openzen.zenscript.parser.member.ParsedDefinitionMember;
19
 import org.openzen.zenscript.parser.member.ParsedDefinitionMember;
23
 import org.openzen.zenscript.parser.type.IParsedType;
20
 import org.openzen.zenscript.parser.type.IParsedType;
27
  * @author Hoofdgebruiker
24
  * @author Hoofdgebruiker
28
  */
25
  */
29
 public class ParsedExpansion extends BaseParsedDefinition {
26
 public class ParsedExpansion extends BaseParsedDefinition {
30
-	public static ParsedExpansion parseExpansion(ZSPackage pkg, CodePosition position, int modifiers, ParsedAnnotation[] annotations, ZSTokenParser tokens, HighLevelDefinition outerDefinition) {
27
+	public static ParsedExpansion parseExpansion(CompilingPackage pkg, CodePosition position, int modifiers, ParsedAnnotation[] annotations, ZSTokenParser tokens, HighLevelDefinition outerDefinition) {
31
 		List<ParsedTypeParameter> parameters = ParsedTypeParameter.parseAll(tokens);
28
 		List<ParsedTypeParameter> parameters = ParsedTypeParameter.parseAll(tokens);
32
 		IParsedType target = IParsedType.parse(tokens);
29
 		IParsedType target = IParsedType.parse(tokens);
33
 		tokens.required(ZSTokenType.T_AOPEN, "{ expected");
30
 		tokens.required(ZSTokenType.T_AOPEN, "{ expected");
34
 		
31
 		
35
 		ParsedExpansion result = new ParsedExpansion(pkg, position, modifiers, annotations, parameters, target, outerDefinition);
32
 		ParsedExpansion result = new ParsedExpansion(pkg, position, modifiers, annotations, parameters, target, outerDefinition);
36
 		while (tokens.optional(ZSTokenType.T_ACLOSE) == null) {
33
 		while (tokens.optional(ZSTokenType.T_ACLOSE) == null) {
37
-			result.addMember(ParsedDefinitionMember.parse(tokens, result.compiled, null));
34
+			result.addMember(ParsedDefinitionMember.parse(tokens, result, null));
38
 		}
35
 		}
39
 		return result;
36
 		return result;
40
 	}
37
 	}
43
 	private final IParsedType target;
40
 	private final IParsedType target;
44
 	private final ExpansionDefinition compiled;
41
 	private final ExpansionDefinition compiled;
45
 	
42
 	
46
-	public ParsedExpansion(ZSPackage pkg, CodePosition position, int modifiers, ParsedAnnotation[] annotations, List<ParsedTypeParameter> genericParameters, IParsedType target, HighLevelDefinition outerDefinition) {
47
-		super(position, modifiers, annotations);
43
+	public ParsedExpansion(CompilingPackage pkg, CodePosition position, int modifiers, ParsedAnnotation[] annotations, List<ParsedTypeParameter> genericParameters, IParsedType target, HighLevelDefinition outerDefinition) {
44
+		super(position, modifiers, pkg, annotations);
48
 		
45
 		
49
 		this.parameters = genericParameters;
46
 		this.parameters = genericParameters;
50
 		this.target = target;
47
 		this.target = target;
51
 		
48
 		
52
-		compiled = new ExpansionDefinition(position, pkg, modifiers, outerDefinition);
49
+		compiled = new ExpansionDefinition(position, pkg.getPackage(), modifiers, outerDefinition);
53
 		compiled.setTypeParameters(ParsedTypeParameter.getCompiled(genericParameters));
50
 		compiled.setTypeParameters(ParsedTypeParameter.getCompiled(genericParameters));
54
 	}
51
 	}
55
 	
52
 	

+ 23
- 10
Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedFunction.java View File

9
 import org.openzen.zencode.shared.CodePosition;
9
 import org.openzen.zencode.shared.CodePosition;
10
 import static org.openzen.zenscript.lexer.ZSTokenType.*;
10
 import static org.openzen.zenscript.lexer.ZSTokenType.*;
11
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
11
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
12
+import org.openzen.zenscript.codemodel.context.CompilingPackage;
12
 import org.openzen.zenscript.codemodel.context.CompilingType;
13
 import org.openzen.zenscript.codemodel.context.CompilingType;
13
 import org.openzen.zenscript.codemodel.context.TypeResolutionContext;
14
 import org.openzen.zenscript.codemodel.context.TypeResolutionContext;
14
 import org.openzen.zenscript.codemodel.definition.FunctionDefinition;
15
 import org.openzen.zenscript.codemodel.definition.FunctionDefinition;
15
-import org.openzen.zenscript.codemodel.definition.ZSPackage;
16
 import org.openzen.zenscript.lexer.ZSTokenParser;
16
 import org.openzen.zenscript.lexer.ZSTokenParser;
17
 import org.openzen.zenscript.codemodel.scope.BaseScope;
17
 import org.openzen.zenscript.codemodel.scope.BaseScope;
18
 import org.openzen.zenscript.codemodel.scope.FunctionScope;
18
 import org.openzen.zenscript.codemodel.scope.FunctionScope;
28
  * @author Stanneke
28
  * @author Stanneke
29
  */
29
  */
30
 public class ParsedFunction extends ParsedDefinition {
30
 public class ParsedFunction extends ParsedDefinition {
31
-	public static ParsedFunction parseFunction(ZSPackage pkg, CodePosition position, int modifiers, ParsedAnnotation[] annotations, ZSTokenParser parser, HighLevelDefinition outerDefinition) {
31
+	public static ParsedFunction parseFunction(CompilingPackage pkg, CodePosition position, int modifiers, ParsedAnnotation[] annotations, ZSTokenParser parser, HighLevelDefinition outerDefinition) {
32
 		String name = parser.required(T_IDENTIFIER, "identifier expected").content;
32
 		String name = parser.required(T_IDENTIFIER, "identifier expected").content;
33
 		ParsedFunctionHeader header = ParsedFunctionHeader.parse(parser);
33
 		ParsedFunctionHeader header = ParsedFunctionHeader.parse(parser);
34
 		ParsedFunctionBody body = ParsedStatement.parseFunctionBody(parser);
34
 		ParsedFunctionBody body = ParsedStatement.parseFunctionBody(parser);
40
 
40
 
41
 	private final FunctionDefinition compiled;
41
 	private final FunctionDefinition compiled;
42
 	
42
 	
43
-	private ParsedFunction(ZSPackage pkg, CodePosition position, int modifiers, ParsedAnnotation[] annotations, String name, ParsedFunctionHeader header, ParsedFunctionBody body, HighLevelDefinition outerDefinition) {
44
-		super(position, modifiers, annotations);
43
+	private ParsedFunction(CompilingPackage pkg, CodePosition position, int modifiers, ParsedAnnotation[] annotations, String name, ParsedFunctionHeader header, ParsedFunctionBody body, HighLevelDefinition outerDefinition) {
44
+		super(position, modifiers, pkg, annotations);
45
 		
45
 		
46
 		this.header = header;
46
 		this.header = header;
47
 		this.body = body;
47
 		this.body = body;
48
 		
48
 		
49
-		compiled = new FunctionDefinition(position, pkg, name, modifiers, outerDefinition);
49
+		compiled = new FunctionDefinition(position, pkg.getPackage(), name, modifiers, outerDefinition);
50
 	}
50
 	}
51
 
51
 
52
 	@Override
52
 	@Override
75
 	}
75
 	}
76
 
76
 
77
 	@Override
77
 	@Override
78
-	public CompilingType getInner(String name) {
79
-		return null;
78
+	public CompilingType getCompiling(TypeResolutionContext context) {
79
+		return new Compiling(context);
80
 	}
80
 	}
81
 
81
 
82
-	@Override
83
-	public HighLevelDefinition load(TypeResolutionContext context) {
84
-		return compiled;
82
+	private class Compiling implements CompilingType {
83
+		private final TypeResolutionContext context;
84
+		
85
+		public Compiling(TypeResolutionContext context) {
86
+			this.context = context;
87
+		}
88
+		
89
+		@Override
90
+		public CompilingType getInner(String name) {
91
+			return null;
92
+		}
93
+
94
+		@Override
95
+		public HighLevelDefinition load() {
96
+			return compiled;
97
+		}
85
 	}
98
 	}
86
 }
99
 }

+ 6
- 6
Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedInterface.java View File

10
 import java.util.List;
10
 import java.util.List;
11
 import org.openzen.zencode.shared.CodePosition;
11
 import org.openzen.zencode.shared.CodePosition;
12
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
12
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
13
+import org.openzen.zenscript.codemodel.context.CompilingPackage;
13
 import org.openzen.zenscript.codemodel.context.TypeResolutionContext;
14
 import org.openzen.zenscript.codemodel.context.TypeResolutionContext;
14
 import org.openzen.zenscript.codemodel.definition.InterfaceDefinition;
15
 import org.openzen.zenscript.codemodel.definition.InterfaceDefinition;
15
-import org.openzen.zenscript.codemodel.definition.ZSPackage;
16
 import org.openzen.zenscript.lexer.ZSTokenParser;
16
 import org.openzen.zenscript.lexer.ZSTokenParser;
17
 import org.openzen.zenscript.lexer.ZSTokenType;
17
 import org.openzen.zenscript.lexer.ZSTokenType;
18
 import org.openzen.zenscript.parser.ParsedAnnotation;
18
 import org.openzen.zenscript.parser.ParsedAnnotation;
24
  * @author Hoofdgebruiker
24
  * @author Hoofdgebruiker
25
  */
25
  */
26
 public class ParsedInterface extends BaseParsedDefinition {
26
 public class ParsedInterface extends BaseParsedDefinition {
27
-	public static ParsedInterface parseInterface(ZSPackage pkg, CodePosition position, int modifiers, ParsedAnnotation[] annotations, ZSTokenParser tokens, HighLevelDefinition outerDefinition) {
27
+	public static ParsedInterface parseInterface(CompilingPackage pkg, CodePosition position, int modifiers, ParsedAnnotation[] annotations, ZSTokenParser tokens, HighLevelDefinition outerDefinition) {
28
 		String name = tokens.required(ZSTokenType.T_IDENTIFIER, "identifier expected").content;
28
 		String name = tokens.required(ZSTokenType.T_IDENTIFIER, "identifier expected").content;
29
 		List<ParsedTypeParameter> genericParameters = ParsedTypeParameter.parseAll(tokens);
29
 		List<ParsedTypeParameter> genericParameters = ParsedTypeParameter.parseAll(tokens);
30
 		List<IParsedType> superInterfaces = Collections.emptyList();
30
 		List<IParsedType> superInterfaces = Collections.emptyList();
39
 		
39
 		
40
 		ParsedInterface result = new ParsedInterface(pkg, position, modifiers, annotations, name, genericParameters, superInterfaces, outerDefinition);
40
 		ParsedInterface result = new ParsedInterface(pkg, position, modifiers, annotations, name, genericParameters, superInterfaces, outerDefinition);
41
 		while (tokens.optional(ZSTokenType.T_ACLOSE) == null) {
41
 		while (tokens.optional(ZSTokenType.T_ACLOSE) == null) {
42
-			result.addMember(ParsedDefinitionMember.parse(tokens, result.compiled, null));
42
+			result.addMember(ParsedDefinitionMember.parse(tokens, result, null));
43
 		}
43
 		}
44
 		return result;
44
 		return result;
45
 	}
45
 	}
49
 	
49
 	
50
 	private final InterfaceDefinition compiled;
50
 	private final InterfaceDefinition compiled;
51
 	
51
 	
52
-	public ParsedInterface(ZSPackage pkg, CodePosition position, int modifiers, ParsedAnnotation[] annotations, String name, List<ParsedTypeParameter> typeParameters, List<IParsedType> superInterfaces, HighLevelDefinition outerDefinition) {
53
-		super(position, modifiers, annotations);
52
+	public ParsedInterface(CompilingPackage pkg, CodePosition position, int modifiers, ParsedAnnotation[] annotations, String name, List<ParsedTypeParameter> typeParameters, List<IParsedType> superInterfaces, HighLevelDefinition outerDefinition) {
53
+		super(position, modifiers, pkg, annotations);
54
 		
54
 		
55
 		this.typeParameters = typeParameters;
55
 		this.typeParameters = typeParameters;
56
 		this.superInterfaces = superInterfaces;
56
 		this.superInterfaces = superInterfaces;
57
 		
57
 		
58
-		compiled = new InterfaceDefinition(position, pkg, name, modifiers, outerDefinition);
58
+		compiled = new InterfaceDefinition(position, pkg.getPackage(), name, modifiers, outerDefinition);
59
 		compiled.setTypeParameters(ParsedTypeParameter.getCompiled(typeParameters));
59
 		compiled.setTypeParameters(ParsedTypeParameter.getCompiled(typeParameters));
60
 	}
60
 	}
61
 
61
 

+ 6
- 7
Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedStruct.java View File

8
 import java.util.List;
8
 import java.util.List;
9
 import org.openzen.zencode.shared.CodePosition;
9
 import org.openzen.zencode.shared.CodePosition;
10
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
10
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
11
+import org.openzen.zenscript.codemodel.context.CompilingPackage;
11
 import org.openzen.zenscript.codemodel.context.TypeResolutionContext;
12
 import org.openzen.zenscript.codemodel.context.TypeResolutionContext;
12
 import org.openzen.zenscript.codemodel.definition.StructDefinition;
13
 import org.openzen.zenscript.codemodel.definition.StructDefinition;
13
-import org.openzen.zenscript.codemodel.definition.ZSPackage;
14
 import org.openzen.zenscript.lexer.ZSTokenParser;
14
 import org.openzen.zenscript.lexer.ZSTokenParser;
15
 import org.openzen.zenscript.lexer.ZSTokenType;
15
 import org.openzen.zenscript.lexer.ZSTokenType;
16
-import org.openzen.zenscript.codemodel.scope.BaseScope;
17
 import org.openzen.zenscript.parser.ParsedAnnotation;
16
 import org.openzen.zenscript.parser.ParsedAnnotation;
18
 import org.openzen.zenscript.parser.member.ParsedDefinitionMember;
17
 import org.openzen.zenscript.parser.member.ParsedDefinitionMember;
19
 
18
 
22
  * @author Hoofdgebruiker
21
  * @author Hoofdgebruiker
23
  */
22
  */
24
 public class ParsedStruct extends BaseParsedDefinition {
23
 public class ParsedStruct extends BaseParsedDefinition {
25
-	public static ParsedStruct parseStruct(ZSPackage pkg, CodePosition position, int modifiers, ParsedAnnotation[] annotations, ZSTokenParser tokens, HighLevelDefinition outerDefinition) {
24
+	public static ParsedStruct parseStruct(CompilingPackage pkg, CodePosition position, int modifiers, ParsedAnnotation[] annotations, ZSTokenParser tokens, HighLevelDefinition outerDefinition) {
26
 		String name = tokens.required(ZSTokenType.T_IDENTIFIER, "identifier expected").content;
25
 		String name = tokens.required(ZSTokenType.T_IDENTIFIER, "identifier expected").content;
27
 		List<ParsedTypeParameter> parameters = ParsedTypeParameter.parseAll(tokens);
26
 		List<ParsedTypeParameter> parameters = ParsedTypeParameter.parseAll(tokens);
28
 		
27
 		
30
 		
29
 		
31
 		ParsedStruct result = new ParsedStruct(pkg, position, modifiers, annotations, name, parameters, outerDefinition);
30
 		ParsedStruct result = new ParsedStruct(pkg, position, modifiers, annotations, name, parameters, outerDefinition);
32
 		while (tokens.optional(ZSTokenType.T_ACLOSE) == null) {
31
 		while (tokens.optional(ZSTokenType.T_ACLOSE) == null) {
33
-			result.addMember(ParsedDefinitionMember.parse(tokens, result.compiled, null));
32
+			result.addMember(ParsedDefinitionMember.parse(tokens, result, null));
34
 		}
33
 		}
35
 		return result;
34
 		return result;
36
 	}
35
 	}
39
 	
38
 	
40
 	private final StructDefinition compiled;
39
 	private final StructDefinition compiled;
41
 	
40
 	
42
-	public ParsedStruct(ZSPackage pkg, CodePosition position, int modifiers, ParsedAnnotation[] annotations, String name, List<ParsedTypeParameter> genericParameters, HighLevelDefinition outerDefinition) {
43
-		super(position, modifiers, annotations);
41
+	public ParsedStruct(CompilingPackage pkg, CodePosition position, int modifiers, ParsedAnnotation[] annotations, String name, List<ParsedTypeParameter> genericParameters, HighLevelDefinition outerDefinition) {
42
+		super(position, modifiers, pkg, annotations);
44
 		
43
 		
45
 		this.parameters = genericParameters;
44
 		this.parameters = genericParameters;
46
 		
45
 		
47
-		compiled = new StructDefinition(position, pkg, name, modifiers, outerDefinition);
46
+		compiled = new StructDefinition(position, pkg.getPackage(), name, modifiers, outerDefinition);
48
 		compiled.setTypeParameters(ParsedTypeParameter.getCompiled(genericParameters));
47
 		compiled.setTypeParameters(ParsedTypeParameter.getCompiled(genericParameters));
49
 	}
48
 	}
50
 
49
 

+ 6
- 6
Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedVariant.java View File

9
 import java.util.List;
9
 import java.util.List;
10
 import org.openzen.zencode.shared.CodePosition;
10
 import org.openzen.zencode.shared.CodePosition;
11
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
11
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
12
+import org.openzen.zenscript.codemodel.context.CompilingPackage;
12
 import org.openzen.zenscript.codemodel.context.TypeResolutionContext;
13
 import org.openzen.zenscript.codemodel.context.TypeResolutionContext;
13
 import org.openzen.zenscript.codemodel.definition.VariantDefinition;
14
 import org.openzen.zenscript.codemodel.definition.VariantDefinition;
14
-import org.openzen.zenscript.codemodel.definition.ZSPackage;
15
 import org.openzen.zenscript.lexer.ZSTokenParser;
15
 import org.openzen.zenscript.lexer.ZSTokenParser;
16
 import org.openzen.zenscript.lexer.ZSTokenType;
16
 import org.openzen.zenscript.lexer.ZSTokenType;
17
 import org.openzen.zenscript.parser.ParsedAnnotation;
17
 import org.openzen.zenscript.parser.ParsedAnnotation;
23
  * @author Hoofdgebruiker
23
  * @author Hoofdgebruiker
24
  */
24
  */
25
 public class ParsedVariant extends BaseParsedDefinition {
25
 public class ParsedVariant extends BaseParsedDefinition {
26
-	public static ParsedVariant parseVariant(ZSPackage pkg, CodePosition position, int modifiers, ParsedAnnotation[] annotations, ZSTokenParser tokens, HighLevelDefinition outerDefinition) {
26
+	public static ParsedVariant parseVariant(CompilingPackage pkg, CodePosition position, int modifiers, ParsedAnnotation[] annotations, ZSTokenParser tokens, HighLevelDefinition outerDefinition) {
27
 		String name = tokens.required(ZSTokenType.T_IDENTIFIER, "identifier expected").content;
27
 		String name = tokens.required(ZSTokenType.T_IDENTIFIER, "identifier expected").content;
28
 		List<ParsedTypeParameter> typeParameters = ParsedTypeParameter.parseAll(tokens);
28
 		List<ParsedTypeParameter> typeParameters = ParsedTypeParameter.parseAll(tokens);
29
 		tokens.required(ZSTokenType.T_AOPEN, "{ expected");
29
 		tokens.required(ZSTokenType.T_AOPEN, "{ expected");
47
 		
47
 		
48
 		if (tokens.optional(ZSTokenType.T_SEMICOLON) != null) {
48
 		if (tokens.optional(ZSTokenType.T_SEMICOLON) != null) {
49
 			while (tokens.optional(ZSTokenType.T_ACLOSE) == null) {
49
 			while (tokens.optional(ZSTokenType.T_ACLOSE) == null) {
50
-				result.addMember(ParsedDefinitionMember.parse(tokens, result.compiled, null));
50
+				result.addMember(ParsedDefinitionMember.parse(tokens, result, null));
51
 			}
51
 			}
52
 		} else {
52
 		} else {
53
 			tokens.required(ZSTokenType.T_ACLOSE, "} expected");
53
 			tokens.required(ZSTokenType.T_ACLOSE, "} expected");
60
 	
60
 	
61
 	private final VariantDefinition compiled;
61
 	private final VariantDefinition compiled;
62
 	
62
 	
63
-	public ParsedVariant(ZSPackage pkg, CodePosition position, int modifiers, ParsedAnnotation[] annotations, String name, List<ParsedTypeParameter> typeParameters, HighLevelDefinition outerDefinition) {
64
-		super(position, modifiers, annotations);
63
+	public ParsedVariant(CompilingPackage pkg, CodePosition position, int modifiers, ParsedAnnotation[] annotations, String name, List<ParsedTypeParameter> typeParameters, HighLevelDefinition outerDefinition) {
64
+		super(position, modifiers, pkg, annotations);
65
 		
65
 		
66
 		this.typeParameters = typeParameters;
66
 		this.typeParameters = typeParameters;
67
-		compiled = new VariantDefinition(position, pkg, name, modifiers, outerDefinition);
67
+		compiled = new VariantDefinition(position, pkg.getPackage(), name, modifiers, outerDefinition);
68
 		compiled.setTypeParameters(ParsedTypeParameter.getCompiled(typeParameters));
68
 		compiled.setTypeParameters(ParsedTypeParameter.getCompiled(typeParameters));
69
 	}
69
 	}
70
 	
70
 	

+ 19
- 20
Parser/src/main/java/org/openzen/zenscript/parser/member/ParsedDefinitionMember.java View File

15
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
15
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
16
 import org.openzen.zenscript.codemodel.Modifiers;
16
 import org.openzen.zenscript.codemodel.Modifiers;
17
 import org.openzen.zenscript.codemodel.OperatorType;
17
 import org.openzen.zenscript.codemodel.OperatorType;
18
-import org.openzen.zenscript.codemodel.context.CompilingType;
19
 import org.openzen.zenscript.codemodel.context.TypeResolutionContext;
18
 import org.openzen.zenscript.codemodel.context.TypeResolutionContext;
20
 import org.openzen.zenscript.codemodel.member.IDefinitionMember;
19
 import org.openzen.zenscript.codemodel.member.IDefinitionMember;
21
 import org.openzen.zenscript.lexer.ZSToken;
20
 import org.openzen.zenscript.lexer.ZSToken;
35
  * @author Hoofdgebruiker
34
  * @author Hoofdgebruiker
36
  */
35
  */
37
 public abstract class ParsedDefinitionMember {
36
 public abstract class ParsedDefinitionMember {
38
-	public static ParsedDefinitionMember parse(ZSTokenParser tokens, HighLevelDefinition forDefinition, ParsedImplementation forImplementation) {
37
+	public static ParsedDefinitionMember parse(ZSTokenParser tokens, ParsedDefinition forDefinition, ParsedImplementation forImplementation) {
39
 		CodePosition start = tokens.getPosition();
38
 		CodePosition start = tokens.getPosition();
40
 		ParsedAnnotation[] annotations = ParsedAnnotation.parseAnnotations(tokens);
39
 		ParsedAnnotation[] annotations = ParsedAnnotation.parseAnnotations(tokens);
41
 		int modifiers = 0;
40
 		int modifiers = 0;
127
 					initializer = ParsedExpression.parse(tokens);
126
 					initializer = ParsedExpression.parse(tokens);
128
 				}
127
 				}
129
 				tokens.required(ZSTokenType.T_SEMICOLON, "; expected");
128
 				tokens.required(ZSTokenType.T_SEMICOLON, "; expected");
130
-				return new ParsedField(start, forDefinition, modifiers, annotations, name, type, initializer, t.type == ZSTokenType.K_VAL, autoGetter, autoSetter);
129
+				return new ParsedField(start, forDefinition.getCompiled(), modifiers, annotations, name, type, initializer, t.type == ZSTokenType.K_VAL, autoGetter, autoSetter);
131
 			}
130
 			}
132
 			case K_THIS: {
131
 			case K_THIS: {
133
 				tokens.next();
132
 				tokens.next();
136
 				if (body == null)
135
 				if (body == null)
137
 					throw new CompileException(start, CompileExceptionCode.METHOD_BODY_REQUIRED, "Function body is required for constructors");
136
 					throw new CompileException(start, CompileExceptionCode.METHOD_BODY_REQUIRED, "Function body is required for constructors");
138
 				
137
 				
139
-				return new ParsedConstructor(start, forDefinition, forImplementation, modifiers, annotations, header, body);
138
+				return new ParsedConstructor(start, forDefinition.getCompiled(), forImplementation, modifiers, annotations, header, body);
140
 			}
139
 			}
141
 			case T_IDENTIFIER: {
140
 			case T_IDENTIFIER: {
142
 				String name = tokens.next().content;
141
 				String name = tokens.next().content;
148
 					tokens.required(ZSTokenType.T_ASSIGN, "= expected");
147
 					tokens.required(ZSTokenType.T_ASSIGN, "= expected");
149
 					ParsedExpression value = ParsedExpression.parse(tokens);
148
 					ParsedExpression value = ParsedExpression.parse(tokens);
150
 					tokens.required(ZSTokenType.T_SEMICOLON, "; expected");
149
 					tokens.required(ZSTokenType.T_SEMICOLON, "; expected");
151
-					return new ParsedConst(start, forDefinition, modifiers & ~Modifiers.CONST, annotations, name, type, value);
150
+					return new ParsedConst(start, forDefinition.getCompiled(), modifiers & ~Modifiers.CONST, annotations, name, type, value);
152
 				}
151
 				}
153
 				
152
 				
154
 				ParsedFunctionHeader header = ParsedFunctionHeader.parse(tokens);
153
 				ParsedFunctionHeader header = ParsedFunctionHeader.parse(tokens);
155
 				ParsedFunctionBody body = ParsedStatement.parseFunctionBody(tokens);
154
 				ParsedFunctionBody body = ParsedStatement.parseFunctionBody(tokens);
156
-				return new ParsedMethod(start, forDefinition, forImplementation, modifiers, annotations, name, header, body);
155
+				return new ParsedMethod(start, forDefinition.getCompiled(), forImplementation, modifiers, annotations, name, header, body);
157
 			}
156
 			}
158
 			case K_SET: {
157
 			case K_SET: {
159
 				tokens.next();
158
 				tokens.next();
163
 					type = IParsedType.parse(tokens);
162
 					type = IParsedType.parse(tokens);
164
 				}
163
 				}
165
 				ParsedFunctionBody body = ParsedStatement.parseFunctionBody(tokens);
164
 				ParsedFunctionBody body = ParsedStatement.parseFunctionBody(tokens);
166
-				return new ParsedSetter(start, forDefinition, forImplementation, modifiers, annotations, name, type, body);
165
+				return new ParsedSetter(start, forDefinition.getCompiled(), forImplementation, modifiers, annotations, name, type, body);
167
 			}
166
 			}
168
 			case K_GET: {
167
 			case K_GET: {
169
 				tokens.next();
168
 				tokens.next();
173
 					type = IParsedType.parse(tokens);
172
 					type = IParsedType.parse(tokens);
174
 				}
173
 				}
175
 				ParsedFunctionBody statements = ParsedStatement.parseFunctionBody(tokens);
174
 				ParsedFunctionBody statements = ParsedStatement.parseFunctionBody(tokens);
176
-				return new ParsedGetter(start, forDefinition, forImplementation, modifiers, annotations, name, type, statements);
175
+				return new ParsedGetter(start, forDefinition.getCompiled(), forImplementation, modifiers, annotations, name, type, statements);
177
 			}
176
 			}
178
 			case K_IMPLEMENTS: {
177
 			case K_IMPLEMENTS: {
179
 				tokens.next();
178
 				tokens.next();
180
 				IParsedType type = IParsedType.parse(tokens);
179
 				IParsedType type = IParsedType.parse(tokens);
181
-				ParsedImplementation implementation = new ParsedImplementation(start, forDefinition, modifiers, annotations, type);
180
+				ParsedImplementation implementation = new ParsedImplementation(start, forDefinition.getCompiled(), modifiers, annotations, type);
182
 				if (tokens.optional(ZSTokenType.T_SEMICOLON) == null) {
181
 				if (tokens.optional(ZSTokenType.T_SEMICOLON) == null) {
183
 					tokens.required(ZSTokenType.T_AOPEN, "{ expected");
182
 					tokens.required(ZSTokenType.T_AOPEN, "{ expected");
184
 					while (tokens.optional(ZSTokenType.T_ACLOSE) == null) {
183
 					while (tokens.optional(ZSTokenType.T_ACLOSE) == null) {
190
 			case T_BROPEN: {
189
 			case T_BROPEN: {
191
 				ParsedFunctionHeader header = ParsedFunctionHeader.parse(tokens);
190
 				ParsedFunctionHeader header = ParsedFunctionHeader.parse(tokens);
192
 				ParsedFunctionBody body = ParsedStatement.parseFunctionBody(tokens);
191
 				ParsedFunctionBody body = ParsedStatement.parseFunctionBody(tokens);
193
-				return new ParsedCaller(start, forDefinition, forImplementation, modifiers, annotations, header, body);
192
+				return new ParsedCaller(start, forDefinition.getCompiled(), forImplementation, modifiers, annotations, header, body);
194
 			}
193
 			}
195
 			case T_SQOPEN: {
194
 			case T_SQOPEN: {
196
 				tokens.next();
195
 				tokens.next();
201
 				}
200
 				}
202
 				ParsedFunctionHeader header = ParsedFunctionHeader.parse(tokens);
201
 				ParsedFunctionHeader header = ParsedFunctionHeader.parse(tokens);
203
 				ParsedFunctionBody body = ParsedStatement.parseFunctionBody(tokens);
202
 				ParsedFunctionBody body = ParsedStatement.parseFunctionBody(tokens);
204
-				return new ParsedOperator(start, forDefinition, forImplementation, modifiers, annotations, operator, header, body);
203
+				return new ParsedOperator(start, forDefinition.getCompiled(), forImplementation, modifiers, annotations, operator, header, body);
205
 			}
204
 			}
206
 			case T_CAT:
205
 			case T_CAT:
207
 				tokens.pushMark();
206
 				tokens.pushMark();
211
 					
210
 					
212
 					// destructor
211
 					// destructor
213
 					ParsedFunctionBody body = ParsedStatement.parseFunctionBody(tokens);
212
 					ParsedFunctionBody body = ParsedStatement.parseFunctionBody(tokens);
214
-					return new ParsedDestructor(start, forDefinition, forImplementation, modifiers, annotations, body);
213
+					return new ParsedDestructor(start, forDefinition.getCompiled(), forImplementation, modifiers, annotations, body);
215
 				}
214
 				}
216
 				tokens.reset();
215
 				tokens.reset();
217
 				// else it is a ~ operator, continue...
216
 				// else it is a ~ operator, continue...
245
 				ZSToken token = tokens.next();
244
 				ZSToken token = tokens.next();
246
 				ParsedFunctionHeader header = ParsedFunctionHeader.parse(tokens);
245
 				ParsedFunctionHeader header = ParsedFunctionHeader.parse(tokens);
247
 				ParsedFunctionBody body = ParsedStatement.parseFunctionBody(tokens);
246
 				ParsedFunctionBody body = ParsedStatement.parseFunctionBody(tokens);
248
-				return new ParsedOperator(start, forDefinition, forImplementation, modifiers, annotations, getOperator(token.type), header, body);
247
+				return new ParsedOperator(start, forDefinition.getCompiled(), forImplementation, modifiers, annotations, getOperator(token.type), header, body);
249
 			}
248
 			}
250
 			case T_EQUAL2: {
249
 			case T_EQUAL2: {
251
 				tokens.next();
250
 				tokens.next();
252
 				ParsedFunctionHeader header = ParsedFunctionHeader.parse(tokens);
251
 				ParsedFunctionHeader header = ParsedFunctionHeader.parse(tokens);
253
 				ParsedFunctionBody body = ParsedStatement.parseFunctionBody(tokens);
252
 				ParsedFunctionBody body = ParsedStatement.parseFunctionBody(tokens);
254
-				return new ParsedOperator(start, forDefinition, forImplementation, modifiers, annotations, OperatorType.EQUALS, header, body);
253
+				return new ParsedOperator(start, forDefinition.getCompiled(), forImplementation, modifiers, annotations, OperatorType.EQUALS, header, body);
255
 			}
254
 			}
256
 			case K_AS: {
255
 			case K_AS: {
257
 				tokens.next();
256
 				tokens.next();
258
 				IParsedType type = IParsedType.parse(tokens);
257
 				IParsedType type = IParsedType.parse(tokens);
259
 				ParsedFunctionBody body = ParsedStatement.parseFunctionBody(tokens);
258
 				ParsedFunctionBody body = ParsedStatement.parseFunctionBody(tokens);
260
-				return new ParsedCaster(start, forDefinition, forImplementation, modifiers, annotations, type, body);
259
+				return new ParsedCaster(start, forDefinition.getCompiled(), forImplementation, modifiers, annotations, type, body);
261
 			}
260
 			}
262
 			case K_IN: {
261
 			case K_IN: {
263
 				tokens.next();
262
 				tokens.next();
264
 				ParsedFunctionHeader header = ParsedFunctionHeader.parse(tokens);
263
 				ParsedFunctionHeader header = ParsedFunctionHeader.parse(tokens);
265
 				ParsedFunctionBody body = ParsedStatement.parseFunctionBody(tokens);
264
 				ParsedFunctionBody body = ParsedStatement.parseFunctionBody(tokens);
266
-				return new ParsedOperator(start, forDefinition, forImplementation, modifiers, annotations, OperatorType.CONTAINS, header, body);
265
+				return new ParsedOperator(start, forDefinition.getCompiled(), forImplementation, modifiers, annotations, OperatorType.CONTAINS, header, body);
267
 			}
266
 			}
268
 			case K_CLASS:
267
 			case K_CLASS:
269
 			case K_INTERFACE:
268
 			case K_INTERFACE:
270
 			case K_ALIAS:
269
 			case K_ALIAS:
271
 			case K_STRUCT:
270
 			case K_STRUCT:
272
 			case K_ENUM:
271
 			case K_ENUM:
273
-				return new ParsedInnerDefinition(forDefinition, ParsedDefinition.parse(forDefinition.pkg, start, modifiers, annotations, tokens, forDefinition));
272
+				return new ParsedInnerDefinition(forDefinition.getCompiled(), ParsedDefinition.parse(forDefinition.pkg, start, modifiers, annotations, tokens, forDefinition.getCompiled()));
274
 			case K_FOR: {
273
 			case K_FOR: {
275
 				tokens.next();
274
 				tokens.next();
276
 				ParsedFunctionHeader header = ParsedFunctionHeader.parse(tokens);
275
 				ParsedFunctionHeader header = ParsedFunctionHeader.parse(tokens);
277
 				ParsedFunctionBody body = ParsedStatement.parseFunctionBody(tokens);
276
 				ParsedFunctionBody body = ParsedStatement.parseFunctionBody(tokens);
278
-				return new ParsedIterator(start, forDefinition, modifiers, annotations, header, body);
277
+				return new ParsedIterator(start, forDefinition.getCompiled(), modifiers, annotations, header, body);
279
 			}
278
 			}
280
 			default:
279
 			default:
281
 				if (modifiers == Modifiers.STATIC && tokens.peek().type == ZSTokenType.T_AOPEN) {
280
 				if (modifiers == Modifiers.STATIC && tokens.peek().type == ZSTokenType.T_AOPEN) {
282
 					ParsedStatementBlock body = ParsedStatementBlock.parseBlock(tokens, annotations, true);
281
 					ParsedStatementBlock body = ParsedStatementBlock.parseBlock(tokens, annotations, true);
283
-					return new ParsedStaticInitializer(forDefinition, tokens.getPosition(), annotations, body);
282
+					return new ParsedStaticInitializer(forDefinition.getCompiled(), tokens.getPosition(), annotations, body);
284
 				}
283
 				}
285
 				throw new CompileException(tokens.getPosition(), CompileExceptionCode.UNEXPECTED_TOKEN, "Unexpected token: " + tokens.peek().content);
284
 				throw new CompileException(tokens.getPosition(), CompileExceptionCode.UNEXPECTED_TOKEN, "Unexpected token: " + tokens.peek().content);
286
 		}
285
 		}
331
 	
330
 	
332
 	public abstract void linkTypes(TypeResolutionContext context);
331
 	public abstract void linkTypes(TypeResolutionContext context);
333
 	
332
 	
334
-	public void registerInnerTypes(Map<String, CompilingType> innerTypes) {}
333
+	public void registerInnerTypes(Map<String, ParsedDefinition> innerTypes) {}
335
 	
334
 	
336
 	public abstract IDefinitionMember getCompiled();
335
 	public abstract IDefinitionMember getCompiled();
337
 	
336
 	

+ 2
- 2
Parser/src/main/java/org/openzen/zenscript/parser/member/ParsedInnerDefinition.java View File

7
 
7
 
8
 import java.util.Map;
8
 import java.util.Map;
9
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
9
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
10
-import org.openzen.zenscript.codemodel.context.CompilingType;
10
+import org.openzen.zenscript.codemodel.context.LocalTypeResolutionContext;
11
 import org.openzen.zenscript.codemodel.context.TypeResolutionContext;
11
 import org.openzen.zenscript.codemodel.context.TypeResolutionContext;
12
 import org.openzen.zenscript.codemodel.member.InnerDefinitionMember;
12
 import org.openzen.zenscript.codemodel.member.InnerDefinitionMember;
13
 import org.openzen.zenscript.codemodel.scope.BaseScope;
13
 import org.openzen.zenscript.codemodel.scope.BaseScope;
33
 	}
33
 	}
34
 	
34
 	
35
 	@Override
35
 	@Override
36
-	public void registerInnerTypes(Map<String, CompilingType> inner) {
36
+	public void registerInnerTypes(Map<String, ParsedDefinition> inner) {
37
 		inner.put(innerDefinition.getCompiled().name, innerDefinition);
37
 		inner.put(innerDefinition.getCompiled().name, innerDefinition);
38
 	}
38
 	}
39
 	
39
 	

+ 2
- 3
ScriptingExample/src/main/java/org/openzen/zenscript/scriptingexample/Main.java View File

42
 		File[] inputFiles = Optional.ofNullable(inputDirectory.listFiles((dir, name) -> name.endsWith(".zs"))).orElseGet(() -> new File[0]);
42
 		File[] inputFiles = Optional.ofNullable(inputDirectory.listFiles((dir, name) -> name.endsWith(".zs"))).orElseGet(() -> new File[0]);
43
 		
43
 		
44
 		ZSPackage pkg = new ZSPackage(null, "");
44
 		ZSPackage pkg = new ZSPackage(null, "");
45
-		CompilingPackage compilingPkg = new CompilingPackage();
45
+		CompilingPackage compilingPkg = new CompilingPackage(pkg);
46
 		ParsedFile[] parsedFiles = parse(pkg, compilingPkg, inputFiles);
46
 		ParsedFile[] parsedFiles = parse(pkg, compilingPkg, inputFiles);
47
 		
47
 		
48
 		ZSPackage global = new ZSPackage(null, "");
48
 		ZSPackage global = new ZSPackage(null, "");
62
 	private static ParsedFile[] parse(ZSPackage pkg, CompilingPackage compilingPkg, File[] files) throws IOException {
62
 	private static ParsedFile[] parse(ZSPackage pkg, CompilingPackage compilingPkg, File[] files) throws IOException {
63
 		ParsedFile[] parsedFiles = new ParsedFile[files.length];
63
 		ParsedFile[] parsedFiles = new ParsedFile[files.length];
64
 		for (int i = 0; i < files.length; i++) {
64
 		for (int i = 0; i < files.length; i++) {
65
-			parsedFiles[i] = ParsedFile.parse(pkg, compilingPkg, new TestBracketParser(), files[i]);
65
+			parsedFiles[i] = ParsedFile.parse(compilingPkg, new TestBracketParser(), files[i]);
66
 		}
66
 		}
67
 		return parsedFiles;
67
 		return parsedFiles;
68
 	}
68
 	}
110
 		SemanticModule result = Module.compileSyntaxToSemantic(
110
 		SemanticModule result = Module.compileSyntaxToSemantic(
111
 				"scripts",
111
 				"scripts",
112
 				new String[0],
112
 				new String[0],
113
-				pkg,
114
 				compiling,
113
 				compiling,
115
 				files,
114
 				files,
116
 				space,
115
 				space,

+ 18
- 0
Shared/src/main/java/listeners/DummyListenerHandle.java View File

1
+package listeners;
2
+
3
+
4
+public final class DummyListenerHandle<T> implements ListenerHandle<T>, AutoCloseable {
5
+    public final T listener;
6
+    
7
+    public DummyListenerHandle(T listener) {
8
+        this.listener = listener;
9
+    }
10
+    
11
+    @Override
12
+    public void close() {
13
+    }
14
+    
15
+    public T getListener() {
16
+        return listener;
17
+    }
18
+}

+ 9
- 0
Shared/src/main/java/listeners/ListenerHandle.java View File

1
+package listeners;
2
+
3
+
4
+public interface ListenerHandle<T> extends AutoCloseable {
5
+    @Override
6
+    public void close();
7
+    
8
+    T getListener();
9
+}

+ 85
- 0
Shared/src/main/java/listeners/ListenerList.java View File

1
+package listeners;
2
+
3
+import listeners.ListenerList;
4
+import zsynthetic.FunctionTToVoid;
5
+
6
+public final class ListenerList<T> {
7
+    public static final int PRIORITY_HIGH = 100;
8
+    public static final int PRIORITY_DEFAULT = 0;
9
+    public static final int PRIORITY_LOW = -100;
10
+    private ListenerList<T>.EventListenerNode first = null;
11
+    private ListenerList<T>.EventListenerNode last = null;
12
+    
13
+    public ListenerHandle<T> add(T listener) {
14
+        return this.add(listener, ListenerList.PRIORITY_DEFAULT);
15
+    }
16
+    
17
+    public ListenerHandle<T> add(T listener, int priority) {
18
+        ListenerList<T>.EventListenerNode node = new ListenerList<T>.EventListenerNode(listener, priority);
19
+        if (first == null) {
20
+            this.first = this.last = node;
21
+        }
22
+        else {
23
+            ListenerList<T>.EventListenerNode previousNode = last;
24
+            while (previousNode != null && priority > previousNode.priority)
25
+                previousNode = previousNode.prev;
26
+            if (previousNode == null) {
27
+                node.next = first;
28
+                first.prev = previousNode;
29
+                this.first = node;
30
+            }
31
+            else {
32
+                if (previousNode.next == null)
33
+                    this.last = node;
34
+                else
35
+                    previousNode.next.prev = node;
36
+                previousNode.next = node;
37
+                node.prev = previousNode;
38
+            }
39
+        }
40
+        return node;
41
+    }
42
+    
43
+    public void clear() {
44
+        this.first = this.last = null;
45
+    }
46
+    
47
+    public void accept(FunctionTToVoid<T> consumer) {
48
+        ListenerList<T>.EventListenerNode current = first;
49
+        while (current != null) {
50
+            consumer.invoke(current.getListener());
51
+            current = current.next;
52
+        }
53
+    }
54
+    
55
+    public boolean getIsEmpty() {
56
+        return first == null;
57
+    }
58
+    private final class EventListenerNode implements ListenerHandle<T>, AutoCloseable {
59
+        public final T listener;
60
+        private final int priority;
61
+        private ListenerList<T>.EventListenerNode next = null;
62
+        private ListenerList<T>.EventListenerNode prev = null;
63
+        
64
+        public EventListenerNode(T listener, int priority) {
65
+            this.listener = listener;
66
+            this.priority = priority;
67
+        }
68
+        
69
+        @Override
70
+        public void close() {
71
+            if (prev == null)
72
+                ListenerList.this.first = next;
73
+            else
74
+                prev.next = next;
75
+            if (next == null)
76
+                ListenerList.this.last = prev;
77
+            else
78
+                next.prev = prev;
79
+        }
80
+        
81
+        public T getListener() {
82
+            return listener;
83
+        }
84
+    }
85
+}

+ 25
- 0
Shared/src/main/java/live/ImmutableLiveBool.java View File

1
+package live;
2
+
3
+import listeners.DummyListenerHandle;
4
+import listeners.ListenerHandle;
5
+import live.ImmutableLiveBool;
6
+import zsynthetic.FunctionBoolBoolToVoid;
7
+
8
+public final class ImmutableLiveBool implements LiveBool {
9
+    public static final ImmutableLiveBool TRUE = new ImmutableLiveBool(true);
10
+    public static final ImmutableLiveBool FALSE = new ImmutableLiveBool(false);
11
+    public final boolean value;
12
+    
13
+    private ImmutableLiveBool(boolean value) {
14
+        this.value = value;
15
+    }
16
+    
17
+    @Override
18
+    public ListenerHandle<FunctionBoolBoolToVoid> addListener(FunctionBoolBoolToVoid listener) {
19
+        return new DummyListenerHandle<FunctionBoolBoolToVoid>(listener);
20
+    }
21
+    
22
+    public boolean getValue() {
23
+        return value;
24
+    }
25
+}

+ 22
- 0
Shared/src/main/java/live/ImmutableLiveObject.java View File

1
+package live;
2
+
3
+import listeners.DummyListenerHandle;
4
+import listeners.ListenerHandle;
5
+import zsynthetic.FunctionTTToVoid;
6
+
7
+public final class ImmutableLiveObject<T> implements LiveObject<T> {
8
+    public final T value;
9
+    
10
+    public ImmutableLiveObject(T value) {
11
+        this.value = value;
12
+    }
13
+    
14
+    @Override
15
+    public ListenerHandle<FunctionTTToVoid<T>> addListener(FunctionTTToVoid<T> listener) {
16
+        return new DummyListenerHandle<FunctionTTToVoid<T>>(listener);
17
+    }
18
+    
19
+    public T getValue() {
20
+        return value;
21
+    }
22
+}

+ 22
- 0
Shared/src/main/java/live/ImmutableLiveString.java View File

1
+package live;
2
+
3
+import listeners.DummyListenerHandle;
4
+import listeners.ListenerHandle;
5
+import zsynthetic.FunctionStringStringToVoid;
6
+
7
+public final class ImmutableLiveString implements LiveString {
8
+    public final String value;
9
+    
10
+    public ImmutableLiveString(String value) {
11
+        this.value = value;
12
+    }
13
+    
14
+    @Override
15
+    public ListenerHandle<FunctionStringStringToVoid> addListener(FunctionStringStringToVoid listener) {
16
+        return new DummyListenerHandle<FunctionStringStringToVoid>(listener);
17
+    }
18
+    
19
+    public String getValue() {
20
+        return value;
21
+    }
22
+}

+ 23
- 0
Shared/src/main/java/live/InverseLiveBool.java View File

1
+package live;
2
+
3
+import listeners.ListenerHandle;
4
+import zsynthetic.FunctionBoolBoolToVoid;
5
+
6
+public final class InverseLiveBool implements LiveBool {
7
+    private final LiveBool source;
8
+    
9
+    public InverseLiveBool(LiveBool source) {
10
+        this.source = source;
11
+    }
12
+    
13
+    @Override
14
+    public boolean getValue() {
15
+        return !source.getValue();
16
+    }
17
+    
18
+    @Override
19
+    public ListenerHandle<FunctionBoolBoolToVoid> addListener(FunctionBoolBoolToVoid listener) {
20
+        return source.addListener((oldVal, newVal) -> 
21
+        listener.invoke(!oldVal, !newVal));
22
+    }
23
+}

+ 88
- 0
Shared/src/main/java/live/LiveArrayList.java View File

1
+package live;
2
+
3
+import java.util.ArrayList;
4
+import java.util.Iterator;
5
+import java.util.List;
6
+import listeners.ListenerHandle;
7
+import listeners.ListenerList;
8
+
9
+final class LiveArrayList<T> implements MutableLiveList<T>, AutoCloseable {
10
+    private final List<T> values = new ArrayList<T>();
11
+    private final ListenerList<LiveList.Listener<T>> listeners = new ListenerList<LiveList.Listener<T>>();
12
+    
13
+    @Override
14
+    public void add(T value) {
15
+        int index = values.size();
16
+        values.add(value);
17
+        listeners.accept(listener -> 
18
+        listener.onInserted(index, value));
19
+    }
20
+    
21
+    @Override
22
+    public void insert(int index, T value) {
23
+        values.add(index, value);
24
+        listeners.accept(listener -> 
25
+        listener.onInserted(index, value));
26
+    }
27
+    
28
+    @Override
29
+    public void setAt(int index, T value) {
30
+        T oldValue = values.get(index);
31
+        values.set(index, value);
32
+        listeners.accept(listener -> 
33
+        listener.onChanged(index, oldValue, value));
34
+    }
35
+    
36
+    @Override
37
+    public void remove(int index) {
38
+        T oldValue = values.remove(index);
39
+        listeners.accept(listener -> 
40
+        listener.onRemoved(index, oldValue));
41
+    }
42
+    
43
+    @Override
44
+    public void remove(T value) {
45
+        int index = this.indexOf(value);
46
+        if (index < 0)
47
+            return;
48
+        this.remove(index);
49
+    }
50
+    
51
+    @Override
52
+    public void clear() {
53
+        int i = this.getLength();
54
+        while (i > 0) {
55
+            i--;
56
+            this.remove(i);
57
+        }
58
+    }
59
+    
60
+    @Override
61
+    public Iterator<T> iterator() {
62
+        return values.iterator();
63
+    }
64
+    
65
+    @Override
66
+    public int indexOf(T value) {
67
+        return values.indexOf(value);
68
+    }
69
+    
70
+    @Override
71
+    public int getLength() {
72
+        return values.size();
73
+    }
74
+    
75
+    @Override
76
+    public T getAt(int index) {
77
+        return values.get(index);
78
+    }
79
+    
80
+    @Override
81
+    public ListenerHandle<LiveList.Listener<T>> addListener(LiveList.Listener<T> listener) {
82
+        return listeners.add(listener);
83
+    }
84
+    
85
+    @Override
86
+    public void close() {
87
+    }
88
+}

+ 10
- 0
Shared/src/main/java/live/LiveBool.java View File

1
+package live;
2
+
3
+import listeners.ListenerHandle;
4
+import zsynthetic.FunctionBoolBoolToVoid;
5
+
6
+public interface LiveBool {
7
+    boolean getValue();
8
+    
9
+    ListenerHandle<FunctionBoolBoolToVoid> addListener(FunctionBoolBoolToVoid listener);
10
+}

+ 12
- 0
Shared/src/main/java/live/LiveInt.java View File

1
+package live;
2
+
3
+import listeners.ListenerHandle;
4
+import zsynthetic.FunctionIntIntToVoid;
5
+
6
+public interface LiveInt {
7
+    int getValue();
8
+    
9
+    void setValue(int value);
10
+    
11
+    ListenerHandle<FunctionIntIntToVoid> addListener(FunctionIntIntToVoid listener);
12
+}

+ 23
- 0
Shared/src/main/java/live/LiveList.java View File

1
+package live;
2
+
3
+import listeners.ListenerHandle;
4
+
5
+public interface LiveList<T> extends AutoCloseable, Iterable<T> {
6
+    @Override
7
+    public void close();
8
+    
9
+    int getLength();
10
+    
11
+    int indexOf(T value);
12
+    
13
+    T getAt(int index);
14
+    
15
+    ListenerHandle<LiveList.Listener<T>> addListener(LiveList.Listener<T> listener);
16
+    public interface Listener<T> {
17
+        void onInserted(int index, T value);
18
+        
19
+        void onChanged(int index, T oldValue, T newValue);
20
+        
21
+        void onRemoved(int index, T oldValue);
22
+    }
23
+}

+ 10
- 0
Shared/src/main/java/live/LiveObject.java View File

1
+package live;
2
+
3
+import listeners.ListenerHandle;
4
+import zsynthetic.FunctionTTToVoid;
5
+
6
+public interface LiveObject<T> {
7
+    T getValue();
8
+    
9
+    ListenerHandle<FunctionTTToVoid<T>> addListener(FunctionTTToVoid<T> listener);
10
+}

+ 10
- 0
Shared/src/main/java/live/LiveString.java View File

1
+package live;
2
+
3
+import listeners.ListenerHandle;
4
+import zsynthetic.FunctionStringStringToVoid;
5
+
6
+public interface LiveString {
7
+    String getValue();
8
+    
9
+    ListenerHandle<FunctionStringStringToVoid> addListener(FunctionStringStringToVoid listener);
10
+}

+ 19
- 0
Shared/src/main/java/live/MutableLiveList.java View File

1
+package live;
2
+
3
+
4
+public interface MutableLiveList<T> extends AutoCloseable, LiveList<T> {
5
+    void add(T value);
6
+    
7
+    void insert(int index, T value);
8
+    
9
+    void setAt(int index, T value);
10
+    
11
+    void remove(int index);
12
+    
13
+    void remove(T value);
14
+    
15
+    void clear();
16
+    
17
+    @Override
18
+    public void close();
19
+}

+ 15
- 15
Shared/src/main/java/org/openzen/zencode/shared/CharacterEntity.java View File

1
 package org.openzen.zencode.shared;
1
 package org.openzen.zencode.shared;
2
 
2
 
3
 public final class CharacterEntity {
3
 public final class CharacterEntity {
4
-	public final char charValue;
5
-	public final String stringValue;
6
-	
7
-	public CharacterEntity(String stringValue, char charValue) {
8
-	    this.charValue = charValue;
9
-	    this.stringValue = stringValue;
10
-	}
11
-	
12
-	public char getCharValue() {
13
-	    return charValue;
14
-	}
15
-	
16
-	public String getStringValue() {
17
-	    return stringValue;
18
-	}
4
+    public final char charValue;
5
+    public final String stringValue;
6
+    
7
+    public CharacterEntity(String stringValue, char charValue) {
8
+        this.charValue = charValue;
9
+        this.stringValue = stringValue;
10
+    }
11
+    
12
+    public char getCharValue() {
13
+        return charValue;
14
+    }
15
+    
16
+    public String getStringValue() {
17
+        return stringValue;
18
+    }
19
 }
19
 }

+ 21
- 21
Shared/src/main/java/org/openzen/zencode/shared/CompileException.java View File

1
 package org.openzen.zencode.shared;
1
 package org.openzen.zencode.shared;
2
 
2
 
3
+import org.openzen.zencode.shared.CodePosition;
3
 import org.openzen.zencode.shared.CompileException;
4
 import org.openzen.zencode.shared.CompileException;
4
 
5
 
5
 public final class CompileException extends RuntimeException {
6
 public final class CompileException extends RuntimeException {
6
-	public static CompileException internalError(String message) {
7
-	    return new CompileException(CodePosition.BUILTIN, CompileExceptionCode.INTERNAL_ERROR, message);
8
-	}
9
-	
10
-	public final CodePosition position;
11
-	public final CompileExceptionCode code;
12
-	
13
-	public CompileException(CodePosition position, CompileExceptionCode code, String message) {
14
-	    super(position.toString() + ": [" + code.toString() + "] " + message);
15
-	    
16
-	    this.position = position;
17
-	    this.code = code;
18
-	}
19
-	
20
-	public CodePosition getPosition() {
21
-	    return position;
22
-	}
23
-	
24
-	public CompileExceptionCode getCode() {
25
-	    return code;
26
-	}
7
+    public static CompileException internalError(String message) {
8
+        return new CompileException(CodePosition.BUILTIN, CompileExceptionCode.INTERNAL_ERROR, message);
9
+    }
10
+    
11
+    public final CodePosition position;
12
+    public final CompileExceptionCode code;
13
+    
14
+    public CompileException(CodePosition position, CompileExceptionCode code, String message) {
15
+        super(position.toString() + ": [" + code.toString() + "] " + message);
16
+        this.position = position;
17
+        this.code = code;
18
+    }
19
+    
20
+    public CodePosition getPosition() {
21
+        return position;
22
+    }
23
+    
24
+    public CompileExceptionCode getCode() {
25
+        return code;
26
+    }
27
 }
27
 }

+ 49
- 48
Shared/src/main/java/org/openzen/zencode/shared/ConcatMap.java View File

1
 package org.openzen.zencode.shared;
1
 package org.openzen.zencode.shared;
2
 
2
 
3
+import org.openzen.zencode.shared.ConcatMap;
3
 import stdlib.EqualsComparable;
4
 import stdlib.EqualsComparable;
4
 
5
 
5
-public final class ConcatMap<K extends EqualsComparable<K>, V>  {
6
-	public static final <K extends EqualsComparable<K>, V> ConcatMap<K, V> empty(Class<K> typeOfK, Class<V> typeOfV) {
7
-	    return new ConcatMap<K, V>(null, null, null);
8
-	}
9
-	
10
-	private final K key;
11
-	private final V value;
12
-	private final ConcatMap<K, V> remaining;
13
-	
14
-	private ConcatMap(K key, V value, ConcatMap<K, V> remaining) {
15
-	    this.key = key;
16
-	    this.value = value;
17
-	    this.remaining = remaining;
18
-	}
19
-	
20
-	public boolean getIsEmpty() {
21
-	    return key == null;
22
-	}
23
-	
24
-	public ConcatMap<K, V> concat(K key, V value) {
25
-	    return new ConcatMap<K, V>(key, value, this);
26
-	}
27
-	
28
-	public boolean contains(K key) {
29
-	    if (this.key == null)
30
-	        return false;
31
-	    if (key.equals_(this.key))
32
-	        return true;
33
-	    if (remaining == null)
34
-	        return false;
35
-	    return remaining.contains(key);
36
-	}
37
-	
38
-	public V getAt(K key) {
39
-	    if (this.key == null)
40
-	        return null;
41
-	    if (key.equals_(this.key))
42
-	        return value;
43
-	    return remaining.getAt(key);
44
-	}
45
-	
46
-	public V getOrDefault(K key, V defaultValue) {
47
-	    if (this.key == null)
48
-	        return defaultValue;
49
-	    if (key.equals_(this.key))
50
-	        return value;
51
-	    return remaining.getOrDefault(key, defaultValue);
52
-	}
6
+public final class ConcatMap<K extends EqualsComparable<K>, V> {
7
+    public static final <K extends EqualsComparable<K>, V> ConcatMap<K, V> empty(Class<K> typeOfK, Class<V> typeOfV) {
8
+        return new ConcatMap<K, V>(null, null, null);
9
+    }
10
+    
11
+    private final K key;
12
+    private final V value;
13
+    private final ConcatMap<K, V> remaining;
14
+    
15
+    private ConcatMap(K key, V value, ConcatMap<K, V> remaining) {
16
+        this.key = key;
17
+        this.value = value;
18
+        this.remaining = remaining;
19
+    }
20
+    
21
+    public boolean getIsEmpty() {
22
+        return key == null;
23
+    }
24
+    
25
+    public ConcatMap<K, V> concat(K key, V value) {
26
+        return new ConcatMap<K, V>(key, value, this);
27
+    }
28
+    
29
+    public boolean contains(K key) {
30
+        if (this.key == null)
31
+            return false;
32
+        if (key.equals_(this.key))
33
+            return true;
34
+        if (remaining == null)
35
+            return false;
36
+        return remaining.contains(key);
37
+    }
38
+    
39
+    public V getAt(K key) {
40
+        if (this.key == null)
41
+            return null;
42
+        if (key.equals_(this.key))
43
+            return value;
44
+        return remaining.getAt(key);
45
+    }
46
+    
47
+    public V getOrDefault(K key, V defaultValue) {
48
+        if (this.key == null)
49
+            return defaultValue;
50
+        if (key.equals_(this.key))
51
+            return value;
52
+        return remaining.getOrDefault(key, defaultValue);
53
+    }
53
 }
54
 }

+ 2
- 15
Shared/src/main/java/org/openzen/zencode/shared/StringExpansion.java View File

18
 	
18
 	
19
 	static  {
19
 	static  {
20
 	    CharacterEntity[] entities = StringExpansion.getCharacterEntities();
20
 	    CharacterEntity[] entities = StringExpansion.getCharacterEntities();
21
-	    // TODO: getCharacterEntities().index(e => e.stringValue);
22
-	    
23
 	    NAMED_CHARACTER_ENTITIES = new HashMap<>();
21
 	    NAMED_CHARACTER_ENTITIES = new HashMap<>();
24
 	    for (CharacterEntity entity : entities)
22
 	    for (CharacterEntity entity : entities)
25
-	        
26
 	        StringExpansion.NAMED_CHARACTER_ENTITIES.put(entity.stringValue, entity);
23
 	        StringExpansion.NAMED_CHARACTER_ENTITIES.put(entity.stringValue, entity);
27
 	}
24
 	}
28
 	
25
 	
57
 	                return new Error("Unfinished escape sequence");
54
 	                return new Error("Unfinished escape sequence");
58
 	            switch (quoted.charAt(i + 1)) {
55
 	            switch (quoted.charAt(i + 1)) {
59
 	                case '\\':
56
 	                case '\\':
60
-	                    
61
 	                    i++;
57
 	                    i++;
62
 	                    result.append('\\');
58
 	                    result.append('\\');
63
 	                    break;
59
 	                    break;
64
 	                case '&':
60
 	                case '&':
65
-	                    
66
 	                    Result<CharacterEntity, String> temp1 = StringExpansion.readCharacterEntity(quoted, i + 1);
61
 	                    Result<CharacterEntity, String> temp1 = StringExpansion.readCharacterEntity(quoted, i + 1);
67
 	                    if (temp1 instanceof Result.Error)
62
 	                    if (temp1 instanceof Result.Error)
68
 	                        return new Result.Error<>(((Result.Error<CharacterEntity, String>)temp1).value);
63
 	                        return new Result.Error<>(((Result.Error<CharacterEntity, String>)temp1).value);
99
 	                    result.append('\'');
94
 	                    result.append('\'');
100
 	                    break;
95
 	                    break;
101
 	                case 'u':
96
 	                case 'u':
102
-	                    
103
 	                    if (i >= quoted.length() - 5)
97
 	                    if (i >= quoted.length() - 5)
104
 	                        return new Error("Unfinished escape sequence");
98
 	                        return new Error("Unfinished escape sequence");
105
 	                    Result<Integer, String> temp2 = StringExpansion.readHexCharacter(quoted.charAt(i + 2));
99
 	                    Result<Integer, String> temp2 = StringExpansion.readHexCharacter(quoted.charAt(i + 2));
122
 	                    result.append((char)hex0 << 12 | hex1 << 8 | hex2 << 4 | hex3);
116
 	                    result.append((char)hex0 << 12 | hex1 << 8 | hex2 << 4 | hex3);
123
 	                    break;
117
 	                    break;
124
 	                default:
118
 	                default:
125
-	                    
126
 	                    return new Error("Illegal escape sequence");
119
 	                    return new Error("Illegal escape sequence");
127
 	            }
120
 	            }
128
 	        }
121
 	        }
140
 	    for (char c : self.toCharArray()) {
133
 	    for (char c : self.toCharArray()) {
141
 	        switch (c) {
134
 	        switch (c) {
142
 	            case '\\':
135
 	            case '\\':
143
-	                
144
 	                output.append("\\\\");
136
 	                output.append("\\\\");
145
 	                break;
137
 	                break;
146
 	            case '"':
138
 	            case '"':
147
-	                
148
 	                if (quote == '"')
139
 	                if (quote == '"')
149
 	                    output.append("\\\"");
140
 	                    output.append("\\\"");
150
 	                else
141
 	                else
151
 	                    output.append('"');
142
 	                    output.append('"');
152
 	                break;
143
 	                break;
153
 	            case '\'':
144
 	            case '\'':
154
-	                
155
 	                if (quote == '\'')
145
 	                if (quote == '\'')
156
 	                    output.append("\\'");
146
 	                    output.append("\\'");
157
 	                else
147
 	                else
167
 	                output.append("\\t");
157
 	                output.append("\\t");
168
 	                break;
158
 	                break;
169
 	            default:
159
 	            default:
170
-	                
171
 	                if (escapeUnicode && c > '') {
160
 	                if (escapeUnicode && c > '') {
172
 	                    output.append("\\u").append(Strings.lpad(Integer.toHexString((int)c), 4, '0'));
161
 	                    output.append("\\u").append(Strings.lpad(Integer.toHexString((int)c), 4, '0'));
173
 	                }
162
 	                }
206
 	    if (entity.charAt(0) == '#') {
195
 	    if (entity.charAt(0) == '#') {
207
 	        if (entity.length() < 2)
196
 	        if (entity.length() < 2)
208
 	            return new Error("Character entity number too short");
197
 	            return new Error("Character entity number too short");
209
-	        if (str.charAt(1) == 'x') {// hex character entity
210
-	            
198
+	        if (str.charAt(1) == 'x') {
211
 	            if (entity.length() != 7)
199
 	            if (entity.length() != 7)
212
 	                return new Error("Hexadecimal character entity must have 4 hex digits");
200
 	                return new Error("Hexadecimal character entity must have 4 hex digits");
213
 	            int ivalue = Integer.parseInt(entity.substring(2, entity.length()), 16);
201
 	            int ivalue = Integer.parseInt(entity.substring(2, entity.length()), 16);
214
 	            return new Ok(new CharacterEntity(entity, (char)ivalue));
202
 	            return new Ok(new CharacterEntity(entity, (char)ivalue));
215
 	        }
203
 	        }
216
-	        else {// decimal character entity
217
-	            
204
+	        else {
218
 	            int ivalue = Integer.parseInt(entity.substring(1, entity.length()));
205
 	            int ivalue = Integer.parseInt(entity.substring(1, entity.length()));
219
 	            return new Ok(new CharacterEntity(entity, (char)ivalue));
206
 	            return new Ok(new CharacterEntity(entity, (char)ivalue));
220
 	        }
207
 	        }

+ 17
- 17
Shared/src/main/java/org/openzen/zencode/shared/Taggable.java View File

4
 import java.util.Map;
4
 import java.util.Map;
5
 
5
 
6
 public class Taggable {
6
 public class Taggable {
7
-	private final Map<Class<?>, Object> tags = new HashMap<Class<?>, Object>();
8
-	
9
-	public <T> void setTag(Class<T> typeOfT, T tag) {
10
-	    tags.put(typeOfT, tag);
11
-	}
12
-	
13
-	public <T> T getTag(Class<T> typeOfT) {
14
-	    return (T)(tags.get(typeOfT));
15
-	}
16
-	
17
-	public <T> boolean hasTag(Class<T> typeOfT) {
18
-	    return tags.containsKey(typeOfT);
19
-	}
20
-	
21
-	public void addAllTagsFrom(Taggable other) {
22
-	    tags.putAll(other.tags);
23
-	}
7
+    private final Map<Class<?>, Object> tags = new HashMap<Class<?>, Object>();
8
+    
9
+    public <T> void setTag(Class<T> typeOfT, T tag) {
10
+        tags.put(typeOfT, tag);
11
+    }
12
+    
13
+    public <T> T getTag(Class<T> typeOfT) {
14
+        return (T)(tags.get(typeOfT));
15
+    }
16
+    
17
+    public <T> boolean hasTag(Class<T> typeOfT) {
18
+        return tags.containsKey(typeOfT);
19
+    }
20
+    
21
+    public void addAllTagsFrom(Taggable other) {
22
+        tags.putAll(other.tags);
23
+    }
24
 }
24
 }

+ 16
- 26
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;
1
 package org.openzen.zencode.shared;
7
 
2
 
8
 import java.io.IOException;
3
 import java.io.IOException;
9
 import java.io.Reader;
4
 import java.io.Reader;
10
 
5
 
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
-	}
6
+public final class VirtualSourceFile implements SourceFile {
7
+    public final String filename;
8
+    
9
+    public VirtualSourceFile(String filename) {
10
+        this.filename = filename;
11
+    }
12
+    
13
+    @Override
14
+    public Reader open() throws IOException {
15
+        throw new AssertionError("Cannot open virtual source files");
16
+    }
17
+    
18
+    public String getFilename() {
19
+        return filename;
20
+    }
31
 
21
 
32
 	@Override
22
 	@Override
33
 	public void update(String content) throws IOException {
23
 	public void update(String content) throws IOException {
34
-		throw new UnsupportedOperationException("Cannot write to virtual source files");
24
+		throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
35
 	}
25
 	}
36
 }
26
 }

+ 159
- 173
Shared/src/main/java/stdlib/Arrays.java View File

5
 import java.util.HashMap;
5
 import java.util.HashMap;
6
 import java.util.List;
6
 import java.util.List;
7
 import java.util.Map;
7
 import java.util.Map;
8
-import zsynthetic.Function1;
9
-import zsynthetic.Function2;
10
-import zsynthetic.Function3;
11
-import zsynthetic.Function4;
12
-import zsynthetic.Function5;
13
-import zsynthetic.Function6;
14
-import zsynthetic.Function7;
8
+import zsynthetic.FunctionIntTToBool;
9
+import zsynthetic.FunctionIntTToU;
10
+import zsynthetic.FunctionIntTToVoid;
11
+import zsynthetic.FunctionTToBool;
12
+import zsynthetic.FunctionTToU;
13
+import zsynthetic.FunctionTToVoid;
15
 
14
 
16
 public final class Arrays {
15
 public final class Arrays {
17
     private Arrays() {}
16
     private Arrays() {}
18
-	public static <T> T getFirst(Class<T> typeOfT, T[] self) {
19
-	    return self.length == 0 ? null : self[0];
20
-	}
21
-	
22
-	public static <T> T getLast(Class<T> typeOfT, T[] self) {
23
-	    return self.length == 0 ? null : self[self.length - 1];
24
-	}
25
-	
26
-	public static <T> void reverse(Class<T> typeOfT, T[] self) {
27
-	    int limitForI = self.length / 2;
28
-	    for (int i = 0; i < limitForI; i++) {
29
-	        T temp = self[i];
30
-	        self[i] = self[self.length - i - 1];
31
-	        self[self.length - i - 1] = temp;
32
-	    }
33
-	}
34
-	
35
-	public static <U, T> U[] map(Class<T> typeOfT, T[] self, Class<U> typeOfU, Function1<U, T> projection) {
36
-	    U[] temp1 = (U[])(Array.newInstance(typeOfU, self.length));
37
-	    for (int temp2 = 0; temp2 < temp1.length; temp2++)
38
-	        temp1[temp2] = projection.invoke(self[temp2]);
39
-	    return temp1;
40
-	}
41
-	
42
-	public static <U, T> U[] map(Class<T> typeOfT, T[] self, Class<U> typeOfU, Function2<U, T> projection) {
43
-	    U[] temp1 = (U[])(Array.newInstance(typeOfU, self.length));
44
-	    for (int temp2 = 0; temp2 < temp1.length; temp2++)
45
-	        temp1[temp2] = projection.invoke(temp2, self[temp2]);
46
-	    return temp1;
47
-	}
48
-	
49
-	public static <T> T[] filter(Class<T> typeOfT, T[] self, Function3<T> predicate) {
50
-	    List<T> values = new ArrayList<T>();
51
-	    for (T value : self)
52
-	        
53
-	        if (predicate.invoke(value))
54
-	            values.add(value);
55
-	    return values.toArray((T[])(Array.newInstance(typeOfT, values.size())));
56
-	}
57
-	
58
-	public static <T> T[] filter(Class<T> typeOfT, T[] self, Function4<T> predicate) {
59
-	    List<T> values = new ArrayList<T>();
60
-	    for (int i = 0; i < self.length; i++) {
61
-	        T value = self[i];
62
-	        
63
-	        if (predicate.invoke(i, value))
64
-	            values.add(value);
65
-	    }
66
-	    return values.toArray((T[])(Array.newInstance(typeOfT, values.size())));
67
-	}
68
-	
69
-	public static <T> void each(Class<T> typeOfT, T[] self, Function5<T> consumer) {
70
-	    for (T value : self)
71
-	        
72
-	        consumer.invoke(value);
73
-	}
74
-	
75
-	public static <T> void each(Class<T> typeOfT, T[] self, Function6<T> consumer) {
76
-	    for (int i = 0; i < self.length; i++) {
77
-	        T value = self[i];
78
-	        
79
-	        consumer.invoke(i, value);
80
-	    }
81
-	}
82
-	
83
-	public static <T> boolean contains(Class<T> typeOfT, T[] self, Function3<T> predicate) {
84
-	    for (T value : self)
85
-	        
86
-	        if (predicate.invoke(value))
87
-	            return true;
88
-	    return false;
89
-	}
90
-	
91
-	public static <T> boolean contains(Class<T> typeOfT, T[] self, Function4<T> predicate) {
92
-	    for (int i = 0; i < self.length; i++) {
93
-	        T value = self[i];
94
-	        
95
-	        if (predicate.invoke(i, value))
96
-	            return true;
97
-	    }
98
-	    return false;
99
-	}
100
-	
101
-	public static <T> boolean all(Class<T> typeOfT, T[] self, Function3<T> predicate) {
102
-	    for (T value : self)
103
-	        
104
-	        if (!predicate.invoke(value))
105
-	            return false;
106
-	    return true;
107
-	}
108
-	
109
-	public static <T> boolean all(Class<T> typeOfT, T[] self, Function4<T> predicate) {
110
-	    for (int i = 0; i < self.length; i++) {
111
-	        T value = self[i];
112
-	        
113
-	        if (!predicate.invoke(i, value))
114
-	            return false;
115
-	    }
116
-	    return true;
117
-	}
118
-	
119
-	public static <T> T first(Class<T> typeOfT, T[] self, Function3<T> predicate) {
120
-	    for (T value : self)
121
-	        
122
-	        if (predicate.invoke(value))
123
-	            return value;
124
-	    return null;
125
-	}
126
-	
127
-	public static <T> T first(Class<T> typeOfT, T[] self, Function4<T> predicate) {
128
-	    for (int i = 0; i < self.length; i++) {
129
-	        T value = self[i];
130
-	        
131
-	        if (predicate.invoke(i, value))
132
-	            return value;
133
-	    }
134
-	    return null;
135
-	}
136
-	
137
-	public static <T> T last(Class<T> typeOfT, T[] self, Function3<T> predicate) {
138
-	    int i = self.length;
139
-	    while (i > 0) {
140
-	        i--;
141
-	        if (predicate.invoke(self[i]))
142
-	            return self[i];
143
-	    }
144
-	    return null;
145
-	}
146
-	
147
-	public static <T> T last(Class<T> typeOfT, T[] self, Function4<T> predicate) {
148
-	    int i = self.length;
149
-	    while (i > 0) {
150
-	        i--;
151
-	        if (predicate.invoke(i, self[i]))
152
-	            return self[i];
153
-	    }
154
-	    return null;
155
-	}
156
-	
157
-	public static <T> int count(Class<T> typeOfT, T[] self, Function3<T> predicate) {
158
-	    int result = 0;
159
-	    for (T value : self)
160
-	        
161
-	        if (predicate.invoke(value))
162
-	            result++;
163
-	    return result;
164
-	}
165
-	
166
-	public static <T> int count(Class<T> typeOfT, T[] self, Function4<T> predicate) {
167
-	    int result = 0;
168
-	    for (int i = 0; i < self.length; i++) {
169
-	        T value = self[i];
170
-	        
171
-	        if (predicate.invoke(i, value))
172
-	            result++;
173
-	    }
174
-	    return result;
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
-	}
17
+    public static <T> T getFirst(Class<T> typeOfT, T[] self) {
18
+        return self.length == 0 ? null : self[0];
19
+    }
20
+    
21
+    public static <T> T getLast(Class<T> typeOfT, T[] self) {
22
+        return self.length == 0 ? null : self[self.length - 1];
23
+    }
24
+    
25
+    public static <T> void reverse(Class<T> typeOfT, T[] self) {
26
+        int limitForI = self.length / 2;
27
+        for (int i = 0; i < limitForI; i++) {
28
+            T temp = self[i];
29
+            self[i] = self[self.length - i - 1];
30
+            self[self.length - i - 1] = temp;
31
+        }
32
+    }
33
+    
34
+    public static <U, T> U[] map(Class<T> typeOfT, T[] self, Class<U> typeOfU, FunctionTToU<U, T> projection) {
35
+        U[] temp1 = (U[])(Array.newInstance(typeOfU, self.length));
36
+        for (int temp2 = 0; temp2 < temp1.length; temp2++)
37
+            temp1[temp2] = projection.invoke(self[temp2]);
38
+        return temp1;
39
+    }
40
+    
41
+    public static <U, T> U[] map(Class<T> typeOfT, T[] self, Class<U> typeOfU, FunctionIntTToU<U, T> projection) {
42
+        U[] temp1 = (U[])(Array.newInstance(typeOfU, self.length));
43
+        for (int temp2 = 0; temp2 < temp1.length; temp2++)
44
+            temp1[temp2] = projection.invoke(temp2, self[temp2]);
45
+        return temp1;
46
+    }
47
+    
48
+    public static <T> T[] filter(Class<T> typeOfT, T[] self, FunctionTToBool<T> predicate) {
49
+        List<T> values = new ArrayList<T>();
50
+        for (T value : self)
51
+            if (predicate.invoke(value))
52
+                values.add(value);
53
+        return values.toArray((T[])(Array.newInstance(typeOfT, values.size())));
54
+    }
55
+    
56
+    public static <T> T[] filter(Class<T> typeOfT, T[] self, FunctionIntTToBool<T> predicate) {
57
+        List<T> values = new ArrayList<T>();
58
+        for (int i = 0; i < self.length; i++) {
59
+            T value = self[i];
60
+            if (predicate.invoke(i, value))
61
+                values.add(value);
62
+        }
63
+        return values.toArray((T[])(Array.newInstance(typeOfT, values.size())));
64
+    }
65
+    
66
+    public static <T> void each(Class<T> typeOfT, T[] self, FunctionTToVoid<T> consumer) {
67
+        for (T value : self)
68
+            consumer.invoke(value);
69
+    }
70
+    
71
+    public static <T> void each(Class<T> typeOfT, T[] self, FunctionIntTToVoid<T> consumer) {
72
+        for (int i = 0; i < self.length; i++) {
73
+            T value = self[i];
74
+            consumer.invoke(i, value);
75
+        }
76
+    }
77
+    
78
+    public static <T> boolean contains(Class<T> typeOfT, T[] self, FunctionTToBool<T> predicate) {
79
+        for (T value : self)
80
+            if (predicate.invoke(value))
81
+                return true;
82
+        return false;
83
+    }
84
+    
85
+    public static <T> boolean contains(Class<T> typeOfT, T[] self, FunctionIntTToBool<T> predicate) {
86
+        for (int i = 0; i < self.length; i++) {
87
+            T value = self[i];
88
+            if (predicate.invoke(i, value))
89
+                return true;
90
+        }
91
+        return false;
92
+    }
93
+    
94
+    public static <T> boolean all(Class<T> typeOfT, T[] self, FunctionTToBool<T> predicate) {
95
+        for (T value : self)
96
+            if (!predicate.invoke(value))
97
+                return false;
98
+        return true;
99
+    }
100
+    
101
+    public static <T> boolean all(Class<T> typeOfT, T[] self, FunctionIntTToBool<T> predicate) {
102
+        for (int i = 0; i < self.length; i++) {
103
+            T value = self[i];
104
+            if (!predicate.invoke(i, value))
105
+                return false;
106
+        }
107
+        return true;
108
+    }
109
+    
110
+    public static <T> T first(Class<T> typeOfT, T[] self, FunctionTToBool<T> predicate) {
111
+        for (T value : self)
112
+            if (predicate.invoke(value))
113
+                return value;
114
+        return null;
115
+    }
116
+    
117
+    public static <T> T first(Class<T> typeOfT, T[] self, FunctionIntTToBool<T> predicate) {
118
+        for (int i = 0; i < self.length; i++) {
119
+            T value = self[i];
120
+            if (predicate.invoke(i, value))
121
+                return value;
122
+        }
123
+        return null;
124
+    }
125
+    
126
+    public static <T> T last(Class<T> typeOfT, T[] self, FunctionTToBool<T> predicate) {
127
+        int i = self.length;
128
+        while (i > 0) {
129
+            i--;
130
+            if (predicate.invoke(self[i]))
131
+                return self[i];
132
+        }
133
+        return null;
134
+    }
135
+    
136
+    public static <T> T last(Class<T> typeOfT, T[] self, FunctionIntTToBool<T> predicate) {
137
+        int i = self.length;
138
+        while (i > 0) {
139
+            i--;
140
+            if (predicate.invoke(i, self[i]))
141
+                return self[i];
142
+        }
143
+        return null;
144
+    }
145
+    
146
+    public static <T> int count(Class<T> typeOfT, T[] self, FunctionTToBool<T> predicate) {
147
+        int result = 0;
148
+        for (T value : self)
149
+            if (predicate.invoke(value))
150
+                result++;
151
+        return result;
152
+    }
153
+    
154
+    public static <T> int count(Class<T> typeOfT, T[] self, FunctionIntTToBool<T> predicate) {
155
+        int result = 0;
156
+        for (int i = 0; i < self.length; i++) {
157
+            T value = self[i];
158
+            if (predicate.invoke(i, value))
159
+                result++;
160
+        }
161
+        return result;
162
+    }
163
+    
164
+    public static <K, T> Map<K, T> index(Class<T> typeOfT, T[] self, Class<K> typeOfK, FunctionTToU<K, T> key) {
165
+        Map<K, T> result = new HashMap<>();
166
+        for (T value : self)
167
+            result.put(key.invoke(value), value);
168
+        return result;
169
+    }
184
 }
170
 }

+ 2
- 3
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.Function8;
5
+import zsynthetic.FunctionTToU;
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, Function8<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, FunctionTToU<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();
13
 	        V v = temp1.getValue();
13
 	        V v = temp1.getValue();
14
-	        
15
 	        result.put(k, projection.invoke(v));
14
 	        result.put(k, projection.invoke(v));
16
 	    }
15
 	    }
17
 	    return result;
16
 	    return result;

+ 3
- 3
Shared/src/main/java/stdlib/EnforcementLevel.java View File

1
 package stdlib;
1
 package stdlib;
2
 
2
 
3
 public enum EnforcementLevel {
3
 public enum EnforcementLevel {
4
-	INFO,
5
-	ENFORCE,
6
-	PROVE
4
+	INFO(),
5
+	ENFORCE(),
6
+	PROVE()
7
 }
7
 }

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

1
 package stdlib;
1
 package stdlib;
2
 
2
 
3
-public interface EqualsComparable<T>  {
4
-	boolean equals_(T other);
3
+public interface EqualsComparable<T> {
4
+    boolean equals_(T other);
5
 }
5
 }

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

1
 package stdlib;
1
 package stdlib;
2
 
2
 
3
-public interface Hashable<T>  {
4
-	int hashCode();
5
-	
6
-	boolean equals_(T other);
3
+public interface Hashable<T> {
4
+    int hashCode();
5
+    
6
+    boolean equals_(T other);
7
 }
7
 }

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

3
 import stdlib.Result;
3
 import stdlib.Result;
4
 import stdlib.Result.Error;
4
 import stdlib.Result.Error;
5
 import stdlib.Result.Ok;
5
 import stdlib.Result.Ok;
6
-import zsynthetic.Function10;
7
-import zsynthetic.Function11;
8
-import zsynthetic.Function9;
6
+import zsynthetic.FunctionTToResultWithUV;
7
+import zsynthetic.FunctionTToU;
9
 
8
 
10
 public abstract class Result<T, E> {
9
 public abstract class Result<T, E> {
11
-	public <R> Result<R, E> then(Class<R> typeOfR, Function9<R, E, T> fn) {
12
-	    Result<R, E> temp1;
13
-	    switch (this.getDiscriminant()) {
14
-	        case Ok:
15
-	            T result = ((Result.Ok<T, E>)this).value;
16
-	            temp1 = fn.invoke(result);
17
-	            break;
18
-	        case Error:
19
-	            E error = ((Result.Error<T, E>)this).value;
20
-	            temp1 = new Error(error);
21
-	            break;
22
-	        default:
23
-	            throw new AssertionError("Missing case");
24
-	    }
25
-	    return temp1;
26
-	}
27
-	
28
-	public <X> Result<T, X> handle(Class<X> typeOfX, Function10<T, X, E> handler) {
29
-	    Result<T, X> temp1;
30
-	    switch (this.getDiscriminant()) {
31
-	        case Ok:
32
-	            T result = ((Result.Ok<T, E>)this).value;
33
-	            temp1 = new Ok(result);
34
-	            break;
35
-	        case Error:
36
-	            E error = ((Result.Error<T, E>)this).value;
37
-	            temp1 = handler.invoke(error);
38
-	            break;
39
-	        default:
40
-	            throw new AssertionError("Missing case");
41
-	    }
42
-	    return temp1;
43
-	}
44
-	
45
-	public T expect() {
46
-	    T temp1;
47
-	    switch (this.getDiscriminant()) {
48
-	        case Ok:
49
-	            T result = ((Result.Ok<T, E>)this).value;
50
-	            temp1 = result;
51
-	            break;
52
-	        case Error:
53
-	            E error = ((Result.Error<T, E>)this).value;
54
-	            throw new AssertionError("expect() called on an error value");
55
-	        default:
56
-	            throw new AssertionError("Missing case");
57
-	    }
58
-	    return temp1;
59
-	}
60
-	
61
-	public T orElse(T other) {
62
-	    T temp1;
63
-	    switch (this.getDiscriminant()) {
64
-	        case Ok:
65
-	            T result = ((Result.Ok<T, E>)this).value;
66
-	            temp1 = result;
67
-	            break;
68
-	        case Error:
69
-	            E error = ((Result.Error<T, E>)this).value;
70
-	            temp1 = other;
71
-	            break;
72
-	        default:
73
-	            throw new AssertionError("Missing case");
74
-	    }
75
-	    return temp1;
76
-	}
77
-	
78
-	public T orElse(Function11<T, E> other) {
79
-	    T temp1;
80
-	    switch (this.getDiscriminant()) {
81
-	        case Ok:
82
-	            T result = ((Result.Ok<T, E>)this).value;
83
-	            temp1 = result;
84
-	            break;
85
-	        case Error:
86
-	            E error = ((Result.Error<T, E>)this).value;
87
-	            temp1 = other.invoke(error);
88
-	            break;
89
-	        default:
90
-	            throw new AssertionError("Missing case");
91
-	    }
92
-	    return temp1;
93
-	}
10
+    public <R> Result<R, E> then(Class<R> typeOfR, FunctionTToResultWithUV<R, E, T> fn) {
11
+        Result<R, E> temp1;
12
+        switch (this.getDiscriminant()) {
13
+            case Ok:
14
+                T result = ((Result.Ok<T, E>)this).value;
15
+                temp1 = fn.invoke(result);
16
+                break;
17
+            case Error:
18
+                E error = ((Result.Error<T, E>)this).value;
19
+                temp1 = new Error(error);
20
+                break;
21
+            default:
22
+                throw new AssertionError("Missing case");
23
+        }
24
+        return temp1;
25
+    }
26
+    
27
+    public <X> Result<T, X> handle(Class<X> typeOfX, FunctionTToResultWithUV<T, X, E> handler) {
28
+        Result<T, X> temp1;
29
+        switch (this.getDiscriminant()) {
30
+            case Ok:
31
+                T result = ((Result.Ok<T, E>)this).value;
32
+                temp1 = new Ok(result);
33
+                break;
34
+            case Error:
35
+                E error = ((Result.Error<T, E>)this).value;
36
+                temp1 = handler.invoke(error);
37
+                break;
38
+            default:
39
+                throw new AssertionError("Missing case");
40
+        }
41
+        return temp1;
42
+    }
43
+    
44
+    public T expect() {
45
+        T temp1;
46
+        switch (this.getDiscriminant()) {
47
+            case Ok:
48
+                T result = ((Result.Ok<T, E>)this).value;
49
+                temp1 = result;
50
+                break;
51
+            case Error:
52
+                E error = ((Result.Error<T, E>)this).value;
53
+                throw new AssertionError("expect() called on an error value");
54
+            default:
55
+                throw new AssertionError("Missing case");
56
+        }
57
+        return temp1;
58
+    }
59
+    
60
+    public T orElse(T other) {
61
+        T temp1;
62
+        switch (this.getDiscriminant()) {
63
+            case Ok:
64
+                T result = ((Result.Ok<T, E>)this).value;
65
+                temp1 = result;
66
+                break;
67
+            case Error:
68
+                E error = ((Result.Error<T, E>)this).value;
69
+                temp1 = other;
70
+                break;
71
+            default:
72
+                throw new AssertionError("Missing case");
73
+        }
74
+        return temp1;
75
+    }
76
+    
77
+    public T orElse(FunctionTToU<T, E> other) {
78
+        T temp1;
79
+        switch (this.getDiscriminant()) {
80
+            case Ok:
81
+                T result = ((Result.Ok<T, E>)this).value;
82
+                temp1 = result;
83
+                break;
84
+            case Error:
85
+                E error = ((Result.Error<T, E>)this).value;
86
+                temp1 = other.invoke(error);
87
+                break;
88
+            default:
89
+                throw new AssertionError("Missing case");
90
+        }
91
+        return temp1;
92
+    }
94
     public abstract Discriminant getDiscriminant();
93
     public abstract Discriminant getDiscriminant();
95
     
94
     
96
     public static enum Discriminant {
95
     public static enum Discriminant {
98
         Error,
97
         Error,
99
     }
98
     }
100
     
99
     
101
-    public static class Ok<T, E>  extends Result<T, E> {
100
+    public static class Ok<T, E> extends Result<T, E> {
102
         public final T value;
101
         public final T value;
103
         
102
         
104
         public Ok(T value){
103
         public Ok(T value){
111
         }
110
         }
112
     }
111
     }
113
     
112
     
114
-    public static class Error<T, E>  extends Result<T, E> {
113
+    public static class Error<T, E> extends Result<T, E> {
115
         public final E value;
114
         public final E value;
116
         
115
         
117
         public Error(E value){
116
         public Error(E value){
123
             return Discriminant.Error;
122
             return Discriminant.Error;
124
         }
123
         }
125
     }
124
     }
126
-	public static <T, E extends Exception> T unwrap(Class<T> typeOfT, Class<E> typeOfE, Result<T, E> self) throws E {
127
-	    T temp1;
128
-	    switch (self.getDiscriminant()) {
129
-	        case Ok:
130
-	            T result = ((Result.Ok<T, E>)self).value;
131
-	            temp1 = result;
132
-	            break;
133
-	        case Error:
134
-	            E error = ((Result.Error<T, E>)self).value;
135
-	            throw error;
136
-	        default:
137
-	            throw new AssertionError("Missing case");
138
-	    }
139
-	    return temp1;
140
-	}
125
+    public static <T, E extends Exception> T unwrap(Class<T> typeOfT, Class<E> typeOfE, Result<T, E> self) throws E {
126
+        T temp1;
127
+        switch (self.getDiscriminant()) {
128
+            case Ok:
129
+                T result = ((Result.Ok<T, E>)self).value;
130
+                temp1 = result;
131
+                break;
132
+            case Error:
133
+                E error = ((Result.Error<T, E>)self).value;
134
+                throw error;
135
+            default:
136
+                throw new AssertionError("Missing case");
137
+        }
138
+        return temp1;
139
+    }
141
 }
140
 }

+ 3
- 3
Shared/src/main/java/stdlib/StringBuildable.java View File

2
 
2
 
3
 
3
 
4
 public interface StringBuildable {
4
 public interface StringBuildable {
5
-	void toString(StringBuilder output);
6
-	
7
-	String toString();
5
+    void toString(StringBuilder output);
6
+    
7
+    String toString();
8
 }
8
 }

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

2
 
2
 
3
 
3
 
4
 public final class StringBuilder {
4
 public final class StringBuilder {
5
-	public static StringBuilder shl(StringBuilder self, StringBuildable value) {
6
-	    value.toString(self);
7
-	    return self;
8
-	}
5
+    public static StringBuilder shl(StringBuilder self, StringBuildable value) {
6
+        value.toString(self);
7
+        return self;
8
+    }
9
 }
9
 }

+ 1
- 1
Shared/src/main/java/zsynthetic/ArrayHelpers.java View File

3
 public class ArrayHelpers {
3
 public class ArrayHelpers {
4
     public static <T> boolean contains(T[] haystack, T needle) {
4
     public static <T> boolean contains(T[] haystack, T needle) {
5
         for (int i = 0; i < haystack.length; i++)
5
         for (int i = 0; i < haystack.length; i++)
6
-            if (java.util.Objects.equals(haystack[i], needle))
6
+            if (haystack[i].equals(needle))
7
                 return true;
7
                 return true;
8
         return false;
8
         return false;
9
     }
9
     }

+ 0
- 8
Shared/src/main/java/zsynthetic/Function10.java View File

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

+ 0
- 6
Shared/src/main/java/zsynthetic/Function11.java View File

1
-package zsynthetic;
2
-
3
-@FunctionalInterface
4
-public interface Function11<T, E>  {
5
-    T invoke(E error);
6
-}

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

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

+ 0
- 6
Shared/src/main/java/zsynthetic/Function8.java View File

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

+ 6
- 0
Shared/src/main/java/zsynthetic/FunctionBoolBoolToVoid.java View File

1
+package zsynthetic;
2
+
3
+@FunctionalInterface
4
+public interface FunctionBoolBoolToVoid {
5
+    void invoke(boolean oldValue, boolean newValue);
6
+}

+ 6
- 0
Shared/src/main/java/zsynthetic/FunctionIntIntToVoid.java View File

1
+package zsynthetic;
2
+
3
+@FunctionalInterface
4
+public interface FunctionIntIntToVoid {
5
+    void invoke(int oldValue, int newValue);
6
+}

Shared/src/main/java/zsynthetic/Function4.java → Shared/src/main/java/zsynthetic/FunctionIntTToBool.java View File

1
 package zsynthetic;
1
 package zsynthetic;
2
 
2
 
3
 @FunctionalInterface
3
 @FunctionalInterface
4
-public interface Function4<T>  {
4
+public interface FunctionIntTToBool<T> {
5
     boolean invoke(int index, T value);
5
     boolean invoke(int index, T value);
6
 }
6
 }

Shared/src/main/java/zsynthetic/Function2.java → Shared/src/main/java/zsynthetic/FunctionIntTToU.java View File

1
 package zsynthetic;
1
 package zsynthetic;
2
 
2
 
3
 @FunctionalInterface
3
 @FunctionalInterface
4
-public interface Function2<U, T>  {
4
+public interface FunctionIntTToU<U, T> {
5
     U invoke(int index, T value);
5
     U invoke(int index, T value);
6
 }
6
 }

Shared/src/main/java/zsynthetic/Function6.java → Shared/src/main/java/zsynthetic/FunctionIntTToVoid.java View File

1
 package zsynthetic;
1
 package zsynthetic;
2
 
2
 
3
 @FunctionalInterface
3
 @FunctionalInterface
4
-public interface Function6<T>  {
4
+public interface FunctionIntTToVoid<T> {
5
     void invoke(int index, T value);
5
     void invoke(int index, T value);
6
 }
6
 }

+ 6
- 0
Shared/src/main/java/zsynthetic/FunctionStringStringToVoid.java View File

1
+package zsynthetic;
2
+
3
+@FunctionalInterface
4
+public interface FunctionStringStringToVoid {
5
+    void invoke(String oldValue, String newValue);
6
+}

+ 6
- 0
Shared/src/main/java/zsynthetic/FunctionTTToVoid.java View File

1
+package zsynthetic;
2
+
3
+@FunctionalInterface
4
+public interface FunctionTTToVoid<T> {
5
+    void invoke(T oldValue, T newValue);
6
+}

Shared/src/main/java/zsynthetic/Function3.java → Shared/src/main/java/zsynthetic/FunctionTToBool.java View File

1
 package zsynthetic;
1
 package zsynthetic;
2
 
2
 
3
 @FunctionalInterface
3
 @FunctionalInterface
4
-public interface Function3<T>  {
4
+public interface FunctionTToBool<T> {
5
     boolean invoke(T value);
5
     boolean invoke(T value);
6
 }
6
 }

Shared/src/main/java/zsynthetic/Function9.java → Shared/src/main/java/zsynthetic/FunctionTToResultWithUV.java View File

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

Shared/src/main/java/zsynthetic/Function1.java → Shared/src/main/java/zsynthetic/FunctionTToU.java View File

1
 package zsynthetic;
1
 package zsynthetic;
2
 
2
 
3
 @FunctionalInterface
3
 @FunctionalInterface
4
-public interface Function1<U, T>  {
4
+public interface FunctionTToU<U, T> {
5
     U invoke(T value);
5
     U invoke(T value);
6
 }
6
 }

Shared/src/main/java/zsynthetic/Function5.java → Shared/src/main/java/zsynthetic/FunctionTToVoid.java View File

1
 package zsynthetic;
1
 package zsynthetic;
2
 
2
 
3
 @FunctionalInterface
3
 @FunctionalInterface
4
-public interface Function5<T>  {
4
+public interface FunctionTToVoid<T> {
5
     void invoke(T value);
5
     void invoke(T value);
6
 }
6
 }

Loading…
Cancel
Save