porffor 0.57.12 → 0.57.13

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.
@@ -206,6 +206,10 @@ const generate = (scope, decl, global = false, name = undefined, valueUnused = f
206
206
  case 'ArrowFunctionExpression':
207
207
  case 'FunctionDeclaration':
208
208
  case 'FunctionExpression':
209
+ // ignore body-less function definitions, likely ts overload signatures
210
+ if (!decl.body) {
211
+ return cacheAst(decl, [ number(UNDEFINED) ]);
212
+ }
209
213
  return cacheAst(decl, generateFunc(scope, decl)[1]);
210
214
 
211
215
  case 'BlockStatement':
@@ -1934,10 +1938,10 @@ const typeIsIterable = wasm => [
1934
1938
  ...typeIsOneOf(wasm, [ TYPES.array, TYPES.set, TYPES.map, TYPES.string, TYPES.bytestring, TYPES.__porffor_generator ]),
1935
1939
  // typed array
1936
1940
  ...wasm,
1937
- number(TYPES.uint8array, Valtype.i32),
1941
+ number(TYPES.uint8clampedarray, Valtype.i32),
1938
1942
  [ Opcodes.i32_ge_s ],
1939
1943
  ...wasm,
1940
- number(TYPES.biguint64array, Valtype.i32),
1944
+ number(TYPES.float64array, Valtype.i32),
1941
1945
  [ Opcodes.i32_le_s ],
1942
1946
  [ Opcodes.i32_and ],
1943
1947
  [ Opcodes.i32_or ],
@@ -6388,7 +6392,7 @@ const generateTaggedTemplate = (scope, decl, global = false, name = undefined, v
6388
6392
  continue;
6389
6393
  }
6390
6394
 
6391
- let inst = Opcodes[asm[0].replace('.', '_')];
6395
+ let inst = Opcodes[asm[0].replaceAll('.', '_')];
6392
6396
  if (inst == null) throw new Error(`inline asm: inst ${asm[0]} not found`);
6393
6397
  if (!Array.isArray(inst)) inst = [ inst ];
6394
6398
 
@@ -37,9 +37,7 @@ export default (wasm, name = '', ind = 0, locals = {}, params = [], returns = []
37
37
  if (inst[0] === 0xfd) { // simd inst prefix
38
38
  if (inst[1] >= 128) inst = [ [ inst[0], inst[1], inst[2] ], ...inst.slice(3) ];
39
39
  else inst = [ [ inst[0], inst[1] ], ...inst.slice(2) ];
40
- }
41
-
42
- if (inst[0] === 0xfc) { // misc inst prefix
40
+ } else if (inst[0] > 0xf0) { // other multi-byte insts
43
41
  inst = [ [ inst[0], inst[1] ], ...inst.slice(2) ];
44
42
  }
45
43
 
package/compiler/types.js CHANGED
@@ -56,7 +56,7 @@ registerInternalType('ArrayBuffer');
56
56
  registerInternalType('SharedArrayBuffer');
57
57
  registerInternalType('DataView');
58
58
 
59
- for (const x of [ 'Uint8', 'Int8', 'Uint8Clamped', 'Uint16', 'Int16', 'Uint32', 'Int32', 'Float32', 'Float64', 'BigInt64', 'BigUint64' ])
59
+ for (const x of [ 'Uint8Clamped', 'Uint8', 'Int8', 'Uint16', 'Int16', 'Uint32', 'Int32', 'BigUint64', 'BigInt64', 'Float32', 'Float64' ])
60
60
  registerInternalType(`${x}Array`, ['iterable', 'length']);
61
61
 
62
62
  registerInternalType('WeakRef');
@@ -252,5 +252,55 @@ export const Opcodes = {
252
252
 
253
253
  v128_or: [ 0xfd, 80 ],
254
254
  v128_xor: [ 0xfd, 81 ],
255
- v128_any_true: [ 0xfd, 83 ]
255
+ v128_any_true: [ 0xfd, 83 ],
256
+
257
+ // Atomic memory operations
258
+ memory_atomic_notify: [ 0xfe, 0x00 ],
259
+ memory_atomic_wait32: [ 0xfe, 0x01 ],
260
+ memory_atomic_wait64: [ 0xfe, 0x02 ],
261
+ atomic_fence: [ 0xfe, 0x03, 0x00 ],
262
+
263
+ i32_atomic_load: [ 0xfe, 0x10 ],
264
+ i64_atomic_load: [ 0xfe, 0x11 ],
265
+ i32_atomic_load8: [ 0xfe, 0x12 ],
266
+ i32_atomic_load16: [ 0xfe, 0x13 ],
267
+ i32_atomic_store: [ 0xfe, 0x17 ],
268
+ i64_atomic_store: [ 0xfe, 0x18 ],
269
+ i32_atomic_store8: [ 0xfe, 0x19 ],
270
+ i32_atomic_store16: [ 0xfe, 0x1a ],
271
+
272
+ i32_atomic_rmw_add: [ 0xfe, 0x1e ],
273
+ i64_atomic_rmw_add: [ 0xfe, 0x1f ],
274
+ i32_atomic_rmw_add8: [ 0xfe, 0x20 ],
275
+ i32_atomic_rmw_add16: [ 0xfe, 0x21 ],
276
+
277
+ i32_atomic_rmw_sub: [ 0xfe, 0x25 ],
278
+ i64_atomic_rmw_sub: [ 0xfe, 0x26 ],
279
+ i32_atomic_rmw_sub8: [ 0xfe, 0x27 ],
280
+ i32_atomic_rmw_sub16: [ 0xfe, 0x28 ],
281
+
282
+ i32_atomic_rmw_and: [ 0xfe, 0x2c ],
283
+ i64_atomic_rmw_and: [ 0xfe, 0x2d ],
284
+ i32_atomic_rmw_and8: [ 0xfe, 0x2e ],
285
+ i32_atomic_rmw_and16: [ 0xfe, 0x2f ],
286
+
287
+ i32_atomic_rmw_or: [ 0xfe, 0x33 ],
288
+ i64_atomic_rmw_or: [ 0xfe, 0x34 ],
289
+ i32_atomic_rmw_or8: [ 0xfe, 0x35 ],
290
+ i32_atomic_rmw_or16: [ 0xfe, 0x36 ],
291
+
292
+ i32_atomic_rmw_xor: [ 0xfe, 0x3a ],
293
+ i64_atomic_rmw_xor: [ 0xfe, 0x3b ],
294
+ i32_atomic_rmw_xor8: [ 0xfe, 0x3c ],
295
+ i32_atomic_rmw_xor16: [ 0xfe, 0x3d ],
296
+
297
+ i32_atomic_rmw_xchg: [ 0xfe, 0x41 ],
298
+ i64_atomic_rmw_xchg: [ 0xfe, 0x42 ],
299
+ i32_atomic_rmw_xchg8: [ 0xfe, 0x43 ],
300
+ i32_atomic_rmw_xchg16: [ 0xfe, 0x44 ],
301
+
302
+ i32_atomic_rmw_cmpxchg: [ 0xfe, 0x48 ],
303
+ i64_atomic_rmw_cmpxchg: [ 0xfe, 0x49 ],
304
+ i32_atomic_rmw_cmpxchg8: [ 0xfe, 0x4a ],
305
+ i32_atomic_rmw_cmpxchg16: [ 0xfe, 0x4b ]
256
306
  };
package/foo.js ADDED
@@ -0,0 +1,10 @@
1
+ const wow = x => {
2
+ switch (x) {
3
+ case 1:
4
+ return true;
5
+ }
6
+
7
+ return false;
8
+ };
9
+
10
+ console.log(wow(1337));
package/foo.ts CHANGED
@@ -1,5 +1,12 @@
1
- namespace wasm {
2
- export declare function imported_wasm_func(a: number): void;
1
+ // namespace wasm {
2
+ // export declare function imported_wasm_func(a: number): void;
3
+ // }
4
+
5
+ // wasm.imported_wasm_func(1337);
6
+
7
+ class Vector {
8
+ foo(x: number): number
3
9
  }
4
10
 
5
- wasm.imported_wasm_func(1337);
11
+ const foo = new Vector()
12
+ console.log(foo.foo(""))
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "porffor",
3
3
  "description": "An ahead-of-time JavaScript compiler",
4
- "version": "0.57.12",
4
+ "version": "0.57.13",
5
5
  "author": "Oliver Medhurst <honk@goose.icu>",
6
6
  "license": "MIT",
7
7
  "scripts": {},
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.57.12';
3
+ globalThis.version = '0.57.13';
4
4
 
5
5
  // deno compat
6
6
  if (typeof process === 'undefined' && typeof Deno !== 'undefined') {