Packages with Gritpack
An Oberon 07z program is a Gritpack package. Gritpack is a package manager for projects that use more than one language, so an Oberon package sits as comfortably next to C as next to other Oberon packages.
A package's manifest names it, says which language it is written in with dialect = "oberon/07z", and lists its dependencies. The standard library, TOML and HTTP are ordinary packages: oberon07z-stdlib, oberon07z-toml and oberon07z-http.
[package]
name = "hello"
version = "0.1.0"
dialect = "oberon/07z"
encoding = "source/utf8"
files = ["src/**"]
[dependencies]
oberon07z-stdlib = "0.1.0"
Several packages can live in one repository as a workspace. The standard library's own repository is one: the library and its packages are published, and the clients that test them stay internal.
schema = 2
[resolution]
workspace = "prefer-compatible"
[[members]]
path = "stdlib"
adapter = "native"
role = "publishable"
[[members]]
path = "conformance/arena"
adapter = "native"
role = "internal-only"
The compiler doesn't go looking for files. It asks Gritpack for the exact sources of the program, checks each one against its recorded digest, and compiles exactly those. The Gritpack documentation covers packages, workspaces and publishing.
Submodules
In Wirth's Oberon-07, a module's name is one identifier, and every module of every library shares one flat namespace. In Oberon 07z a name can have dotted parts, so a library can group its modules the way you'd group directories:
| Module | What it is |
|---|---|
IO.Reader | One reader for standard input, files and memory |
IO.Console | Standard output and error |
IO.Fmt | Decimal and hex output |
Net.TCP | TCP connections |
Text.Parse | Integers from text |
An import names the full path, and can give it a short alias. IMPORT R := IO.Reader lets the module write R.Read.
The MODULE line names the module, not the file's path. In the standard library, src/Fmt/HexByte.ob is part of IO.Fmt, and src/Parse/Integer.ob is part of Text.Parse. Files go where they make sense to the people who work on them.
One module, several files
A module can be written across several files. Each file starts with the same MODULE line, and together they make one module. The standard library's Arena is eight files, one for each operation:
stdlib/src/Arena/ Open.ob MODULE Arena; Alloc.ob MODULE Arena; Put.ob MODULE Arena; Get.ob MODULE Arena; Copy.ob MODULE Arena; CopyIn.ob MODULE Arena; CopyOut.ob MODULE Arena; Release.ob MODULE Arena;
The files of a module share everything inside it. A procedure in one file can call a private procedure in another, while importers see only what the module exports. The compiler rejects a name declared twice, and the order of the files doesn't matter.
To everyone who imports it, Arena is one module with one interface. How many files it takes to write is the module's own business.
Testing
Because a module can span files, and a file's path doesn't decide its module, a module's tests can be part of the module itself, kept in their own directory:
src/Parse.ob MODULE Parse; the module test/Parse.ob MODULE Parse; its tests
A test written this way is inside the module, so it can call the module's private procedures and check its internal state directly. Nothing is exported just so a test can reach it, and the module's interface stays exactly what its importers need.
Tests that check the module from outside, through its interface alone, go in a separate client package. The standard library tests every module that way, with a client that imports it and runs its documented success and failure cases.
Platforms
The same idea keeps platform code apart. A module's shared code goes in one file, and the code that differs between systems goes in a fragment of the same module for each system:
src/Files.ob MODULE Files; shared code linux/Files.ob MODULE Files; Linux windows/Files.ob MODULE Files; Windows
Each platform's fragment implements the same private procedures that the shared code calls. Importers see one Files module with one interface on every system, and there is no conditional compilation and no preprocessor: each platform's code is plain Oberon, in a file of its own.
Today Oberon 07z builds native executables for Linux on x86-64.