A c-like compiled programming language for low level development.
- Type checking
- Native string implementation
- Standard library
- Self hosted compiler
- Code generation optimization
- Constant evaluation optimization
Simple program that returns with 0 exit code:
main :: () -> int {
return 0;
}
Instructions on how to get the Langin compiler up and running locally on your Linux system.
Clone the repository:
$ git clone https://github.com/proxin187/Langin
Run the tests to make sure the compiler is not broken (See Testing)
Build the compiler:
$ sudo sh build.sh
Usage: langin [FILE] [OPTIONS]
-r: run the final executable
Langin comes with tests provided to test if all the compiler features work correctly in the ./tests
folder. It is recommended to run the tests before building to compiler to be sure you have a working version of the compiler.
Run the tests with the command shown below:
$ python test.py
If all the tests ran successfully the output should look like this:
[TESTS]: successfully ran all tests in `./tests`
In the language specifications you can find the specifications for syntax, types and behavior.
A binary expression is a math expression consisting of left/right expressions and an operator such as +
, -
, *
, /
Example:
34 + 35
In Langin the order of operations is very simple, the order of execution follows a recursive pattern where recursion is always on the right side.
Example:
34 + 35 * 2 + 8 == 34 + (35 * (2 + 8)) # NOT VALID SYNTAX #
A function is a callable piece of code which can accept up to 6 arguments and can return a value back to the caller.
Example:
square :: (num1 -> int, num2 -> int) -> int {
return num1 * num2;
}
A variable is a value paired with a identifier used to reference it, variables are used to store values and have easy access to them, in Langin variables are stored localy on the stack.
Example:
let num -> int = 34 + 35;
If statements in Langin work just like in any other language consisting of a condition and a body.
Example:
let example -> int = 69;
if example != 69 {
return 420;
}
A else statement allows you to extend if statements by having a case only executed if all the previous conditions where false.
Example:
let example -> int = 69;
if example != 69 {
return 420;
} else if example == 48 {
return 88;
} else {
return 69;
}
A while loop just like if statements consists of a condition and body but what differs between them is that while loops will continue executing the body until the condition is false.
Example:
let example -> int = 0;
while example != 10 {
example = example + 1;
}
A pointer is a value pointing to a address, pointers have multiple use cases and is a core part of low level programming.
Example:
let num -> int 420;
let num_ptr -> ptr = # # reference #
In Langin pointers does not specify what type they are pointing to, this means the user will have to keep track of this when dereferencing a pointer.
Example:
let dereferenced -> int = int[num_ptr];
int[num_ptr] = 69;
Include is a keyword used to include libraries into your program, include takes a path and extends it like a macro into your program.
Example:
include "std/lib.lang"
Inline assembly is used to embed assembly into your code, inline assembly is unsafe and should only be used in developing libraries and not directly into the program, the only assembly flavor currently supported is linux-x86_64-fasm.
Example:
asm("mov rax, 1");
Type | Description |
---|---|
int |
64bit unsigned integer. |
ptr |
pointer pointing to any type. |
void |
0 bit type. |
Op | Description |
---|---|
+ |
get the sum of two values. |
- |
subtract a value from another value. |
* |
multiply a value with another value. |
/ |
divide a value with another value. |
Op | Description |
---|---|
== |
check if two values are equal. |
!= |
check if two values are unequal. |
> |
check if a value is bigger. |
< |
check if a value is smaller. |