diff options
author | Kyle Gunger <kgunger@gmail.com> | 2022-02-14 12:40:19 -0500 |
---|---|---|
committer | Kyle Gunger <kgunger@gmail.com> | 2022-02-14 12:40:19 -0500 |
commit | ede2462cfb2c7f8bb17dc835f9d4a34d06545ecd (patch) | |
tree | 48280b719adf2a53bc1ffa3973a0923101e0a8e9 /src/texec | |
parent | ff03145aacbf937308f20e32c9835ea2a049e518 (diff) |
[EXEC] Operator eval stub
Diffstat (limited to 'src/texec')
-rw-r--r-- | src/texec/eval.go | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/texec/eval.go b/src/texec/eval.go index 542fcf4..880e7b6 100644 --- a/src/texec/eval.go +++ b/src/texec/eval.go @@ -484,18 +484,52 @@ func resolveArtifact(a TArtifact, ctx *VarMap) *TVariable { // Value statement parsing +func evalDotChain(v tparse.Node, ctx *VarMap) TVariable { + return null +} + +// Try to convert a value into a specific type +func convValue(val TVariable, t TType) TVariable { + return null +} + // Parse a value node func evalValue(v tparse.Node, ctx *VarMap) TVariable { switch v.Data.Data { case "=": + dtyp := (*(*ctx)[v.Sub[0].Data.Data]).Type + dval := evalValue(v.Sub[1], ctx) + (*ctx)[v.Sub[0].Data.Data].Data = (convValue(dval, dtyp)).Data case "+": + a := evalValue(v.Sub[0], ctx) + b := evalValue(v.Sub[1], ctx) + return TVariable{tInt, a.Data.(int) + b.Data.(int)} case "-": + a := evalValue(v.Sub[0], ctx) + b := evalValue(v.Sub[1], ctx) + return TVariable{tInt, a.Data.(int) - b.Data.(int)} case "*": + a := evalValue(v.Sub[0], ctx) + b := evalValue(v.Sub[1], ctx) + return TVariable{tInt, a.Data.(int) * b.Data.(int)} case "/": + a := evalValue(v.Sub[0], ctx) + b := evalValue(v.Sub[1], ctx) + return TVariable{tInt, a.Data.(int) / b.Data.(int)} case "&&": + a := evalValue(v.Sub[0], ctx) + b := evalValue(v.Sub[1], ctx) + return TVariable{tBool, a.Data.(bool) && b.Data.(bool)} case "||": + a := evalValue(v.Sub[0], ctx) + b := evalValue(v.Sub[1], ctx) + return TVariable{tInt, a.Data.(bool) || b.Data.(bool)} case "==": + a := evalValue(v.Sub[0], ctx) + b := evalValue(v.Sub[1], ctx) + return TVariable{tBool, a.Data.(int) == b.Data.(int)} case ".": + return evalDotChain(v, ctx) } return null } |