porffor 0.60.2 → 0.60.3

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/AGENT.md ADDED
@@ -0,0 +1,20 @@
1
+ you are an assistant coder for Porffor - an early javascript and typescript to webassembly and native ahead-of-time compiler. the codebase is written in js and ts.
2
+
3
+ - built-ins apis (Date, String.prototype, etc) are written in ts inside `compiler/builtins`
4
+ - once you update a file inside that directory, you MUST run `./porf precompile` to compile to make your changes effective
5
+ - test your work using the test262 tools available, iterate independently but do not get stuck on one chain of thought or approach. paths for test262 tools should be relative to the 'test262/test' directory (e.g., 'built-ins/RegExp' NOT 'test262/test/built-ins/RegExp').
6
+ - to get an overview of the most failing directories, use the command: `node test262/fails.cjs`
7
+ - to just evaluate code in the engine, use the command: `./porf -p "..."`
8
+ - after finishing, check if your work/diff could be simplified
9
+ - always use single quotes (unless double is required)
10
+ - 2-space indentation, LF line endings, no trailing whitespace
11
+ - built-in APIs in `compiler/builtins/` written in TypeScript
12
+ - inline code in built-ins, avoid helper functions
13
+ - use semicolons
14
+ - do not use trailing commas
15
+ - use const/let, avoid var
16
+ - follow existing naming: camelCase for variables, PascalCase for types
17
+ - when possible, do not concat strings and instead write to them directly using wasm memory
18
+ - there are no closures, you cannot use locals between functions. use arguments or globals if really necessary
19
+ - The user prefers that prototype functions not have explicit return types in this codebase.
20
+ - The user prefers not to use global variables in built-in functions.
package/compiler/2c.js CHANGED
@@ -612,6 +612,21 @@ export default ({ funcs, globals, data, pages }) => {
612
612
  let func = funcs.find(x => x.index === i[1]);
613
613
  if (!func) {
614
614
  const importFunc = importFuncs[i[1]];
615
+ if (Prefs['2cWasmImports']) {
616
+ const name = '__porf_import_' + importFunc.name;
617
+ if (!prepend.has(name)) {
618
+ prepend.set(name, `
619
+ __attribute__((import_module(""), import_name("${importFunc.import}")))
620
+ extern ${importFunc.returns.length > 0 ? CValtype[importFunc.returns[0]] : 'void'} ${name}(${importFunc.params.map(x => CValtype[x]).join(', ')});`);
621
+ }
622
+
623
+ const call = `${name}(${importFunc.params.length > 0 ? vals.pop() : ''})`;
624
+ if (importFunc.returns.length > 0) vals.push(call);
625
+ else line(call);
626
+
627
+ break;
628
+ }
629
+
615
630
  switch (importFunc.name) {
616
631
  case 'print':
617
632
  line(`printf("${valtype === 'f64' ? '%.15g' : '%i'}", ${vals.pop()})`);
@@ -807,6 +822,8 @@ export default ({ funcs, globals, data, pages }) => {
807
822
  // todo: allow catching
808
823
  const type = vals.pop();
809
824
  const val = vals.pop();
825
+ if (Prefs['2cWasmImports']) break;
826
+
810
827
  line(`printf("Uncaught ")`);
811
828
 
812
829
  // const id = tmpId++;
@@ -326,7 +326,7 @@ export const __JSON_parse = (_: bytestring) => {
326
326
  }
327
327
 
328
328
  while (true) {
329
- arr.push(parseValue());
329
+ Porffor.array.fastPush(arr, parseValue());
330
330
  skipWhitespace();
331
331
  if (pos >= len) throw new SyntaxError('Unterminated array');
332
332