GithubHelp home page GithubHelp logo

plank's Introduction

Plank

This is an implementation of plank - a little programming language I am building for "Compiling methods" course.

Here is a simple guide to the language: plank-language.md.

Currently here you can find:

  • a compiler frontend that can generate plank IR
  • a few optimizations that work on IR
  • a simple interpreter that can execute IR
  • a simple compiler backend that converts IR to x86 assembly.

This repository currently consists of 9 crates:

  • plank-errors - defines Position and Span types, handles error reporting and formatting.
  • plank-syntax - defines plank AST, and contains parser for plank source code.
  • plank-frontend - validates plank programs and converts AST to intermediate representation.
  • plank-ir - defines plank intermediate representation and contains optimizations.
  • plank-interpreter - a simple virtual machine for executing plank intermediate representation.
  • plank-x86-backend - generates x86 assembly.
  • plank - driver program that glues everything together.
  • plank-server - plank language server.
  • tests - a simple program that builds and runs tests.

Examples

Here's a hello world program:

fn puts(mut string: *u8) {
    while *string != 0 {
        putc(*string);
        // this doesn't look very nice :(
        string = (string as u32 + 1) as *u8;
    }
    putc('\n');
}

fn main() -> i32 {
    puts("Hello, world!");
    return 0;
}

You can find more in examples.

Installing

Make sure that you have rust and cargo installed.

git clone https://github.com/jDomantas/plank.git
cd plank
cargo install --path plank

Editor support

If you are using Visual Studio Code, there is an extension that provides syntax highligting and displays diagnostics provided by plank language server.

You can find the extension on the VSCode extension marketplace, and you can find its code on jDomantas/plank-vscode.

You can install plank language server from this repo:

git clone https://github.com/jDomantas/plank.git
cd plank
cargo install --path plank-server

By default (I think) cargo installs binaries to a place that is on your path, so everything should work without further intervention. If for some reason that isn't the case, you can provide path to plank-server executable in vscode configuration.

Running tests

Compiler and interpreter are tested by throwing programs at them and verifying that the outcome matches the expected one. The program that is responsible for that is in tests crate. x86 backend is not tested.

You can run tests by running cargo run -p tests in repository root. More precisely, test runner expects to find the following directories:

  • ./examples - we want to make sure that the examples aren't broken
  • ./tests/compile-fail - programs that should not build
  • ./tests/pass - programs that should produce correct output when ran with given input.

Currently there are only a couple of test programs, but this will be improved over time. Or maybe not. I probably won't work on this after the semester.

plank's People

Contributors

jdomantas 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.