porffor 0.18.17 → 0.18.19

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.
@@ -111,15 +111,12 @@ export const BuiltinFuncs = function() {
111
111
  ${funcs.map(x => {
112
112
  const wasm = JSON.stringify(x.wasm.filter(x => x.length && x[0] != null)).replace(/\["alloc","(.*?)","(.*?)",(.*?)\]/g, (_, reason, type, valtype) => `...number(allocPage(scope, '${reason}', '${type}') * pageSize, ${valtype})`).replace(/\[16,"(.*?)"]/g, (_, name) => `[16, builtin('${name}')]`).replace(/\["throw","(.*?)","(.*?)"\]/g, (_, constructor, message) => `...internalThrow(scope, '${constructor}', \`${message}\`)`);
113
113
  return ` this.${x.name} = {
114
- wasm: (scope, {${wasm.includes('allocPage(') ? 'allocPage,' : ''}${wasm.includes('builtin(') ? 'builtin,' : ''}${wasm.includes('internalThrow(') ? 'internalThrow,' : ''}}) => ${wasm},
115
- params: ${JSON.stringify(x.params)},
116
- typedParams: true,
117
- returns: ${JSON.stringify(x.returns)},
118
- ${x.returnType != null ? `returnType: ${JSON.stringify(x.returnType)}` : 'typedReturns: true'},
119
- locals: ${JSON.stringify(Object.values(x.locals).slice(x.params.length).map(x => x.type))},
120
- localNames: ${JSON.stringify(Object.keys(x.locals))},
121
- ${x.data && x.data.length > 0 ? ` data: ${JSON.stringify(x.data)},` : ''}
122
- ${x.table ? ` table: true,` : ''}${x.constr ? ` constr: true,` : ''}${x.hasRestArgument ? ` hasRestArgument: true,` : ''}
114
+ wasm: (scope, {${`${wasm.includes('allocPage(') ? 'allocPage,' : ''}${wasm.includes('builtin(') ? 'builtin,' : ''}${wasm.includes('internalThrow(') ? 'internalThrow,' : ''}`.slice(0, -1)}}) => ${wasm},
115
+ params: ${JSON.stringify(x.params)}, typedParams: 1,
116
+ returns: ${JSON.stringify(x.returns)}, ${x.returnType != null ? `returnType: ${JSON.stringify(x.returnType)}` : 'typedReturns: 1'},
117
+ locals: ${JSON.stringify(Object.values(x.locals).slice(x.params.length).map(x => x.type))}, localNames: ${JSON.stringify(Object.keys(x.locals))},
118
+ ${x.data && x.data.length > 0 ? ` data: [${x.data.map(x => `[${x.offset ?? 'null'},[${x.bytes.join(',')}]]`).join(',')}],` : ''}
119
+ ${x.table ? ` table: 1,` : ''}${x.constr ? ` constr: 1,` : ''}${x.hasRestArgument ? ` hasRestArgument: 1,` : ''}
123
120
  };`.replaceAll('\n\n', '\n').replaceAll('\n\n', '\n').replaceAll('\n\n', '\n');
124
121
  }).join('\n')}
125
122
  };`;
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.18.17+4d4df7afe",
4
+ "version": "0.18.19+cf63905b0",
5
5
  "author": "CanadaHonk",
6
6
  "license": "MIT",
7
7
  "scripts": {},
package/runner/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import fs from 'node:fs';
3
- globalThis.version = '0.18.17+4d4df7afe';
3
+ globalThis.version = '0.18.19+cf63905b0';
4
4
 
5
5
  // deno compat
6
6
  if (typeof process === 'undefined' && typeof Deno !== 'undefined') {
@@ -1,147 +0,0 @@
1
- import type {} from './porffor.d.ts';
2
-
3
- // radix: number|any for rawType check
4
- // export const parseInt = (input: string|bytestring, radix: number|any): f64 => {
5
- export const parseInt = (input: string|bytestring, radix: number): f64 => {
6
- // todo/perf: optimize this instead of doing a naive algo (https://kholdstare.github.io/technical/2020/05/26/faster-integer-parsing.html)
7
- // todo/perf: use i32s here once that becomes not annoying
8
-
9
- if (Porffor.rawType(radix) != Porffor.TYPES.number) {
10
- // todo: string to number
11
- radix = 10;
12
- }
13
-
14
- if (radix == 0) radix = 10;
15
- if (radix < 2 || radix > 36) return NaN;
16
-
17
- let nMax: f64 = 58;
18
- if (radix < 10) nMax = 48 + radix;
19
-
20
- // if (Porffor.rawType(input) == Porffor.TYPES.bytestring) input = __ByteString_prototype_trimStart(input);
21
- // else input = __String_prototype_trimStart(input);
22
-
23
- let n: f64 = NaN;
24
-
25
- const inputPtr: f64 = Porffor.wasm`local.get ${input}`;
26
- const len: f64 = Porffor.wasm.i32.load(inputPtr, 0, 0);
27
- let i: f64 = inputPtr;
28
-
29
- let negative: boolean = false;
30
-
31
- if (Porffor.rawType(input) == Porffor.TYPES.bytestring) {
32
- const endPtr: f64 = i + len;
33
-
34
- // check start of string
35
- const startChr: f64 = Porffor.wasm.i32.load8_u(i, 0, 4);
36
-
37
- // +, ignore
38
- if (startChr == 43) i++;
39
-
40
- // -, switch to negative
41
- if (startChr == 45) {
42
- negative = true;
43
- i++;
44
- }
45
-
46
- // 0, potential start of hex
47
- if (startChr == 48) {
48
- const second: f64 = Porffor.wasm.i32.load8_u(i + 1, 0, 4);
49
- // 0x or 0X
50
- if (second == 120 || second == 88) {
51
- // set radix to 16 and skip leading 2 chars
52
- i += 2;
53
- radix = 16;
54
- }
55
- }
56
-
57
- while (i < endPtr) {
58
- const chr: f64 = Porffor.wasm.i32.load8_u(i++, 0, 4);
59
-
60
- if (chr >= 48 && chr < nMax) {
61
- if (Number.isNaN(n)) n = 0;
62
-
63
- n *= radix;
64
- n += chr - 48;
65
- } else if (radix > 10) {
66
- if (chr >= 97 && chr < (87 + radix)) {
67
- if (Number.isNaN(n)) n = 0;
68
-
69
- n *= radix;
70
- n += chr - 87;
71
- } else if (chr >= 65 && chr < (55 + radix)) {
72
- if (Number.isNaN(n)) n = 0;
73
-
74
- n *= radix;
75
- n += chr - 55;
76
- } else {
77
- if (negative) return -n;
78
- return n;
79
- }
80
- } else {
81
- if (negative) return -n;
82
- return n;
83
- }
84
- }
85
-
86
- if (negative) return -n;
87
- return n;
88
- }
89
-
90
- const endPtr: f64 = i + len * 2;
91
-
92
- // check start of string
93
- const startChr: f64 = Porffor.wasm.i32.load16_u(i, 0, 4);
94
-
95
- // +, ignore
96
- if (startChr == 43) i += 2;
97
-
98
- // -, switch to negative
99
- if (startChr == 45) {
100
- negative = true;
101
- i += 2;
102
- }
103
-
104
- // 0, potential start of hex
105
- if (startChr == 48) {
106
- const second: f64 = Porffor.wasm.i32.load16_u(i + 2, 0, 4);
107
- // 0x or 0X
108
- if (second == 120 || second == 88) {
109
- // set radix to 16 and skip leading 2 chars
110
- i += 4;
111
- radix = 16;
112
- }
113
- }
114
-
115
- while (i < endPtr) {
116
- const chr: f64 = Porffor.wasm.i32.load16_u(i, 0, 4);
117
- i += 2;
118
-
119
- if (chr >= 48 && chr < nMax) {
120
- if (Number.isNaN(n)) n = 0;
121
-
122
- n *= radix;
123
- n += chr - 48;
124
- } else if (radix > 10) {
125
- if (chr >= 97 && chr < (87 + radix)) {
126
- if (Number.isNaN(n)) n = 0;
127
-
128
- n *= radix;
129
- n += chr - 87;
130
- } else if (chr >= 65 && chr < (55 + radix)) {
131
- if (Number.isNaN(n)) n = 0;
132
-
133
- n *= radix;
134
- n += chr - 55;
135
- } else {
136
- if (negative) return -n;
137
- return n;
138
- }
139
- } else {
140
- if (negative) return -n;
141
- return n;
142
- }
143
- }
144
-
145
- if (negative) return -n;
146
- return n;
147
- };