It is interesting to think that 500 lines of code is something one can write in one or two days. But, writing a C compiler in 500 of comprehensible code (even in python) is challenge in itself that may take months after a few years of solid learning. I wonder if is this a good path to becoming an extremely productive developer. If some one spends time developing projects like this, but for different areas... A kernel…
> But, writing a C compiler in 500 of comprehensible code (even in python) is challenge in itself that may take months after a few years of solid learning. The people behind this project avoided that caveat by simply not implementing C. Apparently they kept a bit of the syntax but then proceeded to cherry-pick features that suited them and not make.an effort to even try to comply with any version of the standard.
Writing a C compiler in 500 lines of Python
21–30 of 183 posts
Re: Writing a C compiler in 500 lines of Python
#22It is interesting to think that 500 lines of code is something one can write in one or two days. But, writing a C compiler in 500 of comprehensible code (even in python) is challenge in itself that may take months after a few years of solid learning. I wonder if is this a good path to becoming an extremely productive developer. If some one spends time developing projects like this, but for different areas... A kernel…
Re: Writing a C compiler in 500 lines of Python
#23It is interesting to think that 500 lines of code is something one can write in one or two days. But, writing a C compiler in 500 of comprehensible code (even in python) is challenge in itself that may take months after a few years of solid learning. I wonder if is this a good path to becoming an extremely productive developer. If some one spends time developing projects like this, but for different areas... A kernel…
> 0.1 Bellard Off topic, but a log scale might be useful: 0.1 Bellard --> -10 deciBellards. That allows for: 0.001 Bellard --> -30 deciBellards. Problem: Programmers with negative productivity cannot be represented on the same log scale.
Are they a 4σ programmer, 1σ programmer, -0.5σ programmer, -2σ programmer?
Plus, most people are "average" not negative productivity, and CDFs let you use really fun stuff like Beta Distributions (variable, shapable distributions) and Gamma Distributions (exponential distributions). They're super sweet as far as probability statistics.
[1] https://en.wikipedia.org/wiki/Cumulative_distribution_functi...
[2] https://en.wikipedia.org/wiki/Probability_density_function
Re: Writing a C compiler in 500 lines of Python
#24C4x86 | 0.6K (very close)
small C (x86) | 3.1K
Ritchie's earliest struct compiler | 2.3K
v7 Unix C compiler | 10.2K
chibicc | 8.4K
Biederman's romcc | 25.0K
Re: Writing a C compiler in 500 lines of Python
#25Is there a C compiler written in Python that aims for maximum readability rather than trying to get as much done under X lines of code?
Re: Writing a C compiler in 500 lines of Python
#26For some value of “C”: > Notably, it doesn't support: > structs :-( would be possible with more code, the fundamentals were there, I just couldn't squeeze it in > enums / unions > preprocessor directives (this would probably be 500 lines by itself...) > floating point. would also be possible, the wasm_type stuff is in, again just couldn't squeeze it in > 8 byte types (long/long long or double) > some other small thin…
(Respect to the author for doing this, I just couldn’t resist the obvious joke)
Re: Writing a C compiler in 500 lines of Python
#27Just for comparison the LOCs for some other small C or C like compilers. It's not that far away from Ritchie's C4x86 | 0.6K (very close) small C (x86) | 3.1K Ritchie's earliest struct compiler | 2.3K v7 Unix C compiler | 10.2K chibicc | 8.4K Biederman's romcc | 25.0K
Re: Writing a C compiler in 500 lines of Python
#28> Instead, we'll be single-pass: code generation happens during parsing IIRC, C was specifically designed to allow single-pass compilation, right? I.e. in many languages you don't know what needs to be output without parsing the full AST, but in C, syntax directly implies semantics. I think I remember hearing this was because early computers couldn't necessarily fit the AST for an entire code file in memory at once
Compare that to, say, Rust, which would be pretty painful to single-pass compile with all the non-local behavior around traits.
Re: Writing a C compiler in 500 lines of Python
#29Just for comparison the LOCs for some other small C or C like compilers. It's not that far away from Ritchie's C4x86 | 0.6K (very close) small C (x86) | 3.1K Ritchie's earliest struct compiler | 2.3K v7 Unix C compiler | 10.2K chibicc | 8.4K Biederman's romcc | 25.0K
Re: Writing a C compiler in 500 lines of Python
#30I made similar project in TypeScript[1]. Basically multipass compiler that generates x86 assembly, compiles it to binary and runs it. The worst thing were register allocator, designing IR code and assembler. [1] https://github.com/Mati365/ts-c-compiler