infinitylang is a functional, statically typed programming language with a lisp syntax. It combines ahead of time compilation and type safety with the expressiveness of lisp. The infinity compiler is based on llvm.
(print "hello")infinitylang is composed of many embedded "expressions". In each layer of expression there can be many elements. In the example above, the expression has two elements in it: print and "hello".
The first element in an expression is the function and all subsequent elements are arguments.
Each element can be a sub-expression wrapping multiple elements:
(print (->S (+ 1 1))) ;prints 2Here, (+ 1 1) is an expression with three elements that evaluates to the number two. Then, the ->S element converts that to a string and print prints the string "2".
You can leave a comment with the comment syntax.
(print "hello") ; this is a commentOnly full line comments are allowed.
Each element can have a type. For example:
(def Str:greeting "hello")The Str type annotates greeting to be a string. Types can be applied to elements (Char:33) or expressions (Char:(+ 33 1)).
The current types supported are Int, Bool, Str, Array.
Curly braces denote blocks. A block can contain many expressions with elements in them. Every infinity program is actually a single block.
{
(def Str:greeting "hello")
(def Char:exclamation 33)
(append greeting exclamation)
(print greeting)
}The compiler will go down the expressions on the block one by one in order. With blocks, you can have control flow. There are two control flows currently in infinity: if and while.
(if (< 1 0) { ; if 1 < 0
(print "one is less than zero") ; then block
} {
(print "one is more than zero") ; else block
})
you can also define functions with blocks
(fun Nil:(print_greeting) {
(print "hello world")
})
(print_greeting) ; prints hello worldYou can have a collection of elements with an array.
(def Array<Int>:favorite_numbers [1 2 3])
(remove favorite_numbers 0)
(print (->S (get favorite_numbers 0))) ; prints 2Arrays are dynamically sized.
You can leave out directives for the preprocessor.
!define HELLO "hello"
{(echo HELLO)} ; prints "hello"The two preprocessing directives currently supported are !define and !import. Import reads another infinity file and combines it into the current file.
You can play with code from other languages. For example:
hello.c
void sayhello() {
puts("hello from c code");
}(extern (sayhello))
(sayhello) ; prints "hello from c code"| function name | argument types | return type | description |
|---|---|---|---|
| + | Int Int / Float Float | Int / Float | adds two numbers |
| - | Int Int / Float Float | Int / Float | subtracts two numbers |
| * | Int Int / Float Float | Int / Float | multiplies two numbers |
| / | Int Int / Float Float | Int / Float | divides two numbers |
| % | Int Int / Float Float | Int / Float | modulo operation |
| function name | argument types | return type | description |
|---|---|---|---|
| ++ | Int / Float | Int / Float | increments value by 1 |
| -- | Int / Float | Int / Float | decrements value by 1 |
| += | Int Int / Float Float | Int / Float | adds RHS to LHS and stores result |
| -= | Int Int / Float Float | Int / Float | subtracts RHS from LHS and stores result |
| inc | Int / Float | Int / Float | increments value by 1 |
| dec | Int / Float | Int / Float | decrements value by 1 |
| function name | argument types | return type | description |
|---|---|---|---|
| == | Int Int / Float Float | Bool | equality comparison |
| != | Int Int / Float Float | Bool | inequality comparison |
| > | Int Int / Float Float | Bool | greater-than comparison |
| >= | Int Int / Float Float | Bool | greater-than-or-equal comparison |
| < | Int Int / Float Float | Bool | less-than comparison |
| <= | Int Int / Float Float | Bool | less-than-or-equal comparison |
| function name | argument types | return type | description |
|---|---|---|---|
| ! | Bool | Bool | logical NOT |
| && | Bool Bool | Bool | logical AND |
| || | Bool Bool | Bool | logical OR |
| function name | argument types | return type | description |
|---|---|---|---|
| def | TypedIdentifier [Value] | Type | declares a variable (type annotation required) |
| = | Identifier Value | Type | reassigns an existing variable |
| function name | argument types | return type | description |
|---|---|---|---|
| return | none | Nil | returns from function with no value |
| return | Any | Any | returns value from function |
| function name | argument types | return type | description |
|---|---|---|---|
| Str | Nil | prints string to stdout |
| function name | argument types | return type | description |
|---|---|---|---|
| ->S | Char | Str | converts char to string |
| ->S | Int | Str | converts integer to string |
| ->S | Float | Str | converts float to string |
| ->S | Bool | Str | converts boolean to string |
| ->I | Str | Int | parses integer from string |
| function name | argument types | return type | description |
|---|---|---|---|
| array | T... | Array | creates array from elements |
| len | Array / Str | Int | returns array or string length |
| get | Array Int | T | retrieves element at index |
| set | Array Int T | Nil | sets element at index |
| function name | argument types | return type | description |
|---|---|---|---|
| append | Array T | Array | appends element to array |
| insert | Array Int T | Array | inserts element at index |
| remove | Array Int | Array | removes element at index |
| pop_back | Array | T | removes and returns last element |
make will build an infinity binary.
infinity hello.inf -o hello.ll compiles hello.inf to hello.ll.
Then, clang hello.ll -o hello will produce the hello binary.