Selaa lähdekoodia

- Fixed $ not working in setters

- Fixed erratic StringBuilder class
- Updated shared with new live classes
Stan Hebben 6 vuotta sitten
vanhempi
commit
4f0727d2f7

+ 4
- 2
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/SetterMember.java Näytä tiedosto

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

+ 9
- 2
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/FunctionScope.java Näytä tiedosto

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

+ 5
- 1
Parser/src/main/java/org/openzen/zenscript/parser/member/ParsedSetter.java Näytä tiedosto

@@ -12,6 +12,7 @@ import org.openzen.zenscript.codemodel.FunctionHeader;
12 12
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
13 13
 import org.openzen.zenscript.codemodel.Modifiers;
14 14
 import org.openzen.zenscript.codemodel.context.TypeResolutionContext;
15
+import org.openzen.zenscript.codemodel.expression.GetFunctionParameterExpression;
15 16
 import org.openzen.zenscript.codemodel.member.SetterMember;
16 17
 import org.openzen.zenscript.codemodel.scope.BaseScope;
17 18
 import org.openzen.zenscript.codemodel.scope.FunctionScope;
@@ -95,7 +96,10 @@ public class ParsedSetter extends ParsedDefinitionMember {
95 96
 		inferHeaders(scope);
96 97
 		
97 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 103
 		compiled.annotations = ParsedAnnotation.compileForMember(annotations, getCompiled(), scope);
100 104
 		compiled.setBody(body.compile(innerScope, header));
101 105
 	}

+ 5
- 0
Shared/src/main/java/live/MutableLiveInt.java Näytä tiedosto

@@ -0,0 +1,5 @@
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 Näytä tiedosto

@@ -0,0 +1,5 @@
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 Näytä tiedosto

@@ -0,0 +1,33 @@
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 Näytä tiedosto

@@ -0,0 +1,33 @@
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 Näytä tiedosto

@@ -1,8 +0,0 @@
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 Näytä tiedosto

@@ -0,0 +1,30 @@
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…
Peruuta
Tallenna