Visible Whitespace

From Esolang
Jump to navigation Jump to search

Visible Whitespace is a derivative of Whitespace where all commands (which are represented by whitespace characters in Whitespace) are given a visible representation. Visible Whitespace code must be passed through a Visible Whitespace Transpiler before it can be executed by a Whitespace interpreter or compiler.

Visible Whitespace is not intended to be used as or considered to be its own language, but as an alternative representation of Whitespace code. While Visible Whitespace removes much of the frustration of visually organizing and understanding Whitespace code, the underlying intellectual challenge of writing Whitespace code, such as the stack-based paradigm, are kept intact.

In the code samples below, all Whitespace code is represented with s, t, and n replacing space, tab, and newline, respectively, in the interest of brevity and, crucially, visibility.

Number literals

To stay true to Whitespace as much as possible without being too annoying, Visible Whitespace accepts numbers in the following format:

Numbers
Lang. Sign Binary value Terminator
WS s for positive, t for negative s for 0, t for 1 \n
VWS + or - As many 0 or 1 as needed #

Any time `number` or `label` appears in the command’s declaration, they are taken to be in this notation.

Commands

IMPs
VWS WS Command
IO tn I/O
Stack s Stack manipulation
Math ts Arithmetic
Flow n Flow control
Heap tt Heap access

As with Whitespace, the output commands discard the output item after use.

IO
Command WS Meaning
IO.char_in() tn.ts Read a character and push its value to the stack.
IO.num_in() tn.tt Read a number and push its value to the stack.
IO.char_out() tn.ss Output the top of the stack as a character.
IO.num_out() tn.st Output the top of the stack as a number.
Stack
Command WS Meaning
Stack.push(number) s.s Push number to the stack.
Stack.copy() s.ns Duplicate the item on the top of the stack.
Stack.swap() s.nt Swap the top two items on the stack.
Stack.discard() s.nn Discard the top item on the stack.
Stack.copy_nth(number) s.ts(#) Get the nth item in the stack and push a copy onto the stack. (Added in WS 0.3)
Stack.slide_n(number) s.tn(#) Set aside the top item of the stack, discard the next n items, then push the top item back on. (Added in WS 0.3)
Math
Command WS Meaning
Math.plus() ts.ss Add the top 2 items on the stack and push the result.
Math.minus() ts.st Subtract the top 2 items on the stack (first pushed goes on the left) and push the result.
Math.times() ts.sn Multiply the top 2 items on the stack and push the result.
Math.divide() ts.ts Divide the top 2 items on the stack (first pushed goes on the left) and push the integer quotient.
Math.modulo() ts.tt Divide the top 2 items on the stack (first pushed goes on the left) and push the remainder.
Flow
Command WS Meaning
Flow.label(label) n.ss(#) Declare a label in the program.
Flow.call(label) n.st(#) Jump to the given label as a subroutine.
Flow.return() n.tn() End a subroutine and return to where it was called.
Flow.jump(label) n.sn(#) Unconditionally jump to a label.
Flow.if_zero(label) n.ts(#) Jump to a label if the top of the stack is 0.
Flow.if_negative(label) n.tt(#) Jump to a label if the top of the stack is negative.
Flow.halt() n.nn() Ends the program.

The Heap IMP allows storage and retrieval of data in arbitrary addresses in the Whitespace interpreter or compiler’s virtual memory.

Heap commands operate on the top two items of the stack. The first to be pushed is the address, then the second to be pushed is the value.

Heap
Command WS Meaning
Heap.set() tt.s() Store a value in an address.
Heap.get() tt.t() Retrieve a value in an address.

Visible Whitespace was first defined and transpiler implemented in Python by User:Haley Halcyon.