A typed Chia programming language targeting CLVM bytecode.

Overview

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.

You might also like...
A low-level assembly language for the Ethereum Virtual Machine built in blazing-fast pure rust.
A low-level assembly language for the Ethereum Virtual Machine built in blazing-fast pure rust.

huff-rs • huff-rs is a Huff compiler built in rust. What is a Huff? Huff is a low-level programming language designed for developing highly optimized

STARK - SNARK recursive zero knowledge proofs, combinaison of the Winterfell library and the Circom language

STARK - SNARK recursive proofs The point of this library is to combine the SNARK and STARK computation arguments of knowledge, namely the Winterfell l

Validity is a next-generation, deduction-based language for formally verified, context-aware, autonomous & reactive smart contracts.
Validity is a next-generation, deduction-based language for formally verified, context-aware, autonomous & reactive smart contracts.

Validity Language Validity is a next-generation, deduction-based language for formally verified, context-aware, autonomous & reactive smart contracts.

An open source Rust high performance cryptocurrency trading API with support for multiple exchanges and language wrappers. written in rust(🦀) with ❤️

Les.rs - Rust Cryptocurrency Exchange Library An open source Rust high performance cryptocurrency trading API with support for multiple exchanges and

an extended polynomial identity language (PIL) in rust

powdr an extended polynomial identity language (PIL) in rust Ideas This is a random list of ideas that help designing the language. Most if this is he

An EVM low-level language that gives full control over the control flow of the smart contract.

Meplang - An EVM low-level language Meplang is a low-level programming language that produces EVM bytecode. It is designed for developers who need ful

`llm-chain` is a powerful rust crate for building chains in large language models allowing you to summarise text and complete complex tasks

llm-chain 🚀 llm-chain is a collection of Rust crates designed to help you work with Large Language Models (LLMs) more effectively. Our primary focus

An extensible and practical demonstration of constructing evm-based sandwich attacks built with ethers-rs and Huff language.
An extensible and practical demonstration of constructing evm-based sandwich attacks built with ethers-rs and Huff language.

subway-rs • Construct evm-based sandwich attacks using Rust and Huff. Getting Started subway-rs is a port of libevm's original subway, implemented wit

A fast zero-knowledge proof friendly Move language runtime environment.
A fast zero-knowledge proof friendly Move language runtime environment.

zkMove Lite zkMove Lite is a lightweight zero-knowledge proof friendly Move language virtual machine. Move bytecode is automatically "compiled" into c

Releases(0.1.1)
  • 0.1.1(Jul 6, 2024)

    What's Changed

    • Fix type guard stack order and raise in if statements by @Rigidity in https://github.com/Rigidity/rue/pull/22

    Full Changelog: https://github.com/Rigidity/rue/compare/0.1.0...0.1.1

    Source code(tar.gz)
    Source code(zip)
  • 0.1.0(Jul 6, 2024)

    What's Changed

    • Add Rust workflow by @Rigidity in https://github.com/Rigidity/rue/pull/1
    • Rework dependency graph by @Rigidity in https://github.com/Rigidity/rue/pull/2
    • Optimizations and server side rendered docs site by @Rigidity in https://github.com/Rigidity/rue/pull/3
    • Refactor by @Rigidity in https://github.com/Rigidity/rue/pull/4
    • Initial implementation of stdlib and modules by @Rigidity in https://github.com/Rigidity/rue/pull/5
    • Generic types by @Rigidity in https://github.com/Rigidity/rue/pull/6
    • Add more stdlib and examples by @Rigidity in https://github.com/Rigidity/rue/pull/7
    • Functional programming utilities by @Rigidity in https://github.com/Rigidity/rue/pull/8
    • Initial cleanup effort by @Rigidity in https://github.com/Rigidity/rue/pull/9
    • Overhaul function types by @Rigidity in https://github.com/Rigidity/rue/pull/10
    • Field guards by @Rigidity in https://github.com/Rigidity/rue/pull/11
    • Add rest and optional, and optimization by @Rigidity in https://github.com/Rigidity/rue/pull/12
    • Royalty split puzzle by @Rigidity in https://github.com/Rigidity/rue/pull/13
    • Write p2 fusion puzzle in Rue (example purposes only) by @Rigidity in https://github.com/Rigidity/rue/pull/14
    • Error messages by @Rigidity in https://github.com/Rigidity/rue/pull/15
    • Fix inline function inner definitions by @Rigidity in https://github.com/Rigidity/rue/pull/16
    • Fix recursive constant bug by @Rigidity in https://github.com/Rigidity/rue/pull/17
    • Recursive constant fix by @Rigidity in https://github.com/Rigidity/rue/pull/18
    • Mir by @Rigidity in https://github.com/Rigidity/rue/pull/19
    • Fix constant bug by @Rigidity in https://github.com/Rigidity/rue/pull/20
    • Testing by @Rigidity in https://github.com/Rigidity/rue/pull/21

    New Contributors

    • @Rigidity made their first contribution in https://github.com/Rigidity/rue/pull/1

    Full Changelog: https://github.com/Rigidity/rue/commits/0.1.0

    Source code(tar.gz)
    Source code(zip)
Owner
Rigidity
Rust enthusiast. Software Engineer at Chia Network, Inc.
Rigidity
A Minimalistic Rust library to extract all potential function selectors from EVM bytecode without source code.

EVM Hound A Minimalistic Rust library to extract all potential function selectors from EVM bytecode without source code. Installation $ cargo add evm_

null 34 Dec 3, 2023
A tool for quickly collecting function selectors and decoding signatures from on-chain EVM bytecode.

Overview | Disclaimer | Tests | Installation | Usage | Examples | Aknowledgements | License Overview Sigmund provides a CLI that allows users to colle

wavefnx 46 Jul 22, 2024
Aya is an eBPF library for the Rust programming language, built with a focus on developer experience and operability.

Aya API docs | Chat | Aya-Related Projects Overview eBPF is a technology that allows running user-supplied programs inside the Linux kernel. For more

null 1.5k Jan 6, 2023
A bitcoin vanity address generator written with the Rust programming language.

btc-vanity A bitcoin vanity address generator written with the Rust programming language. With btc-vanity you can create a private key which has a com

Emirhan TALA 22 Aug 7, 2023
Scrypto Advent Calendar. Learn the new programming langage to build quick and secure DeFi applications.

Scrypto Advent Calendar I am publishing new Christmas related Scrypto examples every day from Dec 1st to Dec 25th. "Watch" this project to get notifie

Clement Bisaillon 26 Nov 13, 2022
Emerging smart contract language for the Ethereum blockchain.

Emerging smart contract language for the Ethereum blockchain.

null 1.4k Jan 9, 2023
Zero-Knowledge Assembly language and compiler

zkAsm A Zero-Knowledge circuit assembly language, designed to represent Zero-Knowledge circuits in a compressed format, to be stored on blockchains. I

null 1 Dec 30, 2021
Noir is a domain specific language for zero knowledge proofs

The Noir Programming Language Noir is a Domain Specific Language for SNARK proving systems. It has been designed to use any ACIR compatible proving sy

null 404 Jan 1, 2023
Encrypt your files in cow language 🐄

Cow-encryptor Encrypt your files in cow language ?? Installation ?? Arch Linux ?? cow-encryptor is in the AUR yay -S cow-encryptor Other ?? ?? With ma

Skwal 2 Sep 19, 2022
Prost is a Protocol Buffers implementation for the Rust Language.

PROST! prost is a Protocol Buffers implementation for the Rust Language. prost generates simple, idiomatic Rust code from proto2 and proto3 files. Com

Tokio 2.5k Jan 8, 2023