Skip to content

jiangyinzuo/rc

Repository files navigation

The RC Programing Language

build codecov

A rust-like toy language written in Rust. Available target is riscv32im.

Quick Start

Installation

Hello, World!

Create a file named foo.rc.

// File name: foo.rc
extern "C" {
    fn putchar(c: i32);
}

fn add10(x: i32) -> i32 {
    x + 10
}

pub fn main() -> i32 {
    putchar(103 + 1); // 'h'
    putchar(101); // 'e'
    let mut i = 0;
    while i < 2 {
        putchar(108); // 'l' 'l'
        i += 1;
    }
    putchar(333 / 3i32); // 'o'
    putchar(10); // '\n'
    0
}

Compile foo.rc to RISC-V assembly language.

$ ./rcc foo.rc -o foo.S

Assemble and link to executable file.

$ riscv64-unknown-elf-gcc -march=rv32im -mabi=ilp32 foo.S -o foo

Run in QEMU

$ qemu-riscv32 ./foo
hello

References

About

A rust-like toy programing language.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages