Stefan's Turbo Pascal Corner

Here, you find some unusual projects I did for Turbo Pascal. TP's best days are now over, as there are much better alternatives available. On the other hand, extending the old compiler's capabilities is a fun and challenging task. I still use and improve both programs. I'd be glad if you find a use for them, or maybe even improve them.


tputuner is a code optimizer for Turbo Pascal 6.0 and (NEW) 7.0. The Turbo Pascal compiler does not optimize much, all it does is a bit constant-folding and some dead-code elimination.

tputuner reads a compiled .tpu file (TPU9), disassembles it, optimizes it, and writes out the optimized version. tputuner features a rudimentary data flow analysis (mostly only reload optimisation), common subexpression elimination, some jump tweaking, peephole optimisations and basic register allocation. The main focus of tputuner is a size reduction, not necessarily speed increase, but usually, size reduction doesn't hurt speed. Reliable speed optimisations are not possible anyway with that little knowledge tputuner has.

I developed tputuner in C++ under Linux because that made it easier to handle large amounts of data. It also compiles under DOS with DJGPP.

TPUTUNER can be configured for Turbo 6 or Turbo 7 at compile time, the precompiled binary is for Turbo 7.

DPMI for Turbo Pascal

D4TP allows Turbo Pascal 6 / 7 users to write protected mode programs. This is a pure DPMI client, i.e., not a complete DOS extender. It loads your program into protected mode if possible (=if a resident DPMI server is found), otherwise it will continue to execute in real mode.

Since 27/Apr/2002, D4TP is able to load Borland's dpmi16bi.ovl DPMI server when needed.

The main advantage of D4TP is that it allows your program to access megabytes of memory (though it is only 16 bit, I've already seen a D4TP program allocate 20 meg). Also, it becomes harder to completely screw up the system with a dangling pointer.

You need to port a bit of your code. However, that's not as complicated as it sounds, I ported PCC, a 70000 lines project, in two or three days.

D4TP programs need a resident DPMI server. Unlike programs compiled with BP7, they do not automatically load one. This is only a problem for the few people who still run plain DOS (like me ;-). In DOS boxes, DPMI is usually available.

Compiling big projects

Turbo Pascal was always classified as a "hobbyist" product. Still, people do big projects with it, me being one of them. What does "big" mean here? In the magnitude of 100 modules. When reaching this range, you'll experience more and more errors of the type "out of memory", "too many nested files", "too many symbols" -- not fun, really.

What is the source of these problems? Turbo Pascal insists on doing its own dependency analysis and recompilation management. There is no way of recompiling a module depending on something you modified without recompiling the modified module itself -- and this pulls in a myriad of other modules. This easily fills up Turbo's internal tables.

Of course, there's a way out. Everything Turbo Pascal really needs to recompile a module is the interface of the modules it used, not the implementation. You know C? You always include the header files, not the implementation files. So there must be a way to make Turbo Pascal compile only the interface of a module. And, there is one. Quite Hackish one, otherwise it would not be worth being mentioned here ;-)

This sounds complicated, but actually is not. You do not have to run through this whole one-two-three for each recompile. When you just changed part of an implementation of a function, a simple tpc /m main suffices. Only if you change critical items in interface parts, you need to do the whole thing. Even then, you do not have to regenerate all the interface parts in src\int, only those which actually changed.

Other tips to make programs compile better:

[ Main Page | All files ]

Stefan -
Last modified: Mon Jun 10 13:09:25 CEST 2002