11 Commits

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

+ 2
- 0
.gitignore View File

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

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

5
  */
5
  */
6
 package org.openzen.zenscript.codemodel.annotations;
6
 package org.openzen.zenscript.codemodel.annotations;
7
 
7
 
8
-import java.util.Collections;
9
-import java.util.List;
10
 import org.openzen.zencode.shared.CodePosition;
8
 import org.openzen.zencode.shared.CodePosition;
11
 import org.openzen.zenscript.codemodel.FunctionHeader;
9
 import org.openzen.zenscript.codemodel.FunctionHeader;
12
 import org.openzen.zenscript.codemodel.FunctionParameter;
10
 import org.openzen.zenscript.codemodel.FunctionParameter;
24
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
22
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
25
 import org.openzen.zenscript.codemodel.type.StringTypeID;
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
  * @author Hoofdgebruiker
30
  * @author Hoofdgebruiker
31
 public class NativeAnnotationDefinition implements AnnotationDefinition {
32
 public class NativeAnnotationDefinition implements AnnotationDefinition {
32
 	public static final NativeAnnotationDefinition INSTANCE = new NativeAnnotationDefinition();
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
 			new FunctionHeader(BasicTypeID.VOID, StringTypeID.UNIQUE));
36
 			new FunctionHeader(BasicTypeID.VOID, StringTypeID.UNIQUE));
36
 	
37
 	
37
 	private NativeAnnotationDefinition() {}
38
 	private NativeAnnotationDefinition() {}

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

4227
 		} else {
4227
 		} else {
4228
 			getJavaWriter().invokeVirtual(methodInfo);
4228
 			getJavaWriter().invokeVirtual(methodInfo);
4229
 		}
4229
 		}
4230
-		if (methodInfo.genericResult)
4230
+		if (methodInfo.genericResult) {
4231
 			getJavaWriter().checkCast(context.getInternalName(resultType));
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
 		return true;
4241
 		return true;
4234
 	}
4242
 	}

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

1
 package org.openzen.zenscript.javabytecode.compiler.definitions;
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
 import org.objectweb.asm.ClassWriter;
3
 import org.objectweb.asm.ClassWriter;
6
 import org.objectweb.asm.Opcodes;
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
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
14
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
9
 import org.openzen.zenscript.codemodel.member.IDefinitionMember;
15
 import org.openzen.zenscript.codemodel.member.IDefinitionMember;
16
+import org.openzen.zenscript.codemodel.member.ImplementationMember;
10
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
17
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
11
 import org.openzen.zenscript.codemodel.type.GenericTypeID;
18
 import org.openzen.zenscript.codemodel.type.GenericTypeID;
19
+import org.openzen.zenscript.codemodel.type.StoredType;
12
 import org.openzen.zenscript.javabytecode.JavaBytecodeContext;
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
 import java.io.FileOutputStream;
31
 import java.io.FileOutputStream;
17
 import java.io.IOException;
32
 import java.io.IOException;
18
 import java.util.ArrayList;
33
 import java.util.ArrayList;
19
 import java.util.List;
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
 public class JavaDefinitionVisitor implements DefinitionVisitor<byte[]> {
37
 public class JavaDefinitionVisitor implements DefinitionVisitor<byte[]> {
25
-	private static final JavaMethod CLASS_FORNAME
38
+	private final JavaMethod CLASS_FORNAME
26
 			= JavaMethod.getNativeStatic(JavaClass.CLASS, "forName", "(Ljava/lang/String;)Ljava/lang/Class;");
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
 			= JavaMethod.getNativeStatic(JavaClass.CLASS, "valueOf", "(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/Enum;");
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
 			= JavaMethod.getNativeVirtual(JavaClass.ARRAYS, "clone", "()Ljava/lang/Object;");
43
 			= JavaMethod.getNativeVirtual(JavaClass.ARRAYS, "clone", "()Ljava/lang/Object;");
31
 
44
 
32
 	private final JavaClassWriter outerWriter;
45
 	private final JavaClassWriter outerWriter;

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

190
 			for (IDefinitionMember imember : member.members)
190
 			for (IDefinitionMember imember : member.members)
191
 				imember.accept(this);
191
 				imember.accept(this);
192
 		} else {
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
 			throw new UnsupportedOperationException("Non-inline interface implementations not yet available");
200
 			throw new UnsupportedOperationException("Non-inline interface implementations not yet available");
194
 		}
201
 		}
195
 		return null;
202
 		return null;

+ 1
- 0
JavaIntegration/src/main/java/org/openzen/zencode/java/ScriptingEngine.java View File

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

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

13
  * @author Hoofdgebruiker
13
  * @author Hoofdgebruiker
14
  */
14
  */
15
 public interface JavaCompileSpace {
15
 public interface JavaCompileSpace {
16
+	void register(JavaCompiledModule module);
17
+
16
 	GlobalTypeRegistry getRegistry();
18
 	GlobalTypeRegistry getRegistry();
17
 	
19
 	
18
 	JavaCompiledModule getCompiled(Module module);
20
 	JavaCompiledModule getCompiled(Module module);

+ 3
- 0
JavaShared/src/main/java/org/openzen/zenscript/javashared/JavaContext.java View File

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

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

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

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

5
  */
5
  */
6
 package org.openzen.zenscript.javashared.prepare;
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
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
10
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
10
 import org.openzen.zenscript.codemodel.definition.AliasDefinition;
11
 import org.openzen.zenscript.codemodel.definition.AliasDefinition;
11
 import org.openzen.zenscript.codemodel.definition.ClassDefinition;
12
 import org.openzen.zenscript.codemodel.definition.ClassDefinition;
19
 import org.openzen.zenscript.codemodel.member.IDefinitionMember;
20
 import org.openzen.zenscript.codemodel.member.IDefinitionMember;
20
 import org.openzen.zenscript.codemodel.type.DefinitionTypeID;
21
 import org.openzen.zenscript.codemodel.type.DefinitionTypeID;
21
 import org.openzen.zenscript.codemodel.type.TypeID;
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
 	public JavaClass visitClass(ClassDefinition definition) {
60
 	public JavaClass visitClass(ClassDefinition definition) {
65
 		if (isPrepared(definition))
61
 		if (isPrepared(definition))
66
 			return context.getJavaClass(definition);
62
 			return context.getJavaClass(definition);
67
-		
63
+
68
 		return visitClassCompiled(definition, true, JavaClass.Kind.CLASS);
64
 		return visitClassCompiled(definition, true, JavaClass.Kind.CLASS);
69
 	}
65
 	}
70
 
66
 
134
 	}
130
 	}
135
 	
131
 	
136
 	private JavaClass visitClassCompiled(HighLevelDefinition definition, boolean startsEmpty, JavaClass.Kind kind) {
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
 		if (definition.getSuperType() != null)
138
 		if (definition.getSuperType() != null)
138
 			prepare(definition.getSuperType());
139
 			prepare(definition.getSuperType());
139
 		
140
 		

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

5
  */
5
  */
6
 package org.openzen.zenscript.javashared.prepare;
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
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
8
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
13
 import org.openzen.zenscript.codemodel.annotations.NativeTag;
9
 import org.openzen.zenscript.codemodel.annotations.NativeTag;
14
 import org.openzen.zenscript.codemodel.definition.AliasDefinition;
10
 import org.openzen.zenscript.codemodel.definition.AliasDefinition;
33
 import org.openzen.zenscript.javashared.JavaContext;
29
 import org.openzen.zenscript.javashared.JavaContext;
34
 import org.openzen.zenscript.javashared.JavaMethod;
30
 import org.openzen.zenscript.javashared.JavaMethod;
35
 import org.openzen.zenscript.javashared.JavaModifiers;
31
 import org.openzen.zenscript.javashared.JavaModifiers;
32
+import org.openzen.zenscript.javashared.JavaNativeClass;
36
 import org.openzen.zenscript.javashared.JavaVariantOption;
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
  * @author Hoofdgebruiker
41
  * @author Hoofdgebruiker
41
  */
42
  */
42
 public class JavaPrepareDefinitionVisitor implements DefinitionVisitor<JavaClass> {
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
 			JavaNativeClass cls = new JavaNativeClass(new JavaClass("java.lang", "StringBuilder", JavaClass.Kind.CLASS));
48
 			JavaNativeClass cls = new JavaNativeClass(new JavaClass("java.lang", "StringBuilder", JavaClass.Kind.CLASS));
48
 			cls.addConstructor("constructor", "()V");
49
 			cls.addConstructor("constructor", "()V");
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
 			iterator.addMethod("empty", new JavaMethod(JavaClass.COLLECTIONS, JavaMethod.Kind.STATIC, "emptyIterator", false, "()Ljava/lang/Iterator;", JavaModifiers.STATIC | JavaModifiers.PUBLIC, false));
99
 			iterator.addMethod("empty", new JavaMethod(JavaClass.COLLECTIONS, JavaMethod.Kind.STATIC, "emptyIterator", false, "()Ljava/lang/Iterator;", JavaModifiers.STATIC | JavaModifiers.PUBLIC, false));
99
 			iterator.addInstanceMethod("hasNext", "hasNext", "()Z");
100
 			iterator.addInstanceMethod("hasNext", "hasNext", "()Z");
100
 			iterator.addInstanceMethod("next", "next", "()Ljava/lang/Object;");
101
 			iterator.addInstanceMethod("next", "next", "()Ljava/lang/Object;");

BIN
ScriptingExample/src/main/resources/StdLibs.jar View File


Loading…
Cancel
Save