Skip to content

Latest commit

 

History

History
202 lines (139 loc) · 11 KB

LANGUAGE.md

File metadata and controls

202 lines (139 loc) · 11 KB

vilmos Language Specification

Table of Contents

  1. Introduction
    1. Idea
    2. Instructions
    3. Types
    4. Memory
    5. Errors
  2. Instructions list
    1. I/O
    2. Arithmetic operators
    3. Logical operators
    4. Bitwise operators
    5. Stack operations
    6. Control flow
    7. File management
    8. Miscellaneous
  3. Insert data in memory

Introduction

Idea

vilmos is an interpreted programming language that uses colors and pictures instead of code. Its name is a tribute to the Hungarian painter Vilmos Huszár. Some of his most famous paintings
rapresent blocky shapes, just like the pixels/squares needed to write vilmos programs.

Composition - Vilmos Huszár

Back to top

Instructions

In a vilmos program, instructions are rapresented by squares of the same dimensions. The minimum acceptable dimension is a single pixel. There is not a maximum dimension limit.

The instructions are executed starting from the upper-left corner to the lower-right corner, but of course they can also
be all on the same row.

NOTICE: An instruction, in vilmos, must match perfectly with the relative color code so a program must be a .png image. In this way there will be no quality loss.

Instruction set is strongly inspired by SuperStack! one.

Execution order example

exec-order-alt

Back to top

Types

vilmos supports following two data types:

  • int: a 32-bit signed integer [-2147483648 to 2147483647]
  • string: a sequence of ASCII characters with \0 delimiter at the beginning of the string

Memory

vilmos is a stack-based language, so the memory is rapresented by a stack (a little bit "stronger" than a classic
one thanks to some powerful and useful operations provided by the language out of the box).

By default, memory has no maximum limit (it only depends to your device memory). This can be changed setting a maximum stack size while using official interpreter.

Back to top

Errors

If your vilmos painting encounters an error during runtime, the execution will be immediately stopped.

If you are using the official interpreter, when the execution is stopped, it will also be displayed an error
message that describes what happened. This can be avoided by using the debugger tool provided out of the box by the interpreter.

Back to top

Instructions List

I/O

Instruction Description Color code Color preview
INPUT_INT Gets value from stdio as number and pushes it into the stack. If a file is opened,this instruction will read content from it and pushes all the characters in the file into the stack. #ffffff #ffffff
INPUT_ASCII Gets values as ASCII char of a string and puts them into the stack. If a file is opened,this instruction will read content from it and pushes all the characters in the file into the stack. #e3e3e3 #e3e3e3
OUTPUT_INT Pops the top of the stack and outputs it as number. If a file is opened,this instruction will write values into the file as integers and not in stdout. #000001 #000001
OUTPUT_ASCII Pops the top of the stack and outputs it as ASCII char. If a file is opened,this instruction will write into the file as ASCII chars and not in stdout. #4b4b4b #4b4b4b

Back to top

Arithmetic operators

Instruction Description Color code Color preview
SUM Pops two numbers, adds them and pushes the result in the stack #00ced1 #00ced1
SUB Pops two numbers, subtracts them and pushes the result in the stack #ffa500 #ffa500
DIV Pops two numbers, divides them and pushes the result in the stack #8a2be2 #8a2be2
MUL Pops two numbers, multiplies them and pushes the result in the stack #8b0000 #8b0000
MOD Pops two numbers, and pushes the result of the modulus in the stack #ffdab9 #ffdab9

Back to top

Logical operators

Instruction Description Color code Color preview
AND Pops two numbers, and pushes the result of AND [0 is false, anything else is true] [pushes 1 if true or 0 is false] #ecf3dc #ecf3dc
OR Pops two numbers, and pushes the result of OR [0 is false, anything else is true] [pushes 1 if true or 0 is false] #b7c6e6 #b7c6e6
XOR Pops two numbers, and pushes the result of XOR [0 is false, anything else is true] [pushes 1 if true or 0 is false] #f5e3d7 #f5e3d7
NAND Pops two numbers, and pushes the result of NAND [0 is false, anything else is true] [pushes 1 if true or 0 is false] #e1d3ef #e1d3ef
NOT Pops one number, and pushes the result of NOT [0 is false, anything else is true] [pushes 1 if true or 0 is false] #ff9aa2 #ff9aa2

Back to top

Bitwise operators

Instruction Description Color code Color preview
BAND Pops two numbers, and pushes the result of their bitwise AND #8aa399 #8aa399
BOR Pops two numbers, and pushes the result of their bitwise OR #7d84b2 #7d84b2
BXOR Pops two numbers, and pushes the result of their bitwise XOR #8fa6cb #8fa6cb
BNOT Pops one number, and pushes the result of its bitwise NOT #dbf4a7 #dbf4a7
RSHIFT Pops two numbers, and pushes the result of the second >> the first #439dba #439dba
LSHIFT Pops two numbers, and pushes the result of the second << the first #2d6a7d #2d6a7d

Back to top

Stack operations

Instruction Description Color code Color preview
POP Pops one element, and discardes it #cc9e06 #cc9e06
SWAP Swaps the top two elements in the stack #ffbd4a #ffbd4a
CYCLE Cycles clockwise the stack of one position #e37f9d #e37f9d
RCYCLE Cycles counterclockwise the stack of one position #e994ae #e994ae
DUP Duplicates the top of the stack #006994 #006994
REVERSE Reverses the content of the stack #a5a58d #a5a58d

Back to top

Control flow

Instruction Description Color code Color preview
WHILE Enters in a while loop: if the top element is true loop, else exits while loop. It doesn't pop the element. #2e1a47 #2e1a47
WHILE_END Ends while loop #68478d #68478d
QUIT Terminates program execution #b7e4c7 #b7e4c7

Back to top

File management

Instruction Description Color code Color preview
FILE_OPEN Opens the file using the last string in the stack as path. The string is popped from the stack. While the file is open, INPUT_ASCII and INPUT_INT instructions will read all the file content and push each char into the stack. While the file is open, OUTPUT_INT and OUTPUT_ASCII instructions will write into the file. If the file doesn't exists, it will be created. An opened file is in read-write append mode. Only one file can be opened at a time. #91f68b #91f68b
FILE_CLOSE Closes the currently opened file. INPUT_ASCII, OUTPUT_ASCII, INPUT_INT and INPUT_ASCII will return to their standard behaviour. #2fed23 #2fed23

Back to top

Miscellaneous

Instruction Description Color code Color preview
RND Pops one number, and pushes in the stack a random number between [0, n[ where n is the number popped #008000 #008000

Back to top

Insert data in memory

vilmos supports the possibility to insert into the stack integers and strings directly from the given image.

When an operation square is encountered and its color code doesn't match with any of the default/custom color codes
defined, the sum of red, green and yellow operation square's value is pushed into the memory.

NOTICE: When pushing a string into the stack, remember to insert at the beginning of the string the \0 delimiter (rapresented by #000000 RGB value) Thanks to this delimiter it is possible to have in memory multiple strings and integers at the same time. It is also possible to insert a single char, but remember to insert the delimeter!

Example program that inserts 100 in memory and outputs it:

insert-int-alt

Example program that inserts 'vilmos' string in memory and outputs it:

insert-string-alt

Have fun painting coding

Back to top