Inspiration

Recently my school's robotic coach approached me and lamented about the current state of Vex's programming language ecosystem, especially the lack of high-level alternatives to C or C++. RobotC, while somewhat higher level, costs $599 per license which is unaffordable to our school. So I wanted to make SuperForth, a previous project of mine which aims to solve many of the issues with C, accessible and usable with Vex for my school's robotics club.

What it does

Capote aims not only to compiler SuperForth to performant C code, but ultimately aims to make the user experience as seamless, and easy as possible. It's fully compatible with SuperForth's existing standard library, and almost every other feature save dynamic linking.

How we built it

It was built partially using SuperForth itself - the inputted code is compiled into an intermediate bytecode (that can also be run on SuperForth's virtual machine), then the bytecode is transpiled to highly efficient C-code, which is then compiled with GCC.

Challenges we ran into

Debugging and testing the compiler was especially difficult because of the lack of high-level control flow in the emitted C-code.

Another big challenge was devising how each op-code's equivalent c code was going to be like. For a while picking a C compiler was difficult because assigned gotos aren't supported by the C-standard. However, SuperForth's IL requires some form of assigned goto because one of SuperForth's core features is the anonymous function.

Accomplishments that we're proud of

Capote produces SuperFast C-code. For example, Capote-compiled SuperForth Fibonacci:

include "io.txt";
include "string.txt";
global readonly auto fib = proc (int n) return int {
    if(n <= 1) {
        return n;
    }
    return thisproc(n - 1) + thisproc(n - 2);
};
$fib(35);
println(itos(fib(45)));

Can now be executed in 10 seconds, rather than 60 seconds with vanilla SuperForth.

What we learned

I used to be the guy that would always harp about performance and raw computing power. In fact, I'm still kinda that guy, however I've now realized the importance of development speed and prototyping. If I hadn't chose to transpiled to C, and directly transpiled to some form of assembly, I wouldn't spend a day working but rather weeks, if ever. And not to mention how tedious debugging assembly output would be.

What's next for Capote

Capote will eventually be seamlessly integrated with PROS, a robot control library, to solve the problems described in Capote's inspiration. Capote may also, one day in the future, compile directly to assembly or LLVM.

JUDGES Here is the extended demonstration video.

Built With

Share this project:

Updates