The B Compiler Suite in Java consists of the B Compiler proper
(b-comp
) that compiles B source to virtual machine code, an
assembler (b-as
), a linker (b-link
), a disassembler (b-dis
) and
a virtual machine interpreter (b-vm
).
The suite is implemented in non-idiomatic Java, so that it should be quite easy to reimplement it in C, or even B itself. This means that classes are used like structures (records) or namespaces. Instead of getters and setters, public variables are used. Thus, Java is used primarily for its collection library, string handling and memory management.
The aim of this project is to provide a historically accurate implementation of B. Since a crucial property is word addressing instead of byte addressing, a word-addressed virtual machine has been chosen as target instead of a modern byte-addressed architecture such as x86_64. A translation to C would have been rather pointless.
See the file INSTALL.txt
.
.b
: B source file
.bs
: Assembler file
.bo
: Object file
b-comp
[-h
|--help
] [-o
FILE.bs
] FILE.b
b-as
[-h
|--help
] [-o
FILE.bs
] FILE.bo
b-link
[-h
|--help
] [-s
SIZE] [-o
FILE] FILE.bo
...
Creates an executable from the specified object files. The b-vm
interpreter is added as #/usr/bin/b-vm
as the first line of
executable file, so that it can be run directly.
The library libb.bo
is always automatically included as first object
file.
SIZE is an integer that gives the default memory size (in MB) when running with the VM interpreter.
b-dis
FILE
FILE is the name of executable generated by b-link
.
b-vm
[-h
|--help
] [-s
SIZE] FILE
FILE is the name of executable generated by b-link
.
SIZE is an integer that gives the memory size (in MB).
The language as implemented follows closely the User's Reference to B (Thompson, 1972).
The following lists limitations and deviations of the implementation compared to Thompson, 1972.
-
The wordsize of the VM is 32 bit instead of the 16 bit on the PDP-11. This also means there are 4 characters in each word. Within a word, character are ordered from LSB to MSB.
-
Most functions are implemented as system calls.
-
Supported functions:
- char
- chdir
- close
- creat
- ctime
- execl
- execv
- exit
- getchar
- halt
- lchar
- mkdir
- open
- printf
- printn
- putchar
- read
- seek
- time
- unlink
- write
-
Unsupported functions:
- chmod
- chown
- fork
- fstat
- getuid
- gtty
- link
- setuid
- stat
- stty
- wait
-
The maximum number of arguments in the external vector
argv
is 20. -
Internal labels cannot be assigned to variables.