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

Safe HaskellSafe-Inferred



Defines the basic operations for reading and writing through ports.

Each core has four ports connecting it to its neighbors. The cores around the edges have ports connected to IO devices. A Channel is just a type containing the four ports that you can write to or read from.



data Channel Source

A channel representing the four communication directions a core may use. In practice, these will either be hooked up to other cores or to IO. Nothing represents no message; if there is a word, execution will block.



data Port Source

The four possible port directions.



emptyChannel :: Channel Source

An empty channel has no reads or writes and doesn't block execution.

writePort Source


:: F18Word

The address to write to. Only bits 5–8 are considered.

-> F18Word

The word to write to the channel.

-> Channel

The resulting channel, with any unused ports empty.

Write to the ports specified by the given memory address. This will clear all the channels not being written to (by setting them to Nothing).

The ports to use are specified by bits 5–8 of the address. These bits correspond respectively to up, left, down and right. Bits 5 and 7 are inverted—0 turns the channel *on*.

readPort :: F18Word -> Channel -> Maybe F18Word Source

Read the inputs from the ports specified by the given address. The address is handled the same way as in writePort. Returns Nothing if blocked on the read.

If more than one of the read ports has data, this currently just chooses the first one based on the right, down, left, up order. I don't know if this is the correct behavior—perhaps I should just xor them together or something?