ソースを参照

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

kindlich 5年前
コミット
ee59ddba30
この署名に対応する既知のキーがデータベースに存在しません

JavaIntegration/src/main/resources/StdLibs.zip → JavaIntegration/StdLibs.jar ファイルの表示


+ 4
- 3
JavaIntegration/src/main/java/org/openzen/zencode/java/ScriptingEngine.java ファイルの表示

@@ -43,11 +43,12 @@ public class ScriptingEngine {
43 43
 		space = new ModuleSpace(registry, new ArrayList<>(), StorageType.getStandard());
44 44
 		
45 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 48
 			stdlibModule = Validator.validate(stdlibModule, error -> System.out.println(error.toString()));
49 49
 			space.addModule("stdlib", stdlibModule);
50
-		} catch (IOException | CompileException | ParseException ex) {
50
+			registerCompiled(stdlibModule);
51
+		} catch (CompileException | ParseException | IOException ex) {
51 52
 			throw new RuntimeException(ex);
52 53
 		}
53 54
 		this.logger = new EmptyLogger();

+ 5
- 4
JavaShared/src/main/java/org/openzen/zenscript/javashared/prepare/JavaPrepareDefinitionVisitor.java ファイルの表示

@@ -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,8 +29,13 @@ 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

+ 86
- 0
Parser/src/main/java/org/openzen/zenscript/parser/FolderPackage.java ファイルの表示

@@ -0,0 +1,86 @@
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 ファイルの表示

@@ -14,6 +14,7 @@ import org.openzen.zenscript.codemodel.member.ConstructorMember;
14 14
 import org.openzen.zenscript.codemodel.member.FunctionalMember;
15 15
 import org.openzen.zenscript.codemodel.scope.TypeScope;
16 16
 import org.openzen.zenscript.codemodel.type.StoredType;
17
+import org.openzen.zenscript.codemodel.type.member.BuiltinID;
17 18
 import org.openzen.zenscript.parser.ParsedAnnotation;
18 19
 import org.openzen.zenscript.parser.definitions.ParsedFunctionHeader;
19 20
 import org.openzen.zenscript.parser.statements.ParsedFunctionBody;
@@ -34,7 +35,7 @@ public class ParsedConstructor extends ParsedFunctionalMember {
34 35
 
35 36
 	@Override
36 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 41
 	@Override

読み込み中…
キャンセル
保存