porffor 0.24.0 → 0.24.2

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.
@@ -3142,6 +3142,8 @@ const generateAssign = (scope, decl, _global, _name, valueUnused = false) => {
3142
3142
  ]
3143
3143
  }),
3144
3144
 
3145
+ [TYPES.undefined]: internalThrow(scope, 'TypeError', 'Cannot set property of undefined', true),
3146
+
3145
3147
  // default: internalThrow(scope, 'TypeError', `Cannot assign member with this type`)
3146
3148
  default: [
3147
3149
  ...objectWasm,
@@ -4376,7 +4378,7 @@ const makeArray = (scope, decl, global = false, name = '$undeclared', initEmpty
4376
4378
  return [ out, pointer ];
4377
4379
  }
4378
4380
  } else {
4379
- const rawPtr = read_signedLEB128(pointer[0].slice(1));
4381
+ const rawPtr = allocator.lastPtr;
4380
4382
 
4381
4383
  scope.arrays ??= new Map();
4382
4384
  const firstAssign = !scope.arrays.has(uniqueName);
@@ -4384,14 +4386,34 @@ const makeArray = (scope, decl, global = false, name = '$undeclared', initEmpty
4384
4386
 
4385
4387
  const local = global ? globals[name] : scope.locals?.[name];
4386
4388
  if (
4387
- Prefs.data && firstAssign && useRawElements &&
4389
+ Prefs.data && useRawElements &&
4388
4390
  name !== '#member_prop' && name !== '#member_prop_assign' &&
4389
4391
  (!globalThis.precompile || !global)
4390
4392
  ) {
4391
- makeData(scope, elements, rawPtr, itemType, initEmpty);
4393
+ if (Prefs.activeData && firstAssign) {
4394
+ makeData(scope, elements, rawPtr, itemType, initEmpty);
4395
+
4396
+ // local value as pointer
4397
+ return [ number(rawPtr, intOut ? Valtype.i32 : valtypeBinary), pointer ];
4398
+ }
4399
+
4400
+ if (Prefs.passiveData) {
4401
+ const data = makeData(scope, elements, null, itemType, initEmpty);
4402
+ if (data) {
4403
+ // init data
4404
+ out.push(
4405
+ ...pointer,
4406
+ ...number(0, Valtype.i32),
4407
+ ...number(data.size, Valtype.i32),
4408
+ [ ...Opcodes.memory_init, ...unsignedLEB128(data.idx), 0 ]
4409
+ );
4410
+ }
4411
+
4412
+ // return pointer in out
4413
+ out.push(...number(rawPtr, intOut ? Valtype.i32 : valtypeBinary));
4392
4414
 
4393
- // local value as pointer
4394
- return [ number(rawPtr, intOut ? Valtype.i32 : valtypeBinary), pointer ];
4415
+ return [ out, pointer ];
4416
+ }
4395
4417
  }
4396
4418
 
4397
4419
  if (local != null) {
@@ -4920,6 +4942,8 @@ const generateMember = (scope, decl, _global, _name) => {
4920
4942
  postlude: setLastType(scope, TYPES.number)
4921
4943
  }),
4922
4944
 
4945
+ [TYPES.undefined]: internalThrow(scope, 'TypeError', 'Cannot read property of undefined', true),
4946
+
4923
4947
  // default: internalThrow(scope, 'TypeError', 'Unsupported member expression object', true)
4924
4948
  default: [
4925
4949
  ...number(0),
package/compiler/index.js CHANGED
@@ -41,8 +41,12 @@ export default (code, flags) => {
41
41
  const pageSizeOpt = process.argv.find(x => x.startsWith('--page-size='));
42
42
  if (pageSizeOpt) pageSize = parseInt(pageSizeOpt.split('=')[1]) * 1024;
43
43
 
44
- // enable pgo by default for c/native
45
- if (target !== 'wasm') Prefs.pgo = Prefs.pgo === false ? false : true;
44
+ // change some prefs by default for c/native
45
+ if (target !== 'wasm') {
46
+ Prefs.pgo = Prefs.pgo === false ? false : true;
47
+ Prefs.passiveData = false;
48
+ }
49
+
46
50
  if (Prefs.pgo) pgo.setup();
47
51
 
48
52
  if (Prefs.profileCompiler) console.log(`0. began compilation (host runtime startup) in ${performance.now().toFixed(2)}ms`);
@@ -104,8 +108,11 @@ export default (code, flags) => {
104
108
 
105
109
  if (Prefs.profileCompiler) console.log(`3. optimized in ${(performance.now() - t2).toFixed(2)}ms`);
106
110
 
111
+ const out = { funcs, globals, tags, exceptions, pages, data };
112
+ if (globalThis.precompile) return out;
113
+
107
114
  const t3 = performance.now();
108
- const wasm = assemble(funcs, globals, tags, pages, data, flags);
115
+ const wasm = out.wasm = assemble(funcs, globals, tags, pages, data, flags);
109
116
  if (Prefs.profileCompiler) console.log(`4. assembled in ${(performance.now() - t3).toFixed(2)}ms`);
110
117
 
111
118
  if (Prefs.optFuncs) logFuncs(funcs, globals, exceptions);
@@ -117,8 +124,6 @@ export default (code, flags) => {
117
124
  console.log([...pages.keys()].map(x => `\x1B[36m - ${x}\x1B[0m`).join('\n') + '\n');
118
125
  }
119
126
 
120
- const out = { wasm, funcs, globals, tags, exceptions, pages, data };
121
-
122
127
  if (target === 'wasm' && outFile) {
123
128
  fs.writeFileSync(outFile, Buffer.from(wasm));
124
129
 
@@ -24,7 +24,7 @@ const compile = async (file, _funcs) => {
24
24
  first = source.slice(0, source.indexOf('\n'));
25
25
  }
26
26
 
27
- let args = ['--bytestring', '--todo-time=compile', '--truthy=no_nan_negative', '--no-treeshake-wasm-imports', '--no-rm-unused-types', '--scoped-page-names', '--funsafe-no-unlikely-proto-checks', '--fast-length', '--parse-types', '--opt-types'];
27
+ let args = ['--bytestring', '--todo-time=compile', '--truthy=no_nan_negative', '--no-rm-unused-types', '--scoped-page-names', '--funsafe-no-unlikely-proto-checks', '--fast-length', '--parse-types', '--opt-types', '--no-passive-data', '--active-data'];
28
28
  if (first.startsWith('// @porf')) {
29
29
  args = first.slice('// @porf '.length).split(' ').concat(args);
30
30
  }
package/compiler/prefs.js CHANGED
@@ -1,4 +1,4 @@
1
- const onByDefault = [ 'bytestring', 'treeshakeWasmImports', 'alwaysMemory', 'indirectCalls', 'optUnused', 'data', 'rmUnusedTypes' ];
1
+ const onByDefault = [ 'bytestring', 'treeshakeWasmImports', 'alwaysMemory', 'indirectCalls', 'optUnused', 'data', 'passiveData', 'rmUnusedTypes' ];
2
2
 
3
3
  let cache = {};
4
4
  const obj = new Proxy({}, {
package/compiler/wrap.js CHANGED
@@ -116,8 +116,12 @@ ${flags & 0b0001 ? ` get func idx: ${get}
116
116
 
117
117
  if (!func) return function () {};
118
118
 
119
+ let name = func.name;
120
+ // eg: __String_prototype_toLowerCase -> toLowerCase
121
+ if (name.startsWith('__')) name = name.split('_').pop();
122
+
119
123
  // make fake empty func for repl/etc
120
- return {[func.name]() {}}[func.name];
124
+ return {[name]() {}}[name];
121
125
  }
122
126
 
123
127
  case TYPES.string: {
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.24.0+1839fcc22",
4
+ "version": "0.24.2+c071f9a2f",
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.24.0+1839fcc22';
3
+ globalThis.version = '0.24.2+c071f9a2f';
4
4
 
5
5
  // deno compat
6
6
  if (typeof process === 'undefined' && typeof Deno !== 'undefined') {