Code Monkey home page Code Monkey logo

rue's Introduction

Rue Lang

Rue is a typed programming language which gets compiled to CLVM bytecode. It's designed to be an alternative to Chialisp for writing on-chain code for the Chia blockchain.

This is a very experimental compiler, and should not be used in production at this time. Feel free to try the examples though!

Setup

First, install Rust and clone this repository. Then from the repository root, run the following command to install the CLI:

cargo install --path crates/rue-cli

Now you can run the examples, such as:

rue hello_world.rue
rue factorial.rue

You cannot currently pass arguments to the programs, however you can also run with chia-dev-tools:

brun -x ff02ffff01ff018d48656c6c6f2c20776f726c6421ff0180 80

Compilation

There are a series of compiler passes used to construct the final CLVM output:

Source

Currently, a single file is used as the source for a Rue program. It's read into memory as a UTF-8 encoded string.

Lexer

The source text is then split into tokens by the lexer. Each token represents things such as punctuation, strings, identifiers, and keywords. This is done to improve performance and enhance error messages during the parser phase.

Parser

The hand written recursive descent parser is responsible for implementing the language's grammar. You begin top down with the whole program, then for example parse a series of functions, where each function has a parameter list, and so on. Ultimately you end up with a Concrete Syntax Tree (CST) containing your entire program broken up into meaningful segments.

AST

The CST is not ideal for processing by the compiler since it's untyped and contains tokens it doesn't care about, such as whitespace and keywords. So in this phase, the CST is transformed into an Abstract Syntax Tree (AST), which is a strongly typed representation of all of the parts of the syntax we care about in the compiler and adjacent tooling. However, you can still at any time take an AST node and get its underlying CST node for things such as error reporting.

HIR

The AST gets transformed into the HIR (high-level intermediate representation) in a couple passes. First, the symbol table is populated with function declarations. This allows you to call functions which have been defined after the code you're evaluating. Next, the functions are actually themselves evaluated, converting AST expressions into HIR nodes. Type checking, name resolution, and error reporting are done during this phase.

LIR

Once the typed HIR has been built, it is then translated to a much simpler form with all language constructs boiled down to their CLVM counterparts. This is the low-level intermediate representation. Optimizations are applied during this phase, including tree shaking (removing dead code) and expression simplification.

Codegen

Finally, you can generate CLVM from the LIR through a series of transformations and some additional optimizations can be applied at the end.

rue's People

Contributors

rigidity avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

marvinquevedo

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.