mirror of
https://github.com/arnaucube/circom.git
synced 2026-02-06 18:56:40 +01:00
small patches
This commit is contained in:
24
src/exec.js
24
src/exec.js
@@ -78,6 +78,10 @@ function exec(ctx, ast) {
|
||||
return execPlusPlusRight(ctx, ast);
|
||||
} else if (ast.op == "PLUSPLUSLEFT") {
|
||||
return execPlusPlusLeft(ctx, ast);
|
||||
} else if (ast.op == "MINUSMINUSRIGHT") {
|
||||
return execMinusMinusRight(ctx, ast);
|
||||
} else if (ast.op == "MINUSMINUSLEFT") {
|
||||
return execMinusMinusLeft(ctx, ast);
|
||||
} else if (ast.op == "/") {
|
||||
return execDiv(ctx, ast);
|
||||
} else if (ast.op == "\\") {
|
||||
@@ -368,6 +372,8 @@ function execInstantiateComponet(ctx, vr, fn) {
|
||||
|
||||
ctx.scopes = oldScopes.slice(0, scopeLevel+1);
|
||||
|
||||
if (template.params.length != paramValues.length) return error(ctx, fn, "Invalid number of parameters: " + templateName);
|
||||
|
||||
const scope = {};
|
||||
for (let i=0; i< template.params.length; i++) {
|
||||
scope[template.params[i]] = paramValues[i];
|
||||
@@ -623,6 +629,7 @@ function execVarAssignement(ctx, ast) {
|
||||
if ((typeof(num) != "object")||(num == null)) return error(ctx, ast, "Variable not defined");
|
||||
|
||||
if (num.type == "COMPONENT") return execInstantiateComponet(ctx, v, ast.values[1]);
|
||||
if (ctx.error) return;
|
||||
// if (num.type == "SIGNAL") return error(ctx, ast, "Cannot assign to a signal with `=` use <-- or <== ops");
|
||||
|
||||
const res = exec(ctx, ast.values[1]);
|
||||
@@ -926,6 +933,23 @@ function execPlusPlusLeft(ctx, ast) {
|
||||
return resAfter;
|
||||
}
|
||||
|
||||
function execMinusMinusRight(ctx, ast) {
|
||||
const resBefore = exec(ctx, ast.values[0]);
|
||||
if (ctx.error) return;
|
||||
const resAfter = execSub(ctx,{ values: [ast.values[0], {type: "NUMBER", value: bigInt(1)}] } );
|
||||
if (ctx.error) return;
|
||||
execVarAssignement(ctx, { values: [ast.values[0], resAfter] });
|
||||
return resBefore;
|
||||
}
|
||||
|
||||
function execMinusMinusLeft(ctx, ast) {
|
||||
if (ctx.error) return;
|
||||
const resAfter = execSub(ctx,{ values: [ast.values[0], {type: "NUMBER", value: bigInt(1)}] } );
|
||||
if (ctx.error) return;
|
||||
execVarAssignement(ctx, { values: [ast.values[0], resAfter] });
|
||||
return resAfter;
|
||||
}
|
||||
|
||||
function execTerCon(ctx, ast) {
|
||||
const cond = exec(ctx, ast.values[0]);
|
||||
if (ctx.error) return;
|
||||
|
||||
@@ -63,6 +63,10 @@ function gen(ctx, ast) {
|
||||
return genPlusPlusRight(ctx, ast);
|
||||
} else if (ast.op == "PLUSPLUSLEFT") {
|
||||
return genPlusPlusLeft(ctx, ast);
|
||||
} else if (ast.op == "MINUSMINUSRIGHT") {
|
||||
return genMinusMinusRight(ctx, ast);
|
||||
} else if (ast.op == "MINUSMINUSLEFT") {
|
||||
return genMinusMinusLeft(ctx, ast);
|
||||
} else if (ast.op == "**") {
|
||||
return genExp(ctx, ast);
|
||||
} else if (ast.op == "/") {
|
||||
@@ -231,6 +235,7 @@ function genFunctionDef(ctx, ast) {
|
||||
}
|
||||
|
||||
function genFor(ctx, ast) {
|
||||
ctx.scopes.push({});
|
||||
const init = gen(ctx, ast.init);
|
||||
if (ctx.error) return;
|
||||
const condition = gen(ctx, ast.condition);
|
||||
@@ -239,6 +244,7 @@ function genFor(ctx, ast) {
|
||||
if (ctx.error) return;
|
||||
const body = gen(ctx, ast.body);
|
||||
if (ctx.error) return;
|
||||
ctx.scopes.pop();
|
||||
return `for (${init};${condition};${step}) { \n${body}\n }\n`;
|
||||
}
|
||||
|
||||
@@ -431,6 +437,14 @@ function genPlusPlusLeft(ctx, ast) {
|
||||
return genVarAssignement(ctx, {values: [ast.values[0], {type: "OP", op: "+", values: [ast.values[0], {type: "NUMBER", value: bigInt(1)}]}]});
|
||||
}
|
||||
|
||||
function genMinusMinusRight(ctx, ast) {
|
||||
return `(${genVarAssignement(ctx, {values: [ast.values[0], {type: "OP", op: "-", values: [ast.values[0], {type: "NUMBER", value: bigInt(1)}]}]})}).add(__P__).sub(bigInt(1)).mod(__P__)`;
|
||||
}
|
||||
|
||||
function genMinusMinusLeft(ctx, ast) {
|
||||
return genVarAssignement(ctx, {values: [ast.values[0], {type: "OP", op: "-", values: [ast.values[0], {type: "NUMBER", value: bigInt(1)}]}]});
|
||||
}
|
||||
|
||||
function genAdd(ctx, ast) {
|
||||
const a = gen(ctx, ast.values[0]);
|
||||
if (ctx.error) return;
|
||||
|
||||
Reference in New Issue
Block a user