Writing a C compiler in 500 lines of Python
1–10 of 183 posts
Re: Writing a C compiler in 500 lines of Python
#2Re: Writing a C compiler in 500 lines of Python
#3https://www.blackhat.com/presentations/win-usa-04/bh-win-04-...
(minus directly emitting opcodes, and fitting into 500 lines, of course.)
Re: Writing a C compiler in 500 lines of Python
#4Re: Writing a C compiler in 500 lines of Python
#5Finally, one can have inefficient C.
https://root.cern.ch/root/html534/guides/users-guide/CINT.ht...
Re: Writing a C compiler in 500 lines of Python
#6IIRC, 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
Re: Writing a C compiler in 500 lines of Python
#7I 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, a compressor, renderer, multimedia/network stack, IA/ML... Will that turn a good dev into a 0.1 Bellard?
Re: Writing a C compiler in 500 lines of Python
#8Re: Writing a C compiler in 500 lines of Python
#9Re: Writing a C compiler in 500 lines of Python
#10> 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
It explains the memory limits and what happened :)
> After the TMG version of B was working, Thompson rewrote B in itself (a bootstrapping step). During development, he continually struggled against memory limitations: each language addition inflated the compiler so it could barely fit, but each rewrite taking advantage of the feature reduced its size. For example, B introduced generalized assignment operators, using x=+y to add y to x. The notation came from Algol 68 [Wijngaarden 75] via McIlroy, who had incorporated it into his version of TMG. (In B and early C, the operator was spelled =+ instead of += ; this mistake, repaired in 1976, was induced by a seductively easy way of handling the first form in B's lexical analyzer.)