Skip to content

Commit 97f3232

Browse files
committed
add flowType() method
1 parent 5bfa477 commit 97f3232

File tree

22 files changed

+122
-28
lines changed

22 files changed

+122
-28
lines changed

interfaces/types.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,28 @@ declare class TypedHashMap<K, V> extends TypedEntity {
9696
static ref: ReferenceType<TypedHashMap<K, V>>;
9797
}
9898

99+
declare class TypedHashSet<E> extends TypedEntity {
100+
@@iterator(): Iterator<E>;
101+
static [symbol: Symbol]: any;
102+
103+
static cast (input: any): TypedHashSet<E>;
104+
static accepts (input: any): boolean;
105+
static initialize (backing: Backing, address: float64, initialValue?: Object|Set): void;
106+
static store (backing: Backing, address: float64, value: Object|Set|TypedHashSet<E>): void;
107+
static load (backing: Backing, address: float64): TypedHashSet<E>;
108+
static clear (backing: Backing, address: float64): void;
109+
static destructor (backing: Backing, address: float64): void;
110+
static emptyValue (): TypedHashSet<E>;
111+
static randomValue (): TypedHashSet<E>;
112+
static hashValue (input: TypedHashSet<E>|Set<E>): uint32;
113+
static equal (valueA: TypedHashSet<E>, valueB: TypedHashSet<E>): boolean;
114+
static compareValues (valueA: TypedHashSet<E>, valueB: TypedHashSet<E>): int8;
115+
static compareAddresses (backing: Backing, addressA: float64, addressB: float64): int8;
116+
static compareAddressValue (backing: Backing, address: float64, value: TypedHashSet<E>): int8;
117+
static Array: Class<ArrayType<TypedHashSet<E>>>;
118+
static ref: ReferenceType<TypedHashSet<E>>;
119+
}
120+
99121
declare class TypedStruct<S> extends TypedEntity {
100122
static [symbol: Symbol]: any;
101123
static cast (input: any): TypedStruct<S>;
@@ -140,6 +162,7 @@ declare type PrimitiveType<T> = Class<TypedPrimitive<T>>;
140162
declare type ReferenceType<T> = Class<TypedReference<T>>;
141163
declare type ArrayType<E> = Class<TypedArray<E>>;
142164
declare type HashMapType<K, V> = Class<TypedHashMap<K, V>>;
165+
declare type HashSetType<E> = Class<TypedHashSet<E>>;
143166
declare type StructType<S> = Class<TypedStruct<S>>;
144167
declare type ObjectType<S> = Class<TypedObject<S>>;
145168

@@ -148,6 +171,7 @@ declare type Type = Class<
148171
| TypedReference<any>
149172
| TypedArray<any>
150173
| TypedHashMap<any, any>
174+
| TypedHashSet<any>
151175
| TypedStruct<any>
152176
| TypedObject<Object>
153177
>;

src/builtins/any/index.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export function make (realm: Realm): PrimitiveType<any> {
1313
byteAlignment: 8,
1414
byteLength: 12,
1515
cast (input: any): any {
16+
// @flowIssue 252
1617
if (typeof input === 'function' || typeof input === 'symbol') {
1718
throw new TypeError(`Cannot store values with type: ${typeof input}`);
1819
}
@@ -24,6 +25,7 @@ export function make (realm: Realm): PrimitiveType<any> {
2425
}
2526
},
2627
accepts (input: any): boolean {
28+
// @flowIssue 252
2729
if (typeof input === 'function' || typeof input === 'symbol') {
2830
return false;
2931
}
@@ -34,7 +36,7 @@ export function make (realm: Realm): PrimitiveType<any> {
3436
initialize (backing: Backing, address: float64, initialValue: any): void {
3537
const Type = realm.typeOf(initialValue);
3638
let initialAddress;
37-
if (Type === null) {
39+
if (Type == null) {
3840
backing.setFloat64(address, 0);
3941
backing.setUint32(address + 8, 0);
4042
}
@@ -60,7 +62,7 @@ export function make (realm: Realm): PrimitiveType<any> {
6062
if (existingTypeId !== 0) {
6163
const existingType = realm.I[existingTypeId];
6264

63-
if (existingType === Type && Type.byteLength <= 8) {
65+
if (Type != null && existingType === Type && Type.byteLength <= 8) {
6466
Type.store(backing, address, value);
6567
return; // nothing left to do.
6668
}
@@ -77,7 +79,7 @@ export function make (realm: Realm): PrimitiveType<any> {
7779
}
7880
let valueAddress;
7981

80-
if (Type === null) {
82+
if (Type == null) {
8183
backing.setFloat64(address, 0);
8284
backing.setUint32(address + 8, 0);
8385
}
@@ -118,12 +120,15 @@ export function make (realm: Realm): PrimitiveType<any> {
118120
},
119121
hashValue (input): uint32 {
120122
const Type = realm.typeOf(input);
121-
if (Type === null) {
123+
if (Type == null) {
122124
return 4;
123125
}
124126
else {
125127
return Type.hashValue(input);
126128
}
129+
},
130+
flowType () {
131+
return `any`;
127132
}
128133
});
129134
Any[$CanBeEmbedded] = true;

src/builtins/boolean/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ export function make ({PrimitiveType}: Realm): PrimitiveType<boolean> {
3030
},
3131
hashValue (input): uint32 {
3232
return hashInteger(input ? 1 : 0);
33-
}
33+
},
34+
flowType () {
35+
return `boolean`;
36+
}
3437
});
3538
}

src/builtins/float32/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ export function make ({PrimitiveType}: Realm): PrimitiveType<float32> {
2828
randomValue (): float32 {
2929
return Math.fround(((Math.random() * Math.pow(2, 16)) * Math.pow(2, 8)) - Math.random() * Math.pow(2, 24));
3030
},
31-
hashValue: hashFloat32
31+
hashValue: hashFloat32,
32+
flowType () {
33+
return `float32`;
34+
}
3235
});
3336
}

src/builtins/float64/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ export function make ({PrimitiveType}: Realm): PrimitiveType<float64> {
2828
randomValue (): float64 {
2929
return ((Math.random() * Math.pow(2, 16)) * Math.pow(2, 8)) - Math.random() * Math.pow(2, 24)
3030
},
31-
hashValue: hashFloat64
31+
hashValue: hashFloat64,
32+
flowType () {
33+
return `float64`;
34+
}
3235
});
3336
}

src/builtins/int16/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ export function make ({PrimitiveType}: Realm): PrimitiveType<int16> {
2828
randomValue (): int16 {
2929
return Math.floor(Math.random() * Math.pow(2, 16)) - Math.pow(2, 15);
3030
},
31-
hashValue: hashInteger
31+
hashValue: hashInteger,
32+
flowType () {
33+
return `int16`;
34+
}
3235
});
3336
}

src/builtins/int32/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ export function make ({PrimitiveType}: Realm): PrimitiveType<int32> {
2828
randomValue (): int32 {
2929
return Math.floor(Math.random() * Math.pow(2, 32)) - Math.pow(2, 31);
3030
},
31-
hashValue: hashInteger
31+
hashValue: hashInteger,
32+
flowType () {
33+
return `int32`;
34+
}
3235
});
3336
}

src/builtins/int8/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ export function make ({PrimitiveType}: Realm): PrimitiveType<int8> {
2828
randomValue (): int8 {
2929
return Math.floor(Math.random() * Math.pow(2, 8)) - Math.pow(2, 7);
3030
},
31-
hashValue: hashInteger
31+
hashValue: hashInteger,
32+
flowType () {
33+
return `int8`;
34+
}
3235
});
3336
}

src/builtins/interned-string/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ export function make (realm: Realm): PrimitiveType<string> {
7070
hashValue: hashString,
7171
equal (valueA: string, valueB: string) {
7272
return valueA === valueB;
73+
},
74+
flowType () {
75+
return `string`;
7376
}
7477
});
7578

src/builtins/object/index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@ export function make (realm: Realm): ObjectType<Object> {
9191
randomValue (): any {
9292
return null;
9393
},
94-
hashValue: hashAny
94+
hashValue: hashAny,
95+
flowType () {
96+
return `Object`;
97+
}
9598
});
9699

97100
function createAccessors (target: TypedObject) {
@@ -141,13 +144,15 @@ export function make (realm: Realm): ObjectType<Object> {
141144

142145
function loadObject (backing: Backing, address: float64): Object {
143146
const output = {
147+
// @flowIssue 252
144148
[$Backing]: backing,
149+
// @flowIssue 252
145150
[$Address]: address
146151
};
147152
const length = backing.getUint32(address);
148153
let current = address + 8;
149154
for (let i = 0; i < length; i++) {
150-
output[T.String.load(backing, current)] = T.Any.load(backing, current + 8);
155+
output[(T.String.load(backing, current): any)] = T.Any.load(backing, current + 8);
151156
current += 24;
152157
}
153158
return output;

0 commit comments

Comments
 (0)