Skip to content
/ mulang Public

Micro Language: A toy language for mere compiler engineering mortals.

License

Notifications You must be signed in to change notification settings

plotfi/mulang

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

µ-lang

A language just for fun.

The grammar was orignally taken from a C grammer at https://www.lysator.liu.se/c but has since been heavily modified. The only C parts left are mostly from the lexer and from the binary expression parsing.

Mulang depends on LLVM and MLIR as well as Flex and Bison.

The Mu (muc) compiler uses MLIR.

Syntax

typealias int = int32;

// interative fib function. No arrays so no memoization yet.
fn fibonacci(n: int) -> int {

  if n < 2 {
    return n;
  }

  var prev: int = 0;
  var current: int = 1;
  var i: int = 2;

  /*
     To Keep the language simple, while loops are the only kind of loops.
     Theres also no increment operator since using x = x + 1 does the same job.
  */ 
  while i <= n {
    var next: int = prev + current;
    prev = current;
    current = next;
    i = i + 1;
  }

  return current;
}

fn main() -> int {
  var fib: int = fibonacci(5);

  // Still have no idea how I will make strings or printing work.
  _ = printf("fibonacci of 5 is: %d\n", fib);

  return 0;
}

Build Steps

First, build LLVM like so:

mkdir ~/opt/dev   # I like to develop projects here
git clone https://github.com/llvm/llvm-project
cd llvm-project

cmake -GNinja -DCMAKE_BUILD_TYPE=Release \
              -DLLVM_ENABLE_ASSERTIONS=ON \
              -DLLVM_BUILD_EXAMPLES=ON \
              -DLLVM_TARGETS_TO_BUILD="Native" \
              -DLLVM_ENABLE_PROJECTS="clang;mlir" \
              -DLLVM_INSTALL_UTILS=ON \
              -B./build \
              -DCMAKE_INSTALL_PREFIX=./destdir \
              ./llvm

ninja -C ./build
ninja -C ./build install

Next, checkout mulang and build like so:

cd ~/opt/dev
git clone https://github.com/plotfi/mulang

export LLVM_DIR=$HOME/opt/dev/llvm-project
make

About

Micro Language: A toy language for mere compiler engineering mortals.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published