Pascal-P versions? #142
samiam95124
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Is Pascal-P6 version 6.0 of Pascal-P6
I get asked occasionally "what is up with the odd version numbers of Pascal-P", IE, why did P2, P4, P5 and P6 get separated out into different code bases? The short answer is: "I didn't do that", but of course there is more to it than that. The "official" versions of Pascal-P really begin with Pascal-P2. The reason for this is that "Pascal-P1" was just a term professor Wirth used to refer to the mess of different versions running around before he created Pascal-P2. Some of those escaped outside of ETH[1], Zurich. Wirth gathered the different versions of the Pascal-P system and came up with one, organized source that was Pascal-P2. This was the source used to create many compilers and interpreters, including UCSD Pascal, which was heavily modified.
Two years later, Wirth refactored the source to come up with Pascal-P3 and Pascal-P4. The difference between these versions is that Pascal-P3 was machine level compatible with Pascal-P2, but Pascal-P4 was not[1]. Since Pascal-P2 was the most widely used version to create other compilers and interpreters (including the CDC6000 compiler), Pascal-P4 was mainly famous because Steve Pemberton wrote a book about the workings of that system.
There isn't a lot of difference between Pascal-P2 and Pascal-P4 really. The main change was an attempt to make it independent of the character set on the host machine, since the original CDC6000 system had its own, non-ASCII character set. This is less important nowadays with ISO 8859 being the rule for 8 bit characters (the other being Unicode). Thus Pascal-P2 and Pascal-P4 could well be x.xx point versions of each other. They just didn't do things like that back way when.
OK, so why did I perpetuate that mistake? The main reason is that version numbers are supposed to demarcate different versions of a functionally identical product, and the versions of Pascal-P after Pascal-P4 are functionally distinct. Lets go through it.
Pascal-P4
Pascal-P4 uses a subset of Pascal, not the full language. It was designed to be the minimum set of the language that could compile itself, but it actually cannot do that without modification, as I found out the hard way. Pascal-P4 has two big advantages for use:
Thus in a lot of ways it is the ideal compiler to use in a compiler class, or form your own experimental language, etc. And thus it would have been wrong for me to simply modify it going forward. Instead I forked that compiler.
Pascal-P5
Pascal-P5 was really the point I was going for in modifying the original compiler. It implements the full language, and obeys the ISO 7185 standard, to boot. Its also a more modern compiler/interpreter. Like UCSD Pascal, and succeeding languages like Java, it uses a byte code machine, that is, a stack machine that uses single byte instruction codes. The old, Pascal-P4 machine uses 60 bit words from the CDC6000 computer.
Pascal-P5 is a good starting point for anyone who wants to make their own Pascal compiler and perhaps their own custom extensions. And indeed, there are several such forks around. It was meant to create a FOSS version of the "Model Pascal compiler", which used to be unobtainium, but recently became available in source form. Time permitting, I will try to compile and run that.
Pascal-P5 thus serves not only as an example implementation of the full ISO 7185 language, but also as a good test for other ISO 7185 compiler implementations.
Thus hopefully you will understand why I left Pascal-P5 as a stand-alone compiler separate from Pascal-P6.
Pascal-P6
Pascal-P6 was designed to be a practical and usable compiler for Pascal. As such, it not only features a full machine code compiler, but also a set of extensions to the original language. Some people have asked me why I extended original Pascal, but the truth is there was never a compiler that didn't add such extensions, including the CDC6000 compiler. Its part of making a working implementation of the language.
The stack machine in Pascal-P6 was retooled to match modern machines. It uses a downward growing stack and an upward growing heap. It uses a framing system that matches modern processors with a "pull down" display system. It's because of these changes Pascal-P6 can be fitted with a back end machine code translator known as pgen that makes it a true compiler. Interestingly, Pascal-P6 maintains its ability to both interpret and compile code to a target machine from the same intermediate form, like more recent languages such as Java or C#.
Also much like Java and C#, Pascal-P6 can generate a binary only deck for its Pascal-P stack machine. The result of that is that it can run on a stripped down interpreter without an assembler/linker built in. There is both a Pascal version of that known as pmach and a version written in standard C. Using that, Pascal-P6 can be ported anywhere a C compiler is available, which is basically everywhere. It could also be used on a Pascal-P machine written in assembly, like the UCSD Pascal machine, or even run on a hardware machine like the original Pascal engine or Java Beans.
Finally, Pascal-P6 features a built in symbolic debugger for its interpreter, pint. This allows for capabilities beyond what an assembly language debugger such as gdb can provide, like trace functions and occupancy graphing.
Conclusion
Hopefully this explains the different versions of Pascal-P, and why I kept them separate.
[1] This (backward intermediate compatibility) was a luxury afforded by the early compilers. I don't do that in the modern (Pascal-P6) compilers, which are often not even compatible between different version releases.
[2] Ok, joking here. Wirth sent tapes out of the source to anyone who requested them.
Beta Was this translation helpful? Give feedback.
All reactions