mirror of
https://github.com/arnaucube/circom.git
synced 2026-02-06 18:56:40 +01:00
Array params in templates
This commit is contained in:
1
cli.js
1
cli.js
@@ -61,6 +61,7 @@ compiler(fullFileName).then( (cir) => {
|
||||
process.exit(0);
|
||||
}, (err) => {
|
||||
// console.log(err);
|
||||
console.log(err.stack);
|
||||
if (err.pos) {
|
||||
console.error(`ERROR at ${err.errFile}:${err.pos.first_line},${err.pos.first_column}-${err.pos.last_line},${err.pos.last_column} ${err.errStr}`);
|
||||
} else {
|
||||
|
||||
18
package-lock.json
generated
18
package-lock.json
generated
@@ -1469,9 +1469,9 @@
|
||||
}
|
||||
},
|
||||
"snarkjs": {
|
||||
"version": "0.1.3",
|
||||
"resolved": "https://registry.npmjs.org/snarkjs/-/snarkjs-0.1.3.tgz",
|
||||
"integrity": "sha512-z5HhuNt019ZzNzUztETK31rpjRRSz3Uzy8TjGgSROf+9ZT9i6dbdWkjTC3fh5o9H+R/2+hcR+7IKAmpIR56V+A==",
|
||||
"version": "0.1.5",
|
||||
"resolved": "https://registry.npmjs.org/snarkjs/-/snarkjs-0.1.5.tgz",
|
||||
"integrity": "sha512-4GiP60ONIitWRnC5+Gsl7nIO62fvkGN9Y9jsDWBKORZI34eNXJBrMjhCbT+0X57FS2XjY0MsR0/Qvg2cs1H0sQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"big-integer": "^1.6.35",
|
||||
@@ -1481,9 +1481,9 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"ajv": {
|
||||
"version": "6.5.4",
|
||||
"resolved": "https://registry.npmjs.org/ajv/-/ajv-6.5.4.tgz",
|
||||
"integrity": "sha512-4Wyjt8+t6YszqaXnLDfMmG/8AlO5Zbcsy3ATHncCzjW/NoPzAId8AK6749Ybjmdt+kUY1gP60fCu46oDxPv/mg==",
|
||||
"version": "6.5.5",
|
||||
"resolved": "https://registry.npmjs.org/ajv/-/ajv-6.5.5.tgz",
|
||||
"integrity": "sha512-7q7gtRQDJSyuEHjuVgHoUa2VuemFiCMrfQc9Tc08XTAc4Zj/5U1buQJ0HU6i7fKjXU09SVgSmxa4sLvuvS8Iyg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"fast-deep-equal": "^2.0.1",
|
||||
@@ -1514,9 +1514,9 @@
|
||||
}
|
||||
},
|
||||
"eslint": {
|
||||
"version": "5.7.0",
|
||||
"resolved": "https://registry.npmjs.org/eslint/-/eslint-5.7.0.tgz",
|
||||
"integrity": "sha512-zYCeFQahsxffGl87U2aJ7DPyH8CbWgxBC213Y8+TCanhUTf2gEvfq3EKpHmEcozTLyPmGe9LZdMAwC/CpJBM5A==",
|
||||
"version": "5.9.0",
|
||||
"resolved": "https://registry.npmjs.org/eslint/-/eslint-5.9.0.tgz",
|
||||
"integrity": "sha512-g4KWpPdqN0nth+goDNICNXGfJF7nNnepthp46CAlJoJtC5K/cLu3NgCM3AHu1CkJ5Hzt9V0Y0PBAO6Ay/gGb+w==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@babel/code-frame": "^7.0.0",
|
||||
|
||||
@@ -38,6 +38,6 @@
|
||||
"eslint": "^5.0.1",
|
||||
"eslint-plugin-mocha": "^5.0.0",
|
||||
"jison": "^0.4.18",
|
||||
"snarkjs": "0.1.5"
|
||||
"snarkjs": "0.1.6"
|
||||
}
|
||||
}
|
||||
|
||||
19
src/exec.js
19
src/exec.js
@@ -318,8 +318,7 @@ function execInstantiateComponet(ctx, vr, fn) {
|
||||
const v = exec(ctx, fn.params[i]);
|
||||
if (ctx.error) return;
|
||||
|
||||
if (v.type != "NUMBER") return error(ctx, fn.params[i], "expected a number");
|
||||
paramValues.push( v.value);
|
||||
paramValues.push(v);
|
||||
}
|
||||
if (template.params.length != paramValues.length) error(ctx, fn, "Invalid Number of parameters");
|
||||
|
||||
@@ -330,6 +329,15 @@ function execInstantiateComponet(ctx, vr, fn) {
|
||||
instantiateComponent(vv);
|
||||
|
||||
function instantiateComponent(varVal) {
|
||||
|
||||
function extractValue(v) {
|
||||
if (Array.isArray(v)) {
|
||||
return v.map(extractValue);
|
||||
} else {
|
||||
return v.value.toString();
|
||||
}
|
||||
}
|
||||
|
||||
if (Array.isArray(varVal)) {
|
||||
for (let i =0; i<varVal.length; i++) {
|
||||
instantiateComponent(varVal[i]);
|
||||
@@ -355,11 +363,8 @@ function execInstantiateComponet(ctx, vr, fn) {
|
||||
|
||||
const scope = {};
|
||||
for (let i=0; i< template.params.length; i++) {
|
||||
scope[template.params[i]] = {
|
||||
type: "NUMBER",
|
||||
value: paramValues[i]
|
||||
};
|
||||
ctx.components[ctx.currentComponent].params[template.params[i]] = paramValues[i];
|
||||
scope[template.params[i]] = paramValues[i];
|
||||
ctx.components[ctx.currentComponent].params[template.params[i]] = extractValue(paramValues[i]);
|
||||
}
|
||||
|
||||
ctx.components[ctx.currentComponent].template = templateName;
|
||||
|
||||
Reference in New Issue
Block a user