porffor 0.14.0-b5a80d8e3 → 0.14.0-bb0b06c17

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.
@@ -0,0 +1,408 @@
1
+ // todo: use any and Number(x) in all these later
2
+ // todo: specify the rest of this file later
3
+ // todo/perf: make i32 variants later
4
+ // todo/perf: add a compiler pref for accuracy vs perf (epsilion?)
5
+
6
+ export const __Math_exp = (x: number): number => {
7
+ if (!Number.isFinite(x)) {
8
+ if (x == -Infinity) return 0;
9
+ return x;
10
+ }
11
+
12
+ if (x < 0) {
13
+ // exp(-x) = 1 / exp(+x)
14
+ return 1 / Math.exp(-x);
15
+ }
16
+
17
+ const k: number = Math.floor(x / Math.LN2);
18
+ const r: number = x - k * Math.LN2;
19
+
20
+ // Horner's method
21
+ let term: number = r;
22
+ let sum: number = 1 + r;
23
+ let i: number = 2;
24
+
25
+ while (Math.abs(term) > 1e-15) {
26
+ term *= r / i;
27
+ sum += term;
28
+ i++;
29
+ }
30
+
31
+ return sum * (1 << k);
32
+ };
33
+
34
+ export const __Math_log2 = (y: number): number => {
35
+ if (y <= 0) return NaN;
36
+ if (!Number.isFinite(y)) return y;
37
+
38
+ // approx using log knowledge
39
+ let x: number = y;
40
+ let exponent: number = 0;
41
+
42
+ while (x >= 2) {
43
+ x /= 2;
44
+ exponent++;
45
+ }
46
+
47
+ while (x < 1) {
48
+ x *= 2;
49
+ exponent--;
50
+ }
51
+
52
+ // 1 <= x < 2 -> 0 <= x < 1
53
+ x -= 1;
54
+
55
+ // refine with Newton-Raphson method
56
+ let delta: number;
57
+ do {
58
+ const e_x: number = Math.exp(x * Math.LN2);
59
+ delta = (e_x - y) / (e_x * Math.LN2);
60
+ x -= delta;
61
+ } while (Math.abs(delta) > 1e-15);
62
+
63
+ return x + exponent;
64
+ };
65
+
66
+ export const __Math_log = (y: number): number => {
67
+ if (y <= 0) {
68
+ if (y == 0) return -Infinity;
69
+ return NaN;
70
+ }
71
+ if (!Number.isFinite(y)) return y;
72
+
73
+ // guess using log knowledge
74
+ let x: number = y > 1 ? Math.log2(y) : 0;
75
+
76
+ // refine with Newton-Raphson method
77
+ let delta: number;
78
+ do {
79
+ const e_x: number = Math.exp(x);
80
+ delta = (e_x - y) / e_x;
81
+ x -= delta;
82
+ } while (Math.abs(delta) > 1e-15);
83
+
84
+ return x;
85
+ };
86
+
87
+ export const __Math_log10 = (x: number): number => {
88
+ if (x <= 0) {
89
+ if (x == 0) return -Infinity;
90
+ return NaN;
91
+ }
92
+ if (!Number.isFinite(x)) return x;
93
+
94
+ return Math.log(x) / Math.LN10;
95
+ };
96
+
97
+ // 21.3.2.26 Math.pow (base, exponent)
98
+ // https://tc39.es/ecma262/#sec-math.pow
99
+ export const __Math_pow = (base: number, exponent: number): number => {
100
+ // 1. Set base to ? ToNumber(base).
101
+ // 2. Set exponent to ? ToNumber(exponent).
102
+ // todo
103
+
104
+ // 3. Return Number::exponentiate(base, exponent).
105
+
106
+ // Number::exponentiate (base, exponent)
107
+ // https://tc39.es/ecma262/#sec-numeric-types-number-exponentiate
108
+ // 1. If exponent is NaN, return NaN.
109
+ if (Number.isNaN(exponent)) return NaN;
110
+
111
+ // 2. If exponent is either +0𝔽 or -0𝔽, return 1𝔽.
112
+ if (exponent == 0) return 1;
113
+
114
+ if (!Number.isFinite(base)) {
115
+ // 3. If base is NaN, return NaN.
116
+ if (Number.isNaN(base)) return base;
117
+
118
+ // 4. If base is +∞𝔽, then
119
+ if (base == Infinity) {
120
+ // a. If exponent > +0𝔽, return +∞𝔽. Otherwise, return +0𝔽.
121
+ if (exponent > 0) return base;
122
+ return 0;
123
+ }
124
+
125
+ // 5. If base is -∞𝔽, then
126
+ const isOdd = exponent % 2 == 1;
127
+
128
+ // a. If exponent > +0𝔽, then
129
+ if (exponent > 0) {
130
+ // i. If exponent is an odd integral Number, return -∞𝔽. Otherwise, return +∞𝔽.
131
+ if (isOdd) return -Infinity;
132
+ return Infinity;
133
+ }
134
+
135
+ // b. Else,
136
+ // i. If exponent is an odd integral Number, return -0𝔽. Otherwise, return +0𝔽.
137
+ if (isOdd) return -0;
138
+ return 0;
139
+ }
140
+
141
+ if (base == 0) {
142
+ // 6. If base is +0𝔽, then
143
+ if (1 / base == Infinity) {
144
+ // a. If exponent > +0𝔽, return +0𝔽. Otherwise, return +∞𝔽.
145
+ if (exponent > 0) return 0;
146
+ return Infinity;
147
+ }
148
+
149
+ // 7. If base is -0𝔽, then
150
+ const isOdd = exponent % 2 == 1;
151
+
152
+ // a. If exponent > +0𝔽, then
153
+ if (exponent > 0) {
154
+ // i. If exponent is an odd integral Number, return -0𝔽. Otherwise, return +0𝔽.
155
+ if (isOdd) return -0;
156
+ return 0;
157
+ }
158
+
159
+ // b. Else,
160
+ // i. If exponent is an odd integral Number, return -∞𝔽. Otherwise, return +∞𝔽.
161
+ if (isOdd) return -Infinity;
162
+ return Infinity;
163
+ }
164
+
165
+ // 8. Assert: base is finite and is neither +0𝔽 nor -0𝔽.
166
+ // todo
167
+
168
+ // 9. If exponent is +∞𝔽, then
169
+ if (exponent == Infinity) {
170
+ const abs = Math.abs(base);
171
+
172
+ // a. If abs(ℝ(base)) > 1, return +∞𝔽.
173
+ if (abs > 1) return Infinity;
174
+
175
+ // b. If abs(ℝ(base)) = 1, return NaN.
176
+ if (abs == 1) return NaN;
177
+
178
+ // c. If abs(ℝ(base)) < 1, return +0𝔽.
179
+ return 0;
180
+ }
181
+
182
+ // 10. If exponent is -∞𝔽, then
183
+ if (exponent == -Infinity) {
184
+ const abs = Math.abs(base);
185
+
186
+ // a. If abs(ℝ(base)) > 1, return +0𝔽.
187
+ if (abs > 1) return 0;
188
+
189
+ // b. If abs(ℝ(base)) = 1, return NaN.
190
+ if (abs == 1) return NaN;
191
+
192
+ // c. If abs(ℝ(base)) < 1, return +∞𝔽.
193
+ return Infinity;
194
+ }
195
+
196
+ // 11. Assert: exponent is finite and is neither +0𝔽 nor -0𝔽.
197
+ // todo
198
+
199
+ // 12. If base < -0𝔽 and exponent is not an integral Number, return NaN.
200
+ if (base < 0) if (!Number.isInteger(exponent)) return NaN;
201
+
202
+ // 13. Return an implementation-approximated Number value representing the result of raising ℝ(base) to the ℝ(exponent) power.
203
+ return Math.exp(exponent * Math.log(base));
204
+ };
205
+
206
+
207
+ export const __Math_expm1 = (x: number): number => {
208
+ if (!Number.isFinite(x)) {
209
+ if (x == -Infinity) return -1;
210
+ return x;
211
+ }
212
+
213
+ // use exp(x) - 1 for large x (perf)
214
+ if (Math.abs(x) > 1e-5) return Math.exp(x) - 1;
215
+
216
+ // Taylor series
217
+ let sum: number = x;
218
+ let term: number = x;
219
+ let i: number = 2;
220
+
221
+ while (Math.abs(term) > 1e-15) {
222
+ term *= x / i;
223
+ sum += term;
224
+ i++;
225
+ }
226
+
227
+ return sum;
228
+ };
229
+
230
+ export const __Math_log1p = (x: number): number => {
231
+ if (x == -1) return -Infinity; // log(0) = -inf
232
+ if (!Number.isFinite(x)) return x;
233
+
234
+ // use exp(x) - 1 for large x (perf)
235
+ if (Math.abs(x) > 1e-5) return Math.log(1 + x);
236
+
237
+ // Taylor series
238
+ let sum: number = 0;
239
+ let term: number = x;
240
+ let i: number = 2;
241
+
242
+ while (Math.abs(term) > 1e-15) {
243
+ term *= -x / i;
244
+ sum += term;
245
+ i++;
246
+ }
247
+
248
+ return sum;
249
+ };
250
+
251
+
252
+ export const __Math_sqrt = (y: number): number => {
253
+ if (y <= 0) {
254
+ if (y == 0) return 0;
255
+ return NaN;
256
+ }
257
+ if (!Number.isFinite(y)) return y;
258
+
259
+ // Babylonian method
260
+ let x: number = y;
261
+ let prev: number;
262
+
263
+ do {
264
+ prev = x;
265
+ x = 0.5 * (x + y / x);
266
+ } while (Math.abs(prev - x) > 1e-15);
267
+
268
+ return x;
269
+ };
270
+
271
+ export const __Math_cbrt = (y: number): number => {
272
+ if (y == 0) return 0; // cbrt(0) = 0
273
+ if (!Number.isFinite(y)) return y;
274
+
275
+ // Babylonian method
276
+ let x = Math.abs(y);
277
+
278
+ let prev: number;
279
+
280
+ do {
281
+ prev = x;
282
+ x = (2 * x + y / (x * x)) / 3;
283
+ } while (Math.abs(prev - x) > 1e-15);
284
+
285
+ return y < 0 ? -x : x;
286
+ };
287
+
288
+
289
+ // todo: varargs
290
+ export const __Math_hypot = (x: number, y: number): number => Math.sqrt(x * x + y * y);
291
+
292
+ export const __Math_sin = (x: number): number => {
293
+ // -inf <= x <= inf -> 0 <= x <= 2pi
294
+ const piX2: number = Math.PI * 2;
295
+ x %= piX2;
296
+ if (x < 0) x += piX2;
297
+
298
+ const x2: number = x * x;
299
+
300
+ return x * (
301
+ 1 + x2 * (
302
+ -1.66666666666666307295e-1 + x2 * (
303
+ 8.33333333332211858878e-3 + x2 * (
304
+ -1.98412698295895385996e-4 + x2 * (
305
+ 2.75573136213857245213e-6 + x2 * (
306
+ -2.50507477628578072866e-8 + x2 * (
307
+ 1.58962301576546568060e-10
308
+ )
309
+ )
310
+ )
311
+ )
312
+ )
313
+ )
314
+ );
315
+
316
+ // todo: investigate which is better (consider perf and accuracy)
317
+ // const x2 = x * x;
318
+ // const x4 = x2 * x2;
319
+ // const x6 = x4 * x2;
320
+ // const x8 = x4 * x4;
321
+ // const x10 = x6 * x4;
322
+ // const x12 = x6 * x6;
323
+ // const x14 = x12 * x2;
324
+
325
+ // return x * (
326
+ // 1 - x2 / 6 + x4 / 120 - x6 / 5040 + x8 / 362880 - x10 / 39916800 + x12 / 6227020800 - x14 / 1307674368000
327
+ // );
328
+ };
329
+
330
+ export const __Math_cos = (x: number): number => Math.sin(x - Math.PI / 2);
331
+ export const __Math_tan = (x: number): number => Math.sin(x) / Math.cos(x);
332
+
333
+ export const __Math_sinh = (x: number): number => (Math.exp(x) - Math.exp(-x)) / 2;
334
+ export const __Math_cosh = (x: number): number => (Math.exp(x) + Math.exp(-x)) / 2;
335
+ export const __Math_tanh = (x: number): number => Math.sinh(x) / Math.cosh(x);
336
+
337
+
338
+ export const __Math_asinh = (x: number): number => Math.log(x + Math.sqrt(x * x + 1));
339
+ export const __Math_acosh = (x: number): number => {
340
+ if (x < 1) return NaN;
341
+ return Math.log(x + Math.sqrt(x * x - 1));
342
+ };
343
+ export const __Math_atanh = (x: number): number => {
344
+ if (Math.abs(x) >= 1) return NaN;
345
+ return 0.5 * Math.log((1 + x) / (1 - x));
346
+ };
347
+
348
+
349
+ export const __Math_asin = (x: number): number => {
350
+ if (x <= -1) {
351
+ if (x == -1) return -Math.PI / 2;
352
+ return NaN;
353
+ }
354
+ if (x >= 1) {
355
+ if (x == 1) return Math.PI / 2;
356
+ return NaN;
357
+ }
358
+
359
+ // Taylor series
360
+ let sum: number = x;
361
+ let term: number = x;
362
+ let n: number = 1;
363
+
364
+ while (Math.abs(term) > 1e-15) {
365
+ term *= x * x * (2 * n - 1) * (2 * n - 1) / ((2 * n) * (2 * n + 1));
366
+ sum += term / (2 * n + 1);
367
+ n++;
368
+ }
369
+
370
+ return sum;
371
+ };
372
+
373
+ export const __Math_acos = (x: number): number => Math.asin(x) - Math.PI / 2;
374
+
375
+ export const __Math_atan = (x: number): number => {
376
+ if (x == Infinity) return Math.PI / 2
377
+ if (x == -Infinity) return -Math.PI / 2;
378
+
379
+ // Taylor series
380
+ let sum: number = x;
381
+ let term: number = x;
382
+ let n: number = 1;
383
+
384
+ while (Math.abs(term) > 1e-15) {
385
+ term *= -x * x * (2 * n - 1) / ((2 * n) * (2 * n + 1));
386
+ sum += term;
387
+ n++;
388
+ }
389
+
390
+ return sum;
391
+ };
392
+
393
+ export const __Math_atan2 = (y: number, x: number): number => {
394
+ if (x == 0) {
395
+ if (y > 0) return Math.PI / 2;
396
+ if (y < 0) return -Math.PI / 2;
397
+
398
+ return NaN;
399
+ }
400
+
401
+ const ratio = y / x;
402
+ if (x > 0) {
403
+ return Math.atan(ratio);
404
+ }
405
+
406
+ if (y >= 0) return Math.atan(ratio) + Math.PI;
407
+ return Math.atan(ratio) - Math.PI;
408
+ };
@@ -221,8 +221,7 @@ export const BuiltinFuncs = function() {
221
221
  typedParams: true,
222
222
  locals: [ Valtype.i32, Valtype.i32 ],
223
223
  returns: [],
224
- callsSelf: true,
225
- wasm: (scope, { typeSwitch }) => [
224
+ wasm: (scope, { typeSwitch, builtin }) => [
226
225
  ...typeSwitch(scope, [ [ Opcodes.local_get, 1 ] ], {
227
226
  [TYPES.number]: [
228
227
  [ Opcodes.local_get, 0 ],
@@ -327,14 +326,14 @@ export const BuiltinFuncs = function() {
327
326
 
328
327
  [ Opcodes.loop, Blocktype.void ],
329
328
 
330
- // print current char
329
+ // print current array element
331
330
  [ Opcodes.local_get, 2 ],
332
331
  [ Opcodes.load, 0, ValtypeSize.i32 ],
333
332
 
334
333
  [ Opcodes.local_get, 2 ],
335
334
  [ Opcodes.i32_load8_u, 0, ValtypeSize.i32 + ValtypeSize[valtype] ],
336
335
 
337
- [ Opcodes.call, -1 ],
336
+ [ Opcodes.call, builtin('__Porffor_print') ],
338
337
 
339
338
  // increment pointer by sizeof valtype
340
339
  [ Opcodes.local_get, 2 ],
@@ -40,11 +40,11 @@ const todo = (scope, msg, expectsValue = undefined) => {
40
40
  }
41
41
  };
42
42
 
43
- const isFuncType = type => type === 'FunctionDeclaration' || type === 'FunctionExpression' || type === 'ArrowFunctionExpression';
44
- const hasFuncWithName = name => {
45
- const func = funcs.find(x => x.name === name);
46
- return !!(func || builtinFuncs[name] || importedFuncs[name] || internalConstrs[name]);
47
- };
43
+ const isFuncType = type =>
44
+ type === 'FunctionDeclaration' || type === 'FunctionExpression' || type === 'ArrowFunctionExpression';
45
+ const hasFuncWithName = name =>
46
+ funcIndex[name] != null || builtinFuncs[name] != null || importedFuncs[name] != null || internalConstrs[name] != null;
47
+
48
48
  const generate = (scope, decl, global = false, name = undefined, valueUnused = false) => {
49
49
  switch (decl.type) {
50
50
  case 'BinaryExpression':
@@ -147,14 +147,16 @@ const generate = (scope, decl, global = false, name = undefined, valueUnused = f
147
147
  return generateMember(scope, decl, global, name);
148
148
 
149
149
  case 'ExportNamedDeclaration':
150
- // hack to flag new func for export
151
- const funcsBefore = funcs.length;
150
+ const funcsBefore = funcs.map(x => x.name);
152
151
  generate(scope, decl.declaration);
153
152
 
154
- if (funcsBefore !== funcs.length) {
155
- // new func added
156
- const newFunc = funcs[funcs.length - 1];
157
- newFunc.export = true;
153
+ // set new funcs as exported
154
+ if (funcsBefore.length !== funcs.length) {
155
+ const newFuncs = funcs.filter(x => !funcsBefore.includes(x.name)).filter(x => !x.internal);
156
+
157
+ for (const x of newFuncs) {
158
+ x.export = true;
159
+ }
158
160
  }
159
161
 
160
162
  return [];
@@ -1048,14 +1050,14 @@ const generateBinaryExp = (scope, decl, _global, _name) => {
1048
1050
  return out;
1049
1051
  };
1050
1052
 
1051
- const asmFuncToAsm = (func, { name = '#unknown_asm_func', params = [], locals = [], returns = [], localInd = 0 }) => {
1052
- return func({ name, params, locals, returns, localInd }, {
1053
+ const asmFuncToAsm = (func, scope) => {
1054
+ return func(scope, {
1053
1055
  TYPES, TYPE_NAMES, typeSwitch, makeArray, makeString, allocPage, internalThrow,
1054
- builtin: name => {
1055
- let idx = funcIndex[name] ?? importedFuncs[name];
1056
- if (idx === undefined && builtinFuncs[name]) {
1057
- includeBuiltin(null, name);
1058
- idx = funcIndex[name];
1056
+ builtin: n => {
1057
+ let idx = funcIndex[n] ?? importedFuncs[n];
1058
+ if (idx == null && builtinFuncs[n]) {
1059
+ includeBuiltin(null, n);
1060
+ idx = funcIndex[n];
1059
1061
  }
1060
1062
 
1061
1063
  return idx;
@@ -1063,7 +1065,7 @@ const asmFuncToAsm = (func, { name = '#unknown_asm_func', params = [], locals =
1063
1065
  });
1064
1066
  };
1065
1067
 
1066
- const asmFunc = (name, { wasm, params, locals: localTypes, globals: globalTypes = [], globalInits, returns, returnType, localNames = [], globalNames = [], data: _data = [], table = false, callsSelf = false }) => {
1068
+ const asmFunc = (name, { wasm, params, locals: localTypes, globals: globalTypes = [], globalInits, returns, returnType, localNames = [], globalNames = [], data: _data = [], table = false }) => {
1067
1069
  const existing = funcs.find(x => x.name === name);
1068
1070
  if (existing) return existing;
1069
1071
 
@@ -1081,7 +1083,22 @@ const asmFunc = (name, { wasm, params, locals: localTypes, globals: globalTypes
1081
1083
  data.push(copy);
1082
1084
  }
1083
1085
 
1084
- if (typeof wasm === 'function') wasm = asmFuncToAsm(wasm, { name, params, locals, returns, localInd: allLocals.length });
1086
+ const func = {
1087
+ name,
1088
+ params,
1089
+ locals,
1090
+ localInd: allLocals.length,
1091
+ returns,
1092
+ returnType: returnType ?? TYPES.number,
1093
+ internal: true,
1094
+ index: currentFuncIndex++,
1095
+ table
1096
+ };
1097
+
1098
+ funcs.push(func);
1099
+ funcIndex[name] = func.index;
1100
+
1101
+ if (typeof wasm === 'function') wasm = asmFuncToAsm(wasm, func);
1085
1102
 
1086
1103
  let baseGlobalIdx, i = 0;
1087
1104
  for (const type of globalTypes) {
@@ -1100,23 +1117,6 @@ const asmFunc = (name, { wasm, params, locals: localTypes, globals: globalTypes
1100
1117
  }
1101
1118
  }
1102
1119
 
1103
- const func = {
1104
- name,
1105
- params,
1106
- locals,
1107
- returns,
1108
- returnType: returnType ?? TYPES.number,
1109
- wasm,
1110
- internal: true,
1111
- index: currentFuncIndex++
1112
- };
1113
-
1114
- if (callsSelf) for (const inst of wasm) {
1115
- if (inst[0] === Opcodes.call && inst[1] === -1) {
1116
- inst[1] = func.index;
1117
- }
1118
- }
1119
-
1120
1120
  if (table) for (const inst of wasm) {
1121
1121
  if (inst[0] === Opcodes.i32_load16_u && inst.at(-1) === 'read_argc') {
1122
1122
  inst.splice(2, 99);
@@ -1124,10 +1124,7 @@ const asmFunc = (name, { wasm, params, locals: localTypes, globals: globalTypes
1124
1124
  }
1125
1125
  }
1126
1126
 
1127
- funcs.push(func);
1128
- funcIndex[name] = func.index;
1129
-
1130
- if (table) funcs.table = true;
1127
+ func.wasm = wasm;
1131
1128
 
1132
1129
  return func;
1133
1130
  };
@@ -1479,16 +1476,11 @@ const countLeftover = wasm => {
1479
1476
  else if (inst[0] === Opcodes.return) count = 0;
1480
1477
  else if (inst[0] === Opcodes.call) {
1481
1478
  let func = funcs.find(x => x.index === inst[1]);
1482
- if (inst[1] === -1) {
1483
- // todo: count for calling self
1484
- } else if (!func && inst[1] < importedFuncs.length) {
1485
- count -= importedFuncs[inst[1]].params;
1486
- count += importedFuncs[inst[1]].returns;
1479
+ if (inst[1] < importedFuncs.length) {
1480
+ func = importedFuncs[inst[1]];
1481
+ count = count - func.params + func.returns;
1487
1482
  } else {
1488
- if (func) {
1489
- count -= func.params.length;
1490
- } else count--;
1491
- if (func) count += func.returns.length;
1483
+ count = count - func.params.length + func.returns.length;
1492
1484
  }
1493
1485
  } else if (inst[0] === Opcodes.call_indirect) {
1494
1486
  count--; // funcidx
@@ -1641,6 +1633,7 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
1641
1633
 
1642
1634
  if (!funcIndex[rhemynName]) {
1643
1635
  const func = Rhemyn[funcName](regex, currentFuncIndex++, rhemynName);
1636
+ func.internal = true;
1644
1637
 
1645
1638
  funcIndex[func.name] = func.index;
1646
1639
  funcs.push(func);
@@ -1812,11 +1805,6 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
1812
1805
 
1813
1806
  if (idx === undefined && internalConstrs[name]) return internalConstrs[name].generate(scope, decl, _global, _name);
1814
1807
 
1815
- if (idx === undefined && name === scope.name) {
1816
- // hack: calling self, func generator will fix later
1817
- idx = -1;
1818
- }
1819
-
1820
1808
  if (idx === undefined && name.startsWith('__Porffor_wasm_')) {
1821
1809
  const wasmOps = {
1822
1810
  // pointer, align, offset
@@ -1998,11 +1986,10 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
1998
1986
  return internalThrow(scope, 'ReferenceError', `${unhackName(name)} is not defined`, true);
1999
1987
  }
2000
1988
 
2001
- const func = funcs.find(x => x.index === idx);
2002
-
2003
- const userFunc = (funcIndex[name] && !importedFuncs[name] && !builtinFuncs[name] && !internalConstrs[name]) || idx === -1;
1989
+ const func = funcs[idx - importedFuncs.length]; // idx === scope.index ? scope : funcs.find(x => x.index === idx);
1990
+ const userFunc = func && !func.internal;
2004
1991
  const typedParams = userFunc || builtinFuncs[name]?.typedParams;
2005
- const typedReturns = (func ? func.returnType == null : userFunc) || builtinFuncs[name]?.typedReturns;
1992
+ const typedReturns = (func && func.returnType == null) || builtinFuncs[name]?.typedReturns;
2006
1993
  const paramCount = func && (typedParams ? func.params.length / 2 : func.params.length);
2007
1994
 
2008
1995
  let args = decl.arguments;
@@ -3471,8 +3458,7 @@ const generateMember = (scope, decl, _global, _name) => {
3471
3458
  if (decl.property.name === 'length') {
3472
3459
  const func = funcs.find(x => x.name === name);
3473
3460
  if (func) {
3474
- const userFunc = funcIndex[name] && !importedFuncs[name] && !builtinFuncs[name] && !internalConstrs[name];
3475
- const typedParams = userFunc || builtinFuncs[name]?.typedParams;
3461
+ const typedParams = !func.internal || builtinFuncs[name]?.typedParams;
3476
3462
  return withType(scope, number(typedParams ? func.params.length / 2 : func.params.length), TYPES.number);
3477
3463
  }
3478
3464
 
@@ -3698,34 +3684,39 @@ const generateFunc = (scope, decl) => {
3698
3684
  const name = decl.id ? decl.id.name : `anonymous_${randId()}`;
3699
3685
  const params = decl.params ?? [];
3700
3686
 
3701
- // const innerScope = { ...scope };
3702
3687
  // TODO: share scope/locals between !!!
3703
- const innerScope = {
3688
+ const func = {
3704
3689
  locals: {},
3705
3690
  localInd: 0,
3706
3691
  // value, type
3707
3692
  returns: [ valtypeBinary, Valtype.i32 ],
3708
3693
  throws: false,
3709
- name
3694
+ name,
3695
+ index: currentFuncIndex++
3710
3696
  };
3711
3697
 
3712
3698
  if (typedInput && decl.returnType) {
3713
3699
  const { type } = extractTypeAnnotation(decl.returnType);
3714
3700
  // if (type != null && !Prefs.indirectCalls) {
3715
3701
  if (type != null) {
3716
- innerScope.returnType = type;
3717
- innerScope.returns = [ valtypeBinary ];
3702
+ func.returnType = type;
3703
+ func.returns = [ valtypeBinary ];
3718
3704
  }
3719
3705
  }
3720
3706
 
3721
3707
  for (let i = 0; i < params.length; i++) {
3722
- allocVar(innerScope, params[i].name, false);
3708
+ const name = params[i].name;
3709
+ // if (name == null) return todo('non-identifier args are not supported');
3710
+
3711
+ allocVar(func, name, false);
3723
3712
 
3724
3713
  if (typedInput && params[i].typeAnnotation) {
3725
- addVarMetadata(innerScope, params[i].name, false, extractTypeAnnotation(params[i]));
3714
+ addVarMetadata(func, name, false, extractTypeAnnotation(params[i]));
3726
3715
  }
3727
3716
  }
3728
3717
 
3718
+ func.params = Object.values(func.locals).map(x => x.type);
3719
+
3729
3720
  let body = objectHack(decl.body);
3730
3721
  if (decl.type === 'ArrowFunctionExpression' && decl.expression) {
3731
3722
  // hack: () => 0 -> () => return 0
@@ -3735,37 +3726,23 @@ const generateFunc = (scope, decl) => {
3735
3726
  };
3736
3727
  }
3737
3728
 
3738
- const wasm = generate(innerScope, body);
3739
- const func = {
3740
- name,
3741
- params: Object.values(innerScope.locals).slice(0, params.length * 2).map(x => x.type),
3742
- index: currentFuncIndex++,
3743
- ...innerScope
3744
- };
3745
3729
  funcIndex[name] = func.index;
3730
+ funcs.push(func);
3746
3731
 
3747
- if (name === 'main') func.gotLastType = true;
3732
+ const wasm = generate(func, body);
3733
+ func.wasm = wasm;
3748
3734
 
3749
- // quick hack fixes
3750
- for (const inst of wasm) {
3751
- if (inst[0] === Opcodes.call && inst[1] === -1) {
3752
- inst[1] = func.index;
3753
- }
3754
- }
3735
+ if (name === 'main') func.gotLastType = true;
3755
3736
 
3756
3737
  // add end return if not found
3757
3738
  if (name !== 'main' && wasm[wasm.length - 1]?.[0] !== Opcodes.return && countLeftover(wasm) === 0) {
3758
3739
  wasm.push(
3759
3740
  ...number(0),
3760
- ...(innerScope.returnType != null ? [] : number(TYPES.undefined, Valtype.i32)),
3741
+ ...(func.returnType != null ? [] : number(TYPES.undefined, Valtype.i32)),
3761
3742
  [ Opcodes.return ]
3762
3743
  );
3763
3744
  }
3764
3745
 
3765
- func.wasm = wasm;
3766
-
3767
- funcs.push(func);
3768
-
3769
3746
  return func;
3770
3747
  };
3771
3748
 
@@ -4014,9 +3991,8 @@ export default program => {
4014
3991
 
4015
3992
  if (Prefs.astLog) console.log(JSON.stringify(program.body.body, null, 2));
4016
3993
 
4017
- generateFunc(scope, program);
3994
+ const main = generateFunc(scope, program);
4018
3995
 
4019
- const main = funcs[funcs.length - 1];
4020
3996
  main.export = true;
4021
3997
  main.returns = [ valtypeBinary, Valtype.i32 ];
4022
3998
 
@@ -4043,7 +4019,7 @@ export default program => {
4043
4019
  }
4044
4020
 
4045
4021
  // if blank main func and other exports, remove it
4046
- if (main.wasm.length === 0 && funcs.reduce((acc, x) => acc + (x.export ? 1 : 0), 0) > 1) funcs.splice(funcs.length - 1, 1);
4022
+ if (main.wasm.length === 0 && funcs.reduce((acc, x) => acc + (x.export ? 1 : 0), 0) > 1) funcs.splice(main.index - importedFuncs.length, 1);
4047
4023
 
4048
4024
  return { funcs, globals, tags, exceptions, pages, data };
4049
4025
  };
@@ -1376,6 +1376,213 @@ export const BuiltinFuncs = function() {
1376
1376
  locals: [127,127,124,124,124,124,124,124,124,124,124,124],
1377
1377
  localNames: ["input","input#type","radix","radix#type","logictmpi","#last_type","nMax","n","inputPtr","len","i","negative","endPtr","startChr","second","chr"],
1378
1378
  };
1379
+ this.__Math_exp = {
1380
+ wasm: (scope, {builtin,}) => [[32,0],[16, builtin('__Number_isFinite')],[68,0,0,0,0,0,0,0,0],[97],[4,64],[32,0],[68,0,0,0,0,0,0,240,127],[154],[97],[4,64],[68,0,0,0,0,0,0,0,0],[15],[11],[32,0],[15],[11],[32,0],[68,0,0,0,0,0,0,0,0],[99],[4,64],[68,0,0,0,0,0,0,240,63],[32,0],[154],[65,0],[16, builtin('__Math_exp')],[163],[15],[11],[32,0],[68,239,57,250,254,66,46,230,63],[163],[16, builtin('__Math_floor')],[33,2],[32,0],[32,2],[68,239,57,250,254,66,46,230,63],[162],[161],[34,3],[33,4],[68,0,0,0,0,0,0,240,63],[32,3],[160],[33,5],[68,0,0,0,0,0,0,0,64],[33,6],[3,64],[32,4],[16, builtin('__Math_abs')],[68,22,86,231,158,175,3,210,60],[100],[4,64],[32,4],[32,3],[32,6],[163],[162],[33,4],[32,5],[32,4],[160],[33,5],[32,6],[68,0,0,0,0,0,0,240,63],[160],[33,6],[12,1],[11],[11],[32,5],[68,0,0,0,0,0,0,240,63],[32,2],[16, builtin('f64_<<')],[162],[15]],
1381
+ params: [124,127],
1382
+ typedParams: true,
1383
+ returns: [124],
1384
+ returnType: 0,
1385
+ locals: [124,124,124,124,124],
1386
+ localNames: ["x","x#type","k","r","term","sum","i"],
1387
+ };
1388
+ this.__Math_log2 = {
1389
+ wasm: (scope, {builtin,}) => [[32,0],[68,0,0,0,0,0,0,0,0],[101],[4,64],[68,0,0,0,0,0,0,248,127],[15],[11],[32,0],[16, builtin('__Number_isFinite')],[68,0,0,0,0,0,0,0,0],[97],[4,64],[32,0],[15],[11],[32,0],[33,2],[68,0,0,0,0,0,0,0,0],[33,3],[3,64],[32,2],[68,0,0,0,0,0,0,0,64],[102],[4,64],[32,2],[68,0,0,0,0,0,0,0,64],[163],[33,2],[32,3],[68,0,0,0,0,0,0,240,63],[160],[33,3],[12,1],[11],[11],[3,64],[32,2],[68,0,0,0,0,0,0,240,63],[99],[4,64],[32,2],[68,0,0,0,0,0,0,0,64],[162],[33,2],[32,3],[68,0,0,0,0,0,0,240,63],[161],[33,3],[12,1],[11],[11],[32,2],[68,0,0,0,0,0,0,240,63],[161],[33,2],[3,64],[2,64],[32,2],[68,239,57,250,254,66,46,230,63],[162],[65,0],[16, builtin('__Math_exp')],[34,5],[32,0],[161],[32,5],[68,239,57,250,254,66,46,230,63],[162],[163],[33,4],[32,2],[32,4],[161],[33,2],[32,4],[16, builtin('__Math_abs')],[68,22,86,231,158,175,3,210,60],[100],[13,1],[11],[11],[32,2],[32,3],[160],[15]],
1390
+ params: [124,127],
1391
+ typedParams: true,
1392
+ returns: [124],
1393
+ returnType: 0,
1394
+ locals: [124,124,124,124],
1395
+ localNames: ["y","y#type","x","exponent","delta","e_x"],
1396
+ };
1397
+ this.__Math_log = {
1398
+ wasm: (scope, {builtin,}) => [[32,0],[68,0,0,0,0,0,0,0,0],[101],[4,64],[32,0],[68,0,0,0,0,0,0,0,0],[97],[4,64],[68,0,0,0,0,0,0,240,127],[154],[15],[11],[68,0,0,0,0,0,0,248,127],[15],[11],[32,0],[16, builtin('__Number_isFinite')],[68,0,0,0,0,0,0,0,0],[97],[4,64],[32,0],[15],[11],[32,0],[68,0,0,0,0,0,0,240,63],[100],[4,124],[32,0],[65,0],[16, builtin('__Math_log2')],[65,0],[33,3],[5],[68,0,0,0,0,0,0,0,0],[65,0],[33,3],[11],[33,2],[3,64],[2,64],[32,2],[65,0],[16, builtin('__Math_exp')],[34,5],[32,0],[161],[32,5],[163],[33,4],[32,2],[32,4],[161],[33,2],[32,4],[16, builtin('__Math_abs')],[68,22,86,231,158,175,3,210,60],[100],[13,1],[11],[11],[32,2],[15]],
1399
+ params: [124,127],
1400
+ typedParams: true,
1401
+ returns: [124],
1402
+ returnType: 0,
1403
+ locals: [124,127,124,124],
1404
+ localNames: ["y","y#type","x","#last_type","delta","e_x"],
1405
+ };
1406
+ this.__Math_log10 = {
1407
+ wasm: (scope, {builtin,}) => [[32,0],[68,0,0,0,0,0,0,0,0],[101],[4,64],[32,0],[68,0,0,0,0,0,0,0,0],[97],[4,64],[68,0,0,0,0,0,0,240,127],[154],[15],[11],[68,0,0,0,0,0,0,248,127],[15],[11],[32,0],[16, builtin('__Number_isFinite')],[68,0,0,0,0,0,0,0,0],[97],[4,64],[32,0],[15],[11],[32,0],[65,0],[16, builtin('__Math_log')],[68,22,85,181,187,177,107,2,64],[163],[15]],
1408
+ params: [124,127],
1409
+ typedParams: true,
1410
+ returns: [124],
1411
+ returnType: 0,
1412
+ locals: [],
1413
+ localNames: ["x","x#type"],
1414
+ };
1415
+ this.__Math_pow = {
1416
+ wasm: (scope, {builtin,}) => [[32,2],[16, builtin('__Number_isNaN')],[252,3],[4,64],[68,0,0,0,0,0,0,248,127],[15],[11],[32,2],[68,0,0,0,0,0,0,0,0],[97],[4,64],[68,0,0,0,0,0,0,240,63],[15],[11],[32,0],[16, builtin('__Number_isFinite')],[68,0,0,0,0,0,0,0,0],[97],[4,64],[32,0],[16, builtin('__Number_isNaN')],[252,3],[4,64],[32,0],[15],[11],[32,0],[68,0,0,0,0,0,0,240,127],[97],[4,64],[32,2],[68,0,0,0,0,0,0,0,0],[100],[4,64],[32,0],[15],[11],[68,0,0,0,0,0,0,0,0],[15],[11],[32,2],[68,0,0,0,0,0,0,0,64],[16, builtin('f64_%')],[68,0,0,0,0,0,0,240,63],[97],[184],[33,4],[65,1],[33,5],[32,2],[68,0,0,0,0,0,0,0,0],[100],[4,64],[32,4],[33,6],[32,5],[33,7],[2,127],[32,7],[65,2],[70],[4,64,"TYPESWITCH|String"],[32,6],[252,3],[40,1,0],[12,1],[11],[32,7],[65,16],[70],[4,64,"TYPESWITCH|Array"],[65,1],[12,1],[11],[32,7],[65,18],[70],[4,64,"TYPESWITCH|ByteString"],[32,6],[252,3],[40,1,0],[12,1],[11],[32,6],[252,3],[11,"TYPESWITCH_end"],[4,64],[68,0,0,0,0,0,0,240,127],[154],[15],[11],[68,0,0,0,0,0,0,240,127],[15],[11],[32,4],[33,6],[32,5],[33,7],[2,127],[32,7],[65,2],[70],[4,64,"TYPESWITCH|String"],[32,6],[252,3],[40,1,0],[12,1],[11],[32,7],[65,16],[70],[4,64,"TYPESWITCH|Array"],[65,1],[12,1],[11],[32,7],[65,18],[70],[4,64,"TYPESWITCH|ByteString"],[32,6],[252,3],[40,1,0],[12,1],[11],[32,6],[252,3],[11,"TYPESWITCH_end"],[4,64],[68,0,0,0,0,0,0,0,128],[15],[11],[68,0,0,0,0,0,0,0,0],[15],[11],[32,0],[68,0,0,0,0,0,0,0,0],[97],[4,64],[68,0,0,0,0,0,0,240,63],[32,0],[163],[68,0,0,0,0,0,0,240,127],[97],[4,64],[32,2],[68,0,0,0,0,0,0,0,0],[100],[4,64],[68,0,0,0,0,0,0,0,0],[15],[11],[68,0,0,0,0,0,0,240,127],[15],[11],[32,2],[68,0,0,0,0,0,0,0,64],[16, builtin('f64_%')],[68,0,0,0,0,0,0,240,63],[97],[184],[33,4],[65,1],[33,5],[32,2],[68,0,0,0,0,0,0,0,0],[100],[4,64],[32,4],[33,6],[32,5],[33,7],[2,127],[32,7],[65,2],[70],[4,64,"TYPESWITCH|String"],[32,6],[252,3],[40,1,0],[12,1],[11],[32,7],[65,16],[70],[4,64,"TYPESWITCH|Array"],[65,1],[12,1],[11],[32,7],[65,18],[70],[4,64,"TYPESWITCH|ByteString"],[32,6],[252,3],[40,1,0],[12,1],[11],[32,6],[252,3],[11,"TYPESWITCH_end"],[4,64],[68,0,0,0,0,0,0,0,128],[15],[11],[68,0,0,0,0,0,0,0,0],[15],[11],[32,4],[33,6],[32,5],[33,7],[2,127],[32,7],[65,2],[70],[4,64,"TYPESWITCH|String"],[32,6],[252,3],[40,1,0],[12,1],[11],[32,7],[65,16],[70],[4,64,"TYPESWITCH|Array"],[65,1],[12,1],[11],[32,7],[65,18],[70],[4,64,"TYPESWITCH|ByteString"],[32,6],[252,3],[40,1,0],[12,1],[11],[32,6],[252,3],[11,"TYPESWITCH_end"],[4,64],[68,0,0,0,0,0,0,240,127],[154],[15],[11],[68,0,0,0,0,0,0,240,127],[15],[11],[32,2],[68,0,0,0,0,0,0,240,127],[97],[4,64],[32,0],[16, builtin('__Math_abs')],[33,8],[65,0],[33,9],[32,8],[68,0,0,0,0,0,0,240,63],[100],[4,64],[68,0,0,0,0,0,0,240,127],[15],[11],[32,8],[68,0,0,0,0,0,0,240,63],[97],[4,64],[68,0,0,0,0,0,0,248,127],[15],[11],[68,0,0,0,0,0,0,0,0],[15],[11],[32,2],[68,0,0,0,0,0,0,240,127],[154],[97],[4,64],[32,0],[16, builtin('__Math_abs')],[33,8],[65,0],[33,9],[32,8],[68,0,0,0,0,0,0,240,63],[100],[4,64],[68,0,0,0,0,0,0,0,0],[15],[11],[32,8],[68,0,0,0,0,0,0,240,63],[97],[4,64],[68,0,0,0,0,0,0,248,127],[15],[11],[68,0,0,0,0,0,0,240,127],[15],[11],[32,0],[68,0,0,0,0,0,0,0,0],[99],[4,64],[32,2],[16, builtin('__Number_isInteger')],[68,0,0,0,0,0,0,0,0],[97],[4,64],[68,0,0,0,0,0,0,248,127],[15],[11],[11],[32,2],[32,0],[65,0],[16, builtin('__Math_log')],[162],[65,0],[16, builtin('__Math_exp')],[15]],
1417
+ params: [124,127,124,127],
1418
+ typedParams: true,
1419
+ returns: [124],
1420
+ returnType: 0,
1421
+ locals: [124,127,124,127,124,127],
1422
+ localNames: ["base","base#type","exponent","exponent#type","isOdd","isOdd#type","#logicinner_tmp","#typeswitch_tmp","abs","abs#type"],
1423
+ };
1424
+ this.__Math_expm1 = {
1425
+ wasm: (scope, {builtin,}) => [[32,0],[16, builtin('__Number_isFinite')],[68,0,0,0,0,0,0,0,0],[97],[4,64],[32,0],[68,0,0,0,0,0,0,240,127],[154],[97],[4,64],[68,0,0,0,0,0,0,240,191],[15],[11],[32,0],[15],[11],[32,0],[16, builtin('__Math_abs')],[68,241,104,227,136,181,248,228,62],[100],[4,64],[32,0],[65,0],[16, builtin('__Math_exp')],[68,0,0,0,0,0,0,240,63],[161],[15],[11],[32,0],[33,2],[32,0],[33,3],[68,0,0,0,0,0,0,0,64],[33,4],[3,64],[32,3],[16, builtin('__Math_abs')],[68,22,86,231,158,175,3,210,60],[100],[4,64],[32,3],[32,0],[32,4],[163],[162],[33,3],[32,2],[32,3],[160],[33,2],[32,4],[68,0,0,0,0,0,0,240,63],[160],[33,4],[12,1],[11],[11],[32,2],[15]],
1426
+ params: [124,127],
1427
+ typedParams: true,
1428
+ returns: [124],
1429
+ returnType: 0,
1430
+ locals: [124,124,124],
1431
+ localNames: ["x","x#type","sum","term","i"],
1432
+ };
1433
+ this.__Math_log1p = {
1434
+ wasm: (scope, {builtin,}) => [[32,0],[68,0,0,0,0,0,0,240,191],[97],[4,64],[68,0,0,0,0,0,0,240,127],[154],[15],[11],[32,0],[16, builtin('__Number_isFinite')],[68,0,0,0,0,0,0,0,0],[97],[4,64],[32,0],[15],[11],[32,0],[16, builtin('__Math_abs')],[68,241,104,227,136,181,248,228,62],[100],[4,64],[68,0,0,0,0,0,0,240,63],[32,0],[160],[65,0],[16, builtin('__Math_log')],[15],[11],[68,0,0,0,0,0,0,0,0],[33,2],[32,0],[33,3],[68,0,0,0,0,0,0,0,64],[33,4],[3,64],[32,3],[16, builtin('__Math_abs')],[68,22,86,231,158,175,3,210,60],[100],[4,64],[32,3],[32,0],[154],[32,4],[163],[162],[33,3],[32,2],[32,3],[160],[33,2],[32,4],[68,0,0,0,0,0,0,240,63],[160],[33,4],[12,1],[11],[11],[32,2],[15]],
1435
+ params: [124,127],
1436
+ typedParams: true,
1437
+ returns: [124],
1438
+ returnType: 0,
1439
+ locals: [124,124,124],
1440
+ localNames: ["x","x#type","sum","term","i"],
1441
+ };
1442
+ this.__Math_sqrt = {
1443
+ wasm: (scope, {builtin,}) => [[32,0],[68,0,0,0,0,0,0,0,0],[101],[4,64],[32,0],[68,0,0,0,0,0,0,0,0],[97],[4,64],[68,0,0,0,0,0,0,0,0],[15],[11],[68,0,0,0,0,0,0,248,127],[15],[11],[32,0],[16, builtin('__Number_isFinite')],[68,0,0,0,0,0,0,0,0],[97],[4,64],[32,0],[15],[11],[32,0],[33,2],[3,64],[2,64],[32,2],[33,3],[68,0,0,0,0,0,0,224,63],[32,2],[32,0],[32,2],[163],[160],[162],[33,2],[32,3],[32,2],[161],[16, builtin('__Math_abs')],[68,22,86,231,158,175,3,210,60],[100],[13,1],[11],[11],[32,2],[15]],
1444
+ params: [124,127],
1445
+ typedParams: true,
1446
+ returns: [124],
1447
+ returnType: 0,
1448
+ locals: [124,124],
1449
+ localNames: ["y","y#type","x","prev"],
1450
+ };
1451
+ this.__Math_cbrt = {
1452
+ wasm: (scope, {builtin,}) => [[32,0],[68,0,0,0,0,0,0,0,0],[97],[4,64],[68,0,0,0,0,0,0,0,0],[15],[11],[32,0],[16, builtin('__Number_isFinite')],[68,0,0,0,0,0,0,0,0],[97],[4,64],[32,0],[15],[11],[32,0],[16, builtin('__Math_abs')],[33,2],[65,0],[33,3],[3,64],[2,64],[32,2],[33,4],[68,0,0,0,0,0,0,0,64],[32,2],[162],[32,0],[32,2],[32,2],[162],[163],[160],[68,0,0,0,0,0,0,8,64],[163],[34,2],[65,0],[33,3],[26],[32,4],[32,2],[161],[16, builtin('__Math_abs')],[68,22,86,231,158,175,3,210,60],[100],[13,1],[11],[11],[32,0],[68,0,0,0,0,0,0,0,0],[99],[4,124],[32,2],[154],[5],[32,2],[11],[15]],
1453
+ params: [124,127],
1454
+ typedParams: true,
1455
+ returns: [124],
1456
+ returnType: 0,
1457
+ locals: [124,127,124,127],
1458
+ localNames: ["y","y#type","x","x#type","prev","#last_type"],
1459
+ };
1460
+ this.__Math_hypot = {
1461
+ wasm: (scope, {builtin,}) => [[32,0],[32,0],[162],[32,2],[32,2],[162],[160],[65,0],[16, builtin('__Math_sqrt')],[15]],
1462
+ params: [124,127,124,127],
1463
+ typedParams: true,
1464
+ returns: [124],
1465
+ returnType: 0,
1466
+ locals: [],
1467
+ localNames: ["x","x#type","y","y#type"],
1468
+ };
1469
+ this.__Math_sin = {
1470
+ wasm: (scope, {builtin,}) => [[68,24,45,68,84,251,33,9,64],[68,0,0,0,0,0,0,0,64],[162],[33,2],[32,0],[32,2],[16, builtin('f64_%')],[34,0],[68,0,0,0,0,0,0,0,0],[99],[4,64],[32,0],[32,2],[160],[33,0],[11],[32,0],[32,0],[162],[33,3],[32,0],[68,0,0,0,0,0,0,240,63],[32,3],[68,72,85,85,85,85,85,197,191],[32,3],[68,208,247,16,17,17,17,129,63],[32,3],[68,3,223,191,25,160,1,42,191],[32,3],[68,161,72,125,86,227,29,199,62],[32,3],[68,93,31,41,169,229,229,90,190],[32,3],[68,205,156,209,31,253,216,229,61],[162],[160],[162],[160],[162],[160],[162],[160],[162],[160],[162],[160],[162],[15]],
1471
+ params: [124,127],
1472
+ typedParams: true,
1473
+ returns: [124],
1474
+ returnType: 0,
1475
+ locals: [124,124],
1476
+ localNames: ["x","x#type","piX2","x2"],
1477
+ };
1478
+ this.__Math_cos = {
1479
+ wasm: (scope, {builtin,}) => [[32,0],[68,24,45,68,84,251,33,9,64],[68,0,0,0,0,0,0,0,64],[163],[161],[65,0],[16, builtin('__Math_sin')],[15]],
1480
+ params: [124,127],
1481
+ typedParams: true,
1482
+ returns: [124],
1483
+ returnType: 0,
1484
+ locals: [],
1485
+ localNames: ["x","x#type"],
1486
+ };
1487
+ this.__Math_tan = {
1488
+ wasm: (scope, {builtin,}) => [[32,0],[65,0],[16, builtin('__Math_sin')],[32,0],[65,0],[16, builtin('__Math_cos')],[163],[15]],
1489
+ params: [124,127],
1490
+ typedParams: true,
1491
+ returns: [124],
1492
+ returnType: 0,
1493
+ locals: [],
1494
+ localNames: ["x","x#type"],
1495
+ };
1496
+ this.__Math_sinh = {
1497
+ wasm: (scope, {builtin,}) => [[32,0],[65,0],[16, builtin('__Math_exp')],[32,0],[154],[65,0],[16, builtin('__Math_exp')],[161],[68,0,0,0,0,0,0,0,64],[163],[15]],
1498
+ params: [124,127],
1499
+ typedParams: true,
1500
+ returns: [124],
1501
+ returnType: 0,
1502
+ locals: [],
1503
+ localNames: ["x","x#type"],
1504
+ };
1505
+ this.__Math_cosh = {
1506
+ wasm: (scope, {builtin,}) => [[32,0],[65,0],[16, builtin('__Math_exp')],[32,0],[154],[65,0],[16, builtin('__Math_exp')],[160],[68,0,0,0,0,0,0,0,64],[163],[15]],
1507
+ params: [124,127],
1508
+ typedParams: true,
1509
+ returns: [124],
1510
+ returnType: 0,
1511
+ locals: [],
1512
+ localNames: ["x","x#type"],
1513
+ };
1514
+ this.__Math_tanh = {
1515
+ wasm: (scope, {builtin,}) => [[32,0],[65,0],[16, builtin('__Math_sinh')],[32,0],[65,0],[16, builtin('__Math_cosh')],[163],[15]],
1516
+ params: [124,127],
1517
+ typedParams: true,
1518
+ returns: [124],
1519
+ returnType: 0,
1520
+ locals: [],
1521
+ localNames: ["x","x#type"],
1522
+ };
1523
+ this.__Math_asinh = {
1524
+ wasm: (scope, {builtin,}) => [[32,0],[32,0],[32,0],[162],[68,0,0,0,0,0,0,240,63],[160],[65,0],[16, builtin('__Math_sqrt')],[160],[65,0],[16, builtin('__Math_log')],[15]],
1525
+ params: [124,127],
1526
+ typedParams: true,
1527
+ returns: [124],
1528
+ returnType: 0,
1529
+ locals: [],
1530
+ localNames: ["x","x#type"],
1531
+ };
1532
+ this.__Math_acosh = {
1533
+ wasm: (scope, {builtin,}) => [[32,0],[68,0,0,0,0,0,0,240,63],[99],[4,64],[68,0,0,0,0,0,0,248,127],[15],[11],[32,0],[32,0],[32,0],[162],[68,0,0,0,0,0,0,240,63],[161],[65,0],[16, builtin('__Math_sqrt')],[160],[65,0],[16, builtin('__Math_log')],[15]],
1534
+ params: [124,127],
1535
+ typedParams: true,
1536
+ returns: [124],
1537
+ returnType: 0,
1538
+ locals: [],
1539
+ localNames: ["x","x#type"],
1540
+ };
1541
+ this.__Math_atanh = {
1542
+ wasm: (scope, {builtin,}) => [[32,0],[16, builtin('__Math_abs')],[68,0,0,0,0,0,0,240,63],[102],[4,64],[68,0,0,0,0,0,0,248,127],[15],[11],[68,0,0,0,0,0,0,224,63],[68,0,0,0,0,0,0,240,63],[32,0],[160],[68,0,0,0,0,0,0,240,63],[32,0],[161],[163],[65,0],[16, builtin('__Math_log')],[162],[15]],
1543
+ params: [124,127],
1544
+ typedParams: true,
1545
+ returns: [124],
1546
+ returnType: 0,
1547
+ locals: [],
1548
+ localNames: ["x","x#type"],
1549
+ };
1550
+ this.__Math_asin = {
1551
+ wasm: (scope, {builtin,}) => [[32,0],[68,0,0,0,0,0,0,240,191],[101],[4,64],[32,0],[68,0,0,0,0,0,0,240,191],[97],[4,64],[68,24,45,68,84,251,33,9,64],[154],[68,0,0,0,0,0,0,0,64],[163],[15],[11],[68,0,0,0,0,0,0,248,127],[15],[11],[32,0],[68,0,0,0,0,0,0,240,63],[102],[4,64],[32,0],[68,0,0,0,0,0,0,240,63],[97],[4,64],[68,24,45,68,84,251,33,9,64],[68,0,0,0,0,0,0,0,64],[163],[15],[11],[68,0,0,0,0,0,0,248,127],[15],[11],[32,0],[33,2],[32,0],[33,3],[68,0,0,0,0,0,0,240,63],[33,4],[3,64],[32,3],[16, builtin('__Math_abs')],[68,22,86,231,158,175,3,210,60],[100],[4,64],[32,3],[32,0],[32,0],[162],[68,0,0,0,0,0,0,0,64],[32,4],[162],[68,0,0,0,0,0,0,240,63],[161],[162],[68,0,0,0,0,0,0,0,64],[32,4],[162],[68,0,0,0,0,0,0,240,63],[161],[162],[68,0,0,0,0,0,0,0,64],[32,4],[162],[68,0,0,0,0,0,0,0,64],[32,4],[162],[68,0,0,0,0,0,0,240,63],[160],[162],[163],[162],[33,3],[32,2],[32,3],[68,0,0,0,0,0,0,0,64],[32,4],[162],[68,0,0,0,0,0,0,240,63],[160],[163],[160],[33,2],[32,4],[68,0,0,0,0,0,0,240,63],[160],[33,4],[12,1],[11],[11],[32,2],[15]],
1552
+ params: [124,127],
1553
+ typedParams: true,
1554
+ returns: [124],
1555
+ returnType: 0,
1556
+ locals: [124,124,124],
1557
+ localNames: ["x","x#type","sum","term","n"],
1558
+ };
1559
+ this.__Math_acos = {
1560
+ wasm: (scope, {builtin,}) => [[32,0],[65,0],[16, builtin('__Math_asin')],[68,24,45,68,84,251,33,9,64],[68,0,0,0,0,0,0,0,64],[163],[161],[15]],
1561
+ params: [124,127],
1562
+ typedParams: true,
1563
+ returns: [124],
1564
+ returnType: 0,
1565
+ locals: [],
1566
+ localNames: ["x","x#type"],
1567
+ };
1568
+ this.__Math_atan = {
1569
+ wasm: (scope, {builtin,}) => [[32,0],[68,0,0,0,0,0,0,240,127],[97],[4,64],[68,24,45,68,84,251,33,9,64],[68,0,0,0,0,0,0,0,64],[163],[15],[11],[32,0],[68,0,0,0,0,0,0,240,127],[154],[97],[4,64],[68,24,45,68,84,251,33,9,64],[154],[68,0,0,0,0,0,0,0,64],[163],[15],[11],[32,0],[33,2],[32,0],[33,3],[68,0,0,0,0,0,0,240,63],[33,4],[3,64],[32,3],[16, builtin('__Math_abs')],[68,22,86,231,158,175,3,210,60],[100],[4,64],[32,3],[32,0],[154],[32,0],[162],[68,0,0,0,0,0,0,0,64],[32,4],[162],[68,0,0,0,0,0,0,240,63],[161],[162],[68,0,0,0,0,0,0,0,64],[32,4],[162],[68,0,0,0,0,0,0,0,64],[32,4],[162],[68,0,0,0,0,0,0,240,63],[160],[162],[163],[162],[33,3],[32,2],[32,3],[160],[33,2],[32,4],[68,0,0,0,0,0,0,240,63],[160],[33,4],[12,1],[11],[11],[32,2],[15]],
1570
+ params: [124,127],
1571
+ typedParams: true,
1572
+ returns: [124],
1573
+ returnType: 0,
1574
+ locals: [124,124,124],
1575
+ localNames: ["x","x#type","sum","term","n"],
1576
+ };
1577
+ this.__Math_atan2 = {
1578
+ wasm: (scope, {builtin,}) => [[32,2],[68,0,0,0,0,0,0,0,0],[97],[4,64],[32,0],[68,0,0,0,0,0,0,0,0],[100],[4,64],[68,24,45,68,84,251,33,9,64],[68,0,0,0,0,0,0,0,64],[163],[15],[11],[32,0],[68,0,0,0,0,0,0,0,0],[99],[4,64],[68,24,45,68,84,251,33,9,64],[154],[68,0,0,0,0,0,0,0,64],[163],[15],[11],[68,0,0,0,0,0,0,248,127],[15],[11],[32,0],[32,2],[163],[33,4],[65,0],[33,5],[32,2],[68,0,0,0,0,0,0,0,0],[100],[4,64],[32,4],[32,5],[16, builtin('__Math_atan')],[15],[11],[32,0],[68,0,0,0,0,0,0,0,0],[102],[4,64],[32,4],[32,5],[16, builtin('__Math_atan')],[68,24,45,68,84,251,33,9,64],[160],[15],[11],[32,4],[32,5],[16, builtin('__Math_atan')],[68,24,45,68,84,251,33,9,64],[161],[15]],
1579
+ params: [124,127,124,127],
1580
+ typedParams: true,
1581
+ returns: [124],
1582
+ returnType: 0,
1583
+ locals: [124,127],
1584
+ localNames: ["y","y#type","x","x#type","ratio","ratio#type"],
1585
+ };
1379
1586
  this.__Number_prototype_toString = {
1380
1587
  wasm: (scope, {allocPage,builtin,internalThrow,}) => [...number(allocPage(scope, 'bytestring: __Number_prototype_toString/out', 'i8') * pageSize, 124),[34,4],[33,5],[32,0],[16, builtin('__Number_isFinite')],[68,0,0,0,0,0,0,0,0],[97],[4,64],[32,0],[16, builtin('__Number_isNaN')],[252,3],[4,64],[32,4],[252,3],[34,6],[65,3],[54,1,0],[32,6],[65,206,0],[58,0,4],[32,6],[65,225,0],[58,0,5],[32,6],[65,206,0],[58,0,6],[32,6],[184],[33,4],[5],[32,0],[68,0,0,0,0,0,0,240,127],[97],[4,64],[32,4],[252,3],[34,6],[65,8],[54,1,0],[32,6],[65,201,0],[58,0,4],[32,6],[65,238,0],[58,0,5],[32,6],[65,230,0],[58,0,6],[32,6],[65,233,0],[58,0,7],[32,6],[65,238,0],[58,0,8],[32,6],[65,233,0],[58,0,9],[32,6],[65,244,0],[58,0,10],[32,6],[65,249,0],[58,0,11],[32,6],[184],[33,4],[5],[32,4],[252,3],[34,6],[65,9],[54,1,0],[32,6],[65,45],[58,0,4],[32,6],[65,201,0],[58,0,5],[32,6],[65,238,0],[58,0,6],[32,6],[65,230,0],[58,0,7],[32,6],[65,233,0],[58,0,8],[32,6],[65,238,0],[58,0,9],[32,6],[65,233,0],[58,0,10],[32,6],[65,244,0],[58,0,11],[32,6],[65,249,0],[58,0,12],[32,6],[184],[33,4],[11],[11],[32,4],[65,18],[15],[11],[32,2],[32,3],[16, builtin('__Porffor_rawType')],[68,0,0,0,0,0,0,0,0],[98],[4,64],[68,0,0,0,0,0,0,36,64],[34,2],[65,0],[33,3],[26],[11],[32,2],[68,0,0,0,0,0,0,0,0],[16, builtin('f64_|')],[34,2],[65,0],[33,3],[26],[32,2],[68,0,0,0,0,0,0,0,64],[99],[34,7],[69],[4,127],[32,2],[68,0,0,0,0,0,0,66,64],[100],[65,1],[33,8],[5],[32,7],[65,1],[33,8],[11],[4,64],...internalThrow(scope, 'RangeError', `toString() radix argument must be between 2 and 36`),[11],[32,0],[68,0,0,0,0,0,0,0,0],[97],[4,64],[32,4],[252,3],[34,6],[65,1],[54,1,0],[32,6],[65,48],[58,0,4],[32,6],[184],[34,4],[65,18],[15],[11],[32,0],[68,0,0,0,0,0,0,0,0],[99],[4,64],[32,0],[154],[33,0],[32,5],[32,5],[68,0,0,0,0,0,0,240,63],[160],[33,5],[252,2],[65,45],[58,0,4],[11],[32,0],[16, builtin('__Math_trunc')],[33,9],...number(allocPage(scope, 'bytestring: __Number_prototype_toString/digits', 'i8') * pageSize, 124),[33,10],[68,0,0,0,0,0,0,0,0],[33,11],[32,2],[68,0,0,0,0,0,0,36,64],[97],[4,64],[32,9],[68,80,239,226,214,228,26,75,68],[102],[4,64],[68,0,0,0,0,0,0,240,63],[33,12],[68,0,0,0,0,0,0,240,191],[33,13],[3,64],[32,9],[68,0,0,0,0,0,0,0,0],[100],[4,64],[32,9],[32,2],[16, builtin('f64_%')],[33,14],[32,9],[32,2],[163],[16, builtin('__Math_trunc')],[33,9],[32,13],[68,0,0,0,0,0,0,240,63],[160],[33,13],[32,12],[252,3],[4,64],[32,14],[68,0,0,0,0,0,0,0,0],[97],[4,64],[12,3],[11],[68,0,0,0,0,0,0,0,0],[33,12],[11],[32,10],[32,11],[160],[252,2],[32,14],[252,2],[58,0,4],[32,11],[68,0,0,0,0,0,0,240,63],[160],[33,11],[12,1],[11],[11],[32,10],[32,11],[160],[33,15],[32,5],[32,11],[160],[33,16],[32,5],[68,0,0,0,0,0,0,240,63],[160],[33,17],[3,64],[32,5],[32,16],[99],[4,64],[32,5],[32,17],[97],[4,64],[32,5],[32,5],[68,0,0,0,0,0,0,240,63],[160],[33,5],[252,2],[65,46],[58,0,4],[32,16],[68,0,0,0,0,0,0,240,63],[160],[33,16],[11],[32,15],[68,0,0,0,0,0,0,240,63],[161],[34,15],[252,2],[45,0,4],[183],[34,14],[68,0,0,0,0,0,0,36,64],[99],[4,64],[32,14],[68,0,0,0,0,0,0,72,64],[160],[33,14],[5],[32,14],[68,0,0,0,0,0,192,85,64],[160],[33,14],[11],[32,5],[32,5],[68,0,0,0,0,0,0,240,63],[160],[33,5],[252,2],[32,14],[252,2],[58,0,4],[12,1],[11],[11],[32,5],[32,5],[68,0,0,0,0,0,0,240,63],[160],[33,5],[252,2],[65,229,0],[58,0,4],[32,5],[32,5],[68,0,0,0,0,0,0,240,63],[160],[33,5],[252,2],[65,43],[58,0,4],[68,0,0,0,0,0,0,0,0],[33,11],[3,64],[32,13],[68,0,0,0,0,0,0,0,0],[100],[4,64],[32,10],[32,11],[160],[252,2],[32,13],[32,2],[16, builtin('f64_%')],[252,2],[58,0,4],[32,13],[32,2],[163],[16, builtin('__Math_trunc')],[33,13],[32,11],[68,0,0,0,0,0,0,240,63],[160],[33,11],[12,1],[11],[11],[32,10],[32,11],[160],[33,15],[32,5],[32,11],[160],[33,16],[3,64],[32,5],[32,16],[99],[4,64],[32,15],[68,0,0,0,0,0,0,240,63],[161],[34,15],[252,2],[45,0,4],[183],[34,14],[68,0,0,0,0,0,0,36,64],[99],[4,64],[32,14],[68,0,0,0,0,0,0,72,64],[160],[33,14],[5],[32,14],[68,0,0,0,0,0,192,85,64],[160],[33,14],[11],[32,5],[32,5],[68,0,0,0,0,0,0,240,63],[160],[33,5],[252,2],[32,14],[252,2],[58,0,4],[12,1],[11],[11],[32,4],[252,3],[32,5],[32,4],[161],[34,18],[252,3],[54,1,0],[32,4],[65,18],[15],[11],[32,0],[68,141,237,181,160,247,198,176,62],[99],[4,64],[32,0],[33,19],[68,0,0,0,0,0,0,240,63],[33,13],[3,64],[65,1],[4,64],[32,19],[32,2],[162],[34,19],[16, builtin('__Math_trunc')],[34,20],[68,0,0,0,0,0,0,0,0],[100],[4,64],[32,19],[32,20],[161],[68,187,189,215,217,223,124,219,61],[99],[4,64],[12,2],[11],[5],[32,13],[68,0,0,0,0,0,0,240,63],[160],[33,13],[11],[12,1],[11],[11],[3,64],[32,19],[68,0,0,0,0,0,0,0,0],[100],[4,64],[32,19],[32,2],[16, builtin('f64_%')],[33,14],[32,19],[32,2],[163],[16, builtin('__Math_trunc')],[33,19],[32,10],[32,11],[160],[252,2],[32,14],[252,2],[58,0,4],[32,11],[68,0,0,0,0,0,0,240,63],[160],[33,11],[12,1],[11],[11],[32,10],[32,11],[160],[33,15],[32,5],[32,11],[160],[33,16],[32,5],[68,0,0,0,0,0,0,240,63],[160],[33,17],[3,64],[32,5],[32,16],[99],[4,64],[32,15],[68,0,0,0,0,0,0,240,63],[161],[34,15],[252,2],[45,0,4],[183],[33,14],[32,5],[32,17],[97],[4,64],[32,5],[32,5],[68,0,0,0,0,0,0,240,63],[160],[33,5],[252,2],[65,46],[58,0,4],[32,16],[68,0,0,0,0,0,0,240,63],[160],[33,16],[11],[32,14],[68,0,0,0,0,0,0,36,64],[99],[4,64],[32,14],[68,0,0,0,0,0,0,72,64],[160],[33,14],[5],[32,14],[68,0,0,0,0,0,192,85,64],[160],[33,14],[11],[32,5],[32,5],[68,0,0,0,0,0,0,240,63],[160],[33,5],[252,2],[32,14],[252,2],[58,0,4],[12,1],[11],[11],[32,5],[32,5],[68,0,0,0,0,0,0,240,63],[160],[33,5],[252,2],[65,229,0],[58,0,4],[32,5],[32,5],[68,0,0,0,0,0,0,240,63],[160],[33,5],[252,2],[65,45],[58,0,4],[68,0,0,0,0,0,0,0,0],[33,11],[3,64],[32,13],[68,0,0,0,0,0,0,0,0],[100],[4,64],[32,10],[32,11],[160],[252,2],[32,13],[32,2],[16, builtin('f64_%')],[252,2],[58,0,4],[32,13],[32,2],[163],[16, builtin('__Math_trunc')],[33,13],[32,11],[68,0,0,0,0,0,0,240,63],[160],[33,11],[12,1],[11],[11],[32,10],[32,11],[160],[33,15],[32,5],[32,11],[160],[33,16],[3,64],[32,5],[32,16],[99],[4,64],[32,15],[68,0,0,0,0,0,0,240,63],[161],[34,15],[252,2],[45,0,4],[183],[34,14],[68,0,0,0,0,0,0,36,64],[99],[4,64],[32,14],[68,0,0,0,0,0,0,72,64],[160],[33,14],[5],[32,14],[68,0,0,0,0,0,192,85,64],[160],[33,14],[11],[32,5],[32,5],[68,0,0,0,0,0,0,240,63],[160],[33,5],[252,2],[32,14],[252,2],[58,0,4],[12,1],[11],[11],[32,4],[252,3],[32,5],[32,4],[161],[34,18],[252,3],[54,1,0],[32,4],[65,18],[15],[11],[11],[32,9],[68,0,0,0,0,0,0,0,0],[97],[4,64],[32,10],[252,2],[65,0],[58,0,4],[68,0,0,0,0,0,0,240,63],[33,11],[5],[3,64],[32,9],[68,0,0,0,0,0,0,0,0],[100],[4,64],[32,10],[32,11],[160],[252,2],[32,9],[32,2],[16, builtin('f64_%')],[252,2],[58,0,4],[32,9],[32,2],[163],[16, builtin('__Math_trunc')],[33,9],[32,11],[68,0,0,0,0,0,0,240,63],[160],[33,11],[12,1],[11],[11],[11],[32,10],[32,11],[160],[33,15],[32,5],[32,11],[160],[33,16],[3,64],[32,5],[32,16],[99],[4,64],[32,15],[68,0,0,0,0,0,0,240,63],[161],[34,15],[252,2],[45,0,4],[183],[34,14],[68,0,0,0,0,0,0,36,64],[99],[4,64],[32,14],[68,0,0,0,0,0,0,72,64],[160],[33,14],[5],[32,14],[68,0,0,0,0,0,192,85,64],[160],[33,14],[11],[32,5],[32,5],[68,0,0,0,0,0,0,240,63],[160],[33,5],[252,2],[32,14],[252,2],[58,0,4],[12,1],[11],[11],[32,0],[32,0],[16, builtin('__Math_trunc')],[161],[34,19],[68,0,0,0,0,0,0,0,0],[100],[4,64],[32,5],[32,5],[68,0,0,0,0,0,0,240,63],[160],[33,5],[252,2],[65,46],[58,0,4],[32,19],[68,0,0,0,0,0,0,240,63],[160],[33,19],[68,0,0,0,0,0,0,48,64],[32,11],[161],[33,21],[68,0,0,0,0,0,0,0,0],[33,22],[3,64],[32,22],[32,21],[99],[4,64],[32,19],[32,2],[162],[33,19],[32,22],[68,0,0,0,0,0,0,240,63],[160],[33,22],[12,1],[11],[11],[32,19],[16, builtin('__Math_round')],[33,19],[68,0,0,0,0,0,0,0,0],[33,11],[68,0,0,0,0,0,0,240,63],[33,12],[3,64],[32,19],[68,0,0,0,0,0,0,240,63],[100],[4,64],[32,19],[32,2],[16, builtin('f64_%')],[33,14],[32,19],[32,2],[163],[16, builtin('__Math_trunc')],[33,19],[32,12],[252,3],[4,64],[32,14],[68,0,0,0,0,0,0,0,0],[97],[4,64],[12,3],[11],[68,0,0,0,0,0,0,0,0],[33,12],[11],[32,10],[32,11],[160],[252,2],[32,14],[252,2],[58,0,4],[32,11],[68,0,0,0,0,0,0,240,63],[160],[33,11],[12,1],[11],[11],[32,10],[32,11],[160],[33,15],[32,5],[32,11],[160],[33,16],[3,64],[32,5],[32,16],[99],[4,64],[32,15],[68,0,0,0,0,0,0,240,63],[161],[34,15],[252,2],[45,0,4],[183],[34,14],[68,0,0,0,0,0,0,36,64],[99],[4,64],[32,14],[68,0,0,0,0,0,0,72,64],[160],[33,14],[5],[32,14],[68,0,0,0,0,0,192,85,64],[160],[33,14],[11],[32,5],[32,5],[68,0,0,0,0,0,0,240,63],[160],[33,5],[252,2],[32,14],[252,2],[58,0,4],[12,1],[11],[11],[11],[32,4],[252,3],[32,5],[32,4],[161],[34,18],[252,3],[54,1,0],[32,4],[65,18],[15]],
1381
1588
  params: [124,127,124,127],
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "porffor",
3
3
  "description": "a basic experimental wip aot optimizing js -> wasm engine/compiler/runtime in js",
4
- "version": "0.14.0-b5a80d8e3",
4
+ "version": "0.14.0-bb0b06c17",
5
5
  "author": "CanadaHonk",
6
6
  "license": "MIT",
7
7
  "scripts": {