fix int div, add floats (need tests for these)
This commit is contained in:
parent
439cc2e6bf
commit
c0e5477828
@ -1,60 +1,56 @@
|
|||||||
module Instruction.FloatInstructions where
|
module Instructions.FloatInstructions where
|
||||||
|
|
||||||
import State
|
import State
|
||||||
|
|
||||||
instructionIntAdd :: State -> State
|
instructionFloatAdd :: State -> State
|
||||||
instructionIntAdd state@(State {int = (i1 : i2 : is)}) = state {int = i2 + i1 : is}
|
instructionFloatAdd state@(State {float = (f1 : f2 : fs)}) = state {float = f2 + f1 : fs}
|
||||||
instructionIntAdd state = state
|
instructionFloatAdd state = state
|
||||||
|
|
||||||
instructionIntSub :: State -> State
|
instructionFloatSub :: State -> State
|
||||||
instructionIntSub state@(State {int = (i1 : i2 : is)}) = state {int = i2 - i1 : is}
|
instructionFloatSub state@(State {float = (f1 : f2 : fs)}) = state {float = f2 - f1 : fs}
|
||||||
instructionIntSub state = state
|
instructionFloatSub state = state
|
||||||
|
|
||||||
instructionIntMul :: State -> State
|
instructionFloatMul :: State -> State
|
||||||
instructionIntMul state@(State {int = (i1 : i2 : is)}) = state {int = i2 * i1 : is}
|
instructionFloatMul state@(State {float = (f1 : f2 : fs)}) = state {float = f2 * f1 : fs}
|
||||||
instructionIntMul state = state
|
instructionFloatMul state = state
|
||||||
|
|
||||||
instructionIntDiv :: State -> State
|
instructionFloatDiv :: State -> State
|
||||||
instructionIntDiv state@(State {int = (i1 : i2 : is)}) = state {int = i2 `div` i1 : is}
|
instructionFloatDiv state@(State {float = (f1 : f2 : fs)}) = state {float = if f1 /= 0 then f2 / f1 : fs else f1 : f2 : fs}
|
||||||
instructionIntDiv state = state
|
instructionFloatDiv state = state
|
||||||
|
|
||||||
instructionIntMod :: State -> State
|
instructionFloatMin :: State -> State
|
||||||
instructionIntMod state@(State {int = (i1 : i2 : is)}) = state {int = i2 `mod` i1 : is}
|
instructionFloatMin state@(State {float = (f1 : f2 : fs)}) = state {float = min f1 f2 : fs}
|
||||||
instructionIntMod state = state
|
instructionFloatMin state = state
|
||||||
|
|
||||||
instructionIntMin :: State -> State
|
instructionFloatMax :: State -> State
|
||||||
instructionIntMin state@(State {int = (i1 : i2 : is)}) = state {int = min i1 i2 : is}
|
instructionFloatMax state@(State {float = (f1 : f2 : fs)}) = state {float = max f1 f2 : fs}
|
||||||
instructionIntMin state = state
|
instructionFloatMax state = state
|
||||||
|
|
||||||
instructionIntMax :: State -> State
|
instructionFloatInc :: State -> State
|
||||||
instructionIntMax state@(State {int = (i1 : i2 : is)}) = state {int = max i1 i2 : is}
|
instructionFloatInc state@(State {float = (f1 : fs)}) = state {float = f1 + 1 : fs}
|
||||||
instructionIntMax state = state
|
instructionFloatInc state = state
|
||||||
|
|
||||||
instructionIntInc :: State -> State
|
instructionFloatDec :: State -> State
|
||||||
instructionIntInc state@(State {int = (i1 : is)}) = state {int = i1 + 1 : is}
|
instructionFloatDec state@(State {float = (f1 : fs)}) = state {float = f1 - 1 : fs}
|
||||||
instructionIntInc state = state
|
instructionFloatDec state = state
|
||||||
|
|
||||||
instructionIntDec :: State -> State
|
instructionFloatLT :: State -> State
|
||||||
instructionIntDec state@(State {int = (i1 : is)}) = state {int = i1 - 1 : is}
|
instructionFloatLT state@(State {float = f1 : f2 : fs, bool = bs}) = state {float = fs, bool = (f1 < f2) : bs}
|
||||||
instructionIntDec state = state
|
instructionFloatLT state = state
|
||||||
|
|
||||||
instructionIntLT :: State -> State
|
instructionFloatGT :: State -> State
|
||||||
instructionIntLT state@(State {int = i1 : i2 : is, bool = bs}) = state {int = is, bool = (i1 < i2) : bs}
|
instructionFloatGT state@(State {float = f1 : f2 : fs, bool = bs}) = state {float = fs, bool = (f1 > f2) : bs}
|
||||||
instructionIntLT state = state
|
instructionFloatGT state = state
|
||||||
|
|
||||||
instructionIntGT :: State -> State
|
instructionFloatLTE :: State -> State
|
||||||
instructionIntGT state@(State {int = i1 : i2 : is, bool = bs}) = state {int = is, bool = (i1 > i2) : bs}
|
instructionFloatLTE state@(State {float = f1 : f2 : fs, bool = bs}) = state {float = fs, bool = (f1 <= f2) : bs}
|
||||||
instructionIntGT state = state
|
instructionFloatLTE state = state
|
||||||
|
|
||||||
instructionIntLTE :: State -> State
|
instructionFloatGTE :: State -> State
|
||||||
instructionIntLTE state@(State {int = i1 : i2 : is, bool = bs}) = state {int = is, bool = (i1 <= i2) : bs}
|
instructionFloatGTE state@(State {float = f1 : f2 : fs, bool = bs}) = state {float = fs, bool = (f1 >= f2) : bs}
|
||||||
instructionIntLTE state = state
|
instructionFloatGTE state = state
|
||||||
|
|
||||||
instructionIntGTE :: State -> State
|
instructionFloatPop :: State -> State
|
||||||
instructionIntGTE state@(State {int = i1 : i2 : is, bool = bs}) = state {int = is, bool = (i1 >= i2) : bs}
|
instructionFloatPop state@(State {float = (_ : fs)}) = state {float = fs}
|
||||||
instructionIntGTE state = state
|
instructionFloatPop state = state
|
||||||
|
|
||||||
instructionIntPop :: State -> State
|
|
||||||
instructionIntPop state@(State {int = (_ : is)}) = state {int = is}
|
|
||||||
instructionIntPop state = state
|
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
module Instructions.IntInstructions where
|
module Instructions.IntInstructions where
|
||||||
|
|
||||||
import State
|
import State
|
||||||
|
import Debug.Trace
|
||||||
|
|
||||||
instructionIntAdd :: State -> State
|
instructionIntAdd :: State -> State
|
||||||
instructionIntAdd state@(State {int = (i1 : i2 : is)}) = state {int = i2 + i1 : is}
|
instructionIntAdd state@(State {int = (i1 : i2 : is)}) = state {int = i2 + i1 : is}
|
||||||
@ -15,7 +16,7 @@ instructionIntMul state@(State {int = (i1 : i2 : is)}) = state {int = i2 * i1 :
|
|||||||
instructionIntMul state = state
|
instructionIntMul state = state
|
||||||
|
|
||||||
instructionIntDiv :: State -> State
|
instructionIntDiv :: State -> State
|
||||||
instructionIntDiv state@(State {int = (i1 : i2 : is)}) = state {int = i2 `div` i1 : is}
|
instructionIntDiv state@(State {int = (i1 : i2 : is)}) = state {int = if i1 /= 0 then (i2 `div` i1) : is else i1 : i2 : is}
|
||||||
instructionIntDiv state = state
|
instructionIntDiv state = state
|
||||||
|
|
||||||
instructionIntMod :: State -> State
|
instructionIntMod :: State -> State
|
||||||
|
Loading…
x
Reference in New Issue
Block a user