diff --git a/src/Instructions/ExecInstructions.hs b/src/Instructions/ExecInstructions.hs index 8aa243e..bd27ec2 100644 --- a/src/Instructions/ExecInstructions.hs +++ b/src/Instructions/ExecInstructions.hs @@ -4,22 +4,22 @@ import State import Instructions.IntInstructions instructionExecIf :: State -> State -instructionExecIf state@(State {exec = (e1 : e2 : es), bool = (b : _)}) = +instructionExecIf state@(State {_exec = (e1 : e2 : es), _bool = (b : _)}) = if b - then state {exec = e1 : es} - else state {exec = e2 : es} + then state {_exec = e1 : es} + else state {_exec = e2 : es} instructionExecIf state = state instructionExecDup :: State -> State -instructionExecDup state@(State {exec = alles@(e0 : _)}) = - state {exec = e0 : alles} +instructionExecDup state@(State {_exec = alles@(e : _)}) = + state {_exec = e : alles} instructionExecDup state = state instructionExecDoRange :: State -> State -instructionExecDoRange state@(State {exec = (e1 : es), int = (i0 : i1 : is)}) = +instructionExecDoRange state@(State {_exec = (e1 : es), _int = (i0 : i1 : is)}) = if increment i0 i1 /= 0 - then state {exec = e1 : Block [GeneInt (i1 + increment i0 i1), GeneInt i0, StateFunc instructionExecDoRange, e1] : es, int = i1 : is} - else state {exec = e1 : es, int = i1 : is} + then state {_exec = e1 : Block [GeneInt (i1 + increment i0 i1), GeneInt i0, StateFunc instructionExecDoRange, e1] : es, _int = i1 : is} + else state {_exec = e1 : es, _int = i1 : is} where increment :: Int -> Int -> Int increment destIdx currentIdx @@ -29,37 +29,37 @@ instructionExecDoRange state@(State {exec = (e1 : es), int = (i0 : i1 : is)}) = instructionExecDoRange state = state instructionExecDoCount :: State -> State -instructionExecDoCount state@(State {exec = (e1 : es), int = (i1 : is)}) = - if i1 < 1 +instructionExecDoCount state@(State {_exec = (e : es), _int = (i : is)}) = + if i < 1 then state - else state {exec = Block [GeneInt 0, GeneInt $ i1 - 1, StateFunc instructionExecDoRange, e1] : es, int = is} + else state {_exec = Block [GeneInt 0, GeneInt $ i - 1, StateFunc instructionExecDoRange, e] : es, _int = is} instructionExecDoCount state = state instructionExecDoTimes :: State -> State -instructionExecDoTimes state@(State {exec = (e1 : es), int = (i1 : is)}) = - if i1 < 1 +instructionExecDoTimes state@(State {_exec = (e : es), _int = (i : is)}) = + if i < 1 then state - else state {exec = Block [GeneInt 0, GeneInt $ i1 - 1, StateFunc instructionExecDoRange, Block [StateFunc instructionIntPop, e1]] : es, int = is} + else state {_exec = Block [GeneInt 0, GeneInt $ i - 1, StateFunc instructionExecDoRange, Block [StateFunc instructionIntPop, e]] : es, _int = is} instructionExecDoTimes state = state instructionExecWhile :: State -> State -instructionExecWhile state@(State {exec = (_ : es), bool = []}) = - state {exec = es} -instructionExecWhile state@(State {exec = alles@(e1 : es), bool = (b1 : bs)}) = - if b1 - then state {exec = e1 : StateFunc instructionExecWhile : alles, bool = bs} - else state {exec = es} +instructionExecWhile state@(State {_exec = (_ : es), _bool = []}) = + state {_exec = es} +instructionExecWhile state@(State {_exec = alles@(e : es), _bool = (b : bs)}) = + if b + then state {_exec = e : StateFunc instructionExecWhile : alles, _bool = bs} + else state {_exec = es} instructionExecWhile state = state instructionExecDoWhile :: State -> State -instructionExecDoWhile state@(State {exec = alles@(e1 : _)}) = - state {exec = e1 : StateFunc instructionExecWhile : alles} +instructionExecDoWhile state@(State {_exec = alles@(e : _)}) = + state {_exec = e : StateFunc instructionExecWhile : alles} instructionExecDoWhile state = state --- Eats the boolean no matter what +-- Eats the _boolean no matter what instructionExecWhen :: State -> State -instructionExecWhen state@(State {exec = (_ : es), bool = (b1 : bs)}) = - if not b1 - then state {exec = es, bool = bs} - else state {bool = bs} +instructionExecWhen state@(State {_exec = (_ : es), _bool = (b : bs)}) = + if not b + then state {_exec = es, _bool = bs} + else state {_bool = bs} instructionExecWhen state = state diff --git a/src/Instructions/FloatInstructions.hs b/src/Instructions/FloatInstructions.hs index 8199988..8d9c834 100644 --- a/src/Instructions/FloatInstructions.hs +++ b/src/Instructions/FloatInstructions.hs @@ -3,54 +3,54 @@ module Instructions.FloatInstructions where import State instructionFloatAdd :: State -> State -instructionFloatAdd state@(State {float = (f1 : f2 : fs)}) = state {float = f2 + f1 : fs} +instructionFloatAdd state@(State {_float = (f1 : f2 : fs)}) = state {_float = f2 + f1 : fs} instructionFloatAdd state = state instructionFloatSub :: State -> State -instructionFloatSub state@(State {float = (f1 : f2 : fs)}) = state {float = f2 - f1 : fs} +instructionFloatSub state@(State {_float = (f1 : f2 : fs)}) = state {_float = f2 - f1 : fs} instructionFloatSub state = state instructionFloatMul :: State -> State -instructionFloatMul state@(State {float = (f1 : f2 : fs)}) = state {float = f2 * f1 : fs} +instructionFloatMul state@(State {_float = (f1 : f2 : fs)}) = state {_float = f2 * f1 : fs} instructionFloatMul state = state instructionFloatDiv :: State -> State -instructionFloatDiv state@(State {float = (f1 : f2 : fs)}) = state {float = if f1 /= 0 then f2 / f1 : fs else f1 : f2 : fs} +instructionFloatDiv state@(State {_float = (f1 : f2 : fs)}) = state {_float = if f1 /= 0 then f2 / f1 : fs else f1 : f2 : fs} instructionFloatDiv state = state instructionFloatMin :: State -> State -instructionFloatMin state@(State {float = (f1 : f2 : fs)}) = state {float = min f1 f2 : fs} +instructionFloatMin state@(State {_float = (f1 : f2 : fs)}) = state {_float = min f1 f2 : fs} instructionFloatMin state = state instructionFloatMax :: State -> State -instructionFloatMax state@(State {float = (f1 : f2 : fs)}) = state {float = max f1 f2 : fs} +instructionFloatMax state@(State {_float = (f1 : f2 : fs)}) = state {_float = max f1 f2 : fs} instructionFloatMax state = state instructionFloatInc :: State -> State -instructionFloatInc state@(State {float = (f1 : fs)}) = state {float = f1 + 1 : fs} +instructionFloatInc state@(State {_float = (f1 : fs)}) = state {_float = f1 + 1 : fs} instructionFloatInc state = state instructionFloatDec :: State -> State -instructionFloatDec state@(State {float = (f1 : fs)}) = state {float = f1 - 1 : fs} +instructionFloatDec state@(State {_float = (f1 : fs)}) = state {_float = f1 - 1 : fs} instructionFloatDec state = state instructionFloatLT :: State -> State -instructionFloatLT state@(State {float = f1 : f2 : fs, bool = bs}) = state {float = fs, bool = (f1 < f2) : bs} +instructionFloatLT state@(State {_float = f1 : f2 : fs, _bool = bs}) = state {_float = fs, _bool = (f1 < f2) : bs} instructionFloatLT state = state instructionFloatGT :: State -> State -instructionFloatGT state@(State {float = f1 : f2 : fs, bool = bs}) = state {float = fs, bool = (f1 > f2) : bs} +instructionFloatGT state@(State {_float = f1 : f2 : fs, _bool = bs}) = state {_float = fs, _bool = (f1 > f2) : bs} instructionFloatGT state = state instructionFloatLTE :: State -> State -instructionFloatLTE state@(State {float = f1 : f2 : fs, bool = bs}) = state {float = fs, bool = (f1 <= f2) : bs} +instructionFloatLTE state@(State {_float = f1 : f2 : fs, _bool = bs}) = state {_float = fs, _bool = (f1 <= f2) : bs} instructionFloatLTE state = state instructionFloatGTE :: State -> State -instructionFloatGTE state@(State {float = f1 : f2 : fs, bool = bs}) = state {float = fs, bool = (f1 >= f2) : bs} +instructionFloatGTE state@(State {_float = f1 : f2 : fs, _bool = bs}) = state {_float = fs, _bool = (f1 >= f2) : bs} instructionFloatGTE state = state instructionFloatPop :: State -> State -instructionFloatPop state@(State {float = (_ : fs)}) = state {float = fs} +instructionFloatPop state@(State {_float = (_ : fs)}) = state {_float = fs} instructionFloatPop state = state diff --git a/src/Instructions/IntInstructions.hs b/src/Instructions/IntInstructions.hs index d12ee6a..3d25aa4 100644 --- a/src/Instructions/IntInstructions.hs +++ b/src/Instructions/IntInstructions.hs @@ -4,57 +4,57 @@ import State -- import Debug.Trace 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} instructionIntAdd state = state instructionIntSub :: State -> State -instructionIntSub state@(State {int = (i1 : i2 : is)}) = state {int = i2 - i1 : is} +instructionIntSub state@(State {_int = (i1 : i2 : is)}) = state {_int = i2 - i1 : is} instructionIntSub state = state instructionIntMul :: State -> State -instructionIntMul state@(State {int = (i1 : i2 : is)}) = state {int = i2 * i1 : is} +instructionIntMul state@(State {_int = (i1 : i2 : is)}) = state {_int = i2 * i1 : is} instructionIntMul state = state instructionIntDiv :: State -> State -instructionIntDiv state@(State {int = (i1 : i2 : is)}) = state {int = if i1 /= 0 then (i2 `div` i1) : is else i1 : i2 : 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 instructionIntMod :: State -> State -instructionIntMod state@(State {int = (i1 : i2 : is)}) = state {int = i2 `mod` i1 : is} +instructionIntMod state@(State {_int = (i1 : i2 : is)}) = state {_int = i2 `mod` i1 : is} instructionIntMod state = state instructionIntMin :: State -> State -instructionIntMin state@(State {int = (i1 : i2 : is)}) = state {int = min i1 i2 : is} +instructionIntMin state@(State {_int = (i1 : i2 : is)}) = state {_int = min i1 i2 : is} instructionIntMin state = state instructionIntMax :: State -> State -instructionIntMax state@(State {int = (i1 : i2 : is)}) = state {int = max i1 i2 : is} +instructionIntMax state@(State {_int = (i1 : i2 : is)}) = state {_int = max i1 i2 : is} instructionIntMax state = state instructionIntInc :: State -> State -instructionIntInc state@(State {int = (i1 : is)}) = state {int = i1 + 1 : is} +instructionIntInc state@(State {_int = (i1 : is)}) = state {_int = i1 + 1 : is} instructionIntInc state = state instructionIntDec :: State -> State -instructionIntDec state@(State {int = (i1 : is)}) = state {int = i1 - 1 : is} +instructionIntDec state@(State {_int = (i1 : is)}) = state {_int = i1 - 1 : is} instructionIntDec state = state instructionIntLT :: State -> State -instructionIntLT state@(State {int = i1 : i2 : is, bool = bs}) = state {int = is, bool = (i1 < i2) : bs} +instructionIntLT state@(State {_int = i1 : i2 : is, _bool = bs}) = state {_int = is, _bool = (i1 < i2) : bs} instructionIntLT state = state instructionIntGT :: State -> State -instructionIntGT state@(State {int = i1 : i2 : is, bool = bs}) = state {int = is, bool = (i1 > i2) : bs} +instructionIntGT state@(State {_int = i1 : i2 : is, _bool = bs}) = state {_int = is, _bool = (i1 > i2) : bs} instructionIntGT state = state instructionIntLTE :: State -> State -instructionIntLTE state@(State {int = i1 : i2 : is, bool = bs}) = state {int = is, bool = (i1 <= i2) : bs} +instructionIntLTE state@(State {_int = i1 : i2 : is, _bool = bs}) = state {_int = is, _bool = (i1 <= i2) : bs} instructionIntLTE state = state instructionIntGTE :: State -> State -instructionIntGTE state@(State {int = i1 : i2 : is, bool = bs}) = state {int = is, bool = (i1 >= i2) : bs} +instructionIntGTE state@(State {_int = i1 : i2 : is, _bool = bs}) = state {_int = is, _bool = (i1 >= i2) : bs} instructionIntGTE state = state instructionIntPop :: State -> State -instructionIntPop state@(State {int = (_ : is)}) = state {int = is} +instructionIntPop state@(State {_int = (_ : is)}) = state {_int = is} instructionIntPop state = state