4 ms·
In a similar vein: tcc, the Tiny C Compiler: http://www.bellard.org/tcc/ http://www.bellard.org/tcc/ 34 kLOC instead of 7, and no fancy VM/kernel stuff, but i
by lisper 10y ago
In a similar vein: tcc, the Tiny C Compiler:
http://www.bellard.org/tcc/ http://www.bellard.org/tcc/
34 kLOC instead of 7, and no fancy VM/kernel stuff, but it does full C99.
- tptacek 10y agoEven more impressive (to my way of thinking) is c4: https://github.com/rswier/c4/blob/master/c4.c https://github.com/rswier/c4/blob/master/c4.c c4 is what you might call a microscopic C compiler; it's surprising how much it does for the code it has.
- dzdt 10y agoC4 handles a similar subset of C to what selfie does, but is a full order of magnitude smaller : about 600 lines. And it is very readable despite the terseness!
- pvg 10y agoThere's a bunch of other stuff in Selfie beyond the C compiler so you can't really compare them by line count.
- rswier 10y agoc4.c author here - selfie seems to fill a niche between c4 and my other more full featured compiler/os swieros. Very cool! https://github.com/rswier/swieros/blob/master/00README.txt https://github.com/rswier/swieros/blob/master/00README.txt
- pvg 10y agoYep, I just meant to point out they're different. Selfie is something educators wrote for their purposes. c4.c is more like a piece of code poetry.
- vidarh 10y agoOne thing I love is how it reads the whole source file into RAM and operates on it as an array. So many compilers (including my own...) avoid this, which I guess ostensibly lets them handle huge machine generated source files (but that's an extreme outlier, and really I'd be inclined to let people depending on that use something else or work around it). The first compiler I saw that didn't was Wouter van Oortsmerssen's AmigaE compiler [1], which demonstrated that it was a viable strategy even when your compiler is expected to run on a machine with 512KB RAM. It's one example of where we often over-abstract for dubious benefits. [1] http://strlen.com/amiga-e http://strlen.com/amiga-e
- masklinn 10y agoOn a machine with virtual memory couldn't it fix the source size issue by mmaping instead of reading it into ram, and leting the OS page it in/out of memory?
- vidarh 10y agoYes, that should work, as long as you make sure to ensure it gets zero terminated so you don't have to do length checks all over the place - that'd lose a lot of the benefit. For files that are not a multiple of the page sizze that's guaranteed. I've never tried to request mapping of more bytes than a file takes, though... I'm going to guess that still does something sane, but I've not tested it.
- masklinn 10y ago> I've never tried to request mapping of more bytes than a file takes, though... I'm going to guess that still does something sane, but I've not tested it. Sadly, the Opengroup and Linux man pages say that > Memory access within the mapping but beyond the current end of the underlying objects may result in SIGBUS signals being sent to the process.
- vidarh 10y agoJoy... Oh, well, I think on modern systems it'd be reasonable to just refuse to deal with source files that are too large to load into RAM, and leave it at that.
- Meegul 10y agoThat's mind-boggling to me. My lisp interpreter is hardly shorter than that, granted it was designed with extensibility as a goal. Still, incredible.
- nickpsecurity 10y agoYeah, but wasn't TCC designed to be the opposite of easy to understand? It was entered into the obfuscated, C contest. I'll leave it to a C coder to tell me if TCC and Selfie are in same ballpark on amateur comprehension.
- lisper 10y agoWhy don't you look at the code and decide for yourself?
- nickpsecurity 10y agoBrain injury. Forgot C & ASM minus tiny fragments. Still haven't relearned them. Getting close to time to do that again, though. A subset at least.
- noam87 10y agoHi, have you written about your experience programming after a brain injury?
- nickpsecurity 10y agoI might once I do it. I remember enough fragments of what worked and didn't to do my R&D at a high-level just above the actual implementation. I'm seeing so many opportunities in a number of paradigms I've had a really hard time committing to which I'll start with. Given it will be a slog of a process... I might do a write-up if I do. I did code a problem or two afterward. Reusing principles from high-assurance systems and security helped. Keep design, language, & implementation simple. Straightforward control flow with no looping between layers. Safe language. Straight-forward toolchain. I ended up doing those problems in a subset of FreeBASIC since I was up and running so fast w/ no fighting with IDE's, etc. Solutions came out correct in first implementation due to design principles & refactoring specs on paper. Coding phase simply didn't have much room for added error.
- vidarh 10y ago