Introduction
Welcome to the documentation for Kope, our language inspired by C and javascript and compiled in WebAssembly by our GlaDOS Project.
Getting started
To quickly get started, follow these steps:
Clone the repository.
Run `make` to build GLaDOS.
Now that we have compiled the program, we need to code our own program in kope, head up to the next part to learn how!
Hello world!
We'll start off by writing a simple hello world.
But first, we'll learn how to create a function.
fn foobar(a, b)
{
...
}
fn
tells the code that a function is being created.foobar
is the name of the function, choose whatever you want.(a, b)
are the function arguments, define them using the parenthesis, then give them a name (herea
andb
){ ... }
open the function, that's where your code will go
Functions can also return a value using the return
keyword followed by a value (example: return 4
).
Alright, now that you know how to create a function, let's introduce the main
function.
The main
function is the function that is being executed first, so if we want to write a Hello world!, then we'll have to create a main function:
main.kop
fn main()
{
print("Hello world!\n");
}
There you go, Hello world!
The print
function takes 1 argument, here a string, that is gonna be written to the screen. The \n
at the end of the string means that we want to add a new-line at after the text.
Now that we have created our main
function printing "Hello world!" to the terminal, we need to compile and run our code, head up to the next part to learn how!
Compile and run your program
Now that we have our file main.kop
, we'll have to compile it using GLaDOS
Compile using GLaDOS
Compiling is pretty straight forward, all we need to do is to give our file to the GLaDOS program and use the -c
argument
Let's compile our file main.kop
:
> ./GLaDOS -c main.kop -o main.wasm
Well done! Look, there is a new file in our directory:
> ls
main.wasm exectuable
Run using GLaDOS
Now that you have your executable, you need to use the VM in the GLaDOS program.
To do so, use this command:
> ./GLaDOS -r executable
Hello world!
Go further
You can find the main cores of this language's syntax here :
An example kope file is also included Here
Variables
To create a variable, you need to use the keyword var
and set a value. You don't need to precise the type of your variable, the language will process it and guess the type.
main.kop
fn main(argc, argv)
{
var value = 4;
print(value);
}
To learn how to compile the file, check this out!
> ./GLaDOS -r executable
4
Function that returns a value
As said on the Hello world! page, functions can return value that can be used or stored in a variable.
main.kop
fn sum(x, y)
{
return x + y;
}
fn main()
{
var x = 5;
var y = 8;
var z = sum(x, y);
print(z);
print(sum(z, x));
}
To learn how to compile the file, check this out!
> ./GLaDOS -r executable
13
18
Conditions
This language cover a various number of operators returning boolean values
a < b
less thana <= b
less than or equal toa > b
greater thanéa >=
greater than or equal to ba == b
equal toa /= b
not equal to
Their use is pretty straight forward, you can get the boolean value and store it as a variable or use it in if statements
var value = 1 == 2;
// value == false
Condition can be combined thanks to this operator:
a && b
anda || b
or
var value = 1 == 2 || true == true;
// value == true
As we said earlier, they can be use in if statements, check out next page...
If Statements
Usage of if statements is pretty straight forward and easy to use.
if (condition) {
...
};
If you'd like to see a real example
main.kop
fn main(argc, argv)
{
if (4 > 9) {
print("It is true!");
};
To learn how to compile the file, check this out!
> ./GLaDOS -r executable
It is false!
While Statements
Usage of while statements is pretty straight forward and easy to use.
while (condition) {
...
};
If you'd like to see a real example
main.kop
fn main(argc, argv)
{
var i = 0
print("Here are all digit: ")
While (i < 10) {
print(i);
print(" ");
};
To learn how to compile the file, check this out!
> ./GLaDOS -r executable
Here are all digit: 1 2 3 4 5 6 7 8 9