TinyCompiler: A compiler in a week-end
31–40 of 120 posts
Re: TinyCompiler: A compiler in a week-end
#32Earlier quoted context omitted.
> Would you consider that to be a compiler? :-) :) No. Under my definition there needs to be some non-trivial transformation into or out of an intermediate and/or target representation (either syntax-directed directly out of the parser, or from a materialized AST). Personally I would argue that even if you trivially "compiled" to sequential bytecode, if the bytecode is then interpreted it is hard to argue that you ha…
I have written all kinds of compilers, interpreters and vms over the last 15 years. A couple of them for work. The rest for fun. Some vms used RC, others did mark-and-sweep GC. Some vms even did JIT. A lot of them were simple treewalk interpreters because the point was to play with the syntax of the language. Based on that experience, I would say your definition is more academic than realworldly as javac (or any comp…
I think it depends on how you interpret my "non-trivial transformation into or out of an intermediate and/or target representation". For example if javac involves IR, SSA based analysis and transformation (which I assume it does) then that would be a non-trivial transformation and I'd call it a compiler. If on the other hand it was a direct syntax-directed transformation to java byte code then I'd call it a translator not a compiler. But I'm not claiming any authority over definitions here. Words aren't my strong suit.
Re: TinyCompiler: A compiler in a week-end
#33Earlier quoted context omitted.
The Dragon Book is terrible as an introduction. There are better books I would probably recommend, but not to a beginner. The best "complete" intro out there today is Nystrom's Crafting Interpreters.[1] [1] https://www.craftinginterpreters.com/contents.html
> There are better books I would probably recommend I'm curious what you'd recommend. For what it's worth my goal was to compile to machine code. Anything less would have seemed insufficient. Later I got Appel's "Modern Compiler Implementation in Java" and Allen and Kennedy "Optimizing Compilers for Modern Architectures". Cooper and Torczon "Engineering a Compiler" was recommended here recently. I haven't seen it.
"Engineering a Compiler" is quite approachable.
But, once you know the basics, you get the best bang-for-the-buck by looking at source code of various compilers and virtual machines.
Re: TinyCompiler: A compiler in a week-end
#34Earlier quoted context omitted.
I have written all kinds of compilers, interpreters and vms over the last 15 years. A couple of them for work. The rest for fun. Some vms used RC, others did mark-and-sweep GC. Some vms even did JIT. A lot of them were simple treewalk interpreters because the point was to play with the syntax of the language. Based on that experience, I would say your definition is more academic than realworldly as javac (or any comp…
> javac (or any compiler targeting the JVM) is not a real compiler according to it I think it depends on how you interpret my "non-trivial transformation into or out of an intermediate and/or target representation". For example if javac involves IR, SSA based analysis and transformation (which I assume it does) then that would be a non-trivial transformation and I'd call it a compiler. If on the other hand it was a d…
Re: TinyCompiler: A compiler in a week-end
#35Earlier quoted context omitted.
I have written all kinds of compilers, interpreters and vms over the last 15 years. A couple of them for work. The rest for fun. Some vms used RC, others did mark-and-sweep GC. Some vms even did JIT. A lot of them were simple treewalk interpreters because the point was to play with the syntax of the language. Based on that experience, I would say your definition is more academic than realworldly as javac (or any comp…
> javac (or any compiler targeting the JVM) is not a real compiler according to it I think it depends on how you interpret my "non-trivial transformation into or out of an intermediate and/or target representation". For example if javac involves IR, SSA based analysis and transformation (which I assume it does) then that would be a non-trivial transformation and I'd call it a compiler. If on the other hand it was a d…
https://github.com/openjdk/jdk/blob/master/src/jdk.compiler/...
I am fairly certain that it does not. The JVM is a stack-machine.
I wrote a compiler for a simple programming language that compiled down to JVM bytecode for a project in the early 2010s. Its output for test programs was as fast as the comparative Java ones because they were fairly similar at the bytecode level.
The HotSpot JVM is where all the optimization effort is applied.
Re: TinyCompiler: A compiler in a week-end
#36Only a happy customer, but if you want an amazing experience building a compiler I highly recommend David Beazley's Compiler Course (or anything else you can sign up for) https://www.dabeaz.com/
Re: TinyCompiler: A compiler in a week-end
#37Earlier quoted context omitted.
I think OP is just trying to demystify the complexity of compliers for the sake of an educational resource. It's high quality work, compressed to a very small line count
Well, Python and Pascal were designed as a teaching language, and ended up being remarkably good for actual programming.
Re: TinyCompiler: A compiler in a week-end
#38I don't think one can understand compilers in a "week-end".
The fun part are the magic algorithms you sometimes get to use
Re: TinyCompiler: A compiler in a week-end
#39Earlier quoted context omitted.
Well, Python and Pascal were designed as a teaching language, and ended up being remarkably good for actual programming.
I didn't know this regarding Pascal, do you have any source ref on this?
"Pascal was influenced by the ALGOL W efforts, with the explicit goals of teaching programming in a structured fashion and for the development of system software.[5] A generation of students used Pascal as an introductory language in undergraduate courses."
Its grammar made it relatively easy to write compilers for the language, which could be done as undergraduate exercises. Of course, this did not make it so popular with professional programmers - see http://eprg.org/computerphile/pascal.pdf by Brian Kernighan, although extended Pascals such as Delphi were very productive in the Windows environment.