porffor 0.17.0-30b9c5fa5 → 0.17.0-41e9c641a

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.
@@ -1590,7 +1590,7 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
1590
1590
  if (!name && decl.callee.type === 'MemberExpression') {
1591
1591
  // megahack for /regex/.func()
1592
1592
  const funcName = decl.callee.property.name;
1593
- if (decl.callee.object.regex && Object.hasOwn(Rhemyn, funcName)) {
1593
+ if (decl.callee.object.regex && ['test'].includes(funcName)) {
1594
1594
  const regex = decl.callee.object.regex.pattern;
1595
1595
  const rhemynName = `regex_${funcName}_${regex}`;
1596
1596
 
@@ -1613,7 +1613,7 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
1613
1613
  [ Opcodes.call, idx ],
1614
1614
  Opcodes.i32_from_u,
1615
1615
 
1616
- ...setLastType(scope, TYPES.boolean)
1616
+ ...setLastType(scope, Rhemyn.types[funcName])
1617
1617
  ];
1618
1618
  }
1619
1619
 
@@ -1622,24 +1622,35 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
1622
1622
  target = decl.callee.object;
1623
1623
  }
1624
1624
 
1625
- // if (protoName && baseType === TYPES.string && Rhemyn[protoName]) {
1626
- // const func = Rhemyn[protoName](decl.arguments[0].regex.pattern, currentFuncIndex++);
1625
+ if (protoName) {
1626
+ if (['search'].includes(protoName)) {
1627
+ const regex = decl.arguments[0].regex.pattern;
1628
+ const rhemynName = `regex_${protoName}_${regex}`;
1629
+
1630
+ if (!funcIndex[rhemynName]) {
1631
+ const func = Rhemyn[protoName](regex, currentFuncIndex++, rhemynName);
1632
+ func.internal = true;
1633
+
1634
+ funcIndex[func.name] = func.index;
1635
+ funcs.push(func);
1636
+ }
1627
1637
 
1628
- // funcIndex[func.name] = func.index;
1629
- // funcs.push(func);
1638
+ const idx = funcIndex[rhemynName];
1639
+ return [
1640
+ // make string arg
1641
+ ...generate(scope, target),
1642
+ Opcodes.i32_to_u,
1643
+ ...getNodeType(scope, target),
1630
1644
 
1631
- // return [
1632
- // generate(scope, decl.callee.object)
1645
+ // call regex func
1646
+ [ Opcodes.call, idx ],
1647
+ Opcodes.i32_from_u,
1633
1648
 
1634
- // // call regex func
1635
- // [ Opcodes.call, func.index ],
1636
- // Opcodes.i32_from_u
1637
- // ];
1638
- // }
1649
+ ...setLastType(scope, Rhemyn.types[protoName])
1650
+ ];
1651
+ }
1639
1652
 
1640
- if (protoName) {
1641
1653
  const protoBC = {};
1642
-
1643
1654
  const builtinProtoCands = Object.keys(builtinFuncs).filter(x => x.startsWith('__') && x.endsWith('_prototype_' + protoName));
1644
1655
 
1645
1656
  if (!decl._protoInternalCall && builtinProtoCands.length > 0) {
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.17.0-30b9c5fa5",
4
+ "version": "0.17.0-41e9c641a",
5
5
  "author": "CanadaHonk",
6
6
  "license": "MIT",
7
7
  "scripts": {},
package/rhemyn/compile.js CHANGED
@@ -267,21 +267,26 @@ const wrapFunc = (regex, func, name, index) => {
267
267
  // bytestring
268
268
  ...generate(parsed, false, true, 1, func),
269
269
  [ Opcodes.end ]
270
- ], name, index);
270
+ ], name, index, types[func]);
271
271
  };
272
272
 
273
273
  export const test = (regex, index = 0, name = 'regex_test_' + regex) => wrapFunc(regex, 'test', name, index);
274
274
  export const search = (regex, index = 0, name = 'regex_search_' + regex) => wrapFunc(regex, 'search', name, index);
275
275
 
276
- const outputFunc = (wasm, name, index) => ({
276
+ export const types = {
277
+ test: TYPES.boolean,
278
+ search: TYPES.number
279
+ };
280
+
281
+ const outputFunc = (wasm, name, index, returnType) => ({
277
282
  name,
278
283
  index,
279
284
  wasm,
285
+ returnType,
280
286
 
281
287
  export: true,
282
288
  params: [ Valtype.i32, Valtype.i32 ],
283
289
  returns: [ Valtype.i32 ],
284
- returnType: TYPES.boolean,
285
290
  locals: {
286
291
  basePointer: { idx: 0, type: Valtype.i32 },
287
292
  inputType: { idx: 1, type: Valtype.i32 },