Skip to content

vivekascoder/tiny_lang

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

158 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tiny Lang

Tiny Lang

Tiny Lang is a toy programming language.

Install

git clone https://github.com/vivekascoder/tiny_lang
cd tiny_lang
cargo install --path .

Run program

tiny_lang interpret ./examples/main.tiny

Web playground

Tiny Lang also compiles to WebAssembly, so you can write and run Tiny Lang programs directly in the browser:

tiny-lang.vivek.ink

Repl

tiny_lang repl --with (ast/lex/interpret)

Compiler

To compile the tiny program into machine code use the following command.

tiny_lang compile ./examples/main.tiny
chmod +x ./a.out
./a.out

🗒️ NOTE: Make sure you have llvm installed in your system along with clang, as we rely on llc and clang to compile.

Syntax highlighting for tiny programs

cp -r ./syntax ~/.vscode/extensions/

After restarting your VsCode, you'll have tiny lang syntax support.

Examples

/**
* calculate sum of fibonacci sequence using tiny lang.
**/

extern fun printf(s: *i8, ...) => usize;

fun fibo(num: usize) => usize {
    if (num == 0) {
        return 0;
    } else {
        if (num == 1) {
            return 1;
        } else {
            return fibo(num - 1) + fibo(num - 2);
        }
    }
}

fun main() => usize {
    printf("%d", fibo(5));
    return 0;
}
/**
* Implementation of rule 30 in tiny lang.
**/

fun main() => void {
    let state = 1 << 31;

    let i = 0;
    while (i < 32) {
        let j = 64;

        while (j > 0) {
            let condition = state >> j & 1;
            // print(condition); print('\t');
            if (condition > 0) {
                // print('O');
            } else {
                // print('X');
            }
            j = j - 1;
        }

        print('\n');
        let a = state >> 1;
        let b = state | state << 1;
        state = a ^ b;
        print(state);
        print('\n');

        i = i + 1;
    }
} 

main();

For more exmaples.

Check out the examples folder.

About

Tiny Lang is a toy programming language that runs everywhere even in browsers using WASM.

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages