renamed evalToValues to binExprToValues

This commit is contained in:
Samuel Hammersberg 2023-02-04 15:21:04 +01:00
parent d779605814
commit cd47f7dde3
2 changed files with 8 additions and 8 deletions

View file

@ -156,7 +156,7 @@ compile (Program prgE) = do
emitAdd :: Exp -> Exp -> CompilerState emitAdd :: Exp -> Exp -> CompilerState
emitAdd e1 e2 = do emitAdd e1 e2 = do
(v1,v2) <- evalToValues e1 e2 (v1,v2) <- binExprToValues e1 e2
increaseVarCount increaseVarCount
v <- gets variableCount v <- gets variableCount
emit $ Variable $ Ident $ show v emit $ Variable $ Ident $ show v
@ -164,7 +164,7 @@ compile (Program prgE) = do
emitMul :: Exp -> Exp -> CompilerState emitMul :: Exp -> Exp -> CompilerState
emitMul e1 e2 = do emitMul e1 e2 = do
(v1,v2) <- evalToValues e1 e2 (v1,v2) <- binExprToValues e1 e2
increaseVarCount increaseVarCount
v <- gets variableCount v <- gets variableCount
emit $ Variable $ Ident $ show v emit $ Variable $ Ident $ show v
@ -173,7 +173,7 @@ compile (Program prgE) = do
emitMod :: Exp -> Exp -> CompilerState emitMod :: Exp -> Exp -> CompilerState
emitMod e1 e2 = do emitMod e1 e2 = do
-- //TODO Replace with `let m a b = rem (abs $ b + a) b` -- //TODO Replace with `let m a b = rem (abs $ b + a) b`
(v1,v2) <- evalToValues e1 e2 (v1,v2) <- binExprToValues e1 e2
increaseVarCount increaseVarCount
vadd <- gets variableCount vadd <- gets variableCount
emit $ Variable $ Ident $ show vadd emit $ Variable $ Ident $ show vadd
@ -193,7 +193,7 @@ compile (Program prgE) = do
emitDiv :: Exp -> Exp -> CompilerState emitDiv :: Exp -> Exp -> CompilerState
emitDiv e1 e2 = do emitDiv e1 e2 = do
(v1,v2) <- evalToValues e1 e2 (v1,v2) <- binExprToValues e1 e2
increaseVarCount increaseVarCount
v <- gets variableCount v <- gets variableCount
emit $ Variable $ Ident $ show v emit $ Variable $ Ident $ show v
@ -201,14 +201,14 @@ compile (Program prgE) = do
emitSub :: Exp -> Exp -> CompilerState emitSub :: Exp -> Exp -> CompilerState
emitSub e1 e2 = do emitSub e1 e2 = do
(v1,v2) <- evalToValues e1 e2 (v1,v2) <- binExprToValues e1 e2
increaseVarCount increaseVarCount
v <- gets variableCount v <- gets variableCount
emit $ Variable $ Ident $ show v emit $ Variable $ Ident $ show v
emit $ Sub I64 v1 v2 emit $ Sub I64 v1 v2
evalToValues :: Exp -> Exp -> State CodeGenerator (Value, Value) binExprToValues :: Exp -> Exp -> State CodeGenerator (Value, Value)
evalToValues e1 e2 = case (e1, e2) of binExprToValues e1 e2 = case (e1, e2) of
-- instead of declaring variables for working on ints, -- instead of declaring variables for working on ints,
-- we can directly pass them to their functions. -- we can directly pass them to their functions.
(EInt i1, EInt i2) -> return (VInteger i1, VInteger i2) (EInt i1, EInt i2) -> return (VInteger i1, VInteger i2)

View file

@ -2,4 +2,4 @@
main = (0-3) % (7) -- ((2 * (123 + 4214 % (1230)) - 1231) / 314) main = ((2 * (123 + 4214 % (1230)) - 1231) / 314)