Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

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

License

NotificationsYou must be signed in to change notification settings

XChy/XSharp

Repository files navigation

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 withLLVM

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 XSharpsudo apt install llvm-15# Install toolchain for compiling XSharpsudo apt install build-essentialgit clone git@github.com:XChy/XSharp.git where/xsharp/lies/incd where/xsharp/lies/in./buildRelease.sh

Usage

#default compile into a binary executablebin/xsharpc xxx.xsharp#compile into bytecode, not supported yetbin/xsharpc -vm xxx.xsharp# compile into bytecode which can be executed by XSharp's VMbin/xsharp xxx.xe# execute the bytecode

Third-Party

  • LLVM (optional)

    XSharp can compile XSharp code into LLVM IR, whichXSharp applyLLVM15(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

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

classfoo{    i32getAge()    {return self.age;    }voidsetAge(i32 age)    {        self.age = age;    }    i32 age;}
  • HelloWorld

voidmain(){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

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp