Browse Source

- Fixed $ not working in setters

- Fixed erratic StringBuilder class
- Updated shared with new live classes
Stan Hebben 6 years ago
parent
commit
4f0727d2f7

+ 4
- 2
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/SetterMember.java View File

31
 	public final String name;
31
 	public final String name;
32
 	private SetterMemberRef overrides;
32
 	private SetterMemberRef overrides;
33
 	public Statement body;
33
 	public Statement body;
34
-	public final FunctionParameter parameter;
34
+	public FunctionParameter parameter;
35
 	
35
 	
36
 	public SetterMember(
36
 	public SetterMember(
37
 			CodePosition position,
37
 			CodePosition position,
105
 	public void setOverrides(SetterMemberRef overrides) {
105
 	public void setOverrides(SetterMemberRef overrides) {
106
 		this.overrides = overrides;
106
 		this.overrides = overrides;
107
 		
107
 		
108
-		if (type.type == BasicTypeID.UNDETERMINED)
108
+		if (type.type == BasicTypeID.UNDETERMINED) {
109
 			type = overrides.getType();
109
 			type = overrides.getType();
110
+			parameter = new FunctionParameter(overrides.getType(), "value");
111
+		}
110
 	}
112
 	}
111
 
113
 
112
 	@Override
114
 	@Override

+ 9
- 2
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/FunctionScope.java View File

33
 	private final FunctionHeader header;
33
 	private final FunctionHeader header;
34
 	private final GenericMapper typeParameterMap;
34
 	private final GenericMapper typeParameterMap;
35
 	private final StoredType thisType;
35
 	private final StoredType thisType;
36
+	private final DollarEvaluator dollar;
36
 	
37
 	
37
 	public FunctionScope(BaseScope outer, FunctionHeader header) {
38
 	public FunctionScope(BaseScope outer, FunctionHeader header) {
39
+		this(outer, header, null);
40
+	}
41
+	
42
+	public FunctionScope(BaseScope outer, FunctionHeader header, DollarEvaluator dollar) {
38
 		this.outer = outer;
43
 		this.outer = outer;
39
 		this.header = header;
44
 		this.header = header;
40
 		this.thisType = outer.getThisType() == null || header.storage == null ? outer.getThisType() : outer.getThisType().type.stored(header.storage);
45
 		this.thisType = outer.getThisType() == null || header.storage == null ? outer.getThisType() : outer.getThisType().type.stored(header.storage);
46
+		this.dollar = dollar;
41
 		
47
 		
42
 		if (outer.getLocalTypeParameters() == null)
48
 		if (outer.getLocalTypeParameters() == null)
43
 			throw new NullPointerException();
49
 			throw new NullPointerException();
112
 
118
 
113
 	@Override
119
 	@Override
114
 	public DollarEvaluator getDollar() {
120
 	public DollarEvaluator getDollar() {
115
-		for (FunctionParameter parameter : header.parameters)
121
+		return dollar;
122
+		/*for (FunctionParameter parameter : header.parameters)
116
 			if (parameter.name.equals("$"))
123
 			if (parameter.name.equals("$"))
117
 				return position -> new GetFunctionParameterExpression(position, parameter);
124
 				return position -> new GetFunctionParameterExpression(position, parameter);
118
 		
125
 		
119
-		return null;
126
+		return null;*/
120
 	}
127
 	}
121
 	
128
 	
122
 	@Override
129
 	@Override

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

12
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
12
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
13
 import org.openzen.zenscript.codemodel.Modifiers;
13
 import org.openzen.zenscript.codemodel.Modifiers;
14
 import org.openzen.zenscript.codemodel.context.TypeResolutionContext;
14
 import org.openzen.zenscript.codemodel.context.TypeResolutionContext;
15
+import org.openzen.zenscript.codemodel.expression.GetFunctionParameterExpression;
15
 import org.openzen.zenscript.codemodel.member.SetterMember;
16
 import org.openzen.zenscript.codemodel.member.SetterMember;
16
 import org.openzen.zenscript.codemodel.scope.BaseScope;
17
 import org.openzen.zenscript.codemodel.scope.BaseScope;
17
 import org.openzen.zenscript.codemodel.scope.FunctionScope;
18
 import org.openzen.zenscript.codemodel.scope.FunctionScope;
95
 		inferHeaders(scope);
96
 		inferHeaders(scope);
96
 		
97
 		
97
 		FunctionHeader header = new FunctionHeader(compiled.type);
98
 		FunctionHeader header = new FunctionHeader(compiled.type);
98
-		FunctionScope innerScope = new FunctionScope(scope, header);
99
+		FunctionScope innerScope = new FunctionScope(
100
+				scope,
101
+				header,
102
+				position -> new GetFunctionParameterExpression(position, compiled.parameter));
99
 		compiled.annotations = ParsedAnnotation.compileForMember(annotations, getCompiled(), scope);
103
 		compiled.annotations = ParsedAnnotation.compileForMember(annotations, getCompiled(), scope);
100
 		compiled.setBody(body.compile(innerScope, header));
104
 		compiled.setBody(body.compile(innerScope, header));
101
 	}
105
 	}

+ 5
- 0
Shared/src/main/java/live/MutableLiveInt.java View File

1
+package live;
2
+
3
+public interface MutableLiveInt extends LiveInt {
4
+    void setValue(int value);
5
+}

+ 5
- 0
Shared/src/main/java/live/MutableLiveString.java View File

1
+package live;
2
+
3
+public interface MutableLiveString extends LiveString {
4
+    void setValue(String value);
5
+}

+ 33
- 0
Shared/src/main/java/live/SimpleLiveInt.java View File

1
+package live;
2
+
3
+import listeners.ListenerHandle;
4
+import listeners.ListenerList;
5
+import zsynthetic.FunctionIntIntToVoid;
6
+
7
+public final class SimpleLiveInt implements MutableLiveInt {
8
+    private final ListenerList<FunctionIntIntToVoid> listeners = new ListenerList<FunctionIntIntToVoid>();
9
+    private int value;
10
+    
11
+    public SimpleLiveInt(int value) {
12
+        this.value = value;
13
+    }
14
+    
15
+    @Override
16
+    public ListenerHandle<FunctionIntIntToVoid> addListener(FunctionIntIntToVoid listener) {
17
+        return listeners.add(listener);
18
+    }
19
+    
20
+    @Override
21
+    public void setValue(int value) {
22
+        if (value == this.value)
23
+            return;
24
+        int oldValue = this.value;
25
+        this.value = value;
26
+        listeners.accept(listener -> 
27
+        listener.invoke(oldValue, this.value));
28
+    }
29
+    
30
+    public int getValue() {
31
+        return value;
32
+    }
33
+}

+ 33
- 0
Shared/src/main/java/live/SimpleLiveString.java View File

1
+package live;
2
+
3
+import java.util.function.BiConsumer;
4
+import listeners.ListenerHandle;
5
+import listeners.ListenerList;
6
+
7
+public final class SimpleLiveString implements MutableLiveString {
8
+    private final ListenerList<BiConsumer<String, String>> listeners = new ListenerList<BiConsumer<String, String>>();
9
+    private String value;
10
+    
11
+    public SimpleLiveString(String value) {
12
+        this.value = value;
13
+    }
14
+    
15
+    @Override
16
+    public ListenerHandle<BiConsumer<String, String>> addListener(BiConsumer<String, String> listener) {
17
+        return listeners.add(listener);
18
+    }
19
+    
20
+    @Override
21
+    public void setValue(String value) {
22
+        if (value.equals(this.value))
23
+            return;
24
+        String oldValue = this.value;
25
+        this.value = value;
26
+        listeners.accept(listener -> 
27
+        listener.accept(oldValue, this.value));
28
+    }
29
+    
30
+    public String getValue() {
31
+        return value;
32
+    }
33
+}

+ 0
- 8
Shared/src/main/java/stdlib/StringBuilder.java View File

1
-package stdlib;
2
-
3
-public final class StringBuilder {
4
-    public static StringBuilder shl(StringBuilder self, StringBuildable value) {
5
-        value.toString(self);
6
-        return self;
7
-    }
8
-}

+ 30
- 0
Shared/src/main/java/stdlib/StringBuilderExpansion.java View File

1
+package stdlib;
2
+
3
+import java.util.function.Function;
4
+
5
+public final class StringBuilderExpansion {
6
+    public static StringBuilder shl(StringBuilder self, StringBuildable value) {
7
+        value.toString(self);
8
+        return self;
9
+    }
10
+    
11
+    public static <T extends StringBuildable> StringBuilder append(StringBuilder self, Class<T> typeOfT, T[] values, String separator) {
12
+        for (int i = 0; i < values.length; i++) {
13
+            T value = values[i];
14
+            if (i > 0)
15
+                self.append(separator);
16
+            value.toString(self);
17
+        }
18
+        return self;
19
+    }
20
+    
21
+    public static <T> StringBuilder append(StringBuilder self, Class<T> typeOfT, T[] values, Function<T, String> stringer, String separator) {
22
+        for (int i = 0; i < values.length; i++) {
23
+            T value = values[i];
24
+            if (i > 0)
25
+                self.append(separator);
26
+            self.append(stringer.apply(value));
27
+        }
28
+        return self;
29
+    }
30
+}

Loading…
Cancel
Save