View unanswered posts | View active topics It is currently Tue Jun 18, 2019 9:26 am

Reply to topic  [ 6 posts ] 
 CC8 - A native C compiler for the PDP-8 running OS/8 
Author Message

Joined: Wed Jan 09, 2013 6:54 pm
Posts: 1188
Posted to the PiDP-8 list by Ian Schofield

It'd be great if this small native compiler (GPL) could be readily ported to other small architectures. I'm thinking OPC, but maybe micros like the 6502 would also do the trick.

...some of you may be wondering what is the point of all this. It actually arose from the use of small embedded systems. Even now, reprogramming these can be a pain and sometimes you wish that they had an on board OS that you can talk to. Well OS/8 is just that and all you need is an AVR and possibly an SD card and firmware updates can tested in place. Obviously, that is how the Raspberry Pi itself can now be used and this concept has really taken off in the last couple of years as in, why use a PIC/AVR when you can use a PiZero.
In addition, there is the fun of doing stuff using a reasonably modern language on historical hardware. Having just looked into the graphics side of SIMH with a view to rationalising the use of multiple libraries I was struck by the lack of stuff to run on a TX-0 and the PDP-1. Writing machine code for these is tricky but a re-targetable c compiler could be used to bring them back to life. See p8.c or code8.c which generate the code fragments ... altering this is just a bit easier than sdcc.

CC-Update.tar.gz [756.73 KiB]
Downloaded 180 times
Mon Mar 05, 2018 3:43 pm

Joined: Sat Oct 28, 2017 12:16 am
Posts: 7
Interesting stuff! CC8 seems to be the name of the cross-compiler used to boot-strap the native compiler. "Readily portable" was not really my first thought when looking at the native compiler (n8.c) though ;) These days you only see code like that when looking at minified Javascript :D

Tue Mar 06, 2018 10:35 pm

Joined: Wed Jan 09, 2013 6:54 pm
Posts: 1188
hmm, OK, I confess I didn't look at the source...

Wed Mar 07, 2018 9:45 am

Joined: Sat Oct 28, 2017 12:16 am
Posts: 7
The native c compiler only implements a limited version of c. It should be considered to
be a 'c like' scripting language.

The language looks closer to B than to C imo. There is only one data type (12-bit int), no "struct" etc.

I guess the native compiler code was kept so terse (one letter function names, no symbolic constants used for the emitted tokens) in order to enable self-hosting, but it really makes the code hard to follow. I would have rather given up self-hosting for a more readable/serviceable source code of the native compiler. For self-hosting, one could still implement a tool in the hosted compiler that parses the native compiler code and produces a minimized version. There are also very few comments, ironically some of those that are included are rather superfluous:

J(  ) {

   K( );
   case '&': J( ); stri(20); break;
   case '|': J( ); stri(-20); break;
   default: p--; return;
} /* end J */

Oh, "end J" - really? Thanks for helping me figure that one out! ;) I would rather have known what "J", "K", "20", "-20" are supposed to mean.

Still, fascinating stuff for such a limited machine! :)

Wed Mar 07, 2018 6:09 pm

Joined: Wed Jan 09, 2013 6:54 pm
Posts: 1188
Indeed, multi-pass compilers were quite normal back in the day, and that would be a good way to support a less restricted language.

Wed Mar 07, 2018 6:38 pm

Joined: Sat Oct 28, 2017 12:16 am
Posts: 7
It actually seems that the native compiler is not self-hosting after all, because it uses language features and syntax that are only available in the cross-compiler (as explained in "libc-information.txt").

Thu Mar 08, 2018 8:38 am
Display posts from previous:  Sort by  
Reply to topic   [ 6 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software