porffor 0.61.0 → 0.61.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/compiler/builtins/_internal_object.ts +1 -1
- package/compiler/builtins/annexb_string.js +5 -4
- package/compiler/builtins/array.ts +16 -16
- package/compiler/builtins/arraybuffer.ts +4 -4
- package/compiler/builtins/base64.ts +2 -2
- package/compiler/builtins/bigint.ts +5 -5
- package/compiler/builtins/crypto.ts +1 -1
- package/compiler/builtins/dataview.ts +1 -1
- package/compiler/builtins/date.ts +9 -9
- package/compiler/builtins/error.js +1 -1
- package/compiler/builtins/function.ts +1 -1
- package/compiler/builtins/json.ts +5 -5
- package/compiler/builtins/map.ts +5 -5
- package/compiler/builtins/number.ts +3 -3
- package/compiler/builtins/object.ts +8 -8
- package/compiler/builtins/porffor.d.ts +2 -2
- package/compiler/builtins/promise.ts +9 -9
- package/compiler/builtins/reflect.ts +1 -1
- package/compiler/builtins/regexp.ts +319 -388
- package/compiler/builtins/set.ts +2 -2
- package/compiler/builtins/string.ts +42 -42
- package/compiler/builtins/string_f64.ts +2 -2
- package/compiler/builtins/symbol.ts +2 -2
- package/compiler/builtins/typedarray.js +5 -5
- package/compiler/builtins/uint8array_base64.ts +2 -2
- package/compiler/builtins/uri.ts +145 -145
- package/compiler/builtins/weakmap.ts +3 -3
- package/compiler/builtins/weakref.ts +1 -1
- package/compiler/builtins/weakset.ts +1 -1
- package/compiler/builtins.js +43 -75
- package/compiler/builtins_precompiled.js +682 -676
- package/compiler/codegen.js +16 -11
- package/compiler/wrap.js +13 -0
- package/jsr.json +1 -1
- package/package.json +1 -1
- package/runtime/index.js +1 -1
|
@@ -18,10 +18,10 @@ export const __WeakMap_prototype_delete = (_this: WeakMap, key: any) => {
|
|
|
18
18
|
export const WeakMap = function (iterable: any): WeakMap {
|
|
19
19
|
if (!new.target) throw new TypeError("Constructor WeakMap requires 'new'");
|
|
20
20
|
|
|
21
|
-
const out: WeakMap = Porffor.
|
|
21
|
+
const out: WeakMap = Porffor.malloc(8);
|
|
22
22
|
|
|
23
|
-
const keys: any[] = Porffor.
|
|
24
|
-
const vals: any[] = Porffor.
|
|
23
|
+
const keys: any[] = Porffor.malloc();
|
|
24
|
+
const vals: any[] = Porffor.malloc();
|
|
25
25
|
Porffor.wasm.i32.store(out, keys, 0, 0);
|
|
26
26
|
Porffor.wasm.i32.store(out, vals, 0, 4);
|
|
27
27
|
|
|
@@ -5,7 +5,7 @@ export const WeakRef = function (target: any): WeakRef {
|
|
|
5
5
|
|
|
6
6
|
if (!Porffor.object.isObjectOrSymbol(target)) throw new TypeError('Target for WeakRef needs to be an object or symbol');
|
|
7
7
|
|
|
8
|
-
const out: WeakRef = Porffor.
|
|
8
|
+
const out: WeakRef = Porffor.malloc(9);
|
|
9
9
|
|
|
10
10
|
Porffor.wasm`local.get ${out}
|
|
11
11
|
i32.to_u
|
|
@@ -18,7 +18,7 @@ export const __WeakSet_prototype_delete = (_this: WeakSet, value: any) => {
|
|
|
18
18
|
export const WeakSet = function (iterable: any): WeakSet {
|
|
19
19
|
if (!new.target) throw new TypeError("Constructor WeakSet requires 'new'");
|
|
20
20
|
|
|
21
|
-
const out: WeakSet =
|
|
21
|
+
const out: WeakSet = Porffor.malloc();
|
|
22
22
|
if (iterable != null) for (const x of iterable) {
|
|
23
23
|
__WeakSet_prototype_add(out, x);
|
|
24
24
|
}
|
package/compiler/builtins.js
CHANGED
|
@@ -1022,89 +1022,50 @@ export const BuiltinFuncs = () => {
|
|
|
1022
1022
|
]
|
|
1023
1023
|
};
|
|
1024
1024
|
|
|
1025
|
-
_.
|
|
1026
|
-
|
|
1027
|
-
params: [],
|
|
1028
|
-
locals: [],
|
|
1029
|
-
returns: [ Valtype.i32 ],
|
|
1030
|
-
returnType: TYPES.number,
|
|
1031
|
-
wasm: () => [
|
|
1032
|
-
number(1, Valtype.i32),
|
|
1033
|
-
[ Opcodes.memory_grow, 0 ],
|
|
1034
|
-
number(PageSize, Valtype.i32),
|
|
1035
|
-
[ Opcodes.i32_mul ]
|
|
1036
|
-
]
|
|
1037
|
-
},
|
|
1038
|
-
chunk: {
|
|
1039
|
-
params: [],
|
|
1040
|
-
locals: [],
|
|
1041
|
-
globalInits: { chunkPtr: 0, chunkOffset: 100 * PageSize },
|
|
1042
|
-
returns: [ Valtype.i32 ],
|
|
1043
|
-
returnType: TYPES.number,
|
|
1044
|
-
wasm: (scope, { glbl }) => [
|
|
1045
|
-
// if chunkOffset >= chunks:
|
|
1046
|
-
...glbl(Opcodes.global_get, 'chunkOffset', Valtype.i32),
|
|
1047
|
-
number(PageSize * (Prefs.allocatorChunks ?? 16), Valtype.i32),
|
|
1048
|
-
[ Opcodes.i32_ge_s ],
|
|
1049
|
-
[ Opcodes.if, Valtype.i32 ],
|
|
1050
|
-
// chunkOffset = 1 page
|
|
1051
|
-
number(pageSize, Valtype.i32),
|
|
1052
|
-
...glbl(Opcodes.global_set, 'chunkOffset', Valtype.i32),
|
|
1053
|
-
|
|
1054
|
-
// return chunkPtr = allocated
|
|
1055
|
-
number(Prefs.allocatorChunks ?? 16, Valtype.i32),
|
|
1056
|
-
[ Opcodes.memory_grow, 0 ],
|
|
1057
|
-
number(PageSize, Valtype.i32),
|
|
1058
|
-
[ Opcodes.i32_mul ],
|
|
1059
|
-
...glbl(Opcodes.global_set, 'chunkPtr', Valtype.i32),
|
|
1060
|
-
...glbl(Opcodes.global_get, 'chunkPtr', Valtype.i32),
|
|
1061
|
-
[ Opcodes.else ],
|
|
1062
|
-
// return chunkPtr + chunkOffset
|
|
1063
|
-
...glbl(Opcodes.global_get, 'chunkPtr', Valtype.i32),
|
|
1064
|
-
...glbl(Opcodes.global_get, 'chunkOffset', Valtype.i32),
|
|
1065
|
-
[ Opcodes.i32_add ],
|
|
1066
|
-
|
|
1067
|
-
// chunkOffset += 1 page
|
|
1068
|
-
number(pageSize, Valtype.i32),
|
|
1069
|
-
...glbl(Opcodes.global_get, 'chunkOffset', Valtype.i32),
|
|
1070
|
-
[ Opcodes.i32_add ],
|
|
1071
|
-
...glbl(Opcodes.global_set, 'chunkOffset', Valtype.i32),
|
|
1072
|
-
[ Opcodes.end ]
|
|
1073
|
-
]
|
|
1074
|
-
}
|
|
1075
|
-
})[Prefs.allocator ?? 'chunk'];
|
|
1076
|
-
|
|
1077
|
-
_.__Porffor_allocateBytes = {
|
|
1025
|
+
_.__Porffor_malloc = {
|
|
1026
|
+
defaultParam: () => ({ type: 'Literal', value: pageSize }),
|
|
1078
1027
|
params: [ Valtype.i32 ],
|
|
1079
1028
|
locals: [],
|
|
1080
|
-
globalInits: { currentPtr: 0, bytesWritten: pageSize }, // init to pageSize so we always allocate on first call
|
|
1081
1029
|
returns: [ Valtype.i32 ],
|
|
1082
1030
|
returnType: TYPES.number,
|
|
1083
1031
|
wasm: (scope, { builtin, glbl }) => [
|
|
1084
|
-
// if
|
|
1085
|
-
...glbl(Opcodes.global_get, '
|
|
1086
|
-
|
|
1032
|
+
// if currentPtr + bytesToAllocate >= endPtr
|
|
1033
|
+
...glbl(Opcodes.global_get, 'currentPtr', Valtype.i32),
|
|
1034
|
+
[ Opcodes.local_get, 0 ],
|
|
1035
|
+
[ Opcodes.i32_add ],
|
|
1036
|
+
...glbl(Opcodes.global_get, 'endPtr', Valtype.i32),
|
|
1087
1037
|
[ Opcodes.i32_ge_s ],
|
|
1088
1038
|
[ Opcodes.if, Valtype.i32 ],
|
|
1089
|
-
//
|
|
1039
|
+
// currentPtr = newly allocated pages + bytesToAllocate
|
|
1040
|
+
number(Prefs.allocatorChunks ?? 16, Valtype.i32),
|
|
1041
|
+
[ Opcodes.memory_grow, 0 ],
|
|
1042
|
+
number(PageSize, Valtype.i32),
|
|
1043
|
+
[ Opcodes.i32_mul ],
|
|
1090
1044
|
[ Opcodes.local_get, 0 ],
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
// return currentPtr = newly allocated page
|
|
1094
|
-
[ Opcodes.call, builtin('__Porffor_allocate') ],
|
|
1045
|
+
[ Opcodes.i32_add ],
|
|
1095
1046
|
...glbl(Opcodes.global_set, 'currentPtr', Valtype.i32),
|
|
1096
1047
|
...glbl(Opcodes.global_get, 'currentPtr', Valtype.i32),
|
|
1048
|
+
|
|
1049
|
+
// endPtr = currentPtr + limit - bytesToAllocate
|
|
1050
|
+
number((Prefs.allocatorChunks ?? 16) * PageSize, Valtype.i32),
|
|
1051
|
+
[ Opcodes.i32_add ],
|
|
1052
|
+
[ Opcodes.local_get, 0 ],
|
|
1053
|
+
[ Opcodes.i32_sub ],
|
|
1054
|
+
...glbl(Opcodes.global_set, 'endPtr', Valtype.i32),
|
|
1055
|
+
|
|
1056
|
+
// return currentPtr - bytesToAllocate
|
|
1057
|
+
...glbl(Opcodes.global_get, 'currentPtr', Valtype.i32),
|
|
1058
|
+
[ Opcodes.local_get, 0 ],
|
|
1059
|
+
[ Opcodes.i32_sub ],
|
|
1097
1060
|
[ Opcodes.else ],
|
|
1098
|
-
// return currentPtr
|
|
1061
|
+
// return currentPtr
|
|
1099
1062
|
...glbl(Opcodes.global_get, 'currentPtr', Valtype.i32),
|
|
1100
|
-
...glbl(Opcodes.global_get, 'bytesWritten', Valtype.i32),
|
|
1101
|
-
[ Opcodes.i32_add ],
|
|
1102
1063
|
|
|
1103
|
-
//
|
|
1064
|
+
// currentPtr = currentPtr + bytesToAllocate
|
|
1065
|
+
...glbl(Opcodes.global_get, 'currentPtr', Valtype.i32),
|
|
1104
1066
|
[ Opcodes.local_get, 0 ],
|
|
1105
|
-
...glbl(Opcodes.global_get, 'bytesWritten', Valtype.i32),
|
|
1106
1067
|
[ Opcodes.i32_add ],
|
|
1107
|
-
...glbl(Opcodes.global_set, '
|
|
1068
|
+
...glbl(Opcodes.global_set, 'currentPtr', Valtype.i32),
|
|
1108
1069
|
[ Opcodes.end ]
|
|
1109
1070
|
]
|
|
1110
1071
|
};
|
|
@@ -1116,14 +1077,21 @@ export const BuiltinFuncs = () => {
|
|
|
1116
1077
|
returns: [ Valtype.i32 ],
|
|
1117
1078
|
returnType: TYPES.string,
|
|
1118
1079
|
wasm: (scope, { builtin }) => [
|
|
1119
|
-
//
|
|
1120
|
-
[ Opcodes.call, builtin('__Porffor_allocate') ],
|
|
1121
|
-
[ Opcodes.local_tee, 3 ],
|
|
1122
|
-
|
|
1123
|
-
// dst.length = src.length
|
|
1080
|
+
// len = src.length
|
|
1124
1081
|
[ Opcodes.local_get, 0 ],
|
|
1125
1082
|
[ Opcodes.i32_load, 0, 0 ],
|
|
1126
1083
|
[ Opcodes.local_tee, 1 ],
|
|
1084
|
+
|
|
1085
|
+
// dst = malloc(4 + len * 2)
|
|
1086
|
+
number(2, Valtype.i32),
|
|
1087
|
+
[ Opcodes.i32_mul ],
|
|
1088
|
+
number(4, Valtype.i32),
|
|
1089
|
+
[ Opcodes.i32_add ],
|
|
1090
|
+
[ Opcodes.call, builtin('__Porffor_malloc') ],
|
|
1091
|
+
[ Opcodes.local_tee, 3 ],
|
|
1092
|
+
|
|
1093
|
+
// dst.length = len
|
|
1094
|
+
[ Opcodes.local_get, 1 ],
|
|
1127
1095
|
[ Opcodes.i32_store, 0, 0 ],
|
|
1128
1096
|
|
|
1129
1097
|
[ Opcodes.loop, Blocktype.void ],
|
|
@@ -1257,7 +1225,7 @@ export const BuiltinFuncs = () => {
|
|
|
1257
1225
|
[ Opcodes.end ],
|
|
1258
1226
|
|
|
1259
1227
|
number(16, Valtype.i32),
|
|
1260
|
-
[ Opcodes.call, builtin('
|
|
1228
|
+
[ Opcodes.call, builtin('__Porffor_malloc') ],
|
|
1261
1229
|
[ Opcodes.local_tee, 3 ],
|
|
1262
1230
|
|
|
1263
1231
|
// sign is already 0
|
|
@@ -1319,7 +1287,7 @@ export const BuiltinFuncs = () => {
|
|
|
1319
1287
|
[ Opcodes.end ],
|
|
1320
1288
|
|
|
1321
1289
|
number(16, Valtype.i32),
|
|
1322
|
-
[ Opcodes.call, builtin('
|
|
1290
|
+
[ Opcodes.call, builtin('__Porffor_malloc') ],
|
|
1323
1291
|
[ Opcodes.local_tee, 3 ],
|
|
1324
1292
|
|
|
1325
1293
|
// sign = x != abs
|