Cubix

From Esolang
Jump to navigation Jump to search

Cubix is a stack-based 2-dimensional language where the code is wrapped around a cube.

Overview

Cubix was inspired by Labyrinth and Hexagony, both stack-based 2D languages with their own quirks.

Cubix utilizes a stack which can be populated with integers. At the beginning of the program, the stack contains infinite zeroes.

Running the code

The first thing the interpreter does is remove whitespace, then figure out the smallest cube that the code will fit onto. The code is then padded with no-ops until all six sides are filled. That means that this "Hello, World!" program:

./v.o;@?/"!dlroW"S',u/"Hello"

is exactly the same as this one:

        . / v
        . o ;
        @ ? /
  " ! d l r o W " S ' , u
  / " H e l l o " . . . .
  . . . . . . . . . . . .
        . . .
        . . .
        . . .

Then the code is run like a regular 2-dimensional language, except that the IP (instruction pointer) wraps around like the code is on a cube.

Operators

Unless specified otherwise (with "pop" or "in place"), operators do not remove their operands from the stack.

I/O

  • i - Push a single charcode from the input. If there is no more input, pushes -1.
  • I - Consume all input until a match of /-?\d+/ is found, and push that integer. If no integers are found, pushes 0.
  • A - Push a -1, then push all remaining charcodes in the input in reverse order.
  • o - Output the top item as a charcode.
  • O - Output the top item as a number.

Arithmetic

  • ( - Decrement the top item in place.
  • ) - Increment the top item in place.
  • + - Add the top two items.
  • - - Subtract the top two items.
  • * - Multiply the top two items.
  • , - Integer-divide the top two items, rounding toward 0.
  • & - Pop the top two items, concatenate their digits, and push the result.
  • n - Negate the top item in place.
  • ~ - Take bitwise NOT of the top item in place.
  • a - Take bitwise AND of the top two items.
  • b - Take bitwise OR of the top two items.
  • c - Take bitwise XOR of the top two items.

Stack manipulation

  • : - Duplicate the top item.
  • ; - Pop the top item.
  • # - Push the length of the stack.
  • s - Swap the top two items.
  • r - Rotate the top three items (push the top one down two spots).
  • q - Send the top item to the bottom.
  • t - Pop X and bring the Xth item to the top.

Literals

  • 0-9 - Push that digit.
  • ' - Push the charcode of the next char.
  • " - Start/end a string literal, performing ' on each item until the next ".
  • N - Push a newline, or 10.
  • S - Push a space, or 32.
  • Q - Push a ", or 34.

Control flow

  • . - No-op.
  • / \ - Flip the IP diagonally.
  • | - Flip the IP horizontally. No-op if the IP is traveling N or S.
  • _ - Flip the IP vertically. No-op if the IP is traveling W or E.
  • T - Flip the IP diagonally.
  • < ^ > v - Point the IP in a specific direction.
  • D - point the IP in a random direction.
  • L - Turn the IP left (90° counter-clockwise).
  • R - Turn the IP right (90° clockwise).
  • U - "U-turn" the IP to the left (90° counter-clockwise twice).
  • u - "U-turn" the IP to the right (90° clockwise twice).
  • W - "Sidestep" the IP to the left (90° counter-clockwise) before continuing in the original direction.
  • w - "Sidestep" the IP to the right (90° clockwise) before continuing in the original direction.
  • $ - Skip the next instruction.
  • ! - If the top item is non-zero, skip the next instruction.
  • ? - If the top item is negative, turn left; if it's positive, turn right; otherwise, continue straight.
  • @ - End the program.

Example programs

Example programs can be found in the online interpreter.

Links