Skip to content

Hydrogen standard-library design plan

Design proposal: The packages and APIs below are planned, not installable implementations.

Development reference from Hylang-Stdlib. Commands and source paths on this page are relative to that repository checkout. For current task status, use the development project.

This document proposes future packages and APIs. None of the Hydrogen.* or Australis.* library layers shown here are installable implementations in this repository. Existing compiler/runtime System.* builtins are documented in the usage guide and API reference. Code in this plan illustrates proposed contracts rather than runnable current examples.

This is a design sequence, not a completion checklist. A phase is complete only when its named Hydrogen.* or Australis.* package builds from this repository, its example runs on the stated target, and package tests pass. Existing compiler builtins and Australis kernel services do not satisfy that gate by themselves.

Work in this plan Owning repository Current boundary
Language syntax, module/package resolution, native code generation, target profiles, and diagnostics under “Required Compiler Support” Hylang-Compiler The SDK and native compiler support different subsets. Project references and source closure exist; a standard-library lookup path and installable Hydrogen.* packages do not.
Hydrogen.Core, Memory, Text, Runtime, and IO code, contracts, and package tests Hylang-Stdlib Proposed here; no .hyproj packages are shipped.
Kernel and userspace syscall contracts, access checks, and native application loading Australis-OS AUEX services and a small AUN1 ring 3 path exist. General Hydrogen AUN1 output remains compiler work.
Australis.Kernel, Userspace, and UI wrappers Hylang-Stdlib, after the relevant OS contracts exist Proposed APIs must match tested OS interfaces.

The first actionable library gate is a tiny Hydrogen.Core project consumed by another project, using a compiler-supported import form and a test on each claimed target. The illustrative use examples below are not working build instructions yet.

Build a fully usable Hydrogen standard library in small, practical phases.

Hydrogen should be standalone. It should not depend on the C standard library, .NET, the CLR, or another language runtime.

The standard library should grow from the smallest possible freestanding core into a complete Australis OS development platform.


Hydrogen.Core // always available, no OS dependency
Hydrogen.Memory // allocators, slices, buffers
Hydrogen.Runtime // optional runtime services
Hydrogen.Text // strings, UTF-8, formatting
Hydrogen.IO // platform-backed IO
Australis.Kernel // kernel-only APIs
Australis.Userspace // app/service APIs
Australis.UI // windowing/UI APIs

Every library layer should clearly state:

  • Whether it works in freestanding mode
  • Whether it requires heap allocation
  • Whether it requires Australis OS
  • Whether it requires the Hydrogen runtime
  • Whether it is safe, unsafe, or mixed

Create the rules and structure before adding lots of APIs.

This phase prevents the standard library from becoming messy later.

/std
/Hydrogen.Core
/Hydrogen.Memory
/Hydrogen.Runtime
/Hydrogen.Text
/Hydrogen.IO
/Australis.Kernel
/Australis.Userspace
/Australis.UI
  • Naming convention: PascalCase
  • File/module structure
  • Public/private/internal rules
  • How imports work
  • How docs are generated
  • How tests are written
  • How freestanding builds exclude unavailable APIs
  • module imports
  • public/private visibility
  • basic package/project references
  • build targets
  • standard library lookup path

This phase is complete when a Hydrogen file can import a standard library module:

use Hydrogen.Core;
public function Main(): int {
return 0;
}

Create the always-available base library.

Hydrogen.Core should work everywhere:

  • kernel mode
  • userspace mode
  • freestanding mode
  • runtime-enabled mode
  • runtime-disabled mode

It should have no OS dependency.

Hydrogen.Core.Types
Hydrogen.Core.Result
Hydrogen.Core.Option
Hydrogen.Core.Math
Hydrogen.Core.Diagnostics
Hydrogen.Core.Convert
Hydrogen.Core.Bitwise
Hydrogen.Core.Compare
Hydrogen.Core.Panic

Support common type aliases and helpers:

u8
u16
u32
u64
i8
i16
i32
i64
usize
isize
bool
char
byte
void
Result<T, E>
Ok(value)
Error(error)

Example:

function Divide(a: int, b: int): Result<int, string> {
if (b == 0) {
return Error("Cannot divide by zero");
}
return Ok(a / b);
}
Option<T>
Some(value)
None

Example:

function FindUser(id: int): Option<User> {
...
}
Panic("Something went wrong");

Behaviour depends on target:

  • freestanding: halt or trap
  • kernel: kernel panic
  • userspace: terminate process
  • debug: include file/line if available

Start small:

Math.Min(a, b)
Math.Max(a, b)
Math.Abs(x)
Math.Clamp(value, min, max)

Avoid floating-point-heavy APIs until later.

Useful for OS work:

Bits.Set(value, bit)
Bits.Clear(value, bit)
Bits.Toggle(value, bit)
Bits.Has(value, bit)
Bits.AlignUp(value, alignment)
Bits.AlignDown(value, alignment)

Basic explicit conversions:

Convert.ToInt(...)
Convert.ToUInt(...)
Convert.ToBool(...)

Do not make conversions too magical.

  • generics
  • basic structs/enums
  • static functions
  • compile-time constants
  • basic error messages

You can write small Hydrogen programs without touching OS APIs:

use Hydrogen.Core;
function Main(): int {
var result = Math.Clamp(150, 0, 100);
return result;
}

Create safe and unsafe memory tools.

This is one of the most important libraries for Hydrogen because the language is low-level and OS-focused.

Hydrogen.Memory.Pointer
Hydrogen.Memory.Slice
Hydrogen.Memory.Buffer
Hydrogen.Memory.Allocator
Hydrogen.Memory.FixedBuffer
Hydrogen.Memory.Layout
Hydrogen.Memory.Unsafe
ptr<T>
null
&value
*pointer

Helper APIs:

Pointer.IsNull(pointer)
Pointer.Offset(pointer, count)
Pointer.Cast<TFrom, TTo>(pointer)

A slice is a pointer plus a length.

slice<T>

Example:

function Fill(buffer: slice<byte>, value: byte): void {
for (var i = 0; i < buffer.Length; i++) {
buffer[i] = value;
}
}

Owned memory regions:

Buffer<T>
Buffer<byte>

Possible behaviour:

  • stores pointer
  • stores length
  • knows allocator
  • can be disposed/freed

Example:

var buffer = Buffer<byte>.Create(1024);
defer buffer.Free();

Hydrogen should not assume one allocator.

interface IAllocator {
function Allocate(size: usize, alignment: usize): ptr<byte>;
function Free(pointer: ptr<byte>): void;
}

Default allocators can come later.

sizeof<T>()
alignof<T>()
offsetof<T>("Field")

Example:

comptime assert(sizeof<GdtEntry>() == 8);
Memory.Copy(dest, src, count)
Memory.Move(dest, src, count)
Memory.Set(dest, value, count)
Memory.Zero(dest, count)
Memory.Compare(a, b, count)

These must be Hydrogen-native, not libc wrappers.

  • pointer types
  • unsafe
  • defer
  • fixed-size arrays
  • basic compile-time functions
  • optional bounds checks

You can allocate, use, and free memory in Hydrogen:

use Hydrogen.Memory;
function Main(): int {
var buffer = Buffer<byte>.Create(1024);
defer buffer.Free();
Memory.Zero(buffer.Data, buffer.Length);
return 0;
}

Create a clear, honest text model.

Hydrogen strings should be UTF-8 by default, but the library must not pretend that bytes and characters are the same thing.

Hydrogen.Text.String
Hydrogen.Text.Utf8
Hydrogen.Text.Rune
Hydrogen.Text.Format
Hydrogen.Text.Parse
Hydrogen.Text.Ascii
Hydrogen.Text.StringBuilder

Recommended model:

string // UTF-8 text
byte // raw 8-bit value
char/rune // Unicode scalar value

Avoid making string[index] mean “character at index”.

Prefer:

text.ByteLength
text.ByteAt(index)
text.RuneCount()
text.RuneAt(index)
text.Runes()

Very useful early on:

Ascii.IsDigit(c)
Ascii.IsLetter(c)
Ascii.IsWhitespace(c)
Ascii.ToUpper(c)
Ascii.ToLower(c)
Utf8.Validate(bytes)
Utf8.DecodeNext(bytes, index)
Utf8.EncodeRune(rune, buffer)

Start simple:

Format.Int(value)
Format.UInt(value)
Format.Hex(value)
Format.Bool(value)

Later:

String.Format("Value: {0}", value)
Parse.Int("123")
Parse.UInt("123")
Parse.Bool("true")

Return Result, not exceptions:

var value = try Parse.Int("123");

For runtime/userspace builds:

var builder = StringBuilder.Create();
defer builder.Free();
builder.Append("Hello ");
builder.Append("Hydrogen");
var text = builder.ToString();
  • string literals
  • byte arrays
  • slices
  • Result
  • optional heap allocation
  • iteration

You can format and parse basic text without libc:

use Hydrogen.Text;
function Main(): int {
var number = try Parse.Int("42");
var text = Format.Int(number);
return 0;
}

Create optional runtime services.

This layer should not be required for freestanding or kernel code unless explicitly enabled.

Hydrogen.Runtime.Startup
Hydrogen.Runtime.Heap
Hydrogen.Runtime.GC
Hydrogen.Runtime.Panic
Hydrogen.Runtime.TypeInfo
Hydrogen.Runtime.Debug
Hydrogen.Runtime.Console
Hydrogen.Runtime.Threading

Responsible for:

  • setting up runtime state
  • calling Main
  • handling return codes
  • calling global initializers if supported

A runtime heap for normal applications.

Runtime.Heap.Allocate(size)
Runtime.Heap.Free(pointer)

GC should be optional.

Project config example:

{
"runtime": "native",
"gc": false
}

or:

{
"runtime": "managed",
"gc": true
}

Runtime-enabled panic can include:

  • message
  • file
  • line
  • stack trace
  • process termination

Optional future feature:

typeof<T>()
value.GetType()

Should not be required for low-level builds.

Runtime-level console for debugging:

Console.Write("Hello");
Console.WriteLine("Hydrogen");

In freestanding builds, this should either be unavailable or target-specific.

  • runtime profile selection
  • entrypoint generation
  • optional metadata
  • optional GC hooks
  • build modes

A normal Hydrogen userspace app can start, allocate memory, print text, and exit.

use Hydrogen.Runtime;
public function Main(): int {
Console.WriteLine("Hello from Hydrogen Runtime");
return 0;
}

Create the APIs required to write Australis OS kernel components in Hydrogen.

This layer should be available only in kernel/freestanding targets.

Australis.Kernel.Boot
Australis.Kernel.CPU
Australis.Kernel.Interrupts
Australis.Kernel.Memory
Australis.Kernel.Paging
Australis.Kernel.Ports
Australis.Kernel.Devices
Australis.Kernel.Debug
Australis.Kernel.Scheduler
Australis.Kernel.Syscalls
Australis.Kernel.Panic
@entry
function KernelStart(info: ptr<BootInfo>): void {
Kernel.Main(info);
}
CPU.Halt()
CPU.DisableInterrupts()
CPU.EnableInterrupts()
CPU.ReadCr3()
CPU.WriteCr3(value)

Some of these require unsafe.

For x86/x64 port IO:

Ports.In8(port)
Ports.Out8(port, value)
Ports.In16(port)
Ports.Out16(port, value)
@interrupt(14)
function PageFault(frame: ptr<InterruptFrame>): void {
Panic.Fatal("Page fault");
}

APIs:

Interrupts.Register(vector, handler)
Interrupts.Enable()
Interrupts.Disable()
PhysicalMemory.AllocatePage()
PhysicalMemory.FreePage(page)
VirtualMemory.Map(...)
VirtualMemory.Unmap(...)
Paging.MapPage(virtualAddress, physicalAddress, flags)
Paging.UnmapPage(virtualAddress)
Paging.Flush(address)
KernelDebug.WriteLine("Booting Australis...");

This might write to serial, framebuffer, or debug console.

Kernel.Panic("Fatal kernel error");

Should halt safely.

  • freestanding mode
  • no libc
  • no mandatory heap
  • inline assembly or compiler intrinsics
  • interrupt attributes
  • section attributes
  • packed structs
  • fixed memory layout

You can write a minimal kernel entry in Hydrogen:

use Australis.Kernel;
@entry
function KernelStart(info: ptr<BootInfo>): void {
KernelDebug.WriteLine("Australis booted from Hydrogen");
CPU.HaltLoop();
}

Create platform-backed input/output.

This layer is not always available. It depends on the current target.

For userspace apps, it talks to Australis OS services. For hosted builds, it may talk to the host platform. For kernel builds, it should generally be unavailable or replaced by kernel debug output.

Application source uses one recognizable API surface. Each backend maps that surface to its platform runtime or operating-system calls. Target namespaces are reserved for capabilities whose behavior cannot be expressed portably.

Hydrogen.IO.File
Hydrogen.IO.Directory
Hydrogen.IO.Path
Hydrogen.IO.Stream
Hydrogen.IO.Console
Hydrogen.IO.Device
File.Open(path)
File.ReadAllText(path)
File.ReadAllBytes(path)
File.WriteAllText(path, text)
File.Exists(path)
File.Delete(path)

Use Result:

var text = try File.ReadAllText("config.txt");
Directory.Exists(path)
Directory.Create(path)
Directory.List(path)
Path.Join(a, b)
Path.Extension(path)
Path.FileName(path)
Path.DirectoryName(path)
interface Stream {
function Read(buffer: slice<byte>): Result<usize, IOError>;
function Write(buffer: slice<byte>): Result<usize, IOError>;
function Close(): void;
}
Console.WriteLine("Hello");
Console.ReadLine()
  • Result
  • strings
  • slices
  • runtime or platform syscall support
  • interfaces or traits

A userspace Hydrogen app can read/write files and print output.

use Hydrogen.IO;
function Main(): int {
var text = try File.ReadAllText("hello.txt");
Console.WriteLine(text);
return 0;
}

Create the standard APIs for Australis OS applications and services.

This layer should wrap Australis system calls in safe Hydrogen APIs.

Australis.Userspace.Process
Australis.Userspace.Thread
Australis.Userspace.Syscall
Australis.Userspace.Permissions
Australis.Userspace.Environment
Australis.Userspace.Time
Australis.Userspace.Services
Australis.Userspace.App
Process.CurrentId()
Process.Exit(code)
Process.Spawn(path, args)
Thread.Sleep(ms)
Thread.Start(function)
Thread.CurrentId()

Low-level syscall wrapper:

Syscall.Invoke(number, arg1, arg2, arg3)

Most users should not need this directly.

Permissions.Has("filesystem.read")
Permissions.Request("network")
Environment.Get("HOME")
Environment.Args()
Environment.CurrentDirectory()
Time.Now()
Time.UtcNow()
Time.Sleep(ms)
App.Name()
App.PackageId()
App.Version()
  • target-aware builds
  • syscall attributes or wrappers
  • project/app metadata
  • Result
  • optional async later

A Hydrogen Australis app can interact with the OS without manually calling syscalls.

use Australis.Userspace;
function Main(): int {
Console.WriteLine(App.Name());
Thread.Sleep(1000);
return 0;
}

Create the standard UI layer for Hydrogen applications on Australis OS.

This should come after userspace APIs are stable.

Australis.UI.App
Australis.UI.Window
Australis.UI.View
Australis.UI.Controls
Australis.UI.Layout
Australis.UI.Input
Australis.UI.Graphics
Australis.UI.Theme
Australis.UI.Events
var app = UIApp.Create();
app.Run();
var window = Window.Create("My App", 800, 600);
window.Show();

Start small:

Button
Label
TextBox
Panel
Image
ListView

Example:

var button = Button.Create("Click me");
button.OnClick += function() {
Console.WriteLine("Clicked");
};
StackPanel
Grid
DockPanel
Canvas
Mouse.Position()
Keyboard.IsKeyDown(Key.Enter)
Canvas.DrawRect(...)
Canvas.DrawText(...)
Canvas.DrawImage(...)
Theme.Current()
Theme.SetAccentColor(...)
  • delegates/events or function references
  • objects or structs with methods
  • userspace runtime
  • strings
  • memory management
  • app manifest support

You can build a simple graphical Australis app in Hydrogen:

use Australis.UI;
function Main(): int {
var app = UIApp.Create();
var window = Window.Create("Hydrogen App", 800, 600);
var button = Button.Create("Click me");
button.OnClick += function() {
Console.WriteLine("Hello from UI");
};
window.Content = button;
window.Show();
return app.Run();
}

Make the standard library reliable, documented, tested, and pleasant to use.

Every public type/function should include:

  • description
  • example
  • target availability
  • safety notes
  • allocation behaviour
  • possible errors

Example:

File.ReadAllText(path)
Available:
- Australis userspace
- hosted native mode
Unavailable:
- freestanding
- kernel mode
Allocates:
- yes
Errors:
- FileNotFound
- PermissionDenied
- InvalidUtf8

Create tests for:

  • Core
  • Memory
  • Text
  • Runtime
  • IO
  • Kernel APIs where testable
  • Userspace APIs
  • UI basics

Test standard library under:

freestanding-debug
freestanding-release
kernel-debug
kernel-release
userspace-debug
userspace-release
hosted-debug
hosted-release

Create example projects:

examples/hello-world
examples/file-reader
examples/memory-buffer
examples/kernel-hello
examples/userspace-app
examples/ui-counter

Improve error messages when unavailable APIs are used:

use Hydrogen.IO;

In freestanding mode:

error HY2004: Hydrogen.IO is not available in freestanding builds
help: use Australis.Kernel.Debug for kernel debug output

The standard library feels usable by someone other than you.


Declare a stable first version.

This does not mean the library is finished forever. It means users can trust the core APIs.

  • Result
  • Option
  • Math
  • Panic
  • conversions
  • bit helpers
  • primitive helpers
  • pointers
  • slices
  • buffers
  • allocator interface
  • memory copy/move/set/zero
  • layout helpers
  • UTF-8 validation
  • byte/rune APIs
  • formatting
  • parsing
  • basic StringBuilder
  • startup
  • heap
  • panic handling
  • console
  • debug support
  • optional GC hooks, even if GC is not complete
  • files
  • directories
  • paths
  • streams
  • console
  • boot
  • CPU
  • interrupts
  • ports
  • paging
  • physical memory
  • panic/debug
  • process
  • thread
  • syscalls
  • environment
  • time
  • permissions
  • app metadata
  • app
  • window
  • controls
  • events
  • basic layout
  • input
  • drawing basics

Hydrogen is v1-standard-library-ready when you can build:

  1. A freestanding kernel component
  2. A userspace command-line tool
  3. A file-reading utility
  4. A graphical Australis app
  5. A small library/package used by another Hydrogen project

All without relying on libc, .NET, CLR, or another language runtime.


Build this first:

Hydrogen.Core
Hydrogen.Memory
Hydrogen.Text minimal
Australis.Kernel.Debug

This lets you write kernel-level proof-of-concept code.

Then build:

Hydrogen.Runtime minimal
Hydrogen.IO.Console
Australis.Userspace.Process
Australis.Userspace.Syscall

This lets you write userspace command-line apps.

Then build:

Hydrogen.IO.File
Hydrogen.Text formatting/parsing
Hydrogen.Memory.Buffer

This lets you write real tools.

Then build:

Australis.UI
Australis.Userspace.App
Australis.Userspace.Permissions

This lets you write graphical Australis applications.


The Hydrogen standard library should prove that Hydrogen is not a C wrapper, not a C# clone, and not dependent on another runtime.

It should show that Hydrogen is:

A standalone native language with its own compiler, own standard library, own runtime model, and first-class Australis OS integration.

The standard library should be built from the bottom up:

Core -> Memory -> Text -> Runtime -> Kernel -> IO -> Userspace -> UI

Each phase should produce something usable, even before the whole roadmap is finished.