Browse Source

Fix array assignement and not allow assign with equal

feature/witness_bin
Jordi Baylina 5 years ago
parent
commit
0be08d67b0
No known key found for this signature in database GPG Key ID: 7480C80C1BE43112
1 changed files with 10 additions and 8 deletions
  1. +10
    -8
      src/exec.js

+ 10
- 8
src/exec.js

@ -709,12 +709,14 @@ function execVarAssignement(ctx, ast) {
if (num.type == "COMPONENT") return execInstantiateComponet(ctx, v, ast.values[1]); if (num.type == "COMPONENT") return execInstantiateComponet(ctx, v, ast.values[1]);
if (ctx.error) return; if (ctx.error) return;
// if (num.type == "SIGNAL") return error(ctx, ast, "Cannot assign to a signal with `=` use <-- or <== ops");
if ((num.type == "SIGNAL")&&(ast.op == "=")) return error(ctx, ast, "Cannot assign to a signal with `=` use <-- or <== ops");
if ((["NUMBER", "COMPONENT"].indexOf(num.type) >= 0 )&&(ast.op != "=")) return error(ctx, ast, `Cannot assign to a var with ${ast.op}. use = op`);
const res = exec(ctx, ast.values[1]); const res = exec(ctx, ast.values[1]);
if (ctx.error) return; if (ctx.error) return;
setScope(ctx, v.name, v.selectors, res);
Object.assign(num, res);
// setScope(ctx, v.name, v.selectors, res);
return v; return v;
} }
@ -986,13 +988,13 @@ function execMul(ctx, ast) {
function execVarAddAssignement(ctx, ast) { function execVarAddAssignement(ctx, ast) {
const res = execAdd(ctx,{ values: [ast.values[0], ast.values[1]] } ); const res = execAdd(ctx,{ values: [ast.values[0], ast.values[1]] } );
if (ctx.error) return; if (ctx.error) return;
return execVarAssignement(ctx, { values: [ast.values[0], res] });
return execVarAssignement(ctx, { op:"=", values: [ast.values[0], res] });
} }
function execVarMulAssignement(ctx, ast) { function execVarMulAssignement(ctx, ast) {
const res = execMul(ctx,{ values: [ast.values[0], ast.values[1]] } ); const res = execMul(ctx,{ values: [ast.values[0], ast.values[1]] } );
if (ctx.error) return; if (ctx.error) return;
return execVarAssignement(ctx, { values: [ast.values[0], res] });
return execVarAssignement(ctx, { op:"=", values: [ast.values[0], res] });
} }
function execPlusPlusRight(ctx, ast) { function execPlusPlusRight(ctx, ast) {
@ -1000,7 +1002,7 @@ function execPlusPlusRight(ctx, ast) {
if (ctx.error) return; if (ctx.error) return;
const resAfter = execAdd(ctx,{ values: [ast.values[0], {type: "NUMBER", value: bigInt(1)}] } ); const resAfter = execAdd(ctx,{ values: [ast.values[0], {type: "NUMBER", value: bigInt(1)}] } );
if (ctx.error) return; if (ctx.error) return;
execVarAssignement(ctx, { values: [ast.values[0], resAfter] });
execVarAssignement(ctx, { op:"=", values: [ast.values[0], resAfter] });
return resBefore; return resBefore;
} }
@ -1008,7 +1010,7 @@ function execPlusPlusLeft(ctx, ast) {
if (ctx.error) return; if (ctx.error) return;
const resAfter = execAdd(ctx,{ values: [ast.values[0], {type: "NUMBER", value: bigInt(1)}] } ); const resAfter = execAdd(ctx,{ values: [ast.values[0], {type: "NUMBER", value: bigInt(1)}] } );
if (ctx.error) return; if (ctx.error) return;
execVarAssignement(ctx, { values: [ast.values[0], resAfter] });
execVarAssignement(ctx, { op:"=", values: [ast.values[0], resAfter] });
return resAfter; return resAfter;
} }
@ -1017,7 +1019,7 @@ function execMinusMinusRight(ctx, ast) {
if (ctx.error) return; if (ctx.error) return;
const resAfter = execSub(ctx,{ values: [ast.values[0], {type: "NUMBER", value: bigInt(1)}] } ); const resAfter = execSub(ctx,{ values: [ast.values[0], {type: "NUMBER", value: bigInt(1)}] } );
if (ctx.error) return; if (ctx.error) return;
execVarAssignement(ctx, { values: [ast.values[0], resAfter] });
execVarAssignement(ctx, { op:"=", values: [ast.values[0], resAfter] });
return resBefore; return resBefore;
} }
@ -1025,7 +1027,7 @@ function execMinusMinusLeft(ctx, ast) {
if (ctx.error) return; if (ctx.error) return;
const resAfter = execSub(ctx,{ values: [ast.values[0], {type: "NUMBER", value: bigInt(1)}] } ); const resAfter = execSub(ctx,{ values: [ast.values[0], {type: "NUMBER", value: bigInt(1)}] } );
if (ctx.error) return; if (ctx.error) return;
execVarAssignement(ctx, { values: [ast.values[0], resAfter] });
execVarAssignement(ctx, { op:"=", values: [ast.values[0], resAfter] });
return resAfter; return resAfter;
} }

Loading…
Cancel
Save