porffor 0.2.0-e04e26f → 0.2.0-e62542f
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 +254 -0
- package/README.md +63 -44
- package/asur/index.js +1 -1
- package/compiler/assemble.js +1 -1
- package/compiler/builtins/annexb_string.js +2 -2
- package/compiler/builtins/annexb_string.ts +5 -6
- package/compiler/builtins/array.ts +10 -10
- package/compiler/builtins/base64.ts +4 -79
- package/compiler/builtins/crypto.ts +1 -1
- package/compiler/builtins/date.ts +1292 -349
- package/compiler/builtins/escape.ts +2 -2
- package/compiler/builtins/int.ts +3 -3
- package/compiler/builtins/number.ts +1 -1
- package/compiler/builtins/porffor.d.ts +21 -4
- package/compiler/builtins/string.ts +22 -22
- package/compiler/builtins/tostring.ts +4 -4
- package/compiler/builtins.js +6 -30
- package/compiler/codegen.js +138 -68
- package/compiler/decompile.js +0 -1
- package/compiler/generated_builtins.js +499 -154
- package/compiler/parse.js +4 -2
- package/compiler/precompile.js +7 -2
- package/compiler/prefs.js +6 -5
- package/compiler/prototype.js +14 -14
- package/compiler/types.js +1 -1
- package/compiler/wrap.js +3 -3
- package/package.json +1 -1
- package/rhemyn/compile.js +42 -25
- package/rhemyn/parse.js +4 -5
- package/runner/index.js +45 -4
- package/runner/repl.js +2 -2
- package/runner/sizes.js +1 -1
@@ -1,4 +1,4 @@
|
|
1
|
-
// @porf
|
1
|
+
// @porf --funsafe-no-unlikely-proto-checks --valtype=i32
|
2
2
|
|
3
3
|
import type {} from './porffor';
|
4
4
|
|
@@ -13,7 +13,7 @@ export const escape = (input: string|bytestring): bytestring => {
|
|
13
13
|
|
14
14
|
let i: i32 = Porffor.wasm`local.get ${input}`;
|
15
15
|
|
16
|
-
if (Porffor.wasm`local.get ${input+1}` == Porffor.TYPES.
|
16
|
+
if (Porffor.wasm`local.get ${input+1}` == Porffor.TYPES.bytestring) {
|
17
17
|
const endPtr: i32 = i + len;
|
18
18
|
while (i < endPtr) {
|
19
19
|
const chr: i32 = Porffor.wasm.i32.load8_u(i++, 0, 4);
|
package/compiler/builtins/int.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
// @porf
|
1
|
+
// @porf --funsafe-no-unlikely-proto-checks
|
2
2
|
|
3
3
|
// radix: number|any for rawType check
|
4
4
|
// export const parseInt = (input: string|bytestring, radix: number|any): f64 => {
|
@@ -17,7 +17,7 @@ export const parseInt = (input: string|bytestring, radix: number): f64 => {
|
|
17
17
|
let nMax: f64 = 58;
|
18
18
|
if (radix < 10) nMax = 48 + radix;
|
19
19
|
|
20
|
-
// if (Porffor.rawType(input) == Porffor.TYPES.
|
20
|
+
// if (Porffor.rawType(input) == Porffor.TYPES.bytestring) input = __ByteString_prototype_trimStart(input);
|
21
21
|
// else input = __String_prototype_trimStart(input);
|
22
22
|
|
23
23
|
let n: f64 = NaN;
|
@@ -28,7 +28,7 @@ export const parseInt = (input: string|bytestring, radix: number): f64 => {
|
|
28
28
|
|
29
29
|
let negative: boolean = false;
|
30
30
|
|
31
|
-
if (Porffor.rawType(input) == Porffor.TYPES.
|
31
|
+
if (Porffor.rawType(input) == Porffor.TYPES.bytestring) {
|
32
32
|
const endPtr: f64 = i + len;
|
33
33
|
|
34
34
|
// check start of string
|
@@ -7,23 +7,40 @@ type PorfforGlobal = {
|
|
7
7
|
wasm: {
|
8
8
|
(...args: any[]): any;
|
9
9
|
i32: {
|
10
|
-
or(a: i32, b: i32): i32;
|
11
|
-
|
12
10
|
load(pointer: i32, align: i32, offset: i32): i32;
|
13
11
|
store(pointer: i32, value: i32, align: i32, offset: i32): i32;
|
14
12
|
load8_u(pointer: i32, align: i32, offset: i32): i32;
|
15
13
|
store8(pointer: i32, value: i32, align: i32, offset: i32): i32;
|
16
14
|
load16_u(pointer: i32, align: i32, offset: i32): i32;
|
17
15
|
store16(pointer: i32, value: i32, align: i32, offset: i32): i32;
|
16
|
+
const(value: i32): i32;
|
17
|
+
}
|
18
|
+
|
19
|
+
f64: {
|
20
|
+
load(pointer: i32, align: i32, offset: i32): i32;
|
21
|
+
store(pointer: i32, value: f64, align: i32, offset: i32): f64;
|
18
22
|
}
|
19
23
|
}
|
20
24
|
|
21
|
-
// randomInt(): i32;
|
22
25
|
randomByte(): i32;
|
23
26
|
|
24
27
|
type(x: any): bytestring;
|
25
28
|
rawType(x: any): i32;
|
26
|
-
TYPES:
|
29
|
+
TYPES: {
|
30
|
+
number: i32;
|
31
|
+
boolean: i32;
|
32
|
+
string: i32;
|
33
|
+
undefined: i32;
|
34
|
+
object: i32;
|
35
|
+
function: i32;
|
36
|
+
symbol: i32;
|
37
|
+
bigint: i32;
|
38
|
+
|
39
|
+
_array: i32;
|
40
|
+
_regexp: i32;
|
41
|
+
_bytestring: i32;
|
42
|
+
_date: i32;
|
43
|
+
}
|
27
44
|
|
28
45
|
fastOr(...args: any): boolean;
|
29
46
|
fastAnd(...args: any): boolean;
|
@@ -1,4 +1,4 @@
|
|
1
|
-
// @porf
|
1
|
+
// @porf --funsafe-no-unlikely-proto-checks --valtype=i32
|
2
2
|
|
3
3
|
export const __String_fromCharCode = (code: i32) => {
|
4
4
|
// todo: support >1 arg
|
@@ -37,7 +37,7 @@ export const __String_prototype_toUpperCase = (_this: string) => {
|
|
37
37
|
return out;
|
38
38
|
};
|
39
39
|
|
40
|
-
export const
|
40
|
+
export const __ByteString_prototype_toUpperCase = (_this: bytestring) => {
|
41
41
|
const len: i32 = _this.length;
|
42
42
|
|
43
43
|
let out: bytestring = '';
|
@@ -83,7 +83,7 @@ export const __String_prototype_toLowerCase = (_this: string) => {
|
|
83
83
|
return out;
|
84
84
|
};
|
85
85
|
|
86
|
-
export const
|
86
|
+
export const __ByteString_prototype_toLowerCase = (_this: bytestring) => {
|
87
87
|
const len: i32 = _this.length;
|
88
88
|
|
89
89
|
let out: bytestring = '';
|
@@ -134,10 +134,10 @@ export const __String_prototype_startsWith = (_this: string, searchString: strin
|
|
134
134
|
return true;
|
135
135
|
};
|
136
136
|
|
137
|
-
export const
|
137
|
+
export const __ByteString_prototype_startsWith = (_this: bytestring, searchString: bytestring, position: number) => {
|
138
138
|
// if searching non-bytestring, bytestring will not start with it
|
139
139
|
// todo: change this to just check if = string and ToString others
|
140
|
-
if (Porffor.wasm`local.get ${searchString+1}` != Porffor.TYPES.
|
140
|
+
if (Porffor.wasm`local.get ${searchString+1}` != Porffor.TYPES.bytestring) return false;
|
141
141
|
|
142
142
|
// todo/perf: investigate whether for counter vs while ++s are faster
|
143
143
|
|
@@ -204,10 +204,10 @@ export const __String_prototype_endsWith = (_this: string, searchString: string,
|
|
204
204
|
return true;
|
205
205
|
};
|
206
206
|
|
207
|
-
export const
|
207
|
+
export const __ByteString_prototype_endsWith = (_this: bytestring, searchString: bytestring, endPosition: number) => {
|
208
208
|
// if searching non-bytestring, bytestring will not start with it
|
209
209
|
// todo: change this to just check if = string and ToString others
|
210
|
-
if (Porffor.wasm`local.get ${searchString+1}` != Porffor.TYPES.
|
210
|
+
if (Porffor.wasm`local.get ${searchString+1}` != Porffor.TYPES.bytestring) return false;
|
211
211
|
|
212
212
|
let i: i32 = Porffor.wasm`local.get ${_this}`,
|
213
213
|
j: i32 = Porffor.wasm`local.get ${searchString}`;
|
@@ -282,10 +282,10 @@ export const __String_prototype_indexOf = (_this: string, searchString: string,
|
|
282
282
|
return -1;
|
283
283
|
};
|
284
284
|
|
285
|
-
export const
|
285
|
+
export const __ByteString_prototype_indexOf = (_this: bytestring, searchString: bytestring, position: number) => {
|
286
286
|
// if searching non-bytestring, bytestring will not start with it
|
287
287
|
// todo: change this to just check if = string and ToString others
|
288
|
-
if (Porffor.wasm`local.get ${searchString+1}` != Porffor.TYPES.
|
288
|
+
if (Porffor.wasm`local.get ${searchString+1}` != Porffor.TYPES.bytestring) return -1;
|
289
289
|
|
290
290
|
let thisPtr: i32 = Porffor.wasm`local.get ${_this}`;
|
291
291
|
const searchPtr: i32 = Porffor.wasm`local.get ${searchString}`;
|
@@ -369,10 +369,10 @@ export const __String_prototype_lastIndexOf = (_this: string, searchString: stri
|
|
369
369
|
return -1;
|
370
370
|
};
|
371
371
|
|
372
|
-
export const
|
372
|
+
export const __ByteString_prototype_lastIndexOf = (_this: bytestring, searchString: bytestring, position: number) => {
|
373
373
|
// if searching non-bytestring, bytestring will not start with it
|
374
374
|
// todo: change this to just check if = string and ToString others
|
375
|
-
if (Porffor.wasm`local.get ${searchString+1}` != Porffor.TYPES.
|
375
|
+
if (Porffor.wasm`local.get ${searchString+1}` != Porffor.TYPES.bytestring) return -1;
|
376
376
|
|
377
377
|
let thisPtr: i32 = Porffor.wasm`local.get ${_this}`;
|
378
378
|
const searchPtr: i32 = Porffor.wasm`local.get ${searchString}`;
|
@@ -455,10 +455,10 @@ export const __String_prototype_includes = (_this: string, searchString: string,
|
|
455
455
|
return false;
|
456
456
|
};
|
457
457
|
|
458
|
-
export const
|
458
|
+
export const __ByteString_prototype_includes = (_this: bytestring, searchString: bytestring, position: number) => {
|
459
459
|
// if searching non-bytestring, bytestring will not start with it
|
460
460
|
// todo: change this to just check if = string and ToString others
|
461
|
-
if (Porffor.wasm`local.get ${searchString+1}` != Porffor.TYPES.
|
461
|
+
if (Porffor.wasm`local.get ${searchString+1}` != Porffor.TYPES.bytestring) return -1;
|
462
462
|
|
463
463
|
let thisPtr: i32 = Porffor.wasm`local.get ${_this}`;
|
464
464
|
const searchPtr: i32 = Porffor.wasm`local.get ${searchString}`;
|
@@ -542,7 +542,7 @@ export const __String_prototype_padStart = (_this: string, targetLength: number,
|
|
542
542
|
return out;
|
543
543
|
};
|
544
544
|
|
545
|
-
export const
|
545
|
+
export const __ByteString_prototype_padStart = (_this: bytestring, targetLength: number, padString: bytestring) => {
|
546
546
|
// todo: handle padString being non-bytestring
|
547
547
|
|
548
548
|
let out: bytestring = Porffor.bs``;
|
@@ -631,7 +631,7 @@ export const __String_prototype_padEnd = (_this: string, targetLength: number, p
|
|
631
631
|
return out;
|
632
632
|
};
|
633
633
|
|
634
|
-
export const
|
634
|
+
export const __ByteString_prototype_padEnd = (_this: bytestring, targetLength: number, padString: bytestring) => {
|
635
635
|
// todo: handle padString being non-bytestring
|
636
636
|
|
637
637
|
let out: bytestring = Porffor.bs``;
|
@@ -713,7 +713,7 @@ export const __String_prototype_substring = (_this: string, start: number, end:
|
|
713
713
|
return out;
|
714
714
|
};
|
715
715
|
|
716
|
-
export const
|
716
|
+
export const __ByteString_prototype_substring = (_this: bytestring, start: number, end: number) => {
|
717
717
|
const len: i32 = _this.length;
|
718
718
|
if (Porffor.wasm`local.get ${end+1}` == Porffor.TYPES.undefined) end = len;
|
719
719
|
else if (start > end) {
|
@@ -786,7 +786,7 @@ export const __String_prototype_substr = (_this: string, start: number, length:
|
|
786
786
|
return out;
|
787
787
|
};
|
788
788
|
|
789
|
-
export const
|
789
|
+
export const __ByteString_prototype_substr = (_this: string, start: number, length: number) => {
|
790
790
|
const len: i32 = _this.length;
|
791
791
|
|
792
792
|
start |= 0;
|
@@ -862,7 +862,7 @@ export const __String_prototype_slice = (_this: string, start: number, end: numb
|
|
862
862
|
return out;
|
863
863
|
};
|
864
864
|
|
865
|
-
export const
|
865
|
+
export const __ByteString_prototype_slice = (_this: bytestring, start: number, end: number) => {
|
866
866
|
const len: i32 = _this.length;
|
867
867
|
if (Porffor.wasm`local.get ${end+1}` == Porffor.TYPES.undefined) end = len;
|
868
868
|
|
@@ -935,7 +935,7 @@ export const __String_prototype_trimStart = (_this: string) => {
|
|
935
935
|
return out;
|
936
936
|
};
|
937
937
|
|
938
|
-
export const
|
938
|
+
export const __ByteString_prototype_trimStart = (_this: bytestring) => {
|
939
939
|
let out: bytestring = Porffor.bs``;
|
940
940
|
|
941
941
|
let outPtr: i32 = Porffor.wasm`local.get ${out}`;
|
@@ -1006,7 +1006,7 @@ export const __String_prototype_trimEnd = (_this: string) => {
|
|
1006
1006
|
return out;
|
1007
1007
|
};
|
1008
1008
|
|
1009
|
-
export const
|
1009
|
+
export const __ByteString_prototype_trimEnd = (_this: bytestring) => {
|
1010
1010
|
let out: bytestring = Porffor.bs``;
|
1011
1011
|
|
1012
1012
|
let outPtr: i32 = Porffor.wasm`local.get ${out}`;
|
@@ -1049,7 +1049,7 @@ export const __String_prototype_trim = (_this: string) => {
|
|
1049
1049
|
return __String_prototype_trimStart(__String_prototype_trimEnd(_this));
|
1050
1050
|
};
|
1051
1051
|
|
1052
|
-
export const
|
1052
|
+
export const __ByteString_prototype_trim = (_this: bytestring) => {
|
1053
1053
|
// todo/perf: optimize and not just reuse
|
1054
|
-
return
|
1054
|
+
return __ByteString_prototype_trimStart(__ByteString_prototype_trimEnd(_this));
|
1055
1055
|
};
|
@@ -1,4 +1,4 @@
|
|
1
|
-
// // @porf
|
1
|
+
// // @porf --funsafe-no-unlikely-proto-checks --valtype=i32
|
2
2
|
|
3
3
|
export const __Boolean_prototype_toString = (_this: boolean) => {
|
4
4
|
let out: bytestring = '';
|
@@ -14,7 +14,7 @@ export const __String_prototype_toString = (_this: string) => {
|
|
14
14
|
return out;
|
15
15
|
};
|
16
16
|
|
17
|
-
export const
|
17
|
+
export const __ByteString_prototype_toString = (_this: bytestring) => {
|
18
18
|
let out: bytestring = Porffor.bs``;
|
19
19
|
Porffor.clone(_this, out);
|
20
20
|
return out;
|
@@ -36,10 +36,10 @@ export const __Function_prototype_toString = (_this: Function) => {
|
|
36
36
|
};
|
37
37
|
|
38
38
|
|
39
|
-
// // export const
|
39
|
+
// // export const __Array_prototype_toString = (_this: any[]) => {
|
40
40
|
// // return _this.join();
|
41
41
|
// // };
|
42
42
|
|
43
|
-
// // export const
|
43
|
+
// // export const __RegExp_prototype_toString = (_this: number) => {
|
44
44
|
|
45
45
|
// // };
|
package/compiler/builtins.js
CHANGED
@@ -141,7 +141,7 @@ export const BuiltinVars = function() {
|
|
141
141
|
|
142
142
|
// wintercg(tm)
|
143
143
|
this.__navigator_userAgent = (scope, { makeString }) => makeString(scope, `Porffor/0.2.0`, false, '__navigator_userAgent');
|
144
|
-
this.__navigator_userAgent.type = Prefs.bytestring ? TYPES.
|
144
|
+
this.__navigator_userAgent.type = Prefs.bytestring ? TYPES.bytestring : TYPES.string;
|
145
145
|
|
146
146
|
for (const x in TYPES) {
|
147
147
|
this['__Porffor_TYPES_' + x] = number(TYPES[x]);
|
@@ -216,7 +216,7 @@ export const BuiltinFuncs = function() {
|
|
216
216
|
};
|
217
217
|
|
218
218
|
|
219
|
-
this.
|
219
|
+
this.__Porffor_print = {
|
220
220
|
params: [ valtypeBinary, Valtype.i32 ],
|
221
221
|
typedParams: true,
|
222
222
|
locals: [ Valtype.i32, Valtype.i32 ],
|
@@ -273,7 +273,7 @@ export const BuiltinFuncs = function() {
|
|
273
273
|
|
274
274
|
[ Opcodes.end ]
|
275
275
|
],
|
276
|
-
[TYPES.
|
276
|
+
[TYPES.bytestring]: [
|
277
277
|
// simply print a (byte)string :))
|
278
278
|
// cache input pointer as i32
|
279
279
|
[ Opcodes.local_get, 0 ],
|
@@ -307,7 +307,7 @@ export const BuiltinFuncs = function() {
|
|
307
307
|
|
308
308
|
[ Opcodes.end ]
|
309
309
|
],
|
310
|
-
[TYPES.
|
310
|
+
[TYPES.array]: [
|
311
311
|
...printStaticStr('[ '),
|
312
312
|
|
313
313
|
// cache input pointer as i32
|
@@ -368,10 +368,7 @@ export const BuiltinFuncs = function() {
|
|
368
368
|
[ Opcodes.local_get, 0 ],
|
369
369
|
[ Opcodes.call, importedFuncs.print ],
|
370
370
|
]
|
371
|
-
}, Blocktype.void)
|
372
|
-
|
373
|
-
...char('\n'),
|
374
|
-
[ Opcodes.call, importedFuncs.printChar ]
|
371
|
+
}, Blocktype.void)
|
375
372
|
]
|
376
373
|
};
|
377
374
|
|
@@ -918,27 +915,6 @@ export const BuiltinFuncs = function() {
|
|
918
915
|
]
|
919
916
|
};
|
920
917
|
|
921
|
-
// this.__Porffor_randomInt = {
|
922
|
-
// params: [],
|
923
|
-
// locals: prng.locals,
|
924
|
-
// localNames: [ 's1', 's0' ],
|
925
|
-
// globals: prng.globals,
|
926
|
-
// globalNames: [ 'state0', 'state1' ],
|
927
|
-
// globalInits: [ prngSeed0, prngSeed1 ],
|
928
|
-
// returns: [ Valtype.i32 ],
|
929
|
-
// wasm: [
|
930
|
-
// ...prng.wasm,
|
931
|
-
|
932
|
-
// ...(prng.returns === Valtype.i64 ? [
|
933
|
-
// // the lowest bits of the output generated by xorshift128+ have low quality
|
934
|
-
// ...number(56, Valtype.i64),
|
935
|
-
// [ Opcodes.i64_shr_u ],
|
936
|
-
|
937
|
-
// [ Opcodes.i32_wrap_i64 ],
|
938
|
-
// ] : []),
|
939
|
-
// ]
|
940
|
-
// };
|
941
|
-
|
942
918
|
this.__Porffor_randomByte = {
|
943
919
|
params: [],
|
944
920
|
locals: prng.locals,
|
@@ -1063,7 +1039,7 @@ export const BuiltinFuncs = function() {
|
|
1063
1039
|
typedParams: true,
|
1064
1040
|
locals: [ Valtype.i32, Valtype.i32 ],
|
1065
1041
|
returns: [ valtypeBinary ],
|
1066
|
-
returnType: Prefs.bytestring ? TYPES.
|
1042
|
+
returnType: Prefs.bytestring ? TYPES.bytestring : TYPES.string,
|
1067
1043
|
wasm: (scope, { TYPE_NAMES, typeSwitch, makeString }) => {
|
1068
1044
|
const bc = {};
|
1069
1045
|
for (const x in TYPE_NAMES) {
|