[TUHS] What is the intermediate code generated by the bc interpreter?

Angelo Papenhoff aap at papnet.eu
Mon May 12 17:14:14 AEST 2025


Hi,
thanks for mentioning my project!
I recently ported the compiler to ITS on the PDP-10 and had to revisit
the question of the intermediate code.
My take is that it was probably an ASCII code and not all too different
from PDP-7 assembly. One striking difference between the PDP-7 and
PDP-11 interpreter that have survived is the handling of lvalues. Taking
the address of something is done by an operator (u1) in the PDP-7
interpreter, whereas on the PDP-11 this is handled somewhere in the
compilation process, and in addition to the automatic (a) and external
(x) operators there are now lvalue versions of them (va and vx).
I very very strongly suspect that this is handled by the B assembler and
not the compiler.

Two other questions are where the 'i'-versions of the a/x/c operators
and the control flow of the conditional ?: operator were handled.
For the latter i concluded it had to be the assembler, although the
label numbers in printf.o are in line with those that would have been
generated by the compiler. In contrast, the first and second pass of
the C compiler use different ranges of labels.

Unfortunately all these questions appeared and became clearer only over time
and as a result there are various incarnations of my reconstructed compiler
in the github repo....I should really make a push to clean it up a bit
better, it's a complete mess.

You may also want to check out my talk on B at VCFB 2024:
https://www.youtube.com/watch?v=OLDTPlLa1bI

Cheers,
aap

On 12/05/25, Thalia Archibald via TUHS wrote:
> On May 11, 2025, at 03:28, Jackson Helie G wrote:
> > I am curious about what the intermediate code generated by bc is?
> 
> 
> Hi,
> 
> I don’t have a direct answer, but I can refer you to Angelo Papenhoff’s work in
> reconstructing B, which is probably the most extensive and faithful to the
> original. He’s written B compilers[0] in C for bootstrapping purposes, another
> in B, and reconstructed one in B which works on Unix V1. The intermediate code I
> think you’re referring to is the threaded code, which Angelo covers on his
> site[1], from having reverse engineered libb and bilib. There was some
> discussion on this list about it some years ago[2]. His work is probably the
> best resource.
> 
> [0]: https://github.com/aap/b
> [1]: http://squoze.net/B/
> [2]: https://www.tuhs.org/pipermail/tuhs/2019-April/017750.html
> 
> Thalia


More information about the TUHS mailing list