porffor 0.17.0-30b9c5fa5 → 0.17.0-3d806f394
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/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 +2 -2
- package/compiler/codegen.js +379 -123
- package/compiler/generated_builtins.js +2703 -702
- 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/compile.js +49 -16
@@ -1,11 +1,12 @@
|
|
1
|
-
export default () => {
|
1
|
+
export default async () => {
|
2
2
|
let out = '';
|
3
3
|
|
4
|
-
const
|
5
|
-
|
6
|
-
|
4
|
+
const arrayCode = (await import('node:fs')).readFileSync(globalThis.precompileCompilerPath + '/builtins/array.ts', 'utf8');
|
5
|
+
const typedArrayFuncs = [...arrayCode.matchAll(/\/\/ @porf-typed-array[\s\S]+?^};$/gm)].map(x => x[0]);
|
6
|
+
|
7
|
+
const constr = name => out += `export const ${name} = function (arg: any): ${name} {
|
8
|
+
if (!new.target) throw new TypeError("Constructor ${name} requires 'new'");
|
7
9
|
|
8
|
-
export const ${name}$constructor = (arg: any): ${name} => {
|
9
10
|
const out: ${name} = Porffor.allocate();
|
10
11
|
let len: i32 = 0;
|
11
12
|
|
@@ -26,7 +27,58 @@ export const ${name}$constructor = (arg: any): ${name} => {
|
|
26
27
|
|
27
28
|
out.length = len;
|
28
29
|
return out;
|
29
|
-
}
|
30
|
+
};
|
31
|
+
|
32
|
+
export const __${name}_prototype_byteLength$get = (_this: ${name}) => {
|
33
|
+
return _this.length * ${name}.BYTES_PER_ELEMENT;
|
34
|
+
};
|
35
|
+
|
36
|
+
export const __${name}_prototype_at = (_this: ${name}, index: number) => {
|
37
|
+
const len: i32 = _this.length;
|
38
|
+
index |= 0;
|
39
|
+
if (index < 0) {
|
40
|
+
index = len + index;
|
41
|
+
if (index < 0) return undefined;
|
42
|
+
}
|
43
|
+
if (index >= len) return undefined;
|
44
|
+
|
45
|
+
return _this[index];
|
46
|
+
};
|
47
|
+
|
48
|
+
export const __${name}_prototype_slice = (_this: ${name}, start: number, end: number) => {
|
49
|
+
const len: i32 = _this.length;
|
50
|
+
if (Porffor.rawType(end) == Porffor.TYPES.undefined) end = len;
|
51
|
+
|
52
|
+
start |= 0;
|
53
|
+
end |= 0;
|
54
|
+
|
55
|
+
if (start < 0) {
|
56
|
+
start = len + start;
|
57
|
+
if (start < 0) start = 0;
|
58
|
+
}
|
59
|
+
if (start > len) start = len;
|
60
|
+
if (end < 0) {
|
61
|
+
end = len + end;
|
62
|
+
if (end < 0) end = 0;
|
63
|
+
}
|
64
|
+
if (end > len) end = len;
|
65
|
+
|
66
|
+
let out: ${name} = Porffor.allocate();
|
67
|
+
|
68
|
+
if (start > end) return out;
|
69
|
+
|
70
|
+
let i: i32 = start;
|
71
|
+
let j: i32 = 0;
|
72
|
+
while (i < end) {
|
73
|
+
out[j++] = _this[i++];
|
74
|
+
}
|
75
|
+
|
76
|
+
out.length = end - start;
|
77
|
+
return out;
|
78
|
+
};
|
79
|
+
|
80
|
+
${typedArrayFuncs.reduce((acc, x) => acc + x.replace('// @porf-typed-array\n', '').replaceAll('Array', name).replaceAll('any[]', name) + '\n\n', '')}
|
81
|
+
`;
|
30
82
|
|
31
83
|
constr('Uint8Array');
|
32
84
|
constr('Int8Array');
|
package/compiler/builtins.js
CHANGED
@@ -161,7 +161,6 @@ export const BuiltinVars = function() {
|
|
161
161
|
[ Opcodes.call, importedFuncs.timeOrigin ]
|
162
162
|
];
|
163
163
|
|
164
|
-
|
165
164
|
this.__Uint8Array_BYTES_PER_ELEMENT = number(1);
|
166
165
|
this.__Int8Array_BYTES_PER_ELEMENT = number(1);
|
167
166
|
this.__Uint8ClampedArray_BYTES_PER_ELEMENT = number(1);
|
@@ -205,7 +204,8 @@ export const BuiltinFuncs = function() {
|
|
205
204
|
...number(TYPES.number, Valtype.i32),
|
206
205
|
[ Opcodes.local_get, 1 ],
|
207
206
|
...number(TYPES.number, Valtype.i32),
|
208
|
-
[ Opcodes.call, builtin('__Math_pow') ]
|
207
|
+
[ Opcodes.call, builtin('__Math_pow') ],
|
208
|
+
[ Opcodes.drop ],
|
209
209
|
]
|
210
210
|
};
|
211
211
|
|