IRCIS

From Esolang
Jump to navigation Jump to search

IRCIS

IRCIS (I Run Chars I See) is a 2D grid-based esoteric programming language. It was built with the idea of visualization of execution flow in mind. The program structure was inspired by Befunge's grid structure with execution flow controlled by movement commands. Apart from the movement commands, the rest of the commands and workings are completely different and unique to IRCIS.

Implementation of the language along with visualizations of some programs can be found on the Github page for this program.

Command list

Cmd Description
< > ^ v Movement control
+ - * / % Arithmetic Ops in stack (in Integer mode)
# Print stack top to output
$ Print Newline
! End Processing
<space> . Blanks, Ignored
" Toggles Stack mode
' Goes to Integer mode
@<n> Push n'th index element of stack to top. @0 duplicates top
&<n> Pop n elements from stack
? Check stack top. If true then continue, else go right/left
* Split into multiple Runners
@<str> Push value in variable <str> to stack
&<str> Set value in stack top to variable <str>
r Generate a random 0 or 1 and push to stack
R Push random number between 0 and limit to stack
p Pause the Runner stack top number of ticks

Language rules

Basics and movement

  • Default/First Runner starts at the first character of the source file(0, 0) and moves right from there.
  • The source file is transformed into a rectangular grid by padding blanks and processed as such.
  • '.' (dot) and ' ' (space) characters are considered blanks and are ignored.
  • Every Runner has its own stack.
  • Runner parses and executes commands based on the character read in the position of the Runner.
  • Movement of the Runner can be controlled using the characters '>', '^', 'v' and '>'.
  • A Runner dies if it reaches the end of Grid, sees an End Processing(!) character or in the event of an error.

Printing

  • Hash(#) is used to write values to output. It pops and prints the stack top value to output.
  • Dollar($) character starts a new line in the output.

Stack operations

  • Stack push mode can be toggled with the double-quote(") character. In stack push mode, any character that comes in is pushed into the Runner stack as-is.
  • Integer mode can be used to push in integers and perform arithmetic operations. Integer mode processing starts on seeing a quote(') character.
  • Integer mode has precedence over stack mode. i.e "e'100.f In this piece of code, 'e' is pushed to stack followed by integer 100 then f. * The '.' (blank) after 100 is not pushed to stack but acts as a separator to signify the end of Integer mode.
  • Integer mode ends on seeing a blank character.
  • Arithmetic operations are done when the operator is called in Integer mode.
  • Arithmetic operations on the stack are done as: If A and B are the values on the stack, B is stack top and addition(+) is the operation called, then A and B are popped from the stack and B+A is pushed back into the stack with operands in that order.
  • The <n>'th element from the stack top can be pushed to the top of the stack by specifying <n> after the stack push '@' operator.
  • Specifying <n> after the stack pop '&' operator, pops <n> elements from the stack.

Conditional

  • Question mark(?) is used for the conditional operation. It checks if the stack top value is non-zero.
  • If the top value is non-zero, execution continues in the current direction.
  • If the top value is zero, execution can go left or right depending on which side of the '?' there is a non-blank character. (Left and right here are with respect to the Runner object.)
  • Left has higher priority if both sides have a non-blank character.

Splitting/creating more Runners

  • Star(*) character is used to create more Runner objects.
  • On seeing a star, Runners are created in every direction to the star that has a non-blank character.
  • The current Runner object continues in one of the split directions and new Runners are created if any, in other directions.
  • The new Runners have a copy of the original Runner's stack.

Variables

  • Values can be saved to a variable by specifying a name <str> for the variable after the stack pop '&' operator. Saving to a variable doesn't pop the value from the stack.
  • Values can be pushed to stack from a variable by specifying the variable name <str> after the stack push '@' operator.
  • Variables names starting with an uppercase character are global variables and lowercase are local to the Runner instance. Global variables are accessible from any Runner no matter where it was set.
  • When a split happens the local variables are copied to both Runner instances.
  • When 2 Runner instances try to write the same global variable in the same step, the value in the global variable depends on the Runner update order.

Random values and visual pause

  • 'r' operator generates a random 0 or 1 value and pushes to stack.
  • 'R' operator pops a limit value from the stack and generates a random value between 0 and limit and pushes it to stack.
  • 'p' operator pauses Runner execution stack top number of ticks. The stack top is popped.

Examples

Hello,_World!

>."!dlroW olleH"..>.#.v.
..................^...<.

FizzBuzz

>..'16..&limit..v........................................................
v..........0'...<........................................................
v.....1&..?..$..-'..timil@.0@..+'..1'..1&..<......?..galF@...<..........
..........!................................^.#.1@.<.....................
...................>.........................................^..........
...................^....................................................
>..'0..&Flag..&1...*>...'3..@1..'%..?.!.................................
...................v................>..'1.&Flag.."zziF"..####!..........
...................>...'5..@1..'%..?.!..................................
...................................>....'1.&Flag.."zzuB"..####!.........

External resources