Browse Source

[WIP] Compile default values in functions

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

+ 17
- 8
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/FileScope.java View File

@@ -5,24 +5,21 @@
5 5
  */
6 6
 package org.openzen.zenscript.codemodel.scope;
7 7
 
8
-import java.util.Collections;
9
-import java.util.List;
10
-import java.util.Map;
11 8
 import org.openzen.zencode.shared.CodePosition;
12 9
 import org.openzen.zencode.shared.CompileException;
13 10
 import org.openzen.zencode.shared.CompileExceptionCode;
14
-import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
15 11
 import org.openzen.zenscript.codemodel.FunctionHeader;
16 12
 import org.openzen.zenscript.codemodel.GenericMapper;
13
+import org.openzen.zenscript.codemodel.GenericName;
14
+import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
17 15
 import org.openzen.zenscript.codemodel.context.TypeResolutionContext;
18 16
 import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
17
+import org.openzen.zenscript.codemodel.definition.ZSPackage;
18
+import org.openzen.zenscript.codemodel.expression.InvalidExpression;
19 19
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
20 20
 import org.openzen.zenscript.codemodel.partial.PartialGlobalExpression;
21 21
 import org.openzen.zenscript.codemodel.partial.PartialTypeExpression;
22 22
 import org.openzen.zenscript.codemodel.statement.LoopStatement;
23
-import org.openzen.zenscript.codemodel.GenericName;
24
-import org.openzen.zenscript.codemodel.definition.ZSPackage;
25
-import org.openzen.zenscript.codemodel.expression.InvalidExpression;
26 23
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
27 24
 import org.openzen.zenscript.codemodel.type.ISymbol;
28 25
 import org.openzen.zenscript.codemodel.type.StoredType;
@@ -32,6 +29,10 @@ import org.openzen.zenscript.codemodel.type.member.TypeMemberPreparer;
32 29
 import org.openzen.zenscript.codemodel.type.storage.StaticExpressionStorageTag;
33 30
 import org.openzen.zenscript.codemodel.type.storage.StorageTag;
34 31
 
32
+import java.util.Collections;
33
+import java.util.List;
34
+import java.util.Map;
35
+
35 36
 /**
36 37
  *
37 38
  * @author Hoofdgebruiker
@@ -42,7 +43,15 @@ public class FileScope extends BaseScope {
42 43
 	private final LocalMemberCache memberCache;
43 44
 	private final Map<String, ISymbol> globals;
44 45
 	private final TypeMemberPreparer preparer;
45
-	
46
+
47
+	public FileScope(
48
+			TypeResolutionContext context,
49
+			List<ExpansionDefinition> expansions,
50
+			Map<String, ISymbol> globals) {
51
+		this(context, expansions, globals, member -> {
52
+		});
53
+	}
54
+
46 55
 	public FileScope(
47 56
 			TypeResolutionContext context,
48 57
 			List<ExpansionDefinition> expansions,

+ 15
- 5
Parser/src/main/java/org/openzen/zenscript/parser/definitions/ParsedFunctionParameter.java View File

@@ -7,12 +7,18 @@ import org.openzen.zenscript.codemodel.expression.Expression;
7 7
 import org.openzen.zenscript.codemodel.expression.InvalidExpression;
8 8
 import org.openzen.zenscript.codemodel.scope.BaseScope;
9 9
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
10
+import org.openzen.zenscript.codemodel.scope.FileScope;
11
+import org.openzen.zenscript.codemodel.type.BasicTypeID;
10 12
 import org.openzen.zenscript.codemodel.type.StoredType;
11 13
 import org.openzen.zenscript.parser.ParsedAnnotation;
12 14
 import org.openzen.zenscript.parser.PrecompilationState;
13 15
 import org.openzen.zenscript.parser.expression.ParsedExpression;
14 16
 import org.openzen.zenscript.parser.type.IParsedType;
15 17
 
18
+import java.util.ArrayList;
19
+import java.util.Collections;
20
+import java.util.HashMap;
21
+
16 22
 /**
17 23
  *
18 24
  * @author Stanneke
@@ -23,9 +29,9 @@ public class ParsedFunctionParameter {
23 29
 	public final IParsedType type;
24 30
 	public final ParsedExpression defaultValue;
25 31
 	public final boolean variadic;
26
-	
32
+
27 33
 	private FunctionParameter compiled;
28
-	
34
+
29 35
 	public ParsedFunctionParameter(ParsedAnnotation[] annotations, String name, IParsedType type, ParsedExpression defaultValue, boolean variadic) {
30 36
 		this.annotations = annotations;
31 37
 		this.name = name;
@@ -33,14 +39,18 @@ public class ParsedFunctionParameter {
33 39
 		this.defaultValue = defaultValue;
34 40
 		this.variadic = variadic;
35 41
 	}
36
-	
42
+
37 43
 	public FunctionParameter compile(TypeResolutionContext context) {
38 44
 		if (compiled != null)
39 45
 			return compiled;
40
-		
46
+
41 47
 		StoredType cType = type.compile(context);
42 48
 		Expression cDefaultValue = null;
43
-		return compiled = new FunctionParameter(cType, name, null, variadic);
49
+
50
+
51
+		this.compiled = new FunctionParameter(cType, name, null, variadic);
52
+		compileInitializer(new FileScope(context, Collections.emptyList(), Collections.emptyMap()), new PrecompilationState());
53
+		return compiled;
44 54
 	}
45 55
 
46 56
 	// TODO: this isn't called!

Loading…
Cancel
Save