array-forth- A simple interpreter for arrayForth, the language used on GreenArrays chips.

Safe HaskellNone




data Instrs Source

Represents a word in memory. This word can either contain opcodes, opcodes and a jump address or just a constant number.

type NativeProgram = [Instrs] Source

A program in the F18A instruction set.

splitWords :: (a -> Bool) -> [a] -> [[a]] Source

Splits a list into chunks of at most four, breaking off a chunk whenever it sees an element matching the given predicate. This is useful for splitting a program along word boundaries, accounting for jump addresses.

readNativeProgram :: String -> Either ParseError NativeProgram Source

Read a whole program, splitting instructions up into words.

toBits :: Instrs -> F18Word Source

Returns the given instructions as an actual word. This assumes the address is sized appropriately.

fromBits :: F18Word -> Instrs Source

Reads in a word as a set of opcodes.

toOpcodes :: Instrs -> [Opcode] Source

Returns the opcodes in the given instruction word. A constant corresponds to not having any opcodes.

runningTime :: NativeProgram -> Double Source

Estimates the running time of the program in nanoseconds. This is based on the numbers provided in the manual: faster instructions take 1.5 nanoseconds and slower ones take 5. For now, this estimate ignores control flow like ifs and loops.