mirror of
https://github.com/arnaucube/circom.git
synced 2026-02-06 18:56:40 +01:00
Move basic circuits to circomlib
This commit is contained in:
@@ -158,7 +158,8 @@ function error(ctx, ast, errStr) {
|
||||
},
|
||||
errStr: errStr,
|
||||
errFile: ctx.fileName,
|
||||
ast: ast
|
||||
ast: ast,
|
||||
message: errStr
|
||||
};
|
||||
}
|
||||
|
||||
@@ -622,6 +623,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 (num.type == "SIGNAL") return error(ctx, ast, "Cannot assign to a signal with `=` use <-- or <== ops");
|
||||
|
||||
const res = exec(ctx, ast.values[1]);
|
||||
if (ctx.error) return;
|
||||
|
||||
70
src/genOptCode.js
Normal file
70
src/genOptCode.js
Normal file
@@ -0,0 +1,70 @@
|
||||
|
||||
|
||||
module.exports = genOpt;
|
||||
|
||||
|
||||
function genOpt(ctx, ast) {
|
||||
if (ast.type == "OP") {
|
||||
if (ast.op == "=") {
|
||||
return genOptVarAssignement(ctx, ast);
|
||||
} else {
|
||||
error(ctx, ast, "GENOPT -> Invalid operation: " + ast.op);
|
||||
}
|
||||
} else if (ast.type == "TEMPLATEDEF") {
|
||||
return genOptTemplateDef(ctx, ast);
|
||||
} else {
|
||||
error(ctx, ast, "GENOPT -> Invalid AST node type: " + ast.type);
|
||||
}
|
||||
}
|
||||
|
||||
function error(ctx, ast, errStr) {
|
||||
ctx.error = {
|
||||
pos: {
|
||||
first_line: ast.first_line,
|
||||
first_column: ast.first_column,
|
||||
last_line: ast.last_line,
|
||||
last_column: ast.last_column
|
||||
},
|
||||
errStr: errStr,
|
||||
errFile: ctx.fileName,
|
||||
ast: ast
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
function genOptTemplateDef(ctx, ast) {
|
||||
if (ctx.templates[ast.name]) {
|
||||
return error(ctx, ast, "Template name already exists: "+ast.name);
|
||||
}
|
||||
ctx.templates[ast.name] = {
|
||||
type: "TEMPLATE",
|
||||
params: ast.params,
|
||||
block: ast.block,
|
||||
fileName: ctx.fileName,
|
||||
filePath: ctx.filePath
|
||||
};
|
||||
}
|
||||
|
||||
function genOptVarAssignement(ctx, ast) {
|
||||
let varName;
|
||||
if (ast.values[0].type == "DECLARE") {
|
||||
varName = genOptCode(ctx, ast.values[0]);
|
||||
if (ctx.error) return;
|
||||
} else {
|
||||
varName = ast.values[0];
|
||||
}
|
||||
const varContent = getScope(ctx, varName.name, varName.selectors);
|
||||
if (ctx.error) return;
|
||||
|
||||
if ((typeof(varContent) != "object")||(varContent == null)) return error(ctx, ast, "Variable not defined");
|
||||
|
||||
if (varContent.type == "COMPONENT") return genOptInstantiateComponet(ctx, varName, ast.values[1]);
|
||||
if (varContent.type == "SIGNAL") return error(ctx, ast, "Cannot assig to a signal with `=` use <-- or <== ops");
|
||||
|
||||
const res = genOpt(ctx, ast.values[1]);
|
||||
if (ctx.error) return;
|
||||
|
||||
setScope(ctx, varName.name, varName.selectors, res);
|
||||
|
||||
return v;
|
||||
}
|
||||
@@ -143,7 +143,8 @@ function error(ctx, ast, errStr) {
|
||||
last_column: ast.last_column
|
||||
},
|
||||
errStr: errStr,
|
||||
ast: ast
|
||||
ast: ast,
|
||||
message: errStr
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user