LLVM backed progamming language (golang subset)
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.circleci
cmd/tre
compiler
pkg/fmt
.gitignore
LICENSE
README.md
codecov.yml
go.mod
go.modverify

README.md

tre

A LLVM backed Go compiler.

tre is built in Go and can compile a subset of Go code to LLVM IR. Clang is used to compile the IR to an executable.

Building

# Build tre and run a test program
go build -i github.com/zegl/tre/cmd/tre && ./tre tests/tests/fib.tre && ./output-binary

Example

Example program that calculates the fibonacci sequence.

func fib(num int) int {
    if num < 2 {
        return num
    }

    return fib(num-2) + fib(num-1)
}

func main() {
    printf("%d\n", fib(34))
}

More examples of what's possible can be found in the compiler testdata.

Features

Types

  • int (all signed types)
  • string
  • struct
  • array
  • slice
  • map
  • bool
  • func

Language features

  • Functions
    • Named functions
    • Methods
    • More than 1 return variable
    • First class functions: Assign a function to a variable, functions as arguments etc.
  • Strings
  • Arrays
  • Builtin functions
    • println (to be removed)
    • printf (to be removed)
    • exit (to be removed)
    • len (string, array, slice) TODO: Maps
    • cap (slice)
    • append (slice)
  • Packages
  • Methods
  • Pointers
  • Interfaces
    • Empty interfaces
    • Values receiver methods
    • Pointer receiver methods

Dependencies