AnyCPU
http://anycpu.org/forum/

CC8 - A native C compiler for the PDP-8 running OS/8
http://anycpu.org/forum/viewtopic.php?f=8&t=509
Page 1 of 1

Author:  BigEd [ Mon Mar 05, 2018 3:43 pm ]
Post subject:  CC8 - A native C compiler for the PDP-8 running OS/8

.
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.

Quote:
...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.


Attachments:
CC-Update.tar.gz [756.73 KiB]
Downloaded 291 times

Author:  hmn [ Tue Mar 06, 2018 10:35 pm ]
Post subject:  Re: CC8 - A native C compiler for the PDP-8 running OS/8

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

Author:  BigEd [ Wed Mar 07, 2018 9:45 am ]
Post subject:  Re: CC8 - A native C compiler for the PDP-8 running OS/8

hmm, OK, I confess I didn't look at the source...

Author:  hmn [ Wed Mar 07, 2018 6:09 pm ]
Post subject:  Re: CC8 - A native C compiler for the PDP-8 running OS/8

Quote:
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:

Code:
J(  ) {

   K( );
   switch(*p++){
   case '&': J( ); stri(20); break;
   case '|': J( ); stri(-20); break;
   default: p--; return;
   }
   stkp--;
} /* 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! :)

Author:  BigEd [ Wed Mar 07, 2018 6:38 pm ]
Post subject:  Re: CC8 - A native C compiler for the PDP-8 running OS/8

Indeed, multi-pass compilers were quite normal back in the day, and that would be a good way to support a less restricted language.

Author:  hmn [ Thu Mar 08, 2018 8:38 am ]
Post subject:  Re: CC8 - A native C compiler for the PDP-8 running OS/8

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").

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/