Relative Subleq

From Esolang
(Redirected from Relative subleq)
Jump to navigation Jump to search

Relative Subleq is an OISC esoteric programming language directly based on standard Subleq.

Memory in Relative Subleq is made up of 3 elements:

  1. a memory pointer, called P
  2. a memory tape, unbounded in both directions, with each cell being an unbounded signed integer
  3. an input-output queue, which upon initialization contains the inputs list of the program, terminating the list with the number 0

Instructions are still 3 arguments (A,B,C), like in Subleq, however rather than being the current location of the pointer and the two cells to the right, they are the cell to the left (A), the current location of P (B), and the cell to the right (C).

The single instruction is described in pseudocode (following Lua's code conventions) as follows, using the notation "[x]" to denote "cell with address = P+(x)":

  A = [-1]
  B = [0]
  C = [1]
  if A ~= 0 then
     a = [A]
  else
     a = ioqueue.pop()
  end
  
  if B ~= 0 then
     [B] = [B] - a
     condjump = ([B] <= 0)
  else
     ioqueue.push(a)
     condjump = true
  end
  
  if condjump and (C ~= 0) then
     P = P+C
  elseif not condjump then
     P = P+3
  else
     halt()
  end

Outputting is handled as follows:

Upon pushing 0, check if previous backmost item of queue is negative. If so, make a list of the next n many backmost items in the queue, where n is the absolute value of the previous backmost item of the queue. In the list, these should be ordered frontmost to backmost, and not include the newly pushed 0 or the negative-valued item preceding it. For all items k of the new list:

  • If 0 < k < 256, replace k in the list with the corresponding ext. ASCII char.
  • If k < 0, replace k in the list with the bitwise inversion of k.
  • If k == 0, discard all previous items of the list, including this one.

Upon reaching the end of the list, concatenate all remaining integer or char items of the list into a string, and then print the result.

The behavior of values >=256 is left undefined, to permit implementations to use these values for other purposes.