Browse Source

Started working on propagating a logger object instead of having to resort to Sysout

Mwahaha, Jared you will have to review this :manic_laugther:
kindlich 4 years ago
parent
commit
1b737430f9
No known key found for this signature in database
54 changed files with 711 additions and 443 deletions
  1. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/HighLevelDefinition.java
  2. 20
    14
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/SemanticModule.java
  3. 2
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/partial/PartialMemberGroupExpression.java
  4. 7
    6
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/DefinitionTypeID.java
  5. 2
    1
      CompilerShared/src/main/java/org/openzen/zenscript/compiler/Target.java
  6. 20
    11
      Constructor/src/main/java/org/openzen/zenscript/constructor/ConstructorRegistry.java
  7. 2
    1
      Constructor/src/main/java/org/openzen/zenscript/constructor/Main.java
  8. 4
    2
      Constructor/src/main/java/org/openzen/zenscript/constructor/ModuleLoader.java
  9. 4
    3
      Constructor/src/main/java/org/openzen/zenscript/constructor/ParsedModule.java
  10. 4
    2
      Constructor/src/main/java/org/openzen/zenscript/constructor/module/DirectoryModuleReference.java
  11. 3
    1
      Constructor/src/main/java/org/openzen/zenscript/constructor/module/ModuleReference.java
  12. 2
    1
      Constructor/src/main/java/org/openzen/zenscript/constructor/module/SourceModule.java
  13. 9
    7
      Constructor/src/main/java/org/openzen/zenscript/constructor/module/SourceModuleReference.java
  14. 2
    1
      Constructor/src/main/java/org/openzen/zenscript/constructor/module/directory/DirectorySourceModule.java
  15. 43
    0
      Constructor/src/main/java/org/openzen/zenscript/constructor/module/logging/EmptyModuleLogger.java
  16. 6
    0
      Constructor/src/main/java/org/openzen/zenscript/constructor/module/logging/ModuleLogger.java
  17. 4
    2
      IDE/src/main/java/org/openzen/zenscript/ide/host/local/LocalModule.java
  18. 16
    28
      IDE/src/main/java/org/openzen/zenscript/ide/host/local/LocalTarget.java
  19. 80
    0
      IDE/src/main/java/org/openzen/zenscript/ide/host/local/logging/LocalModuleLogger.java
  20. 57
    0
      IDE/src/main/java/org/openzen/zenscript/ide/host/local/logging/LocalValidatorLogger.java
  21. 4
    3
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaBytecodeContext.java
  22. 8
    4
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaBytecodeModule.java
  23. 9
    3
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaBytecodeRunUnit.java
  24. 12
    7
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaCompiler.java
  25. 6
    6
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaExpressionVisitor.java
  26. 143
    138
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaWriter.java
  27. 7
    7
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/definitions/JavaDefinitionVisitor.java
  28. 5
    5
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/definitions/JavaExpansionMemberVisitor.java
  29. 10
    9
      JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/definitions/JavaMemberVisitor.java
  30. 0
    34
      JavaIntegration/src/main/java/org/openzen/zencode/java/EmptyLogger.java
  31. 8
    4
      JavaIntegration/src/main/java/org/openzen/zencode/java/JavaNativeLoader.java
  32. 4
    3
      JavaIntegration/src/main/java/org/openzen/zencode/java/JavaNativeModule.java
  33. 21
    36
      JavaIntegration/src/main/java/org/openzen/zencode/java/ScriptingEngine.java
  34. 7
    0
      JavaIntegration/src/main/java/org/openzen/zencode/java/logger/ScriptingEngineLogger.java
  35. 83
    0
      JavaIntegration/src/main/java/org/openzen/zencode/java/logger/ScriptingEngineStreamLogger.java
  36. 2
    2
      JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaClass.java
  37. 4
    1
      JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaContext.java
  38. 6
    6
      JavaShared/src/main/java/org/openzen/zenscript/javashared/prepare/JavaPrepareClassMethodVisitor.java
  39. 3
    3
      JavaShared/src/main/java/org/openzen/zenscript/javashared/prepare/JavaPrepareDefinitionMemberVisitor.java
  40. 2
    2
      JavaShared/src/main/java/org/openzen/zenscript/javashared/prepare/JavaPrepareExpansionMethodVisitor.java
  41. 3
    2
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceCompiler.java
  42. 3
    2
      JavaSourceCompiler/src/main/java/org/openzen/zenscript/javasource/JavaSourceContext.java
  43. 6
    4
      Parser/src/main/java/org/openzen/zenscript/parser/FolderPackage.java
  44. 10
    8
      Parser/src/main/java/org/openzen/zenscript/parser/ParsedFile.java
  45. 5
    4
      Parser/src/main/java/org/openzen/zenscript/parser/ZippedPackage.java
  46. 0
    4
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedNewExpression.java
  47. 5
    0
      Parser/src/main/java/org/openzen/zenscript/parser/logger/ParserLogger.java
  48. 0
    58
      ScriptingExample/src/main/java/org/openzen/zenscript/scriptingexample/logging/StreamLogger.java
  49. 7
    0
      Shared/src/main/java/org/openzen/zencode/shared/logging/CompileExceptionLogger.java
  50. 1
    1
      Shared/src/main/java/org/openzen/zencode/shared/logging/IZSLogger.java
  51. 7
    0
      Shared/src/main/java/org/openzen/zencode/shared/logging/SourceFileLogger.java
  52. 6
    4
      Validator/src/main/java/org/openzen/zenscript/validator/Validator.java
  53. 21
    0
      Validator/src/main/java/org/openzen/zenscript/validator/logger/IZSValidationLogger.java
  54. 5
    0
      Validator/src/main/java/org/openzen/zenscript/validator/logger/ValidatorLogger.java

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/HighLevelDefinition.java View File

@@ -196,7 +196,7 @@ public abstract class HighLevelDefinition extends Taggable {
196 196
 		}
197 197
 		
198 198
 		if (isDestructible() && destructor == null && !(this instanceof ExpansionDefinition)) {
199
-			System.out.println("Added destructor to " + position);
199
+			//System.out.println("Added destructor to " + position);
200 200
 			destructor = new DestructorMember(position, this, Modifiers.PUBLIC);
201 201
 			members.add(destructor);
202 202
 		}

+ 20
- 14
CodeModel/src/main/java/org/openzen/zenscript/codemodel/SemanticModule.java View File

@@ -9,6 +9,8 @@ import java.util.ArrayList;
9 9
 import java.util.HashMap;
10 10
 import java.util.List;
11 11
 import java.util.Map;
12
+
13
+import org.openzen.zencode.shared.logging.*;
12 14
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
13 15
 import org.openzen.zenscript.codemodel.annotations.AnnotationProcessor;
14 16
 import org.openzen.zenscript.codemodel.context.ModuleContext;
@@ -43,20 +45,22 @@ public class SemanticModule {
43 45
 	public final List<ExpansionDefinition> expansions;
44 46
 	public final AnnotationDefinition[] annotations;
45 47
 	public final StorageType[] storageTypes;
48
+	public final IZSLogger logger;
46 49
 	
47 50
 	public SemanticModule(
48
-			Module module,
49
-			SemanticModule[] dependencies,
50
-			FunctionParameter[] parameters,
51
-			State state,
52
-			ZSPackage rootPackage,
53
-			ZSPackage modulePackage,
54
-			PackageDefinitions definitions,
55
-			List<ScriptBlock> scripts,
56
-			GlobalTypeRegistry registry,
57
-			List<ExpansionDefinition> expansions,
58
-			AnnotationDefinition[] annotations,
59
-			StorageType[] storageTypes)
51
+	        Module module,
52
+            SemanticModule[] dependencies,
53
+            FunctionParameter[] parameters,
54
+            State state,
55
+            ZSPackage rootPackage,
56
+            ZSPackage modulePackage,
57
+            PackageDefinitions definitions,
58
+            List<ScriptBlock> scripts,
59
+            GlobalTypeRegistry registry,
60
+            List<ExpansionDefinition> expansions,
61
+            AnnotationDefinition[] annotations,
62
+            StorageType[] storageTypes,
63
+            IZSLogger logger)
60 64
 	{
61 65
 		this.name = module.name;
62 66
 		this.module = module;
@@ -73,7 +77,8 @@ public class SemanticModule {
73 77
 		this.expansions = expansions;
74 78
 		this.annotations = annotations;
75 79
 		this.storageTypes = storageTypes;
76
-	}
80
+        this.logger = logger;
81
+    }
77 82
 	
78 83
 	public boolean isValid() {
79 84
 		return state != State.INVALID;
@@ -108,7 +113,8 @@ public class SemanticModule {
108 113
 				registry,
109 114
 				expansions,
110 115
 				annotations,
111
-				storageTypes);
116
+				storageTypes,
117
+                logger);
112 118
 	}
113 119
 	
114 120
 	public ModuleContext getContext() {

+ 2
- 2
CodeModel/src/main/java/org/openzen/zenscript/codemodel/partial/PartialMemberGroupExpression.java View File

@@ -100,8 +100,8 @@ public class PartialMemberGroupExpression implements IPartialExpression {
100 100
 				// ignore this here
101 101
 			}
102 102
 		}
103
-		if (results.isEmpty())
104
-			System.out.println("!");
103
+		//if (results.isEmpty())
104
+		//	System.out.println("!");
105 105
 		return results;
106 106
 	}
107 107
 

+ 7
- 6
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/DefinitionTypeID.java View File

@@ -101,12 +101,13 @@ public class DefinitionTypeID implements TypeID {
101 101
 		DefinitionTypeID current = this;
102 102
 		do {
103 103
 			if (current.typeArguments != null) {
104
-				if (current.definition.typeParameters == null)
105
-					System.out.println("Type parameters but no generic parameters");
106
-				else
107
-					for (int i = 0; i < current.typeArguments.length; i++)
108
-						mapping.put(current.definition.typeParameters[i], current.typeArguments[i]);
109
-			}
104
+                if(current.definition.typeParameters != null) {
105
+                    for (int i = 0; i < current.typeArguments.length; i++)
106
+                        mapping.put(current.definition.typeParameters[i], current.typeArguments[i]);
107
+                }//else {
108
+                //    System.out.println("Type parameters but no generic parameters");
109
+                //}
110
+            }
110 111
 
111 112
 			current = current.outer;
112 113
 		} while (current != null && !current.definition.isStatic());

+ 2
- 1
CompilerShared/src/main/java/org/openzen/zenscript/compiler/Target.java View File

@@ -5,6 +5,7 @@
5 5
  */
6 6
 package org.openzen.zenscript.compiler;
7 7
 
8
+import org.openzen.zencode.shared.logging.*;
8 9
 import org.openzen.zenscript.codemodel.SemanticModule;
9 10
 
10 11
 /**
@@ -12,7 +13,7 @@ import org.openzen.zenscript.codemodel.SemanticModule;
12 13
  * @author Hoofdgebruiker
13 14
  */
14 15
 public interface Target {
15
-	public ZenCodeCompiler createCompiler(SemanticModule module);
16
+	public ZenCodeCompiler createCompiler(SemanticModule module, IZSLogger logger);
16 17
 	
17 18
 	public String getModule();
18 19
 	

+ 20
- 11
Constructor/src/main/java/org/openzen/zenscript/constructor/ConstructorRegistry.java View File

@@ -6,6 +6,7 @@
6 6
 package org.openzen.zenscript.constructor;
7 7
 
8 8
 import org.json.JSONObject;
9
+import org.openzen.zencode.shared.logging.*;
9 10
 import org.openzen.zenscript.codemodel.SemanticModule;
10 11
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
11 12
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
@@ -75,8 +76,8 @@ public class ConstructorRegistry {
75 76
 		}
76 77
 
77 78
 		@Override
78
-		public ZenCodeCompiler createCompiler(SemanticModule module) {
79
-			return new JavaSourceZenCompiler(output, module.registry);
79
+		public ZenCodeCompiler createCompiler(SemanticModule module, IZSLogger logger) {
80
+			return new JavaSourceZenCompiler(output, module.registry, logger);
80 81
 		}
81 82
 
82 83
 		@Override
@@ -107,17 +108,19 @@ public class ConstructorRegistry {
107 108
 		
108 109
 		public final GlobalTypeRegistry registry;
109 110
 		private final SimpleJavaCompileSpace space;
111
+		private final IZSLogger logger;
110 112
 		
111
-		public JavaSourceZenCompiler(File output, GlobalTypeRegistry registry) {
113
+		public JavaSourceZenCompiler(File output, GlobalTypeRegistry registry, IZSLogger logger) {
112 114
 			this.output = output;
113 115
 			compiler = new JavaSourceCompiler(registry);
114 116
 			this.registry = registry;
115 117
 			space = new SimpleJavaCompileSpace(registry);
116
-		}
118
+            this.logger = logger;
119
+        }
117 120
 
118 121
 		@Override
119 122
 		public void addModule(SemanticModule module) {
120
-			JavaSourceModule result = compiler.compile(module, space, module.modulePackage.fullName);
123
+			JavaSourceModule result = compiler.compile(logger, module, space, module.modulePackage.fullName);
121 124
 			writeMappings(result);
122 125
 			
123 126
 			modules.add(result);
@@ -169,8 +172,8 @@ public class ConstructorRegistry {
169 172
 		}
170 173
 
171 174
 		@Override
172
-		public ZenCodeCompiler createCompiler(SemanticModule module) {
173
-			return new JavaBytecodeJarCompiler();
175
+		public ZenCodeCompiler createCompiler(SemanticModule module, IZSLogger logger) {
176
+			return new JavaBytecodeJarCompiler(logger);
174 177
 		}
175 178
 
176 179
 		@Override
@@ -199,11 +202,17 @@ public class ConstructorRegistry {
199 202
 		private final ZSPackage stdlib = new ZSPackage(root, "stdlib");
200 203
 		public final GlobalTypeRegistry registry = new GlobalTypeRegistry(stdlib);
201 204
 		
202
-		private final JavaCompiler compiler = new JavaCompiler();
205
+		private final JavaCompiler compiler;
203 206
 		private final List<JavaBytecodeModule> modules = new ArrayList<>();
204 207
 		private final SimpleJavaCompileSpace space = new SimpleJavaCompileSpace(registry);
205
-
206
-		@Override
208
+        private final IZSLogger logger;
209
+        
210
+        public JavaBytecodeJarCompiler(IZSLogger logger) {
211
+            this.logger = logger;
212
+            compiler = new JavaCompiler(logger);
213
+        }
214
+        
215
+        @Override
207 216
 		public void addModule(SemanticModule module) {
208 217
 			JavaBytecodeModule result = compiler.compile(module.modulePackage.fullName, module, space);
209 218
 			modules.add(result);
@@ -217,7 +226,7 @@ public class ConstructorRegistry {
217 226
 
218 227
 		@Override
219 228
 		public void run() {
220
-			JavaBytecodeRunUnit unit = new JavaBytecodeRunUnit();
229
+			JavaBytecodeRunUnit unit = new JavaBytecodeRunUnit(logger);
221 230
 			for (JavaBytecodeModule module : modules)
222 231
 				unit.add(module);
223 232
 			//unit.add(compiler.helpers);

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

@@ -9,6 +9,7 @@ import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
9 9
 import org.openzen.zenscript.constructor.module.ModuleReference;
10 10
 import org.openzen.zenscript.constructor.module.SourceModuleReference;
11 11
 import org.openzen.zenscript.constructor.module.directory.DirectorySourceModule;
12
+import org.openzen.zenscript.constructor.module.logging.*;
12 13
 
13 14
 public class Main {
14 15
     /**
@@ -22,7 +23,7 @@ public class Main {
22 23
 			return;
23 24
 		}
24 25
 		
25
-		Consumer<CompileException> exceptionLogger = exception -> System.err.println(exception.toString());
26
+        ModuleLogger exceptionLogger = new EmptyModuleLogger();
26 27
 		
27 28
 		File currentDirectory = new File(arguments.directory);
28 29
 		ZSPackage root = ZSPackage.createRoot();

+ 4
- 2
Constructor/src/main/java/org/openzen/zenscript/constructor/ModuleLoader.java View File

@@ -11,9 +11,11 @@ import java.util.Map;
11 11
 import java.util.Stack;
12 12
 import java.util.function.Consumer;
13 13
 import org.openzen.zencode.shared.CompileException;
14
+import org.openzen.zencode.shared.logging.*;
14 15
 import org.openzen.zenscript.codemodel.SemanticModule;
15 16
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
16 17
 import org.openzen.zenscript.constructor.module.ModuleReference;
18
+import org.openzen.zenscript.constructor.module.logging.*;
17 19
 
18 20
 /**
19 21
  *
@@ -27,9 +29,9 @@ public class ModuleLoader {
27 29
 	private final Stack<String> compilingModulesStack = new Stack<>();
28 30
 	
29 31
 	private final GlobalTypeRegistry registry;
30
-	private final Consumer<CompileException> exceptionLogger;
32
+	private final ModuleLogger exceptionLogger;
31 33
 	
32
-	public ModuleLoader(GlobalTypeRegistry registry, Consumer<CompileException> exceptionLogger) {
34
+	public ModuleLoader(GlobalTypeRegistry registry, ModuleLogger exceptionLogger) {
33 35
 		this.registry = registry;
34 36
 		this.exceptionLogger = exceptionLogger;
35 37
 	}

+ 4
- 3
Constructor/src/main/java/org/openzen/zenscript/constructor/ParsedModule.java View File

@@ -16,6 +16,7 @@ import org.json.JSONArray;
16 16
 import org.json.JSONObject;
17 17
 import org.json.JSONTokener;
18 18
 import org.openzen.zencode.shared.CompileException;
19
+import org.openzen.zencode.shared.logging.*;
19 20
 import org.openzen.zenscript.codemodel.context.CompilingPackage;
20 21
 import org.openzen.zenscript.lexer.ParseException;
21 22
 import org.openzen.zenscript.parser.BracketExpressionParser;
@@ -32,12 +33,12 @@ public class ParsedModule {
32 33
 	public final String packageName;
33 34
 	public final String javaPackageName;
34 35
 	public final String host;
35
-	private final Consumer<CompileException> exceptionLogger;
36
+	//private final CompileExceptionLogger exceptionLogger;
36 37
 	
37
-	public ParsedModule(String name, File directory, File moduleFile, Consumer<CompileException> exceptionLogger) throws IOException {
38
+	public ParsedModule(String name, File directory, File moduleFile, CompileExceptionLogger exceptionLogger) throws IOException {
38 39
 		this.name = name;
39 40
 		this.sourceDirectory = new File(directory, "src");
40
-		this.exceptionLogger = exceptionLogger;
41
+		//this.exceptionLogger = exceptionLogger;
41 42
 		
42 43
 		BufferedInputStream input = new BufferedInputStream(new FileInputStream(moduleFile));
43 44
 		JSONObject json = new JSONObject(new JSONTokener(input));

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

@@ -8,9 +8,10 @@ package org.openzen.zenscript.constructor.module;
8 8
 import org.openzen.zenscript.constructor.module.directory.SourceDirectoryPackage;
9 9
 import java.io.File;
10 10
 import java.io.IOException;
11
+import java.lang.*;
12
+import java.lang.String;
11 13
 import java.util.ArrayList;
12 14
 import java.util.List;
13
-import java.util.function.Consumer;
14 15
 import org.json.JSONArray;
15 16
 import org.json.JSONObject;
16 17
 import org.openzen.zencode.shared.CompileException;
@@ -28,6 +29,7 @@ import org.openzen.zenscript.constructor.ParsedModule;
28 29
 import org.openzen.zenscript.constructor.ModuleLoader;
29 30
 import org.openzen.zenscript.codemodel.type.TypeSymbol;
30 31
 import org.openzen.zenscript.codemodel.type.storage.StorageType;
32
+import org.openzen.zenscript.constructor.module.logging.*;
31 33
 import org.openzen.zenscript.lexer.ParseException;
32 34
 import org.openzen.zenscript.parser.ParsedFile;
33 35
 
@@ -53,7 +55,7 @@ public class DirectoryModuleReference implements ModuleReference {
53 55
 	}
54 56
 
55 57
 	@Override
56
-	public SemanticModule load(ModuleLoader loader, GlobalTypeRegistry registry, Consumer<CompileException> exceptionLogger) {
58
+	public SemanticModule load(ModuleLoader loader, GlobalTypeRegistry registry, ModuleLogger exceptionLogger) {
57 59
 		if (!directory.exists())
58 60
 			throw new ConstructorException("Error: module directory not found: " + directory);
59 61
 		

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

@@ -7,9 +7,11 @@ package org.openzen.zenscript.constructor.module;
7 7
 
8 8
 import java.util.function.Consumer;
9 9
 import org.openzen.zencode.shared.CompileException;
10
+import org.openzen.zencode.shared.logging.*;
10 11
 import org.openzen.zenscript.codemodel.SemanticModule;
11 12
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
12 13
 import org.openzen.zenscript.constructor.ModuleLoader;
14
+import org.openzen.zenscript.constructor.module.logging.*;
13 15
 
14 16
 /**
15 17
  *
@@ -18,7 +20,7 @@ import org.openzen.zenscript.constructor.ModuleLoader;
18 20
 public interface ModuleReference {
19 21
 	public String getName();
20 22
 	
21
-	public SemanticModule load(ModuleLoader loader, GlobalTypeRegistry registry, Consumer<CompileException> exceptionLogger);
23
+	public SemanticModule load(ModuleLoader loader, GlobalTypeRegistry registry, ModuleLogger exceptionLogger);
22 24
 	
23 25
 	public SourcePackage getRootPackage();
24 26
 }

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

@@ -8,6 +8,7 @@ package org.openzen.zenscript.constructor.module;
8 8
 import java.util.Map;
9 9
 import java.util.function.Consumer;
10 10
 import org.openzen.zencode.shared.CompileException;
11
+import org.openzen.zencode.shared.logging.*;
11 12
 import org.openzen.zenscript.codemodel.SemanticModule;
12 13
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
13 14
 import org.openzen.zenscript.codemodel.type.ISymbol;
@@ -22,7 +23,7 @@ public interface SourceModule {
22 23
 	
23 24
 	public SourcePackage getRootPackage();
24 25
 	
25
-	public SemanticModule[] loadDependencies(ModuleLoader loader, GlobalTypeRegistry registry, Consumer<CompileException> exceptionLogger);
26
+	public SemanticModule[] loadDependencies(ModuleLoader loader, GlobalTypeRegistry registry, CompileExceptionLogger exceptionLogger);
26 27
 	
27 28
 	public Map<String, ISymbol> getGlobals(SemanticModule module);
28 29
 }

+ 9
- 7
Constructor/src/main/java/org/openzen/zenscript/constructor/module/SourceModuleReference.java View File

@@ -11,6 +11,7 @@ import java.util.function.Consumer;
11 11
 import org.openzen.zencode.shared.CompileException;
12 12
 import org.openzen.zencode.shared.CompileExceptionCode;
13 13
 import org.openzen.zencode.shared.SourceFile;
14
+import org.openzen.zencode.shared.logging.*;
14 15
 import org.openzen.zenscript.codemodel.FunctionParameter;
15 16
 import org.openzen.zenscript.codemodel.Module;
16 17
 import org.openzen.zenscript.codemodel.ModuleSpace;
@@ -21,6 +22,7 @@ import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
21 22
 import org.openzen.zenscript.constructor.ConstructorException;
22 23
 import org.openzen.zenscript.constructor.ModuleLoader;
23 24
 import org.openzen.zenscript.codemodel.type.storage.StorageType;
25
+import org.openzen.zenscript.constructor.module.logging.*;
24 26
 import org.openzen.zenscript.lexer.ParseException;
25 27
 import org.openzen.zenscript.parser.BracketExpressionParser;
26 28
 import org.openzen.zenscript.parser.ParsedFile;
@@ -48,8 +50,8 @@ public class SourceModuleReference implements ModuleReference {
48 50
 	}
49 51
 
50 52
 	@Override
51
-	public SemanticModule load(ModuleLoader loader, GlobalTypeRegistry registry, Consumer<CompileException> exceptionLogger) {
52
-		SemanticModule[] dependencies = module.loadDependencies(loader, registry, exceptionLogger);
53
+	public SemanticModule load(ModuleLoader loader, GlobalTypeRegistry registry, ModuleLogger logger) {
54
+		SemanticModule[] dependencies = module.loadDependencies(loader, registry, logger);
53 55
 
54 56
 		ModuleSpace space = new ModuleSpace(registry, new ArrayList<>(), StorageType.getStandard());
55 57
 		for (SemanticModule module : dependencies) {
@@ -64,8 +66,8 @@ public class SourceModuleReference implements ModuleReference {
64 66
 		Module module = new Module(getName());
65 67
 		CompilingPackage compilingPackage = new CompilingPackage(pkg, module);
66 68
 
67
-		ParsedFile[] parsedFiles = parse(compilingPackage, exceptionLogger);
68
-		SemanticModule result = ParsedFile.compileSyntaxToSemantic(dependencies, compilingPackage, parsedFiles, space, FunctionParameter.NONE, exceptionLogger);
69
+		ParsedFile[] parsedFiles = parse(compilingPackage, logger);
70
+		SemanticModule result = ParsedFile.compileSyntaxToSemantic(dependencies, compilingPackage, parsedFiles, space, FunctionParameter.NONE, logger);
69 71
 		result.globals.putAll(this.module.getGlobals(result));
70 72
 		return result;
71 73
 	}
@@ -75,19 +77,19 @@ public class SourceModuleReference implements ModuleReference {
75 77
 		return module.getRootPackage();
76 78
 	}
77 79
 	
78
-	public ParsedFile[] parse(CompilingPackage compilingPackage, Consumer<CompileException> exceptionLogger) {
80
+	public ParsedFile[] parse(CompilingPackage compilingPackage, CompileExceptionLogger exceptionLogger) {
79 81
 		// TODO: load bracket parsers from host plugins
80 82
 		List<ParsedFile> files = new ArrayList<>();
81 83
 		parse(files, compilingPackage, null, module.getRootPackage(), exceptionLogger);
82 84
 		return files.toArray(new ParsedFile[files.size()]);
83 85
 	}
84 86
 	
85
-	private static void parse(List<ParsedFile> files, CompilingPackage pkg, BracketExpressionParser bracketParser, SourcePackage directory, Consumer<CompileException> exceptionLogger) {
87
+	private static void parse(List<ParsedFile> files, CompilingPackage pkg, BracketExpressionParser bracketParser, SourcePackage directory, CompileExceptionLogger exceptionLogger) {
86 88
 		for (SourceFile file : directory.getFiles()) {
87 89
 			try {
88 90
 				files.add(ParsedFile.parse(pkg, bracketParser, file));
89 91
 			} catch (ParseException ex) {
90
-				exceptionLogger.accept(new CompileException(ex.position, CompileExceptionCode.PARSE_ERROR, ex.message));
92
+				exceptionLogger.logCompileException(new CompileException(ex.position, CompileExceptionCode.PARSE_ERROR, ex.message));
91 93
 			}
92 94
 		}
93 95
 		for (SourcePackage subpkg : directory.getSubPackages()) {

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

@@ -16,6 +16,7 @@ import java.util.function.Consumer;
16 16
 import org.json.JSONArray;
17 17
 import org.json.JSONObject;
18 18
 import org.openzen.zencode.shared.CompileException;
19
+import org.openzen.zencode.shared.logging.*;
19 20
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
20 21
 import org.openzen.zenscript.codemodel.ModuleSpace;
21 22
 import org.openzen.zenscript.codemodel.SemanticModule;
@@ -75,7 +76,7 @@ public class DirectorySourceModule implements SourceModule {
75 76
 	}
76 77
 
77 78
 	@Override
78
-	public SemanticModule[] loadDependencies(ModuleLoader loader, GlobalTypeRegistry registry, Consumer<CompileException> exceptionLogger) {
79
+	public SemanticModule[] loadDependencies(ModuleLoader loader, GlobalTypeRegistry registry, CompileExceptionLogger exceptionLogger) {
79 80
 		List<String> dependencyNames = new ArrayList<>();
80 81
 		if (!isStdLib)
81 82
 			dependencyNames.add("stdlib");

+ 43
- 0
Constructor/src/main/java/org/openzen/zenscript/constructor/module/logging/EmptyModuleLogger.java View File

@@ -0,0 +1,43 @@
1
+package org.openzen.zenscript.constructor.module.logging;
2
+
3
+import org.openzen.zencode.shared.*;
4
+
5
+public class EmptyModuleLogger implements ModuleLogger {
6
+    
7
+    @Override
8
+    public void logCompileException(CompileException exception) {
9
+        error(exception.getMessage());
10
+    }
11
+    
12
+    @Override
13
+    public void info(String message) {
14
+        System.out.println(message);
15
+    }
16
+    
17
+    @Override
18
+    public void debug(String message) {
19
+        System.out.println(message);
20
+    }
21
+    
22
+    @Override
23
+    public void warning(String message) {
24
+        System.out.println(message);
25
+    }
26
+    
27
+    @Override
28
+    public void error(String message) {
29
+        System.err.println(message);
30
+    }
31
+    
32
+    @Override
33
+    public void throwingErr(String message, Throwable throwable) {
34
+        System.err.println(message);
35
+        throwable.printStackTrace();
36
+    }
37
+    
38
+    @Override
39
+    public void throwingWarn(String message, Throwable throwable) {
40
+        System.out.println(message);
41
+        throwable.printStackTrace(System.out);
42
+    }
43
+}

+ 6
- 0
Constructor/src/main/java/org/openzen/zenscript/constructor/module/logging/ModuleLogger.java View File

@@ -0,0 +1,6 @@
1
+package org.openzen.zenscript.constructor.module.logging;
2
+
3
+import org.openzen.zencode.shared.logging.*;
4
+import org.openzen.zenscript.parser.logger.*;
5
+
6
+public interface ModuleLogger extends CompileExceptionLogger, ParserLogger {}

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

@@ -13,7 +13,9 @@ import org.openzen.zenscript.ide.host.IDECodeError;
13 13
 import org.openzen.zenscript.ide.host.IDEModule;
14 14
 import org.openzen.zenscript.ide.host.IDEModuleType;
15 15
 import org.openzen.zenscript.ide.host.IDEPackage;
16
-import org.openzen.zenscript.validator.Validator;
16
+import org.openzen.zenscript.ide.host.local.logging.*;
17
+import org.openzen.zenscript.validator.*;
18
+import org.openzen.zenscript.validator.logger.*;
17 19
 
18 20
 /**
19 21
  *
@@ -46,6 +48,6 @@ public class LocalModule implements IDEModule {
46 48
 	@Override
47 49
 	public void prebuild(ModuleLoader loader, Consumer<IDECodeError> errors) {
48 50
 		SemanticModule module = loader.getModule(this.module.getName());
49
-		Validator.validate(module, entry -> errors.accept(new IDECodeError(null, entry.position, entry.message)));
51
+		Validator.validate(module, new LocalValidatorLogger(errors));
50 52
 	}
51 53
 }

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

@@ -12,6 +12,7 @@ import java.util.Stack;
12 12
 import java.util.function.Consumer;
13 13
 import live.LiveObject;
14 14
 import live.SimpleLiveObject;
15
+import org.openzen.zencode.shared.logging.*;
15 16
 import org.openzen.zenscript.codemodel.SemanticModule;
16 17
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
17 18
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
@@ -23,14 +24,17 @@ import org.openzen.zenscript.constructor.Project;
23 24
 import org.openzen.zenscript.constructor.module.directory.DirectorySourceModule;
24 25
 import org.openzen.zenscript.constructor.module.ModuleReference;
25 26
 import org.openzen.zenscript.constructor.module.SourceModuleReference;
27
+import org.openzen.zenscript.constructor.module.logging.*;
26 28
 import org.openzen.zenscript.ide.host.IDECodeError;
27 29
 import org.openzen.zenscript.ide.host.IDECompileState;
28 30
 import org.openzen.zenscript.ide.host.IDESourceFile;
29 31
 import org.openzen.zenscript.ide.host.IDETarget;
30
-import org.openzen.zenscript.ide.ui.view.output.ErrorOutputSpan;
31
-import org.openzen.zenscript.ide.ui.view.output.OutputLine;
32
+import org.openzen.zenscript.ide.host.local.logging.*;
33
+import org.openzen.zenscript.ide.ui.view.output.*;
34
+import org.openzen.zenscript.parser.logger.*;
32 35
 import org.openzen.zenscript.validator.ValidationLogEntry;
33 36
 import org.openzen.zenscript.validator.Validator;
37
+import org.openzen.zenscript.validator.logger.*;
34 38
 import stdlib.Strings;
35 39
 
36 40
 /**
@@ -92,30 +96,14 @@ public class LocalTarget implements IDETarget {
92 96
 		ZSPackage root = ZSPackage.createRoot();
93 97
 		ZSPackage stdlibPackage = new ZSPackage(root, "stdlib");
94 98
 		GlobalTypeRegistry registry = new GlobalTypeRegistry(stdlibPackage);
95
-		
96
-		ModuleLoader moduleLoader = new ModuleLoader(registry, exception -> {
97
-			IDESourceFile sourceFile = new LocalSourceFile(exception.position.file);
98
-			state.addError(sourceFile, new IDECodeError(sourceFile, exception.position, exception.message));
99
-			
100
-			String[] lines = Strings.split(exception.getMessage(), '\n');
101
-			for (String line : lines) {
102
-				output.accept(new OutputLine(new ErrorOutputSpan(line)));
103
-			}
104
-		});
99
+        final LocalModuleLogger localModuleLogger = new LocalModuleLogger(state, output);
100
+        ModuleLoader moduleLoader = new ModuleLoader(registry, localModuleLogger);
101
+        
105 102
 		//moduleLoader.register("stdlib", new DirectoryModuleReference("stdlib", new File("../../StdLibs/stdlib"), true));
106 103
 		moduleLoader.register("stdlib", new SourceModuleReference(new DirectorySourceModule("stdlib", new File("../../StdLibs/stdlib"), true), true));
107 104
 		Set<String> compiledModules = new HashSet<>();
108
-		
109
-		Consumer<ValidationLogEntry> validationLogger = entry -> {
110
-			String[] message = Strings.split(entry.message, '\n');
111
-			output.accept(new OutputLine(new ErrorOutputSpan(entry.kind + " " + entry.position.toString() + ": " + message[0])));
112
-			for (int i = 1; i < message.length; i++)
113
-				output.accept(new OutputLine(new ErrorOutputSpan("    " + message[i])));
114
-			
115
-			IDESourceFile sourceFile = new LocalSourceFile(entry.position.file);
116
-			state.addError(sourceFile, new IDECodeError(sourceFile, entry.position, entry.message));
117
-		};
118
-		try {
105
+        
106
+        try {
119 107
 			for (Library library : project.libraries) {
120 108
 				for (ModuleReference module : library.modules)
121 109
 					moduleLoader.register(module.getName(), module);
@@ -125,22 +113,22 @@ public class LocalTarget implements IDETarget {
125 113
 			}
126 114
 			
127 115
 			SemanticModule module = moduleLoader.getModule(target.getModule());
128
-			module = Validator.validate(module.normalize(), validationLogger);
116
+			module = Validator.validate(module.normalize(), localModuleLogger);
129 117
 			
130 118
 			if (compile) {
131
-				ZenCodeCompiler compiler = target.createCompiler(module);
119
+				ZenCodeCompiler compiler = target.createCompiler(module, localModuleLogger);
132 120
 				if (!module.isValid())
133 121
 					return compiler;
134 122
 
135 123
 				SemanticModule stdlib = moduleLoader.getModule("stdlib");
136
-				stdlib = Validator.validate(stdlib.normalize(), validationLogger);
124
+				stdlib = Validator.validate(stdlib.normalize(), localModuleLogger);
137 125
 				if (!stdlib.isValid())
138 126
 					return compiler;
139 127
 
140 128
 				compiler.addModule(stdlib);
141 129
 				compiledModules.add(stdlib.name);
142 130
 
143
-				boolean isValid = compileDependencies(moduleLoader, compiler, compiledModules, new Stack<>(), module, validationLogger);
131
+				boolean isValid = compileDependencies(moduleLoader, compiler, compiledModules, new Stack<>(), module, localModuleLogger);
144 132
 				if (!isValid)
145 133
 					return compiler;
146 134
 
@@ -169,7 +157,7 @@ public class LocalTarget implements IDETarget {
169 157
 		}
170 158
 	}
171 159
 	
172
-	private boolean compileDependencies(ModuleLoader loader, ZenCodeCompiler compiler, Set<String> compiledModules, Stack<String> compilingModules, SemanticModule module, Consumer<ValidationLogEntry> logger) {
160
+	private boolean compileDependencies(ModuleLoader loader, ZenCodeCompiler compiler, Set<String> compiledModules, Stack<String> compilingModules, SemanticModule module, ValidatorLogger logger) {
173 161
 		for (SemanticModule dependency : module.dependencies) {
174 162
 			if (compiledModules.contains(dependency.name))
175 163
 				continue;

+ 80
- 0
IDE/src/main/java/org/openzen/zenscript/ide/host/local/logging/LocalModuleLogger.java View File

@@ -0,0 +1,80 @@
1
+package org.openzen.zenscript.ide.host.local.logging;
2
+
3
+import org.openzen.zencode.shared.*;
4
+import org.openzen.zenscript.constructor.module.logging.*;
5
+import org.openzen.zenscript.ide.host.*;
6
+import org.openzen.zenscript.ide.host.local.*;
7
+import org.openzen.zenscript.ide.ui.view.output.*;
8
+import org.openzen.zenscript.validator.*;
9
+import org.openzen.zenscript.validator.logger.*;
10
+import stdlib.*;
11
+
12
+import java.util.function.*;
13
+
14
+public class LocalModuleLogger implements ModuleLogger, ValidatorLogger {
15
+    
16
+    private final LocalCompileState state;
17
+    private final Consumer<OutputLine> output;
18
+    
19
+    public LocalModuleLogger(LocalCompileState state, Consumer<OutputLine> output) {
20
+        this.state = state;
21
+        this.output = output;
22
+    }
23
+    
24
+    @Override
25
+    public void logCompileException(CompileException exception) {
26
+        IDESourceFile sourceFile = new LocalSourceFile(exception.position.file);
27
+        state.addError(sourceFile, new IDECodeError(sourceFile, exception.position, exception.message));
28
+        
29
+        String[] lines = Strings.split(exception.getMessage(), '\n');
30
+        for(String line : lines) {
31
+            output.accept(new OutputLine(new ErrorOutputSpan(line)));
32
+        }
33
+    }
34
+    
35
+    @Override
36
+    public void info(String message) {
37
+        output.accept(new OutputLine(new BasicOutputSpan(message)));
38
+    }
39
+    
40
+    @Override
41
+    public void debug(String message) {
42
+        output.accept(new OutputLine(new BasicOutputSpan(message)));
43
+    }
44
+    
45
+    @Override
46
+    public void warning(String message) {
47
+        output.accept(new OutputLine(new BasicOutputSpan(message)));
48
+    }
49
+    
50
+    @Override
51
+    public void error(String message) {
52
+        output.accept(new OutputLine(new ErrorOutputSpan(message)));
53
+    }
54
+    
55
+    @Override
56
+    public void throwingErr(String message, Throwable throwable) {
57
+        output.accept(new OutputLine(new ErrorOutputSpan(message)));
58
+    }
59
+    
60
+    @Override
61
+    public void throwingWarn(String message, Throwable throwable) {
62
+        output.accept(new OutputLine(new BasicOutputSpan(message)));
63
+    }
64
+    
65
+    @Override
66
+    public void logValidationError(ValidationLogEntry entry) {
67
+        String[] message = Strings.split(entry.message, '\n');
68
+        output.accept(new OutputLine(new ErrorOutputSpan(entry.kind + " " + entry.position.toString() + ": " + message[0])));
69
+        for(int i = 1; i < message.length; i++)
70
+            output.accept(new OutputLine(new ErrorOutputSpan("    " + message[i])));
71
+        
72
+        IDESourceFile sourceFile = new LocalSourceFile(entry.position.file);
73
+        state.addError(sourceFile, new IDECodeError(sourceFile, entry.position, entry.message));
74
+    }
75
+    
76
+    @Override
77
+    public void logValidationWarning(ValidationLogEntry warningEntry) {
78
+        logValidationError(warningEntry);
79
+    }
80
+}

+ 57
- 0
IDE/src/main/java/org/openzen/zenscript/ide/host/local/logging/LocalValidatorLogger.java View File

@@ -0,0 +1,57 @@
1
+package org.openzen.zenscript.ide.host.local.logging;
2
+
3
+import org.openzen.zenscript.ide.host.*;
4
+import org.openzen.zenscript.validator.*;
5
+import org.openzen.zenscript.validator.logger.*;
6
+
7
+import java.util.function.*;
8
+
9
+public class LocalValidatorLogger implements ValidatorLogger {
10
+    
11
+    private final Consumer<IDECodeError> errors;
12
+    
13
+    public LocalValidatorLogger(Consumer<IDECodeError> errors) {
14
+        this.errors = errors;
15
+    }
16
+    
17
+    @Override
18
+    public void info(String message) {
19
+        throw new UnsupportedOperationException();
20
+    }
21
+    
22
+    @Override
23
+    public void debug(String message) {
24
+        throw new UnsupportedOperationException();
25
+    }
26
+    
27
+    @Override
28
+    public void warning(String message) {
29
+        throw new UnsupportedOperationException();
30
+    }
31
+    
32
+    @Override
33
+    public void error(String message) {
34
+        throw new UnsupportedOperationException();
35
+    }
36
+    
37
+    @Override
38
+    public void throwingErr(String message, Throwable throwable) {
39
+        throw new UnsupportedOperationException();
40
+    }
41
+    
42
+    @Override
43
+    public void throwingWarn(String message, Throwable throwable) {
44
+        throw new UnsupportedOperationException();
45
+    }
46
+    
47
+    @Override
48
+    public void logValidationError(ValidationLogEntry errorEntry) {
49
+        logValidationWarning(errorEntry);
50
+    }
51
+    
52
+    @Override
53
+    public void logValidationWarning(ValidationLogEntry entry) {
54
+        final IDECodeError ideCodeError = new IDECodeError(null, entry.position, entry.message);
55
+        errors.accept(ideCodeError);
56
+    }
57
+}

+ 4
- 3
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaBytecodeContext.java View File

@@ -9,6 +9,7 @@ import org.objectweb.asm.ClassWriter;
9 9
 import org.objectweb.asm.Opcodes;
10 10
 import org.objectweb.asm.Type;
11 11
 import org.openzen.zencode.shared.CodePosition;
12
+import org.openzen.zencode.shared.logging.*;
12 13
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
13 14
 import org.openzen.zenscript.codemodel.type.StoredType;
14 15
 import org.openzen.zenscript.codemodel.type.TypeID;
@@ -34,8 +35,8 @@ public class JavaBytecodeContext extends JavaContext {
34 35
 	private final JavaTypeDescriptorVisitor descriptorVisitor;
35 36
 	private int lambdaCounter = 0;
36 37
 	
37
-	public JavaBytecodeContext(JavaBytecodeModule target, JavaCompileSpace space, ZSPackage modulePackage, String basePackage) {
38
-		super(space, modulePackage, basePackage);
38
+	public JavaBytecodeContext(JavaBytecodeModule target, JavaCompileSpace space, ZSPackage modulePackage, String basePackage, IZSLogger logger) {
39
+		super(space, modulePackage, basePackage, logger);
39 40
 		
40 41
 		this.target = target;
41 42
 		
@@ -102,7 +103,7 @@ public class JavaBytecodeContext extends JavaContext {
102 103
 		rangeWriter.visitField(Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL, "to", getDescriptor(range.baseType), null, null).visitEnd();
103 104
 		
104 105
 		JavaMethod method = JavaMethod.getConstructor(range.cls, "(" + getDescriptor(range.baseType) + getDescriptor(range.baseType) + ")V", Opcodes.ACC_PUBLIC);
105
-		JavaWriter constructorWriter = new JavaWriter(CodePosition.GENERATED, rangeWriter, method, null, method.descriptor, null);
106
+		JavaWriter constructorWriter = new JavaWriter(logger, CodePosition.GENERATED, rangeWriter, method, null, method.descriptor, null);
106 107
 		constructorWriter.loadObject(0);
107 108
 		constructorWriter.invokeSpecial("java/lang/Object", "<init>", "()V");
108 109
 		constructorWriter.loadObject(0);

+ 8
- 4
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaBytecodeModule.java View File

@@ -9,6 +9,8 @@ import java.util.ArrayList;
9 9
 import java.util.HashMap;
10 10
 import java.util.List;
11 11
 import java.util.Map;
12
+
13
+import org.openzen.zencode.shared.logging.*;
12 14
 import org.openzen.zenscript.codemodel.FunctionParameter;
13 15
 import org.openzen.zenscript.codemodel.Module;
14 16
 import org.openzen.zenscript.javashared.JavaCompiledModule;
@@ -21,17 +23,19 @@ import org.openzen.zenscript.javashared.JavaMethod;
21 23
 public class JavaBytecodeModule extends JavaCompiledModule {
22 24
 	private final Map<String, byte[]> classes = new HashMap<>();
23 25
 	private final List<JavaScriptMethod> scripts = new ArrayList<>();
24
-	
25
-	public JavaBytecodeModule(Module module, FunctionParameter[] parameters) {
26
+    private final IZSLogger logger;
27
+    
28
+    public JavaBytecodeModule(Module module, FunctionParameter[] parameters, IZSLogger logger) {
26 29
 		super(module, parameters);
27
-	}
30
+        this.logger = logger;
31
+    }
28 32
 	
29 33
 	public void addClass(String name, byte[] bytecode) {
30 34
 		if (bytecode == null)
31 35
 			return;
32 36
 
33 37
 		if(name.startsWith("java")) {
34
-			System.err.println("Invalid name " + name);
38
+			logger.debug("Warning: Invalid name " + name);
35 39
 		} else {
36 40
 			classes.put(name, bytecode);
37 41
 		}

+ 9
- 3
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaBytecodeRunUnit.java View File

@@ -9,6 +9,7 @@ import org.objectweb.asm.ClassWriter;
9 9
 import org.objectweb.asm.Opcodes;
10 10
 import org.objectweb.asm.Type;
11 11
 import org.openzen.zencode.shared.CodePosition;
12
+import org.openzen.zencode.shared.logging.*;
12 13
 import org.openzen.zenscript.codemodel.FunctionHeader;
13 14
 import org.openzen.zenscript.codemodel.FunctionParameter;
14 15
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
@@ -38,8 +39,13 @@ public class JavaBytecodeRunUnit {
38 39
 	private final List<JavaParameterInfo> scriptParameterInfo = new ArrayList<>();
39 40
 
40 41
 	private boolean scriptsWritten = false;
41
-
42
-	public void add(JavaBytecodeModule module) {
42
+	private final IZSLogger logger;
43
+    
44
+    public JavaBytecodeRunUnit(IZSLogger logger) {
45
+        this.logger = logger;
46
+    }
47
+    
48
+    public void add(JavaBytecodeModule module) {
43 49
 		scriptsWritten = false;
44 50
 
45 51
 		for (Map.Entry<String, byte[]> classEntry : module.getClasses().entrySet())
@@ -125,7 +131,7 @@ public class JavaBytecodeRunUnit {
125 131
 		headerBuilder.append(")V");
126 132
 
127 133
 		JavaMethod runMethod = JavaMethod.getStatic(new JavaClass("script", "Scripts", JavaClass.Kind.CLASS), "run", headerBuilder.toString(), Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC);
128
-		final JavaWriter runWriter = new JavaWriter(CodePosition.GENERATED, scriptsClassWriter, runMethod, null, null, null);
134
+		final JavaWriter runWriter = new JavaWriter(logger, CodePosition.GENERATED, scriptsClassWriter, runMethod, null, null, null);
129 135
 		runWriter.start();
130 136
 		for (JavaScriptMethod method : scripts) {
131 137
 			for (int i = 0; i < method.parameters.length; i++) {

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

@@ -11,6 +11,7 @@ import org.objectweb.asm.ClassWriter;
11 11
 import org.objectweb.asm.Opcodes;
12 12
 import org.openzen.zencode.shared.CodePosition;
13 13
 import org.openzen.zencode.shared.SourceFile;
14
+import org.openzen.zencode.shared.logging.*;
14 15
 import org.openzen.zenscript.codemodel.FunctionHeader;
15 16
 import org.openzen.zenscript.codemodel.FunctionParameter;
16 17
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
@@ -35,16 +36,20 @@ import org.openzen.zenscript.javashared.prepare.JavaPrepareDefinitionVisitor;
35 36
  * @author Hoofdgebruiker
36 37
  */
37 38
 public class JavaCompiler {
38
-	private int generatedScriptBlockCounter = 0;
39
+    
40
+    private int generatedScriptBlockCounter = 0;
39 41
 	private int expansionCounter = 0;
40
-
41
-	public JavaCompiler() {}
42
+	private IZSLogger logger;
43
+    
44
+    public JavaCompiler(IZSLogger logger) {
45
+        this.logger = logger;
46
+    }
42 47
 	
43 48
 	public JavaBytecodeModule compile(String packageName, SemanticModule module, JavaCompileSpace space) {
44 49
 		Map<String, JavaScriptFile> scriptBlocks = new LinkedHashMap<>();
45 50
 		
46
-		JavaBytecodeModule target = new JavaBytecodeModule(module.module, module.parameters);
47
-		JavaBytecodeContext context = new JavaBytecodeContext(target, space, module.modulePackage, packageName);
51
+		JavaBytecodeModule target = new JavaBytecodeModule(module.module, module.parameters, logger);
52
+		JavaBytecodeContext context = new JavaBytecodeContext(target, space, module.modulePackage, packageName, logger);
48 53
 		context.addModule(module.module, target);
49 54
 		
50 55
 		for (HighLevelDefinition definition : module.definitions.getAll()) {
@@ -92,7 +97,7 @@ public class JavaCompiler {
92 97
 			JavaMethod method = JavaMethod.getStatic(new JavaClass(context.getPackageName(script.pkg), className, JavaClass.Kind.CLASS), methodName, scriptDescriptor, Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC);
93 98
 			scriptFile.scriptMethods.add(new JavaScriptMethod(method, module.parameters, javaScriptParameters));
94 99
 
95
-			final JavaStatementVisitor statementVisitor = new JavaStatementVisitor(context, context.getJavaModule(script.module), new JavaWriter(CodePosition.UNKNOWN, visitor, method, null, null, null));
100
+			final JavaStatementVisitor statementVisitor = new JavaStatementVisitor(context, context.getJavaModule(script.module), new JavaWriter(logger, CodePosition.UNKNOWN, visitor, method, null, null, null));
96 101
 			statementVisitor.start();
97 102
 			for (Statement statement : script.statements) {
98 103
 				statement.accept(statementVisitor);
@@ -108,7 +113,7 @@ public class JavaCompiler {
108 113
 
109 114
 			if (target.getClasses().containsKey(entry.getKey())) {
110 115
 				//TODO Scripts and definitions seem to create the same class. Bad!
111
-				System.err.println("Trying to register " + entry.getKey() + " a 2nd time");
116
+				logger.warning("Warning: Trying to register " + entry.getKey() + " a 2nd time");
112 117
 			}else{
113 118
 				target.addClass(entry.getKey(), entry.getValue().classWriter.toByteArray());
114 119
 			}

+ 6
- 6
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaExpressionVisitor.java View File

@@ -2059,7 +2059,7 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void>, JavaNativ
2059 2059
 		//Bridge method!!!
2060 2060
 		if (!Objects.equals(methodInfo.descriptor, descriptor)) {
2061 2061
 			final JavaMethod bridgeMethodInfo = new JavaMethod(methodInfo.cls, methodInfo.kind, methodInfo.name, methodInfo.compile, methodInfo.descriptor, methodInfo.modifiers | JavaModifiers.BRIDGE | JavaModifiers.SYNTHETIC, methodInfo.genericResult, methodInfo.typeParameterArguments);
2062
-			final JavaWriter bridgeWriter = new JavaWriter(expression.position, lambdaCW, bridgeMethodInfo, null, methodInfo.descriptor, null, "java/lang/Override");
2062
+			final JavaWriter bridgeWriter = new JavaWriter(context.logger, expression.position, lambdaCW, bridgeMethodInfo, null, methodInfo.descriptor, null, "java/lang/Override");
2063 2063
 			bridgeWriter.start();
2064 2064
 			
2065 2065
 			//This.name(parameters, casted)
@@ -2086,9 +2086,9 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void>, JavaNativ
2086 2086
 			
2087 2087
 			final JavaMethod actualMethod = new JavaMethod(methodInfo.cls, methodInfo.kind, methodInfo.name, methodInfo.compile, context.getMethodDescriptor(expression.header), methodInfo.modifiers, methodInfo.genericResult, methodInfo.typeParameterArguments);
2088 2088
 			//No @Override
2089
-			functionWriter = new JavaWriter(expression.position, lambdaCW, actualMethod, null, signature, null);
2089
+			functionWriter = new JavaWriter(context.logger, expression.position, lambdaCW, actualMethod, null, signature, null);
2090 2090
 		} else {
2091
-			functionWriter = new JavaWriter(expression.position, lambdaCW, methodInfo, null, signature, null, "java/lang/Override");
2091
+			functionWriter = new JavaWriter(context.logger, expression.position, lambdaCW, methodInfo, null, signature, null, "java/lang/Override");
2092 2092
 		}
2093 2093
 
2094 2094
 		javaWriter.newObject(className);
@@ -2097,7 +2097,7 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void>, JavaNativ
2097 2097
 		final String constructorDesc = calcFunctionSignature(expression.closure);
2098 2098
 
2099 2099
 
2100
-		final JavaWriter constructorWriter = new JavaWriter(expression.position, lambdaCW, JavaMethod.getConstructor(javaWriter.method.cls, constructorDesc, Opcodes.ACC_PUBLIC), null, null, null);
2100
+		final JavaWriter constructorWriter = new JavaWriter(context.logger, expression.position, lambdaCW, JavaMethod.getConstructor(javaWriter.method.cls, constructorDesc, Opcodes.ACC_PUBLIC), null, null, null);
2101 2101
 		constructorWriter.start();
2102 2102
 		constructorWriter.loadObject(0);
2103 2103
 		constructorWriter.dup();
@@ -4173,7 +4173,7 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void>, JavaNativ
4173 4173
 
4174 4174
 		//Constructor
4175 4175
 		{
4176
-			final JavaWriter constructorWriter = new JavaWriter(expression.position, lambdaCW, JavaMethod.getConstructor(javaWriter.method.cls, constructorDesc, Opcodes.ACC_PUBLIC), null, null, null);
4176
+			final JavaWriter constructorWriter = new JavaWriter(context.logger, expression.position, lambdaCW, JavaMethod.getConstructor(javaWriter.method.cls, constructorDesc, Opcodes.ACC_PUBLIC), null, null, null);
4177 4177
 			constructorWriter.start();
4178 4178
 			constructorWriter.loadObject(0);
4179 4179
 			constructorWriter.dup();
@@ -4189,7 +4189,7 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void>, JavaNativ
4189 4189
 		//The actual method
4190 4190
 		{
4191 4191
 			final JavaMethod actualMethod = new JavaMethod(tag.method.cls, tag.method.kind, tag.method.name, tag.method.compile, tag.method.descriptor, tag.method.modifiers & ~JavaModifiers.ABSTRACT, tag.method.genericResult, tag.method.typeParameterArguments);
4192
-			final JavaWriter functionWriter = new JavaWriter(expression.position, lambdaCW, actualMethod, null, methodDescriptor, null, "java/lang/Override");
4192
+			final JavaWriter functionWriter = new JavaWriter(context.logger, expression.position, lambdaCW, actualMethod, null, methodDescriptor, null, "java/lang/Override");
4193 4193
 			functionWriter.start();
4194 4194
 
4195 4195
 			//this.wrapped

+ 143
- 138
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaWriter.java
File diff suppressed because it is too large
View File


+ 7
- 7
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/definitions/JavaDefinitionVisitor.java View File

@@ -133,7 +133,7 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<byte[]> {
133 133
 
134 134
 	@Override
135 135
 	public byte[] visitEnum(EnumDefinition definition) {
136
-		System.out.println("Compiling enum " + definition.name + " in " + definition.position.getFilename());
136
+		context.logger.debug("Compiling enum " + definition.name + " in " + definition.position.getFilename());
137 137
 
138 138
 		String superTypeInternalName = definition.getSuperType() == null ? "java/lang/Object" : context.getInternalName(definition.getSuperType());
139 139
 
@@ -151,7 +151,7 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<byte[]> {
151 151
         }
152 152
 
153 153
 		JavaMethod valuesMethod = JavaMethod.getStatic(toClass, "values", "()[L" + toClass.internalName + ";", Opcodes.ACC_STATIC | Opcodes.ACC_PUBLIC);
154
-		JavaWriter valuesWriter = new JavaWriter(definition.position, writer, true, valuesMethod, definition, null, null);
154
+		JavaWriter valuesWriter = new JavaWriter(context.logger, definition.position, writer, true, valuesMethod, definition, null, null);
155 155
 		valuesWriter.start();
156 156
 		valuesWriter.getStaticField(toClass.internalName, "$VALUES", "[L" + toClass.internalName + ";");
157 157
 		valuesWriter.invokeVirtual(ARRAY_CLONE);
@@ -160,7 +160,7 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<byte[]> {
160 160
 		valuesWriter.end();
161 161
 
162 162
 		JavaMethod valueOfMethod = JavaMethod.getStatic(toClass, "valueOf", "(Ljava/lang/String;)L" + toClass.internalName + ";", Opcodes.ACC_STATIC | Opcodes.ACC_PUBLIC);
163
-		JavaWriter valueOfWriter = new JavaWriter(definition.position, writer, true, valueOfMethod, definition, null, null);
163
+		JavaWriter valueOfWriter = new JavaWriter(context.logger, definition.position, writer, true, valueOfMethod, definition, null, null);
164 164
 		valueOfWriter.start();
165 165
 		valueOfWriter.invokeStatic(CLASS_FORNAME);
166 166
 		valueOfWriter.loadObject(0);
@@ -186,7 +186,7 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<byte[]> {
186 186
         final String signature = context.getMethodSignature(definition.header);
187 187
 		final JavaMethod method = context.getJavaMethod(definition.caller);
188 188
 
189
-		final JavaWriter writer = new JavaWriter(definition.position, outerWriter, true, method, definition, signature, null);
189
+		final JavaWriter writer = new JavaWriter(context.logger, definition.position, outerWriter, true, method, definition, signature, null);
190 190
         final JavaStatementVisitor statementVisitor = new JavaStatementVisitor(context, context.getJavaModule(definition.module), writer);
191 191
         statementVisitor.start();
192 192
 		boolean returns = definition.caller.body.accept(statementVisitor);
@@ -301,7 +301,7 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<byte[]> {
301 301
 			optionInitSignatureBuilder.append(")V");
302 302
 
303 303
 			JavaMethod constructorMethod = JavaMethod.getConstructor(optionTag.variantOptionClass, optionInitDescBuilder.toString(), JavaModifiers.PUBLIC);
304
-			final JavaWriter initWriter = new JavaWriter(option.position, optionWriter, constructorMethod, variant, optionInitSignatureBuilder.toString(), null);
304
+			final JavaWriter initWriter = new JavaWriter(context.logger, option.position, optionWriter, constructorMethod, variant, optionInitSignatureBuilder.toString(), null);
305 305
 			initWriter.start();
306 306
 			initWriter.loadObject(0);
307 307
 			initWriter.dup();
@@ -319,7 +319,7 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<byte[]> {
319 319
 
320 320
 			//Denominator for switch-cases
321 321
 			JavaMethod denominator = JavaMethod.getVirtual(optionTag.variantOptionClass, "getDenominator", "()I", JavaModifiers.PUBLIC);
322
-			final JavaWriter getDenominator = new JavaWriter(option.position, optionWriter, denominator, null, null, null, "java/lang/Override");
322
+			final JavaWriter getDenominator = new JavaWriter(context.logger, option.position, optionWriter, denominator, null, null, null, "java/lang/Override");
323 323
 			getDenominator.start();
324 324
 			getDenominator.constant(option.ordinal);
325 325
 			getDenominator.returnInt();
@@ -336,7 +336,7 @@ public class JavaDefinitionVisitor implements DefinitionVisitor<byte[]> {
336 336
 			member.accept(visitor);
337 337
 		}
338 338
 
339
-		final JavaWriter superInitWriter = new JavaWriter(variant.position, writer, JavaMethod.getConstructor(toClass, "()V", Opcodes.ACC_PUBLIC), variant, "()V", null);
339
+		final JavaWriter superInitWriter = new JavaWriter(context.logger, variant.position, writer, JavaMethod.getConstructor(toClass, "()V", Opcodes.ACC_PUBLIC), variant, "()V", null);
340 340
 		superInitWriter.start();
341 341
 		superInitWriter.loadObject(0);
342 342
 		superInitWriter.invokeSpecial("java/lang/Object", "<init>", "()V");

+ 5
- 5
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/definitions/JavaExpansionMemberVisitor.java View File

@@ -37,7 +37,7 @@ public class JavaExpansionMemberVisitor implements MemberVisitor<Void> {
37 37
 		this.context = context;
38 38
 		javaModule = context.getJavaModule(definition.module);
39 39
 
40
-		final JavaWriter javaWriter = new JavaWriter(definition.position, writer, new JavaMethod(context.getJavaClass(definition), JavaMethod.Kind.STATICINIT, "<clinit>", true, "()V", 0, false), definition, null, null);
40
+		final JavaWriter javaWriter = new JavaWriter(context.logger, definition.position, writer, new JavaMethod(context.getJavaClass(definition), JavaMethod.Kind.STATICINIT, "<clinit>", true, "()V", 0, false), definition, null, null);
41 41
 		this.clinitStatementVisitor = new JavaStatementVisitor(context, javaModule, javaWriter);
42 42
 		this.clinitStatementVisitor.start();
43 43
 		CompilerUtils.writeDefaultFieldInitializers(context, javaWriter, definition, true);
@@ -131,7 +131,7 @@ public class JavaExpansionMemberVisitor implements MemberVisitor<Void> {
131 131
 		}
132 132
 
133 133
 
134
-		final JavaWriter methodWriter = new JavaWriter(member.position, writer, true, method, definition, true, methodSignature, methodDescriptor, null);
134
+		final JavaWriter methodWriter = new JavaWriter(context.logger, member.position, writer, true, method, definition, true, methodSignature, methodDescriptor, null);
135 135
 		methodWriter.label(methodStart);
136 136
 
137 137
 		if (!isStatic) {
@@ -212,7 +212,7 @@ public class JavaExpansionMemberVisitor implements MemberVisitor<Void> {
212 212
 		final Label methodEnd = new Label();
213 213
 
214 214
 		final JavaMethod method = context.getJavaMethod(member);
215
-		final JavaWriter methodWriter = new JavaWriter(member.position, this.writer, true, method, definition, true, signature, descriptor, new String[0]);
215
+		final JavaWriter methodWriter = new JavaWriter(context.logger, member.position, this.writer, true, method, definition, true, signature, descriptor, new String[0]);
216 216
 
217 217
 		methodWriter.label(methodStart);
218 218
 
@@ -257,7 +257,7 @@ public class JavaExpansionMemberVisitor implements MemberVisitor<Void> {
257 257
 		final Label methodEnd = new Label();
258 258
 
259 259
 		final JavaMethod javaMethod = context.getJavaMethod(member);
260
-		final JavaWriter methodWriter = new JavaWriter(member.position, writer, true, javaMethod, member.definition, true, signature, description, new String[0]);
260
+		final JavaWriter methodWriter = new JavaWriter(context.logger, member.position, writer, true, javaMethod, member.definition, true, signature, description, new String[0]);
261 261
 
262 262
 
263 263
 		methodWriter.label(methodStart);
@@ -318,7 +318,7 @@ public class JavaExpansionMemberVisitor implements MemberVisitor<Void> {
318 318
 		final Label methodEnd = new Label();
319 319
 
320 320
 		final JavaMethod javaMethod = context.getJavaMethod(member);
321
-		final JavaWriter methodWriter = new JavaWriter(member.position, writer, true, javaMethod, member.definition, true, methodSignature, methodDescriptor, new String[0]);
321
+		final JavaWriter methodWriter = new JavaWriter(context.logger, member.position, writer, true, javaMethod, member.definition, true, methodSignature, methodDescriptor, new String[0]);
322 322
 
323 323
 		methodWriter.label(methodStart);
324 324
 		methodWriter.nameVariable(0, "expandedObj", methodStart, methodEnd, context.getType(this.expandedClass));

+ 10
- 9
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/definitions/JavaMemberVisitor.java View File

@@ -4,6 +4,7 @@ import org.objectweb.asm.ClassWriter;
4 4
 import org.objectweb.asm.Label;
5 5
 import org.objectweb.asm.Opcodes;
6 6
 import org.objectweb.asm.Type;
7
+import org.openzen.zencode.shared.logging.*;
7 8
 import org.openzen.zenscript.codemodel.FunctionParameter;
8 9
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
9 10
 import org.openzen.zenscript.codemodel.Modifiers;
@@ -38,7 +39,7 @@ public class JavaMemberVisitor implements MemberVisitor<Void> {
38 39
 		this.context = context;
39 40
 		javaModule = context.getJavaModule(definition.module);
40 41
 
41
-        final JavaWriter javaWriter = new JavaWriter(definition.position, writer, new JavaMethod(toClass, JavaMethod.Kind.STATICINIT, "<clinit>", true, "()V", 0, false), definition, null, null);
42
+        final JavaWriter javaWriter = new JavaWriter(context.logger, definition.position, writer, new JavaMethod(toClass, JavaMethod.Kind.STATICINIT, "<clinit>", true, "()V", 0, false), definition, null, null);
42 43
         this.clinitStatementVisitor = new JavaStatementVisitor(context, javaModule, javaWriter);
43 44
         this.clinitStatementVisitor.start();
44 45
         CompilerUtils.writeDefaultFieldInitializers(context, javaWriter, definition, true);
@@ -65,7 +66,7 @@ public class JavaMemberVisitor implements MemberVisitor<Void> {
65 66
 
66 67
         final Label constructorStart = new Label();
67 68
         final Label constructorEnd = new Label();
68
-        final JavaWriter constructorWriter = new JavaWriter(member.position, writer, method, definition, context.getMethodSignature(member.header), null);
69
+        final JavaWriter constructorWriter = new JavaWriter(context.logger, member.position, writer, method, definition, context.getMethodSignature(member.header), null);
69 70
         constructorWriter.label(constructorStart);
70 71
         CompilerUtils.tagConstructorParameters(context, javaModule, member.definition, member.header, isEnum);
71 72
         if(isEnum) {
@@ -98,7 +99,7 @@ public class JavaMemberVisitor implements MemberVisitor<Void> {
98 99
 
99 100
 		if (!member.isConstructorForwarded()) {
100 101
 			if (isEnum) {
101
-				System.out.println("Writing enum constructor");
102
+				context.logger.debug("Writing enum constructor");
102 103
 				constructorWriter.getVisitor().newLocal(Type.getType(String.class));
103 104
 				constructorWriter.getVisitor().newLocal(Type.getType(int.class));
104 105
 				constructorWriter.loadObject(0);
@@ -106,7 +107,7 @@ public class JavaMemberVisitor implements MemberVisitor<Void> {
106 107
 				constructorWriter.loadInt(2);
107 108
 				constructorWriter.invokeSpecial(Type.getInternalName(Enum.class), "<init>", "(Ljava/lang/String;I)V");
108 109
 			} else if (definition.getSuperType() == null) {
109
-				System.out.println("Writing regular constructor");
110
+				context.logger.debug("Writing regular constructor");
110 111
 				constructorWriter.loadObject(0);
111 112
 				constructorWriter.invokeSpecial(Type.getInternalName(Object.class), "<init>", "()V");
112 113
 			}
@@ -144,7 +145,7 @@ public class JavaMemberVisitor implements MemberVisitor<Void> {
144 145
 
145 146
 		final Label constructorStart = new Label();
146 147
 		final Label constructorEnd = new Label();
147
-		final JavaWriter destructorWriter = new JavaWriter(member.position, writer, method, definition, null, null);
148
+		final JavaWriter destructorWriter = new JavaWriter(context.logger, member.position, writer, method, definition, null, null);
148 149
 		destructorWriter.label(constructorStart);
149 150
 		
150 151
         final JavaStatementVisitor statementVisitor = new JavaStatementVisitor(context, javaModule, destructorWriter);
@@ -163,7 +164,7 @@ public class JavaMemberVisitor implements MemberVisitor<Void> {
163 164
         final boolean isAbstract = member.body == null || Modifiers.isAbstract(member.getEffectiveModifiers());
164 165
         final JavaMethod method = context.getJavaMethod(member);
165 166
 		
166
-		final JavaWriter methodWriter = new JavaWriter(member.position, writer, method, definition, context.getMethodSignature(member.header), null);
167
+		final JavaWriter methodWriter = new JavaWriter(context.logger, member.position, writer, method, definition, context.getMethodSignature(member.header), null);
167 168
 
168 169
 		if (!isAbstract) {
169 170
 			if (method.isAbstract() || method.cls.kind == JavaClass.Kind.INTERFACE)
@@ -195,7 +196,7 @@ public class JavaMemberVisitor implements MemberVisitor<Void> {
195 196
 		final Label methodEnd = new Label();
196 197
 
197 198
 		final JavaMethod method = context.getJavaMethod(member);
198
-		final JavaWriter methodWriter = new JavaWriter(member.position, this.writer, true, method, definition, false, signature, descriptor, new String[0]);
199
+		final JavaWriter methodWriter = new JavaWriter(context.logger, member.position, this.writer, true, method, definition, false, signature, descriptor, new String[0]);
199 200
 
200 201
 		methodWriter.label(methodStart);
201 202
 		final JavaStatementVisitor statementVisitor = new JavaStatementVisitor(context, javaModule, methodWriter);
@@ -216,7 +217,7 @@ public class JavaMemberVisitor implements MemberVisitor<Void> {
216 217
 		final Label methodEnd = new Label();
217 218
 
218 219
 		final JavaMethod javaMethod = context.getJavaMethod(member);
219
-		final JavaWriter methodWriter = new JavaWriter(member.position, writer, true, javaMethod, member.definition, false, signature, description, new String[0]);
220
+		final JavaWriter methodWriter = new JavaWriter(context.logger, member.position, writer, true, javaMethod, member.definition, false, signature, description, new String[0]);
220 221
 		methodWriter.label(methodStart);
221 222
 
222 223
 		//in script you use $ but the parameter is named "value", which to choose?
@@ -267,7 +268,7 @@ public class JavaMemberVisitor implements MemberVisitor<Void> {
267 268
 		final Label methodEnd = new Label();
268 269
 
269 270
 
270
-		final JavaWriter methodWriter = new JavaWriter(member.position, writer, true, javaMethod, member.definition, false, methodSignature, methodDescriptor, new String[0]);
271
+		final JavaWriter methodWriter = new JavaWriter(context.logger, member.position, writer, true, javaMethod, member.definition, false, methodSignature, methodDescriptor, new String[0]);
271 272
 
272 273
 		methodWriter.label(methodStart);
273 274
 

+ 0
- 34
JavaIntegration/src/main/java/org/openzen/zencode/java/EmptyLogger.java View File

@@ -1,34 +0,0 @@
1
-package org.openzen.zencode.java;
2
-
3
-public class EmptyLogger implements IZSLogger {
4
-    
5
-    @Override
6
-    public void info(String message) {
7
-    
8
-    }
9
-    
10
-    @Override
11
-    public void debug(String message) {
12
-    
13
-    }
14
-    
15
-    @Override
16
-    public void warning(String message) {
17
-    
18
-    }
19
-    
20
-    @Override
21
-    public void error(String message) {
22
-    
23
-    }
24
-    
25
-    @Override
26
-    public void throwingErr(String message, Throwable throwable) {
27
-    
28
-    }
29
-    
30
-    @Override
31
-    public void throwingWarn(String message, Throwable throwable) {
32
-    
33
-    }
34
-}

+ 8
- 4
JavaIntegration/src/main/java/org/openzen/zencode/java/JavaNativeLoader.java View File

@@ -8,6 +8,7 @@ package org.openzen.zencode.java;
8 8
 import java.util.*;
9 9
 import java.util.function.Consumer;
10 10
 import org.openzen.zencode.shared.CompileException;
11
+import org.openzen.zencode.shared.logging.*;
11 12
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
12 13
 
13 14
 /**
@@ -18,11 +19,13 @@ public class JavaNativeLoader {
18 19
 	private final Class<?>[] classes;
19 20
 	private final Class<?>[] globals;
20 21
 	private final Map<String, LoadingModule> modulesByName = new HashMap<>();
21
-	private boolean loaded = false;
22
+    private final IZSLogger logger;
23
+    private boolean loaded = false;
22 24
 	
23
-	public JavaNativeLoader(Class<?>[] classes, Class<?>[] globals) {
25
+	public JavaNativeLoader(Class<?>[] classes, Class<?>[] globals, IZSLogger logger) {
24 26
 		this.classes = classes;
25 27
 		this.globals = globals;
28
+		this.logger = logger;
26 29
 	}
27 30
 	
28 31
 	public LoadingModule addModule(
@@ -65,7 +68,7 @@ public class JavaNativeLoader {
65 68
 		for (Class<?> cls : classes) {
66 69
 			LoadingModule module = findModuleByPackage(modulesByPackage, getPackageName(cls));
67 70
 			if (module == null) {
68
-				System.out.println("Warning: module not found for class " + cls.getName());
71
+				logger.warning("Module not found for class " + cls.getName());
69 72
 			} else {
70 73
 				module.classes.add(cls);
71 74
 			}
@@ -73,7 +76,7 @@ public class JavaNativeLoader {
73 76
 		for (Class<?> cls : globals) {
74 77
 			LoadingModule module = findModuleByPackage(modulesByPackage, getPackageName(cls));
75 78
 			if (module == null) {
76
-				System.out.println("Warning: module not found for class " + cls.getName());
79
+				logger.warning("Module not found for class " + cls.getName());
77 80
 			} else {
78 81
 				module.globals.add(cls);
79 82
 			}
@@ -110,6 +113,7 @@ public class JavaNativeLoader {
110 113
 		}
111 114
 		
112 115
 		module.resolved = new JavaNativeModule(
116
+                logger,
113 117
 				module.pkg,
114 118
 				module.name,
115 119
 				module.basePackage,

+ 4
- 3
JavaIntegration/src/main/java/org/openzen/zencode/java/JavaNativeModule.java View File

@@ -472,9 +472,10 @@ public class JavaNativeModule {
472 472
 			final Class<?> classFromType = getClassFromType(expandedType);
473 473
 			if(classFromType == null) {
474 474
 				//TODO REMOVE
475
-				System.err.println("Could not get class for type " + expandedType + " attempting to do stuff anyways");
476
-			} else 	if(!method.getParameterTypes()[0].isAssignableFrom(classFromType))
477
-				throw new IllegalArgumentException("Cannot add extension method " + method + " as its first parameter does not match the extended type.");
475
+				logger.debug("Could not get class for type " + expandedType + " attempting to do stuff anyways");
476
+			} else if(!method.getParameterTypes()[0].isAssignableFrom(classFromType)) {
477
+                throw new IllegalArgumentException("Cannot add extension method " + method + " as its first parameter does not match the extended type.");
478
+            }
478 479
 
479 480
 
480 481
 			final ZenCodeType.Method methodAnnotation = method.getAnnotation(ZenCodeType.Method.class);

+ 21
- 36
JavaIntegration/src/main/java/org/openzen/zencode/java/ScriptingEngine.java View File

@@ -5,6 +5,7 @@
5 5
  */
6 6
 package org.openzen.zencode.java;
7 7
 
8
+import org.openzen.zencode.java.logger.*;
8 9
 import org.openzen.zencode.shared.*;
9 10
 import org.openzen.zenscript.codemodel.*;
10 11
 import org.openzen.zenscript.codemodel.context.*;
@@ -20,7 +21,6 @@ import org.openzen.zenscript.validator.*;
20 21
 import java.io.*;
21 22
 import java.lang.reflect.InvocationTargetException;
22 23
 import java.util.*;
23
-import java.util.function.*;
24 24
 
25 25
 /**
26 26
  *
@@ -37,36 +37,34 @@ public class ScriptingEngine {
37 37
 	
38 38
 	public boolean debug = false;
39 39
 	
40
-	public IZSLogger logger;
40
+	public final ScriptingEngineLogger logger;
41 41
 	
42 42
 	public ScriptingEngine() {
43
-		space = new ModuleSpace(registry, new ArrayList<>(), StorageType.getStandard());
44
-		
45
-		try {
46
-            ZippedPackage stdlibs = new ZippedPackage(ScriptingEngine.class.getResourceAsStream("/StdLibs.jar"));
47
-            SemanticModule stdlibModule = stdlibs.loadModule(space, "stdlib", null, new SemanticModule[0], FunctionParameter.NONE, stdlib);
48
-			stdlibModule = Validator.validate(stdlibModule, error -> System.out.println(error.toString()));
49
-			space.addModule("stdlib", stdlibModule);
50
-			registerCompiled(stdlibModule);
51
-		} catch (CompileException | ParseException | IOException ex) {
52
-			throw new RuntimeException(ex);
53
-		}
54
-		this.logger = new EmptyLogger();
43
+        this(new ScriptingEngineStreamLogger());
55 44
     }
56 45
     
57
-    public ScriptingEngine(IZSLogger logger) {
58
-        this();
46
+    public ScriptingEngine(ScriptingEngineLogger logger) {
47
+        this.space = new ModuleSpace(registry, new ArrayList<>(), StorageType.getStandard());
59 48
         this.logger = logger;
49
+        try {
50
+            ZippedPackage stdlibs = new ZippedPackage(ScriptingEngine.class.getResourceAsStream("/StdLibs.jar"));
51
+            SemanticModule stdlibModule = stdlibs.loadModule(space, "stdlib", null, SemanticModule.NONE, FunctionParameter.NONE, stdlib, logger);
52
+            stdlibModule = Validator.validate(stdlibModule, logger);
53
+            space.addModule("stdlib", stdlibModule);
54
+            registerCompiled(stdlibModule);
55
+        } catch (CompileException | ParseException | IOException ex) {
56
+            throw new RuntimeException(ex);
57
+        }
60 58
     }
61 59
 	
62 60
 	public JavaNativeModule createNativeModule(String name, String basePackage, JavaNativeModule... dependencies) {
63 61
 		ZSPackage testPackage = new ZSPackage(space.rootPackage, name);
64
-		return new JavaNativeModule(testPackage, name, basePackage, registry, dependencies);
62
+		return new JavaNativeModule(logger, testPackage, name, basePackage, registry, dependencies);
65 63
 	}
66 64
 	
67 65
 	public void registerNativeProvided(JavaNativeModule module) throws CompileException {
68 66
 		SemanticModule semantic = Validator.validate(
69
-				module.toSemantic(space), System.out::println);
67
+				module.toSemantic(space), logger);
70 68
 		if (!semantic.isValid())
71 69
 			return;
72 70
 		
@@ -87,26 +85,13 @@ public class ScriptingEngine {
87 85
 			BracketExpressionParser bracketParser,
88 86
 			FunctionParameter[] scriptParameters,
89 87
 			String... dependencies) throws ParseException
90
-	{
91
-		return createScriptedModule(name, sources, bracketParser, scriptParameters, Throwable::printStackTrace, System.out::println, sourceFile -> System.out.println("Loading " + sourceFile.getFilename()), dependencies);
92
-	}
93
-	
94
-	public SemanticModule createScriptedModule(
95
-			String name,
96
-			SourceFile[] sources,
97
-			BracketExpressionParser bracketParser,
98
-			FunctionParameter[] scriptParameters,
99
-			Consumer<CompileException> compileExceptionConsumer,
100
-			Consumer<ValidationLogEntry> validatorErrorConsumer,
101
-			Consumer<SourceFile> sourceFileConsumer,
102
-			String... dependencies) throws ParseException
103 88
 	{
104 89
 		Module scriptModule = new Module(name);
105 90
 		CompilingPackage scriptPackage = new CompilingPackage(new ZSPackage(space.rootPackage, name), scriptModule);
106 91
 		
107 92
 		ParsedFile[] files = new ParsedFile[sources.length];
108 93
 		for (int i = 0; i < sources.length; i++) {
109
-			sourceFileConsumer.accept(sources[i]);
94
+			logger.logSourceFile(sources[i]);
110 95
 			files[i] = ParsedFile.parse(scriptPackage, bracketParser, sources[i]);
111 96
 		}
112 97
 		
@@ -122,13 +107,13 @@ public class ScriptingEngine {
122 107
 				files,
123 108
 				space,
124 109
 				scriptParameters,
125
-				compileExceptionConsumer);
110
+				logger);
126 111
 		if (!scripts.isValid())
127 112
 			return scripts;
128 113
 		
129 114
 		return Validator.validate(
130 115
 				scripts.normalize(),
131
-				validatorErrorConsumer);
116
+				logger);
132 117
 	}
133 118
 	
134 119
 	public void registerCompiled(SemanticModule module) {
@@ -148,9 +133,9 @@ public class ScriptingEngine {
148 133
         for (JavaNativeModule nativeModule : nativeModules)
149 134
             javaSpace.register(nativeModule.getCompiled());
150 135
         
151
-        JavaCompiler compiler = new JavaCompiler();
136
+        JavaCompiler compiler = new JavaCompiler(logger);
152 137
         
153
-        JavaBytecodeRunUnit runUnit = new JavaBytecodeRunUnit();
138
+        JavaBytecodeRunUnit runUnit = new JavaBytecodeRunUnit(logger);
154 139
         for (SemanticModule compiled : compiledModules)
155 140
             runUnit.add(compiler.compile(compiled.name, compiled, javaSpace));
156 141
         if (debug)

+ 7
- 0
JavaIntegration/src/main/java/org/openzen/zencode/java/logger/ScriptingEngineLogger.java View File

@@ -0,0 +1,7 @@
1
+package org.openzen.zencode.java.logger;
2
+
3
+import org.openzen.zencode.shared.logging.*;
4
+import org.openzen.zenscript.parser.logger.*;
5
+import org.openzen.zenscript.validator.logger.*;
6
+
7
+public interface ScriptingEngineLogger extends ValidatorLogger, SourceFileLogger, ParserLogger {}

+ 83
- 0
JavaIntegration/src/main/java/org/openzen/zencode/java/logger/ScriptingEngineStreamLogger.java View File

@@ -0,0 +1,83 @@
1
+package org.openzen.zencode.java.logger;
2
+
3
+import org.openzen.zencode.shared.*;
4
+import org.openzen.zenscript.validator.*;
5
+
6
+import java.io.*;
7
+
8
+public class ScriptingEngineStreamLogger implements ScriptingEngineLogger {
9
+    
10
+    private final PrintStream infoStream, debugStream, warningStream, errorStream;
11
+    
12
+    public ScriptingEngineStreamLogger(PrintStream debugStream, PrintStream infoStream, PrintStream warningStream, PrintStream errorStream) {
13
+        this.infoStream = infoStream;
14
+        this.debugStream = debugStream;
15
+        this.warningStream = warningStream;
16
+        this.errorStream = errorStream;
17
+    }
18
+    
19
+    public ScriptingEngineStreamLogger(PrintStream normalStream, PrintStream errorStream) {
20
+        this(normalStream, normalStream, normalStream, errorStream);
21
+    }
22
+    
23
+    public ScriptingEngineStreamLogger() {
24
+        this(System.out, System.err);
25
+    }
26
+    
27
+    @Override
28
+    public void info(String message) {
29
+        infoStream.println("INFO: " + message);
30
+        infoStream.flush();
31
+    }
32
+    
33
+    @Override
34
+    public void debug(String message) {
35
+        debugStream.println("DEBUG:   " + message);
36
+        debugStream.flush();
37
+    }
38
+    
39
+    @Override
40
+    public void warning(String message) {
41
+        warningStream.println("WARNING: " + message);
42
+        warningStream.flush();
43
+    }
44
+    
45
+    @Override
46
+    public void error(String message) {
47
+        errorStream.println("ERROR:   " + message);
48
+    }
49
+    
50
+    @Override
51
+    public void throwingErr(String message, Throwable throwable) {
52
+        errorStream.println("ERROR:   " + message);
53
+        throwable.printStackTrace(errorStream);
54
+        errorStream.flush();
55
+    }
56
+    
57
+    @Override
58
+    public void throwingWarn(String message, Throwable throwable) {
59
+        warningStream.println("WARNING: " + message);
60
+        throwable.printStackTrace(warningStream);
61
+        warningStream.flush();
62
+    }
63
+    
64
+    @Override
65
+    public void logCompileException(CompileException exception) {
66
+        throw new UnsupportedOperationException();
67
+    }
68
+    
69
+    @Override
70
+    public void logSourceFile(SourceFile file) {
71
+        info("Loading File: " + file.getFilename());
72
+    }
73
+    
74
+    @Override
75
+    public void logValidationError(ValidationLogEntry errorEntry) {
76
+        error(errorEntry.toString());
77
+    }
78
+    
79
+    @Override
80
+    public void logValidationWarning(ValidationLogEntry warningEntry) {
81
+        warning(warningEntry.toString());
82
+    }
83
+}

+ 2
- 2
JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaClass.java View File

@@ -41,8 +41,8 @@ public class JavaClass implements Comparable<JavaClass> {
41 41
 			return new JavaClass("", internalName, kind, new String[0]);
42 42
 		
43 43
 		int lastSlash = internalName.lastIndexOf('/');
44
-		if (lastSlash < 0)
45
-			System.out.println(internalName);
44
+		//if (lastSlash < 0)
45
+		//	System.out.println(internalName);
46 46
 		
47 47
 		String pkg = lastSlash < 0 ? "" : internalName.substring(0, lastSlash);
48 48
 		String className = lastSlash < 0 ? internalName : internalName.substring(lastSlash + 1);

+ 4
- 1
JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaContext.java View File

@@ -10,6 +10,7 @@ import java.util.HashMap;
10 10
 import java.util.List;
11 11
 import java.util.Map;
12 12
 import org.openzen.zencode.shared.CodePosition;
13
+import org.openzen.zencode.shared.logging.*;
13 14
 import org.openzen.zenscript.codemodel.FunctionHeader;
14 15
 import org.openzen.zenscript.codemodel.FunctionParameter;
15 16
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
@@ -48,8 +49,10 @@ public abstract class JavaContext {
48 49
 	
49 50
 	public final ZSPackage modulePackage;
50 51
 	public final String basePackage;
52
+	public final IZSLogger logger;
51 53
 	
52
-	public JavaContext(JavaCompileSpace space, ZSPackage modulePackage, String basePackage) {
54
+	public JavaContext(JavaCompileSpace space, ZSPackage modulePackage, String basePackage, IZSLogger logger) {
55
+	    this.logger = logger;
53 56
 		this.space = space;
54 57
 		this.registry = space.getRegistry();
55 58
 		

+ 6
- 6
JavaShared/src/main/java/org/openzen/zenscript/javashared/prepare/JavaPrepareClassMethodVisitor.java View File

@@ -73,7 +73,7 @@ public class JavaPrepareClassMethodVisitor implements MemberVisitor<Void> {
73 73
 	@Override
74 74
 	public Void visitConst(ConstMember member) {
75 75
 		if (DEBUG_EMPTY && cls.empty)
76
-			System.out.println("Class " + cls.fullName + " not empty because of const " + member.name);
76
+			context.logger.debug("Class " + cls.fullName + " not empty because of const " + member.name);
77 77
 		
78 78
 		cls.empty = false;
79 79
 		module.setFieldInfo(member, new JavaField(cls, member.name, context.getDescriptor(member.getType()), context.getSignature(member.getType())));
@@ -105,7 +105,7 @@ public class JavaPrepareClassMethodVisitor implements MemberVisitor<Void> {
105 105
 	@Override
106 106
 	public Void visitDestructor(DestructorMember member) {
107 107
 		if (DEBUG_EMPTY && cls.empty)
108
-			System.out.println("Class " + cls.fullName + " not empty because of destructor");
108
+			context.logger.debug("Class " + cls.fullName + " not empty because of destructor");
109 109
 		
110 110
 		cls.empty = false;
111 111
 		return null;
@@ -163,7 +163,7 @@ public class JavaPrepareClassMethodVisitor implements MemberVisitor<Void> {
163 163
 				m.accept(this);
164 164
 		} else {
165 165
 			if (DEBUG_EMPTY && cls.empty)
166
-				System.out.println("Class " + cls.fullName + " not empty because of unmergeable implementation");
166
+				context.logger.debug("Class " + cls.fullName + " not empty because of unmergeable implementation");
167 167
 			
168 168
 			cls.empty = false;
169 169
 			
@@ -187,7 +187,7 @@ public class JavaPrepareClassMethodVisitor implements MemberVisitor<Void> {
187 187
 		member.innerDefinition.accept(innerDefinitionPrepare);
188 188
 		
189 189
 		if (DEBUG_EMPTY && cls.empty)
190
-			System.out.println("Class " + cls.fullName + " not empty because of inner definition " + member.innerDefinition.name);
190
+			context.logger.debug("Class " + cls.fullName + " not empty because of inner definition " + member.innerDefinition.name);
191 191
 		cls.empty = false;
192 192
 		return null;
193 193
 	}
@@ -195,7 +195,7 @@ public class JavaPrepareClassMethodVisitor implements MemberVisitor<Void> {
195 195
 	@Override
196 196
 	public Void visitStaticInitializer(StaticInitializerMember member) {
197 197
 		if (DEBUG_EMPTY && cls.empty)
198
-			System.out.println("Class " + cls.fullName + " not empty because of static initializer");
198
+			context.logger.debug("Class " + cls.fullName + " not empty because of static initializer");
199 199
 		
200 200
 		cls.empty = false;
201 201
 		return null;
@@ -339,7 +339,7 @@ public class JavaPrepareClassMethodVisitor implements MemberVisitor<Void> {
339 339
 		
340 340
 		if (method.compile && member.getBuiltin() != BuiltinID.CLASS_DEFAULT_CONSTRUCTOR) {
341 341
 			if (DEBUG_EMPTY && cls.empty)
342
-				System.out.println("Class " + cls.fullName + " not empty because of " + member.describe());
342
+				context.logger.debug("Class " + cls.fullName + " not empty because of " + member.describe());
343 343
 			
344 344
 			cls.empty = false;
345 345
 		}

+ 3
- 3
JavaShared/src/main/java/org/openzen/zenscript/javashared/prepare/JavaPrepareDefinitionMemberVisitor.java View File

@@ -52,7 +52,7 @@ public class JavaPrepareDefinitionMemberVisitor implements DefinitionVisitor<Jav
52 52
 		if (definition.module != module.module)
53 53
 			throw new IllegalArgumentException("Definition is not in the same module as the current module!");
54 54
 		
55
-		System.out.println("~~ Preparing " + definition.name);
55
+		context.logger.debug("~~ Preparing " + definition.name);
56 56
 		definition.accept(this);
57 57
 	}
58 58
 	
@@ -152,7 +152,7 @@ public class JavaPrepareDefinitionMemberVisitor implements DefinitionVisitor<Jav
152 152
 	}
153 153
 	
154 154
 	private void visitClassMembers(HighLevelDefinition definition, JavaClass cls, JavaNativeClass nativeClass, boolean startsEmpty) {
155
-		System.out.println("Preparing " + cls.internalName);
155
+		context.logger.debug("Preparing " + cls.internalName);
156 156
 		JavaPrepareClassMethodVisitor methodVisitor = new JavaPrepareClassMethodVisitor(context, module, cls, nativeClass, this, startsEmpty);
157 157
 		for (IDefinitionMember member : definition.members) {
158 158
 			member.accept(methodVisitor);
@@ -161,7 +161,7 @@ public class JavaPrepareDefinitionMemberVisitor implements DefinitionVisitor<Jav
161 161
 	}
162 162
 	
163 163
 	private void visitExpansionMembers(HighLevelDefinition definition, JavaClass cls, JavaNativeClass nativeClass) {
164
-		System.out.println("Preparing " + cls.internalName);
164
+		context.logger.debug("Preparing " + cls.internalName);
165 165
 		JavaPrepareExpansionMethodVisitor methodVisitor = new JavaPrepareExpansionMethodVisitor(context, module, cls, nativeClass);
166 166
 		for (IDefinitionMember member : definition.members) {
167 167
 			member.accept(methodVisitor);

+ 2
- 2
JavaShared/src/main/java/org/openzen/zenscript/javashared/prepare/JavaPrepareExpansionMethodVisitor.java View File

@@ -65,7 +65,7 @@ public class JavaPrepareExpansionMethodVisitor implements MemberVisitor<Void> {
65 65
 		module.setFieldInfo(member, field);
66 66
 		
67 67
 		if (DEBUG_EMPTY && cls.empty)
68
-			System.out.println("Class " + cls.fullName + " not empty because of const");
68
+			context.logger.debug("Class " + cls.fullName + " not empty because of const");
69 69
 		
70 70
 		cls.empty = false;
71 71
 		return null;
@@ -202,7 +202,7 @@ public class JavaPrepareExpansionMethodVisitor implements MemberVisitor<Void> {
202 202
 		
203 203
 		if (method.compile) {
204 204
 			if (DEBUG_EMPTY && cls.empty)
205
-				System.out.println("Class " + cls.fullName + " not empty because of " + member.describe());
205
+				context.logger.debug("Class " + cls.fullName + " not empty because of " + member.describe());
206 206
 			
207 207
 			cls.empty = false;
208 208
 		}

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

@@ -8,6 +8,7 @@ package org.openzen.zenscript.javasource;
8 8
 import java.util.HashMap;
9 9
 import java.util.Map;
10 10
 import org.openzen.zencode.shared.SourceFile;
11
+import org.openzen.zencode.shared.logging.*;
11 12
 import org.openzen.zenscript.codemodel.FunctionParameter;
12 13
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
13 14
 import org.openzen.zenscript.codemodel.Module;
@@ -31,8 +32,8 @@ public class JavaSourceCompiler {
31 32
 		settings = new JavaSourceFormattingSettings.Builder().build();
32 33
 	}
33 34
 	
34
-	public JavaSourceModule compile(SemanticModule module, JavaCompileSpace space, String basePackage) {
35
-		JavaSourceContext context = new JavaSourceContext(helpers, settings, space, module.modulePackage, basePackage);
35
+	public JavaSourceModule compile(IZSLogger logger, SemanticModule module, JavaCompileSpace space, String basePackage) {
36
+		JavaSourceContext context = new JavaSourceContext(logger, helpers, settings, space, module.modulePackage, basePackage);
36 37
 		
37 38
 		JavaSourceModule result = new JavaSourceModule(module.module, module.parameters);
38 39
 		context.addModule(module.module, result);

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

@@ -5,6 +5,7 @@
5 5
  */
6 6
 package org.openzen.zenscript.javasource;
7 7
 
8
+import org.openzen.zencode.shared.logging.*;
8 9
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
9 10
 import org.openzen.zenscript.codemodel.type.StoredType;
10 11
 import org.openzen.zenscript.codemodel.type.TypeID;
@@ -22,8 +23,8 @@ public class JavaSourceContext extends JavaContext {
22 23
 	private final JavaSyntheticClassGenerator generator;
23 24
 	public final JavaSourceSyntheticHelperGenerator helperGenerator;
24 25
 	
25
-	public JavaSourceContext(JavaSourceModule helpers, JavaSourceFormattingSettings settings, JavaCompileSpace space, ZSPackage modulePackage, String basePackage) {
26
-		super(space, modulePackage, basePackage);
26
+	public JavaSourceContext(IZSLogger logger, JavaSourceModule helpers, JavaSourceFormattingSettings settings, JavaCompileSpace space, ZSPackage modulePackage, String basePackage) {
27
+		super(space, modulePackage, basePackage, logger);
27 28
 		
28 29
 		typeDescriptorVisitor = new JavaTypeDescriptorVisitor(this);
29 30
 		this.generator = new JavaSourceSyntheticTypeGenerator(helpers, settings, this);

+ 6
- 4
Parser/src/main/java/org/openzen/zenscript/parser/FolderPackage.java View File

@@ -9,6 +9,7 @@ import org.openzen.zenscript.codemodel.SemanticModule;
9 9
 import org.openzen.zenscript.codemodel.context.CompilingPackage;
10 10
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
11 11
 import org.openzen.zenscript.lexer.ParseException;
12
+import org.openzen.zenscript.parser.logger.*;
12 13
 
13 14
 import java.io.BufferedReader;
14 15
 import java.io.File;
@@ -60,11 +61,11 @@ public class FolderPackage {
60 61
         files.add(parent);
61 62
     }
62 63
 	
63
-	public SemanticModule loadModule(ModuleSpace space, String name, BracketExpressionParser bracketParser, SemanticModule[] dependencies, FunctionParameter[] scriptParameters) throws ParseException {
64
-		return loadModule(space, name, bracketParser, dependencies, scriptParameters, new ZSPackage(space.rootPackage, name));
64
+	public SemanticModule loadModule(ModuleSpace space, String name, BracketExpressionParser bracketParser, SemanticModule[] dependencies, FunctionParameter[] scriptParameters, ParserLogger logger) throws ParseException {
65
+		return loadModule(space, name, bracketParser, dependencies, scriptParameters, new ZSPackage(space.rootPackage, name), logger);
65 66
 	}
66 67
 	
67
-	public SemanticModule loadModule(ModuleSpace space, String name, BracketExpressionParser bracketParser, SemanticModule[] dependencies, FunctionParameter[] scriptParameters, ZSPackage pkg) throws ParseException {
68
+	public SemanticModule loadModule(ModuleSpace space, String name, BracketExpressionParser bracketParser, SemanticModule[] dependencies, FunctionParameter[] scriptParameters, ZSPackage pkg, ParserLogger logger) throws ParseException {
68 69
 		List<SourceFile> sourceFiles = files.get(name);
69 70
 		if (sourceFiles == null)
70 71
 			return null; // no such module
@@ -80,7 +81,8 @@ public class FolderPackage {
80 81
 				scriptPackage,
81 82
 				files,
82 83
 				space,
83
-				scriptParameters, Throwable::printStackTrace);
84
+				scriptParameters,
85
+                logger);
84 86
 		return scripts.normalize();
85 87
 	}
86 88
 }

+ 10
- 8
Parser/src/main/java/org/openzen/zenscript/parser/ParsedFile.java View File

@@ -11,6 +11,7 @@ import org.openzen.zencode.shared.CompileExceptionCode;
11 11
 import org.openzen.zencode.shared.FileSourceFile;
12 12
 import org.openzen.zencode.shared.LiteralSourceFile;
13 13
 import org.openzen.zencode.shared.SourceFile;
14
+import org.openzen.zencode.shared.logging.*;
14 15
 import org.openzen.zenscript.codemodel.FunctionHeader;
15 16
 import org.openzen.zenscript.codemodel.FunctionParameter;
16 17
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
@@ -33,6 +34,7 @@ import org.openzen.zenscript.codemodel.type.BasicTypeID;
33 34
 import org.openzen.zenscript.codemodel.type.ISymbol;
34 35
 import org.openzen.zenscript.lexer.ParseException;
35 36
 import org.openzen.zenscript.lexer.ZSTokenParser;
37
+import org.openzen.zenscript.parser.logger.*;
36 38
 import org.openzen.zenscript.parser.statements.ParsedStatement;
37 39
 
38 40
 import java.io.File;
@@ -42,7 +44,6 @@ import java.util.Collections;
42 44
 import java.util.HashMap;
43 45
 import java.util.List;
44 46
 import java.util.Map;
45
-import java.util.function.Consumer;
46 47
 
47 48
 import static org.openzen.zenscript.lexer.ZSTokenType.EOF;
48 49
 import static org.openzen.zenscript.lexer.ZSTokenType.K_IMPORT;
@@ -58,7 +59,7 @@ public class ParsedFile {
58 59
 			ParsedFile[] files,
59 60
 			ModuleSpace registry,
60 61
 			FunctionParameter[] parameters,
61
-			Consumer<CompileException> exceptionLogger) {
62
+			ParserLogger logger) {
62 63
 		// We are considering all these files to be in the same package, so make
63 64
 		// a single PackageDefinition instance. If these files were in multiple
64 65
 		// packages, we'd need an instance for every package.
@@ -100,7 +101,7 @@ public class ParsedFile {
100 101
 		}
101 102
 		
102 103
 		if (failed)
103
-			return new SemanticModule(pkg.module, dependencies, parameters, SemanticModule.State.INVALID, rootPackage, pkg.getPackage(), definitions, Collections.emptyList(), registry.registry, expansions, registry.getAnnotations(), registry.getStorageTypes());
104
+			return new SemanticModule(pkg.module, dependencies, parameters, SemanticModule.State.INVALID, rootPackage, pkg.getPackage(), definitions, Collections.emptyList(), registry.registry, expansions, registry.getAnnotations(), registry.getStorageTypes(), logger);
104 105
 		
105 106
 		// scripts will store all the script blocks encountered in the files
106 107
 		PrecompilationState precompiler = new PrecompilationState();
@@ -114,11 +115,11 @@ public class ParsedFile {
114 115
 			// compileCode will convert the parsed statements and expressions
115 116
 			// into semantic code. This semantic code can then be compiled
116 117
 			// to various targets.
117
-			file.compileCode(moduleContext, precompiler, rootPackage, pkg, expansions, scripts, globals, scriptHeader, exceptionLogger, importErrors);
118
+			file.compileCode(moduleContext, precompiler, rootPackage, pkg, expansions, scripts, globals, scriptHeader, logger, importErrors);
118 119
 		}
119 120
         
120 121
         for(CompileException error : importErrors.values()) {
121
-            exceptionLogger.accept(error);
122
+            logger.logCompileException(error);
122 123
         }
123 124
 		return new SemanticModule(
124 125
 				pkg.module,
@@ -132,7 +133,7 @@ public class ParsedFile {
132 133
 				registry.registry,
133 134
 				expansions,
134 135
 				registry.getAnnotations(),
135
-				registry.getStorageTypes());
136
+				registry.getStorageTypes(), logger);
136 137
 	}
137 138
 	
138 139
 	public static ParsedFile parse(CompilingPackage compilingPackage, BracketExpressionParser bracketParser, File file) throws ParseException {
@@ -294,7 +295,8 @@ public class ParsedFile {
294 295
             List<ScriptBlock> scripts,
295 296
             Map<String, ISymbol> globals,
296 297
             FunctionHeader scriptHeader,
297
-            Consumer<CompileException> exceptionLogger, Map<String, CompileException> importErrors) {
298
+            CompileExceptionLogger exceptionLogger,
299
+            Map<String, CompileException> importErrors) {
298 300
 		FileResolutionContext context = new FileResolutionContext(moduleContext, rootPackage, modulePackage);
299 301
 		loadImports(context, rootPackage, modulePackage, importErrors);
300 302
 		
@@ -303,7 +305,7 @@ public class ParsedFile {
303 305
 			try {
304 306
 				definition.compile(scope);
305 307
 			} catch (CompileException ex) {
306
-				exceptionLogger.accept(ex);
308
+				exceptionLogger.logCompileException(ex);
307 309
 			}
308 310
 		}
309 311
 		

+ 5
- 4
Parser/src/main/java/org/openzen/zenscript/parser/ZippedPackage.java View File

@@ -24,6 +24,7 @@ import org.openzen.zenscript.codemodel.SemanticModule;
24 24
 import org.openzen.zenscript.codemodel.context.CompilingPackage;
25 25
 import org.openzen.zenscript.codemodel.definition.ZSPackage;
26 26
 import org.openzen.zenscript.lexer.ParseException;
27
+import org.openzen.zenscript.parser.logger.*;
27 28
 
28 29
 /**
29 30
  *
@@ -57,11 +58,11 @@ public class ZippedPackage {
57 58
 		}
58 59
 	}
59 60
 	
60
-	public SemanticModule loadModule(ModuleSpace space, String name, BracketExpressionParser bracketParser, SemanticModule[] dependencies, FunctionParameter[] scriptParameters) throws ParseException {
61
-		return loadModule(space, name, bracketParser, dependencies, scriptParameters, new ZSPackage(space.rootPackage, name));
61
+	public SemanticModule loadModule(ModuleSpace space, String name, BracketExpressionParser bracketParser, SemanticModule[] dependencies, FunctionParameter[] scriptParameters, ParserLogger logger) throws ParseException {
62
+		return loadModule(space, name, bracketParser, dependencies, scriptParameters, new ZSPackage(space.rootPackage, name), logger);
62 63
 	}
63 64
 	
64
-	public SemanticModule loadModule(ModuleSpace space, String name, BracketExpressionParser bracketParser, SemanticModule[] dependencies, FunctionParameter[] scriptParameters, ZSPackage pkg) throws ParseException {
65
+	public SemanticModule loadModule(ModuleSpace space, String name, BracketExpressionParser bracketParser, SemanticModule[] dependencies, FunctionParameter[] scriptParameters, ZSPackage pkg, ParserLogger logger) throws ParseException {
65 66
 		List<SourceFile> sourceFiles = files.get(name);
66 67
 		if (sourceFiles == null)
67 68
 			return null; // no such module
@@ -78,7 +79,7 @@ public class ZippedPackage {
78 79
 				files,
79 80
 				space,
80 81
 				scriptParameters,
81
-				ex -> ex.printStackTrace());
82
+				logger);
82 83
 		return scripts.normalize();
83 84
 	}
84 85
 }

+ 0
- 4
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedNewExpression.java View File

@@ -52,10 +52,6 @@ public class ParsedNewExpression extends ParsedExpression{
52 52
 		try {
53 53
 			TypeMembers members = scope.getTypeMembers(type);
54 54
 			TypeMemberGroup constructors = members.getOrCreateGroup(OperatorType.CONSTRUCTOR);
55
-			/*for (TypeMember<FunctionalMemberRef> member : constructors.getMethodMembers()) {
56
-				if (member.member.getBuiltin() == BuiltinID.ARRAY_CONSTRUCTOR_PROJECTED)
57
-					System.out.println("X");
58
-			}*/
59 55
 
60 56
 			List<StoredType>[] predictedTypes = constructors.predictCallTypes(position, scope, scope.hints, arguments.arguments.size());
61 57
 			CallArguments compiledArguments = arguments.compileCall(position, scope, null, constructors);

+ 5
- 0
Parser/src/main/java/org/openzen/zenscript/parser/logger/ParserLogger.java View File

@@ -0,0 +1,5 @@
1
+package org.openzen.zenscript.parser.logger;
2
+
3
+import org.openzen.zencode.shared.logging.*;
4
+
5
+public interface ParserLogger extends IZSLogger, CompileExceptionLogger {}

+ 0
- 58
ScriptingExample/src/main/java/org/openzen/zenscript/scriptingexample/logging/StreamLogger.java View File

@@ -1,58 +0,0 @@
1
-package org.openzen.zenscript.scriptingexample.logging;
2
-
3
-import org.openzen.zencode.java.IZSLogger;
4
-
5
-import java.io.PrintStream;
6
-
7
-public class StreamLogger implements IZSLogger {
8
-    private final PrintStream infoStream, debugStream, warningStream, errorStream;
9
-
10
-    public StreamLogger(PrintStream debugStream, PrintStream infoStream, PrintStream warningStream, PrintStream errorStream) {
11
-        this.infoStream = infoStream;
12
-        this.debugStream = debugStream;
13
-        this.warningStream = warningStream;
14
-        this.errorStream = errorStream;
15
-    }
16
-
17
-    public StreamLogger(PrintStream normalStream, PrintStream errorStream) {
18
-        this(normalStream, normalStream, normalStream, errorStream);
19
-    }
20
-
21
-    public StreamLogger(){
22
-        this(System.out, System.err);
23
-    }
24
-
25
-    @Override
26
-    public void info(String message) {
27
-        System.out.println("INFO: " + message);
28
-    }
29
-
30
-    @Override
31
-    public void debug(String message) {
32
-        System.out.println("DEBUG:   " + message);
33
-    }
34
-
35
-    @Override
36
-    public void warning(String message) {
37
-        System.out.println("WARNING: " + message);
38
-    }
39
-
40
-    @Override
41
-    public void error(String message) {
42
-        System.err.println("ERROR:   " + message);
43
-    }
44
-
45
-    @Override
46
-    public void throwingErr(String message, Throwable throwable) {
47
-        System.err.println("ERROR:   " + message);
48
-        throwable.printStackTrace(System.err);
49
-        System.err.flush();
50
-    }
51
-
52
-    @Override
53
-    public void throwingWarn(String message, Throwable throwable) {
54
-        System.err.println("WARNING: " + message);
55
-        throwable.printStackTrace(System.out);
56
-        System.out.flush();
57
-    }
58
-}

+ 7
- 0
Shared/src/main/java/org/openzen/zencode/shared/logging/CompileExceptionLogger.java View File

@@ -0,0 +1,7 @@
1
+package org.openzen.zencode.shared.logging;
2
+
3
+import org.openzen.zencode.shared.*;
4
+
5
+public interface CompileExceptionLogger {
6
+    void logCompileException(CompileException exception);
7
+}

JavaIntegration/src/main/java/org/openzen/zencode/java/IZSLogger.java → Shared/src/main/java/org/openzen/zencode/shared/logging/IZSLogger.java View File

@@ -1,4 +1,4 @@
1
-package org.openzen.zencode.java;
1
+package org.openzen.zencode.shared.logging;
2 2
 
3 3
 public interface IZSLogger {
4 4
     

+ 7
- 0
Shared/src/main/java/org/openzen/zencode/shared/logging/SourceFileLogger.java View File

@@ -0,0 +1,7 @@
1
+package org.openzen.zencode.shared.logging;
2
+
3
+import org.openzen.zencode.shared.*;
4
+
5
+public interface SourceFileLogger {
6
+    void logSourceFile(SourceFile file);
7
+}

+ 6
- 4
Validator/src/main/java/org/openzen/zenscript/validator/Validator.java View File

@@ -8,7 +8,7 @@ package org.openzen.zenscript.validator;
8 8
 import java.util.ArrayList;
9 9
 import java.util.Collections;
10 10
 import java.util.List;
11
-import java.util.function.Consumer;
11
+
12 12
 import org.openzen.zencode.shared.CodePosition;
13 13
 import org.openzen.zenscript.codemodel.AccessScope;
14 14
 import org.openzen.zenscript.codemodel.FunctionHeader;
@@ -20,6 +20,7 @@ import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
20 20
 import org.openzen.zenscript.codemodel.statement.Statement;
21 21
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
22 22
 import org.openzen.zenscript.validator.analysis.StatementScope;
23
+import org.openzen.zenscript.validator.logger.*;
23 24
 import org.openzen.zenscript.validator.visitors.DefinitionValidator;
24 25
 import org.openzen.zenscript.validator.visitors.StatementValidator;
25 26
 
@@ -28,7 +29,7 @@ import org.openzen.zenscript.validator.visitors.StatementValidator;
28 29
  * @author Hoofdgebruiker
29 30
  */
30 31
 public class Validator {
31
-	public static SemanticModule validate(SemanticModule module, Consumer<ValidationLogEntry> logger) {
32
+	public static SemanticModule validate(SemanticModule module, ValidatorLogger logger) {
32 33
 		if (module.state != SemanticModule.State.NORMALIZED)
33 34
 			throw new IllegalStateException("Module is not yet normalized");
34 35
 		
@@ -41,7 +42,7 @@ public class Validator {
41 42
 		}
42 43
 		
43 44
 		for (ValidationLogEntry entry : validator.getLog()) {
44
-			logger.accept(entry);
45
+			logger.logValidationLogEntry(entry);
45 46
 		}
46 47
 		
47 48
 		SemanticModule.State state = validator.hasErrors() ? SemanticModule.State.INVALID : SemanticModule.State.VALIDATED;
@@ -57,7 +58,8 @@ public class Validator {
57 58
 				module.registry,
58 59
 				module.expansions,
59 60
 				module.annotations,
60
-				module.storageTypes);
61
+				module.storageTypes,
62
+                logger);
61 63
 	}
62 64
 	
63 65
 	private final List<ValidationLogEntry> log = new ArrayList<>();

+ 21
- 0
Validator/src/main/java/org/openzen/zenscript/validator/logger/IZSValidationLogger.java View File

@@ -0,0 +1,21 @@
1
+package org.openzen.zenscript.validator.logger;
2
+
3
+import org.openzen.zenscript.validator.*;
4
+
5
+public interface IZSValidationLogger {
6
+    
7
+    default void logValidationLogEntry(ValidationLogEntry entry) {
8
+        switch(entry.kind) {
9
+            case ERROR:
10
+                logValidationError(entry);
11
+                break;
12
+            case WARNING:
13
+                logValidationWarning(entry);
14
+                break;
15
+        }
16
+    }
17
+    
18
+    void logValidationError(ValidationLogEntry errorEntry);
19
+    
20
+    void logValidationWarning(ValidationLogEntry warningEntry);
21
+}

+ 5
- 0
Validator/src/main/java/org/openzen/zenscript/validator/logger/ValidatorLogger.java View File

@@ -0,0 +1,5 @@
1
+package org.openzen.zenscript.validator.logger;
2
+
3
+import org.openzen.zencode.shared.logging.*;
4
+
5
+public interface ValidatorLogger extends IZSValidationLogger, IZSLogger {}

Loading…
Cancel
Save