porffor 0.55.32 → 0.55.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/compiler/builtins/_internal_object.ts +348 -239
- package/compiler/builtins/_internal_string.ts +4 -4
- package/compiler/builtins/annexb_string.js +12 -11
- package/compiler/builtins/array.ts +21 -22
- package/compiler/builtins/arraybuffer.ts +4 -4
- package/compiler/builtins/bigint.ts +4 -4
- package/compiler/builtins/console.ts +9 -9
- package/compiler/builtins/dataview.ts +3 -3
- package/compiler/builtins/date.ts +46 -52
- package/compiler/builtins/error.js +1 -1
- package/compiler/builtins/json.ts +6 -6
- package/compiler/builtins/math.ts +1 -1
- package/compiler/builtins/number.ts +9 -9
- package/compiler/builtins/object.ts +32 -32
- package/compiler/builtins/object_hiddenPrototype.js +42 -0
- package/compiler/builtins/porffor.d.ts +4 -3
- package/compiler/builtins/promise.ts +6 -6
- package/compiler/builtins/reflect.ts +1 -1
- package/compiler/builtins/set.ts +7 -7
- package/compiler/builtins/string_f64.ts +2 -2
- package/compiler/builtins/symbol.ts +2 -2
- package/compiler/builtins/typedarray.js +7 -7
- package/compiler/builtins/z_ecma262.ts +7 -7
- package/compiler/builtins.js +5 -6
- package/compiler/builtins_objects.js +27 -5
- package/compiler/builtins_precompiled.js +529 -525
- package/compiler/codegen.js +29 -39
- package/compiler/precompile.js +4 -3
- package/package.json +1 -1
- package/r.cjs +2 -9
- package/runner/index.js +1 -1
- package/compiler/builtins/__internal_object.ts +0 -83
- package/compiler/builtins/object_prototypeWithHidden.js +0 -47
@@ -18,168 +18,7 @@ import type {} from './porffor.d.ts';
|
|
18
18
|
// enumerable - 0b0100
|
19
19
|
// writable - 0b1000
|
20
20
|
|
21
|
-
|
22
|
-
const t: i32 = Porffor.wasm`local.get ${arg+1}`;
|
23
|
-
return Porffor.fastAnd(
|
24
|
-
arg != 0, // null
|
25
|
-
t > 0x05,
|
26
|
-
t != Porffor.TYPES.string,
|
27
|
-
t != Porffor.TYPES.bytestring
|
28
|
-
);
|
29
|
-
};
|
30
|
-
|
31
|
-
export const __Porffor_object_isObjectOrNull = (arg: any): boolean => {
|
32
|
-
const t: i32 = Porffor.wasm`local.get ${arg+1}`;
|
33
|
-
return Porffor.fastAnd(
|
34
|
-
t > 0x05,
|
35
|
-
t != Porffor.TYPES.string,
|
36
|
-
t != Porffor.TYPES.bytestring
|
37
|
-
);
|
38
|
-
};
|
39
|
-
|
40
|
-
export const __Porffor_object_isObjectOrSymbol = (arg: any): boolean => {
|
41
|
-
const t: i32 = Porffor.wasm`local.get ${arg+1}`;
|
42
|
-
return Porffor.fastAnd(
|
43
|
-
arg != 0, // null
|
44
|
-
t > 0x04,
|
45
|
-
t != Porffor.TYPES.string,
|
46
|
-
t != Porffor.TYPES.bytestring
|
47
|
-
);
|
48
|
-
};
|
49
|
-
|
50
|
-
|
51
|
-
export const __Porffor_object_preventExtensions = (obj: any): void => {
|
52
|
-
if (Porffor.wasm`local.get ${obj+1}` != Porffor.TYPES.object) {
|
53
|
-
obj = __Porffor_object_underlying(obj);
|
54
|
-
if (Porffor.wasm`local.get ${obj+1}` != Porffor.TYPES.object) return;
|
55
|
-
}
|
56
|
-
|
57
|
-
Porffor.wasm.i32.store8(obj, Porffor.wasm.i32.load8_u(obj, 0, 2) | 0b0001, 0, 2);
|
58
|
-
};
|
59
|
-
|
60
|
-
export const __Porffor_object_isInextensible = (obj: any): boolean => {
|
61
|
-
if (Porffor.wasm`local.get ${obj+1}` != Porffor.TYPES.object) {
|
62
|
-
obj = __Porffor_object_underlying(obj);
|
63
|
-
if (Porffor.wasm`local.get ${obj+1}` != Porffor.TYPES.object) return false;
|
64
|
-
}
|
65
|
-
|
66
|
-
return (Porffor.wasm.i32.load8_u(obj, 0, 2) & 0b0001) as boolean;
|
67
|
-
};
|
68
|
-
|
69
|
-
export const __Porffor_object_setPrototype = (obj: any, proto: any): void => {
|
70
|
-
if (Porffor.wasm`local.get ${obj+1}` != Porffor.TYPES.object) {
|
71
|
-
obj = __Porffor_object_underlying(obj);
|
72
|
-
if (Porffor.wasm`local.get ${obj+1}` != Porffor.TYPES.object) return;
|
73
|
-
}
|
74
|
-
|
75
|
-
if (__Porffor_object_isObjectOrNull(proto)) {
|
76
|
-
Porffor.wasm.i32.store(obj, proto, 0, 4);
|
77
|
-
Porffor.wasm.i32.store8(obj, Porffor.rawType(proto), 0, 3);
|
78
|
-
}
|
79
|
-
};
|
80
|
-
|
81
|
-
export const __Porffor_object_getPrototype = (obj: any): any => {
|
82
|
-
if (Porffor.wasm`local.get ${obj+1}` != Porffor.TYPES.object) {
|
83
|
-
obj = __Porffor_object_underlying(obj);
|
84
|
-
if (Porffor.wasm`local.get ${obj+1}` != Porffor.TYPES.object) {
|
85
|
-
// return empty
|
86
|
-
Porffor.wasm`
|
87
|
-
i32.const 0
|
88
|
-
i32.const 0
|
89
|
-
return`;
|
90
|
-
}
|
91
|
-
}
|
92
|
-
|
93
|
-
Porffor.wasm`
|
94
|
-
local.get ${obj}
|
95
|
-
i32.load 0 4
|
96
|
-
local.get ${obj}
|
97
|
-
i32.load8_u 0 3
|
98
|
-
return`;
|
99
|
-
};
|
100
|
-
|
101
|
-
|
102
|
-
export const __Porffor_object_overrideAllFlags = (obj: any, overrideOr: i32, overrideAnd: i32): void => {
|
103
|
-
if (Porffor.wasm`local.get ${obj+1}` != Porffor.TYPES.object) {
|
104
|
-
obj = __Porffor_object_underlying(obj);
|
105
|
-
if (Porffor.wasm`local.get ${obj+1}` != Porffor.TYPES.object) return;
|
106
|
-
}
|
107
|
-
|
108
|
-
let ptr: i32 = Porffor.wasm`local.get ${obj}`;
|
109
|
-
|
110
|
-
const size: i32 = Porffor.wasm.i32.load16_u(obj, 0, 0);
|
111
|
-
const endPtr: i32 = ptr + size * 18;
|
112
|
-
|
113
|
-
for (; ptr < endPtr; ptr += 18) {
|
114
|
-
let flags: i32 = Porffor.wasm.i32.load8_u(ptr, 0, 24);
|
115
|
-
flags = (flags | overrideOr) & overrideAnd;
|
116
|
-
Porffor.wasm.i32.store8(ptr, flags, 0, 24);
|
117
|
-
}
|
118
|
-
};
|
119
|
-
|
120
|
-
export const __Porffor_object_checkAllFlags = (obj: any, dataAnd: i32, accessorAnd: i32, dataExpected: i32, accessorExpected: i32): boolean => {
|
121
|
-
if (Porffor.wasm`local.get ${obj+1}` != Porffor.TYPES.object) {
|
122
|
-
obj = __Porffor_object_underlying(obj);
|
123
|
-
if (Porffor.wasm`local.get ${obj+1}` != Porffor.TYPES.object) return false;
|
124
|
-
}
|
125
|
-
|
126
|
-
let ptr: i32 = Porffor.wasm`local.get ${obj}`;
|
127
|
-
|
128
|
-
const size: i32 = Porffor.wasm.i32.load16_u(obj, 0, 0);
|
129
|
-
const endPtr: i32 = ptr + size * 18;
|
130
|
-
|
131
|
-
for (; ptr < endPtr; ptr += 18) {
|
132
|
-
const flags: i32 = Porffor.wasm.i32.load8_u(ptr, 0, 24);
|
133
|
-
if (flags & 0b0001) {
|
134
|
-
// accessor
|
135
|
-
if ((flags & accessorAnd) != accessorExpected) return false;
|
136
|
-
} else {
|
137
|
-
// data
|
138
|
-
if ((flags & dataAnd) != dataExpected) return false;
|
139
|
-
}
|
140
|
-
|
141
|
-
}
|
142
|
-
|
143
|
-
return true;
|
144
|
-
};
|
145
|
-
|
146
|
-
export const __Porffor_object_packAccessor = (get: any, set: any): f64 => {
|
147
|
-
// pack i32s get & set into a single f64 (reinterpreted u64)
|
148
|
-
Porffor.wasm`
|
149
|
-
local.get ${set}
|
150
|
-
i64.extend_i32_u
|
151
|
-
i64.const 32
|
152
|
-
i64.shl
|
153
|
-
local.get ${get}
|
154
|
-
i64.extend_i32_u
|
155
|
-
i64.or
|
156
|
-
f64.reinterpret_i64
|
157
|
-
return`;
|
158
|
-
};
|
159
|
-
|
160
|
-
export const __Porffor_object_accessorGet = (entryPtr: i32): Function|undefined => {
|
161
|
-
const out: Function = Porffor.wasm.i32.load(entryPtr, 0, 8);
|
162
|
-
|
163
|
-
// no getter, return undefined
|
164
|
-
if (Porffor.wasm`local.get ${out}` == 0) {
|
165
|
-
return undefined;
|
166
|
-
}
|
167
|
-
|
168
|
-
return out;
|
169
|
-
};
|
170
|
-
|
171
|
-
export const __Porffor_object_accessorSet = (entryPtr: i32): Function|undefined => {
|
172
|
-
const out: Function = Porffor.wasm.i32.load(entryPtr, 0, 12);
|
173
|
-
|
174
|
-
// no setter, return undefined
|
175
|
-
if (Porffor.wasm`local.get ${out}` == 0) {
|
176
|
-
return undefined;
|
177
|
-
}
|
178
|
-
|
179
|
-
return out;
|
180
|
-
};
|
181
|
-
|
182
|
-
|
21
|
+
// hash key for hashmap
|
183
22
|
export const __Porffor_object_hash = (key: any): i32 => {
|
184
23
|
if (Porffor.wasm`local.get ${key+1}` == Porffor.TYPES.symbol) {
|
185
24
|
// symbol, hash is unused so just return 0
|
@@ -362,6 +201,325 @@ local.set ${hash}`;
|
|
362
201
|
return hash;
|
363
202
|
};
|
364
203
|
|
204
|
+
export const __Porffor_object_writeKey = (ptr: i32, key: any, hash: i32): void => {
|
205
|
+
// write hash to ptr
|
206
|
+
Porffor.wasm.i32.store(ptr, hash, 0, 0);
|
207
|
+
|
208
|
+
// encode key type
|
209
|
+
let keyEnc: i32 = Porffor.wasm`local.get ${key}`;
|
210
|
+
|
211
|
+
// set MSB 1 if regular string
|
212
|
+
if (Porffor.wasm`local.get ${key+1}` == Porffor.TYPES.string) keyEnc |= 0x80000000;
|
213
|
+
// set MSB 1&2 if symbol
|
214
|
+
else if (Porffor.wasm`local.get ${key+1}` == Porffor.TYPES.symbol) keyEnc |= 0xc0000000;
|
215
|
+
|
216
|
+
// write encoded key to ptr + 4
|
217
|
+
Porffor.wasm.i32.store(ptr, keyEnc, 0, 4);
|
218
|
+
};
|
219
|
+
|
220
|
+
export const __Porffor_object_fastAdd = (obj: any, key: any, value: any, flags: i32): void => {
|
221
|
+
// add new entry
|
222
|
+
// bump size +1
|
223
|
+
const size: i32 = Porffor.wasm.i32.load16_u(obj, 0, 0);
|
224
|
+
Porffor.wasm.i32.store16(obj, size + 1, 0, 0);
|
225
|
+
|
226
|
+
// entryPtr = current end of object
|
227
|
+
const entryPtr: i32 = Porffor.wasm`local.get ${obj}` + 8 + size * 18;
|
228
|
+
__Porffor_object_writeKey(entryPtr, key, __Porffor_object_hash(key));
|
229
|
+
|
230
|
+
// write new value value
|
231
|
+
Porffor.wasm.f64.store(entryPtr, value, 0, 8);
|
232
|
+
|
233
|
+
// write new tail (value type + flags)
|
234
|
+
Porffor.wasm.i32.store16(entryPtr,
|
235
|
+
flags + (Porffor.wasm`local.get ${value+1}` << 8),
|
236
|
+
0, 16);
|
237
|
+
};
|
238
|
+
|
239
|
+
// store underlying (real) objects for hidden types
|
240
|
+
let underlyingStore: i32 = 0;
|
241
|
+
export const __Porffor_object_underlying = (_obj: any): any => {
|
242
|
+
if (Porffor.type(_obj) == Porffor.TYPES.object) {
|
243
|
+
Porffor.wasm`
|
244
|
+
local.get ${_obj}
|
245
|
+
i32.trunc_sat_f64_u
|
246
|
+
i32.const 7 ;; object
|
247
|
+
return`;
|
248
|
+
}
|
249
|
+
|
250
|
+
if (Porffor.fastAnd(
|
251
|
+
Porffor.type(_obj) >= Porffor.TYPES.error,
|
252
|
+
Porffor.type(_obj) < 0x40
|
253
|
+
)) {
|
254
|
+
Porffor.wasm`
|
255
|
+
local.get ${_obj}
|
256
|
+
i32.trunc_sat_f64_u
|
257
|
+
i32.const 7 ;; object
|
258
|
+
return`;
|
259
|
+
}
|
260
|
+
|
261
|
+
if (Porffor.fastAnd(
|
262
|
+
Porffor.type(_obj) > 0x05,
|
263
|
+
Porffor.type(_obj) != Porffor.TYPES.undefined
|
264
|
+
)) {
|
265
|
+
if (underlyingStore == 0) underlyingStore = Porffor.allocate();
|
266
|
+
|
267
|
+
// check if underlying object already exists for obj
|
268
|
+
const underlyingLength: i32 = Porffor.wasm.i32.load(underlyingStore, 0, 0);
|
269
|
+
const end: i32 = underlyingLength * 12;
|
270
|
+
for (let i: i32 = 0; i < end; i += 12) {
|
271
|
+
if (Porffor.wasm.f64.eq(Porffor.wasm.f64.load(underlyingStore + i, 0, 4), _obj))
|
272
|
+
return Porffor.wasm.i32.load(underlyingStore + i, 0, 12) as object;
|
273
|
+
}
|
274
|
+
|
275
|
+
let obj;
|
276
|
+
Porffor.wasm`
|
277
|
+
local.get ${_obj}
|
278
|
+
i32.trunc_sat_f64_u
|
279
|
+
local.set ${obj}`;
|
280
|
+
|
281
|
+
// it does not, make it
|
282
|
+
const underlying: object = {};
|
283
|
+
if (Porffor.type(_obj) == Porffor.TYPES.function) {
|
284
|
+
if (ecma262.IsConstructor(_obj)) { // constructor
|
285
|
+
// set prototype and prototype.constructor if function and constructor
|
286
|
+
const proto: object = {};
|
287
|
+
__Porffor_object_fastAdd(underlying, 'prototype', proto, 0b1000);
|
288
|
+
__Porffor_object_fastAdd(proto, 'constructor', _obj, 0b1010);
|
289
|
+
}
|
290
|
+
|
291
|
+
__Porffor_object_fastAdd(underlying, 'name', __Porffor_funcLut_name(obj), 0b0010);
|
292
|
+
__Porffor_object_fastAdd(underlying, 'length', __Porffor_funcLut_length(obj), 0b0010);
|
293
|
+
}
|
294
|
+
|
295
|
+
if (Porffor.type(_obj) == Porffor.TYPES.array) {
|
296
|
+
const len: i32 = Porffor.wasm.i32.load(obj, 0, 0);
|
297
|
+
__Porffor_object_fastAdd(underlying, 'length', len, 0b1000);
|
298
|
+
|
299
|
+
// todo: this should somehow be kept in sync?
|
300
|
+
for (let i: i32 = 0; i < len; i++) {
|
301
|
+
let ptr: i32 = obj + i * 9;
|
302
|
+
Porffor.wasm`
|
303
|
+
local x f64
|
304
|
+
local x#type i32
|
305
|
+
local.get ${ptr}
|
306
|
+
f64.load 0 4
|
307
|
+
local.set x
|
308
|
+
|
309
|
+
local.get ${ptr}
|
310
|
+
i32.load8_u 0 12
|
311
|
+
local.set x#type`;
|
312
|
+
__Porffor_object_fastAdd(underlying, __Number_prototype_toString(i), x, 0b1110);
|
313
|
+
}
|
314
|
+
}
|
315
|
+
|
316
|
+
if (Porffor.fastOr(
|
317
|
+
Porffor.type(_obj) == Porffor.TYPES.string,
|
318
|
+
Porffor.type(_obj) == Porffor.TYPES.stringobject)
|
319
|
+
) {
|
320
|
+
const len: i32 = (obj as string).length;
|
321
|
+
__Porffor_object_fastAdd(underlying, 'length', len, 0b0000);
|
322
|
+
|
323
|
+
for (let i: i32 = 0; i < len; i++) {
|
324
|
+
__Porffor_object_fastAdd(underlying, __Number_prototype_toString(i), (obj as string)[i], 0b0100);
|
325
|
+
}
|
326
|
+
|
327
|
+
if (Porffor.type(_obj) == Porffor.TYPES.string) Porffor.wasm.i32.store8(obj, 0b0001, 0, 2); // make inextensible
|
328
|
+
}
|
329
|
+
|
330
|
+
if (Porffor.type(_obj) == Porffor.TYPES.bytestring) {
|
331
|
+
const len: i32 = (obj as bytestring).length;
|
332
|
+
__Porffor_object_fastAdd(underlying, 'length', len, 0b0000);
|
333
|
+
|
334
|
+
for (let i: i32 = 0; i < len; i++) {
|
335
|
+
__Porffor_object_fastAdd(underlying, __Number_prototype_toString(i), (obj as bytestring)[i], 0b0100);
|
336
|
+
}
|
337
|
+
|
338
|
+
Porffor.wasm.i32.store8(obj, 0b0001, 0, 2); // make inextensible
|
339
|
+
}
|
340
|
+
|
341
|
+
// store new underlying obj
|
342
|
+
Porffor.wasm.i32.store(underlyingStore, underlyingLength + 1, 0, 0);
|
343
|
+
Porffor.wasm.f64.store(underlyingStore + underlyingLength * 12, _obj, 0, 4);
|
344
|
+
Porffor.wasm.i32.store(underlyingStore + underlyingLength * 12, underlying, 0, 12);
|
345
|
+
return underlying;
|
346
|
+
}
|
347
|
+
|
348
|
+
Porffor.wasm`
|
349
|
+
local.get ${_obj}
|
350
|
+
i32.trunc_sat_f64_u
|
351
|
+
local.get ${_obj+1}
|
352
|
+
return`;
|
353
|
+
};
|
354
|
+
|
355
|
+
export const __Porffor_object_isObject = (arg: any): boolean => {
|
356
|
+
const t: i32 = Porffor.wasm`local.get ${arg+1}`;
|
357
|
+
return Porffor.fastAnd(
|
358
|
+
arg != 0, // null
|
359
|
+
t > 0x05,
|
360
|
+
t != Porffor.TYPES.string,
|
361
|
+
t != Porffor.TYPES.bytestring
|
362
|
+
);
|
363
|
+
};
|
364
|
+
|
365
|
+
export const __Porffor_object_isObjectOrNull = (arg: any): boolean => {
|
366
|
+
const t: i32 = Porffor.wasm`local.get ${arg+1}`;
|
367
|
+
return Porffor.fastAnd(
|
368
|
+
t > 0x05,
|
369
|
+
t != Porffor.TYPES.string,
|
370
|
+
t != Porffor.TYPES.bytestring
|
371
|
+
);
|
372
|
+
};
|
373
|
+
|
374
|
+
export const __Porffor_object_isObjectOrSymbol = (arg: any): boolean => {
|
375
|
+
const t: i32 = Porffor.wasm`local.get ${arg+1}`;
|
376
|
+
return Porffor.fastAnd(
|
377
|
+
arg != 0, // null
|
378
|
+
t > 0x04,
|
379
|
+
t != Porffor.TYPES.string,
|
380
|
+
t != Porffor.TYPES.bytestring
|
381
|
+
);
|
382
|
+
};
|
383
|
+
|
384
|
+
|
385
|
+
export const __Porffor_object_preventExtensions = (obj: any): void => {
|
386
|
+
if (Porffor.wasm`local.get ${obj+1}` != Porffor.TYPES.object) {
|
387
|
+
obj = __Porffor_object_underlying(obj);
|
388
|
+
if (Porffor.wasm`local.get ${obj+1}` != Porffor.TYPES.object) return;
|
389
|
+
}
|
390
|
+
|
391
|
+
Porffor.wasm.i32.store8(obj, Porffor.wasm.i32.load8_u(obj, 0, 2) | 0b0001, 0, 2);
|
392
|
+
};
|
393
|
+
|
394
|
+
export const __Porffor_object_isInextensible = (obj: any): boolean => {
|
395
|
+
if (Porffor.wasm`local.get ${obj+1}` != Porffor.TYPES.object) {
|
396
|
+
obj = __Porffor_object_underlying(obj);
|
397
|
+
if (Porffor.wasm`local.get ${obj+1}` != Porffor.TYPES.object) return false;
|
398
|
+
}
|
399
|
+
|
400
|
+
return (Porffor.wasm.i32.load8_u(obj, 0, 2) & 0b0001) as boolean;
|
401
|
+
};
|
402
|
+
|
403
|
+
export const __Porffor_object_setPrototype = (obj: any, proto: any): void => {
|
404
|
+
if (Porffor.wasm`local.get ${obj+1}` != Porffor.TYPES.object) {
|
405
|
+
obj = __Porffor_object_underlying(obj);
|
406
|
+
if (Porffor.wasm`local.get ${obj+1}` != Porffor.TYPES.object) return;
|
407
|
+
}
|
408
|
+
|
409
|
+
if (__Porffor_object_isObjectOrNull(proto)) {
|
410
|
+
Porffor.wasm.i32.store(obj, proto, 0, 4);
|
411
|
+
Porffor.wasm.i32.store8(obj, Porffor.type(proto), 0, 3);
|
412
|
+
}
|
413
|
+
};
|
414
|
+
|
415
|
+
export const __Porffor_object_getPrototype = (obj: any): any => {
|
416
|
+
if (Porffor.wasm`local.get ${obj+1}` != Porffor.TYPES.object) {
|
417
|
+
obj = __Porffor_object_underlying(obj);
|
418
|
+
if (Porffor.wasm`local.get ${obj+1}` != Porffor.TYPES.object) {
|
419
|
+
// return empty
|
420
|
+
Porffor.wasm`
|
421
|
+
i32.const 0
|
422
|
+
i32.const 0
|
423
|
+
return`;
|
424
|
+
}
|
425
|
+
}
|
426
|
+
|
427
|
+
Porffor.wasm`
|
428
|
+
local.get ${obj}
|
429
|
+
i32.load 0 4
|
430
|
+
local.get ${obj}
|
431
|
+
i32.load8_u 0 3
|
432
|
+
return`;
|
433
|
+
};
|
434
|
+
|
435
|
+
export const __Porffor_object_getPrototypeWithHidden = (obj: any, trueType: i32): any => {
|
436
|
+
const objectProto: any = __Porffor_object_getPrototype(obj);
|
437
|
+
if (Porffor.type(objectProto) != Porffor.TYPES.empty) return objectProto;
|
438
|
+
|
439
|
+
return __Porffor_object_getHiddenPrototype(trueType);
|
440
|
+
};
|
441
|
+
|
442
|
+
|
443
|
+
export const __Porffor_object_overrideAllFlags = (obj: any, overrideOr: i32, overrideAnd: i32): void => {
|
444
|
+
if (Porffor.wasm`local.get ${obj+1}` != Porffor.TYPES.object) {
|
445
|
+
obj = __Porffor_object_underlying(obj);
|
446
|
+
if (Porffor.wasm`local.get ${obj+1}` != Porffor.TYPES.object) return;
|
447
|
+
}
|
448
|
+
|
449
|
+
let ptr: i32 = Porffor.wasm`local.get ${obj}`;
|
450
|
+
|
451
|
+
const size: i32 = Porffor.wasm.i32.load16_u(obj, 0, 0);
|
452
|
+
const endPtr: i32 = ptr + size * 18;
|
453
|
+
|
454
|
+
for (; ptr < endPtr; ptr += 18) {
|
455
|
+
let flags: i32 = Porffor.wasm.i32.load8_u(ptr, 0, 24);
|
456
|
+
flags = (flags | overrideOr) & overrideAnd;
|
457
|
+
Porffor.wasm.i32.store8(ptr, flags, 0, 24);
|
458
|
+
}
|
459
|
+
};
|
460
|
+
|
461
|
+
export const __Porffor_object_checkAllFlags = (obj: any, dataAnd: i32, accessorAnd: i32, dataExpected: i32, accessorExpected: i32): boolean => {
|
462
|
+
if (Porffor.wasm`local.get ${obj+1}` != Porffor.TYPES.object) {
|
463
|
+
obj = __Porffor_object_underlying(obj);
|
464
|
+
if (Porffor.wasm`local.get ${obj+1}` != Porffor.TYPES.object) return false;
|
465
|
+
}
|
466
|
+
|
467
|
+
let ptr: i32 = Porffor.wasm`local.get ${obj}`;
|
468
|
+
|
469
|
+
const size: i32 = Porffor.wasm.i32.load16_u(obj, 0, 0);
|
470
|
+
const endPtr: i32 = ptr + size * 18;
|
471
|
+
|
472
|
+
for (; ptr < endPtr; ptr += 18) {
|
473
|
+
const flags: i32 = Porffor.wasm.i32.load8_u(ptr, 0, 24);
|
474
|
+
if (flags & 0b0001) {
|
475
|
+
// accessor
|
476
|
+
if ((flags & accessorAnd) != accessorExpected) return false;
|
477
|
+
} else {
|
478
|
+
// data
|
479
|
+
if ((flags & dataAnd) != dataExpected) return false;
|
480
|
+
}
|
481
|
+
|
482
|
+
}
|
483
|
+
|
484
|
+
return true;
|
485
|
+
};
|
486
|
+
|
487
|
+
export const __Porffor_object_packAccessor = (get: any, set: any): f64 => {
|
488
|
+
// pack i32s get & set into a single f64 (reinterpreted u64)
|
489
|
+
Porffor.wasm`
|
490
|
+
local.get ${set}
|
491
|
+
i64.extend_i32_u
|
492
|
+
i64.const 32
|
493
|
+
i64.shl
|
494
|
+
local.get ${get}
|
495
|
+
i64.extend_i32_u
|
496
|
+
i64.or
|
497
|
+
f64.reinterpret_i64
|
498
|
+
return`;
|
499
|
+
};
|
500
|
+
|
501
|
+
export const __Porffor_object_accessorGet = (entryPtr: i32): Function|undefined => {
|
502
|
+
const out: Function = Porffor.wasm.i32.load(entryPtr, 0, 8);
|
503
|
+
|
504
|
+
// no getter, return undefined
|
505
|
+
if (Porffor.wasm`local.get ${out}` == 0) {
|
506
|
+
return undefined;
|
507
|
+
}
|
508
|
+
|
509
|
+
return out;
|
510
|
+
};
|
511
|
+
|
512
|
+
export const __Porffor_object_accessorSet = (entryPtr: i32): Function|undefined => {
|
513
|
+
const out: Function = Porffor.wasm.i32.load(entryPtr, 0, 12);
|
514
|
+
|
515
|
+
// no setter, return undefined
|
516
|
+
if (Porffor.wasm`local.get ${out}` == 0) {
|
517
|
+
return undefined;
|
518
|
+
}
|
519
|
+
|
520
|
+
return out;
|
521
|
+
};
|
522
|
+
|
365
523
|
export const __Porffor_object_lookup = (obj: any, target: any, targetHash: i32): i32 => {
|
366
524
|
if (Porffor.wasm`local.get ${obj}` == 0) return -1;
|
367
525
|
if (Porffor.wasm`local.get ${obj+1}` != Porffor.TYPES.object) {
|
@@ -434,7 +592,19 @@ export const __Porffor_object_get = (obj: any, key: any): any => {
|
|
434
592
|
let entryPtr: i32 = __Porffor_object_lookup(obj, key, hash);
|
435
593
|
if (entryPtr == -1) {
|
436
594
|
// check prototype chain
|
437
|
-
|
595
|
+
if (trueType == Porffor.TYPES.object) {
|
596
|
+
// opt: inline get object prototype
|
597
|
+
Porffor.wasm`
|
598
|
+
local.get ${obj}
|
599
|
+
local.get ${obj}
|
600
|
+
i32.load 0 4
|
601
|
+
local.set ${obj}
|
602
|
+
i32.load8_u 0 3
|
603
|
+
local.set ${obj+1}`;
|
604
|
+
|
605
|
+
// if empty, prototype is object.prototype
|
606
|
+
if (Porffor.type(obj) == Porffor.TYPES.empty) obj = __Object_prototype;
|
607
|
+
} else obj = __Porffor_object_getHiddenPrototype(trueType);
|
438
608
|
|
439
609
|
// todo/opt: put this behind comptime flag if only __proto__ is used
|
440
610
|
if (hash == -406948493) if (key == '__proto__') {
|
@@ -450,7 +620,17 @@ return`;
|
|
450
620
|
while (true) {
|
451
621
|
if ((entryPtr = __Porffor_object_lookup(obj, key, hash)) != -1) break;
|
452
622
|
|
453
|
-
|
623
|
+
// inline get prototype
|
624
|
+
if (Porffor.type(obj) == Porffor.TYPES.object) {
|
625
|
+
Porffor.wasm`
|
626
|
+
local.get ${obj}
|
627
|
+
local.get ${obj}
|
628
|
+
i32.load 0 4
|
629
|
+
local.set ${obj}
|
630
|
+
i32.load8_u 0 3
|
631
|
+
local.set ${obj+1}`;
|
632
|
+
} else obj = __Porffor_object_getPrototype(obj);
|
633
|
+
|
454
634
|
if (Porffor.fastOr(obj == null, Porffor.wasm`local.get ${obj}` == Porffor.wasm`local.get ${lastProto}`)) break;
|
455
635
|
lastProto = obj;
|
456
636
|
}
|
@@ -489,22 +669,6 @@ i32.shr_u
|
|
489
669
|
return`;
|
490
670
|
};
|
491
671
|
|
492
|
-
export const __Porffor_object_writeKey = (ptr: i32, key: any, hash: i32 = __Porffor_object_hash(key)): void => {
|
493
|
-
// write hash to ptr
|
494
|
-
Porffor.wasm.i32.store(ptr, hash, 0, 0);
|
495
|
-
|
496
|
-
// encode key type
|
497
|
-
let keyEnc: i32 = Porffor.wasm`local.get ${key}`;
|
498
|
-
|
499
|
-
// set MSB 1 if regular string
|
500
|
-
if (Porffor.wasm`local.get ${key+1}` == Porffor.TYPES.string) keyEnc |= 0x80000000;
|
501
|
-
// set MSB 1&2 if symbol
|
502
|
-
else if (Porffor.wasm`local.get ${key+1}` == Porffor.TYPES.symbol) keyEnc |= 0xc0000000;
|
503
|
-
|
504
|
-
// write encoded key to ptr + 4
|
505
|
-
Porffor.wasm.i32.store(ptr, keyEnc, 0, 4);
|
506
|
-
};
|
507
|
-
|
508
672
|
export const __Porffor_object_set = (obj: any, key: any, value: any): any => {
|
509
673
|
if (Porffor.wasm`local.get ${obj+1}` != Porffor.TYPES.object) {
|
510
674
|
obj = __Porffor_object_underlying(obj);
|
@@ -519,13 +683,7 @@ export const __Porffor_object_set = (obj: any, key: any, value: any): any => {
|
|
519
683
|
if (entryPtr == -1) {
|
520
684
|
if (hash == -406948493) if (key == '__proto__') {
|
521
685
|
// set prototype
|
522
|
-
|
523
|
-
local.get ${obj}
|
524
|
-
local.get ${obj+1}
|
525
|
-
local.get ${value}
|
526
|
-
i32.trunc_sat_f64_u
|
527
|
-
local.get ${value+1}
|
528
|
-
call __Porffor_object_setPrototype`;
|
686
|
+
__Porffor_object_setPrototype(obj, value);
|
529
687
|
return value;
|
530
688
|
}
|
531
689
|
|
@@ -629,13 +787,7 @@ export const __Porffor_object_setStrict = (obj: any, key: any, value: any): any
|
|
629
787
|
if (entryPtr == -1) {
|
630
788
|
if (hash == -406948493) if (key == '__proto__') {
|
631
789
|
// set prototype
|
632
|
-
|
633
|
-
local.get ${obj}
|
634
|
-
local.get ${obj+1}
|
635
|
-
local.get ${value}
|
636
|
-
i32.trunc_sat_f64_u
|
637
|
-
local.get ${value+1}
|
638
|
-
call __Porffor_object_setPrototype`;
|
790
|
+
__Porffor_object_setPrototype(obj, value);
|
639
791
|
return value;
|
640
792
|
}
|
641
793
|
|
@@ -908,15 +1060,9 @@ export const __Porffor_object_expr_init = (obj: any, key: any, value: any): void
|
|
908
1060
|
const hash: i32 = __Porffor_object_hash(key);
|
909
1061
|
let entryPtr: i32 = __Porffor_object_lookup(obj, key, hash);
|
910
1062
|
if (entryPtr == -1) {
|
911
|
-
if (key == '__proto__') {
|
1063
|
+
if (hash == -406948493) if (key == '__proto__') {
|
912
1064
|
// set prototype
|
913
|
-
|
914
|
-
local.get ${obj}
|
915
|
-
local.get ${obj+1}
|
916
|
-
local.get ${value}
|
917
|
-
i32.trunc_sat_f64_u
|
918
|
-
local.get ${value+1}
|
919
|
-
call __Porffor_object_setPrototype`;
|
1065
|
+
__Porffor_object_setPrototype(obj, value);
|
920
1066
|
return value;
|
921
1067
|
}
|
922
1068
|
|
@@ -940,43 +1086,6 @@ call __Porffor_object_setPrototype`;
|
|
940
1086
|
0, 16);
|
941
1087
|
};
|
942
1088
|
|
943
|
-
export const __Porffor_object_expr_initWithFlags = (obj: any, key: any, value: any, flags: i32): void => {
|
944
|
-
if (Porffor.wasm`local.get ${obj+1}` != Porffor.TYPES.object) obj = __Porffor_object_underlying(obj);
|
945
|
-
|
946
|
-
const hash: i32 = __Porffor_object_hash(key);
|
947
|
-
let entryPtr: i32 = __Porffor_object_lookup(obj, key, hash);
|
948
|
-
if (entryPtr == -1) {
|
949
|
-
if (key == '__proto__') {
|
950
|
-
// set prototype
|
951
|
-
Porffor.wasm`
|
952
|
-
local.get ${obj}
|
953
|
-
local.get ${obj+1}
|
954
|
-
local.get ${value}
|
955
|
-
i32.trunc_sat_f64_u
|
956
|
-
local.get ${value+1}
|
957
|
-
call __Porffor_object_setPrototype`;
|
958
|
-
return value;
|
959
|
-
}
|
960
|
-
|
961
|
-
// add new entry
|
962
|
-
// bump size +1
|
963
|
-
const size: i32 = Porffor.wasm.i32.load16_u(obj, 0, 0);
|
964
|
-
Porffor.wasm.i32.store16(obj, size + 1, 0, 0);
|
965
|
-
|
966
|
-
// entryPtr = current end of object
|
967
|
-
entryPtr = Porffor.wasm`local.get ${obj}` + 8 + size * 18;
|
968
|
-
__Porffor_object_writeKey(entryPtr, key, hash);
|
969
|
-
}
|
970
|
-
|
971
|
-
// write new value value
|
972
|
-
Porffor.wasm.f64.store(entryPtr, value, 0, 8);
|
973
|
-
|
974
|
-
// write new tail (value type + flags)
|
975
|
-
Porffor.wasm.i32.store16(entryPtr,
|
976
|
-
flags + (Porffor.wasm`local.get ${value+1}` << 8),
|
977
|
-
0, 16);
|
978
|
-
};
|
979
|
-
|
980
1089
|
// used for { get foo() {} }
|
981
1090
|
export const __Porffor_object_expr_get = (obj: any, key: any, get: any): void => {
|
982
1091
|
if (Porffor.wasm`local.get ${obj+1}` != Porffor.TYPES.object) obj = __Porffor_object_underlying(obj);
|
@@ -1,8 +1,8 @@
|
|
1
1
|
import type {} from './porffor.d.ts';
|
2
2
|
|
3
3
|
export const __Porffor_compareStrings = (a: any, b: any): boolean => {
|
4
|
-
let at: i32 = Porffor.
|
5
|
-
let bt: i32 = Porffor.
|
4
|
+
let at: i32 = Porffor.type(a);
|
5
|
+
let bt: i32 = Porffor.type(b);
|
6
6
|
|
7
7
|
if ((at | 0b10000000) != Porffor.TYPES.bytestring) {
|
8
8
|
// a is not string or bytestring
|
@@ -36,8 +36,8 @@ export const __Porffor_compareStrings = (a: any, b: any): boolean => {
|
|
36
36
|
};
|
37
37
|
|
38
38
|
export const __Porffor_concatStrings = (a: any, b: any): any => {
|
39
|
-
let at: i32 = Porffor.
|
40
|
-
let bt: i32 = Porffor.
|
39
|
+
let at: i32 = Porffor.type(a);
|
40
|
+
let bt: i32 = Porffor.type(b);
|
41
41
|
|
42
42
|
if ((at | 0b10000000) != Porffor.TYPES.bytestring) {
|
43
43
|
// a is not string or bytestring
|
@@ -1,12 +1,11 @@
|
|
1
1
|
export default () => {
|
2
2
|
let out = ``;
|
3
3
|
const noArgs = (a0, a1) => out += `
|
4
|
-
export const __String_prototype_${a0} = (_this: any) =>
|
5
|
-
|
6
|
-
|
4
|
+
export const __String_prototype_${a0} = (_this: any) =>
|
5
|
+
Porffor.concatStrings(
|
6
|
+
Porffor.concatStrings('<${a1}>', _this),
|
7
|
+
'</${a1}>');
|
7
8
|
|
8
|
-
return Porffor.concatStrings(Porffor.concatStrings(pre, _this), post);
|
9
|
-
};
|
10
9
|
export const __ByteString_prototype_${a0} = (_this: any) =>
|
11
10
|
__String_prototype_${a0}(_this);
|
12
11
|
`;
|
@@ -22,13 +21,15 @@ export const __ByteString_prototype_${a0} = (_this: any) =>
|
|
22
21
|
noArgs('sup', 'sup');
|
23
22
|
|
24
23
|
const arg = (name, s1, s2) => out += `
|
25
|
-
export const __String_prototype_${name} = (_this: any, arg: any) =>
|
26
|
-
|
27
|
-
|
28
|
-
|
24
|
+
export const __String_prototype_${name} = (_this: any, arg: any) =>
|
25
|
+
Porffor.concatStrings(
|
26
|
+
Porffor.concatStrings(
|
27
|
+
Porffor.concatStrings(
|
28
|
+
Porffor.concatStrings('<${s1} ${s2}="', arg),
|
29
|
+
'">'),
|
30
|
+
_this),
|
31
|
+
'</${s1}>');
|
29
32
|
|
30
|
-
return Porffor.concatStrings(Porffor.concatStrings(Porffor.concatStrings(Porffor.concatStrings(pre1, arg), pre2), _this), post);
|
31
|
-
};
|
32
33
|
export const __ByteString_prototype_${name} = (_this: any, arg: any) =>
|
33
34
|
__String_prototype_${name}(_this, arg);
|
34
35
|
`;
|