Explorar el Código

Regeneration of shared (with manual fixes)

Stan Hebben hace 6 años
padre
commit
f943f53cca

+ 10
- 10
Shared/src/main/java/compactio/CompactBytesDataInput.java Ver fichero

@@ -39,17 +39,17 @@ public final class CompactBytesDataInput implements CompactDataInput, AutoClosea
39 39
     
40 40
     @Override
41 41
     public boolean readBool() {
42
-        return this.readByte() != (byte)0;
42
+        return (this.readByte() & 0xFF) != (0 & 0xFF);
43 43
     }
44 44
     
45 45
     @Override
46 46
     public int readByte() {
47
-        return (data[offset++]) & 0xFF;
47
+        return data[offset++];
48 48
     }
49 49
     
50 50
     @Override
51 51
     public byte readSByte() {
52
-        return data[offset++];
52
+        return (byte)(data[offset++]);
53 53
     }
54 54
     
55 55
     @Override
@@ -190,19 +190,19 @@ public final class CompactBytesDataInput implements CompactDataInput, AutoClosea
190 190
             int bvalue = this.readByte();
191 191
             int remainingBits = result.length - 8 * i;
192 192
             if (remainingBits > 0)
193
-                result[i * 8 + 0] = (bvalue & (byte)1) > (byte)0;
193
+                result[i * 8 + 0] = ((bvalue & 1) & 0xFF) > (0 & 0xFF);
194 194
             if (remainingBits > 1)
195
-                result[i * 8 + 2] = (bvalue & (byte)4) > (byte)0;
195
+                result[i * 8 + 2] = ((bvalue & 4) & 0xFF) > (0 & 0xFF);
196 196
             if (remainingBits > 3)
197
-                result[i * 8 + 3] = (bvalue & (byte)8) > (byte)0;
197
+                result[i * 8 + 3] = ((bvalue & 8) & 0xFF) > (0 & 0xFF);
198 198
             if (remainingBits > 4)
199
-                result[i * 8 + 4] = (bvalue & (byte)16) > (byte)0;
199
+                result[i * 8 + 4] = ((bvalue & 16) & 0xFF) > (0 & 0xFF);
200 200
             if (remainingBits > 5)
201
-                result[i * 8 + 5] = (bvalue & (byte)32) > (byte)0;
201
+                result[i * 8 + 5] = ((bvalue & 32) & 0xFF) > (0 & 0xFF);
202 202
             if (remainingBits > 6)
203
-                result[i * 8 + 6] = (bvalue & (byte)64) > (byte)0;
203
+                result[i * 8 + 6] = ((bvalue & 64) & 0xFF) > (0 & 0xFF);
204 204
             if (remainingBits > 7)
205
-                result[i * 8 + 7] = (bvalue & (byte)-128) > (byte)0;
205
+                result[i * 8 + 7] = ((bvalue & 128) & 0xFF) > (0 & 0xFF);
206 206
         }
207 207
         return result;
208 208
     }

+ 3
- 3
Shared/src/main/java/listeners/ListenerList.java Ver fichero

@@ -1,6 +1,6 @@
1 1
 package listeners;
2 2
 
3
-import zsynthetic.FunctionTToVoid;
3
+import java.util.function.Consumer;
4 4
 
5 5
 public final class ListenerList<T> {
6 6
     public static final int PRIORITY_HIGH = 100;
@@ -43,10 +43,10 @@ public final class ListenerList<T> {
43 43
         this.first = this.last = null;
44 44
     }
45 45
     
46
-    public void accept(FunctionTToVoid<T> consumer) {
46
+    public void accept(Consumer<T> consumer) {
47 47
         ListenerList<T>.EventListenerNode current = first;
48 48
         while (current != null) {
49
-            consumer.invoke(current.getListener());
49
+            consumer.accept(current.getListener());
50 50
             current = current.next;
51 51
         }
52 52
     }

+ 3
- 3
Shared/src/main/java/live/ImmutableLiveObject.java Ver fichero

@@ -1,8 +1,8 @@
1 1
 package live;
2 2
 
3
+import java.util.function.BiConsumer;
3 4
 import listeners.DummyListenerHandle;
4 5
 import listeners.ListenerHandle;
5
-import zsynthetic.FunctionTTToVoid;
6 6
 
7 7
 public final class ImmutableLiveObject<T> implements LiveObject<T> {
8 8
     public final T value;
@@ -12,8 +12,8 @@ public final class ImmutableLiveObject<T> implements LiveObject<T> {
12 12
     }
13 13
     
14 14
     @Override
15
-    public ListenerHandle<FunctionTTToVoid<T>> addListener(FunctionTTToVoid<T> listener) {
16
-        return new DummyListenerHandle<FunctionTTToVoid<T>>(listener);
15
+    public ListenerHandle<BiConsumer<T, T>> addListener(BiConsumer<T, T> listener) {
16
+        return new DummyListenerHandle<BiConsumer<T, T>>(listener);
17 17
     }
18 18
     
19 19
     public T getValue() {

+ 3
- 3
Shared/src/main/java/live/ImmutableLiveString.java Ver fichero

@@ -1,8 +1,8 @@
1 1
 package live;
2 2
 
3
+import java.util.function.BiConsumer;
3 4
 import listeners.DummyListenerHandle;
4 5
 import listeners.ListenerHandle;
5
-import zsynthetic.FunctionStringStringToVoid;
6 6
 
7 7
 public final class ImmutableLiveString implements LiveString {
8 8
     public final String value;
@@ -12,8 +12,8 @@ public final class ImmutableLiveString implements LiveString {
12 12
     }
13 13
     
14 14
     @Override
15
-    public ListenerHandle<FunctionStringStringToVoid> addListener(FunctionStringStringToVoid listener) {
16
-        return new DummyListenerHandle<FunctionStringStringToVoid>(listener);
15
+    public ListenerHandle<BiConsumer<String, String>> addListener(BiConsumer<String, String> listener) {
16
+        return new DummyListenerHandle<BiConsumer<String, String>>(listener);
17 17
     }
18 18
     
19 19
     public String getValue() {

+ 2
- 2
Shared/src/main/java/live/LiveObject.java Ver fichero

@@ -1,10 +1,10 @@
1 1
 package live;
2 2
 
3
+import java.util.function.BiConsumer;
3 4
 import listeners.ListenerHandle;
4
-import zsynthetic.FunctionTTToVoid;
5 5
 
6 6
 public interface LiveObject<T> {
7 7
     T getValue();
8 8
     
9
-    ListenerHandle<FunctionTTToVoid<T>> addListener(FunctionTTToVoid<T> listener);
9
+    ListenerHandle<BiConsumer<T, T>> addListener(BiConsumer<T, T> listener);
10 10
 }

+ 2
- 2
Shared/src/main/java/live/LiveString.java Ver fichero

@@ -1,10 +1,10 @@
1 1
 package live;
2 2
 
3
+import java.util.function.BiConsumer;
3 4
 import listeners.ListenerHandle;
4
-import zsynthetic.FunctionStringStringToVoid;
5 5
 
6 6
 public interface LiveString {
7 7
     String getValue();
8 8
     
9
-    ListenerHandle<FunctionStringStringToVoid> addListener(FunctionStringStringToVoid listener);
9
+    ListenerHandle<BiConsumer<String, String>> addListener(BiConsumer<String, String> listener);
10 10
 }

+ 1
- 2
Shared/src/main/java/org/openzen/zencode/shared/CodePosition.java Ver fichero

@@ -3,9 +3,8 @@ package org.openzen.zencode.shared;
3 3
 public final class CodePosition {
4 4
     public static final CodePosition BUILTIN = new CodePosition(new VirtualSourceFile("builtin"), 0, 0, 0, 0);
5 5
     public static final CodePosition NATIVE = new CodePosition(new VirtualSourceFile("native"), 0, 0, 0, 0);
6
-	public static final CodePosition META = new CodePosition(new VirtualSourceFile("meta"), 0, 0, 0, 0);
6
+    public static final CodePosition META = new CodePosition(new VirtualSourceFile("meta"), 0, 0, 0, 0);
7 7
 	public static final CodePosition UNKNOWN = new CodePosition(new VirtualSourceFile("unknown"), 0, 0, 0, 0);
8
-	
9 8
     public final SourceFile file;
10 9
     public final int fromLine;
11 10
     public final int fromLineOffset;

+ 1
- 8
Shared/src/main/java/org/openzen/zencode/shared/CompileExceptionCode.java Ver fichero

@@ -69,12 +69,5 @@ public enum CompileExceptionCode {
69 69
 	VARIANT_OPTION_NOT_AN_EXPRESSION,
70 70
 	DUPLICATE_GLOBAL,
71 71
 	CANNOT_INFER_RETURN_TYPE,
72
-	INVALID_SUFFIX,
73
-	NO_SUCH_MODULE,
74
-	
75
-	NO_SUCH_STORAGE_TYPE,
76
-	INVALID_STORAGE_TYPE_ARGUMENTS,
77
-	STORAGE_NOT_SUPPORTED,
78
-	INCOMPATIBLE_STORAGE_TAG,
79
-	INVALID_TYPE_ARGUMENTS
72
+	INVALID_SUFFIX
80 73
 }

+ 2
- 2
Shared/src/main/java/org/openzen/zencode/shared/StringExpansion.java Ver fichero

@@ -32,7 +32,7 @@ public final class StringExpansion {
32 32
 	public static Result<String, String> unescape(String self) {
33 33
 	    if (!(self.charAt(0) == self.charAt(self.length() - 1)))
34 34
 	        throw new AssertionError("Unbalanced quotes");
35
-	    if (!(self.charAt(0) == '@' && ArrayHelpers.contains(new String[] {"\"", "'"}, Character.toString(self.charAt(1))) || ArrayHelpers.contains(new String[] {"\"", "'"}, Character.toString(self.charAt(0)))))
35
+	    if (!(self.charAt(0) == '@' && ArrayHelpers.contains(new char[] {'"', '\''}, self.charAt(1)) || ArrayHelpers.contains(new char[] {'"', '\''}, self.charAt(0))))
36 36
 	        throw new AssertionError("String is not quoted");
37 37
 	    if (!(self.length() >= 2))
38 38
 	        throw new AssertionError("String is not quoted");
@@ -109,7 +109,7 @@ public final class StringExpansion {
109 109
 	                        return new Result.Error<>(((Result.Error<Integer, String>)temp5).value);
110 110
 	                    int hex3 = ((Result.Ok<Integer, String>)temp5).value;
111 111
 	                    i = i + 5;
112
-	                    result.append((char)hex0 << 12 | hex1 << 8 | hex2 << 4 | hex3);
112
+	                    result.append((char)(hex0 << 12 | hex1 << 8 | hex2 << 4 | hex3));
113 113
 	                    break;
114 114
 	                default:
115 115
 	                    return new Error("Illegal escape sequence");

+ 22
- 22
Shared/src/main/java/stdlib/Arrays.java Ver fichero

@@ -5,9 +5,9 @@ import java.util.ArrayList;
5 5
 import java.util.HashMap;
6 6
 import java.util.List;
7 7
 import java.util.Map;
8
-import zsynthetic.FunctionTToBool;
9
-import zsynthetic.FunctionTToU;
10
-import zsynthetic.FunctionTToVoid;
8
+import java.util.function.Consumer;
9
+import java.util.function.Function;
10
+import java.util.function.Predicate;
11 11
 import zsynthetic.FunctionUSizeTToBool;
12 12
 import zsynthetic.FunctionUSizeTToU;
13 13
 import zsynthetic.FunctionUSizeTToVoid;
@@ -31,24 +31,24 @@ public final class Arrays {
31 31
         }
32 32
     }
33 33
     
34
-    public static <U, T> U[] map(Class<T> typeOfT, T[] self, Class<U> typeOfU, FunctionTToU<U, T> projection) {
34
+    public static <U, T> U[] map(Class<T> typeOfT, T[] self, Class<U> typeOfU, Function<T, U> projection) {
35 35
         U[] temp1 = (U[])(Array.newInstance(typeOfU, self.length));
36 36
         for (int temp2 = 0; temp2 < temp1.length; temp2++)
37
-            temp1[temp2] = projection.invoke(self[temp2]);
37
+            temp1[temp2] = projection.apply(self[temp2]);
38 38
         return temp1;
39 39
     }
40 40
     
41
-    public static <U, T> U[] map(Class<T> typeOfT, T[] self, Class<U> typeOfU, FunctionUSizeTToU<U, T> projection) {
41
+    public static <U, T> U[] map(Class<T> typeOfT, T[] self, Class<U> typeOfU, FunctionUSizeTToU<T, U> projection) {
42 42
         U[] temp1 = (U[])(Array.newInstance(typeOfU, self.length));
43 43
         for (int temp2 = 0; temp2 < temp1.length; temp2++)
44 44
             temp1[temp2] = projection.invoke(temp2, self[temp2]);
45 45
         return temp1;
46 46
     }
47 47
     
48
-    public static <T> T[] filter(Class<T> typeOfT, T[] self, FunctionTToBool<T> predicate) {
48
+    public static <T> T[] filter(Class<T> typeOfT, T[] self, Predicate<T> predicate) {
49 49
         List<T> values = new ArrayList<T>();
50 50
         for (T value : self)
51
-            if (predicate.invoke(value))
51
+            if (predicate.test(value))
52 52
                 values.add(value);
53 53
         return values.toArray((T[])(Array.newInstance(typeOfT, values.size())));
54 54
     }
@@ -63,9 +63,9 @@ public final class Arrays {
63 63
         return values.toArray((T[])(Array.newInstance(typeOfT, values.size())));
64 64
     }
65 65
     
66
-    public static <T> void each(Class<T> typeOfT, T[] self, FunctionTToVoid<T> consumer) {
66
+    public static <T> void each(Class<T> typeOfT, T[] self, Consumer<T> consumer) {
67 67
         for (T value : self)
68
-            consumer.invoke(value);
68
+            consumer.accept(value);
69 69
     }
70 70
     
71 71
     public static <T> void each(Class<T> typeOfT, T[] self, FunctionUSizeTToVoid<T> consumer) {
@@ -75,9 +75,9 @@ public final class Arrays {
75 75
         }
76 76
     }
77 77
     
78
-    public static <T> boolean contains(Class<T> typeOfT, T[] self, FunctionTToBool<T> predicate) {
78
+    public static <T> boolean contains(Class<T> typeOfT, T[] self, Predicate<T> predicate) {
79 79
         for (T value : self)
80
-            if (predicate.invoke(value))
80
+            if (predicate.test(value))
81 81
                 return true;
82 82
         return false;
83 83
     }
@@ -91,9 +91,9 @@ public final class Arrays {
91 91
         return false;
92 92
     }
93 93
     
94
-    public static <T> boolean all(Class<T> typeOfT, T[] self, FunctionTToBool<T> predicate) {
94
+    public static <T> boolean all(Class<T> typeOfT, T[] self, Predicate<T> predicate) {
95 95
         for (T value : self)
96
-            if (!predicate.invoke(value))
96
+            if (!predicate.test(value))
97 97
                 return false;
98 98
         return true;
99 99
     }
@@ -107,9 +107,9 @@ public final class Arrays {
107 107
         return true;
108 108
     }
109 109
     
110
-    public static <T> T first(Class<T> typeOfT, T[] self, FunctionTToBool<T> predicate) {
110
+    public static <T> T first(Class<T> typeOfT, T[] self, Predicate<T> predicate) {
111 111
         for (T value : self)
112
-            if (predicate.invoke(value))
112
+            if (predicate.test(value))
113 113
                 return value;
114 114
         return null;
115 115
     }
@@ -123,11 +123,11 @@ public final class Arrays {
123 123
         return null;
124 124
     }
125 125
     
126
-    public static <T> T last(Class<T> typeOfT, T[] self, FunctionTToBool<T> predicate) {
126
+    public static <T> T last(Class<T> typeOfT, T[] self, Predicate<T> predicate) {
127 127
         int i = self.length;
128 128
         while (i > 0) {
129 129
             i--;
130
-            if (predicate.invoke(self[i]))
130
+            if (predicate.test(self[i]))
131 131
                 return self[i];
132 132
         }
133 133
         return null;
@@ -143,10 +143,10 @@ public final class Arrays {
143 143
         return null;
144 144
     }
145 145
     
146
-    public static <T> int count(Class<T> typeOfT, T[] self, FunctionTToBool<T> predicate) {
146
+    public static <T> int count(Class<T> typeOfT, T[] self, Predicate<T> predicate) {
147 147
         int result = 0;
148 148
         for (T value : self)
149
-            if (predicate.invoke(value))
149
+            if (predicate.test(value))
150 150
                 result++;
151 151
         return result;
152 152
     }
@@ -161,10 +161,10 @@ public final class Arrays {
161 161
         return result;
162 162
     }
163 163
     
164
-    public static <K, T> Map<K, T> index(Class<T> typeOfT, T[] self, Class<K> typeOfK, FunctionTToU<K, T> key) {
164
+    public static <K, T> Map<K, T> index(Class<T> typeOfT, T[] self, Class<K> typeOfK, Function<T, K> key) {
165 165
         Map<K, T> result = new HashMap<>();
166 166
         for (T value : self)
167
-            result.put(key.invoke(value), value);
167
+            result.put(key.apply(value), value);
168 168
         return result;
169 169
     }
170 170
 }

+ 3
- 3
Shared/src/main/java/stdlib/Assoc.java Ver fichero

@@ -2,16 +2,16 @@ package stdlib;
2 2
 
3 3
 import java.util.HashMap;
4 4
 import java.util.Map;
5
-import zsynthetic.FunctionTToU;
5
+import java.util.function.Function;
6 6
 
7 7
 public final class Assoc {
8 8
     private Assoc() {}
9
-	static <W, K, V> Map<K, W> mapValues(Class<K> typeOfK, Class<V> typeOfV, Map<K, V> self, Class<W> typeOfW, FunctionTToU<W, V> projection) {
9
+	static <W, K, V> Map<K, W> mapValues(Class<K> typeOfK, Class<V> typeOfV, Map<K, V> self, Class<W> typeOfW, Function<V, W> projection) {
10 10
 	    Map<K, W> result = new HashMap<>();
11 11
 	    for (Map.Entry<K, V> temp1 : self.entrySet()) {
12 12
 	        K k = temp1.getKey();
13 13
 	        V v = temp1.getValue();
14
-	        result.put(k, projection.invoke(v));
14
+	        result.put(k, projection.apply(v));
15 15
 	    }
16 16
 	    return result;
17 17
 	}

+ 5
- 0
Shared/src/main/java/stdlib/Integers.java Ver fichero

@@ -0,0 +1,5 @@
1
+package stdlib;
2
+
3
+final class Integers {
4
+    private Integers() {}
5
+}

+ 7
- 8
Shared/src/main/java/stdlib/Result.java Ver fichero

@@ -1,15 +1,14 @@
1 1
 package stdlib;
2 2
 
3
-import zsynthetic.FunctionTToResultWithUV;
4
-import zsynthetic.FunctionTToU;
3
+import java.util.function.Function;
5 4
 
6 5
 public abstract class Result<T, E> {
7
-    public <R> Result<R, E> then(Class<R> typeOfR, FunctionTToResultWithUV<R, E, T> fn) {
6
+    public <R> Result<R, E> then(Class<R> typeOfR, Function<T, Result<R, E>> fn) {
8 7
         Result<R, E> temp1;
9 8
         switch (this.getDiscriminant()) {
10 9
             case Ok:
11 10
                 T result = ((Result.Ok<T, E>)this).value;
12
-                temp1 = fn.invoke(result);
11
+                temp1 = fn.apply(result);
13 12
                 break;
14 13
             case Error:
15 14
                 E error = ((Result.Error<T, E>)this).value;
@@ -21,7 +20,7 @@ public abstract class Result<T, E> {
21 20
         return temp1;
22 21
     }
23 22
     
24
-    public <X> Result<T, X> handle(Class<X> typeOfX, FunctionTToResultWithUV<T, X, E> handler) {
23
+    public <X> Result<T, X> handle(Class<X> typeOfX, Function<E, Result<T, X>> handler) {
25 24
         Result<T, X> temp1;
26 25
         switch (this.getDiscriminant()) {
27 26
             case Ok:
@@ -30,7 +29,7 @@ public abstract class Result<T, E> {
30 29
                 break;
31 30
             case Error:
32 31
                 E error = ((Result.Error<T, E>)this).value;
33
-                temp1 = handler.invoke(error);
32
+                temp1 = handler.apply(error);
34 33
                 break;
35 34
             default:
36 35
                 throw new AssertionError("Missing case");
@@ -71,7 +70,7 @@ public abstract class Result<T, E> {
71 70
         return temp1;
72 71
     }
73 72
     
74
-    public T orElse(FunctionTToU<T, E> other) {
73
+    public T orElse(Function<E, T> other) {
75 74
         T temp1;
76 75
         switch (this.getDiscriminant()) {
77 76
             case Ok:
@@ -80,7 +79,7 @@ public abstract class Result<T, E> {
80 79
                 break;
81 80
             case Error:
82 81
                 E error = ((Result.Error<T, E>)this).value;
83
-                temp1 = other.invoke(error);
82
+                temp1 = other.apply(error);
84 83
                 break;
85 84
             default:
86 85
                 throw new AssertionError("Missing case");

+ 5
- 0
Shared/src/main/java/stdlib/USize.java Ver fichero

@@ -0,0 +1,5 @@
1
+package stdlib;
2
+
3
+final class USize {
4
+    private USize() {}
5
+}

+ 7
- 0
Shared/src/main/java/zsynthetic/ArrayHelpers.java Ver fichero

@@ -7,4 +7,11 @@ public class ArrayHelpers {
7 7
                 return true;
8 8
         return false;
9 9
     }
10
+	
11
+	public static boolean contains(char[] haystack, char needle) {
12
+        for (int i = 0; i < haystack.length; i++)
13
+            if (haystack[i] == needle)
14
+                return true;
15
+        return false;
16
+    }
10 17
 }

+ 1
- 1
Shared/src/main/java/zsynthetic/FunctionBoolBoolToVoid.java Ver fichero

@@ -2,5 +2,5 @@ package zsynthetic;
2 2
 
3 3
 @FunctionalInterface
4 4
 public interface FunctionBoolBoolToVoid {
5
-    void invoke(boolean oldValue, boolean newValue);
5
+    void invoke(boolean a, boolean b);
6 6
 }

+ 1
- 1
Shared/src/main/java/zsynthetic/FunctionIntIntToVoid.java Ver fichero

@@ -2,5 +2,5 @@ package zsynthetic;
2 2
 
3 3
 @FunctionalInterface
4 4
 public interface FunctionIntIntToVoid {
5
-    void invoke(int oldValue, int newValue);
5
+    void invoke(int a, int b);
6 6
 }

+ 1
- 1
Shared/src/main/java/zsynthetic/FunctionUSizeTToBool.java Ver fichero

@@ -2,5 +2,5 @@ package zsynthetic;
2 2
 
3 3
 @FunctionalInterface
4 4
 public interface FunctionUSizeTToBool<T> {
5
-    boolean invoke(int index, T value);
5
+    boolean invoke(int a, T b);
6 6
 }

+ 2
- 2
Shared/src/main/java/zsynthetic/FunctionUSizeTToU.java Ver fichero

@@ -1,6 +1,6 @@
1 1
 package zsynthetic;
2 2
 
3 3
 @FunctionalInterface
4
-public interface FunctionUSizeTToU<U, T> {
5
-    U invoke(int index, T value);
4
+public interface FunctionUSizeTToU<T, U> {
5
+    U invoke(int a, T b);
6 6
 }

+ 1
- 1
Shared/src/main/java/zsynthetic/FunctionUSizeTToVoid.java Ver fichero

@@ -2,5 +2,5 @@ package zsynthetic;
2 2
 
3 3
 @FunctionalInterface
4 4
 public interface FunctionUSizeTToVoid<T> {
5
-    void invoke(int index, T value);
5
+    void invoke(int a, T b);
6 6
 }

+ 23
- 0
Shared/src/main/java/zsynthetic/Shared.java Ver fichero

@@ -0,0 +1,23 @@
1
+package zsynthetic;
2
+
3
+public final class Shared<T extends AutoCloseable> {
4
+    private final T value;
5
+    private int refcount = 1;
6
+    
7
+    public Shared(T value) {
8
+        this.value = value;
9
+    }
10
+    
11
+    public synchronized void addRef() {
12
+        refcount++;
13
+    }
14
+    
15
+    public synchronized void release() {
16
+        refcount--;
17
+        if (refcount == 0) {
18
+            try {
19
+                value.close();
20
+            } catch (Exception ex) {}
21
+        }
22
+    }
23
+}

Loading…
Cancelar
Guardar