compute block added

This commit is contained in:
Jordi Baylina
2019-08-29 16:26:19 +02:00
parent 597deb1eaa
commit f05c4e1338
7 changed files with 229 additions and 168 deletions

View File

@@ -131,6 +131,8 @@ function exec(ctx, ast) {
return execFunctionCall(ctx, ast);
} else if (ast.type == "BLOCK") {
return execBlock(ctx, ast);
} else if (ast.type == "COMPUTE") {
return ;
} else if (ast.type == "FOR") {
return execFor(ctx, ast);
} else if (ast.type == "WHILE") {

View File

@@ -116,6 +116,8 @@ function gen(ctx, ast) {
return genFunctionCall(ctx, ast);
} else if (ast.type == "BLOCK") {
return genBlock(ctx, ast);
} else if (ast.type == "COMPUTE") {
return genCompute(ctx, ast);
} else if (ast.type == "FOR") {
return genFor(ctx, ast);
} else if (ast.type == "WHILE") {
@@ -256,6 +258,12 @@ function genWhile(ctx, ast) {
return `while (bigInt(${condition}).neq(bigInt(0))) {\n${body}\n}\n`;
}
function genCompute(ctx, ast) {
const body = gen(ctx, ast.body);
if (ctx.error) return;
return `{\n${body}\n}\n`;
}
function genIf(ctx, ast) {
const condition = gen(ctx, ast.condition);
if (ctx.error) return;