feat[modules]: give datatypes their own file

This commit is contained in:
vegowotenks 2025-06-29 13:51:03 +02:00
parent 0411e8af19
commit 9dfbb4fb1e
4 changed files with 40 additions and 15 deletions

View file

@ -4,23 +4,20 @@
module Language.Brainfuck.Instruction.Extended (Operation(..), Interaction(..), ExtendedInstruction(Modify, Move, Interact, Jump), pattern IfNonZero, pattern WithOffset, mkIfNonZero, mkWithOffset, translationSize, parse) where
import Data.Word (Word8)
import Data.Vector (Vector)
import qualified Data.Vector as Vector
import Numeric.Natural (Natural)
import Language.Brainfuck.Instruction.Compressed (CompressedInstruction)
import Language.Brainfuck.Instruction.Extended.Operation (Operation)
import Language.Brainfuck.Instruction.Extended.Interaction (Interaction)
import qualified Data.Vector as Vector
import qualified Language.Brainfuck.Instruction.Compressed as CompressedInstruction
data Operation
= Add
| Subtract
deriving (Show)
data Interaction
= Read
| Write
deriving (Show)
import qualified Language.Brainfuck.Instruction.Extended.Operation as Operation
import qualified Language.Brainfuck.Instruction.Extended.Interaction as Interaction
pattern WithOffset :: Integer -> ExtendedInstruction -> ExtendedInstruction
pattern WithOffset offset embedded <- AtOffset offset embedded
@ -61,12 +58,12 @@ prependTranslation :: CompressedInstruction -> [ExtendedInstruction] -> [Extende
prependTranslation instruction rest = let
addSingle = (:rest)
in case instruction of
CompressedInstruction.Add i -> addSingle $ Modify Add i
CompressedInstruction.Subtract i -> addSingle $ Modify Subtract i
CompressedInstruction.Add i -> addSingle $ Modify Operation.Add i
CompressedInstruction.Subtract i -> addSingle $ Modify Operation.Subtract i
CompressedInstruction.MoveRight n -> addSingle $ Move $ toInteger n
CompressedInstruction.MoveLeft n -> addSingle $ Move $ toInteger (-n)
CompressedInstruction.ReadByte -> addSingle $ Interact Read
CompressedInstruction.PutByte -> addSingle $ Interact Write
CompressedInstruction.ReadByte -> addSingle $ Interact Interaction.Read
CompressedInstruction.PutByte -> addSingle $ Interact Interaction.Write
CompressedInstruction.Loop body -> let
bodySize = translationSize body
backJump = IfNonZero $ Jump $ -(toInteger bodySize + 1)