Public domain Pcode spec/interpreter

Paul Robinson <>
Sat, 17 Sep 1994 05:24:11 GMT

          From comp.compilers

Related articles
Public domain Pcode spec/interpreter ? (1994-09-11)
Public domain Pcode spec/interpreter (Paul Robinson) (1994-09-17)
Re: Public domain Pcode spec/interpreter (1994-09-17)
Re: Public domain Pcode spec/interpreter (1994-09-18)
Re: Public domain Pcode spec/interpreter (1994-09-20)
Re: Public domain Pcode spec/interpreter bfaust@saratoga.physik.Uni-Osnabrueck.DE (1994-09-21)
| List of all articles for this month |

Newsgroups: comp.compilers
From: Paul Robinson <>
Keywords: code, comment
Organization: Tansin A. Darcos & Company, Silver Spring, MD USA
References: 94-09-033
Date: Sat, 17 Sep 1994 05:24:11 GMT

Tim Carver <>, writes that he is looking for a Pcode
interpreter so that he can freely intermix interpreted code with machine
code in a target environment, e.g. move to machine code where it's time

Done correctly, I think this is a wonderful idea. It would be an
excellent way of developing much more machine-independent programs, and
would be a fairly good way of making easier-to-port compilers.

I know that the term 'pcode' is often used to mean interpreting of Pascal
Programs, but in this case I am using it to mean a pseudo-machine code for
any programming language which uses the set of codes.

I'll first throw a little gasoline on the fire by bringing up some issues
he should think about, then offer some suggestions.

First, what is the target language?

In designing a PCode Interpreter, the needs of the language being targeted
must be taken into consideration. For example, in FORTRAN, the data type
declarations in a FORMAT statement have to be taken into account, as would
the DEFINE FILE and SEEK statements. But FORTRAN doesn't have record
structures and pointers.

In Pascal, you have pointers, dynamic memory, variables being new every
time a procedure is invoked, recursion, and if you go into the new stuff,
object orientation. But you don't have COMMON other than global variables
and not the same way FORTRAN does it. All I/O is done through procedure
names (except WRITE/WRITELN, being a procedure, does have special handling
because of its special options).

Is the Pcode to be language specific or a generic specification?

If the Pcode is language specific it can be used to take some of the work
off of the compiler designer. But a general purpose p-code is by
definition the machine language of a real or fictional machine.

In fact, many languages that are "compiled" do implement some of their
features using call instructions to routines with argument lists, instead
of repeating the same code inline in the resulting binary.

A good example of this would be arithmetic. For example, generating a set
of call instructions for the six major add instructions (I=I+I, I=I+R,
I=R+R, R=I+I, R=R+I, R=R+R where R is a real and I is an integer) means
that the code can simply consist of a call and the three addresses or the
result address and one address and a value or two values if the arguments
are constants. The same applies for the other three primitive operations.

The advantage to doing this can include reduced code size, ability to do
range checks for overflow, divide by zero, and if the machine has a
separate math coprocessor, the mathematics can be pipelined so that
several instructions can run simultaneously while other code is being
executed. (This also allows the compiler to use the coprocessor directly
for all arithmetic or avoid it if it's not present, instead of doing
testing for every single mathematical operation, since a coprocessor test
can be done once, and a flag can be checked; by placing the math code in a
subroutine, the flag check can be set up as part of a test and jump,
allowing automatic use of either software math routines or a coprocessor
every time, something which would probably be too expensive to do every
time someone does an addition, subtraction, multiplication or division.)

For a Pcode targeted to a specific language, there is the FACILIS subset
Pascal compiler written by Nicklaus Wirth and translated to run, for
example, under Turbo Pascal version 3.0, available from several BBSs,
possibly searchable by Archie or part of the collection of Pascal
compilers I sell. The meaning of the pcode generated is listed in
{Software, Practice and Experience} Volume 1, if you look for his name.

A similar set is used by the Stanford Pascal Compiler, and the post
processor for the language then translates Pcode into IBM 360/370 machine

Another reference P-Code (which may or may not be public domain) is used by
the Augusta compiler which accepts a subset of the ADA language.

For a real machine code that is in the public domain, there is the 360
Instruction Set for the IBM Mainframe series. IBM published the technical
specifications in its reference manuals without a copyright notice before
the U.S. went on the Berne Convention, so the specification and machine
code are in the Public Domain. Also, the older "green card" which people
made fun of, was uncopyrighted and listed all of the 360 instructions.
(We used them at Long Beach City College (California) which had a Univac
90/60, a close compatible clone of the IBM 360 Mainframe with some of the
370s enhancements). Later the "gold card" came out which listed the 370
instructions, and ended up going from a 6-sided reference card into a
15-page pamphlet.

If he wants to discuss this further, Mr. Carver can write me privately on
the subject, and we can see about working out something for him which will
fit whatever his needs are, withoun necessarily having to squeeze into
something that might not fit what he wants.

Paul Robinson - Paul@TDR.COM
[There have been lots of systems that use p-code to permit highly portable
binaries. I used a database called Dataflex, and it is my impression that
the Pick OS which includes a nice database is also p-code. Beware of trying
to define a p-code for multiple source languages; there lies the path to
UNCOL heat death. -John]

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.