
Internals of a Turbo Pascal Compiler - agumonkey
http://turbopascal.org/
======
barrkel
This site doesn't describe the internals of Borland's Turbo Pascal compiler.
It describes a compiler written in Turbo Pascal that can compile some subset
of Turbo Pascal's language.

Borland's Turbo Pascal compiler was written in 16-bit x86 assembly, mostly by
Anders Hejlsberg.

There is an explanation of this on the front page of the site, but it's not
clear from the headline.

(I used to work at Borland on the Delphi compiler, and had access to the
source of tpc.exe.)

~~~
antimagic
I have very fond memories of just how blazingly fast Turbo Pascal was at
compiling on my Mac. It stunned me every time. I remember spending most of one
summer writing a text adventure game with it, based in the Australian Gold
Rush. It even had NPCs which was quite advanced for text adventures of the day
(I think the only NPCs in adventure games that I had encountered up to that
point were those in the Hobbit, and of course the bloody thief in Zork
(although he wasn't really an NPC, but was implemented as a bunch of semi-
random encounters)...

Good times. In particular, I remember having to implement my own strings,
because for a text adventure you often want to have access to strings longer
than 255 characters...

Sadly, I never managed to make the jump from writing console applications with
TP to writing proper Mac GUI apps. But "Inside Macintosh" cost an absolute
fortune at the time (for a 10 year-old kid at any rate), so I ended up
scraping enough money together to buy another text book whose name escapes me.
I must have read the first few chapters about a million times - they talked
about handles and graphics ports etc, but I could never get any code from them
to run in TP (I think they were assuming that you would be using MPW?).

Which brings me to the point of this long rambling message - did TP really
support graphics programming on the Mac? I know my version of TP was an
official bought copy, so we had the manual, but I don't remember ever seeing
anything that explained GUI programming in there.

~~~
pjmlp
Well you also had Apple's Object Pascal as the original OS system programming
language, which was the inspiration for the OOP approach Turbo Pascal adopted.

With that one, you could surely do graphics programming on the Mac.

As for Turbo Pascal itself, I wasn't aware it was available on the Mac as
well.

~~~
ido
A more popular alternative to Apple's MPW on the mac was the 3rd party
Lightspeed Pascal (later renamed THINK Pascal), which in many ways was quite
similar to Turbo Pascal on the PC.

IIRC TP was just a quick port & had a very short life on the mac.

------
pjmlp
I loved Turbo Pascal.

When I got to learn C, already had Turbo Pascal 3, 4, 5.5 and 6.0 on my
toolbox.

Compared with Turbo Pascal, the only thing C had going for it was being
available in other systems. Everything else was meh.

No memory safe handling, no bounds checking, no units (modules), no
namespacing, no proper strings, no OOP support, arrays decaying into pointers,
no type safe enumerations, no sets, no generic array indexes...

At least C++ allowed me to get some of those Turbo Pascal features back.

~~~
agumonkey
Pascal was off time. A lot of these traits are really worthy, but it wasn't
attractive at the time .. was it as 'performant' as C too or was it a very
nice environment to craft sound code productively whereas C code could allow
you to tap into hardware more aggressively no matter how much headaches that
would give you ?

~~~
pjmlp
Pascal and C compilers produced similar code quality back then.

Everyone praises C compiler quality nowadays. On those home computers, C,
Pascal and Modula-2 were good enough for general purpose applications, if one
wanted real speed, Assembly was the only way to go.

Turbo Pascal, as well as any other Pascal dialects, had the same capabilities
to access hardware as C offered.

Also the MS-DOS game development scene and the demo scene tools were heavily
based in Turbo Pascal, besides the usual Assembly stuff.

~~~
agumonkey
Oh right, I remember inline asm in TP now. I smile at how easy this thing was,
I didn't even know how many thing happened under the cover, I just typed so
glyphs (I didn't know the language) and hit F5 IIRC. Only recently I heard how
they designed the compiler to be so fast you didn't see the build step.

~~~
klagermkii
Thinking you press F5 for compile/run? That's the kind of shibboleth that outs
the QuickBASIC heathen!

------
Udo
Turbo Pascal was my first contact with compiled languages in school, after
starting off with Commodore Basic as a kid and graduating to Amos and some
other Amiga stuff later. TP was my first contact with real PCs, too. After
school I moved to Delphi, which was basically a thin wrapper around the Win32
API with Object Pascal syntax and the nicest IDE I had ever used (and probably
will ever use).

Delphi really paid my bills as a newbie commercial programmer. That was around
the time when the internet took off, and I wrote my first CGI servers in
Pascal to make dynamic websites. The Pascal/Delphi language and environment
were incredibly versatile and you could write some really fast code with it.

Fond memories. In many ways, TP leveled me up as a programmer.

~~~
melling
I think a lot of people would have claimed that the Amiga was the more
powerful Personal Computer. In many ways, it was more interesting than the Mac
or Windows computers. It simply didn't have the software support from
Microsoft, for example.

The Amiga did make its own dent in the universe:
[http://www.geek.com/games/cgi-first-introduced-to-tv-in-
baby...](http://www.geek.com/games/cgi-first-introduced-to-tv-in-babylon-5-by-
mit-presentor-771051/)

~~~
lobster_johnson
In most alternate universes, the Amiga would never could have been a
competitor to the PC or even the Mac.

The secret to the PC's success was not just the clone market, but the open
architecture that permitted endless permutations on interexchangable
components: motherboards, graphics cards, hard drives, etc. were all
pluggable.

Amiga's custom chipset and architecture gave it a huge edge (mostly in
multimedia), but the tight coupling made it an evolutionary dead end. Even if
they licensed the OS and opened the architecture to clones, the hardware
dependency wouldn't have been able to follow suit.

------
rottyguy
I was working at a software store during the mid-late 80's (Babbages if anyone
knows it) and had a customer come in asking for a small, lightweight editor...
You know like "turbo pascal but w/o the compiler part". First time I ever
heard of it and, tbh, had no idea what he was talking about. I later used it
to do some work for in my CS class (highschool was teaching programming via
Pascal). It's a good language to learn after basic and before C/C++.

IIRC correctly, TP used a yellow font (well ascii) on a black background
(default)? Didn't it also have some quick key combinations (I recall a ctrl+k
for some reason but I'm sure it's just memory...)

~~~
jablan
> Didn't it also have some quick key combinations (I recall a ctrl+k for some
> reason but I'm sure it's just memory...)

Exactly. So-called WordStar combinations, which lot of the editors of the time
were using. AFAIK, it is still used on some quite popular text editors on
Linux (joe?).

[https://en.wikipedia.org/wiki/WordStar](https://en.wikipedia.org/wiki/WordStar)

~~~
jhallenworld
I'm compelled to plug the recently released JOE 4.1 here:
[http://sourceforge.net/p/joe-
editor/mercurial/ci/default/tre...](http://sourceforge.net/p/joe-
editor/mercurial/ci/default/tree/NEWS.md)

"jstar" version of JOE has the WordStar keys.

------
junto
Turbo Pascal was the first language I was taught in school, although I had
already taught myself BASIC on a BBC B Microcomputer as a child.

I loved Pascal and wrote a race management program for my local sailing club
when I was 16. Fond memories. The whole experience was a voyage of discovery,
as I had to write my own "windows" style UI using ASCII codes.

I used Delphi later on in university along with Modular2, and C++. I never
felt the same passion for these languages as I had had for Turbo Pascal.

I later moved on to VB and VBscript, and didn't like them at all but they paid
the bills.

The next time I felt that same type of passion was for C#. Somehow it just
clicked. I think it is about what you can achieve productively with the
language, as well as the language itself.

~~~
luso_brazilian
You will then be pleased to know that C# development team is led by Anders
Hejlsberg, the same Anders mentioned in the article that created what went to
become Borland Turbo Pascal. IIRC, he also led the development of Borland
Delphi and its language, Object Pascal.

He is really a prolific language designer, one of the unsung heroes of that
area.

~~~
barrkel
Object Pascal was originally an Apple invention (with help from Wirth), and
made some strides towards ISO standardisation. However it used a value-based
OO model that made vtables optional until you added the first virtual method,
permitted object slicing, had no common ancestor for all classes, had an odd
syntax for calling constructors (using extra parameters to New), etc.

Delphi introduced a new object model while retaining the old object model for
backward compatibility. The language was renamed to Delphi some time later to
reflect this; while Object Pascal in practice meant the language that the
Borland compilers compiled, its technical and historical meaning is both
broader (more compilers) and more limited (a smaller language with different
features).

~~~
junto
Interestingly I just Googled Borland to see what they do these days:
[http://www.borland.com/Products](http://www.borland.com/Products)

Seems like they made quite a major pivot?

~~~
lucifersam
Yes, quite some time back they split the languages and compilers part out and
the rump of Borland became an application lifecycle management company, or
something like that.

The bit you're probably looking for is at
[http://www.embarcadero.com/](http://www.embarcadero.com/) now. Some of the
old people like David Intersimone are still there.

I worked with Delphi for a long time, through versions 3, 5 and 7 (the odd
numbers were always better). When .NET came, the whole situation went crazy
and never recovered. I can't remember the twists and turns now, but I think
they released a .NET only RAD Studio which was awful, then they added the
Win32 bits back but Delphi.NET was still awful. Then they dropped .NET and
incorporated Remobjects Chrome/Oxygene as Delphi Prism, which was an Object
Pascal inspired .NET language. Now they've split again, and Radstudio is all
about Firemonkey, a cross-platform UI library. Remobjects are doing their own
thing.

~~~
jimmcslim
I've been working with Delphi for the last 18 months; previously Java and .Net
many years before that, but Delphi in the distant, distant past.

In my opinion, Delphi needs to just die, and the people/companies that have
code bases built on it need to rewrite. There are lots of choices for software
development these days, I don't think Delphi stands out for any particular use
case in the modern world. But hey, maybe I'm just bitter after RAD Studio
crashed on me one too many times...

~~~
nickpsecurity
Compared to VC++, it was easier to learn, read, write, make reliable apps, and
extend. I could teach anyone a Wirth language. The Go community is learning
the benefits of Pascal-style design. People wanting a new Delphi should
probably use Go. Just because Delphi stagnated and died off.

Anyone wanting Pascal/Delphi today should use Lazaurus IDE w/ Free Pascal
Compiler. Compatible with Delphi where it mattered, aiming for better in other
areas, open-source, and cross-platform. Best use case is a C or C++
replacement that's safer, easy to read, and supports computers with little
resources. Go's not there yet on runtime side.

~~~
amyjess
> People wanting a new Delphi should probably use Go. Just because Delphi
> stagnated and died off.

Or, for that matter, Nim, which also has a huge amount of Pascal heritage.

Go is a hybrid of Oberon and C (with semantics leaning more towards Oberon and
syntax more towards C, but they're both mixed in), and Nim is Modula-3
semantics married to Python syntax (with the best parts of a bunch of other
languages thrown in). Both Oberon and Modula-3 are descended from Modula-2,
which in turn is descended from Pascal.

Personally, I'm more in the Nim camp, partially because I prefer Modula-3 to
Oberon, partially because I prefer Nim's Pythonesque syntax to Go's C/Oberon
mashup syntax, and partially because Nim's metaprogramming features are truly
beautiful.

~~~
beagle3
> which in turn is descended from Python.

I think you meant Pascal?

~~~
amyjess
Yes, I did. I'll edit it.

(...and edited)

------
huhtenberg
> _Anders Hejlsberg developed Blue Label Pascal... This compiler was later
> licensed by a software company Borland which added user interface and
> editor, changed the name to Turbo Pascal and offered it for a competitive
> price._

Nooo... Another account of TP origins was that it was _written_ by Philippe
Kahn (the founder of Borland), back when he was just a one-man operation
running from a small office on top of a Jaguar car service shop. But
apparently it wasn't. Damn.

~~~
jonsen
[http://blogs.embarcadero.com/davidi/2008/11/02/38933](http://blogs.embarcadero.com/davidi/2008/11/02/38933)

~~~
tonyedgecombe
The implementation size breakdown for the 12k compiler was: Compiler - 5.5k,
On-Screen editor - 1.5k, Runtime library - 4.5k, and Control program 0.5k.

------
swaits
Fans of Turbo Pascal, or more so Delphi, will be interested in Lazarus.
[http://www.lazarus-ide.org/](http://www.lazarus-ide.org/)

~~~
krylon
I took over maintenance of an in-house application written in
Delphi/ObjectPascal about 18 months ago (as one of my many tasks - I have
spent maybe one or two weeks working on it since), and I thought Lazarus was a
neat way of getting me started, having no prior Pascal experience whatsoever.
Alas, the IDE crashed on me so frequently both under GNU/Linux and OS X that I
gave up within a couple of days. Either it is not very stable or I was
mistreating it somehow, although I don't know how.

The documentation was very helpful, though, in getting to know Pascal. Taking
over maintenance of an application written in a languange you can read but
hardly write (whatever bad things people might be tempted to say about Pascal,
cryptic syntax is not among them, I am certain) is a strange process.

------
mahouse
I'm triggered by the lack of diversity in that story. I am pretty sure Niklaus
Wirth was actually black, but that fact was hidden by white male zealots.

~~~
doodpants
[https://en.wikipedia.org/wiki/Niklaus_Wirth](https://en.wikipedia.org/wiki/Niklaus_Wirth)

~~~
tedunangst
You must be part of the cover up.

