text-register-machine-0.3.0: A Haskell implementation of the 1# Text Register Machine

Language.TRM.Programs

Contents

Synopsis

1# Examples

succBB' :: WordSource

Yields the successor of the backwards-binary number in register 1.

 *Language.TRM> decodeBB <$> phi succBB [(1, encodeBB 0)]
 Just 1
 *Language.TRM> decodeBB <$> phi succBB [(1, encodeBB 119)]
 Just 120

plusBB' :: WordSource

Yields the sum of two backwards-binary numbers in registers 1 and 2.

 *Language.TRM> decodeBB <$> phi plusBB [(1, encodeBB 2), (2, encodeBB 3)]
 Just 5
 *Language.TRM> decodeBB <$> phi plusBB [(1, encodeBB 100), (2, encodeBB 20)]
 Just 120

1#L Programs

clearSource

Arguments

:: Register

Register to clear.

-> LComp () 

moveSource

Arguments

:: Register

Source Register.

-> Register

Destination Register.

-> LComp () 

copySource

Arguments

:: Register

Source Register.

-> Register

Destination Register.

-> Register

Temporary Register.

-> LComp () 

compare :: Register -> Register -> LComp ()Source

Compares the contents of the given registers for equality, leaving a 1 in the first register if they are, or nothing otherwise. The contents of both registers are destroyed in the process.

succBBSource

Arguments

:: Register

Register to increment.

-> Register

Temporary Register, assumed to be empty.

-> LComp () 

addBB :: Register -> Register -> [Register] -> LComp ()Source

Add the first two argument registers using primitive recursion. The remaining registers are temporaries assumed to be empty.

 *Language.TRM.Programs> decodeBB <$> runL (addBB 1 2 [3..7]) [(1, encodeBB 100), (2, encodeBB 20)]
 Just 120