mirror of
https://github.com/arnaucube/circom.git
synced 2026-02-06 18:56:40 +01:00
Tests added and Comparators
This commit is contained in:
16
src/exec.js
16
src/exec.js
@@ -98,6 +98,8 @@ function exec(ctx, ast) {
|
||||
return execGte(ctx, ast);
|
||||
} else if (ast.op == "==") {
|
||||
return execEq(ctx, ast);
|
||||
} else if (ast.op == "!=") {
|
||||
return execNeq(ctx, ast);
|
||||
} else if (ast.op == "?") {
|
||||
return execTerCon(ctx, ast);
|
||||
} else {
|
||||
@@ -680,6 +682,20 @@ function execEq(ctx, ast) {
|
||||
};
|
||||
}
|
||||
|
||||
function execNeq(ctx, ast) {
|
||||
const a = exec(ctx, ast.values[0]);
|
||||
if (ctx.error) return;
|
||||
if (a.type != "NUMBER") return { type: "NUMBER" };
|
||||
const b = exec(ctx, ast.values[1]);
|
||||
if (ctx.error) return;
|
||||
if (b.type != "NUMBER") return { type: "NUMBER" };
|
||||
if (!a.value || !b.value) return { type: "NUMBER" };
|
||||
return {
|
||||
type: "NUMBER",
|
||||
value: a.value.eq(b.value) ? bigInt(0) : bigInt(1)
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
function execBAnd(ctx, ast) {
|
||||
const a = exec(ctx, ast.values[0]);
|
||||
|
||||
@@ -83,6 +83,8 @@ function gen(ctx, ast) {
|
||||
return genGte(ctx, ast);
|
||||
} else if (ast.op == "==") {
|
||||
return genEq(ctx, ast);
|
||||
} else if (ast.op == "!=") {
|
||||
return genNeq(ctx, ast);
|
||||
} else if (ast.op == "?") {
|
||||
return genTerCon(ctx, ast);
|
||||
} else {
|
||||
@@ -314,7 +316,9 @@ function genVariable(ctx, ast) {
|
||||
if (ctx.error) return;
|
||||
}
|
||||
|
||||
|
||||
if (!v) {
|
||||
return error(ctx, ast, "Invalid left operand");
|
||||
}
|
||||
if (v.type == "VARIABLE") {
|
||||
return `ctx.getVar("${ast.name}",[${sels.join(",")}])`;
|
||||
} else if (v.type == "SIGNAL") {
|
||||
@@ -530,7 +534,15 @@ function genEq(ctx, ast) {
|
||||
if (ctx.error) return;
|
||||
const b = gen(ctx, ast.values[1]);
|
||||
if (ctx.error) return;
|
||||
return `bigInt(${a}).eq(bigInt(${b})) ? 1 : 0`;
|
||||
return `(bigInt(${a}).eq(bigInt(${b})) ? 1 : 0)`;
|
||||
}
|
||||
|
||||
function genNeq(ctx, ast) {
|
||||
const a = gen(ctx, ast.values[0]);
|
||||
if (ctx.error) return;
|
||||
const b = gen(ctx, ast.values[1]);
|
||||
if (ctx.error) return;
|
||||
return `(bigInt(${a}).eq(bigInt(${b})) ? 0 : 1)`;
|
||||
}
|
||||
|
||||
function genUMinus(ctx, ast) {
|
||||
|
||||
Reference in New Issue
Block a user