Giter Club home page Giter Club logo

proto's Introduction

Proto

Proto (for prototype and primitive) is a single-file programming language that I will be using as I play with different parts of a compiler and programming languages concepts.

This repo contains the reference implementation using an interpreter. As things progress, I will create different backends using bytecode, a JIT compiler (that can either ouput bytecode or assembly code), and of course just generate assembly for a particular machine.

That's the general plan thus far but initially, with the interpreter, the goal is to first gain a better understanding of the choices existing programming languages have made, why those choices were made, and compare them.

What a Proto program looks like

Here is a program that calculates the n-th Fibonnaci number.

fib : function(n: const int) -> int {
    t1:     int = 1
    t2:     int = 0
    result: int = 0

    for (i: int = 0; i < n; i += 1) {
        t2      = result
        result  = t1
        t1      = t1 + t2
    }

    return result
}

main : function() -> int {
    println(fib(92))
    return 0
}

Testing

Make sure bazel is installed. Instructions can be found at https://bazel.build/install/bazelisk.

All tests are under the tests folder. Each subfolder contains tests for a particular module of the interpreter.

To run all tests:

bazel test --test_output=all //tests/...

To run tests for a specific module of the interpreter, e.g. the parser:

bazel test --test_output=all //tests/parser:parser_test

Building

To generate the main binary for the interpreter:

bazel build //src:main

Note for Windows: after installing Bazel, remember to change the options in .bazelrc to use Windows syntax of forward slashes and colons to pass options to the compiler.

Running

In the file fibonnaci.pro, there is a sample program that calculates the n-th Fibonacci number.

It exercises almost all of the parts of the language already implemented.

To run the interpreter:

bazel-bin/sr/main program.pro

Where program.pro is the file containing your Proto code. Or in this case replace program.pro with fibonnaci.pro.

proto's People

Contributors

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