GithubHelp home page GithubHelp logo

xchy / xsharp Goto Github PK

View Code? Open in Web Editor NEW
16.0 1.0 2.0 749 KB

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

License: GNU General Public License v3.0

C++ 94.55% CMake 0.90% C 0.08% Shell 0.06% LLVM 3.41% Python 1.00%
compiler parser cpp jvm-bytecode jvm-languages lexer runtime compilers llvm llvm-frontend

xsharp's Introduction

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 [email protected]: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

  • LLVM (optional)

    XSharp can compile XSharp code into LLVM IR, which XSharp apply LLVM15(or above) to compile and optimize to generate binary.

  • FMT

    For format printing.

  • CLI11

    For CLI argument parser.

  • Boehm GC (Temporary GC, I may develop a unique one for XSharp later)

    For garbage collection.

TODOs

  • simple OOP
  • basic types
  • complete type conversion rules
  • module
  • match pattern

Syntax

  • Variable Declaration

i32 a = 2333;
  • Function Declaration

i32 abs(i32 a)
{
    if(a >= 0)
        return a
    else
        return -a;
}
  • Class Declaration

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

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

    i32 age;
}
  • HelloWorld

void main(){
    print("Hello,World!");
}
  • Hierarchy of Source

--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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.