porffor 0.17.0-f43ba190c โ 0.18.2
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/README.md +6 -4
- package/compiler/2c.js +1 -1
- package/compiler/assemble.js +19 -4
- package/compiler/builtins/array.ts +102 -9
- package/compiler/builtins/date.ts +104 -106
- package/compiler/builtins/error.js +2 -5
- package/compiler/builtins/set.ts +4 -5
- package/compiler/builtins/string_f64.ts +4 -6
- package/compiler/builtins/symbol.ts +2 -1
- package/compiler/builtins/typedarray.js +58 -6
- package/compiler/builtins/z_ecma262.ts +1 -0
- package/compiler/builtins.js +13 -2
- package/compiler/codegen.js +486 -127
- package/compiler/generated_builtins.js +2714 -713
- package/compiler/opt.js +3 -0
- package/compiler/precompile.js +4 -2
- package/compiler/prototype.js +0 -69
- package/package.json +1 -1
- package/rhemyn/README.md +7 -4
- package/rhemyn/compile.js +170 -76
- package/runner/index.js +3 -2
- package/runner/repl.js +1 -2
- package/runner/version.js +0 -12
package/README.md
CHANGED
@@ -148,27 +148,29 @@ These include some early (stage 1/0) and/or dead (last commit years ago) proposa
|
|
148
148
|
- Array constructor (`Array(5)`, `new Array(1, 2, 3)`)
|
149
149
|
- Labelled statements (`foo: while (...)`)
|
150
150
|
- `do...while` loops
|
151
|
+
- Optional parameters (`(foo = 'bar') => { ... }`)
|
151
152
|
|
152
153
|
### Built-ins
|
153
154
|
|
154
155
|
- `NaN` and `Infinity`
|
155
156
|
- `isNaN()` and `isFinite()`
|
156
157
|
- Most of `Number` (`MAX_VALUE`, `MIN_VALUE`, `MAX_SAFE_INTEGER`, `MIN_SAFE_INTEGER`, `POSITIVE_INFINITY`, `NEGATIVE_INFINITY`, `EPSILON`, `NaN`, `isNaN`, `isFinite`, `isInteger`, `isSafeInteger`)
|
157
|
-
-
|
158
|
+
- Most `Math` funcs (`sqrt`, `abs`, `floor`, `sign`, `round`, `trunc`, `clz32`, `fround`, `random`, `exp`, `log`, `log2`, `log10`, `pow`, `expm1`, `log1p`, `sqrt`, `cbrt`, `hypot`, `sin`, `cos`, `tan`, `sinh`, `cosh`, `tanh`, `asinh`, `acosh`, `atanh`, `asin`, `acos`, `atan`, `atan2`)
|
158
159
|
- Basic `globalThis` support
|
159
160
|
- Basic `Boolean` and `Number`
|
160
161
|
- Basic `eval` for literals
|
161
162
|
- `Math.random()` using self-made xorshift128+ PRNG
|
162
163
|
- Some of `performance` (`now()`, `timeOrigin`)
|
163
|
-
-
|
164
|
-
-
|
165
|
-
- Most of `String.prototype` (`at`, `charAt`, `charCodeAt`, `toUpperCase`, `toLowerCase`, `startsWith`, `endsWith`, `indexOf`, `lastIndexOf`, `includes`, `padStart`, `padEnd`, `substring`, `substr`, `slice`, `trimStart`, `trimEnd`, `trim`, `toString`, `big`, `blink`, `bold`, `fixed`, `italics`, `small`, `strike`, `sub`, `sup`, `trimLeft`, `trimRight`, )
|
164
|
+
- Most of `Array.prototype` (`at`, `push`, `pop`, `shift`, `fill`, `slice`, `indexOf`, `lastIndexOf`, `includes`, `with`, `reverse`, `toReversed`, `forEach`, `filter`, `map`, `find`, `findLast`, `findIndex`, `findLastIndex`, `every`, `some`, `reduce`, `reduceRight`, `join`, `toString`)
|
165
|
+
- Most of `Array` (`of`, `isArray`)
|
166
|
+
- Most of `String.prototype` (`at`, `charAt`, `charCodeAt`, `toUpperCase`, `toLowerCase`, `startsWith`, `endsWith`, `indexOf`, `lastIndexOf`, `includes`, `padStart`, `padEnd`, `substring`, `substr`, `slice`, `trimStart`, `trimEnd`, `trim`, `toString`, `big`, `blink`, `bold`, `fixed`, `italics`, `small`, `strike`, `sub`, `sup`, `trimLeft`, `trimRight`, `trim`)
|
166
167
|
- Some of `crypto` (`randomUUID`)
|
167
168
|
- `escape`
|
168
169
|
- `btoa`
|
169
170
|
- Most of `Number.prototype` (`toString`, `toFixed`, `toExponential`)
|
170
171
|
- `parseInt`
|
171
172
|
- Spec-compliant `Date`
|
173
|
+
- WIP typed arrays (`Uint8Array`, `Int32Array`, etc)
|
172
174
|
|
173
175
|
### Custom
|
174
176
|
|
package/compiler/2c.js
CHANGED
@@ -705,5 +705,5 @@ _time_out = _time.tv_nsec / 1000000. + _time.tv_sec * 1000.;`);
|
|
705
705
|
const makeIncludes = includes => [...includes.keys()].map(x => `#include <${x}>\n`).join('');
|
706
706
|
out = platformSpecific(makeIncludes(winIncludes), makeIncludes(unixIncludes), false) + '\n' + makeIncludes(includes) + '\n' + alwaysPreface + [...prepend.values()].join('\n') + '\n\n' + out;
|
707
707
|
|
708
|
-
return out.trim();
|
708
|
+
return `// generated by porffor ${globalThis.version ?? '0.17.0'}\n` + out.trim();
|
709
709
|
};
|
package/compiler/assemble.js
CHANGED
@@ -82,7 +82,17 @@ export default (funcs, globals, tags, pages, data, flags, noTreeshake = false) =
|
|
82
82
|
params.push(valtypeBinary, Valtype.i32);
|
83
83
|
}
|
84
84
|
|
85
|
-
|
85
|
+
if (inst.at(-1) === 'constr') {
|
86
|
+
inst.pop();
|
87
|
+
params.unshift(Valtype.i32);
|
88
|
+
}
|
89
|
+
|
90
|
+
let returns = [ valtypeBinary, Valtype.i32 ];
|
91
|
+
if (inst.at(-1) === 'no_type_return') {
|
92
|
+
inst.pop();
|
93
|
+
returns = [ valtypeBinary ];
|
94
|
+
}
|
95
|
+
|
86
96
|
inst[1] = getType(params, returns);
|
87
97
|
}
|
88
98
|
}
|
@@ -116,16 +126,21 @@ export default (funcs, globals, tags, pages, data, flags, noTreeshake = false) =
|
|
116
126
|
] ])
|
117
127
|
);
|
118
128
|
|
119
|
-
if (pages.has('func
|
120
|
-
// generate func
|
129
|
+
if (pages.has('func lut') && !data.addedFuncArgcLut) {
|
130
|
+
// generate func lut data
|
121
131
|
const bytes = [];
|
122
132
|
for (let i = 0; i < funcs.length; i++) {
|
123
133
|
const argc = Math.floor(funcs[i].params.length / 2);
|
124
134
|
bytes.push(argc % 256, (argc / 256 | 0) % 256);
|
135
|
+
|
136
|
+
let flags = 0b00000000; // 8 flag bits
|
137
|
+
if (funcs[i].returnType != null) flags |= 0b1;
|
138
|
+
if (funcs[i].constr) flags |= 0b10;
|
139
|
+
bytes.push(flags);
|
125
140
|
}
|
126
141
|
|
127
142
|
data.push({
|
128
|
-
offset: pages.get('func
|
143
|
+
offset: pages.get('func lut').ind * pageSize,
|
129
144
|
bytes
|
130
145
|
});
|
131
146
|
data.addedFuncArgcLut = true;
|
@@ -4,6 +4,7 @@ export const __Array_isArray = (x: unknown): boolean =>
|
|
4
4
|
// Porffor.wasm`local.get ${x+1}` == Porffor.TYPES.array;
|
5
5
|
Porffor.rawType(x) == Porffor.TYPES.array;
|
6
6
|
|
7
|
+
|
7
8
|
export const __Array_prototype_slice = (_this: any[], start: number, end: number) => {
|
8
9
|
const len: i32 = _this.length;
|
9
10
|
if (Porffor.rawType(end) == Porffor.TYPES.undefined) end = len;
|
@@ -22,7 +23,7 @@ export const __Array_prototype_slice = (_this: any[], start: number, end: number
|
|
22
23
|
}
|
23
24
|
if (end > len) end = len;
|
24
25
|
|
25
|
-
let out: any[] =
|
26
|
+
let out: any[] = Porffor.allocate();
|
26
27
|
|
27
28
|
if (start > end) return out;
|
28
29
|
|
@@ -42,10 +43,38 @@ export const __Array_prototype_slice = (_this: any[], start: number, end: number
|
|
42
43
|
}
|
43
44
|
|
44
45
|
out.length = end - start;
|
45
|
-
|
46
46
|
return out;
|
47
47
|
};
|
48
48
|
|
49
|
+
// @porf-typed-array
|
50
|
+
export const __Array_prototype_fill = (_this: any[], value: any, start: any, end: any) => {
|
51
|
+
const len: i32 = _this.length;
|
52
|
+
|
53
|
+
if (Porffor.rawType(start) == Porffor.TYPES.undefined) start = 0;
|
54
|
+
if (Porffor.rawType(end) == Porffor.TYPES.undefined) end = len;
|
55
|
+
|
56
|
+
start |= 0;
|
57
|
+
end |= 0;
|
58
|
+
|
59
|
+
if (start < 0) {
|
60
|
+
start = len + start;
|
61
|
+
if (start < 0) start = 0;
|
62
|
+
}
|
63
|
+
if (start > len) start = len;
|
64
|
+
if (end < 0) {
|
65
|
+
end = len + end;
|
66
|
+
if (end < 0) end = 0;
|
67
|
+
}
|
68
|
+
if (end > len) end = len;
|
69
|
+
|
70
|
+
for (let i: i32 = start; i < end; i++) {
|
71
|
+
_this[i] = value;
|
72
|
+
}
|
73
|
+
|
74
|
+
return _this;
|
75
|
+
};
|
76
|
+
|
77
|
+
// @porf-typed-array
|
49
78
|
export const __Array_prototype_indexOf = (_this: any[], searchElement: any, position: number) => {
|
50
79
|
const len: i32 = _this.length;
|
51
80
|
if (position > 0) {
|
@@ -60,6 +89,7 @@ export const __Array_prototype_indexOf = (_this: any[], searchElement: any, posi
|
|
60
89
|
return -1;
|
61
90
|
};
|
62
91
|
|
92
|
+
// @porf-typed-array
|
63
93
|
export const __Array_prototype_lastIndexOf = (_this: any[], searchElement: any, position: number) => {
|
64
94
|
const len: i32 = _this.length;
|
65
95
|
if (position > 0) {
|
@@ -74,6 +104,7 @@ export const __Array_prototype_lastIndexOf = (_this: any[], searchElement: any,
|
|
74
104
|
return -1;
|
75
105
|
};
|
76
106
|
|
107
|
+
// @porf-typed-array
|
77
108
|
export const __Array_prototype_includes = (_this: any[], searchElement: any, position: number) => {
|
78
109
|
const len: i32 = _this.length;
|
79
110
|
if (position > 0) {
|
@@ -88,6 +119,7 @@ export const __Array_prototype_includes = (_this: any[], searchElement: any, pos
|
|
88
119
|
return false;
|
89
120
|
};
|
90
121
|
|
122
|
+
// @porf-typed-array
|
91
123
|
export const __Array_prototype_with = (_this: any[], index: number, value: any) => {
|
92
124
|
const len: i32 = _this.length;
|
93
125
|
if (index < 0) {
|
@@ -101,8 +133,7 @@ export const __Array_prototype_with = (_this: any[], index: number, value: any)
|
|
101
133
|
throw new RangeError('Invalid index');
|
102
134
|
}
|
103
135
|
|
104
|
-
|
105
|
-
let out: any[] = [];
|
136
|
+
let out: any[] = Porffor.allocate();
|
106
137
|
|
107
138
|
Porffor.clone(_this, out);
|
108
139
|
|
@@ -111,6 +142,7 @@ export const __Array_prototype_with = (_this: any[], index: number, value: any)
|
|
111
142
|
return out;
|
112
143
|
};
|
113
144
|
|
145
|
+
// @porf-typed-array
|
114
146
|
export const __Array_prototype_reverse = (_this: any[]) => {
|
115
147
|
const len: i32 = _this.length;
|
116
148
|
|
@@ -126,14 +158,14 @@ export const __Array_prototype_reverse = (_this: any[]) => {
|
|
126
158
|
return _this;
|
127
159
|
};
|
128
160
|
|
129
|
-
//
|
161
|
+
// @porf-typed-array
|
130
162
|
export const __Array_prototype_toReversed = (_this: any[]) => {
|
131
163
|
const len: i32 = _this.length;
|
132
164
|
|
133
165
|
let start: i32 = 0;
|
134
166
|
let end: i32 = len - 1;
|
135
167
|
|
136
|
-
let out: any[] =
|
168
|
+
let out: any[] = Porffor.allocate();
|
137
169
|
out.length = len;
|
138
170
|
|
139
171
|
while (start < end) {
|
@@ -144,11 +176,13 @@ export const __Array_prototype_toReversed = (_this: any[]) => {
|
|
144
176
|
return out;
|
145
177
|
};
|
146
178
|
|
179
|
+
// @porf-typed-array
|
147
180
|
export const __Array_prototype_valueOf = (_this: any[]) => {
|
148
181
|
return _this;
|
149
182
|
};
|
150
183
|
|
151
184
|
|
185
|
+
// @porf-typed-array
|
152
186
|
export const __Array_prototype_forEach = (_this: any[], callbackFn: any) => {
|
153
187
|
const len: i32 = _this.length;
|
154
188
|
let i: i32 = 0;
|
@@ -157,22 +191,26 @@ export const __Array_prototype_forEach = (_this: any[], callbackFn: any) => {
|
|
157
191
|
}
|
158
192
|
};
|
159
193
|
|
194
|
+
// @porf-typed-array
|
160
195
|
export const __Array_prototype_filter = (_this: any[], callbackFn: any) => {
|
161
|
-
const out: any[] =
|
196
|
+
const out: any[] = Porffor.allocate();
|
162
197
|
|
163
198
|
const len: i32 = _this.length;
|
164
199
|
let i: i32 = 0;
|
200
|
+
let j: i32 = 0;
|
165
201
|
while (i < len) {
|
166
202
|
const el: any = _this[i];
|
167
|
-
if (Boolean(callbackFn(el, i++, _this))) out
|
203
|
+
if (Boolean(callbackFn(el, i++, _this))) out[j++] = el;
|
168
204
|
}
|
169
205
|
|
206
|
+
out.length = j;
|
170
207
|
return out;
|
171
208
|
};
|
172
209
|
|
210
|
+
// @porf-typed-array
|
173
211
|
export const __Array_prototype_map = (_this: any[], callbackFn: any) => {
|
174
212
|
const len: i32 = _this.length;
|
175
|
-
const out: any[] =
|
213
|
+
const out: any[] = Porffor.allocate();
|
176
214
|
out.length = len;
|
177
215
|
|
178
216
|
let i: i32 = 0;
|
@@ -183,6 +221,7 @@ export const __Array_prototype_map = (_this: any[], callbackFn: any) => {
|
|
183
221
|
return out;
|
184
222
|
};
|
185
223
|
|
224
|
+
// @porf-typed-array
|
186
225
|
export const __Array_prototype_find = (_this: any[], callbackFn: any) => {
|
187
226
|
const len: i32 = _this.length;
|
188
227
|
let i: i32 = 0;
|
@@ -192,6 +231,7 @@ export const __Array_prototype_find = (_this: any[], callbackFn: any) => {
|
|
192
231
|
}
|
193
232
|
};
|
194
233
|
|
234
|
+
// @porf-typed-array
|
195
235
|
export const __Array_prototype_findLast = (_this: any[], callbackFn: any) => {
|
196
236
|
let i: i32 = _this.length;
|
197
237
|
while (i > 0) {
|
@@ -200,6 +240,7 @@ export const __Array_prototype_findLast = (_this: any[], callbackFn: any) => {
|
|
200
240
|
}
|
201
241
|
};
|
202
242
|
|
243
|
+
// @porf-typed-array
|
203
244
|
export const __Array_prototype_findIndex = (_this: any[], callbackFn: any) => {
|
204
245
|
const len: i32 = _this.length;
|
205
246
|
let i: i32 = 0;
|
@@ -208,6 +249,7 @@ export const __Array_prototype_findIndex = (_this: any[], callbackFn: any) => {
|
|
208
249
|
}
|
209
250
|
};
|
210
251
|
|
252
|
+
// @porf-typed-array
|
211
253
|
export const __Array_prototype_findLastIndex = (_this: any[], callbackFn: any) => {
|
212
254
|
let i: i32 = _this.length;
|
213
255
|
while (i > 0) {
|
@@ -215,6 +257,7 @@ export const __Array_prototype_findLastIndex = (_this: any[], callbackFn: any) =
|
|
215
257
|
}
|
216
258
|
};
|
217
259
|
|
260
|
+
// @porf-typed-array
|
218
261
|
export const __Array_prototype_every = (_this: any[], callbackFn: any) => {
|
219
262
|
const len: i32 = _this.length;
|
220
263
|
let i: i32 = 0;
|
@@ -225,6 +268,7 @@ export const __Array_prototype_every = (_this: any[], callbackFn: any) => {
|
|
225
268
|
return true;
|
226
269
|
};
|
227
270
|
|
271
|
+
// @porf-typed-array
|
228
272
|
export const __Array_prototype_some = (_this: any[], callbackFn: any) => {
|
229
273
|
const len: i32 = _this.length;
|
230
274
|
let i: i32 = 0;
|
@@ -235,6 +279,7 @@ export const __Array_prototype_some = (_this: any[], callbackFn: any) => {
|
|
235
279
|
return false;
|
236
280
|
};
|
237
281
|
|
282
|
+
// @porf-typed-array
|
238
283
|
export const __Array_prototype_reduce = (_this: any[], callbackFn: any, initialValue: any) => {
|
239
284
|
let acc: any = initialValue ?? _this[0];
|
240
285
|
|
@@ -247,6 +292,7 @@ export const __Array_prototype_reduce = (_this: any[], callbackFn: any, initialV
|
|
247
292
|
return acc;
|
248
293
|
};
|
249
294
|
|
295
|
+
// @porf-typed-array
|
250
296
|
export const __Array_prototype_reduceRight = (_this: any[], callbackFn: any, initialValue: any) => {
|
251
297
|
const len: i32 = _this.length;
|
252
298
|
let acc: any = initialValue ?? _this[len - 1];
|
@@ -259,6 +305,52 @@ export const __Array_prototype_reduceRight = (_this: any[], callbackFn: any, ini
|
|
259
305
|
return acc;
|
260
306
|
};
|
261
307
|
|
308
|
+
// @porf-typed-array
|
309
|
+
export const __Array_prototype_sort = (_this: any[], callbackFn: any) => {
|
310
|
+
// todo: default callbackFn
|
311
|
+
|
312
|
+
// insertion sort, i guess
|
313
|
+
const len: i32 = _this.length;
|
314
|
+
for (let i: i32 = 0; i < len; i++) {
|
315
|
+
const x: any = _this[i];
|
316
|
+
let j: i32 = i;
|
317
|
+
while (j > 0) {
|
318
|
+
const y: any = _this[j - 1];
|
319
|
+
|
320
|
+
// 23.1.3.30.2 CompareArrayElements (x, y, comparefn)
|
321
|
+
// https://tc39.es/ecma262/#sec-comparearrayelements
|
322
|
+
const xt: i32 = Porffor.rawType(x);
|
323
|
+
const yt: i32 = Porffor.rawType(y);
|
324
|
+
let v: number;
|
325
|
+
|
326
|
+
// 1. If x and y are both undefined, return +0๐ฝ.
|
327
|
+
if (xt == Porffor.TYPES.undefined && yt == Porffor.TYPES.undefined) v = 0;
|
328
|
+
// 2. If x is undefined, return 1๐ฝ.
|
329
|
+
else if (xt == Porffor.TYPES.undefined) v = 1;
|
330
|
+
// 3. If y is undefined, return -1๐ฝ.
|
331
|
+
else if (yt == Porffor.TYPES.undefined) v = -1;
|
332
|
+
else {
|
333
|
+
// 4. If comparefn is not undefined, then
|
334
|
+
// a. Let v be ? ToNumber(? Call(comparefn, undefined, ยซ x, y ยป)).
|
335
|
+
v = callbackFn(x, y);
|
336
|
+
|
337
|
+
// b. If v is NaN, return +0๐ฝ.
|
338
|
+
// if (Number.isNaN(v)) v = 0;
|
339
|
+
|
340
|
+
// c. Return v.
|
341
|
+
}
|
342
|
+
|
343
|
+
if (v >= 0) break;
|
344
|
+
_this[j--] = y;
|
345
|
+
}
|
346
|
+
|
347
|
+
_this[j] = x;
|
348
|
+
}
|
349
|
+
|
350
|
+
return _this;
|
351
|
+
};
|
352
|
+
|
353
|
+
// @porf-typed-array
|
262
354
|
export const __Array_prototype_toString = (_this: any[]) => {
|
263
355
|
// todo: this is bytestring only!
|
264
356
|
|
@@ -283,6 +375,7 @@ export const __Array_prototype_toString = (_this: any[]) => {
|
|
283
375
|
return out;
|
284
376
|
};
|
285
377
|
|
378
|
+
// @porf-typed-array
|
286
379
|
export const __Array_prototype_join = (_this: any[], _separator: any) => {
|
287
380
|
// todo: this is bytestring only!
|
288
381
|
// todo/perf: optimize single char separators
|
@@ -718,108 +718,6 @@ export const __Porffor_date_write = (ptr: Date, val: number) => {
|
|
718
718
|
Porffor.wasm.f64.store(ptr, val, 0, 0);
|
719
719
|
};
|
720
720
|
|
721
|
-
// 21.4.2.1 Date (...values)
|
722
|
-
// https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date
|
723
|
-
export const Date$constructor = (v0: unknown, v1: unknown, v2: unknown, v3: unknown, v4: unknown, v5: unknown, v6: unknown): Date => {
|
724
|
-
// todo: passing undefined to params should not act like no arg was passed
|
725
|
-
|
726
|
-
// 2. Let numberOfArgs be the number of elements in values.
|
727
|
-
// sorry.
|
728
|
-
const numberOfArgs: i32 =
|
729
|
-
(Porffor.rawType(v0) != Porffor.TYPES.undefined) +
|
730
|
-
(Porffor.rawType(v1) != Porffor.TYPES.undefined) +
|
731
|
-
(Porffor.rawType(v2) != Porffor.TYPES.undefined) +
|
732
|
-
(Porffor.rawType(v3) != Porffor.TYPES.undefined) +
|
733
|
-
(Porffor.rawType(v4) != Porffor.TYPES.undefined) +
|
734
|
-
(Porffor.rawType(v5) != Porffor.TYPES.undefined) +
|
735
|
-
(Porffor.rawType(v6) != Porffor.TYPES.undefined);
|
736
|
-
|
737
|
-
let dv: number = 0;
|
738
|
-
|
739
|
-
// 3. If numberOfArgs = 0, then
|
740
|
-
if (numberOfArgs == 0) {
|
741
|
-
// a. Let dv be the time value (UTC) identifying the current time.
|
742
|
-
dv = __Date_now();
|
743
|
-
} else if (numberOfArgs == 1) {
|
744
|
-
// 4. Else if numberOfArgs = 1, the n
|
745
|
-
// a. Let value be values[0].
|
746
|
-
const value: any = v0;
|
747
|
-
|
748
|
-
const valueType: i32 = Porffor.rawType(v0);
|
749
|
-
|
750
|
-
let tv: number = 0;
|
751
|
-
|
752
|
-
// b. If value is an Object and value has a [[DateValue]] internal slot, then
|
753
|
-
if (valueType == Porffor.TYPES.date) {
|
754
|
-
// i. Let tv be value.[[DateValue]].
|
755
|
-
tv = __Porffor_date_read(value);
|
756
|
-
} else {
|
757
|
-
// c. Else,
|
758
|
-
// ii. If v is a String, then
|
759
|
-
if (Porffor.fastOr(valueType == Porffor.TYPES.string, valueType == Porffor.TYPES.bytestring)) {
|
760
|
-
// 1. Assert: The next step never returns an abrupt completion because v is a String.
|
761
|
-
|
762
|
-
// 2. Let tv be the result of parsing v as a date, in exactly the same manner as for the parse method (21.4.3.2).
|
763
|
-
tv = __Date_parse(value);
|
764
|
-
} else {
|
765
|
-
// iii. Else,
|
766
|
-
// 1. Let tv be ? ToNumber(v).
|
767
|
-
tv = Number(value);
|
768
|
-
}
|
769
|
-
}
|
770
|
-
|
771
|
-
// d. Let dv be TimeClip(tv).
|
772
|
-
dv = __ecma262_TimeClip(tv);
|
773
|
-
} else {
|
774
|
-
// 5. Else,
|
775
|
-
// a. Assert: numberOfArgs โฅ 2.
|
776
|
-
|
777
|
-
// b. Let y be ? ToNumber(values[0]).
|
778
|
-
const y: number = Number(v0);
|
779
|
-
|
780
|
-
// c. Let m be ? ToNumber(values[1]).
|
781
|
-
const m: number = Number(v1);
|
782
|
-
|
783
|
-
// d. If numberOfArgs > 2, let dt be ? ToNumber(values[2]); else let dt be 1๐ฝ.
|
784
|
-
let dt: number = 1;
|
785
|
-
if (numberOfArgs > 2) dt = Number(v2);
|
786
|
-
|
787
|
-
// e. If numberOfArgs > 3, let h be ? ToNumber(values[3]); else let h be +0๐ฝ.
|
788
|
-
let h: number = 0;
|
789
|
-
if (numberOfArgs > 3) h = Number(v3);
|
790
|
-
|
791
|
-
// f. If numberOfArgs > 4, let min be ? ToNumber(values[4]); else let min be +0๐ฝ.
|
792
|
-
let min: number = 0;
|
793
|
-
if (numberOfArgs > 4) min = Number(v4);
|
794
|
-
|
795
|
-
// g. If numberOfArgs > 5, let s be ? ToNumber(values[5]); else let s be +0๐ฝ.
|
796
|
-
let s: number = 0;
|
797
|
-
if (numberOfArgs > 5) s = Number(v5);
|
798
|
-
|
799
|
-
// h. If numberOfArgs > 6, let milli be ? ToNumber(values[6]); else let milli be +0๐ฝ.
|
800
|
-
let milli: number = 0;
|
801
|
-
if (numberOfArgs > 6) milli = Number(v6);
|
802
|
-
|
803
|
-
// i. Let yr be MakeFullYear(y).
|
804
|
-
const yr: number = __ecma262_MakeFullYear(y);
|
805
|
-
|
806
|
-
// j. Let finalDate be MakeDate(MakeDay(yr, m, dt), MakeTime(h, min, s, milli)).
|
807
|
-
const finalDate: number = __ecma262_MakeDate(__ecma262_MakeDay(yr, m, dt), __ecma262_MakeTime(h, min, s, milli));
|
808
|
-
|
809
|
-
// k. Let dv be TimeClip(UTC(finalDate)).
|
810
|
-
dv = __ecma262_TimeClip(__ecma262_UTC(finalDate));
|
811
|
-
}
|
812
|
-
|
813
|
-
// 6. Let O be ? OrdinaryCreateFromConstructor(NewTarget, "%Date.prototype%", ยซ [[DateValue]] ยป).
|
814
|
-
const O: Date = __Porffor_date_allocate();
|
815
|
-
|
816
|
-
// 7. Set O.[[DateValue]] to dv.
|
817
|
-
__Porffor_date_write(O, dv);
|
818
|
-
|
819
|
-
// 8. Return O.
|
820
|
-
return O;
|
821
|
-
};
|
822
|
-
|
823
721
|
|
824
722
|
// 21.4.4 Properties of the Date Prototype Object
|
825
723
|
// https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-properties-of-the-date-prototype-object
|
@@ -2034,9 +1932,109 @@ export const __Date_prototype_valueOf = (_this: Date) => {
|
|
2034
1932
|
|
2035
1933
|
// 21.4.2.1 Date (...values)
|
2036
1934
|
// https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date
|
2037
|
-
export const Date = (): bytestring
|
1935
|
+
export const Date = function (v0: unknown, v1: unknown, v2: unknown, v3: unknown, v4: unknown, v5: unknown, v6: unknown): bytestring|Date {
|
2038
1936
|
// 1. If NewTarget is undefined, then
|
2039
|
-
|
2040
|
-
|
2041
|
-
|
1937
|
+
if (!new.target) {
|
1938
|
+
// a. Let now be the time value (UTC) identifying the current time.
|
1939
|
+
// b. Return ToDateString(now).
|
1940
|
+
return __ecma262_ToDateString(__Date_now());
|
1941
|
+
}
|
1942
|
+
|
1943
|
+
// todo: passing undefined to params should not act like no arg was passed
|
1944
|
+
|
1945
|
+
// 2. Let numberOfArgs be the number of elements in values.
|
1946
|
+
// sorry.
|
1947
|
+
const numberOfArgs: i32 =
|
1948
|
+
(Porffor.rawType(v0) != Porffor.TYPES.undefined) +
|
1949
|
+
(Porffor.rawType(v1) != Porffor.TYPES.undefined) +
|
1950
|
+
(Porffor.rawType(v2) != Porffor.TYPES.undefined) +
|
1951
|
+
(Porffor.rawType(v3) != Porffor.TYPES.undefined) +
|
1952
|
+
(Porffor.rawType(v4) != Porffor.TYPES.undefined) +
|
1953
|
+
(Porffor.rawType(v5) != Porffor.TYPES.undefined) +
|
1954
|
+
(Porffor.rawType(v6) != Porffor.TYPES.undefined);
|
1955
|
+
|
1956
|
+
let dv: number = 0;
|
1957
|
+
|
1958
|
+
// 3. If numberOfArgs = 0, then
|
1959
|
+
if (numberOfArgs == 0) {
|
1960
|
+
// a. Let dv be the time value (UTC) identifying the current time.
|
1961
|
+
dv = __Date_now();
|
1962
|
+
} else if (numberOfArgs == 1) {
|
1963
|
+
// 4. Else if numberOfArgs = 1, the n
|
1964
|
+
// a. Let value be values[0].
|
1965
|
+
const value: any = v0;
|
1966
|
+
|
1967
|
+
const valueType: i32 = Porffor.rawType(v0);
|
1968
|
+
|
1969
|
+
let tv: number = 0;
|
1970
|
+
|
1971
|
+
// b. If value is an Object and value has a [[DateValue]] internal slot, then
|
1972
|
+
if (valueType == Porffor.TYPES.date) {
|
1973
|
+
// i. Let tv be value.[[DateValue]].
|
1974
|
+
tv = __Porffor_date_read(value);
|
1975
|
+
} else {
|
1976
|
+
// c. Else,
|
1977
|
+
// ii. If v is a String, then
|
1978
|
+
if (Porffor.fastOr(valueType == Porffor.TYPES.string, valueType == Porffor.TYPES.bytestring)) {
|
1979
|
+
// 1. Assert: The next step never returns an abrupt completion because v is a String.
|
1980
|
+
|
1981
|
+
// 2. Let tv be the result of parsing v as a date, in exactly the same manner as for the parse method (21.4.3.2).
|
1982
|
+
tv = __Date_parse(value);
|
1983
|
+
} else {
|
1984
|
+
// iii. Else,
|
1985
|
+
// 1. Let tv be ? ToNumber(v).
|
1986
|
+
tv = Number(value);
|
1987
|
+
}
|
1988
|
+
}
|
1989
|
+
|
1990
|
+
// d. Let dv be TimeClip(tv).
|
1991
|
+
dv = __ecma262_TimeClip(tv);
|
1992
|
+
} else {
|
1993
|
+
// 5. Else,
|
1994
|
+
// a. Assert: numberOfArgs โฅ 2.
|
1995
|
+
|
1996
|
+
// b. Let y be ? ToNumber(values[0]).
|
1997
|
+
const y: number = Number(v0);
|
1998
|
+
|
1999
|
+
// c. Let m be ? ToNumber(values[1]).
|
2000
|
+
const m: number = Number(v1);
|
2001
|
+
|
2002
|
+
// d. If numberOfArgs > 2, let dt be ? ToNumber(values[2]); else let dt be 1๐ฝ.
|
2003
|
+
let dt: number = 1;
|
2004
|
+
if (numberOfArgs > 2) dt = Number(v2);
|
2005
|
+
|
2006
|
+
// e. If numberOfArgs > 3, let h be ? ToNumber(values[3]); else let h be +0๐ฝ.
|
2007
|
+
let h: number = 0;
|
2008
|
+
if (numberOfArgs > 3) h = Number(v3);
|
2009
|
+
|
2010
|
+
// f. If numberOfArgs > 4, let min be ? ToNumber(values[4]); else let min be +0๐ฝ.
|
2011
|
+
let min: number = 0;
|
2012
|
+
if (numberOfArgs > 4) min = Number(v4);
|
2013
|
+
|
2014
|
+
// g. If numberOfArgs > 5, let s be ? ToNumber(values[5]); else let s be +0๐ฝ.
|
2015
|
+
let s: number = 0;
|
2016
|
+
if (numberOfArgs > 5) s = Number(v5);
|
2017
|
+
|
2018
|
+
// h. If numberOfArgs > 6, let milli be ? ToNumber(values[6]); else let milli be +0๐ฝ.
|
2019
|
+
let milli: number = 0;
|
2020
|
+
if (numberOfArgs > 6) milli = Number(v6);
|
2021
|
+
|
2022
|
+
// i. Let yr be MakeFullYear(y).
|
2023
|
+
const yr: number = __ecma262_MakeFullYear(y);
|
2024
|
+
|
2025
|
+
// j. Let finalDate be MakeDate(MakeDay(yr, m, dt), MakeTime(h, min, s, milli)).
|
2026
|
+
const finalDate: number = __ecma262_MakeDate(__ecma262_MakeDay(yr, m, dt), __ecma262_MakeTime(h, min, s, milli));
|
2027
|
+
|
2028
|
+
// k. Let dv be TimeClip(UTC(finalDate)).
|
2029
|
+
dv = __ecma262_TimeClip(__ecma262_UTC(finalDate));
|
2030
|
+
}
|
2031
|
+
|
2032
|
+
// 6. Let O be ? OrdinaryCreateFromConstructor(NewTarget, "%Date.prototype%", ยซ [[DateValue]] ยป).
|
2033
|
+
const O: Date = __Porffor_date_allocate();
|
2034
|
+
|
2035
|
+
// 7. Set O.[[DateValue]] to dv.
|
2036
|
+
__Porffor_date_write(O, dv);
|
2037
|
+
|
2038
|
+
// 8. Return O.
|
2039
|
+
return O;
|
2042
2040
|
};
|
@@ -1,11 +1,8 @@
|
|
1
1
|
export default () => {
|
2
2
|
let out = '';
|
3
3
|
|
4
|
-
const error = name => out += `export const ${name} = (message: bytestring)
|
5
|
-
|
6
|
-
};
|
7
|
-
|
8
|
-
export const ${name}$constructor = (message: bytestring) => {
|
4
|
+
const error = name => out += `export const ${name} = function (message: bytestring) {
|
5
|
+
new.target;
|
9
6
|
return {};
|
10
7
|
};`;
|
11
8
|
|
package/compiler/builtins/set.ts
CHANGED
@@ -8,6 +8,7 @@ memory.grow 0
|
|
8
8
|
i32.const 65536
|
9
9
|
i32.mul
|
10
10
|
i32.from_u
|
11
|
+
i32.const 0
|
11
12
|
return`;
|
12
13
|
};
|
13
14
|
|
@@ -163,11 +164,9 @@ export const __Set_prototype_clear = (_this: Set) => {
|
|
163
164
|
Porffor.wasm.i32.store(_this, 0, 0, 0);
|
164
165
|
};
|
165
166
|
|
166
|
-
export const Set = ()
|
167
|
-
throw new TypeError("Constructor Set requires 'new'");
|
168
|
-
};
|
167
|
+
export const Set = function (iterable: any): any {
|
168
|
+
if (!new.target) throw new TypeError("Constructor Set requires 'new'");
|
169
169
|
|
170
|
-
export const Set$constructor = (iterable: any): Set => {
|
171
170
|
const out: Set = __Porffor_allocate();
|
172
171
|
|
173
172
|
if (Porffor.rawType(iterable) != Porffor.TYPES.undefined) for (const x of iterable) {
|
@@ -182,7 +181,7 @@ export const __Set_prototype_union = (_this: Set, other: any) => {
|
|
182
181
|
throw new TypeError("Set.prototype.union\'s \'other\' argument must be a Set");
|
183
182
|
}
|
184
183
|
|
185
|
-
const out: Set = Set
|
184
|
+
const out: Set = new Set(_this);
|
186
185
|
for (const x of other) {
|
187
186
|
out.add(x);
|
188
187
|
}
|
@@ -1,10 +1,8 @@
|
|
1
|
-
|
2
|
-
export const String = (value: any): bytestring => {
|
3
|
-
if (Porffor.rawType(value) == Porffor.TYPES.symbol) return __Symbol_prototype_toString(value);
|
4
|
-
return __ecma262_ToString(value);
|
5
|
-
};
|
1
|
+
import type {} from './porffor.d.ts';
|
6
2
|
|
3
|
+
// todo: support non-bytestring properly
|
7
4
|
// todo: support constructor/string objects properly
|
8
|
-
export const String
|
5
|
+
export const String = function (value: any): bytestring {
|
6
|
+
if (!new.target && Porffor.rawType(value) == Porffor.TYPES.symbol) return __Symbol_prototype_toString(value);
|
9
7
|
return __ecma262_ToString(value);
|
10
8
|
};
|
@@ -17,7 +17,8 @@ export const __Porffor_symbol_descStore = (op: boolean, value: any): any => {
|
|
17
17
|
|
18
18
|
export const Symbol = (description: any): Symbol => {
|
19
19
|
// 1-based so always truthy as numeric value
|
20
|
-
|
20
|
+
const ptr: Symbol = __Porffor_symbol_descStore(true, description) + 1;
|
21
|
+
return ptr;
|
21
22
|
};
|
22
23
|
|
23
24
|
export const __Symbol_prototype_description$get = (_this: Symbol) => {
|