[comp.sys.apple2] HyperC P-code

BRL102@psuvm.psu.edu (Ben Liblit) (11/28/90)

In article <4673@tellab5.tellabs.com>, toth@tellabs.com (Joseph G. Toth) says:
>
>Has anybody investigated Manx, Apprentice C or HyperC to determine
>whether either of these is a P-code system??

HyperC does have P-code capabilities.  And I must say that it is truly one of
the sweetest P-code systems I've ever seen.  Check this out:

   - The HyperC compiler translates tokenized source (from the preprocessor)
     into P-code source.  That's right, *source*.  You can even read / edit the
     file if it makes you happy.

Now, once you've got the P-code source, there's two things you can do:

   - Put the source through the P-code assembler, which generates object P-code

Or:

   - Put it through the macro expander with an include file (I forget the name)
     that defines a macro for each of the P-code opcodes.  For the most part,
     these are expanded into JSR's.  So now, instead of P-code source, you've
     got good old 65xxx assembly source with lots of JSR's to the P-code
     driver.

   - Take the output from this and pump it through the native code assembler.
     It generates normal 65xxx object code with lots of references to external
     symbols.  These are entry points in the P-code driver.

Now, here's the really nice part.  The driver itself is a native code object
file.  So if you've got native code, with all those external references, just
specify the driver as one of the input files to the linker.  It resolves all
of the references and presto!  Your native code and the driver are doing the
tango.

HyperC also lets you mix native code and P-code freely within the WSM shell.
The shell sets the BRK vector to point to the start of the P-code interpreter.
The P-code *assembler* cooperates by putting a BRK at the start of every P-code
routine.

So, say your main() is executing in native code and you call a P-code routine.
Well, you JSR right to a BRK instruction.  The P-code interpreter kicks in and
the P-code executes, no problem.  When the P-code routine exits, the P-code
interpreter exits too, and you're back in native code to continue executing
main().

Is it just me, or is this one amazingly nifty way to implement a mixed native
code / P-code system?

                            Ben Liblit
                            BRL102 @ psuvm.bitnet -- BRL102 @ psuvm.psu.edu
                            "Fais que tes reves soient plus longs que la nuit."

ericmcg@pnet91.cts.com (Eric Mcgillicuddy) (12/01/90)

I would suggest that you rewrite the P-code assembler to generate Apple Pascal
P-code. Or you could write a Pascal compiler for HyperC. Either method is more
likely to result in success and might just earn you a few shareware bucks. 

Note that you can write any language at all that you wish for HyperC since the
P-code interpreter is what runs the programs (even native mode programs
require it to be present for the library functions). 

I wonder if it would be possible to write an Applesoft compiler for HyperC? 

Nah, why mess with perfection?  :)

UUCP: bkj386!pnet91!ericmcg
INET: ericmcg@pnet91.cts.com