All Projects → phase → mars

phase / mars

Licence: MPL-2.0 license
Minimal language with type inference, structures, control flow, and more.

Programming Languages

kotlin
9241 projects
LLVM
166 projects
common lisp
692 projects
ANTLR
299 projects

Projects that are alternatives of or similar to mars

linux
Linux kernel source tree
Stars: ✭ 234 (+1131.58%)
Mutual labels:  llvm
homebrew-llvm
LLVM formulae for the Homebrew package manager
Stars: ✭ 23 (+21.05%)
Mutual labels:  llvm
deollvm64
deobfuscator llvm arm64 script
Stars: ✭ 67 (+252.63%)
Mutual labels:  llvm
nocc
A LLVM based self-hosting C compiler
Stars: ✭ 22 (+15.79%)
Mutual labels:  llvm
vuo
A realtime visual programming language for interactive media.
Stars: ✭ 103 (+442.11%)
Mutual labels:  llvm
geode
The Geode Programming Language
Stars: ✭ 16 (-15.79%)
Mutual labels:  llvm
TON-Compiler
Clang compiler for Free TON Virtual Machine
Stars: ✭ 56 (+194.74%)
Mutual labels:  llvm
azula
A fast, statically typed compiled language
Stars: ✭ 25 (+31.58%)
Mutual labels:  llvm
EmbedSanitizer
EmbedSantizer is a runtime race detection tool which extends ThreadSanitizer to detect data races in 32-bit ARM applications.
Stars: ✭ 16 (-15.79%)
Mutual labels:  llvm
ugo
µGo编程语言(从头开发一个迷你Go语言编译器)
Stars: ✭ 38 (+100%)
Mutual labels:  llvm
nballerina-cpp
Ballerina compiler backend that generates platform-specific executables.
Stars: ✭ 16 (-15.79%)
Mutual labels:  llvm
Dachs
Dachs; A Doggy 🐶 Programming Language
Stars: ✭ 82 (+331.58%)
Mutual labels:  llvm
mlir-standalone-template
An out-of-tree MLIR dialect template.
Stars: ✭ 44 (+131.58%)
Mutual labels:  llvm
clangbuilder
Building Clang ♡ Utility and Environment
Stars: ✭ 101 (+431.58%)
Mutual labels:  llvm
CSCD70
CSCD70 Compiler Optimization
Stars: ✭ 147 (+673.68%)
Mutual labels:  llvm
neo-c
Yet another modern compiler. It is also C compiler. Using LLVM wih boehmGC
Stars: ✭ 72 (+278.95%)
Mutual labels:  llvm
llrl
An experimental Lisp-like programming language
Stars: ✭ 126 (+563.16%)
Mutual labels:  llvm
llvm2cpg
LLVM meets Code Property Graphs
Stars: ✭ 62 (+226.32%)
Mutual labels:  llvm
contech
The Contech analysis framework provides the means for generating and analyzing task graphs that enable computer architects and programmers to gain a deeper understanding of parallel programs.
Stars: ✭ 43 (+126.32%)
Mutual labels:  llvm
tinylang
Tiny玩具语言(Go语言实现/包含Tiny编译器/CASL汇编器/COMET虚拟机/调试器/支持WebAssembly/LLVM)
Stars: ✭ 61 (+221.05%)
Mutual labels:  llvm

mars compiler

Build Status

codecov

This is a compiler written in Kotlin using an ANTLR parser. The language includes: Global variables, Functions, Classes, Methods, Automatic Memory Management, Type Inference, Calling External Functions, Modules, etc.

Here's some example syntax:

genComplexExpressionsInWhileLoop (a : Int, z : Int, y : Int, x : Int, w : Int)
    var i = 0,
    var sum = 0,
    while i < a
        var v = 42 + x,
        let u = 45 + v * 67 + 124 - (w * 4) / 5,
        v = v * 2 - z,
        var t = 1,
        if z < 10
            t = v * z
        else
            t = v - z
        ;
        let l = 74 * 3 - v + z * x - w,
        i = 5 + u * z * v + t * 2 * l
    ;
    let r = sum * i,
    r

This will be parsed into the AST and printed out as:

; Module: genComplexExpressionsInWhileLoop

; genComplexExpressionsInWhileLoop has 4 statements and a return expression.
function genComplexExpressionsInWhileLoop (a: Int, z: Int, y: Int, x: Int, w: Int) -> Int {
    ; VariableDeclarationStatement
    variable i: Int = 0
    ; VariableDeclarationStatement
    variable sum: Int = 0
    ; WhileStatement
    while (i < a) {
        ; VariableDeclarationStatement
        variable v: Int = (42 + x)
        ; VariableDeclarationStatement
        constant u: Int = (((45 + (v * 67)) + 124) - ((w * 4) / 5))
        ; VariableReassignmentStatement
        v = ((v * 2) - z)
        ; VariableDeclarationStatement
        variable t: Int = 1
        ; IfStatement
        if (z < 10) {
            ; VariableReassignmentStatement
            t = (v * z)
        }
        else if (true) {
            ; VariableReassignmentStatement
            t = (v - z)
        }
        ; VariableDeclarationStatement
        constant l: Int = ((((74 * 3) - v) + (z * x)) - w)
        ; VariableReassignmentStatement
        i = ((5 + ((u * z) * v)) + ((t * 2) * l))
    }
    ; VariableDeclarationStatement
    constant r: Int = (sum * i)
    return r    
}

(Notice the type inference: variables and return types are inferred and checked in the TypePass.)

The LLVM backend will produce something like:

; ModuleID = 'genComplexExpressionsInWhileLoop'

define i32 @genComplexExpressionsInWhileLoop(i32, i32, i32, i32, i32) {
entry:
  br label %"while.c (i < a)"

"while.c (i < a)":                                ; preds = %"if.o (z < 10)", %entry
  %i.0 = phi i32 [ 0, %entry ], [ %"((5 + ((u * z) * v)) + ((t * 2) * l))", %"if.o (z < 10)" ]
  %"(i < a)" = icmp slt i32 %i.0, %0
  br i1 %"(i < a)", label %"while.b (i < a)", label %"while.o (i < a)"

"while.b (i < a)":                                ; preds = %"while.c (i < a)"
  %v = alloca i32, align 4
  %"(42 + x)" = add i32 %3, 42
  store i32 %"(42 + x)", i32* %v, align 4
  %"(v * 67)" = mul i32 %"(42 + x)", 67
  %"((45 + (v * 67)) + 124)" = add i32 %"(v * 67)", 169
  %"(w * 4)" = shl i32 %4, 2
  %"((w * 4) / 5)" = sdiv i32 %"(w * 4)", 5
  %"(((45 + (v * 67)) + 124) - ((w * 4) / 5))" = sub i32 %"((45 + (v * 67)) + 124)", %"((w * 4) / 5)"
  %"(v * 2)" = shl i32 %"(42 + x)", 1
  %"((v * 2) - z)" = sub i32 %"(v * 2)", %1
  store i32 %"((v * 2) - z)", i32* %v, align 4
  %t = alloca i32, align 4
  store i32 1, i32* %t, align 4
  %"(z < 10)" = icmp slt i32 %1, 10
  br i1 %"(z < 10)", label %"if.t (z < 10)", label %"if.t true"

"while.o (i < a)":                                ; preds = %"while.c (i < a)"
  ret i32 0

"if.t (z < 10)":                                  ; preds = %"while.b (i < a)"
  %"(v * z)" = mul i32 %"((v * 2) - z)", %1
  store i32 %"(v * z)", i32* %t, align 4
  br label %"if.o (z < 10)"

"if.o (z < 10)":                                  ; preds = %"if.t true", %"if.t (z < 10)"
  %t8 = phi i32 [ %"(v - z)", %"if.t true" ], [ %"(v * z)", %"if.t (z < 10)" ]
  %"((74 * 3) - v)" = sub i32 222, %"((v * 2) - z)"
  %"(z * x)" = mul i32 %1, %3
  %"(((74 * 3) - v) + (z * x))" = add i32 %"((74 * 3) - v)", %"(z * x)"
  %"((((74 * 3) - v) + (z * x)) - w)" = sub i32 %"(((74 * 3) - v) + (z * x))", %4
  %"(u * z)" = mul i32 %"(((45 + (v * 67)) + 124) - ((w * 4) / 5))", %1
  %"((u * z) * v)" = mul i32 %"(u * z)", %"((v * 2) - z)"
  %"(5 + ((u * z) * v))" = add i32 %"((u * z) * v)", 5
  %"(t * 2)" = shl i32 %t8, 1
  %"((t * 2) * l)" = mul i32 %"(t * 2)", %"((((74 * 3) - v) + (z * x)) - w)"
  %"((5 + ((u * z) * v)) + ((t * 2) * l))" = add i32 %"(5 + ((u * z) * v))", %"((t * 2) * l)"
  br label %"while.c (i < a)"

"if.t true":                                      ; preds = %"while.b (i < a)"
  %"(v - z)" = sub i32 %"((v * 2) - z)", %1
  store i32 %"(v - z)", i32* %t, align 4
  br label %"if.o (z < 10)"
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].