porffor 0.49.4 → 0.49.6
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/console.ts +8 -6
- package/compiler/builtins/math.ts +49 -11
- package/compiler/builtins_precompiled.js +765 -765
- package/compiler/codegen.js +60 -54
- package/compiler/precompile.js +1 -1
- package/package.json +1 -1
- package/richards.js +91 -129
- package/runner/index.js +1 -1
@@ -86,7 +86,7 @@ export const __Porffor_miniLog = (arg: any) => {
|
|
86
86
|
Porffor.printStatic('\n');
|
87
87
|
};
|
88
88
|
|
89
|
-
export const __Porffor_print = (arg: any, colors: boolean = true) => {
|
89
|
+
export const __Porffor_print = (arg: any, colors: boolean = true, depth: number = 0) => {
|
90
90
|
// todo: Symbol.toStringTag could reduce duplication here
|
91
91
|
|
92
92
|
// note: this doesn't have access to the upper scope!! do not use any variables from up there
|
@@ -154,21 +154,23 @@ export const __Porffor_print = (arg: any, colors: boolean = true) => {
|
|
154
154
|
return;
|
155
155
|
}
|
156
156
|
|
157
|
-
Porffor.printStatic('{
|
157
|
+
Porffor.printStatic('{\n');
|
158
158
|
const len: i32 = keys.length - 1;
|
159
159
|
for (let i: i32 = 0; i <= len; i++) {
|
160
160
|
const x: any = keys[i];
|
161
161
|
|
162
|
-
Porffor.printStatic(' ');
|
162
|
+
for (let j: i32 = 0; j <= depth; j++) Porffor.printStatic(' ');
|
163
163
|
__Porffor_printString(x);
|
164
164
|
|
165
165
|
Porffor.printStatic(': ');
|
166
|
-
__Porffor_print(Porffor.object.get(arg, ecma262.ToPropertyKey(x)));
|
166
|
+
__Porffor_print(Porffor.object.get(arg, ecma262.ToPropertyKey(x)), colors, depth + 1);
|
167
167
|
|
168
168
|
if (i != len) Porffor.printStatic(',\n');
|
169
169
|
}
|
170
170
|
|
171
|
-
Porffor.printStatic('
|
171
|
+
Porffor.printStatic('\n');
|
172
|
+
for (let j: i32 = 0; j < depth; j++) Porffor.printStatic(' ');
|
173
|
+
Porffor.printStatic('}');
|
172
174
|
} else {
|
173
175
|
if (colors) Porffor.printStatic('\x1b[1m'); // bold
|
174
176
|
Porffor.printStatic('null');
|
@@ -295,7 +297,7 @@ export const __Porffor_print = (arg: any, colors: boolean = true) => {
|
|
295
297
|
|
296
298
|
for (let i: i32 = 0; i < mapLen; i++) {
|
297
299
|
const key: any = map[i];
|
298
|
-
__Porffor_print(key);
|
300
|
+
__Porffor_print(key, colors);
|
299
301
|
Porffor.printStatic(' => ');
|
300
302
|
__Porffor_print(__Map_prototype_get(arg, key), colors);
|
301
303
|
if (i != mapLen) Porffor.printStatic(', ');
|
@@ -76,18 +76,38 @@ export const __Math_log = (y: number): number => {
|
|
76
76
|
}
|
77
77
|
if (!Number.isFinite(y)) return y;
|
78
78
|
|
79
|
-
//
|
80
|
-
|
79
|
+
// very large numbers
|
80
|
+
if (y > 1e308) {
|
81
|
+
const n = Math.floor(Math.log2(y));
|
82
|
+
return Math.LN2 * n + Math.log(y / (1 << 30) / (1 << (n - 30)));
|
83
|
+
}
|
81
84
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
85
|
+
let m = 0;
|
86
|
+
while (y >= 2) {
|
87
|
+
y /= 2;
|
88
|
+
m++;
|
89
|
+
}
|
90
|
+
while (y < 1) {
|
91
|
+
y *= 2;
|
92
|
+
m--;
|
93
|
+
}
|
89
94
|
|
90
|
-
|
95
|
+
y--; // 1 <= y < 2 -> 0 <= y < 1
|
96
|
+
|
97
|
+
// more accurate series expansion
|
98
|
+
let x = y / (2 + y);
|
99
|
+
const x2 = x * x;
|
100
|
+
let sum = x;
|
101
|
+
let term = x;
|
102
|
+
let i = 1;
|
103
|
+
|
104
|
+
while (Math.abs(term) > 1e-15) {
|
105
|
+
term *= x2 * (2 * i - 1) / (2 * i + 1);
|
106
|
+
sum += term;
|
107
|
+
i++;
|
108
|
+
}
|
109
|
+
|
110
|
+
return 2 * sum + m * Math.LN2;
|
91
111
|
};
|
92
112
|
|
93
113
|
export const __Math_log10 = (x: number): number => {
|
@@ -206,7 +226,25 @@ export const __Math_pow = (base: number, exponent: number): number => {
|
|
206
226
|
if (base < 0) if (!Number.isInteger(exponent)) return NaN;
|
207
227
|
|
208
228
|
// 13. Return an implementation-approximated Number value representing the result of raising ℝ(base) to the ℝ(exponent) power.
|
209
|
-
|
229
|
+
let currentBase: number = base;
|
230
|
+
let currentExponent: number = Math.abs(exponent);
|
231
|
+
|
232
|
+
let result: number = 1;
|
233
|
+
while (currentExponent > 0) {
|
234
|
+
if (currentExponent >= 1) {
|
235
|
+
if (currentExponent % 2 != 0) {
|
236
|
+
result *= currentBase;
|
237
|
+
}
|
238
|
+
currentBase *= currentBase;
|
239
|
+
currentExponent = Math.floor(currentExponent / 2);
|
240
|
+
} else {
|
241
|
+
// Handle fractional part
|
242
|
+
result *= Math.exp(currentExponent * Math.log(Math.abs(currentBase)));
|
243
|
+
break;
|
244
|
+
}
|
245
|
+
}
|
246
|
+
|
247
|
+
return exponent < 0 ? 1 / result : result;
|
210
248
|
};
|
211
249
|
|
212
250
|
|