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