Comet Programming Language
- 3 Devlogs
- 102 Total hours
A compiled programming language written in C made for the Comet stack-based VM.
A compiled programming language written in C made for the Comet stack-based VM.
─────────────────────────────────────────
Hello again!
I’ve turned Comet into an optimizing compiler! So far we don’t have much, but Comet now has constant folding and constant propagation. But what does that actually mean?
Constant folding means we look through the code for any math expressions or other things of the like. If there are any constants in the math expression, then we can replace the expression with what it will equal.
For example:
int x = (2 + 3) * (4 + 5)
The constant folder will see (2+3), and because the expression only has constants it will replace it with 5
int x = 5 * (4 + 5)
The constant folder then sees (4+5), and replaces it with 9.
int x = 5 * 9
And finally it sees 5 * 9 and replaces it with 45.
int x = 45
We’ve turned a 7 instruction expression into 1 instruction!
Constant propogation means that if a variable stays a value that the compiler knows throughout the variable’s lifetime, then we can replace all instances of that variable with its value. For example:
int x = 2 + 3
int y = x + 3 * 2
Constant folding runs and we get
int x = 5
int y = x + 6
x is a compile time constant now, and because it never stops being a constant, we can replace all values of x with 5.
int x = 5
int y = 5 + 6
See how we can now run constant folding again now that we have more information? This is why compilers run optimizations over and over, until the code doesn’t change anymore.
─────────────────────────────────────────
Along with adding an optimizer, I’ve fixed a large bug Return statements are automatically added to functions now! Before, if you didn’t add a return statement, your function could go past where it should’ve been, crashing your program and possibly even running code it shouldn’t. That is now fixed. Comet also throws an error if you don’t include a return statement in a non-void function.
─────────────────────────────────────────
Finally, I’ve extended the docs on the Comet website. It previously only have information on everything up to loops, but now includes info on structs and arrays.
That’s all from me, see you next time!
─────────────────────────────────────────
External libraries now have the ability to define enums. With this, I’ve begun work on a socket library for fun.
─────────────────────────────────────────
In the screenshot I’ve included, I’ve got a very tiny client and server example set up where the server waits for a single connection, and then prints out what the connection sent.
I’ve got the core functions done but I’m gonna add more methods like readExact, readAll, those kinds of methods that just make your life a bit easier.
─────────────────────────────────────────
With the help of a friend, I’ve fixed a number of bugs. I also got cometc and comet to compile without any warnings, which is nice.
Some bugs where:
See you next time!
I’ve got generics, arrays, structs, inheritance, external library support, a package manager, exceptions, loops, enums, and everything else working.
My next steps are writing some of the standard library in C, after I get the language to a usable state I’m planning to bootstrap it!
When I created this project on Stardance I had already begun working on it before the competition started. I think I had already spent around 100 hours on the project. The project was originally written in LLVM, however, LLVM was quite difficult to get working, and I wanted to make progress rather than be stuck fighting with a slow piece of junk.
So I decided to rewrite the entire compiler. I created a VM and decided that the VM would be my compilation target. This made things such as exceptions possible because I would not have to worry about stack unwinding and other very complicated and difficult things.
I’ve made a huge amount of progress since then, and have gotten exceptions, external libraries, generics and structs, as well as arrays working since I created this project.
I must admit, I forgot about the devlogs until now and so this is why I’m so far ahead and creating my first devlog only now. :P
I’ll make sure to keep you guys updated though, see you soon once I get a socket running!