Code Monkey home page Code Monkey logo

mylang's Introduction

Sure, here's a simple README.md that explains the usage and features of your MyLang compiler CLI:


MyLang Compiler

MyLang Compiler is a simple compiler for MyLang, a toy programming language created for studying lexers, parsers, and compilers. MyLang is designed with limited features, including basic data types, recursive functions, and closures, while excluding loops and other complex constructs.

The compiler translates MyLang source code into LLVM Intermediate Representation (IR), enabling further compilation and execution using LLVM toolchains.

Features

  • Supports two data types: integer and boolean (along with a null type for void functions).
  • Enables the creation of recursive functions, providing a way to loop.
  • Supports closures for capturing and utilizing external variables.
  • Compiles MyLang source code into LLVM IR.

Usage

To compile a MyLang program, use the provided CLI tool.

Installation

  1. Make sure you have Python 3.x installed.

  2. Install the required packages using pip:

    pip install llvmlite
  3. Run the MyLang compiler CLI:

    python mylang_compiler_cli.py input_file.my -o output.ll

    Replace input_file.my with the path to your MyLang source code file and output.ll with the desired LLVM IR output file.

Example

Consider the following example MyLang code saved in example.mylang:

function add(a: int, b: int) -> int {
    return a + b;
}

Compile the MyLang code to LLVM IR using the MyLang Compiler:

$ python -m mylang example.mylang -o example.ll

The resulting LLVM IR will be saved in example.ll. Compile the LLVM IR to an executable using llc and clang:

$ llc example.ll
$ clang example.s -o example

If have problems with target check the target triple. I hardcoded it, but you can change it on target triple llvm-ir statement.

To get your current target triple run:

clang -print-effective-triple

Mini tutorial

mylang's People

Stargazers

 avatar

Watchers

 avatar

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.