Skip to content

Commit

Permalink
eval module add support for ntSize
Browse files Browse the repository at this point in the history
Signed-off-by: George Lemon <[email protected]>
  • Loading branch information
georgelemon committed Aug 8, 2023
1 parent 3d9b64f commit b0bd9d6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
27 changes: 24 additions & 3 deletions src/bropkg/engine/eval.nim
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,21 @@ proc evalMathInfix*(c: Compiler, lht, rht: Node, infixOp: MathOp, scope: ScopeTa
# of mMod: calcFloat(modulo)
else: nil

template ofMath(): untyped {.dirty.} =
template ofMath: untyped {.dirty.} =
var rht = evalMathInfix(c, rht.mathLeft, rht.mathRight, rht.mathInfixOp, scope)
evalInfix(c, lht, rht, infixOp, scope)

template ofMathLeft(): untyped {.dirty.} =
template ofMathLeft: untyped {.dirty.} =
var lht = evalMathInfix(c, lht.mathLeft, lht.mathRight, lht.mathInfixOp, scope)
evalInfix(c, lht, rht, infixOp, scope)

template ofCallStack(): untyped {.dirty.} =
template ofCallStack: untyped {.dirty.} =
var rht = handleCallStack(c, rht, scope)
evalInfix(c, lht, rht, infixOp, scope)

template ofSize: untyped {.dirty.} =
evalinfix(c, lht.sizeVal, rht.sizeVal, infixOp, scope)

proc evalInfix(c: Compiler; lht, rht: Node; infixOp: InfixOp; scope: ScopeTable): bool =
return case infixOp
of EQ:
Expand Down Expand Up @@ -182,6 +185,7 @@ proc evalInfix(c: Compiler; lht, rht: Node; infixOp: InfixOp; scope: ScopeTable)
evalInfix(c, lht, call(rht, scope), infixOp, scope)
of ntCallStack: ofCallStack
of ntMathStmt: ofMath
of ntSize: ofSize
else:
false
of ntCallStack:
Expand All @@ -193,9 +197,11 @@ proc evalInfix(c: Compiler; lht, rht: Node; infixOp: InfixOp; scope: ScopeTable)
evalInfix(c, lht, call(rht, scope), infixOp, scope)
of ntCallStack: ofCallStack
of ntMathStmt: ofMath
of ntSize: ofSize
else:
false
of ntMathStmt: ofMathLeft
of ntSize: ofSize
else:
false
of NE:
Expand Down Expand Up @@ -261,6 +267,7 @@ proc evalInfix(c: Compiler; lht, rht: Node; infixOp: InfixOp; scope: ScopeTable)
evalInfix(c, lht, call(rht, scope), infixOp, scope)
of ntCallStack: ofCallStack
of ntMathStmt: ofMath
of ntSize: ofSize
else:
false
of ntCallStack:
Expand All @@ -272,9 +279,11 @@ proc evalInfix(c: Compiler; lht, rht: Node; infixOp: InfixOp; scope: ScopeTable)
evalInfix(c, lht, call(rht, scope), infixOp, scope)
of ntCallStack: ofCallStack
of ntMathStmt: ofMath
of ntSize: ofSize
else:
false
of ntMathStmt: ofMathLeft
of ntSize: ofSize
else:
false
of LT:
Expand Down Expand Up @@ -315,6 +324,7 @@ proc evalInfix(c: Compiler; lht, rht: Node; infixOp: InfixOp; scope: ScopeTable)
evalInfix(c, lht, call(rht, scope), infixOp, scope)
of ntCallStack: ofCallStack
of ntMathStmt: ofMath
of ntSize: ofSize
else:
false
of ntCallStack:
Expand All @@ -325,9 +335,11 @@ proc evalInfix(c: Compiler; lht, rht: Node; infixOp: InfixOp; scope: ScopeTable)
evalInfix(c, lht, call(rht, scope), infixOp, scope)
of ntCallStack: ofCallStack
of ntMathStmt: ofMath
of ntSize: ofSize
else:
false
of ntMathStmt: ofMathLeft
of ntSize: ofSize
else:
false
of LTE:
Expand Down Expand Up @@ -367,6 +379,7 @@ proc evalInfix(c: Compiler; lht, rht: Node; infixOp: InfixOp; scope: ScopeTable)
evalInfix(c, lht, call(rht, scope), infixOp, scope)
of ntCallStack: ofCallStack
of ntMathStmt: ofMath
of ntSize: ofSize
else:
false
of ntCallStack:
Expand All @@ -377,9 +390,11 @@ proc evalInfix(c: Compiler; lht, rht: Node; infixOp: InfixOp; scope: ScopeTable)
evalInfix(c, lht, call(rht, scope), infixOp, scope)
of ntCallStack: ofCallStack
of ntMathStmt: ofMath
of ntSize: ofSize
else:
false
of ntMathStmt: ofMathLeft
of ntSize: ofSize
else:
false
of GT:
Expand Down Expand Up @@ -421,6 +436,7 @@ proc evalInfix(c: Compiler; lht, rht: Node; infixOp: InfixOp; scope: ScopeTable)
of ntCallStack:
var rht = handleCallStack(c, rht, scope)
evalInfix(c, lht, rht, infixOp, scope)
of ntSize: ofSize
else:
false
of ntCallStack:
Expand All @@ -431,9 +447,11 @@ proc evalInfix(c: Compiler; lht, rht: Node; infixOp: InfixOp; scope: ScopeTable)
evalInfix(c, lht, call(rht, scope), infixOp, scope)
of ntCallStack: ofCallStack
of ntMathStmt: ofMath
of ntSize: ofSize
else:
false
of ntMathStmt: ofMathLeft
of ntSize: ofSize
else:
false
of GTE:
Expand Down Expand Up @@ -474,6 +492,7 @@ proc evalInfix(c: Compiler; lht, rht: Node; infixOp: InfixOp; scope: ScopeTable)
evalInfix(c, lht, call(rht, scope), infixOp, scope)
of ntCallStack: ofCallStack
of ntMathStmt: ofMath
of ntSize: ofSize
else:
false
of ntCallStack:
Expand All @@ -484,9 +503,11 @@ proc evalInfix(c: Compiler; lht, rht: Node; infixOp: InfixOp; scope: ScopeTable)
evalInfix(c, lht, call(rht, scope), infixOp, scope)
of ntCallStack: ofCallStack
of ntMathStmt: ofMath
of ntSize: ofSize
else:
false
of ntMathStmt: ofMathLeft
of ntSize: ofSize
else:
false
of AND:
Expand Down
4 changes: 2 additions & 2 deletions src/bropkg/engine/parser.nim
Original file line number Diff line number Diff line change
Expand Up @@ -402,9 +402,9 @@ proc parseCompExp(p: var Parser, lht: Node, scope: var seq[ScopeTable]): Node =
let
lhtNodeType = lht.getNodeType
rhtNodeType = rht.getNodeType
if lhtNodeType notin {ntInt, ntFloat}:
if lhtNodeType notin {ntInt, ntFloat, ntSize}:
errorWithArgs(invalidInfixOperator, rhtToken, [$op, $lhtNodeType])
elif rhtNodeType notin {ntInt, ntFloat}:
elif rhtNodeType notin {ntInt, ntFloat, ntSize}:
errorWithArgs(invalidInfixOperator, rhtToken, [$op, $rhtNodeType])
else: discard

Expand Down

0 comments on commit b0bd9d6

Please sign in to comment.