Browse Source

If without else

feature/witness_bin
Jordi Baylina 6 years ago
parent
commit
4fa0c79e26
No known key found for this signature in database GPG Key ID: 7480C80C1BE43112
3 changed files with 12 additions and 6 deletions
  1. +1
    -1
      src/compiler.js
  2. +4
    -2
      src/exec.js
  3. +7
    -3
      src/gencode.js

+ 1
- 1
src/compiler.js

@ -31,7 +31,7 @@ module.exports = compile;
const parser = require("../parser/jaz.js").parser;
const timeout = ms => new Promise(res => setTimeout(res, ms))
const timeout = ms => new Promise(res => setTimeout(res, ms));
async function compile(srcFile) {
const fullFileName = srcFile;

+ 4
- 2
src/exec.js

@ -578,8 +578,10 @@ function execIf(ctx, ast) {
exec(ctx, ast.then);
if (ctx.error) return;
} else {
exec(ctx, ast.else);
if (ctx.error) return;
if (ast.else) {
exec(ctx, ast.else);
if (ctx.error) return;
}
}
}

+ 7
- 3
src/gencode.js

@ -246,9 +246,13 @@ function genIf(ctx, ast) {
if (ctx.error) return;
const thenBody = gen(ctx, ast.then);
if (ctx.error) return;
const elseBody = gen(ctx, ast.else);
if (ctx.error) return;
return `if (${condition}) {\n${thenBody}\n} else {\n${elseBody}\n}\n`;
if (ast.else) {
const elseBody = gen(ctx, ast.else);
if (ctx.error) return;
return `if (${condition}) {\n${thenBody}\n} else {\n${elseBody}\n}\n`;
} else {
return `if (${condition}) {\n${thenBody}\n}\n`;
}
}

Loading…
Cancel
Save