HNHacker News
TopNewBestAskShowJobs

alexfru

11 karma · joined October 14, 2017

submissionscomments
alexfru··on Local Register Allocator for 8086
bp isn't managed by the allocator precisely to make bp available for local variables.
alexfru··on SmallerC – Small, Simple, Self-Compiling, Single Pass C Compiler
It's less complete in terms of the language and needs less memory. smlrc.c runs in 96KB of RAM on a PIC32 MIPS microcontroller.
alexfru··on SmallerC – Small, Simple, Self-Compiling, Single Pass C Compiler
Going 64-bit is quite a bit of work:

- additional 64-bit types will need additional code for type checks and conversions, switch, etc

- new or improved code generator is needed (ideally, 64-bit non-pointer types should also be supported in 32-bit programs, possibly as register pairs)

- new object and executable formats to handle

- possibly new ABIs to support (pushing arguments onto the stack and never bothering to align the stack pointer onto a multiple of 8 or 16 boundary is kinda easy, it's pretty much free)

And the above work hasn't been done.

alexfru··on SmallerC – Small, Simple, Self-Compiling, Single Pass C Compiler
Yeah, a fifth name appears in the macos branch. :) Not sure if github will show the name when macos is merged into master.

I wanted something small and easily self-hosting. A compiler on a floppy (as in old times). I hope you guys know what floppies are. :)

smlrc.c runs in 96KB on a PIC32 MIPS microcontroller.

LLVM is big and if I don't implement enough of the language (and I hear LLVM is s written in C++, not C), I can't recompile LLVM.

I can write an assembler. Or I can use FASM, which is self-hosting, if I can't compile NASM or YASM.

alexfru··on SmallerC – Small, Simple, Self-Compiling, Single Pass C Compiler
If you haven't used flex & bison and you're writing your first compiler, you need to learn them and still take care of the things they don't do for you out of the box (they don't know C and the context of the input).

IOW, it looks like the hardest work may still be up to you, but now you're dependent on external tools and self-hosting has become a bit questionable/problematic (you'd want those tools to be compiled by your compiler as well, right?).

Parsing tokens, OTOH, isn't a big deal. You don't need heavy artillery for them.

IOW, if you haven't had lots of experience with those tools or compiler creation already, you may not gain much from using them for the first time. If you have, you may reuse your experience and possibly even code.