porffor 0.60.2 → 0.60.4

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.
@@ -4292,8 +4292,6 @@ const generateUnary = (scope, decl) => {
4292
4292
  if (object.type === 'Super') return internalThrow(scope, 'ReferenceError', 'Cannot delete super property', true);
4293
4293
 
4294
4294
  const property = getProperty(decl.argument);
4295
- if (property.value === 'length' || property.value === 'name') scope.noFastFuncMembers = true;
4296
-
4297
4295
  const coctc = coctcOffset(decl.argument);
4298
4296
  const objectTmp = coctc > 0 && localTmp(scope, '#coctc_object', Valtype.i32);
4299
4297
 
@@ -5808,19 +5806,7 @@ const generateMember = (scope, decl, _global, _name) => {
5808
5806
  let final = [], finalEnd, extraBC = {};
5809
5807
  let name = decl.object.name;
5810
5808
 
5811
- // todo: handle globalThis.foo
5812
-
5813
- // hack: .name
5814
- if (decl.property.name === 'name' && hasFuncWithName(name) && !scope.noFastFuncMembers) {
5815
- // function name can mismatch variable/access name
5816
- name = funcByName(name)?.name ?? name;
5817
-
5818
- // eg: __String_prototype_toLowerCase -> toLowerCase
5819
- if (name.startsWith('__')) name = name.split('_').pop();
5820
- if (name.startsWith('#')) name = '';
5821
-
5822
- return withType(scope, makeString(scope, name, true), TYPES.bytestring);
5823
- }
5809
+ // todo: handle globalThis.foo efficiently
5824
5810
 
5825
5811
  const object = decl.object;
5826
5812
  const property = getProperty(decl);
@@ -5837,16 +5823,6 @@ const generateMember = (scope, decl, _global, _name) => {
5837
5823
  // hack: .length
5838
5824
  if (decl.property.name === 'length') {
5839
5825
  // todo: support optional
5840
-
5841
- if (!scope.noFastFuncMembers) {
5842
- const func = funcByName(name);
5843
- if (func) return withType(scope, [ number(countLength(func, name)) ], TYPES.number);
5844
-
5845
- if (Object.hasOwn(builtinFuncs, name)) return withType(scope, [ number(countLength(builtinFuncs[name], name)) ], TYPES.number);
5846
- if (Object.hasOwn(importedFuncs, name)) return withType(scope, [ number(importedFuncs[name].params.length) ], TYPES.number);
5847
- if (Object.hasOwn(internalConstrs, name)) return withType(scope, [ number(internalConstrs[name].length ?? 0) ], TYPES.number);
5848
- }
5849
-
5850
5826
  const out = [
5851
5827
  ...generate(scope, object),
5852
5828
  Opcodes.i32_to_u
@@ -6257,7 +6233,8 @@ const generateAwait = (scope, decl) => {
6257
6233
  const generateClass = (scope, decl) => {
6258
6234
  const expr = decl.type === 'ClassExpression';
6259
6235
 
6260
- const name = decl.id ? decl.id.name : `#anonymous${uniqId()}`;
6236
+ if (!decl.id) decl.id = { type: 'Identifier', name: `#anonymous${uniqId()}` };
6237
+ const name = decl.id.name;
6261
6238
  if (!expr) hoist(scope, name, 2, true);
6262
6239
 
6263
6240
  const body = decl.body.body;
@@ -6732,7 +6709,8 @@ const builtinFuncByName = name => {
6732
6709
  const generateFunc = (scope, decl, forceNoExpr = false) => {
6733
6710
  doNotMarkFuncRef = false;
6734
6711
 
6735
- const name = decl.id ? decl.id.name : `#anonymous${uniqId()}`;
6712
+ if (!decl.id) decl.id = { type: 'Identifier', name: `#anonymous${uniqId()}` };
6713
+ const name = decl.id.name;
6736
6714
  if (decl.type.startsWith('Class')) {
6737
6715
  const out = generateClass(scope, {
6738
6716
  ...decl,
package/compiler/index.js CHANGED
@@ -200,7 +200,7 @@ export default (code, module = Prefs.module) => {
200
200
  const out = { funcs, globals, tags, exceptions, pages, data, times: [ t0, t1, t2, t3 ] };
201
201
  if (globalThis.precompile) return out;
202
202
 
203
- const wasm = out.wasm = assemble(funcs, globals, tags, pages, data);
203
+ let wasm = out.wasm = assemble(funcs, globals, tags, pages, data);
204
204
  if (logProgress) progressDone('assembled', t3);
205
205
 
206
206
  if (Prefs.optFuncs || Prefs.f) logFuncs(funcs, globals, exceptions);
@@ -212,6 +212,48 @@ export default (code, module = Prefs.module) => {
212
212
  console.log([...pages.keys()].map(x => `\x1B[36m - ${x}\x1B[0m`).join('\n') + '\n');
213
213
  }
214
214
 
215
+ if (Prefs.emscripten) {
216
+ const tmpFile = 'porffor_tmp.wasm';
217
+ const cO = Prefs._cO ?? 'Oz';
218
+
219
+ const args = [
220
+ 'emcc',
221
+ '-xc', '-', // use stdin as c source in
222
+ '-s', 'STANDALONE_WASM=1',
223
+ '-s', 'NO_FILESYSTEM=1',
224
+ '-s', 'EXPORTED_FUNCTIONS=\'["_m"]\'',
225
+ '-nostartfiles',
226
+ '-Wl,--no-entry',
227
+ '-o', tmpFile,
228
+ '-' + cO,
229
+ Prefs.d ? '-g' : ''
230
+ ];
231
+
232
+ if (Prefs.clangFast) args.push('-flto=thin', '-march=native', '-ffast-math', '-fno-asynchronous-unwind-tables');
233
+
234
+ if (Prefs.s) args.push('-s');
235
+
236
+ Prefs['2cWasmImports'] = true;
237
+ const c = toc(out)
238
+ .replace(`int main()`, `
239
+ void __wasi_proc_exit(int code) {
240
+ __builtin_trap();
241
+ }
242
+
243
+ int m()`);
244
+ Prefs['2cWasmImports'] = false;
245
+
246
+ // obvious command escape is obvious
247
+ execSync(args.join(' '), {
248
+ stdio: [ 'pipe', 'inherit', 'inherit' ],
249
+ input: c,
250
+ encoding: 'utf8'
251
+ });
252
+
253
+ out.wasm = wasm = fs.readFileSync(tmpFile, null);
254
+ fs.unlinkSync(tmpFile);
255
+ }
256
+
215
257
  if (target === 'wasm' && outFile) {
216
258
  fs.writeFileSync(outFile, Buffer.from(wasm));
217
259
 
package/foo.js ADDED
@@ -0,0 +1,9 @@
1
+ const func = () => {
2
+ let before = 0;
3
+
4
+ TypeError('wow');
5
+
6
+ let after = 1;
7
+ };
8
+
9
+ func();
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.60.2",
4
+ "version": "0.60.4",
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.60.2';
3
+ globalThis.version = '0.60.4';
4
4
 
5
5
  // deno compat
6
6
  if (typeof process === 'undefined' && typeof Deno !== 'undefined') {