Home

Awesome

XSharp

A toy OOP language with lexer, parser, compiler and runtime

Not completed yet, and your contributions are highly appreciated

Background

Having learned about the theory of compiler, a dull coder try to develop something to have fun.

XSharp is compiled into the byte codes,and then run in a XSharp runtime environment.

Also it provide a way to generate native binary with LLVM

Install

This project can be built with CMake

Input the command below in to build XSharp Compiler in your computer(Only support Linux now)

# Install LLVM dependencies for XSharp
sudo apt install llvm-15

# Install toolchain for compiling XSharp
sudo apt install build-essential

git clone git@github.com:XChy/XSharp.git where/xsharp/lies/in

cd where/xsharp/lies/in
./buildRelease.sh

Usage

#default compile into a binary executable
bin/xsharpc xxx.xsharp

#compile into bytecode, not supported yet
bin/xsharpc -vm xxx.xsharp # compile into bytecode which can be executed by XSharp's VM
bin/xsharp xxx.xe          # execute the bytecode

Third-Party

TODOs

Syntax

i32 a = 2333;
i32 abs(i32 a)
{
    if(a >= 0)
        return a
    else
        return -a;
}

class foo
{
    i32 getAge()
    {
        return self.age;
    }

    void setAge(i32 age)
    {
        self.age = age;
    }

    i32 age;
}


void main(){
    print("Hello,World!");
}

--XSharp
 |
 |- XSharp      # Main code of XSharp (Lexer, Parser)
 |- XSharpRuntime # Runtime for X#
 |- XSharpCLI   # Command-line Interface (xsharpc)
 |-
 |- LLVMIR      # Impliment AOT for xsharpc
 |- test        # Test driver