Tox is a small programming language designed to run on a Virtual Machine. The Virtual Machine executable is located in vm/. This programming language was built using the library ply.
Note: The Virtual Machine was developed by students at the University of Minho, Portugal.I did not develop the Virtual Machine, I only developed the programming language. To learn more about the Virtual Machine, please refer to the zip file vms-vf.zip in the vm/ directory. Also note that I made some modifications to the Virtual Machine in order to make it compatible with the Virtual Machine at EWVM. Those modifications include:
- Adding a new instructions to the Virtual Machine (
AND,OR). - Improving the memory consumption of the Virtual Machine by reducing the number of memory leaks.
Installing through pip:
git clone https://github.com/fabiocfabini/tox.git
cd tox
make installNote: Only works on linux.
tox run examples/hello_world.toxTo add one line comments, simply type // followed by the comment. For example:
// This is a commentMultiline comments can be added by typing /* followed by the comment and */ at the end. For example:
/*
This is a multiline comment
*/Has of now, the language supports the following data types:
int,float,string: These are the basic data types of the language;&int,&float,&string: These are the pointer data types of the language;- vec
<int>, vec<float>, vec<string>: These are the vector data types of the language;
Basic arithmetics are supported by the language. These include:
- the
+,-,*,/operators; - the
==,!=,<,>,<=,>=operators; - the
&&,||operators; - the
!operator;
Tox also supports pointer arithmetics. The following operations are supported:
+adds an integer to a pointer;-subtracts an integer from a pointer and returns the difference between two pointers;>,<,>=,<=compares two pointers;
To declare a variable, simply type the variable name followed by : and the variable type. For example:
a: intVariables declared in this way are initialized with the value 0. To declare a variable and initialize it with a value, simply type the variable name followed by : and the variable type followed by = and the value. For example:
a: int = 10To modify the value of a variable, simply type the variable name followed by = and the value. For example:
a = 20To typecast a variable, simply prefix the variable name with the type you want to typecast it to. For example:
a: int = 10
b: float = (float) aIn tox arrays are declared in 3 different ways:
- Declaring an array of a specific size. This will initialize the array with the value
0;
a: vec<int>[10]- Declaring an array through a list of values;
a: vec<int> = [10, 20, 30, 40, 50]- Declaring an array with the
...operator;
a: vec<int> = [1 ... 10]This will initialize the array with the values 1, 2, 3, 4, 5, 6, 7, 8, 9, 10.
To access an array element, simply type the array name followed by [ and the index of the element followed by ]. For example:
a[0]The control flow of the language is similar to the control flow of C. These include:
if,if elseandif else ifstatements;
if expression {
// code
}
// or
if expression {
// code
} else {
// code
}
// or
if expression {
// code
} else if expression {
// code
} else {
// code
}whilestatements;
while expression {
// code
}do whilestatements;
do {
// code
} while(expression)forstatements;
for(i: int = 0; i < 10; i = i + 1) {
// code
}To declare a function start with the key word func followed by the function name, the function parameters and the function return type. For example:
func sum(a: int, b: int) -> int {
return a + b
}To call a function, simply type the function name followed by the function parameters. For example:
sum(10, 20)