@hypermode/functions-as
Advanced tools
Comparing version 0.9.2 to 0.9.3
{ | ||
"name": "@hypermode/functions-as", | ||
"version": "0.9.2", | ||
"version": "0.9.3", | ||
"description": "Hypermode library for AssemblyScript functions", | ||
@@ -21,10 +21,10 @@ "author": "Hypermode, Inc.", | ||
"@hypermode/models-as": "^0.2.1", | ||
"json-as": "^0.9.8", | ||
"json-as": "^0.9.12", | ||
"xid-ts": "^1.1.0" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^20.14.9", | ||
"@typescript-eslint/eslint-plugin": "^7.14.1", | ||
"@typescript-eslint/parser": "^7.14.1", | ||
"assemblyscript": "^0.27.28", | ||
"@types/node": "^20.14.10", | ||
"@typescript-eslint/eslint-plugin": "^7.16.0", | ||
"@typescript-eslint/parser": "^7.16.0", | ||
"assemblyscript": "^0.27.29", | ||
"assemblyscript-prettier": "^3.0.1", | ||
@@ -34,3 +34,3 @@ "eslint": "^8.57.0", | ||
"semver": "^7.6.2", | ||
"typescript": "^5.5.2", | ||
"typescript": "^5.5.3", | ||
"visitor-as": "^0.11.4" | ||
@@ -37,0 +37,0 @@ }, |
import binaryen from "assemblyscript/lib/binaryen.js"; | ||
import { FunctionSignature, TypeDefinition, typeMap, } from "./types.js"; | ||
import { MultiParamGen } from "./multiparam.js"; | ||
export class Extractor { | ||
@@ -7,2 +8,3 @@ binaryen; | ||
program; | ||
transform; | ||
constructor(transform, module) { | ||
@@ -29,3 +31,4 @@ this.program = transform.program; | ||
.concat(hostFunctions) | ||
.flatMap((f) => f.parameters.map((p) => p.type.path).concat(f.returnType.path))); | ||
.flatMap((f) => f.parameters.map((p) => p.type.path).concat(f.returnType.path)) | ||
.map((p) => p.replace(/\|null$/, ""))); | ||
const typesUsed = new Map(); | ||
@@ -122,6 +125,18 @@ allTypes.forEach((t) => { | ||
const d = f.declaration; | ||
return new FunctionSignature(e.name, f.signature.parameterTypes.map((t, i) => ({ | ||
name: d.signature.parameters[i].name.text, | ||
type: getTypeInfo(t), | ||
})), getTypeInfo(f.signature.returnType)); | ||
const params = []; | ||
for (let i = 0; i < f.signature.parameterTypes.length; i++) { | ||
const _type = f.signature.parameterTypes[i]; | ||
const name = d.signature.parameters[i].name.text; | ||
if (name == "__SUPPLIED_PARAMS") | ||
continue; | ||
const type = getTypeInfo(_type); | ||
const optional = MultiParamGen.SN.opt_fns.get(e.name).find((e) => e.param.name == name) | ||
?.param.optional || false; | ||
params.push({ | ||
name, | ||
type, | ||
optional, | ||
}); | ||
} | ||
return new FunctionSignature(e.name, params, getTypeInfo(f.signature.returnType)); | ||
} | ||
@@ -128,0 +143,0 @@ } |
@@ -5,3 +5,26 @@ import { Transform } from "assemblyscript/dist/transform.js"; | ||
import { Extractor } from "./extractor.js"; | ||
import { Source } from "assemblyscript/dist/assemblyscript.js"; | ||
import { MultiParamGen } from "./multiparam.js"; | ||
export default class HypermodeTransform extends Transform { | ||
afterParse(parser) { | ||
const mpgen = MultiParamGen.init(); | ||
const sources = parser.sources | ||
.filter((source) => !isStdlib(source)) | ||
.sort((_a, _b) => { | ||
const a = _a.internalPath; | ||
const b = _b.internalPath; | ||
if (a[0] === "~" && b[0] !== "~") { | ||
return -1; | ||
} | ||
else if (a[0] !== "~" && b[0] === "~") { | ||
return 1; | ||
} | ||
else { | ||
return 0; | ||
} | ||
}); | ||
for (const source of sources) { | ||
mpgen.visitSource(source); | ||
} | ||
} | ||
afterCompile(module) { | ||
@@ -23,2 +46,7 @@ const extractor = new Extractor(this, module); | ||
} | ||
const isStdlibRegex = /~lib\/(?:array|arraybuffer|atomics|builtins|crypto|console|compat|dataview|date|diagnostics|error|function|iterator|map|math|number|object|process|reference|regexp|set|staticarray|string|symbol|table|typedarray|vector|rt\/?|bindings\/|shared\/typeinfo)|util\/|uri|polyfills|memory/; | ||
function isStdlib(s) { | ||
const source = s instanceof Source ? s : s.range.source; | ||
return isStdlibRegex.test(source.internalPath); | ||
} | ||
//# sourceMappingURL=index.js.map |
@@ -0,1 +1,2 @@ | ||
import { MultiParamGen } from "./multiparam.js"; | ||
export class ProgramInfo { | ||
@@ -15,6 +16,17 @@ functions; | ||
toString() { | ||
const params = this.parameters | ||
.map((p) => `${p.name}: ${p.type.name}`) | ||
.join(", "); | ||
return `${this.name}(${params}): ${this.returnType.name}`; | ||
const optionalParams = MultiParamGen.SN?.opt_fns.get(this.name); | ||
let params = ""; | ||
for (let i = 0; i < this.parameters.length; i++) { | ||
const param = this.parameters[i]; | ||
const { defaultValue } = optionalParams[i] || { | ||
defaultValue: null, | ||
}; | ||
if (param.name.startsWith("_")) | ||
continue; | ||
params += `${param.name}: ${param.type.name}`; | ||
if (param.optional) | ||
params += ` = ${defaultValue}`; | ||
params += ", "; | ||
} | ||
return `${this.name}(${params.endsWith(", ") ? params.slice(0, params.length - 2) : params}): ${this.returnType.name}`; | ||
} | ||
@@ -21,0 +33,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
63240
23
1877
Updatedjson-as@^0.9.12