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
@@ -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
@@ -150,7 +150,7 @@ export const BuiltinVars = function() {
|
|
150
150
|
this.Math = number(1);
|
151
151
|
|
152
152
|
// wintercg(tm)
|
153
|
-
this.__navigator_userAgent = (scope, { makeString }) => makeString(scope, `Porffor
|
153
|
+
this.__navigator_userAgent = (scope, { makeString }) => makeString(scope, `Porffor/${globalThis.version ?? '0.17.0'}`, false, '__navigator_userAgent');
|
154
154
|
this.__navigator_userAgent.type = Prefs.bytestring ? TYPES.bytestring : TYPES.string;
|
155
155
|
|
156
156
|
for (const x in TYPES) {
|
@@ -160,6 +160,16 @@ export const BuiltinVars = function() {
|
|
160
160
|
this.__performance_timeOrigin = [
|
161
161
|
[ Opcodes.call, importedFuncs.timeOrigin ]
|
162
162
|
];
|
163
|
+
|
164
|
+
this.__Uint8Array_BYTES_PER_ELEMENT = number(1);
|
165
|
+
this.__Int8Array_BYTES_PER_ELEMENT = number(1);
|
166
|
+
this.__Uint8ClampedArray_BYTES_PER_ELEMENT = number(1);
|
167
|
+
this.__Uint16Array_BYTES_PER_ELEMENT = number(2);
|
168
|
+
this.__Int16Array_BYTES_PER_ELEMENT = number(2);
|
169
|
+
this.__Uint32Array_BYTES_PER_ELEMENT = number(4);
|
170
|
+
this.__Int32Array_BYTES_PER_ELEMENT = number(4);
|
171
|
+
this.__Float32Array_BYTES_PER_ELEMENT = number(4);
|
172
|
+
this.__Float64Array_BYTES_PER_ELEMENT = number(8);
|
163
173
|
};
|
164
174
|
|
165
175
|
export const BuiltinFuncs = function() {
|
@@ -194,7 +204,8 @@ export const BuiltinFuncs = function() {
|
|
194
204
|
...number(TYPES.number, Valtype.i32),
|
195
205
|
[ Opcodes.local_get, 1 ],
|
196
206
|
...number(TYPES.number, Valtype.i32),
|
197
|
-
[ Opcodes.call, builtin('__Math_pow') ]
|
207
|
+
[ Opcodes.call, builtin('__Math_pow') ],
|
208
|
+
[ Opcodes.drop ],
|
198
209
|
]
|
199
210
|
};
|
200
211
|
|