porffor 0.58.9 → 0.58.10

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/index.js CHANGED
@@ -61,8 +61,8 @@ const progressClear = () => {
61
61
  progressLines = 0;
62
62
  };
63
63
 
64
- export default (code, module = undefined) => {
65
- if (module !== undefined) Prefs.module = module;
64
+ export default (code, module = false) => {
65
+ Prefs.module = module;
66
66
 
67
67
  globalThis.valtype = Prefs.valtype ?? 'f64';
68
68
  globalThis.valtypeBinary = Valtype[valtype];
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "porffor",
3
3
  "description": "An ahead-of-time JavaScript compiler",
4
- "version": "0.58.9",
4
+ "version": "0.58.10",
5
5
  "author": "Oliver Medhurst <honk@goose.icu>",
6
6
  "license": "MIT",
7
7
  "scripts": {},
8
8
  "dependencies": {
9
- "acorn": "^8.14.1",
9
+ "acorn": "^8.15.0",
10
10
  "node-repl-polyfill": "github:CanadaHonk/node-repl-polyfill"
11
11
  },
12
12
  "optionalDependencies": {
package/runtime/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import fs from 'node:fs';
3
- globalThis.version = '0.58.9';
3
+ globalThis.version = '0.58.10';
4
4
 
5
5
  // deno compat
6
6
  if (typeof process === 'undefined' && typeof Deno !== 'undefined') {
@@ -1,353 +0,0 @@
1
- // @porf --valtype=i32
2
- import type {} from './porffor.d.ts';
3
-
4
- export const __Porffor_strcmp = (a: any, b: any): boolean => {
5
- // a and b must be string or bytestring
6
- // fast path: check if pointers are equal
7
- if (Porffor.wasm`local.get ${a}` == Porffor.wasm`local.get ${b}`) return true;
8
-
9
- let al: i32 = Porffor.wasm.i32.load(a, 0, 0);
10
- let bl: i32 = Porffor.wasm.i32.load(b, 0, 0);
11
-
12
- // fast path: check if lengths are inequal
13
- if (al != bl) return false;
14
-
15
- if (Porffor.wasm`local.get ${a+1}` == Porffor.TYPES.bytestring) {
16
- if (Porffor.wasm`local.get ${b+1}` == Porffor.TYPES.bytestring) {
17
- // bytestring, bytestring
18
- // this path is hyper-optimized as it is by far the most common and (perf) important
19
-
20
- let ap32: i32 = a - 28;
21
- let bp32: i32 = b - 28;
22
- let ap8: i32 = a - 4;
23
- let bp8: i32 = b - 4;
24
- Porffor.wasm`
25
- ;; load in 2 i64x2 chunks while length >= 32
26
- local.get ${al}
27
- i32.const 32
28
- i32.ge_s
29
- if 64
30
- loop 64
31
- local.get ${ap32}
32
- local.get ${al}
33
- i32.add
34
- v128.load 0 0
35
-
36
- local.get ${bp32}
37
- local.get ${al}
38
- i32.add
39
- v128.load 0 0
40
- v128.xor
41
-
42
- local.get ${ap32}
43
- local.get ${al}
44
- i32.add
45
- v128.load 0 16
46
-
47
- local.get ${bp32}
48
- local.get ${al}
49
- i32.add
50
- v128.load 0 16
51
- v128.xor
52
-
53
- v128.or
54
- v128.any_true
55
- if 64
56
- i32.const 0
57
- return
58
- end
59
-
60
- local.get ${al}
61
- i32.const 32
62
- i32.sub
63
- local.tee ${al}
64
- i32.const 32
65
- i32.ge_s
66
- br_if 0
67
- end
68
- end
69
-
70
- ;; load in i64 chunks while length >= 8
71
- local.get ${al}
72
- i32.const 8
73
- i32.ge_s
74
- if 64
75
- loop 64
76
- local.get ${ap8}
77
- local.get ${al}
78
- i32.add
79
- i64.load 0 0
80
-
81
- local.get ${bp8}
82
- local.get ${al}
83
- i32.add
84
- i64.load 0 0
85
-
86
- i64.ne
87
- if 64
88
- i32.const 0
89
- return
90
- end
91
-
92
- local.get ${al}
93
- i32.const 8
94
- i32.sub
95
- local.tee ${al}
96
- i32.const 8
97
- i32.ge_s
98
- br_if 0
99
- end
100
- end
101
-
102
- ;; load in u16 chunks while length >= 2
103
- local.get ${al}
104
- i32.const 2
105
- i32.ge_s
106
- if 64
107
- loop 64
108
- local.get ${a}
109
- local.get ${al}
110
- i32.add
111
- i32.load16_u 0 2
112
-
113
- local.get ${b}
114
- local.get ${al}
115
- i32.add
116
- i32.load16_u 0 2
117
-
118
- i32.ne
119
- if 64
120
- i32.const 0
121
- return
122
- end
123
-
124
- local.get ${al}
125
- i32.const 2
126
- i32.sub
127
- local.tee ${al}
128
- i32.const 2
129
- i32.ge_s
130
- br_if 0
131
- end
132
- end`;
133
-
134
- // check bonus char if exists
135
- if (al == 1) {
136
- if (Porffor.wasm.i32.load8_u(Porffor.wasm`local.get ${a}`, 0, 4) !=
137
- Porffor.wasm.i32.load8_u(Porffor.wasm`local.get ${b}`, 0, 4)) return false;
138
- }
139
- return true;
140
- } else {
141
- // bytestring, string
142
- for (let i: i32 = 0; i < al; i++) {
143
- if (Porffor.wasm.i32.load8_u(Porffor.wasm`local.get ${a}` + i, 0, 4) !=
144
- Porffor.wasm.i32.load16_u(Porffor.wasm`local.get ${b}` + i*2, 0, 4)) return false;
145
- }
146
- return true;
147
- }
148
- } else {
149
- if (Porffor.wasm`local.get ${b+1}` == Porffor.TYPES.bytestring) {
150
- // string, bytestring
151
- for (let i: i32 = 0; i < al; i++) {
152
- if (Porffor.wasm.i32.load16_u(Porffor.wasm`local.get ${a}` + i*2, 0, 4) !=
153
- Porffor.wasm.i32.load8_u(Porffor.wasm`local.get ${b}` + i, 0, 4)) return false;
154
- }
155
- return true;
156
- } else {
157
- // string, string
158
- // change char lengths to byte lengths
159
- al *= 2;
160
- bl *= 2;
161
-
162
- // copied from bytestring, bytestring
163
- let ap32: i32 = a - 28;
164
- let bp32: i32 = b - 28;
165
- let ap8: i32 = a - 4;
166
- let bp8: i32 = b - 4;
167
- Porffor.wasm`
168
- ;; load in 2 i64x2 chunks while length >= 32
169
- local.get ${al}
170
- i32.const 32
171
- i32.ge_s
172
- if 64
173
- loop 64
174
- local.get ${ap32}
175
- local.get ${al}
176
- i32.add
177
- v128.load 0 0
178
-
179
- local.get ${bp32}
180
- local.get ${al}
181
- i32.add
182
- v128.load 0 0
183
- v128.xor
184
-
185
- local.get ${ap32}
186
- local.get ${al}
187
- i32.add
188
- v128.load 0 16
189
-
190
- local.get ${bp32}
191
- local.get ${al}
192
- i32.add
193
- v128.load 0 16
194
- v128.xor
195
-
196
- v128.or
197
- v128.any_true
198
- if 64
199
- i32.const 0
200
- return
201
- end
202
-
203
- local.get ${al}
204
- i32.const 32
205
- i32.sub
206
- local.tee ${al}
207
- i32.const 32
208
- i32.ge_s
209
- br_if 0
210
- end
211
- end
212
-
213
- ;; load in i64 chunks while length >= 8
214
- local.get ${al}
215
- i32.const 8
216
- i32.ge_s
217
- if 64
218
- loop 64
219
- local.get ${ap8}
220
- local.get ${al}
221
- i32.add
222
- i64.load 0 0
223
-
224
- local.get ${bp8}
225
- local.get ${al}
226
- i32.add
227
- i64.load 0 0
228
-
229
- i64.ne
230
- if 64
231
- i32.const 0
232
- return
233
- end
234
-
235
- local.get ${al}
236
- i32.const 8
237
- i32.sub
238
- local.tee ${al}
239
- i32.const 8
240
- i32.ge_s
241
- br_if 0
242
- end
243
- end
244
-
245
- ;; load in u16 chunks while length >= 2
246
- local.get ${al}
247
- i32.const 2
248
- i32.ge_s
249
- if 64
250
- loop 64
251
- local.get ${a}
252
- local.get ${al}
253
- i32.add
254
- i32.load16_u 0 2
255
-
256
- local.get ${b}
257
- local.get ${al}
258
- i32.add
259
- i32.load16_u 0 2
260
-
261
- i32.ne
262
- if 64
263
- i32.const 0
264
- return
265
- end
266
-
267
- local.get ${al}
268
- i32.const 2
269
- i32.sub
270
- local.tee ${al}
271
- i32.const 2
272
- i32.ge_s
273
- br_if 0
274
- end
275
- end`;
276
- return true;
277
- }
278
- }
279
- };
280
-
281
- export const __Porffor_strcat = (a: any, b: any): any => {
282
- // a and b must be string or bytestring
283
-
284
- const al: i32 = Porffor.wasm.i32.load(a, 0, 0);
285
- const bl: i32 = Porffor.wasm.i32.load(b, 0, 0);
286
-
287
- if (Porffor.wasm`local.get ${a+1}` == Porffor.TYPES.bytestring) {
288
- if (Porffor.wasm`local.get ${b+1}` == Porffor.TYPES.bytestring) {
289
- // bytestring, bytestring
290
- const out: bytestring = Porffor.allocateBytes(4 + al + bl);
291
-
292
- // out.length = a.length + b.length
293
- Porffor.wasm.i32.store(out, al + bl, 0, 0);
294
-
295
- // copy left (fast memcpy)
296
- Porffor.wasm.memory.copy(Porffor.wasm`local.get ${out}` + 4, Porffor.wasm`local.get ${a}` + 4, al, 0, 0);
297
-
298
- // copy right (fast memcpy)
299
- Porffor.wasm.memory.copy(Porffor.wasm`local.get ${out}` + 4 + al, Porffor.wasm`local.get ${b}` + 4, bl, 0, 0);
300
-
301
- return out;
302
- } else {
303
- // bytestring, string
304
- const out: string = Porffor.allocateBytes(4 + (al + bl) * 2);
305
-
306
- // out.length = a.length + b.length
307
- Porffor.wasm.i32.store(out, al + bl, 0, 0);
308
-
309
- // copy left (slow bytestring -> string)
310
- for (let i: i32 = 0; i < al; i++) {
311
- Porffor.wasm.i32.store16(Porffor.wasm`local.get ${out}` + i*2, Porffor.wasm.i32.load8_u(Porffor.wasm`local.get ${a}` + i, 0, 4), 0, 4);
312
- }
313
-
314
- // copy right (fast memcpy)
315
- Porffor.wasm.memory.copy(Porffor.wasm`local.get ${out}` + 4 + al*2, Porffor.wasm`local.get ${b}` + 4, bl * 2, 0, 0);
316
-
317
- return out;
318
- }
319
- } else {
320
- if (Porffor.wasm`local.get ${b+1}` == Porffor.TYPES.bytestring) {
321
- // string, bytestring
322
- const out: string = Porffor.allocateBytes(4 + (al + bl) * 2);
323
-
324
- // out.length = a.length + b.length
325
- Porffor.wasm.i32.store(out, al + bl, 0, 0);
326
-
327
- // copy left (fast memcpy)
328
- Porffor.wasm.memory.copy(Porffor.wasm`local.get ${out}` + 4, Porffor.wasm`local.get ${a}` + 4, al * 2, 0, 0);
329
-
330
- // copy right (slow bytestring -> string)
331
- let ptr: i32 = Porffor.wasm`local.get ${out}` + al*2;
332
- for (let i: i32 = 0; i < bl; i++) {
333
- Porffor.wasm.i32.store16(ptr + i*2, Porffor.wasm.i32.load8_u(Porffor.wasm`local.get ${b}` + i, 0, 4), 0, 4);
334
- }
335
-
336
- return out;
337
- } else {
338
- // string, string
339
- const out: string = Porffor.allocateBytes(4 + (al + bl) * 2);
340
-
341
- // out.length = a.length + b.length
342
- Porffor.wasm.i32.store(out, al + bl, 0, 0);
343
-
344
- // copy left (fast memcpy)
345
- Porffor.wasm.memory.copy(Porffor.wasm`local.get ${out}` + 4, Porffor.wasm`local.get ${a}` + 4, al * 2, 0, 0);
346
-
347
- // copy right (fast memcpy)
348
- Porffor.wasm.memory.copy(Porffor.wasm`local.get ${out}` + 4 + al*2, Porffor.wasm`local.get ${b}` + 4, bl * 2, 0, 0);
349
-
350
- return out;
351
- }
352
- }
353
- };
@@ -1,45 +0,0 @@
1
- import type {} from './porffor.d.ts';
2
-
3
- export const __Porffor_compareStrings = (a: any, b: any): boolean => {
4
- if ((Porffor.type(a) | 0b10000000) != Porffor.TYPES.bytestring) {
5
- // a is not string or bytestring
6
- // check if it is bad type or value
7
- if (Porffor.fastOr(
8
- a == null,
9
-
10
- Porffor.type(a) == Porffor.TYPES.symbol,
11
- Porffor.type(a) == Porffor.TYPES.boolean
12
- )) return false;
13
-
14
- a = ecma262.ToString(a);
15
- }
16
-
17
- if ((Porffor.type(b) | 0b10000000) != Porffor.TYPES.bytestring) {
18
- // b is not string or bytestring
19
- // check if it is bad type or value
20
- if (Porffor.fastOr(
21
- b == null,
22
-
23
- Porffor.type(b) == Porffor.TYPES.symbol,
24
- Porffor.type(b) == Porffor.TYPES.boolean
25
- )) return false;
26
-
27
- b = ecma262.ToString(b);
28
- }
29
-
30
- return Porffor.strcmp(a, b);
31
- };
32
-
33
- export const __Porffor_concatStrings = (a: any, b: any): any => {
34
- if ((Porffor.type(a) | 0b10000000) != Porffor.TYPES.bytestring) {
35
- // a is not string or bytestring
36
- a = ecma262.ToString(a);
37
- }
38
-
39
- if ((Porffor.type(b) | 0b10000000) != Porffor.TYPES.bytestring) {
40
- // b is not string or bytestring
41
- b = ecma262.ToString(b);
42
- }
43
-
44
- return Porffor.strcat(a, b);
45
- };