const fs = require("fs"); const path = require("path"); const bigInt = require("big-integer"); const __P__ = new bigInt("21888242871839275222246405745257275088548364400416034343698204186575808495617"); const __MASK__ = new bigInt(2).pow(253).minus(1); const assert = require("assert"); const gen = require("./gencode"); const exec = require("./exec"); const lc = require("./lcalgebra"); const argv = require("optimist") .alias("c", "circuit") .alias("o", "output") .alias("w", "witnes") .argv; const parser = require("../jaz.js").parser; const fullFileName = path.resolve(process.cwd(), argv.circuit); const fullFilePath = path.dirname(fullFileName); const src = fs.readFileSync(fullFileName, "utf8"); const ast = parser.parse(src); assert(ast.type == "BLOCK"); const ctx = { scopes: [{}], signals: { one: { fullName: "one", value: bigInt(1), equivalence: "", direction: "" } }, currentComponent: "", constrains: [], components: {}, templates: {}, functions: {}, functionParams: {}, filePath: fullFilePath, fileName: fullFileName }; exec(ctx, ast); reduceConstrains(ctx); generateWitnessNames(ctx); generateWitnessConstrains(ctx); if (ctx.error) { console.log(`ERROR at ${ctx.error.errFile}:${ctx.error.pos.first_line},${ctx.error.pos.first_column}-${ctx.error.pos.last_line},${ctx.error.pos.last_column} ${ctx.error.errStr}`); console.log(JSON.stringify(ctx.error.ast, null, 1)); process.exit(1); } /* console.log("SIGNALS"); console.log("=========="); for (let key in ctx.signals) { const signal = ctx.signals[key]; console.log(signal.fullName); } console.log("CONSTRAINS"); console.log("=========="); for (let i=0; i