The Braceless v0.x Compiler
The Braceless language is a new static typed programming language which aims to offer Python v3's convenience at near native speeds (I aim to be able to compete head-on with C and C++) .
The language borrows heavily from these languages:
- Occam and Python (the basic syntax and especially the "indentation matters" principle).
- Python (the semantics, albeit I intend to clean these up considerably).
- C# (the strict semantic models and the static typing).
The languages' name,
Braceless, is a pun on the horde of braces that attack you from all sides when you want to program today. Is it really the case, that Mankind can do no better than derive from the hack C?
The language primarily focuses on adding these "new" features:
- Built-in coding standard: I simply loathe that everybody must produce their own books on how they write their code. In other words: Spaces matter, just like the indentation matters. It makes a lot of sense once you get accustomed to the idea! Half the work of a code review group erased in an instant!
- Ultra-Fast Exception Handling (I simply loathe "Zero Cost Exception Handling" because it is so extremely expensive when an exception occurs; I want my exceptions to be handled at C-like speeds).
- No global variables ever! Nothing ruins the readability of code so much as global variables. Also, they tend to be all but thread-safe and intense multi-threading is and will be the future of software.
- Complete Unicode UTF-8 and UTF-32 support from the start.
- Completely exception aware low-level run-time library from the start.
- Completely object-oriented low-level run-time library from the start.
- A beautiful systems programming language that will eventually interface seemlessly with existing C libraries (never C++).
First and foremost, I need to thank my good friend Alexandre Bencz for having pushed me forward and for having told me when I was doing things upside-down. Good friends tell you when you are wrong and Alexandre does exactly this! Thank you, Alexandre!
Second, I need to thank the author of the Cobra language, Charles G., for implicitly suggesting (by doing it himself) to use Python to write the bootstrap compiler. I have fought numerous battles with C, C++, C#, D, and Go in various attempts of writing a simple bootstrap compiler for Braceless but over the past week I've accomplished more than I ever did in those languages. Why? Because Python has all the features I need (its two drawback are that it is very slow and that it performs no static checks)!
Third, I need to thank Niklaus Wirth, then inventor of Pascal, for unintentionally having stimulated me to become interested in programming language design at the tender age of 11 years. Wirth was my childhood hero and I still think that he has contributed much more to proper software development languages than the plethora of brace-loving people out there. The biggest problem about Pascal was that it used those tedious
end pairs all over the place (and the pointer notation was pretty awkvard too). I can't but help wonder what Wirths track record had been, if Wirth had a chance to study Occam while developing his multitude of programming languages (Pascal predates Occam by 13 years).
This reminds me why I want to do Braceless at all:
- To create a beautiful, efficient, portable, and sensible programming language that makes you as productive as Python v3.x!
The purpose of this project is to write a complete bootstrap compiler for Braceless v0.x in Python v3.x.
The purpose is neither of these:
- To create the fastest, most advanced compiler ever envisioned.
- To create an advanced monster that nobody can understand or maintain.
The purposes are as follows:
- To create a working bootstrap compiler that implements Braceless v0.x and nothing more.
- To generate working executable code using the LLVM v7+ tool chain.
- To prepare for writing the actual production compiler using this bootstrap compiler.
- The compiler must be implemented in portable Python v3.x.
- The compiler must support all of Braceless v0.x.
- The compiler must generate working, usable executables from Braceless v0.x source code.
- The compiler must enforce all Braceless v0.x requirements and static checks.
- The compiler may take two days to compile a simple project, it does not matter!
- The compiler may not use overly advanced concepts or code structures: KISS!
- The compiler must implement some sort of embedded test suite for all components.
"Hello World" Sample
Just a tiny taster for how I envision the classical Hello World sample program to look in Braceless v0.x:
# The mandatory scope (namespace) of the program. scope Samples.Hello_World: # The program's entry point, which returns a value to the host environment. entry Start(system is !Braceless0.System) is cardinal: # Call the provided standard console output routine. call system.Console.Print("Hello World!") return 0
As you can see, Braceless0 is very inspired by both Python and C#, but aims to eradicate the Visual Basic thinking of the latter.
Things worth noting about the sample:
- Braceless is a purely line-oriented language. There is no backslash-at-the-end-of-the-line trick.
- Empty lines are ignored.
- Comments are statements and thus must appear on their own line (and properly indented too).
- All other statements begin with a keyword such as
- Namespaces are called "scopes" in Braceless, at least for the time being.
- Indentation is always done using tabulators, which always count for four spaces.
- The program's entry point is marked using a so-called "entry".
- The entry point must use the profile given above, no other variants will be supported.
- The entry point take a mandatory parameter,
system, that gives access to the environment.
systemargument gives access to all external features, such as disk files and terminals.
- The entry point must return an unsigned integer value, which is returned to the environment.
Hence the standard
Hello World program is a bit bulky, but Braceless is not made for sample programs, but rather for efficient, large, portable, reliable, and sound software systems. Why spend time optimizing your
Hello World sample program, when it is only going to be read and then discarded?
I'll probably forget to keep this list up-to-date, but as of 2019.03.16, these things are working mostly:
- Modules (I've only tried compiling one module at a time).
- Entries and functions.
- Return statements, whether with or without a returned expression.
- Create statements (creates a local variable), the type is not inferred at this point in time.
Things that are missing:
- Virtually everything.
- The ability to build and link an executable.
- The static type checker is very crappy right now, until I get some things fixed.
Exploring on 64-bit Windows
If you want a quick look at the current state of the compiler, take a look at
If you want to try out the compiler yourself, you need three things up front:
A Windows 64-bit installation, whether as a physical box or a virtual machine.
Git for Windows; remember to add it to your PATH somehow before you continue.
Python for Windows; remember to add it to your PATH somehow before you continue.
Braceless intentionally generates LLVM v7.x IR, not object files or executables. This is because I don't want to update binaries for a mere bootstrap compiler all the time. Also, generating LLVM IR makes many things possible in the long run, without me having to spend tons of time studying C++ interfaces and class hierarchies just to get something done.
If you want to compile the generated LLVM IR (
.ll) file into either an assembly or object file, you need to install LLVM v7.x too - and remember to add it to your path.
The compiler does not yet invoke
Clang automatically, but this feature is planned in the near future.
If you want quick results, do this after following the steps above:
cd /d %TEMP% git clone https://github.com/archfrog/Braceless0.git cd Braceless0 build compile Evergrowing.ll nano Evergrowing.s rem Hit Ctrl-X to exit nano.
Exploring on 64-bit Linux
Most Linux distros that I know of come with Git and Python v3.x preinstalled, so all you need to do is this:
# Remember to install LLVM (Clang), if not already installed. cd ~ git clone https://github.com/archfrog/Braceless0.git cd Braceless0 ./b0c.py Samples/Evergrowing.b0 clang -masm=intel -S Evergrowing.ll less Evergrowing.s # Press 'q' to quit less.
Please notice that I have not yet tested the compiler on Linux; but I have tried to prepare for that scenario.
My name is Mikael Egevig, I'm living in Herning, Denmark, and I can be contacted by email on email@example.com.
I know the documentation is sorely lacking, but the compiler is hardly able to do anything sensible just yet, so there's not much to document. As soon as I can begin to write tiny programs in Braceless0, I'll begin documenting my progress a bit more.
Feel free to open an issue on GitHub or mail me if you need help with anything related to Braceless.