porffor 0.2.0-5ac7ea0 → 0.2.0-5c24120
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/CONTRIBUTING.md +256 -0
- package/LICENSE +20 -20
- package/README.md +115 -82
- package/asur/index.js +624 -340
- package/byg/index.js +237 -0
- package/compiler/2c.js +1 -1
- package/compiler/{sections.js → assemble.js} +59 -12
- package/compiler/builtins/annexb_string.js +72 -0
- package/compiler/builtins/annexb_string.ts +18 -0
- package/compiler/builtins/array.ts +145 -0
- package/compiler/builtins/base64.ts +7 -84
- package/compiler/builtins/boolean.ts +20 -0
- package/compiler/builtins/crypto.ts +29 -41
- package/compiler/builtins/date.ts +2070 -0
- package/compiler/builtins/escape.ts +141 -0
- package/compiler/builtins/function.ts +7 -0
- package/compiler/builtins/int.ts +147 -0
- package/compiler/builtins/number.ts +534 -0
- package/compiler/builtins/object.ts +6 -0
- package/compiler/builtins/porffor.d.ts +42 -9
- package/compiler/builtins/string.ts +1080 -0
- package/compiler/builtins.js +60 -87
- package/compiler/{codeGen.js → codegen.js} +848 -316
- package/compiler/decompile.js +0 -1
- package/compiler/embedding.js +22 -22
- package/compiler/encoding.js +108 -10
- package/compiler/generated_builtins.js +1499 -7
- package/compiler/index.js +16 -14
- package/compiler/log.js +2 -2
- package/compiler/opt.js +23 -22
- package/compiler/parse.js +30 -22
- package/compiler/precompile.js +26 -27
- package/compiler/prefs.js +7 -6
- package/compiler/prototype.js +16 -32
- package/compiler/types.js +37 -0
- package/compiler/wasmSpec.js +11 -1
- package/compiler/wrap.js +41 -44
- package/package.json +9 -5
- package/porf +2 -0
- package/rhemyn/compile.js +44 -26
- package/rhemyn/parse.js +322 -320
- package/rhemyn/test/parse.js +58 -58
- package/runner/compare.js +34 -34
- package/runner/debug.js +122 -0
- package/runner/index.js +69 -12
- package/runner/profiler.js +45 -26
- package/runner/repl.js +42 -9
- package/runner/sizes.js +37 -37
- package/runner/info.js +0 -89
- package/runner/transform.js +0 -15
- package/util/enum.js +0 -20
package/compiler/builtins.js
CHANGED
@@ -2,6 +2,7 @@ import { Blocktype, Opcodes, Valtype, ValtypeSize } from "./wasmSpec.js";
|
|
2
2
|
import { number, i32x4 } from "./embedding.js";
|
3
3
|
import Prefs from './prefs.js';
|
4
4
|
import * as GeneratedBuiltins from './generated_builtins.js';
|
5
|
+
import { TYPES } from './types.js';
|
5
6
|
|
6
7
|
export const importedFuncs = [
|
7
8
|
{
|
@@ -23,12 +24,24 @@ export const importedFuncs = [
|
|
23
24
|
returns: 1
|
24
25
|
},
|
25
26
|
{
|
26
|
-
name: '
|
27
|
+
name: 'timeOrigin',
|
28
|
+
import: 'u',
|
29
|
+
params: 0,
|
30
|
+
returns: 1
|
31
|
+
},
|
32
|
+
{
|
33
|
+
name: 'profile1',
|
34
|
+
import: 'y',
|
35
|
+
params: 1,
|
36
|
+
returns: 0
|
37
|
+
},
|
38
|
+
{
|
39
|
+
name: 'profile2',
|
27
40
|
import: 'z',
|
28
41
|
params: 1,
|
29
42
|
returns: 0
|
30
43
|
}
|
31
|
-
]
|
44
|
+
];
|
32
45
|
|
33
46
|
for (let i = 0; i < importedFuncs.length; i++) {
|
34
47
|
const f = importedFuncs[i];
|
@@ -58,10 +71,10 @@ export const NULL = 0;
|
|
58
71
|
|
59
72
|
export const BuiltinVars = function() {
|
60
73
|
this.undefined = number(UNDEFINED);
|
61
|
-
this.undefined.type =
|
74
|
+
this.undefined.type = TYPES.undefined;
|
62
75
|
|
63
76
|
this.null = number(NULL);
|
64
|
-
this.null.type =
|
77
|
+
this.null.type = TYPES.object;
|
65
78
|
|
66
79
|
this.NaN = number(NaN);
|
67
80
|
this.NaN.floatOnly = true;
|
@@ -128,7 +141,15 @@ export const BuiltinVars = function() {
|
|
128
141
|
|
129
142
|
// wintercg(tm)
|
130
143
|
this.__navigator_userAgent = (scope, { makeString }) => makeString(scope, `Porffor/0.2.0`, false, '__navigator_userAgent');
|
131
|
-
this.__navigator_userAgent.type = Prefs.bytestring ?
|
144
|
+
this.__navigator_userAgent.type = Prefs.bytestring ? TYPES.bytestring : TYPES.string;
|
145
|
+
|
146
|
+
for (const x in TYPES) {
|
147
|
+
this['__Porffor_TYPES_' + x] = number(TYPES[x]);
|
148
|
+
}
|
149
|
+
|
150
|
+
this.__performance_timeOrigin = [
|
151
|
+
[ Opcodes.call, importedFuncs.timeOrigin ]
|
152
|
+
];
|
132
153
|
};
|
133
154
|
|
134
155
|
export const BuiltinFuncs = function() {
|
@@ -187,19 +208,20 @@ export const BuiltinFuncs = function() {
|
|
187
208
|
params: [ valtypeBinary ],
|
188
209
|
locals: [],
|
189
210
|
returns: [ valtypeBinary ],
|
190
|
-
returnType:
|
211
|
+
returnType: TYPES.object,
|
191
212
|
wasm: [
|
192
|
-
[ Opcodes.local_get, 0 ]
|
213
|
+
// [ Opcodes.local_get, 0 ]
|
214
|
+
...number(1)
|
193
215
|
]
|
194
216
|
};
|
195
217
|
|
196
218
|
|
197
|
-
this.
|
219
|
+
this.__Porffor_print = {
|
198
220
|
params: [ valtypeBinary, Valtype.i32 ],
|
199
221
|
typedParams: true,
|
200
222
|
locals: [ Valtype.i32, Valtype.i32 ],
|
201
223
|
returns: [],
|
202
|
-
wasm: (scope, {
|
224
|
+
wasm: (scope, { typeSwitch }) => [
|
203
225
|
...typeSwitch(scope, [ [ Opcodes.local_get, 1 ] ], {
|
204
226
|
[TYPES.number]: [
|
205
227
|
[ Opcodes.local_get, 0 ],
|
@@ -251,7 +273,7 @@ export const BuiltinFuncs = function() {
|
|
251
273
|
|
252
274
|
[ Opcodes.end ]
|
253
275
|
],
|
254
|
-
[TYPES.
|
276
|
+
[TYPES.bytestring]: [
|
255
277
|
// simply print a (byte)string :))
|
256
278
|
// cache input pointer as i32
|
257
279
|
[ Opcodes.local_get, 0 ],
|
@@ -285,7 +307,7 @@ export const BuiltinFuncs = function() {
|
|
285
307
|
|
286
308
|
[ Opcodes.end ]
|
287
309
|
],
|
288
|
-
[TYPES.
|
310
|
+
[TYPES.array]: [
|
289
311
|
...printStaticStr('[ '),
|
290
312
|
|
291
313
|
// cache input pointer as i32
|
@@ -346,10 +368,7 @@ export const BuiltinFuncs = function() {
|
|
346
368
|
[ Opcodes.local_get, 0 ],
|
347
369
|
[ Opcodes.call, importedFuncs.print ],
|
348
370
|
]
|
349
|
-
}, Blocktype.void)
|
350
|
-
|
351
|
-
...char('\n'),
|
352
|
-
[ Opcodes.call, importedFuncs.printChar ]
|
371
|
+
}, Blocktype.void)
|
353
372
|
]
|
354
373
|
};
|
355
374
|
|
@@ -361,7 +380,7 @@ export const BuiltinFuncs = function() {
|
|
361
380
|
params: [ valtypeBinary ],
|
362
381
|
locals: [],
|
363
382
|
returns: [ valtypeBinary ],
|
364
|
-
returnType:
|
383
|
+
returnType: TYPES.boolean,
|
365
384
|
wasm: [
|
366
385
|
[ Opcodes.local_get, 0 ],
|
367
386
|
[ Opcodes.local_get, 0 ],
|
@@ -376,7 +395,7 @@ export const BuiltinFuncs = function() {
|
|
376
395
|
params: [ valtypeBinary ],
|
377
396
|
locals: [ valtypeBinary ],
|
378
397
|
returns: [ valtypeBinary ],
|
379
|
-
returnType:
|
398
|
+
returnType: TYPES.boolean,
|
380
399
|
wasm: [
|
381
400
|
[ Opcodes.local_get, 0 ],
|
382
401
|
[ Opcodes.local_get, 0 ],
|
@@ -395,7 +414,7 @@ export const BuiltinFuncs = function() {
|
|
395
414
|
params: [ valtypeBinary ],
|
396
415
|
locals: [],
|
397
416
|
returns: [ valtypeBinary ],
|
398
|
-
returnType:
|
417
|
+
returnType: TYPES.boolean,
|
399
418
|
wasm: [
|
400
419
|
[ Opcodes.local_get, 0 ],
|
401
420
|
[ Opcodes.local_get, 0 ],
|
@@ -410,7 +429,7 @@ export const BuiltinFuncs = function() {
|
|
410
429
|
params: [ valtypeBinary ],
|
411
430
|
locals: [],
|
412
431
|
returns: [ valtypeBinary ],
|
413
|
-
returnType:
|
432
|
+
returnType: TYPES.boolean,
|
414
433
|
wasm: [
|
415
434
|
[ Opcodes.local_get, 0 ],
|
416
435
|
[ Opcodes.local_get, 0 ],
|
@@ -896,28 +915,7 @@ export const BuiltinFuncs = function() {
|
|
896
915
|
]
|
897
916
|
};
|
898
917
|
|
899
|
-
this.
|
900
|
-
params: [],
|
901
|
-
locals: prng.locals,
|
902
|
-
localNames: [ 's1', 's0' ],
|
903
|
-
globals: prng.globals,
|
904
|
-
globalNames: [ 'state0', 'state1' ],
|
905
|
-
globalInits: [ prngSeed0, prngSeed1 ],
|
906
|
-
returns: [ Valtype.i32 ],
|
907
|
-
wasm: [
|
908
|
-
...prng.wasm,
|
909
|
-
|
910
|
-
...(prng.returns === Valtype.i64 ? [
|
911
|
-
// the lowest bits of the output generated by xorshift128+ have low quality
|
912
|
-
...number(56, Valtype.i64),
|
913
|
-
[ Opcodes.i64_shr_u ],
|
914
|
-
|
915
|
-
[ Opcodes.i32_wrap_i64 ],
|
916
|
-
] : []),
|
917
|
-
]
|
918
|
-
};
|
919
|
-
|
920
|
-
this.__Porffor_i32_randomByte = {
|
918
|
+
this.__Porffor_randomByte = {
|
921
919
|
params: [],
|
922
920
|
locals: prng.locals,
|
923
921
|
localNames: [ 's1', 's0' ],
|
@@ -1016,7 +1014,7 @@ export const BuiltinFuncs = function() {
|
|
1016
1014
|
params: [ valtypeBinary ],
|
1017
1015
|
locals: [],
|
1018
1016
|
returns: [ valtypeBinary ],
|
1019
|
-
returnType:
|
1017
|
+
returnType: TYPES.boolean,
|
1020
1018
|
wasm: [
|
1021
1019
|
[ Opcodes.local_get, 0 ],
|
1022
1020
|
...number(0),
|
@@ -1041,7 +1039,7 @@ export const BuiltinFuncs = function() {
|
|
1041
1039
|
typedParams: true,
|
1042
1040
|
locals: [ Valtype.i32, Valtype.i32 ],
|
1043
1041
|
returns: [ valtypeBinary ],
|
1044
|
-
returnType: Prefs.bytestring ?
|
1042
|
+
returnType: Prefs.bytestring ? TYPES.bytestring : TYPES.string,
|
1045
1043
|
wasm: (scope, { TYPE_NAMES, typeSwitch, makeString }) => {
|
1046
1044
|
const bc = {};
|
1047
1045
|
for (const x in TYPE_NAMES) {
|
@@ -1052,60 +1050,35 @@ export const BuiltinFuncs = function() {
|
|
1052
1050
|
}
|
1053
1051
|
};
|
1054
1052
|
|
1055
|
-
|
1056
|
-
const out = [];
|
1057
|
-
|
1058
|
-
for (let i = 0; i < arr.length; i++) {
|
1059
|
-
out.push(...getter, ...number(arr[i], valtype), valtype === Valtype.f64 ? [ Opcodes.f64_eq ] : [ Opcodes.i32_eq ]);
|
1060
|
-
if (i !== 0) out.push([ Opcodes.i32_or ]);
|
1061
|
-
}
|
1062
|
-
|
1063
|
-
return out;
|
1064
|
-
};
|
1065
|
-
|
1066
|
-
this.__Porffor_ptr = {
|
1053
|
+
this.__Porffor_rawType = {
|
1067
1054
|
params: [ valtypeBinary, Valtype.i32 ],
|
1068
1055
|
typedParams: true,
|
1069
|
-
locals: [
|
1056
|
+
locals: [],
|
1070
1057
|
returns: [ valtypeBinary ],
|
1071
|
-
wasm:
|
1072
|
-
|
1073
|
-
|
1074
|
-
[ Opcodes.local_get, 0 ],
|
1075
|
-
[ Opcodes.else ],
|
1076
|
-
...number(NaN),
|
1077
|
-
[ Opcodes.end ]
|
1078
|
-
]
|
1079
|
-
};
|
1080
|
-
|
1081
|
-
this.__Porffor_i32_ptr = {
|
1082
|
-
params: [ Valtype.i32, Valtype.i32 ],
|
1083
|
-
typedParams: true,
|
1084
|
-
locals: [ Valtype.i32, Valtype.i32 ],
|
1085
|
-
returns: [ Valtype.i32 ],
|
1086
|
-
wasm: (_scope, { TYPES }) => [
|
1087
|
-
...localIsOneOf([ [ Opcodes.local_get, 1 ] ], [ TYPES.string, TYPES._array, TYPES._bytestring ], Valtype.i32),
|
1088
|
-
[ Opcodes.if, Valtype.i32 ],
|
1089
|
-
[ Opcodes.local_get, 0 ],
|
1090
|
-
[ Opcodes.else ],
|
1091
|
-
...number(-1, Valtype.i32),
|
1092
|
-
[ Opcodes.end ]
|
1058
|
+
wasm: [
|
1059
|
+
[ Opcodes.local_get, 1 ],
|
1060
|
+
Opcodes.i32_from_u
|
1093
1061
|
]
|
1094
1062
|
};
|
1095
1063
|
|
1096
|
-
|
1097
|
-
|
1098
|
-
params: [ Valtype.i32 ],
|
1064
|
+
this.__Porffor_clone = {
|
1065
|
+
params: [ valtypeBinary, valtypeBinary ],
|
1099
1066
|
locals: [],
|
1100
|
-
returns: [
|
1067
|
+
returns: [],
|
1101
1068
|
wasm: [
|
1069
|
+
// dst
|
1070
|
+
[ Opcodes.local_get, 1 ],
|
1071
|
+
Opcodes.i32_to_u,
|
1072
|
+
|
1073
|
+
// src
|
1102
1074
|
[ Opcodes.local_get, 0 ],
|
1075
|
+
Opcodes.i32_to_u,
|
1076
|
+
|
1077
|
+
// size = pageSize
|
1078
|
+
...number(pageSize, Valtype.i32),
|
1079
|
+
[ ...Opcodes.memory_copy, 0x00, 0x00 ],
|
1103
1080
|
]
|
1104
1081
|
};
|
1105
1082
|
|
1106
|
-
|
1107
|
-
const generated = new GeneratedBuiltins.BuiltinFuncs();
|
1108
|
-
for (const x in generated) {
|
1109
|
-
this[x] = generated[x];
|
1110
|
-
}
|
1083
|
+
GeneratedBuiltins.BuiltinFuncs.call(this);
|
1111
1084
|
};
|