Compare commits

...

4 Commits

Author SHA1 Message Date
Jordi Baylina
859c98d2a4 0.0.28 2019-06-03 07:23:55 +02:00
Jordi Baylina
8048a5ef7d Fix and and or 2019-06-03 07:23:25 +02:00
Jordi Baylina
b7a41cda14 0.0.27 2019-05-11 20:55:54 +02:00
Jordi Baylina
34049f2fbd Conditions to boolean in old versions of node 2019-05-11 20:55:05 +02:00
4 changed files with 14 additions and 8 deletions

2
package-lock.json generated
View File

@@ -1,6 +1,6 @@
{ {
"name": "circom", "name": "circom",
"version": "0.0.26", "version": "0.0.28",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

View File

@@ -1,6 +1,6 @@
{ {
"name": "circom", "name": "circom",
"version": "0.0.26", "version": "0.0.28",
"description": "Language to generate logic circuits", "description": "Language to generate logic circuits",
"main": "index.js", "main": "index.js",
"directories": { "directories": {

View File

@@ -397,6 +397,12 @@ function execInstantiateComponet(ctx, vr, fn) {
function execFunctionCall(ctx, ast) { function execFunctionCall(ctx, ast) {
if (ast.name == "log") {
const v = exec(ctx, ast.params[0]);
console.log(v.value.toString());
return;
}
const scopeLevel = getScopeLevel(ctx, ast.name); const scopeLevel = getScopeLevel(ctx, ast.name);
if (scopeLevel == -1) return error(ctx, ast, "Function not defined: " + ast.name); if (scopeLevel == -1) return error(ctx, ast, "Function not defined: " + ast.name);
const fnc = getScope(ctx, ast.name); const fnc = getScope(ctx, ast.name);
@@ -750,7 +756,7 @@ function execAnd(ctx, ast) {
if (!a.value || !b.value) return { type: "NUMBER" }; if (!a.value || !b.value) return { type: "NUMBER" };
return { return {
type: "NUMBER", type: "NUMBER",
value: (a.value.neq(0) && a.value.neq(0)) ? bigInt(1) : bigInt(0) value: (a.value.neq(0) && b.value.neq(0)) ? bigInt(1) : bigInt(0)
}; };
} }
@@ -764,7 +770,7 @@ function execOr(ctx, ast) {
if (!a.value || !b.value) return { type: "NUMBER" }; if (!a.value || !b.value) return { type: "NUMBER" };
return { return {
type: "NUMBER", type: "NUMBER",
value: (a.value.neq(0) || a.value.neq(0)) ? bigInt(1) : bigInt(0) value: (a.value.neq(0) || b.value.neq(0)) ? bigInt(1) : bigInt(0)
}; };
} }

View File

@@ -245,7 +245,7 @@ function genFor(ctx, ast) {
const body = gen(ctx, ast.body); const body = gen(ctx, ast.body);
if (ctx.error) return; if (ctx.error) return;
ctx.scopes.pop(); ctx.scopes.pop();
return `for (${init};${condition};${step}) { \n${body}\n }\n`; return `for (${init};bigInt(${condition}).neq(bigInt(0));${step}) { \n${body}\n }\n`;
} }
function genWhile(ctx, ast) { function genWhile(ctx, ast) {
@@ -253,7 +253,7 @@ function genWhile(ctx, ast) {
if (ctx.error) return; if (ctx.error) return;
const body = gen(ctx, ast.body); const body = gen(ctx, ast.body);
if (ctx.error) return; if (ctx.error) return;
return `while (${condition}) {\n${body}\n}\n`; return `while (bigInt(${condition}).neq(bigInt(0))) {\n${body}\n}\n`;
} }
function genIf(ctx, ast) { function genIf(ctx, ast) {
@@ -264,9 +264,9 @@ function genIf(ctx, ast) {
if (ast.else) { if (ast.else) {
const elseBody = gen(ctx, ast.else); const elseBody = gen(ctx, ast.else);
if (ctx.error) return; if (ctx.error) return;
return `if (${condition}) {\n${thenBody}\n} else {\n${elseBody}\n}\n`; return `if (bigInt(${condition}).neq(bigInt(0))) {\n${thenBody}\n} else {\n${elseBody}\n}\n`;
} else { } else {
return `if (${condition}) {\n${thenBody}\n}\n`; return `if (bigInt(${condition}).neq(bigInt(0))) {\n${thenBody}\n}\n`;
} }
} }