Browse Source

Array params in templates

feature/witness_bin
Jordi Baylina 5 years ago
parent
commit
5b45bafaac
No known key found for this signature in database GPG Key ID: 7480C80C1BE43112
4 changed files with 23 additions and 17 deletions
  1. +1
    -0
      cli.js
  2. +9
    -9
      package-lock.json
  3. +1
    -1
      package.json
  4. +12
    -7
      src/exec.js

+ 1
- 0
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 {

+ 9
- 9
package-lock.json

@ -1469,9 +1469,9 @@
} }
}, },
"snarkjs": { "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, "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",
"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, "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",
"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, "dev": true,
"requires": { "requires": {
"@babel/code-frame": "^7.0.0", "@babel/code-frame": "^7.0.0",

+ 1
- 1
package.json

@ -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"
} }
} }

+ 12
- 7
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.value);
paramValues.push(v);
} }
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]] = {
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; ctx.components[ctx.currentComponent].template = templateName;

Loading…
Cancel
Save