The Unix Heritage Society mailing list
 help / color / mirror / Atom feed
* [TUHS] What is the intermediate code generated by the bc interpreter?
@ 2025-05-11 10:28 Jackson Helie G
  2025-05-11 15:06 ` [TUHS] " Tom Teixeira
  2025-05-12  6:26 ` Thalia Archibald via TUHS
  0 siblings, 2 replies; 6+ messages in thread
From: Jackson Helie G @ 2025-05-11 10:28 UTC (permalink / raw)
  To: tuhs

[-- Attachment #1: Type: text/plain, Size: 300 bytes --]

I checked Dennis M. Ritchie's "Users' Reference to B" and found an example
of implementing a B program at the bottom of the manual. It said that bc
generates intermediate code suitable for ba, and then ba generates assembly
code. So, I am curious about what the intermediate code generated by bc is?

[-- Attachment #2: Type: text/html, Size: 341 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [TUHS] Re: What is the intermediate code generated by the bc interpreter?
  2025-05-11 10:28 [TUHS] What is the intermediate code generated by the bc interpreter? Jackson Helie G
@ 2025-05-11 15:06 ` Tom Teixeira
  2025-05-12  6:26 ` Thalia Archibald via TUHS
  1 sibling, 0 replies; 6+ messages in thread
From: Tom Teixeira @ 2025-05-11 15:06 UTC (permalink / raw)
  To: tuhs

[-- Attachment #1: Type: text/plain, Size: 1923 bytes --]

On 5/11/25 6:28 AM, Jackson Helie G wrote:
> I checked Dennis M. Ritchie's "Users' Reference to B" and found an 
> example of implementing a B program at the bottom of the manual. It 
> said that bc generates intermediate code suitable for ba, and then ba 
> generates assembly code. So, I am curious about what the intermediate 
> code generated by bc is?

I found this reference 
(https://www.softwarepreservation.org/projects/BCPL/cambridge/Richards-Bootstrapping_BCPL-1973.pdf) 
written by Martin Richards about the intermediate code of BCPL. I never 
saw or used B, but this is one possibility.

But it seems very different from C compilers prior to the Portable C 
Compiler, even though code generation was table driven 
(https://wolfram.schneider.org/bsd/7thEdManVol2/ctour/ctour.html).

Note, before the RTS group at Project MAC started using UNIX, we had a 
home-written operating system for PDP-11/45 and PDP-11/70. I got a BCPL 
compiler from somewhere and made some enhancements - such as direct 
support for external variables and routines using a linker rather than 
the pure BCPL global array. When RTS got access to a VAX-11/780 running 
VMS, I was able to modify the Sixth or Seventh edition C compiler to 
generate code for the VAX-11/780 and wrote enough of a compatibility 
library to port various C programs to VMS. All that vanished once we 
were able to install 4BSD on the VAX-11/780. The machine was shared by 
the people doing the NIL project (New Implementation of LISP) on the 
VAX. I don't remember the details, but this paper coauthored by Guy 
Steele (https://www.dreamsongs.com/Files/HOPL2-Uncut.pdf) implies that 
NIL shifted their efforts to a different target machine: "In 1978, 
Gabriel and Guy Steele set out to implement NIL [Brooks, 1982a] on the 
S-1 Mark IIA, a supercomputer being designed and built by the Lawrence 
Livermore National Laboratory [Correll, 1979; Hailpern, 1979]."

[-- Attachment #2: Type: text/html, Size: 2967 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [TUHS] Re: What is the intermediate code generated by the bc interpreter?
  2025-05-11 10:28 [TUHS] What is the intermediate code generated by the bc interpreter? Jackson Helie G
  2025-05-11 15:06 ` [TUHS] " Tom Teixeira
@ 2025-05-12  6:26 ` Thalia Archibald via TUHS
  2025-05-12  7:14   ` Angelo Papenhoff
  1 sibling, 1 reply; 6+ messages in thread
From: Thalia Archibald via TUHS @ 2025-05-12  6:26 UTC (permalink / raw)
  To: Jackson Helie G; +Cc: tuhs

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [TUHS] Re: What is the intermediate code generated by the bc interpreter?
  2025-05-12  6:26 ` Thalia Archibald via TUHS
@ 2025-05-12  7:14   ` Angelo Papenhoff
  2025-05-12  8:10     ` Thalia Archibald via TUHS
  0 siblings, 1 reply; 6+ messages in thread
From: Angelo Papenhoff @ 2025-05-12  7:14 UTC (permalink / raw)
  To: TUHS

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [TUHS] Re: What is the intermediate code generated by the bc interpreter?
  2025-05-12  7:14   ` Angelo Papenhoff
@ 2025-05-12  8:10     ` Thalia Archibald via TUHS
  2025-05-12 15:21       ` Sebastien F4GRX
  0 siblings, 1 reply; 6+ messages in thread
From: Thalia Archibald via TUHS @ 2025-05-12  8:10 UTC (permalink / raw)
  To: Angelo Papenhoff; +Cc: TUHS

On May 12, 2025, at 00:14, Angelo Papenhoff wrote:
> 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.

Very interesting! Is your take on the intermediate code the cases in
pdp10_its/ba10.b:cexpr?

In your compilers, you hack in preprocessing with sed. Do you know for sure that
B had no preprocessor? It seems inconceivable now, as even `as` had constants.

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

I just watched your talk. Now the B intermediate language makes a lot more sense
and I want to write a B compiler :).

Have you done any further archaeology work on NB since what you have at
<http://squoze.net/NB/>? How did you analyze the old tapes? Is there anything
left there to examine?

Thalia

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [TUHS] Re: What is the intermediate code generated by the bc interpreter?
  2025-05-12  8:10     ` Thalia Archibald via TUHS
@ 2025-05-12 15:21       ` Sebastien F4GRX
  0 siblings, 0 replies; 6+ messages in thread
From: Sebastien F4GRX @ 2025-05-12 15:21 UTC (permalink / raw)
  To: Thalia Archibald, Angelo Papenhoff; +Cc: TUHS

Hello,

On 12/05/2025 10:10, Thalia Archibald via TUHS wrote:
> I just watched your talk. Now the B intermediate language makes a lot more sense
> and I want to write a B compiler :).

I did that, it was fun. I did a recursive descent parser (from scratch, 
so without yacc), and made it generate some C code.

 From a practical aspect, having tasted C for years, I find B quite 
annoying and pointless outside the gigantic historical interest.

Sebastien



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-05-12 15:21 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-05-11 10:28 [TUHS] What is the intermediate code generated by the bc interpreter? Jackson Helie G
2025-05-11 15:06 ` [TUHS] " Tom Teixeira
2025-05-12  6:26 ` Thalia Archibald via TUHS
2025-05-12  7:14   ` Angelo Papenhoff
2025-05-12  8:10     ` Thalia Archibald via TUHS
2025-05-12 15:21       ` Sebastien F4GRX

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).