Turbo Pascal Compiler Written in Turbo Pascal

(turbo51.com)

87 points | by andsoitis 2 days ago ago

36 comments

  • ferguess_k 13 minutes ago

    There is also a webpage about TP internals:

    https://turbopascal.org/turbo-pascal-internals

  • dukoid 5 hours ago

    If you are interested in TP and retro stuff, you might be interested in Jörg's Pasta80 btw.... https://github.com/pleumann/pasta80

  • pjmlp 6 hours ago

    Now that is a project that really feels like donating, especially in today's age.

    If I recall correctly it already has a few years behind it, thus it was actually written by someone that can use the donation.

    > This is not the "original" Borland source code of the Turbo Pascal since it was probably not written in Pascal.

    Indeed, it was written in Assembly during the CP/M days, and slowly got to have more Turbo Pascal into it as the language evolved.

  • gxd 6 hours ago

    If you haven't lived through this era, try one day to download DOSBOX and run Turbo Pascal. You will be impressed with how fast it compiles on an old machine... Often faster than most modern projects on our modern computers.

    • cowlevel 5 hours ago

      Probably no optimization though, right?

      • joakleaf 4 hours ago

        You could enable optimizations. Turbo Pascal generated pretty fast production code in general, and you could also disable run-time checks like range checking etc.

        The generated code wasn't perfect, but you could always use assembler for short routines that needed faster code (e.g. loop-unrolling, tighter register usage, or 80386 32-bit register code, which I think TP never supported). There were also tricks that would improve performance (I seem to remember that 'repeat'/'until' was faster than standard 'for' loops).

        To be honest, it was a very fast tool to work with (even on a 80286) -- The integrated debugger was a dream to work with for the time too.

        I remember switching to C (both Turbo C and later gcc via DJGPP on both a 80386 and 80486). Compiling even standard C was agonizingly slow in comparison to TP, and you couldn't iterate as fast as TP. It was like moving from having fun programming to plain torture.

        I moved on to fully embrace C later (and C++). As the computers got more RAM and got faster, it became a lot better experience, but I never fully understood why C was popular as a general purpose language in the 80s and 90s. I doubt C was optimal for development time.

        TP was a really balanced compromise in a lot of ways.

        • switchbak an hour ago

          For some reason they forced us to use these ancient 8088 machines (in 1996 no less!) at my school. Even there, the speed of Turbo Pascal was just incredible!

          Sure things were very spartan, but you could do a heck of a lot on what is basically a trumped up microcontroller. I have mostly felt that modern tech has been a step backwards - because the inner loop has so much latency. Turbo Pascal and Delphi were really leaders in this regard. Python and friends were good too (aside from the runtime errors!), but getting a real compiled and lean binary so quickly was a very special thing. I didn't enjoy moving to Java after that, especially in those early days.

          If only I had known about TDD back then, I think ultra low latency compiles and fast running tests would be hard to beat.

      • pjmlp 5 hours ago

        There were optimizations already available.

        Even if the basic ones that tend to be part of university compiler assignments, .e.g. peephole optimisations, constant propagation, inlining, bounds checking removal, redundant loads removal,....

        See chapter 21 from Turbo Pascal 7 Language Guide, to use the last one for MS-DOS as example.

        Similar build performance available in other languages, alongside a small set of optimisations.

        It is a urban myth that we cannot have both, only because folks experience is tainted with C and C++ compilers.

        If you want a good example of fast compilation times with optimisations enabled, check D reference compiler dmd, or to keep on the subject, FreePascal or Delphi 13.

      • hnlmorg 4 hours ago

        Optimisations existed back then. But what Pascal did differently to a lot of modern languages was it only required a single-pass compiler and no macros.

        On slow systems of the era, that vastly reduced the amount of work a compiler had to do to turn ASCII into machine code.

        These days, compilers run macros, multiple passes of the source code. Often then building their own byte code or an interim machine representation, before turning that into machine code.

        Those layers of abstraction aren’t without benefit. You get greater composability of code, greater portability, and so on and so forth. So they exist for a reason.

        • switchbak an hour ago

          I often wonder how much benefit we get from most of those optimizations. I rarely felt that Turbo Pascal's runtime was slow or slow enough to cause frustration over something like C.

          I think we could do something similar today - very fast compilation, and straightforward but efficient machine code. And perhaps bolt on the heavy duty optimizations where it is needed. Many JIT's work similar to this, but it seems like you could do it in an AOT style too.

          • wolvesechoes 32 minutes ago

            > I often wonder how much benefit we get from most of those optimizations

            Well, in a world where many among most used apps are made of NodeJS and Electron frontend, I think we are very far away from having to worry about those optimizations in most contexts. Having those written in TP with zero optimizations would still be more resource efficient and performant.

            And when it comes down to squeezing last drop of performance, we forget compilers and still rely on assembly wizards tuning BLAS routines, crypto code etc.

            • switchbak 24 minutes ago

              Not to mention all of the superhuman efforts that chip makers take to make existing app patterns (typically driven by C) perform acceptably.

              It does make you wonder how much we could simplify and take away while still having things be blazing fast. I would assume some of the old optimizations are actually hurting things on newer architectures.

      • OskarS 5 hours ago

        Optimizations is one reason for modern languages to compile slowly, but it's certainly not the only reason. Even at -O0, C++ and Rust are much slower to compile. The culprits are more likely much more advanced type-systems and monomorphization passes for generics. Slow compile times are much more inherent to the languages (compared to Turbo Pascal, certainly).

        • pjmlp 4 hours ago

          Not even, regarding type systems, see D or Ada compilers.

          Or if you prefer to travel back to 1993, here is a developer experience using C++ as if it was Lisp Machine/Smalltalk environment with incremental compilation and hot code reloading.

          "Lucid Energize Demo"

          https://www.youtube.com/watch?v=pQQTScuApWk

          With one of the very first ideas of a LSP could be like,

          https://dreamsongs.com/Files/Energize.pdf

          We got into a culture that accepted slow compilers is normal, it doesn't have to be.

          • vidarh 4 hours ago

            One of the noteworthy papers I remember reading in the early 90's was a demonstration that you could even add SSA form to ETH's Oberon compiler to apply optimisations equivalent to the then-current version of gcc with very little loss in compilation speed.

            I guess today if you want fast, optimized codegen you need to look more at JIT research since it seems the AOT compiler research seems as you say to have just accepted that slow compilers is normal.

            • pjmlp 3 hours ago

              Yes, spot on.

              A good mix is having a JIT/AOT combo, use JIT for the development workflow, and a full blown AOT with all possible optimisations turned on for production releases.

        • wolvesechoes 38 minutes ago

          Not really. In addition to Ada and D mentioned by a sibling comment, Ocaml or F# have even richer type systems than Rust, and compile times are better.

          Yes, compiling Rust in the release mode could take long time and it would be worth all this baggage - monomorphization, trait resolution etc. But there is no reason, except not giving shit, to no have a fast and simple pipeline for debug builds.

      • whobre an hour ago

        If you are interested in an optimizing Pascal compiler from that era, check DRI Pascal MT/+

      • muyuu 5 hours ago

        they are pretty minimal

        the game back then was to use inline assembly for the critical bits, this really worked a treat for the meta of the 90s, with computers that were being asked for multimedia processing with slow CPUs, little RAM and typically no hardware acceleration

        • summa_tech 5 hours ago

          As a positive side of that tradeoff, inline assembly in Turbo Pascal was extremely pleasant to write. Because the optimizations were so light, it did not require complex constraint specifications on the values passed in and out, so you could just refer to local variables directly.

          • vidarh 4 hours ago

            My first compiler was for a Pascal-like language that started with just reading assembler in and spitting assembler out, and then I layered in blocks and expressions step by step and slowly rewrite the compiler itself from a basic text processor in assembler to a proper compiler, making use of each new feature as soon as I'd made sure it worked.

            I wish I still had the code for it - because it had a very simple Wirth-style code generator it was predictable enough that you could even use registers directly in expressions. (M68k, so e.g. you could do "x = D7.w" to set the variable x equal to the low 16 bit word of register D7)

            EDIT: Worth mentioning Randall Hyde's "High Level Assembly"[1] here as an actually published language that did something similar.

            [1] https://en.wikipedia.org/wiki/High_Level_Assembly

  • yomismoaqui 2 hours ago

    As an IDE Turbo Pascal was awesome.

    Blazing fast compiler (on that era's hardware), glorious TUI framework (Turbo Vision) and a nice help system. Anders Hejlsberg is a genius.

    After using this and Delphi and then having to develop UIs on the web it was like losing an arm.

  • plinkplonk 3 hours ago

    you have to pay to get the 32 bit compiler source code. (nothing wrong with this, this information is way down the page, and it might help someone else wondering if this were open source)

    "Most of the source code is published with comments on Turbo Pascal website. Here you will be able to get all the internals of the compiler. However, if you would like to use this compiler for your own project and you need the complete TPC16 package with all source files then please continue reading. You can get TPC16 Turbo Pascal compiler source code for some small compensation"

    TPC 32 - 150 Euros for two downloads in the next 24 hours.

  • JoeAltmaier 3 hours ago

    In the old days, it was quite a common trick to write a sketchy compiler in assembler (or whatever you had) then rewrite it in itself. Iterate two or three times and you had something.

  • Slapshot_gd 3 hours ago

    Wow, the memories from this!! Using inline assembly for mouse support was amazing at the time... Heck, I remember writing a UI/shell for Home Management (included basic apps, and a neat feature to estimate calculate your monthly power bills), that I ran under OS/2 (with win32 support). Ended-up winning a science fair with it in high school in 1993, prize being a copy of OS/2 Warp. I still have that shrinked-wrapped at home :)

  • mtve 4 hours ago
  • ubermonkey 5 hours ago

    I loved Turbo Pascal SO MUCH ca. 1989-1992 or so.

    As a nerd of a certain age, at one time I had a mighty shelf of programming references from Waite Group and Swan and (of course) O'Reilly. Over time, I let nearly all of them go because it's faster to have stuff available digitally now (and has been for 20 years or more), but I kept a few as keepsakes.

    The survivors live on a shelf about six feet from where I'm typing, and there you'll find my K&R book, Booch's work on OO, my college FORTRAN textbook, an O'Reilly twofer (a camel and a baboon; extra points if you can identify those by animal alone), and a fat blue tome called Mastering Turbo Pascal 5.5. It has a rendering of a 911 on the cover. My pal Mike gave it to me for my birthday in probably 1990, back when we were both in college and writing code for a computer lab at the business school there.

    Years turned into decades, and we remained close. Last summer, my wife and I relocated to North Carolina, in part because Mike and his wife live here. I'm having lunch with him today, just as I do every week.

    Sometimes, good languages make good friends.

    • dolmen 4 hours ago

      I started programming with Turbo Pascal at high school. I made a few games in DOS text mode.

      Nowadays my favorite language is Go. It appears that among the programming languages that I did use, Go is the one that feels the nearest to Turbo Pascal.

      • jan_m_savage 4 hours ago

        that's cuz one of the designers of Go was a student of Wirth's.

    • ferguess_k 3 hours ago

      Do you happen to work as a first responder in the past?

    • 000000000001 3 hours ago

      Baboon - JUnit pocket guide?

      Camel - Perl Programming :)

      • ubermonkey 10 minutes ago

        Camel is, of course, Learning Perl.

        Baboon is Embedding Perl in HTML with Mason.

  • JdeBP 2 hours ago

    Another Turbo language in Turbo Pascal:

    * https://news.ycombinator.com/item?id=49967652

  • mobilio 4 hours ago

    Looks abandoned. Last update is "25.06.2013"

    • empw 3 hours ago

      What updates are needed? This is the type of software project that can actually be finished, which is difficult for people to understand today.