Browse Source

Merge remote-tracking branch 'jared/stdlib' into development

kindlich 5 years ago
parent
commit
ee59ddba30
No known key found for this signature in database

JavaIntegration/src/main/resources/StdLibs.zip → JavaIntegration/StdLibs.jar View File


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

43
 		space = new ModuleSpace(registry, new ArrayList<>(), StorageType.getStandard());
43
 		space = new ModuleSpace(registry, new ArrayList<>(), StorageType.getStandard());
44
 		
44
 		
45
 		try {
45
 		try {
46
-			ZippedPackage stdlibs = new ZippedPackage(ScriptingEngine.class.getResourceAsStream("/StdLibs.zip"));
47
-			SemanticModule stdlibModule = stdlibs.loadModule(space, "stdlib", null, new SemanticModule[0], FunctionParameter.NONE, stdlib);
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()));
48
 			stdlibModule = Validator.validate(stdlibModule, error -> System.out.println(error.toString()));
49
 			space.addModule("stdlib", stdlibModule);
49
 			space.addModule("stdlib", stdlibModule);
50
-		} catch (IOException | CompileException | ParseException ex) {
50
+			registerCompiled(stdlibModule);
51
+		} catch (CompileException | ParseException | IOException ex) {
51
 			throw new RuntimeException(ex);
52
 			throw new RuntimeException(ex);
52
 		}
53
 		}
53
 		this.logger = new EmptyLogger();
54
 		this.logger = new EmptyLogger();

+ 5
- 4
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

+ 86
- 0
Parser/src/main/java/org/openzen/zenscript/parser/FolderPackage.java View File

1
+package org.openzen.zenscript.parser;
2
+
3
+import org.openzen.zencode.shared.LiteralSourceFile;
4
+import org.openzen.zencode.shared.SourceFile;
5
+import org.openzen.zenscript.codemodel.FunctionParameter;
6
+import org.openzen.zenscript.codemodel.Module;
7
+import org.openzen.zenscript.codemodel.ModuleSpace;
8
+import org.openzen.zenscript.codemodel.SemanticModule;
9
+import org.openzen.zenscript.codemodel.context.CompilingPackage;
10
+import org.openzen.zenscript.codemodel.definition.ZSPackage;
11
+import org.openzen.zenscript.lexer.ParseException;
12
+
13
+import java.io.BufferedReader;
14
+import java.io.File;
15
+import java.io.FileNotFoundException;
16
+import java.io.FileReader;
17
+import java.util.ArrayList;
18
+import java.util.HashMap;
19
+import java.util.List;
20
+import java.util.Map;
21
+import java.util.stream.Collectors;
22
+
23
+public class FolderPackage {
24
+    
25
+    private Map<String, List<SourceFile>> files = new HashMap<>();
26
+    
27
+    public FolderPackage(File file) {
28
+        ArrayList<File> foundFiles = new ArrayList<>();
29
+        getFiles(file, foundFiles);
30
+    
31
+        String srcString = File.separator + "src" + File.separator;
32
+        foundFiles.stream().filter(fil -> (fil.getPath()+File.separator).substring(file.getPath().length()+ File.separator.length()).indexOf(srcString) > 0).forEach(fil -> {
33
+            String name = (fil.getPath() + File.separator).substring(file.getPath().length() + File.separator.length());
34
+            int slash = name.indexOf(srcString);
35
+            String moduleName = name.substring(0, slash);
36
+            String filename = name.substring(slash + srcString.length());
37
+            if(!files.containsKey(moduleName))
38
+                files.put(moduleName, new ArrayList<>());
39
+            
40
+            try {
41
+                if(!fil.isDirectory())
42
+                    files.get(moduleName).add(new LiteralSourceFile(filename, new BufferedReader(new FileReader(fil)).lines().collect(Collectors.joining("\n"))));
43
+                else
44
+                    files.get(moduleName).add(new LiteralSourceFile(filename, ""));
45
+            } catch(FileNotFoundException e) {
46
+                e.printStackTrace();
47
+            }
48
+            
49
+        });
50
+    }
51
+    
52
+    public void getFiles(File parent, List<File> files) {
53
+        if(parent.isDirectory()) {
54
+            for(File file : parent.listFiles()) {
55
+                if(file.isDirectory()) {
56
+                    getFiles(file, files);
57
+                }
58
+            }
59
+        }
60
+        files.add(parent);
61
+    }
62
+	
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));
65
+	}
66
+	
67
+	public SemanticModule loadModule(ModuleSpace space, String name, BracketExpressionParser bracketParser, SemanticModule[] dependencies, FunctionParameter[] scriptParameters, ZSPackage pkg) throws ParseException {
68
+		List<SourceFile> sourceFiles = files.get(name);
69
+		if (sourceFiles == null)
70
+			return null; // no such module
71
+		
72
+		Module scriptModule = new Module(name);
73
+		CompilingPackage scriptPackage = new CompilingPackage(pkg, scriptModule);
74
+		ParsedFile[] files = new ParsedFile[sourceFiles.size()];
75
+		for (int i = 0; i < files.length; i++)
76
+			files[i] = ParsedFile.parse(scriptPackage, bracketParser, sourceFiles.get(i));
77
+		
78
+		SemanticModule scripts = ParsedFile.compileSyntaxToSemantic(
79
+				dependencies,
80
+				scriptPackage,
81
+				files,
82
+				space,
83
+				scriptParameters, Throwable::printStackTrace);
84
+		return scripts.normalize();
85
+	}
86
+}

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

14
 import org.openzen.zenscript.codemodel.member.FunctionalMember;
14
 import org.openzen.zenscript.codemodel.member.FunctionalMember;
15
 import org.openzen.zenscript.codemodel.scope.TypeScope;
15
 import org.openzen.zenscript.codemodel.scope.TypeScope;
16
 import org.openzen.zenscript.codemodel.type.StoredType;
16
 import org.openzen.zenscript.codemodel.type.StoredType;
17
+import org.openzen.zenscript.codemodel.type.member.BuiltinID;
17
 import org.openzen.zenscript.parser.ParsedAnnotation;
18
 import org.openzen.zenscript.parser.ParsedAnnotation;
18
 import org.openzen.zenscript.parser.definitions.ParsedFunctionHeader;
19
 import org.openzen.zenscript.parser.definitions.ParsedFunctionHeader;
19
 import org.openzen.zenscript.parser.statements.ParsedFunctionBody;
20
 import org.openzen.zenscript.parser.statements.ParsedFunctionBody;
34
 
35
 
35
 	@Override
36
 	@Override
36
 	public void linkTypes(TypeResolutionContext context) {
37
 	public void linkTypes(TypeResolutionContext context) {
37
-		compiled = new ConstructorMember(position, definition, modifiers, header.compile(context), null);
38
+        compiled = new ConstructorMember(position, definition, modifiers, header.compile(context), header.parameters.isEmpty() ? BuiltinID.CLASS_DEFAULT_CONSTRUCTOR : null);
38
 	}
39
 	}
39
 
40
 
40
 	@Override
41
 	@Override

Loading…
Cancel
Save