sunjay / brain

A high level programming language that compiles into the brainfuck esoteric programming language

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Compiling Libraries and Linking

sunjay opened this issue · comments

In order to support libraries, we want to be able to compile brain code into a special library format akin to C/C++ object files and Rust rlib files. There should be a command line argument which compiles some code into a library and outputs a file in the library file format.

Library Format

The library file format should be well defined. It should at minimum contain:

  • A magic number or pair of numbers to differentiate it from any other binary file
  • Version number that updates if and only if there are breaking changes made to the structures that will get stored in the file
  • All public functions exposed by the library and ideally only those functions (this might lead to some bloat)
  • Type definitions for all functions in the file
  • Body definitions which are low-level enough to not take a toll on compilation but high level enough for optimization to still take place
    • In a compact binary format like msgpack
    • Parameters should be in a format that is position independent (see #16)
    • Format should be resiliant enough to not change too dramatically when things like structures and unions/enums are added
  • Debug information if at all possible

TODO:

  • Add linking stage to compiler which resolves external types for static analysis and external definitions for actual compilation and optimization
  • Precompiled prelude distributed with the compiler
  • Be able to distinguish between user code and library code for better error messages and compiler errors (don't complain about outside crate warnings)