From 0be08d67b0264ff59eef4c84baa95cda84670caf Mon Sep 17 00:00:00 2001 From: Jordi Baylina Date: Wed, 4 Dec 2019 17:40:48 +0100 Subject: [PATCH] Fix array assignement and not allow assign with equal --- src/exec.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/exec.js b/src/exec.js index 6578f6c..e9b47ac 100644 --- a/src/exec.js +++ b/src/exec.js @@ -709,12 +709,14 @@ function execVarAssignement(ctx, ast) { if (num.type == "COMPONENT") return execInstantiateComponet(ctx, v, ast.values[1]); 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]); if (ctx.error) return; - setScope(ctx, v.name, v.selectors, res); + Object.assign(num, res); +// setScope(ctx, v.name, v.selectors, res); return v; } @@ -986,13 +988,13 @@ function execMul(ctx, ast) { function execVarAddAssignement(ctx, ast) { const res = execAdd(ctx,{ values: [ast.values[0], ast.values[1]] } ); 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) { const res = execMul(ctx,{ values: [ast.values[0], ast.values[1]] } ); 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) { @@ -1000,7 +1002,7 @@ function execPlusPlusRight(ctx, ast) { if (ctx.error) return; const resAfter = execAdd(ctx,{ values: [ast.values[0], {type: "NUMBER", value: bigInt(1)}] } ); if (ctx.error) return; - execVarAssignement(ctx, { values: [ast.values[0], resAfter] }); + execVarAssignement(ctx, { op:"=", values: [ast.values[0], resAfter] }); return resBefore; } @@ -1008,7 +1010,7 @@ function execPlusPlusLeft(ctx, ast) { if (ctx.error) return; const resAfter = execAdd(ctx,{ values: [ast.values[0], {type: "NUMBER", value: bigInt(1)}] } ); if (ctx.error) return; - execVarAssignement(ctx, { values: [ast.values[0], resAfter] }); + execVarAssignement(ctx, { op:"=", values: [ast.values[0], resAfter] }); return resAfter; } @@ -1017,7 +1019,7 @@ function execMinusMinusRight(ctx, ast) { if (ctx.error) return; const resAfter = execSub(ctx,{ values: [ast.values[0], {type: "NUMBER", value: bigInt(1)}] } ); if (ctx.error) return; - execVarAssignement(ctx, { values: [ast.values[0], resAfter] }); + execVarAssignement(ctx, { op:"=", values: [ast.values[0], resAfter] }); return resBefore; } @@ -1025,7 +1027,7 @@ function execMinusMinusLeft(ctx, ast) { if (ctx.error) return; const resAfter = execSub(ctx,{ values: [ast.values[0], {type: "NUMBER", value: bigInt(1)}] } ); if (ctx.error) return; - execVarAssignement(ctx, { values: [ast.values[0], resAfter] }); + execVarAssignement(ctx, { op:"=", values: [ast.values[0], resAfter] }); return resAfter; }