Commit Graph

8 Commits (68ce32a6dfa46e184362a635ffc79fab2b08e7b2)

Author SHA1 Message Date
James T. Martin 68ce32a6df
Slightly unfuck codegen for relative jumps and blocks.
Still pretty horribly broken. I was generating dispacements
backwards, failing to emit stuff like the beginning of
loops, the logic for `if` jumps was backwards, etc.
I was also completely forgetting to increment file_here
for appends. I don't remember what all I did; check the diff.
2022-10-19 12:21:46 -07:00
James T. Martin 1383484e06
No assertions fail during codegen (lang.c) for test file.
The generated executable is still incorrect
for reasons which I have not yet investigated,
but this is still a step forward.
2022-10-17 11:45:38 -07:00
James T. Martin 8808c41250
Factor out executable format handling into a new file. 2022-09-10 22:06:21 -07:00
James T. Martin d7c0eef7ae
Implemented parser! Recognition only, no output.
Also no top-level declarations or operator precedence.

The syntax is LL(1). LL syntax seems necessary because
our codegen requires emitting certain code (e.g. entering control)
prior to any codegen inside that context, whereas something like
LR would presumably parse the inner expression before recognizing
the control structure. There may be some way to work around this;
I don't know, I'm not a parsing expert.

Certain parts of the syntax are wonky, e.g. juxtaposition as
function application means a missing semicolon can give confusing
results. I suspect indentation-sensitive syntax would work
more nicely, and intend to implement it some time in the future.
2022-09-07 20:42:37 -07:00
James T. Martin 162683d63e
Hacked together a god-awful hand-written lexer. 2022-09-07 11:07:05 -07:00
James T. Martin 46640b6204
Remove gratuitous platform-specific IO.
I don't need some fancy atomic output file updating or
posix_fadvise. I removed all platform-specific code
except for a single `chmod`.

That's not to say there's no advantage to atomically
reading or writing files, but for this project, the first
rule needs to be KISS. It's premature optimization and
overengineering.
2022-09-06 23:16:23 -07:00
James T. Martin 57aa667000
Completely rewrite stack management.
Now we always use the stack instead of keeping a TOS register.
This is very inefficient, but I'll worry about register
allocation later.

The new block model is inspired by x86's `enter` and `leave`
instructions. I intend to support nested procedures at some point
in the future.
2022-09-06 19:47:46 -07:00
James T. Martin b5667c61ec
Initial commit. 2022-09-05 23:48:56 -07:00