ack/lang/b
George Koehler f91bc2804d Tune the installed manual pages.
This commit slightly improves the formatting of the manuals.  My
OpenBSD machine uses mandoc(1) to format manuals.  I check the manuals
with `mandoc -T lint` and fix most of the warnings.  I also make
other changes where mandoc didn't warn me.

roff(7) says, "Each sentence should terminate at the end of an input
line," but we often forgot this rule.  I insert some newlines after
sentences that had ended mid-line.

roff(7) also says that blank lines "are only permitted within literal
contexts."  I delete blank lines.  This removes some extra blank lines
from mandoc's output.  If I do want a blank line in the output, I call
".sp 1" to make it in man(7).  If I want a blank line in the source,
but not the output, I put a plain dot "." so roff ignores it.

Hyphens used for command-line options, like \-a, should be escaped by
a backslash.  I insert a few missing backslashes.

mandoc warns if the date in .TH doesn't look like a date.  Our manuals
had a missing date or the RCS keyword "$Revision$".  Git doesn't
expand RCS keywords.  I put in today's date, 2017-01-18.

Some manuals used tab characters in filled mode.  That doesn't work.
I use .nf to turn off filled mode, or I use .IP in man(7) to make the
indentation without a tab character.

ack(1) defined a macro .SB but never used it, so I delete the
definition.  I also remove a call to the missing macro .RF.

mandoc warns about empty paragraphs.  I deleted them.  mandoc also
warned about these macro pairs in anm(1):

    .SM
    .B text

The .SM did nothing because the .B text is on a different line.  I
changed each pair to .SB for small bold text.

I make a few other small changes.
2017-01-18 23:02:30 -05:00
..
compiler Tune the installed manual pages. 2017-01-18 23:02:30 -05:00
distr Initial EM-ification; start threading word size stuff through the code. 2016-11-27 11:58:59 +01:00
lib Allow programs to override binit() (so they can register their own modules). 2016-12-31 17:39:51 +00:00
LICENSE Initial EM-ification; start threading word size stuff through the code. 2016-11-27 11:58:59 +01:00
README.md Initial EM-ification; start threading word size stuff through the code. 2016-11-27 11:58:59 +01:00

A B Compiler

abc is a compiler for the B Programming Language that targets x86_32 processors. It is currently tested under Linux but should work (or at least be easily ported) to other UNIX-like systems. The code is based on an early C compiler (last1120c) by Dennis Ritchie.

Documentation

  • The Programming Language B

  • B Reference by Ken Thompson describes a presumably earlier variant of B, which is slightly different from the one described above. The compiler cannot understand it, but I plan to implement a compatibility mode (the differences are minor).

Implementation

Since B was first implemented for machines with word addressing, some hacking was required to make it work on the byte addressed x86. Addresses filled in by the linker are always byte addresses, so pointers to these addresses are collectively stored at the end of the .data section and are then converted to word addresses at runtime, before main() is called.

The generated assembly is very inefficient, not even constant expressions are reduced at compile time. Also I/O is currently not buffered.

How to use

The installation requires a little configuration: 'abc' is a frontend for the actual compiler which feels somewhat like gcc (it also handles assembling and linking). Before you can use it, set it's BDIR variable to the directory of the B compiler. In the Makefile, change the directory of the 'install' rule to wherever you want your 'abc' file to reside. Then type

make install libs

which compiles the compiler 'b', installs the 'abc' frontend and compiles the B runtime and library (brt.o and lib.o).

To compile and link a B program, simply type

abc -o outfile file1.b [file2.b ...]

If you want to compile and assemble only:

abc -c file1.b [file2.b ...]

or generate only the assembly:

abc -S file1.b [file2.b ...]

Examples of B programs are in the 'examples' directory, they are mostly from Brian Kernighan's tutorial.

Bugs

Since command line parameters aren't passed word-aligned, B can't handle them easily. brt.s copies the strings to another location and aligns them, the space is not dynamically allocated however and only 256 bytes are available by default.

The library is incomplete but has some of the most important functions.

I have only tested the compiler on an x86_64 gentoo system.