Skip to content

A high level language and compiler built with rust and llvm

License

Notifications You must be signed in to change notification settings

vishruth-thimmaiah/sloppee

Repository files navigation

Sloppee

Warning

This project is a W.I.P. The functionality and features may change or be incomplete.

Warning

This Project is only tested on linux.

Tests Workflow

Installation

1. Install LLVM

If you use linux, dev tools for llvm can be installed from your package manager. For example, on Arch:

pacman -S llvm

For more information, click here

2. Install Rust

On linux:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

For more information, click here

3. Clone the repo:

git clone https://github.com/vishruth-thimmaiah/sloppee.git
cd sloppee

Build the stdlib:

cargo build --release -p stdlib

Build the compiler:

cargo build --release

The compiler executable will be located at target/release/sloppee.

Run tests:

cargo test

Usage

Run the compiler:

sloppee [COMMAND] <file> [OPTIONS]

List Commands:

sloppee --help

Syntax

Examples can be found at examples/.

hello world:

import std:io

func main() i32 {
	io:println("Hello World")
	return 0
}

Declaring Vars:

the 'let' keyword is used, followed by the type, variable name and value.

import std:io

func main() i32 {
  let i32 num = 5
  io.printint(num)
  return 0
}

variable are immutable unless declared otherwise.

Mutable Vars:

A '!' after the type makes a variable mutable.

import std:io

func main() i32 {
  let i32! num = 5
  num = 10
  io.printint(num)
  return 0
}

Math:

Basic math operations are supported.

import std:io

func main() i32 {
  let i32 num = 5
  let i64 num2 = 10
  io.printint(num+num2)
  return 0
}

In the above example, num is implicitly type casted to i64. Implicict type casts are done between two similar data types. For non similar type casts, (ex: f32 to i32) use explicict type casting.

Explicit type casting:

Use '->' for explicict type casting.

import std:io

func main() u32 {
	let f32 a = 34.1
	let u32 b = a -> u32
	
	io:printint(b)
	
	return 0
}

Conditionals:

func main() u32 {
  let u32 a = 2
  if a == 0 {
    return 1
  } else if a == 1 {
    return 2
  } else if a == 2 {
    return 3
  } else {
    return 0
  }
}

Loops:

  • An infinite Loop:
func main() u32 {
    let u32! a = 0
    loop {
        a = a + 1
        return a
    }
    return 0
}
  • A conditional Loop:
func main() u32 {
  let u32! a = 0
  loop a < 10 {
      a = a + 1
  }
  return a
}

About

A high level language and compiler built with rust and llvm

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Languages