intcode-0.4.0.0: Advent of Code 2019 intcode interpreter
Copyright(c) Eric Mertens 2019
LicenseISC
Maintaineremertens@gmail.com
Safe HaskellSafe
LanguageHaskell2010

Intcode.Opcode

Contents

Description

This module provides a representation of the intcode machine's opcodes.

Opcodes are parameterized over their parameters. This allows the implementation to store both parameter modes and resolved parameter pointers in the same constructors.

Synopsis

Types

data Opcode a Source #

Opcodes parameterized over argument representations.

Constructors

Add !a !a !a

addition: c = a + b

Mul !a !a !a

multiplication: c = a * b

Inp !a

input: a = input()

Out !a

output: output(a)

Jnz !a !a

jump-if-true: if a then goto b

Jz !a !a

jump-if-false: if !a then goto b

Lt !a !a !a

less-than: c = a < b

Eq !a !a !a

equals: c = a == b

Arb !a

adjust-rel-base: rel += a

Hlt

halt

Instances

Instances details
Foldable Opcode Source # 
Instance details

Defined in Intcode.Opcode

Methods

fold :: Monoid m => Opcode m -> m #

foldMap :: Monoid m => (a -> m) -> Opcode a -> m #

foldMap' :: Monoid m => (a -> m) -> Opcode a -> m #

foldr :: (a -> b -> b) -> b -> Opcode a -> b #

foldr' :: (a -> b -> b) -> b -> Opcode a -> b #

foldl :: (b -> a -> b) -> b -> Opcode a -> b #

foldl' :: (b -> a -> b) -> b -> Opcode a -> b #

foldr1 :: (a -> a -> a) -> Opcode a -> a #

foldl1 :: (a -> a -> a) -> Opcode a -> a #

toList :: Opcode a -> [a] #

null :: Opcode a -> Bool #

length :: Opcode a -> Int #

elem :: Eq a => a -> Opcode a -> Bool #

maximum :: Ord a => Opcode a -> a #

minimum :: Ord a => Opcode a -> a #

sum :: Num a => Opcode a -> a #

product :: Num a => Opcode a -> a #

Traversable Opcode Source #

Arguments visited from left to right.

Instance details

Defined in Intcode.Opcode

Methods

traverse :: Applicative f => (a -> f b) -> Opcode a -> f (Opcode b) #

sequenceA :: Applicative f => Opcode (f a) -> f (Opcode a) #

mapM :: Monad m => (a -> m b) -> Opcode a -> m (Opcode b) #

sequence :: Monad m => Opcode (m a) -> m (Opcode a) #

Functor Opcode Source # 
Instance details

Defined in Intcode.Opcode

Methods

fmap :: (a -> b) -> Opcode a -> Opcode b #

(<$) :: a -> Opcode b -> Opcode a #

Read a => Read (Opcode a) Source # 
Instance details

Defined in Intcode.Opcode

Show a => Show (Opcode a) Source # 
Instance details

Defined in Intcode.Opcode

Methods

showsPrec :: Int -> Opcode a -> ShowS #

show :: Opcode a -> String #

showList :: [Opcode a] -> ShowS #

Eq a => Eq (Opcode a) Source # 
Instance details

Defined in Intcode.Opcode

Methods

(==) :: Opcode a -> Opcode a -> Bool #

(/=) :: Opcode a -> Opcode a -> Bool #

Ord a => Ord (Opcode a) Source # 
Instance details

Defined in Intcode.Opcode

Methods

compare :: Opcode a -> Opcode a -> Ordering #

(<) :: Opcode a -> Opcode a -> Bool #

(<=) :: Opcode a -> Opcode a -> Bool #

(>) :: Opcode a -> Opcode a -> Bool #

(>=) :: Opcode a -> Opcode a -> Bool #

max :: Opcode a -> Opcode a -> Opcode a #

min :: Opcode a -> Opcode a -> Opcode a #

data Mode Source #

Parameter modes

Constructors

Abs

absolute position

Imm

immediate

Rel

relative position

Instances

Instances details
Read Mode Source # 
Instance details

Defined in Intcode.Opcode

Show Mode Source # 
Instance details

Defined in Intcode.Opcode

Methods

showsPrec :: Int -> Mode -> ShowS #

show :: Mode -> String #

showList :: [Mode] -> ShowS #

Eq Mode Source # 
Instance details

Defined in Intcode.Opcode

Methods

(==) :: Mode -> Mode -> Bool #

(/=) :: Mode -> Mode -> Bool #

Ord Mode Source # 
Instance details

Defined in Intcode.Opcode

Methods

compare :: Mode -> Mode -> Ordering #

(<) :: Mode -> Mode -> Bool #

(<=) :: Mode -> Mode -> Bool #

(>) :: Mode -> Mode -> Bool #

(>=) :: Mode -> Mode -> Bool #

max :: Mode -> Mode -> Mode #

min :: Mode -> Mode -> Mode #

Decoder

decode Source #

Arguments

:: Int

opcode

-> Maybe (Opcode Mode) 

Decode an instruction to determine the opcode and parameter modes.

>>> decode 1002
Just (Mul Abs Imm Abs)