Vitsy

Vitsy is an esoteric programming language designed by the PPCG user VTCAKAVSMoACE. It's control structure is largely linear and stores data in a stack of stacks of arbitrarily large decimals, or, more simply, a two-dimensional stack of arbitrarily large decimals. Its most common interpreters are written in Java and may be found in this GitHub repository. The Java interpreters began development in mid-October 2015 and will continue to be developed for probably all of time. More interpreters (specifically in JavaScript) based on the language (but not identical in behavior) are coming to existence thanks to PPCG users Cᴏɴᴏʀ O'Bʀɪᴇɴ, LegionMammal978, Maltysen, and RikerW.
== Overview ==
Vitsy programs are are aware of any of the following things:
* The main program (this is the program that you run) and the code thereof.
* The data held in STDIN, the input stack, and the program stack.
* The final variable, temporary variables, and objects.
* The decimal stacks.
* They may also be aware of other program files. These programs are loaded dynamically, allowing for programs to be changed mid-execution, if need be.
== Syntax ==
All Vitsy programs are composed of UTF-8 text files (extension optional, typically .vt) containing commands in the Vitsy language. A Vitsy program is organized into four main components: methods, blocks, commands, and use and ext declarations.
=== Methods ===
Methods in Vitsy are separated by newlines and indexed in array format for access. When a Vitsy program is run, the first line (or the main method) is executed. Other methods will not be run unless specified by the method command with that index of the methods. Methods retain the current state of the program stack when called, as well as knowing the current values for the final variable and the temporary variable. Methods in other programs may be called through the class method command, which will call the specified index of the methods in the specified index of the use declarations. Method calling may be recursive.
=== Blocks ===
Blocks are sections of code that are surrounded by [ (the begin block command) and ] (the end block command) commands which designate this section of code to act as though it was a single command. All blocks will continue until closed by the end block command, meaning that if the block is not terminated before the end of the method, they will return to the beginning of the current method and continue until finding their close block. Block behavior is largely dependent on what the command previous to the block is.
==== Conditional Blocks ====
Conditional blocks are blocks preceded by the if or if not commands. If the condition for the if statement is met, the block will be executed, otherwise, it will not. Conditional blocks may not be broken out of as for loops are broken from; calling the end command inside of a conditional block will cause the previous block layer to be broken out of (or, if there are no higher levels of block, the current method will terminate).
==== Repeat Blocks ====
Repeat blocks are preceded by the repeat command and are executed as though it were a single instruction, repeating the contents of the loop as many times as would be repeated for a single command. Repeat blocks may be broken out of with the end command.
==== Loop Blocks ====
If none of the previous types of blocks are found, the block is treated as a loop block, which will loop infinitely unless:
* broken out of with the end command
* the integer value of the top item of the stack is zero at the end of the block
=== Commands ===
Commands are executed one at a time (unthreaded) and may affect the current state of STDIN, STDOUT, the stack, local files (disabled in safe mode), and the system (via shell) (disabled in safe mode). A list of commands is provided below.
Command 	Name 	Description 	Known Bugs
Control Structures	 	 	
) 	if not 	Conditional execution of the next command; if the integer value top item of the stack is not equal to zero, then the next command in the method will be executed. Otherwise, it will not. If the if not command is followed by a opening square bracket, all commands within the that pair of square brackets will be conditionally executed with the same conditions as above. 	
( 	if 	Conditional execution of the next command; if the integer value top item of the stack is equal to zero, then the next command in the method will be executed. Otherwise, it will not. If the if command is followed by a opening square bracket, all commands within the that pair of square brackets will be conditionally executed with the same conditions as above. 	
[ 	begin block 	Begins a block of code. This block of code will be treated differently according to the command previous to the begin block command. If the either the if or if not command is the previous command, it will conditionally execute the block once. If the repeat command is the previous command, it will execute as many times as the top item of the stack specifies (or until broken by the end command). Otherwise, it will be executed until the top item of the stack is zero when the end block command is called (or until broken by the end command).	
] 	end block 	Ends a block of code. This is treated as a non-operational character if we are not currently in a block of code. If the block is an infinite loop block, it will exit the loop if the integer form of the top item is 0 and pop it. If the top item of the stack is not zero, it will not be popped and the position within the method will be returned to the beginning of the block. 	On empty stacks, the loop causes an ArrayOutOfBoundsException.
\ 	repeat 	Repeats the next command or block as many times as specified by the integer value of the top item of the stack. May be broken out of with the end command. 	
; 	end 	Generic end command. Not to be confused with x (exit). If end is called inside of a recursive block statement, the block is broken out of and execution is continued from the command after the block. If end is called outside of a block, it will end the current method immediately and return to the previous method (or exit, if in the main method). 	
x 	exit 	Generic exit command. The program is halted immediately with an error code as the integer representation of the top item of the stack modulo 256. 	
# 	teleport 	Teleport to the index of commands as specified by the integer value of the top item of the stack. This is mainly unsupported, and likely to be removed in future versions. 	
< 	move left 	Change the direction of the instruction pointer's movement towards the left. Moving left also informs the interpreter to wrap around to the end of the method when reaching the first command in the method. 	
> 	move right 	Change the direction of the instruction pointer's movement towards the right. While moving right, methods will finish and return back to the previous method (or terminate the program if on the main method) when the end of the method is reached. 	
" or ' 	toggle quote 	Toggle capturing of instructions as strings. As each instruction is passed, it's UTF-8 value is pushed to the current decimal stack. The quote does not end until locating another quote, wrapping around the line if it must. 	
m 	method 	Pop the integer value of the top item of the current decimal stack as n, go to index n of the methods and execute it. When it finishes, return to this point in the code and continue execution of this line. 	
Data 	 	 	
i 	input 	Pops the final item of the input stack and pushes it to the top of the current decimal stack as its decimal value. If there are no values to be popped from the input stack, -1 is pushed. 	
I 	input length 	Pushes the current length of the input stack to the top of the current decimal stack as its decimal value. 	
l 	length 	Pushes the current length of the current decimal stack to the top of the current decimal stack as its decimal value. 	
z 	get all input 	Pops all items off the input stack and pushes them in top-access order to the program stack. If there are no values to be popped from the input stack, nothing happens. 	
Z 	output the stack	Pops all items off of the current decimal stack and pushes them to STDOUT in top-access order with ISO-8859-1 encoding. 	
O 	output as char 	Pops the top item off of the current decimal stack and pushes it to STDOUT in ISO-8859-1 encoding. 	
N 	output as number	Pops the top item off of the current decimal stack and pushes it to STDOUT as a float value, using the greatest precision available. 	
W 	get STDIN 	Grabs a line from STDIN and evaluates it. If it is parseable as a decimal, it will push the decimal value to them current decimal stack. Otherwise, it will parse it as a string, pushing each character to the current decimal stack in top-access order to the program stack. 	
$ 	single switch 	Switch the top two items of the current decimal stack. If there is only one item on said stack, push a zero to accommodate. 	
% 	multi switch 	Pop the top value off the current decimal stack as n, then rotate the top n items of the stack to the right. If there aren't enough items in the stack, push zeroes to accommodate. 	Zero-filling for stack accommodation is inaccurate and throws values around wildly. Do not use multi switch on a stack with fewer values than specified with n.
=== use and ext Declarations ===
use and ext declarations exist solely for the purposes of calling methods from other programs from a Vitsy program. These declarations always appear at the end of a file, and an example can be found below.
 0K00k
 ;e program2
 ;u program3
In this program, I first push 0 to the current decimal stack, then I call K, which executes a method in the declared ext file. The ext file is declared by ;e and, in this situation, references program2. Therefore, in the first two commands, we have executed the main method of program2. 
Similarly, we declare use files with ;u. In commands 3 through 5, we push 2 zeroes, then call k, which executes a method in the specified declaration of use files. With 00k, I call the 0th index of use declarations (program3's) 0th index of methods. Therefore, we have executed the main Vitsy method of program3.
== Data Structures ==
Data is stored in various locations, some of which are read-only, some of which are neither readable nor writable until active, and some of which are readable and writeable immediately. Most data structures are stacks, but there are a few data structures aside.
=== Stacks ===
Vitsy uses multiple stacks, some of which are multi-layered and contain different values. Details for each stack type are below.
==== Program Stack ====
Vitsy is aware of all data contained in the program stack. The program stack is toroidal and consists of multiple decimal stacks. There is only one program stack per instance of Vitsy, and it may not be destroyed, but it may be modified through commands found in the Data section of the commands list. The program stack is originally instantiated with an empty decimal stack on it.
==== Decimal Stack ====
Decimal Stacks are stacks of arbitrarily large decimal values. Vitsy interacts mostly with this form of stack, and all mathematical operations are executed with values found on this stack. These stacks are toroidal and there may be many decimal stacks per program stack. Decimal stacks may be destroyed, created, and modified within the program stack through commands found in the Data section of the commands list. Each decimal stack is instantiated empty unless it is a clone of another stack.
==== Input Stack ====
String input to any Vitsy program via command line arguments which cannot be parsed as a double are placed onto the input stack. The input stack is top-access only and may only be popped from. Commands which interact with the input stack may be found under the Data section of the commands list.
==== Method Stack ====
The method stack is a trace to the currently accessed method via all the previous methods (Java style). The method stack is wholly inaccessible for information access, and is used solely for the purposes of tracing back to the place where each method was called. There is only one method stack per Vitsy instance which cannot be destroyed or modified in any fashion. The method stack is instantiated with the initial value of the main method of the main program file.
==== Class Stack ====
The class stack is a trace to the currently access program file and is closely related to the method stack, although they are wholly separate. There is only one class stack per Vitsy instance which cannot be destroyed or modified in any fashion. Current class information may be found through commands found in the Separate Program Management section of the commands list. The method stack is instantiated with the initial value of the main program file.
=== Variables ===
There are three different variable types in Vitsy - a temporary variable, a final variable, and objects. These variables are passed over methods and programs and have different behaviors as defined below.
==== Final Variable ====
The final variable may be called by the final variable command under the Data section of the commands list. When the final variable is first called, it captures the top value of the current decimal stack and retains it permanently. Any following calls to it will push its value to the current decimal stack. The final variable's value may not be dumped at any point and said final variable is passed through method calls and separate program calls.
==== Temporary Variable ====
The temporary variable may be called by the temporary variable command under the Data section of the commands list. When the temporary variable is called, it will follow one of the two following behaviors:
* If the temporary variable does not currently have a value assigned to it, it will capture the top value of the current decimal stack and save it for later use.
* If the temporary variable does currently have a value assigned to it, it will dump the value to the current decimal stack and clear its value.
The temporary variable's value may be dumped when the temporary variable command is called and said temporary variable is passed through method calls and separate program calls.
==== Objects ====
Objects are decimal stacks that have been captured and assigned to a specific character in the instructions. An object must be declared with the object command, which declares the following character as an object character (if it does not already have a meaning through commands) and promptly captures the current stack and pushes it to the object. When the declared object character is called again, it will follow one of the two following behaviors:
* If the object does not currently have a stack assigned to it, it will capture the current decimal stack save it for later use.
* If the object does currently have a stack assigned to it, it will dump the stack to the program stack, move to it, and clear its own value.
An example, as I realize this is difficult to follow:
 1234oj jN j
First, we push 1, 2, 3, and 4 to the current decimal stack. Then, we assign the character j (which does not have a command meaning) as an object, grabbing the current decimal stack and assigning the object called j's value to said decimal stack. (There are now no stacks in the program stack.) I now call j again, pushing the decimal stack found in j to the program stack. I then pop the top value and output it as a number, pushing 4 to STDOUT. I now only have 1, 2, and 3 on the stack, which I then capture again by calling j.
The objects's stack may be dumped when its declared character is called and the declared object is passed through method calls and separate program calls.
=== STDIN ===
Although not a data structure necessarily owned by the Vitsy instance, STDIN acts similarly to the input stack (but not exactly) in that each line is a separate item and all items of each line are pushed to the stack, evaluating as a decimal when possible. Calling for STDIN while executing through a command line causes the program to halt until a newline is read from the command line.
== Input/Output ==
Input and output is handled in very specific ways in Vitsy. All manners in which input is accepted or output is pushed may be found below.
=== Command Line Arguments ===
Command line arguments are accepted as a form of input for Vitsy. If all command line arguments are parseable as decimals, their values are pushed onto the initial decimal stack. Otherwise, all of the command line arguments are joined with a space and pushed onto the input stack.
=== STDIN ===
Input through standard input must be explicitly requested by the Vitsy program. When being called via the STDIN command (as found in the Data section of the commands list), a single line is pulled from STDIN, attempted to be parsed as a decimal, and then pushed to the current decimal stack. If using Vitsy through the command line, Vitsy will halt when STDIN is empty and called for new data.
=== STDOUT ===
STDOUT is the only form of output used by a given Vitsy instance for normal output types. See the Data section of the commands list for how data is output to STDOUT when calling various commands.
=== STDERR ===
STDERR is only output to whenever an error is thrown, showing information about the error and what caused it. Vitsy cannot output to STDERR without throwing an error.
== Examples ==
=== Hello, World! ===
 "!dlroW ,olleH"Z
Since quotes push items to the stack in the order in which it encounters them, the string must be pushed in reverse to allow the top-access-only outputting Z command to output everything in the right order.
=== Standard Quine ===
 'rd3*Z
Quotes wrap around a line, meaning that, with this code, we can capture all elements of the code, then reverse the stack (for order) and push the character value for ' and output everything. This is a true quine.
== Trivia ==
* Vitsy comes from a mispronunciation of the first three characters in VTCAKAVSMoACE.
* Vitsy is also referred to as "Purse Dog", Flasp, and VTC's Child.
* Vitsy is also occasionally used throughout VTCAKAVSMoACE's school by Computer Science teachers for quick calculations due to its stack-based nature and simple-to-use polish notation.
* This wiki page for Vitsy is larger in byte count than the entire compiled Vitsy jar.
== External Sources ==
GitHub repository for Vitsy (Java)
GitHub page for Vitsy (JavaScript)
Try It Online (online execution)
Category:Languages Category:Implemented