Live data from Hacker News

TinyCompiler: A compiler in a week-end

ssloy.github.io

41–50 of 120 posts

Re: TinyCompiler: A compiler in a week-end

#42
post #35

Earlier quoted context omitted.

> 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…

> if javac involves IR, SSA based analysis and transformation (which I assume it does) 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 the…

I believe there’s some trivial optimization done by the frontend (constant folding, simplifying string concatenation, converting switch statements to lookup tables) but I think they’d agree with you that javac doesn’t really fit their definition of a compiler and that the HotSpot JIT is the true compiler based on how they talked about the Python interpreter pre-JIT.

Re: TinyCompiler: A compiler in a week-end

#43
post #39
post #37

Earlier quoted context omitted.

I didn't know this regarding Pascal, do you have any source ref on this?

From wikipedia: "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 m…

I have the greatest respect for Prof. Kernighan, but history hasn't been kind to C's unbounded arrays and strings, however convenient they may be for the programmer. Moreover, just two years after his critique, Turbo Pascal would come out with an environment that is still revered as a pioneering and exceptionally productive IDE. It outsold C compilers by multiple orders of magnitude in the mid-1980s. (And that's ignoring unlicensed copies.)

Turbo Pascal's successor, Delphi, was a successful rapid application development environment, and still being used today. Pascal was used extensively at Apple for the Apple III and Lisa, and was also the original development environment for Mac apps.[1]

But he was probably right about Ada, which has survived and may even be enjoying something of a renaissance as a fix for the sins of C (and C++) that isn't as alienating as Rust.

[1] https://archive.org/details/bitsavers_applelisapriefHistoryo...

Re: TinyCompiler: A compiler in a week-end

#44
post #39

Earlier quoted context omitted.

From wikipedia: "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 m…

I have the greatest respect for Prof. Kernighan, but history hasn't been kind to C's unbounded arrays and strings, however convenient they may be for the programmer. Moreover, just two years after his critique, Turbo Pascal would come out with an environment that is still revered as a pioneering and exceptionally productive IDE. It outsold C compilers by multiple orders of magnitude in the mid-1980s. (And that's igno…

I used to be a professional Delphi programmer, but I would not have described Delphi as "extremely successful", partially due to its mismanagement by the various owners of the IP. Its noticeable that Delphi's inventor went on to far greater success with a C-like language - C#.

Re: TinyCompiler: A compiler in a week-end

#46
post #39
post #37

Earlier quoted context omitted.

I didn't know this regarding Pascal, do you have any source ref on this?

From wikipedia: "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 m…

v nice thanks. I think Pascal was the first language we were thought in school, just before C.

Re: TinyCompiler: A compiler in a week-end

#47
post #44

Earlier quoted context omitted.

I have the greatest respect for Prof. Kernighan, but history hasn't been kind to C's unbounded arrays and strings, however convenient they may be for the programmer. Moreover, just two years after his critique, Turbo Pascal would come out with an environment that is still revered as a pioneering and exceptionally productive IDE. It outsold C compilers by multiple orders of magnitude in the mid-1980s. (And that's igno…

I used to be a professional Delphi programmer, but I would not have described Delphi as "extremely successful", partially due to its mismanagement by the various owners of the IP. Its noticeable that Delphi's inventor went on to far greater success with a C-like language - C#.

Edited. Fortunately C# (like Java) fixes what Prof. Kernighan praised about C - unbounded pointers/arrays/strings. At the expense of unpredictable performance due to garbage collection. C# and Java (and JavaScript) retain C-like syntax, but their underpinnings/VMs were heavily influenced by Self and Smalltalk. (Note Pascal also pioneered bytecode compilers.)

Re: TinyCompiler: A compiler in a week-end

#49
post #13
post #3

I don't think one can understand compilers in a "week-end".

The "week-end" part refers to the fact that I wrote it in one week-end with little to no experience in compiler design. You can check the commit history, 12 to 14 Jan, 2024 :)

I think the "week-end" reference up above was a little tongue in cheek, since the modern spelling is a compound word: https://linguix.com/english/common-mistake/week_end_hyphen

Not to take away from this awesome sharing.

Re: TinyCompiler: A compiler in a week-end

#50
post #2

I appreciate how wonderfully simple and dependency free this is. More often than not people just want to write a compiler of sorts without bison or yacc, or LLVM, and just convert expressions into assembler or vm-like instructions that _just run_. This is a great starting point for that, and I wish I had something like it 10 years ago. (Crenshaw's Let's Build a Compiler is an excellent source too if you want to go on…

Shameless plug for another relatively small compiler written in Python with no dependencies: http://cwerg.org
Post reply on HN