Tile

From Esolang
Jump to navigation Jump to search

Tile is a two-dimensional non-textual language made by User:Dtp09. Tile programs consist of a rectangular grid of "tiles", with each tile being either completely white ("empty") or containing four smaller black or white squares, referred to as "subtiles", to represent four bits of data. The data in the tiles represent instructions and other data that can be executed as the program runs.

The program counter is represented as a position on the grid, which travels in a certain direction, executing any tile it lands on as an instruction. The program counter then turns to the left, right, or goes straight, depending on the circumstances, then executes the next instruction. Programs can be thought of as a sort of path that the PC traverses, executing instruction as it moves through the path.

Specifications

Tile uses unsigned 8-bit integers. It uses an unlimited length stack, 64kb memory, an ASCII input that can be read up to 2^16 characters, and an unlimited ASCII output.

Tiles

Below is a list of every combination that a tile on the grid could have. Stack values will be referred to as s1, s2, and s3, representing the top stack value, 2nd top stack value, and 3rd top stack value respectively. If there is no value in the given stack position, it will assume 0.

[s2][s1] represents a 16 bit value, with s2 as the high byte and s1 as the low byte.

Tile Name Description
Empty Negative space, the PC cannot enter or turn here without terminating the program.
░░ No-op No operation. Mostly used for routing a path for the program counter.
░▄ Write Writes s3 to memory location [s2][s1].
▄░ Subtract Pops s1 and s2, pushes s2 - s1.
▄▄ Jump The program counter will move twice in a straight line no matter what. Useful for entering loops, joining two paths, etc.
░▀ Read Pops s1 and s2, pushes value from memory location [s2][s1] to the stack.
░█ Input Pushes the ASCII code of an input character in an index determined by 16-bit value [s2][s1].
▄▀ Multiply Pops s1 and s2, pushes s2 * s1.
▄█ Greater If s2 > s1, turn PC right. Else, turn PC left.
▀░ Push Push an 8-bit value to the stack, using the relative sides of the tile as binary data. (more below)
▀▄ Random Program counter randomly chooses one of up to three possible directions to turn that isn't an empty tile.
█░ Add Pops s1 and s2, pushes s2 + s1.
█▄ Less If s2 < s1, turn PC right. Else, turn PC left.
▀▀ Output Outputs s1 as an ASCII charater then pops it.
▀█ Equals If s2 == s1, turn PC right. Else, turn PC left.
█▀ Divide Pops s1 and s2, pushes quotient of s2 / s1, then pushes remainder.
██ Start/Debug This is where the program counter will start. During execution, it will act as a debug, printing exection info to the JS console.

Additional info

Which Tile is the Start Tile?

You can have multiple start tiles (██) in a single program. As only one tile can be the PC's initial value, it is decided as the tile furthest to the left, then the tile furthest up.

Push

Example of the Push command, where every possible way to push 0b00110101 is shown. Tiles read as data are highlighted red. No-op tiles added for readability.

The Push instruction (▀░) reads a byte of binary data from the tiles to the sides relative to the direction the PC is moving in. Binary data is read with the uppermost/leftmost tile as the upper four bits, and the bottommost/rightmost tile as the lower four bits. If there is only one (non-empty) tile on the relative side of the Push tile, it will assume a byte with the upper four bits unset. A push command with only empty tiles to its relative side will push 0.

Push commands force the PC to move straight, and cannot turn left or right.

Execution End

Execution will end if any of the following happens:

  • Program counter has too many possible places it can go: for instance, if the PC is on a NOP tile and the path can lead it either left or right, it wont choose one and instead terminate the program. Some instruction (push, less/greater/equal, random) have special rules for where the PC will go after execution and aren't affected by this rule.
  • Division by 0
  • Attempt to move program counter out of bounds
  • Attempt to move program counter onto an empty tile

Why are your programs padded with empty tiles?

It looks nicer but its not required

Code Examples

Truth Machine

Inputing 1 will crash the site because its an infinite loop.

Code URL

Hello, World!

Code URL

Nope.

Code URL

Cat

Code URL

Textile

Textile is an attempt at a textual form of tile. It uses an assembly-like syntax and has many of the same functionalities as Tile.

Interpreter

An interpreter was written in HTML+Javascript also by User:Dtp09

Save Code Format

A Save Code is a code that can be used to save and load grid data. Save Codes have been implemented since version 1.1 of the interpreter. They take the contents of the grid, put it in text form, then encode it to Base-64 text.

Decoded from Base-64, the code is stored like this:

(width);(height);(grid data)

The "grid data" refers to the tiles themselves. Each tile is stored in one byte with its contents in the lower four bits. The exception to this is Empty, which is stored as 10000, and no-op which is stored as 10001, as a zero-byte character wouldn't encode for some reason. Every tile is stored in order, filling the grid from top left to right then down a row.

Update Log

The interpreter update log is located at Tile/Update Log