BESM-6 was a Soviet mainframe computer produced from the late 1960s through the 1980s. It was one of the most powerful computers of its era in the Eastern Bloc, and it supported a rich set of programming languages: Algol, Fortran, Pascal, and several assemblers. A modern port of the B language (the predecessor of C) is also supported.
besmc is a command-line tool that lets you write programs in those same languages on
a modern computer and compile them into BESM-6 executables. Under the hood it uses the
dubna simulator, which runs the original BESM-6 compilers
exactly as they ran on the real hardware.
Before you can use besmc you need two things installed:
-
The dubna simulator — download and install it from github.com/besm6/dubna. The
dubnacommand must be on your$PATH. -
The Rust compiler — needed only to build
besmcitself. Install it from rust-lang.org/tools/install.
make
make installThe besmc binary is installed to ~/.cargo/bin/besmc.
Save this Pascal program as hello.pascal:
program main(output);
_(
writeln('Hello, Pascal!');
stop;
_).Note: This Pascal dialect uses
_(and_).as block delimiters instead of the usualbegin/end.
Compile it:
besmc hello.pascalTwo files are created:
| File | What it is |
|---|---|
hello.exe |
The executable program |
hello.lst |
The compiler listing (output from the BESM-6 compiler, useful for diagnosing errors) |
Run the program:
$ ./hello.exe
HELLO, PASCAL!besmc recognises the following file extensions:
| Extension | Language |
|---|---|
.pascal |
Pascal |
.pas |
Pascal-re (requires pascompl on your $PATH) |
.ftn |
Fortran-ГДP |
.fortran |
Fortran Dubna |
.forex |
Forex |
.algol |
Algol-ГДP |
.assem |
Assembler Madlen |
.madlen |
Assembler Madlen-3.5 |
.bemsh |
Assembler БЕМШ (source code written in Cyrillic) |
.b |
B (modern port) |
.obj |
Pre-compiled object library (for linking) |
Working "Hello, World!" examples for every language are in the examples/ directory, with detailed explanations in examples/README.md.
By default besmc produces a ready-to-run .exe. If you want to compile a source file
without linking it (for example, to combine it later with code written in another language),
use the -c flag:
besmc -c hello.pascalThis produces hello.obj instead of hello.exe. Object files can be passed to a later
besmc invocation for linking.
One of BESM-6's strengths was that programs could freely mix languages — a Pascal main
program could call a Fortran subroutine, for instance. Here is how to do that with besmc.
Step 1 — Write the Pascal main program (caller.pascal):
program main (output);
procedure hello; fortran;
_(
hello;
stop;
_).The procedure hello; fortran; declaration tells the Pascal compiler that hello is
implemented in Fortran.
Step 2 — Write the Fortran subroutine (callee.ftn):
subroutine hello
print 1000
1000 format('Hello Fortran from Pascal!')
endStep 3 — Compile each file separately, then link them together:
besmc -c caller.pascal # produces caller.obj
besmc -c callee.ftn # produces callee.obj
besmc caller.obj callee.obj # links both into caller.exeRun the result:
$ ./caller.exe
HELLO FORTRAN FROM PASCAL!| Option | Description |
|---|---|
-c / --compile |
Compile to an object file (.obj); do not link |
-o FILE / --output FILE |
Set the output file name (default: derived from the first input file) |
-t / --save-temps |
Keep intermediate files (.dub script, output.bin, persNN.bin) |
-h / --help |
Print help |
To verify that everything is working:
make testYou should see all tests pass:
running 52 tests
test test::test_exe::test_pascal_exe ... ok
test test::test_exe::test_fortran_exe ... ok
...
test result: ok. 51 passed; 0 failed; 0 ignored