Isolated

From Esolang
Jump to navigation Jump to search

Isolated is a tentative programming language conceived by Tim Stiles in May 2009. It has no stack and no literals, and all four 'variables' are intrinsically related to the programming's functionality; flow is performed by editing the instruction pointer's value relative to something else. I'm not yet sure how useful it is and what the minimum requirements would be to keep it 'in theme' while making it practical; most of it came to me in a 'waking' mental state.

Language overview

The programming environment consists of a tape 2^n cells long with n bits in each; arithmetic is two's complement. They all start out equal to 0. The four variables are the tape pointer, the value under the tape pointer, the instruction pointer and 'I/O' which holds the last value taken in and can be used to take in or give out values. (By default I/O is done by the values of characters/unicode depending on tape size)

A program in Isolated is made up of a series of instructions in binary, eight bits long each. One instruction in Isolated is made of two bits (the target), four bits (an operation) and another two bits (the source). Operations are mostly of the form target = target (operator) source. A program does not end if it moves past the last instruction; it is instead taken mod the number of instructions and continues executing until the 'Stop the program' instruction is executed.

Instructions

Variables

Binary Description
00
Tape contents : value under the tape pointer
01
Tape pointer : points to a cell on the tape
10
Instruction pointer : useful for flow control; operations are modulo number of instructions
11
Input/output :
  • As the target, output the value assigned; if the target is read (as with +=) the last value from input is used, or 0 if no input has been taken yet.
  • As the source, is equal to the next value taken from input.

Operators

Binary Description
0000
=
0001
+=
0010
-=
0011
*=
0100
/=
0101
%=
0110
AND= (bitwise)
0111
OR= (bitwise)
1000
XOR= (bitwise)
1001
NAND= (bitwise)
1010
NOR= (bitwise)
1011
XNOR= (bitwise)
1100
swap places with
1101
average (target = (target + source) / 2, or just target / 2 if both are the same)
1110
unary operation on target; next two bits are not a source but the operator:
Binary Description
00
logical not
01
arithmetic negation
10
absolute value
11
bitwise logical not (this is redundant with target NAND= target)
1111
control operation; next two bits are not a source but the operation:
Binary Description
00
stop the program
01
perform I/O in character/unicode values from now on (default setting)
10
perform I/O in decimal numbers from now on
11
perform I/O in binary numbers from now on

So, for example:

  • 10001000 means ip -= current cell, which moves the program back by the number of instructions under the tape pointer;
  • 00000111 means current cell += input, which takes a value from input and adds it to the current tape cell's value
  • 11001111 means output *= input, which outputs a character to stdout that is equal to the last character taken from stdin multiplied by a new character to be taken from stdin.

Tricks

  • = self is a nop: 00000000, 01000001, 10000010 and 11000011 have no effect.
  • += self multiplies target by two.
  • average= self divides the target by two.
  • NAND= self produces the bitwise inverse.
  • -= self resets the target to 0.
  • /= self sets the target to 1.
  • XNOR= self produces the lowest negative number (all bits 1)
  • 11(operator)11 does some operation with the last and next values from input and outputs the result.

Extended Isolated

Extended Isolated intends to fill 16 bit characters instead of 8 bit ones. It has 4 bits for source/target so far:

Binary Description
0000
tape contents
0001
tape pointer
0010
instruction pointer
0011
input/output
0100
last target used
0101
last source used
0110
last new value used (read-only)
0111
instruction pointer delta (number of instructions IP will move after an instruction if IP is not written to; defaults to 1
1000
instruction under the IP
1001
tape pointer delta (defaults to 0)
1010
random number generator (writing to it gives a new seed, reading returns a random number)
1011
Control (Writing to this would determine how the program is operating; whether it's running or not, how it's processing IO, etc. Probably via a bitmask. Still need to think about this one)

Example programs

Note: due to the lack of an interpreter and because the specifications are somewhat ambiguous, the following programs may or may not work.

Cat program

Assuming input ends with 0. The 0 is printed as well.

binary Isolated readable Isolated pseudo-code
00000011
11000000
00111000
00111000
00000100
00000100
00000100
10001000
10111100
  cc = io
  io = cc
  cc unary= lnot
  cc unary= lnot
  cc += cc
  cc += cc
  cc += cc
  ip -= cc
  xx control= stop  
  take input
  output
  if current cell is 0
  then set it to 0

  else set it to 8

  jump by -8 (loop) or 0 (halt)  
  stop the program

Truth-machine

binary Isolated readable Isolated
00000011
11000000
10000100
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 
00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
10111100
cc = io
io = cc
ip += cc
no-op no-op no-op no-op no-op no-op no-op no-op
no-op no-op no-op no-op no-op no-op no-op no-op
no-op no-op no-op no-op no-op no-op no-op no-op
no-op no-op no-op no-op no-op no-op no-op no-op
no-op no-op no-op no-op no-op no-op no-op no-op
no-op no-op no-op no-op no-op no-op no-op no-op
stop