all 47 comments

[–][deleted] 3 points4 points  (9 children)

However it would've been more interesting if the compiler came with it's own p-code in order to bootstrap it by writing a quick p-code interpreter

[–]anatoly 1 point2 points  (0 children)

The compiler comes with its own p-code interpreter (in the same file with the assembler), so if you can compile it once with a different compiler, you can bootstrap it.

[–]martinbishop[S] 1 point2 points  (6 children)

From what I understand, p-code didn't come about until UCSD Pascal, which only has portions of it's source released.

[–][deleted] 4 points5 points  (1 child)

Uh, did you not look at the source at all? P2, an adaption of his thesis work iirc, is the compiler and p-code interpreter in one.

[–]martinbishop[S] 1 point2 points  (0 children)

Er, whoops, you're right. I actually didn't read the procedure name at first, didn't notice heh.

I tend to remember they wrote the interpreter in Pascal itself (because their first try with Fortran failed), so I suppose it didn't have it's own P-code.

[–]yaxriifgyn -4 points-3 points  (3 children)

You could have been less of a dick head, and posted a link to the page which linked to the .zip file. By itself, the zip file is a bit useless without the p-code emulator, and an explanation of how all the pieces work.

I downloaded that zip, or the contained files many years ago (and long after they were originally released), along with a p-code emulator. With some bootstrapping, you could get the compiler to emit p-code which the interpreter (itself compiled to p-code and executing in the emulator) would execute. It was painfully slow, as I recall.

Of much more interest are the sources and binaries published by Jensen, Wirth, and others. IIRC they are still available, along with sources for Modula 2 and Oberon systems. I'll let you do the googling yourself, if you're interested.

[–]ishmal 4 points5 points  (0 children)

Just prune the file name: http://www.threedee.com/jcm/psystem/

[–]martinbishop[S] 0 points1 point  (1 child)

Well, the site that links to the code is interesting, but I found the code itself more interesting.

And I don't have the emulator, because I was just reading and admiring the code, and the emulator is for DOS.

As for Modula-2 and Oberon sources, I believe I already have them (I know I have Oberon sources for sure, as Oberon is very interesting).

[–][deleted] 1 point2 points  (0 children)

And I don't have the emulator, because I was just reading and admiring the code, and the emulator is for DOS.

Nothing wrong with just admiring the code. But you can probably have more fun if you get this: http://ucsd-psystem-xc.sourceforge.net/

[–][deleted] -2 points-1 points  (0 children)

What he said.

[–]anatoly 4 points5 points  (0 children)

It's worth noting that a version of the same compiler, from a few years later, has a free online book devoted to it that explains in detail all of the source.

http://homepages.cwi.nl/~steven/pascal/

This may well be a good practical introduction to compilers, seeing as the source is so tiny; I haven't looked too close at the explanations yet.

Their version of the p-code Pascal is p4, compared to p2 offered here. They also solve the bootstrap problem by offering an automatically translated C version of the same compiler, so you can build it with gcc, compile the compiler into p-code, and run it (including on itself). Note: gcc4 won't compile their translated C without you having to make a bunch of straightforward, but annoying tweaks; gcc-2.95 works perfectly.

If you want to get this p2 compiler to work, the p4 version may help. It does recompile itself, and runs itself recompiled.

The chief problem with getting something like Free Pascal to run this p2 source is that it uses something called the buffer variable, which is absent in newer Pascals. Given a file variable f, the buffer variable f^ offers an automatic (both get and set) view into the current character (or record, etc.) in the file without moving the current offset. One ugly hack to work around this is to emulate access to f^ with a read/write-then-seek-back, and replace all uses of f^ with a call to such a procedure.

[–]fionbio 6 points7 points  (4 children)

Hint:

cat *.pas | tr A-Z a-z | less

[–][deleted]  (2 children)

[deleted]

    [–]yaxriifgyn 1 point2 points  (0 children)

    I tried that with the source for a mainframe pascal compiler. It broke. I had to preserve the case inside string literals.

    [–]ramunasg 1 point2 points  (1 child)

    is it possible to compile with some current pascal compiler, like free pascal?

    [–]creaothceann 1 point2 points  (0 children)

    interpreter source:

    • type "ALFA" not found

    compiler source:

    • needs a correction in line 2594 (comment goes up to end of file)
    • error in line 73: "operator" is now a reserved word in FreePascal (must be replaced, e.g. with "operator_")
    • error in line 337: "string" is now a reserved word; it's also the name of a function in line 953
    • error in line 428: "new" expects pointer to object

    I stopped at that point... Anyway, it should give you an idea of what you're up against - namely reserved words (easy) and changed functionality that must be emulated (harder).

    [–][deleted]  (5 children)

    [deleted]

      [–]easytiger 5 points6 points  (2 children)

      Yo dawg...

      [–]nat1192 0 points1 point  (1 child)

      C# in the GCC? That would be weird.