11 Commits

Autor SHA1 Mensagem Data
  Jared 033581a709
Added StdLibs to the scripting example, updated gitignore to block out/ 5 anos atrás
  Jared 84b407af0d
Fix Iterator not having methods / fixed stdlibs not being reloadable 5 anos atrás
  Jared aaca0261f1
Removed some unneeded static fields 5 anos atrás
  kindlich a3eea65869
Added all registered modules to the compile space 5 anos atrás
  kindlich 7b39160a6c
Revert change on ParsedConstructor 5 anos atrás
  kindlich ee59ddba30
Merge remote-tracking branch 'jared/stdlib' into development 5 anos atrás
  kindlich fb3382704d
Skip non-linear interface implementations for Native classes 5 anos atrás
  kindlich 187a509863
Set Definition Type members in JavaPrepareDefinitionVisitor 5 anos atrás
  kindlich 4a5b508fbe
Pop method return type if ZC thinks a nonvoid method returns a void value 5 anos atrás
  Jared 2459b7ee67
Didn't mean to push this 5 anos atrás
  Jared 4cbbe1f387
work on getting this working 5 anos atrás

+ 2
- 0
.gitignore Ver arquivo

@@ -2,3 +2,5 @@
2 2
 .nb-gradle
3 3
 build
4 4
 *.class
5
+
6
+out/

+ 4
- 3
CodeModel/src/main/java/org/openzen/zenscript/codemodel/annotations/NativeAnnotationDefinition.java Ver arquivo

@@ -5,8 +5,6 @@
5 5
  */
6 6
 package org.openzen.zenscript.codemodel.annotations;
7 7
 
8
-import java.util.Collections;
9
-import java.util.List;
10 8
 import org.openzen.zencode.shared.CodePosition;
11 9
 import org.openzen.zenscript.codemodel.FunctionHeader;
12 10
 import org.openzen.zenscript.codemodel.FunctionParameter;
@@ -24,6 +22,9 @@ import org.openzen.zenscript.codemodel.statement.Statement;
24 22
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
25 23
 import org.openzen.zenscript.codemodel.type.StringTypeID;
26 24
 
25
+import java.util.Collections;
26
+import java.util.List;
27
+
27 28
 /**
28 29
  *
29 30
  * @author Hoofdgebruiker
@@ -31,7 +32,7 @@ import org.openzen.zenscript.codemodel.type.StringTypeID;
31 32
 public class NativeAnnotationDefinition implements AnnotationDefinition {
32 33
 	public static final NativeAnnotationDefinition INSTANCE = new NativeAnnotationDefinition();
33 34
 	
34
-	private static final List<FunctionHeader> INITIALIZERS = Collections.singletonList(
35
+	private final List<FunctionHeader> INITIALIZERS = Collections.singletonList(
35 36
 			new FunctionHeader(BasicTypeID.VOID, StringTypeID.UNIQUE));
36 37
 	
37 38
 	private NativeAnnotationDefinition() {}

+ 9
- 1
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/JavaExpressionVisitor.java Ver arquivo

@@ -4227,8 +4227,16 @@ public class JavaExpressionVisitor implements ExpressionVisitor<Void>, JavaNativ
4227 4227
 		} else {
4228 4228
 			getJavaWriter().invokeVirtual(methodInfo);
4229 4229
 		}
4230
-		if (methodInfo.genericResult)
4230
+		if (methodInfo.genericResult) {
4231 4231
 			getJavaWriter().checkCast(context.getInternalName(resultType));
4232
+		}
4233
+
4234
+		//Make sure that method results are popped if ZC thinks its a void but it actually is not.
4235
+		//Fixes an issue for List#add() returning void in ZC but Z in Java.
4236
+		if(resultType.type == BasicTypeID.VOID && !methodInfo.descriptor.endsWith(")V")) {
4237
+			final boolean isLarge = methodInfo.descriptor.endsWith(")D") && methodInfo.descriptor.endsWith(")L");
4238
+			getJavaWriter().pop(isLarge);
4239
+		}
4232 4240
 
4233 4241
 		return true;
4234 4242
 	}

+ 23
- 10
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/definitions/JavaDefinitionVisitor.java Ver arquivo

@@ -1,32 +1,45 @@
1 1
 package org.openzen.zenscript.javabytecode.compiler.definitions;
2 2
 
3
-import org.openzen.zenscript.codemodel.member.MethodMember;
4
-import org.openzen.zenscript.javashared.*;
5 3
 import org.objectweb.asm.ClassWriter;
6 4
 import org.objectweb.asm.Opcodes;
7
-import org.openzen.zenscript.codemodel.definition.*;
5
+import org.openzen.zenscript.codemodel.definition.AliasDefinition;
6
+import org.openzen.zenscript.codemodel.definition.ClassDefinition;
7
+import org.openzen.zenscript.codemodel.definition.DefinitionVisitor;
8
+import org.openzen.zenscript.codemodel.definition.EnumDefinition;
9
+import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
10
+import org.openzen.zenscript.codemodel.definition.FunctionDefinition;
11
+import org.openzen.zenscript.codemodel.definition.InterfaceDefinition;
12
+import org.openzen.zenscript.codemodel.definition.StructDefinition;
13
+import org.openzen.zenscript.codemodel.definition.VariantDefinition;
8 14
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
9 15
 import org.openzen.zenscript.codemodel.member.IDefinitionMember;
16
+import org.openzen.zenscript.codemodel.member.ImplementationMember;
10 17
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
11 18
 import org.openzen.zenscript.codemodel.type.GenericTypeID;
19
+import org.openzen.zenscript.codemodel.type.StoredType;
12 20
 import org.openzen.zenscript.javabytecode.JavaBytecodeContext;
13
-import org.openzen.zenscript.javabytecode.compiler.*;
21
+import org.openzen.zenscript.javabytecode.compiler.CompilerUtils;
22
+import org.openzen.zenscript.javabytecode.compiler.JavaClassWriter;
23
+import org.openzen.zenscript.javabytecode.compiler.JavaStatementVisitor;
24
+import org.openzen.zenscript.javabytecode.compiler.JavaWriter;
25
+import org.openzen.zenscript.javashared.JavaClass;
26
+import org.openzen.zenscript.javashared.JavaMethod;
27
+import org.openzen.zenscript.javashared.JavaModifiers;
28
+import org.openzen.zenscript.javashared.JavaTypeGenericVisitor;
29
+import org.openzen.zenscript.javashared.JavaVariantOption;
14 30
 
15
-import java.io.FileNotFoundException;
16 31
 import java.io.FileOutputStream;
17 32
 import java.io.IOException;
18 33
 import java.util.ArrayList;
19 34
 import java.util.List;
20
-import org.openzen.zenscript.codemodel.member.ImplementationMember;
21
-import org.openzen.zenscript.codemodel.type.StoredType;
22 35
 
23 36
 
24 37
 public class JavaDefinitionVisitor implements DefinitionVisitor<byte[]> {
25
-	private static final JavaMethod CLASS_FORNAME
38
+	private final JavaMethod CLASS_FORNAME
26 39
 			= JavaMethod.getNativeStatic(JavaClass.CLASS, "forName", "(Ljava/lang/String;)Ljava/lang/Class;");
27
-	private static final JavaMethod ENUM_VALUEOF
40
+	private final JavaMethod ENUM_VALUEOF
28 41
 			= JavaMethod.getNativeStatic(JavaClass.CLASS, "valueOf", "(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/Enum;");
29
-	private static final JavaMethod ARRAY_CLONE
42
+	private final JavaMethod ARRAY_CLONE
30 43
 			= JavaMethod.getNativeVirtual(JavaClass.ARRAYS, "clone", "()Ljava/lang/Object;");
31 44
 
32 45
 	private final JavaClassWriter outerWriter;

+ 7
- 0
JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/compiler/definitions/JavaMemberVisitor.java Ver arquivo

@@ -190,6 +190,13 @@ public class JavaMemberVisitor implements MemberVisitor<Void> {
190 190
 			for (IDefinitionMember imember : member.members)
191 191
 				imember.accept(this);
192 192
 		} else {
193
+			//TODO: Fixme???
194
+			// What should I do if a native class has interfaces to be visited?
195
+			if(javaModule.getNativeClassInfo(member.definition) != null) {
196
+				return null;
197
+			}
198
+
199
+
193 200
 			throw new UnsupportedOperationException("Non-inline interface implementations not yet available");
194 201
 		}
195 202
 		return null;

+ 1
- 0
JavaIntegration/src/main/java/org/openzen/zencode/java/ScriptingEngine.java Ver arquivo

@@ -47,6 +47,7 @@ public class ScriptingEngine {
47 47
             SemanticModule stdlibModule = stdlibs.loadModule(space, "stdlib", null, new SemanticModule[0], FunctionParameter.NONE, stdlib);
48 48
 			stdlibModule = Validator.validate(stdlibModule, error -> System.out.println(error.toString()));
49 49
 			space.addModule("stdlib", stdlibModule);
50
+			registerCompiled(stdlibModule);
50 51
 		} catch (CompileException | ParseException | IOException ex) {
51 52
 			throw new RuntimeException(ex);
52 53
 		}

+ 2
- 0
JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaCompileSpace.java Ver arquivo

@@ -13,6 +13,8 @@ import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
13 13
  * @author Hoofdgebruiker
14 14
  */
15 15
 public interface JavaCompileSpace {
16
+	void register(JavaCompiledModule module);
17
+
16 18
 	GlobalTypeRegistry getRegistry();
17 19
 	
18 20
 	JavaCompiledModule getCompiled(Module module);

+ 3
- 0
JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaContext.java Ver arquivo

@@ -128,6 +128,9 @@ public abstract class JavaContext {
128 128
 	
129 129
 	public void addModule(Module module, JavaCompiledModule target) {
130 130
 		modules.put(module, target);
131
+
132
+		//TODO: can we do this here?
133
+		space.register(target);
131 134
 	}
132 135
 	
133 136
 	public JavaCompiledModule getJavaModule(Module module) {

+ 2
- 1
JavaShared/src/main/java/org/openzen/zenscript/javashared/SimpleJavaCompileSpace.java Ver arquivo

@@ -21,7 +21,8 @@ public class SimpleJavaCompileSpace implements JavaCompileSpace {
21 21
 	public SimpleJavaCompileSpace(GlobalTypeRegistry registry) {
22 22
 		this.registry = registry;
23 23
 	}
24
-	
24
+
25
+	@Override
25 26
 	public void register(JavaCompiledModule module) {
26 27
 		modules.put(module.module, module);
27 28
 	}

+ 8
- 7
JavaShared/src/main/java/org/openzen/zenscript/javashared/prepare/JavaPrepareDefinitionMemberVisitor.java Ver arquivo

@@ -5,7 +5,8 @@
5 5
  */
6 6
 package org.openzen.zenscript.javashared.prepare;
7 7
 
8
-import org.openzen.zenscript.javashared.JavaNativeClass;
8
+import org.openzen.zenscript.codemodel.generic.TypeParameter;
9
+import org.openzen.zenscript.javashared.*;
9 10
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
10 11
 import org.openzen.zenscript.codemodel.definition.AliasDefinition;
11 12
 import org.openzen.zenscript.codemodel.definition.ClassDefinition;
@@ -19,11 +20,6 @@ import org.openzen.zenscript.codemodel.definition.VariantDefinition;
19 20
 import org.openzen.zenscript.codemodel.member.IDefinitionMember;
20 21
 import org.openzen.zenscript.codemodel.type.DefinitionTypeID;
21 22
 import org.openzen.zenscript.codemodel.type.TypeID;
22
-import org.openzen.zenscript.javashared.JavaClass;
23
-import org.openzen.zenscript.javashared.JavaCompiledModule;
24
-import org.openzen.zenscript.javashared.JavaContext;
25
-import org.openzen.zenscript.javashared.JavaMethod;
26
-import org.openzen.zenscript.javashared.JavaModifiers;
27 23
 
28 24
 /**
29 25
  *
@@ -64,7 +60,7 @@ public class JavaPrepareDefinitionMemberVisitor implements DefinitionVisitor<Jav
64 60
 	public JavaClass visitClass(ClassDefinition definition) {
65 61
 		if (isPrepared(definition))
66 62
 			return context.getJavaClass(definition);
67
-		
63
+
68 64
 		return visitClassCompiled(definition, true, JavaClass.Kind.CLASS);
69 65
 	}
70 66
 
@@ -134,6 +130,11 @@ public class JavaPrepareDefinitionMemberVisitor implements DefinitionVisitor<Jav
134 130
 	}
135 131
 	
136 132
 	private JavaClass visitClassCompiled(HighLevelDefinition definition, boolean startsEmpty, JavaClass.Kind kind) {
133
+
134
+		for (TypeParameter typeParameter : definition.typeParameters) {
135
+			module.setTypeParameterInfo(typeParameter, new JavaTypeParameterInfo(-1));
136
+		}
137
+
137 138
 		if (definition.getSuperType() != null)
138 139
 			prepare(definition.getSuperType());
139 140
 		

+ 8
- 7
JavaShared/src/main/java/org/openzen/zenscript/javashared/prepare/JavaPrepareDefinitionVisitor.java Ver arquivo

@@ -5,10 +5,6 @@
5 5
  */
6 6
 package org.openzen.zenscript.javashared.prepare;
7 7
 
8
-import org.openzen.zenscript.javashared.JavaNativeClass;
9
-import java.util.HashMap;
10
-import java.util.List;
11
-import java.util.Map;
12 8
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
13 9
 import org.openzen.zenscript.codemodel.annotations.NativeTag;
14 10
 import org.openzen.zenscript.codemodel.definition.AliasDefinition;
@@ -33,16 +29,21 @@ import org.openzen.zenscript.javashared.JavaCompiledModule;
33 29
 import org.openzen.zenscript.javashared.JavaContext;
34 30
 import org.openzen.zenscript.javashared.JavaMethod;
35 31
 import org.openzen.zenscript.javashared.JavaModifiers;
32
+import org.openzen.zenscript.javashared.JavaNativeClass;
36 33
 import org.openzen.zenscript.javashared.JavaVariantOption;
37 34
 
35
+import java.util.HashMap;
36
+import java.util.List;
37
+import java.util.Map;
38
+
38 39
 /**
39 40
  *
40 41
  * @author Hoofdgebruiker
41 42
  */
42 43
 public class JavaPrepareDefinitionVisitor implements DefinitionVisitor<JavaClass> {
43
-	private static final Map<String, JavaNativeClass> nativeClasses = new HashMap<>();
44
+	private final Map<String, JavaNativeClass> nativeClasses = new HashMap<>();
44 45
 	
45
-	static {
46
+	 {
46 47
 		{
47 48
 			JavaNativeClass cls = new JavaNativeClass(new JavaClass("java.lang", "StringBuilder", JavaClass.Kind.CLASS));
48 49
 			cls.addConstructor("constructor", "()V");
@@ -94,7 +95,7 @@ public class JavaPrepareDefinitionVisitor implements DefinitionVisitor<JavaClass
94 95
 		}
95 96
 		
96 97
 		{
97
-			JavaNativeClass iterator = new JavaNativeClass(JavaClass.ITERATOR);
98
+			JavaNativeClass iterator = new JavaNativeClass(new JavaClass("java.util", "Iterator", JavaClass.Kind.INTERFACE));
98 99
 			iterator.addMethod("empty", new JavaMethod(JavaClass.COLLECTIONS, JavaMethod.Kind.STATIC, "emptyIterator", false, "()Ljava/lang/Iterator;", JavaModifiers.STATIC | JavaModifiers.PUBLIC, false));
99 100
 			iterator.addInstanceMethod("hasNext", "hasNext", "()Z");
100 101
 			iterator.addInstanceMethod("next", "next", "()Ljava/lang/Object;");

BIN
ScriptingExample/src/main/resources/StdLibs.jar Ver arquivo


Carregando…
Cancelar
Salvar