RWLR

Read Write Left Right was a language created by Tslil Clingman in mid 2007 only to be realised by the author in mid 2008. The language combines the author's wishes for a purely tape based language and the capability for self-modifying code.

Overview
In this language, there are 7 commands, numbered from 0 to 6. The programme and all data are situated on a tape of infinite length, extending both left and right of the current position, thus all tape positions are relative to the current one. There are two heads, the read head and the write head. Both can move an arbitrary amount either left or right along the tape when instructed to, but only the write head can modify the tape and only the read head can extract instructions and data.

In order to execute code, the initial positions of the two heads are specified. The read head the reads the cell underneath it and acts accordingly, if the head is not explicitly instructed to move, it is advanced by one cell to the right. The write head will only move when the appropriate instruction is read from the tape.

The commands are:

0 : MVR

1 : MVW

2 : INC

3 : DEC

4 : IF

5 : CPY

6 : OutP

Command Explanation
0 : This cell is followed by another cell (on its right) containing an integer specifying how much the read head must move by to the right (negative being on the left)

1 : This cell is followed by another cell (on its right) containing an integer specifying how much the write head must move by to the right (negative being on the left), after processing this command, the read head is advanced by two to the right (relative to the one) so as to avoid the adjacent cell

2/3 : This instructs the write head to increase and decrease (respectively) the value of the cell currently under it by one, the read head is then advanced by one to the right

4 : This is of the form "4 x y" meaning 4 is the current cell, x is the test value, if the value in the next cell is non-zero then advance the read head by three to the right (relative to the four) otherwise advance the read head by "y" to the right (relative to the four)

5 : This will copy the value from the cell on the immediate right of the instruction to the cell currently under the write head

6 : This of the form "6 z" and will output the value of the cell "z" to the right of the 6

Interpreter
Below is the interpreter written by the author in python:

def Go (n =[1,5,0,16,4,0,18,1,12,2,1,2,3,1,-19,0,-15,-4,5,40,0,-16,6,-5,0,0],r = 0, w = 0, outp = True): mvd = False k = 0 while True: temp = n        lr = r         lw = w         if outp: print k,' -> R: ',r,' ; W: ',w,' ; Tape: ',n if n[r]==0: r += n[r+1] mvd = True elif n[r]==1: w += n[r+1] elif n[r]==2: n[w] += 1 r -= 1 elif n[r]==3: n[w] -= 1 r -= 1 elif n[r]==4: if n[r+1]>0: r += 3 else: r += n[r+2] mvd = True elif n[r]==5: n[w] = n[r+1] elif n[r]==6: print n[r+n[r+1]] if mvd==False: r += 2 else: mvd = False k += 1 if ((temp==n) and (lr==r) and (lw==w)) or (r>=len(n)): print 'Machine Halted' break

Below is an addition programme: 1,5,0,16,4,0,18,1,12,2,1,2,3,1,-19,0,-15,A,5,B,0,-16,6,-5,0,0 Replace A and B with the numbers you wish to sum. B>=0 (Read/Write on leftmost cell)