porffor 0.14.0-320727338 → 0.14.0-3905158d3
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 +2 -4
- package/compiler/2c.js +0 -3
- package/compiler/builtins/annexb_string.ts +0 -1
- package/compiler/builtins/array.ts +6 -8
- package/compiler/builtins/base64.ts +0 -1
- package/compiler/builtins/boolean.ts +1 -3
- package/compiler/builtins/crypto.ts +0 -1
- package/compiler/builtins/date.ts +0 -2
- package/compiler/builtins/escape.ts +2 -1
- package/compiler/builtins/function.ts +0 -2
- package/compiler/builtins/int.ts +0 -2
- package/compiler/builtins/math.ts +1 -3
- package/compiler/builtins/number.ts +0 -2
- package/compiler/builtins/object.ts +0 -2
- package/compiler/builtins/set.ts +0 -2
- package/compiler/builtins/string.ts +0 -1
- package/compiler/builtins/symbol.ts +0 -2
- package/compiler/codegen.js +12 -4
- package/compiler/generated_builtins.js +83 -83
- package/compiler/precompile.js +2 -2
- package/package.json +1 -1
- package/porffor_tmp.c +152 -0
package/CONTRIBUTING.md
CHANGED
@@ -198,13 +198,11 @@ Store the character code into the `out` pointer variable, and increment it.
|
|
198
198
|
|
199
199
|
## Porffor-specific TS notes
|
200
200
|
|
201
|
-
- For declaring variables, you must use explicit type annotations currently (eg `let a: number = 1`, not `let a = 1`)
|
201
|
+
- For declaring variables, you must use explicit type annotations currently (eg `let a: number = 1`, not `let a = 1`)
|
202
202
|
- You might spot `Porffor.fastOr`/`Porffor.fastAnd`, these are non-short circuiting versions of `||`/`&&`, taking any number of conditions as arguments. You shouldn't don't need to use or worry about these.
|
203
|
-
- **There are ~no objects, you cannot use them.**
|
203
|
+
- **There are ~no objects, you cannot use them/literals.**
|
204
204
|
- Attempt to avoid string/array-heavy code and use more variables instead if possible, easier on memory and CPU/perf.
|
205
205
|
- Do not set a return type for prototype methods, it can cause errors/unexpected results.
|
206
|
-
- You cannot use other functions in the file not exported, or variables not inside the current function.
|
207
|
-
- `if (...)` uses a fast truthy implementation which is not spec-compliant as most conditions should be strictly checked. To use spec-compliant behavior, use `if (Boolean(...))`.
|
208
206
|
|
209
207
|
<br>
|
210
208
|
|
package/compiler/2c.js
CHANGED
@@ -119,9 +119,6 @@ const removeBrackets = str => {
|
|
119
119
|
};
|
120
120
|
|
121
121
|
export default ({ funcs, globals, tags, data, exceptions, pages }) => {
|
122
|
-
// fix declaring order for c
|
123
|
-
funcs.reverse();
|
124
|
-
|
125
122
|
const invOperatorOpcode = Object.values(operatorOpcode).reduce((acc, x) => {
|
126
123
|
for (const k in x) {
|
127
124
|
acc[x[k]] = k;
|
@@ -1,5 +1,3 @@
|
|
1
|
-
import type {} from './porffor.d.ts';
|
2
|
-
|
3
1
|
export const __Array_isArray = (x: unknown): boolean =>
|
4
2
|
// Porffor.wasm`local.get ${x+1}` == Porffor.TYPES.array;
|
5
3
|
Porffor.rawType(x) == Porffor.TYPES.array;
|
@@ -164,7 +162,7 @@ export const __Array_prototype_filter = (_this: any[], callbackFn: any) => {
|
|
164
162
|
let i: i32 = 0;
|
165
163
|
while (i < len) {
|
166
164
|
const el: any = _this[i];
|
167
|
-
if (
|
165
|
+
if (callbackFn(el, i++, _this)) out.push(el);
|
168
166
|
}
|
169
167
|
|
170
168
|
return out;
|
@@ -187,7 +185,7 @@ export const __Array_prototype_find = (_this: any[], callbackFn: any) => {
|
|
187
185
|
let i: i32 = 0;
|
188
186
|
while (i < len) {
|
189
187
|
const el: any = _this[i];
|
190
|
-
if (
|
188
|
+
if (callbackFn(el, i++, _this)) return el;
|
191
189
|
}
|
192
190
|
};
|
193
191
|
|
@@ -195,7 +193,7 @@ export const __Array_prototype_findLast = (_this: any[], callbackFn: any) => {
|
|
195
193
|
let i: i32 = _this.length;
|
196
194
|
while (i > 0) {
|
197
195
|
const el: any = _this[--i];
|
198
|
-
if (
|
196
|
+
if (callbackFn(el, i, _this)) return el;
|
199
197
|
}
|
200
198
|
};
|
201
199
|
|
@@ -203,14 +201,14 @@ export const __Array_prototype_findIndex = (_this: any[], callbackFn: any) => {
|
|
203
201
|
const len: i32 = _this.length;
|
204
202
|
let i: i32 = 0;
|
205
203
|
while (i < len) {
|
206
|
-
if (
|
204
|
+
if (callbackFn(_this[i], i++, _this)) return i;
|
207
205
|
}
|
208
206
|
};
|
209
207
|
|
210
208
|
export const __Array_prototype_findLastIndex = (_this: any[], callbackFn: any) => {
|
211
209
|
let i: i32 = _this.length;
|
212
210
|
while (i > 0) {
|
213
|
-
if (
|
211
|
+
if (callbackFn(_this[--i], i, _this)) return i;
|
214
212
|
}
|
215
213
|
};
|
216
214
|
|
@@ -218,7 +216,7 @@ export const __Array_prototype_every = (_this: any[], callbackFn: any) => {
|
|
218
216
|
const len: i32 = _this.length;
|
219
217
|
let i: i32 = 0;
|
220
218
|
while (i < len) {
|
221
|
-
if (!
|
219
|
+
if (!callbackFn(_this[i], i++, _this)) return false;
|
222
220
|
}
|
223
221
|
|
224
222
|
return true;
|
@@ -1,12 +1,10 @@
|
|
1
|
-
import type {} from './porffor.d.ts';
|
2
|
-
|
3
1
|
// 20.3.3.2 Boolean.prototype.toString ()
|
4
2
|
// https://tc39.es/ecma262/#sec-boolean.prototype.tostring
|
5
3
|
export const __Boolean_prototype_toString = (_this: boolean) => {
|
6
4
|
// 1. Let b be ? ThisBooleanValue(this value).
|
7
5
|
// 2. If b is true, return "true"; else return "false".
|
8
6
|
let out: bytestring = '';
|
9
|
-
if (_this) out = 'true';
|
7
|
+
if (_this == true) out = 'true';
|
10
8
|
else out = 'false';
|
11
9
|
|
12
10
|
return out;
|
package/compiler/builtins/int.ts
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
import type {} from './porffor.d.ts';
|
2
|
-
|
3
1
|
// todo: use any and Number(x) in all these later
|
4
2
|
// todo: specify the rest of this file later
|
5
3
|
// todo/perf: make i32 variants later
|
@@ -19,7 +17,7 @@ export const __Math_exp = (x: number): number => {
|
|
19
17
|
const k: number = Math.floor(x / Math.LN2);
|
20
18
|
const r: number = x - k * Math.LN2;
|
21
19
|
|
22
|
-
//
|
20
|
+
// Horner's method
|
23
21
|
let term: number = r;
|
24
22
|
let sum: number = 1 + r;
|
25
23
|
let i: number = 2;
|
package/compiler/builtins/set.ts
CHANGED
package/compiler/codegen.js
CHANGED
@@ -668,7 +668,7 @@ const compareStrings = (scope, left, right, bytestrings = false) => {
|
|
668
668
|
];
|
669
669
|
};
|
670
670
|
|
671
|
-
const truthy = (scope, wasm, type, intIn = false, intOut = false
|
671
|
+
const truthy = (scope, wasm, type, intIn = false, intOut = false) => {
|
672
672
|
if (isIntToFloatOp(wasm[wasm.length - 1])) return [
|
673
673
|
...wasm,
|
674
674
|
...(!intIn && intOut ? [ Opcodes.i32_to_u ] : [])
|
@@ -703,13 +703,18 @@ const truthy = (scope, wasm, type, intIn = false, intOut = false, forceTruthyMod
|
|
703
703
|
...(!useTmp ? [] : [ [ Opcodes.local_get, tmp ] ]),
|
704
704
|
...(!intOut || (intIn && intOut) ? [] : [ Opcodes.i32_to_u ])
|
705
705
|
];
|
706
|
-
})(
|
706
|
+
})(Prefs.truthy ?? 'full');
|
707
707
|
|
708
708
|
return [
|
709
709
|
...wasm,
|
710
710
|
...(!useTmp ? [] : [ [ Opcodes.local_set, tmp ] ]),
|
711
711
|
|
712
712
|
...typeSwitch(scope, type, {
|
713
|
+
// [TYPES.number]: def,
|
714
|
+
// [TYPES.array]: [
|
715
|
+
// // arrays are always truthy
|
716
|
+
// ...number(1, intOut ? Valtype.i32 : valtypeBinary)
|
717
|
+
// ],
|
713
718
|
[TYPES.string]: [
|
714
719
|
...(!useTmp ? [] : [ [ Opcodes.local_get, tmp ] ]),
|
715
720
|
...(intIn ? [] : [ Opcodes.i32_to_u ]),
|
@@ -745,6 +750,10 @@ const falsy = (scope, wasm, type, intIn = false, intOut = false) => {
|
|
745
750
|
...(!useTmp ? [] : [ [ Opcodes.local_set, tmp ] ]),
|
746
751
|
|
747
752
|
...typeSwitch(scope, type, {
|
753
|
+
// [TYPES.array]: [
|
754
|
+
// // arrays are always truthy
|
755
|
+
// ...number(0, intOut ? Valtype.i32 : valtypeBinary)
|
756
|
+
// ],
|
748
757
|
[TYPES.string]: [
|
749
758
|
...(!useTmp ? [] : [ [ Opcodes.local_get, tmp ] ]),
|
750
759
|
...(intIn ? [] : [ Opcodes.i32_to_u ]),
|
@@ -2579,7 +2588,6 @@ const generateUnary = (scope, decl) => {
|
|
2579
2588
|
];
|
2580
2589
|
|
2581
2590
|
case '!':
|
2582
|
-
// todo/perf: optimize !!
|
2583
2591
|
// !=
|
2584
2592
|
return falsy(scope, generate(scope, decl.argument), getNodeType(scope, decl.argument), false, false);
|
2585
2593
|
|
@@ -3839,7 +3847,7 @@ const internalConstrs = {
|
|
3839
3847
|
generate: (scope, decl) => {
|
3840
3848
|
// todo: boolean object when used as constructor
|
3841
3849
|
const arg = decl.arguments[0] ?? DEFAULT_VALUE;
|
3842
|
-
return truthy(scope, generate(scope, arg), getNodeType(scope, arg)
|
3850
|
+
return truthy(scope, generate(scope, arg), getNodeType(scope, arg));
|
3843
3851
|
},
|
3844
3852
|
type: TYPES.boolean,
|
3845
3853
|
length: 1
|