Here it is, the first update for September. I’ve been thinking a bunch about what I want from the language and what I think I want the shape of it to be. I’ve come the following basic conclusions:
- The syntax will gently evolve from C to Proteus. We’ll take changes a few at a time while the language starts to develop.
- To ensure we’re building something real, I’ll be porting the code from Handmade Hero from C to Proteus1.
So, the last language design article had this snippet:
import stdlib let arguments = environment.arguments guard if arguments.count != 2: println "Invalid usage!"; exit -1 let filename = arguments[1] println "compiling file: {0}\n" filename guard let file = sys.io.fopen filename sys.io.flags.read: println "Unable to open file."; exit -1 guard let content = sys.io.read file: println "Unable to read the entire file."; exit -1 println "file size: {0}" file.size println "file contents: \n{0}" content
The more I played around with this style, I’m a bit concerned that there simply isn’t enough lexical information to make it easily scannable and parseable by humans. Also, I do wonder about the block distinction; I’ve gone back and forth on this. In one sense, I really like the significant whitespace, but on the other, I like the visual clarity of {
and }
; they are easier to grep while scanning quickly2.
With that in mind, the following will be the focus on the syntactical changes from C in the first iteration:
- Switch the order of type declaration
- Stub out the
import
mechanism - Remove the
;
for statement termination; it’s only used for multiple statements per line now.
Note: One other benefit of do the migrations from C to Proteus like this is the ability to convert a C file to a Proteus file (for the most part).
This means that the above sample will look like this:
import stdlib let arguments = environment.arguments guard if arguments.count != 2 { println("Invalid usage!"); exit(-1) } let filename = arguments[1] println("compiling file: {0}\n", filename) guard let file = sys.io.fopen(filename,sys.io.flags.read) { println("Unable to open file."); exit(-1) } guard let content = sys.io.read(file) { println("Unable to read the entire file."); exit(-1) } println("file size: {0}", file.size) println("file contents: \n{0}", content)
The work items over the next couple of weeks boil down to:
- Finish up the initial lexer (scanner and tokenizer are basically there already)
- Start generating executable code (the first round of output will generate C code)
- Start getting the C interop in place
Also, I’ve got a spot setup for the location of the Proteus documentation: https://owensd.io/proteus.
- Handmade Hero is currently closed source. As Proteus matures, I may look into adding an official fork in the GitHub repo. However, until that time, I’ll only talk about my experiences and show a few snippets; I will not be releasing the Proteus version of Handmade Hero until it’s officially released. ↩
-
Of course, if the starting
{
is offscreen, then the}
might not be as helpful‚Ķ I don’t know yet. ↩