News for hackers. Stuff that matters.
Re:Nim compiler — Pascal source code by pjmlp on Sunday November 29, 2020 @07:45AM (#25244844)
No it doesn't. That isn't the official source code of Turbo Pascal.

"Because of my interest in Pascal programming language and compilers I created a Turbo Pascal compiler written in Turbo Pascal - TPC16. This is a compiler compatible with the original Borland Turbo Pascal 7 command line compiler tpc.exe. Later I modified this compiler to compile under Delphi - TPC32. On the foundations of this compiler I later created Turbo51 - Pascal compiler for 8051 microcontrollers. Then I decided to publish the secrets of the first compiler I have created and this website was born. Here you can find the internals, algorithms and data structures of the Turbo Pascal 7 command-line compiler. You can also download the executable file of the TPC16 compiler.

I created the compiler from scratch, but credits for the beauty of the language and for the exceptional elegance of the compiler go to Niklaus Wirth, Anders Hejlsberg and Borland."

https://direct.turbopascal.org/about

Re:Nim compiler — Pascal source code by fm77 on Sunday November 29, 2020 @08:27AM (#25245005)
This may sound like a contradiction to you because you are right, this is not the official source code of Turbo Pascal, but it is the source code of Turbo Pascal.... :-)

Barry also stated this 5 years ago, see

https://news.ycombinator.com/item?id=10202563

but that is not true.

How can I be so sure? I reverse-engineered pretty much all Turbo Pascal versions starting with v4.0 all the way up to v8.0 (Delphi v1.0). I even disassembled the beta versions of Delphi, v7.9h and v7.9k, to see and study the transition from Turbo Pascal to Delphi.

That being said, what you are looking at at turbopascal.org is an absolute mind-blowing reverse-engineering job. One hint is when you look for example at

Procedure AddReferenceRecordForTypedConstant (UnitSegment, BlockRecord: Word; ReferenceFlags: TReferenceFlagSet; DX, TypedConstantOffset: Word);

https://turbopascal.org/processing-typed-constants

at the bottom of the page - where the author couldn't come up with a proper name for the DX register, so he left that identifier unchanged. If you disassemble Turbo Pascal "tpc.exe" and look for that subroutine you'll see that Anders Hejlsberg really used the DX register.... (I know, not really convincing...)

Re:Nim compiler — Pascal source code by geofft on Sunday November 29, 2020 @08:48AM (#25245079)
If I understood right - this is a "white box" reimplementation of the real Turbo Pascal, which uses the same algorithms and structures and control flow as the real one (and therefore should be bug-for-bug compatible) but is written in Pascal instead of assembly? That is, the "DX" argument there isn't actually passed in register DX, but it represents a function call in real Turbo Pascal that passed the same semantic contents in register DX?
Re:Nim compiler — Pascal source code by fm77 on Sunday November 29, 2020 @05:28PM (#25248678)
I don't know what a "white box" reimplementation is (white-box cryptography?) but I guess you meant a clean room implementation (https://en.wikipedia.org/wiki/Clean_room_design) which I believe this is not the case here (I am wild guessing though). For a clean room implementation you need at least two guys, one reverse engineer who writes down his findings and a guy who takes that information and reimplements the same functionality according to the information the reverse-engineer provides.

But you are right in that it uses the same algorithms, structures and control flow as the real Turbo Pascal and therefore should be bug-for-bug compatible but is written in Pascal instead of assembly.

Re:Nim compiler — Pascal source code by geofft on Thursday December 03, 2020 @07:08PM (#25297291)
Probably a poor choice of words, but I mean the opposite of a clean room reimplementation - it's one where the same person is looking at disassembly and writing the new implementation (i.e, the thing being reimplemented is a white box, not a black box).
Re:Nim compiler — Pascal source code by sim_card_map on Sunday November 29, 2020 @08:37AM (#25245037)
Interesting!

Isn't original TP7 source code available?

https://github.com/shidel/DustyTP7

Re:Nim compiler — Pascal source code by elvis70 on Sunday November 29, 2020 @09:09AM (#25245173)
You have linked a source code repository of programs and units written for TP7.

The sources of TP6 have leaked a few years ago. Search for exmortis on HN.

Re:Nim compiler — Pascal source code by fm77 on Sunday November 29, 2020 @05:07PM (#25248546)
That "sources of TP6" you are referring to is not a leak but also a fantastic reverse-engineering job done probably 1993/94 and appeared 20 years ago on the web...
Re:Nim compiler — Pascal source code by elvis70 on Monday November 30, 2020 @09:37AM (#25254124)
In this context, it's a really impressive work! Can you tell us more?