Browse Source

[WIP] Compile default values in functions

kindlich 5 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
  */
5
  */
6
 package org.openzen.zenscript.codemodel.scope;
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
 import org.openzen.zencode.shared.CodePosition;
8
 import org.openzen.zencode.shared.CodePosition;
12
 import org.openzen.zencode.shared.CompileException;
9
 import org.openzen.zencode.shared.CompileException;
13
 import org.openzen.zencode.shared.CompileExceptionCode;
10
 import org.openzen.zencode.shared.CompileExceptionCode;
14
-import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
15
 import org.openzen.zenscript.codemodel.FunctionHeader;
11
 import org.openzen.zenscript.codemodel.FunctionHeader;
16
 import org.openzen.zenscript.codemodel.GenericMapper;
12
 import org.openzen.zenscript.codemodel.GenericMapper;
13
+import org.openzen.zenscript.codemodel.GenericName;
14
+import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
17
 import org.openzen.zenscript.codemodel.context.TypeResolutionContext;
15
 import org.openzen.zenscript.codemodel.context.TypeResolutionContext;
18
 import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
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
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
19
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
20
 import org.openzen.zenscript.codemodel.partial.PartialGlobalExpression;
20
 import org.openzen.zenscript.codemodel.partial.PartialGlobalExpression;
21
 import org.openzen.zenscript.codemodel.partial.PartialTypeExpression;
21
 import org.openzen.zenscript.codemodel.partial.PartialTypeExpression;
22
 import org.openzen.zenscript.codemodel.statement.LoopStatement;
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
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
23
 import org.openzen.zenscript.codemodel.type.BasicTypeID;
27
 import org.openzen.zenscript.codemodel.type.ISymbol;
24
 import org.openzen.zenscript.codemodel.type.ISymbol;
28
 import org.openzen.zenscript.codemodel.type.StoredType;
25
 import org.openzen.zenscript.codemodel.type.StoredType;
32
 import org.openzen.zenscript.codemodel.type.storage.StaticExpressionStorageTag;
29
 import org.openzen.zenscript.codemodel.type.storage.StaticExpressionStorageTag;
33
 import org.openzen.zenscript.codemodel.type.storage.StorageTag;
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
  * @author Hoofdgebruiker
38
  * @author Hoofdgebruiker
42
 	private final LocalMemberCache memberCache;
43
 	private final LocalMemberCache memberCache;
43
 	private final Map<String, ISymbol> globals;
44
 	private final Map<String, ISymbol> globals;
44
 	private final TypeMemberPreparer preparer;
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
 	public FileScope(
55
 	public FileScope(
47
 			TypeResolutionContext context,
56
 			TypeResolutionContext context,
48
 			List<ExpansionDefinition> expansions,
57
 			List<ExpansionDefinition> expansions,

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

7
 import org.openzen.zenscript.codemodel.expression.InvalidExpression;
7
 import org.openzen.zenscript.codemodel.expression.InvalidExpression;
8
 import org.openzen.zenscript.codemodel.scope.BaseScope;
8
 import org.openzen.zenscript.codemodel.scope.BaseScope;
9
 import org.openzen.zenscript.codemodel.scope.ExpressionScope;
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
 import org.openzen.zenscript.codemodel.type.StoredType;
12
 import org.openzen.zenscript.codemodel.type.StoredType;
11
 import org.openzen.zenscript.parser.ParsedAnnotation;
13
 import org.openzen.zenscript.parser.ParsedAnnotation;
12
 import org.openzen.zenscript.parser.PrecompilationState;
14
 import org.openzen.zenscript.parser.PrecompilationState;
13
 import org.openzen.zenscript.parser.expression.ParsedExpression;
15
 import org.openzen.zenscript.parser.expression.ParsedExpression;
14
 import org.openzen.zenscript.parser.type.IParsedType;
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
  * @author Stanneke
24
  * @author Stanneke
23
 	public final IParsedType type;
29
 	public final IParsedType type;
24
 	public final ParsedExpression defaultValue;
30
 	public final ParsedExpression defaultValue;
25
 	public final boolean variadic;
31
 	public final boolean variadic;
26
-	
32
+
27
 	private FunctionParameter compiled;
33
 	private FunctionParameter compiled;
28
-	
34
+
29
 	public ParsedFunctionParameter(ParsedAnnotation[] annotations, String name, IParsedType type, ParsedExpression defaultValue, boolean variadic) {
35
 	public ParsedFunctionParameter(ParsedAnnotation[] annotations, String name, IParsedType type, ParsedExpression defaultValue, boolean variadic) {
30
 		this.annotations = annotations;
36
 		this.annotations = annotations;
31
 		this.name = name;
37
 		this.name = name;
33
 		this.defaultValue = defaultValue;
39
 		this.defaultValue = defaultValue;
34
 		this.variadic = variadic;
40
 		this.variadic = variadic;
35
 	}
41
 	}
36
-	
42
+
37
 	public FunctionParameter compile(TypeResolutionContext context) {
43
 	public FunctionParameter compile(TypeResolutionContext context) {
38
 		if (compiled != null)
44
 		if (compiled != null)
39
 			return compiled;
45
 			return compiled;
40
-		
46
+
41
 		StoredType cType = type.compile(context);
47
 		StoredType cType = type.compile(context);
42
 		Expression cDefaultValue = null;
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
 	// TODO: this isn't called!
56
 	// TODO: this isn't called!

Loading…
Cancel
Save