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.
Ownership and starting gate
Section titled “Ownership and starting gate”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.
Library Layers
Section titled “Library Layers”Hydrogen.Core // always available, no OS dependencyHydrogen.Memory // allocators, slices, buffersHydrogen.Runtime // optional runtime servicesHydrogen.Text // strings, UTF-8, formattingHydrogen.IO // platform-backed IOAustralis.Kernel // kernel-only APIsAustralis.Userspace // app/service APIsAustralis.UI // windowing/UI APIsDesign Rule
Section titled “Design Rule”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
Phase 0 - Standard Library Foundations
Section titled “Phase 0 - Standard Library Foundations”Purpose
Section titled “Purpose”Create the rules and structure before adding lots of APIs.
This phase prevents the standard library from becoming messy later.
Deliverables
Section titled “Deliverables”/std /Hydrogen.Core /Hydrogen.Memory /Hydrogen.Runtime /Hydrogen.Text /Hydrogen.IO /Australis.Kernel /Australis.Userspace /Australis.UIDecisions to Make
Section titled “Decisions to Make”- 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
Required Compiler Support
Section titled “Required Compiler Support”- module imports
- public/private visibility
- basic package/project references
- build targets
- standard library lookup path
Completion Criteria
Section titled “Completion Criteria”This phase is complete when a Hydrogen file can import a standard library module:
use Hydrogen.Core;
public function Main(): int { return 0;}Phase 1 - Hydrogen.Core
Section titled “Phase 1 - Hydrogen.Core”Purpose
Section titled “Purpose”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.
Modules
Section titled “Modules”Hydrogen.Core.TypesHydrogen.Core.ResultHydrogen.Core.OptionHydrogen.Core.MathHydrogen.Core.DiagnosticsHydrogen.Core.ConvertHydrogen.Core.BitwiseHydrogen.Core.CompareHydrogen.Core.PanicFeatures
Section titled “Features”Primitive Type Helpers
Section titled “Primitive Type Helpers”Support common type aliases and helpers:
u8u16u32u64i8i16i32i64usizeisizeboolcharbytevoidResult
Section titled “Result”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
Section titled “Option”Option<T>Some(value)NoneExample:
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.
Bitwise Helpers
Section titled “Bitwise Helpers”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)Conversion
Section titled “Conversion”Basic explicit conversions:
Convert.ToInt(...)Convert.ToUInt(...)Convert.ToBool(...)Do not make conversions too magical.
Required Compiler Support
Section titled “Required Compiler Support”- generics
- basic structs/enums
- static functions
- compile-time constants
- basic error messages
Completion Criteria
Section titled “Completion Criteria”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;}Phase 2 - Hydrogen.Memory
Section titled “Phase 2 - Hydrogen.Memory”Purpose
Section titled “Purpose”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.
Modules
Section titled “Modules”Hydrogen.Memory.PointerHydrogen.Memory.SliceHydrogen.Memory.BufferHydrogen.Memory.AllocatorHydrogen.Memory.FixedBufferHydrogen.Memory.LayoutHydrogen.Memory.UnsafeFeatures
Section titled “Features”Pointers
Section titled “Pointers”ptr<T>null&value*pointerHelper APIs:
Pointer.IsNull(pointer)Pointer.Offset(pointer, count)Pointer.Cast<TFrom, TTo>(pointer)Slices
Section titled “Slices”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; }}Buffers
Section titled “Buffers”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();Allocator Interface
Section titled “Allocator Interface”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.
Layout Helpers
Section titled “Layout Helpers”sizeof<T>()alignof<T>()offsetof<T>("Field")Example:
comptime assert(sizeof<GdtEntry>() == 8);Memory Operations
Section titled “Memory Operations”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.
Required Compiler Support
Section titled “Required Compiler Support”- pointer types
unsafedefer- fixed-size arrays
- basic compile-time functions
- optional bounds checks
Completion Criteria
Section titled “Completion Criteria”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;}Phase 3 - Hydrogen.Text
Section titled “Phase 3 - Hydrogen.Text”Purpose
Section titled “Purpose”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.
Modules
Section titled “Modules”Hydrogen.Text.StringHydrogen.Text.Utf8Hydrogen.Text.RuneHydrogen.Text.FormatHydrogen.Text.ParseHydrogen.Text.AsciiHydrogen.Text.StringBuilderFeatures
Section titled “Features”String Model
Section titled “String Model”Recommended model:
string // UTF-8 textbyte // raw 8-bit valuechar/rune // Unicode scalar valueAvoid making string[index] mean “character at index”.
Prefer:
text.ByteLengthtext.ByteAt(index)text.RuneCount()text.RuneAt(index)text.Runes()ASCII Helpers
Section titled “ASCII Helpers”Very useful early on:
Ascii.IsDigit(c)Ascii.IsLetter(c)Ascii.IsWhitespace(c)Ascii.ToUpper(c)Ascii.ToLower(c)UTF-8 Helpers
Section titled “UTF-8 Helpers”Utf8.Validate(bytes)Utf8.DecodeNext(bytes, index)Utf8.EncodeRune(rune, buffer)Formatting
Section titled “Formatting”Start simple:
Format.Int(value)Format.UInt(value)Format.Hex(value)Format.Bool(value)Later:
String.Format("Value: {0}", value)Parsing
Section titled “Parsing”Parse.Int("123")Parse.UInt("123")Parse.Bool("true")Return Result, not exceptions:
var value = try Parse.Int("123");StringBuilder
Section titled “StringBuilder”For runtime/userspace builds:
var builder = StringBuilder.Create();defer builder.Free();
builder.Append("Hello ");builder.Append("Hydrogen");
var text = builder.ToString();Required Compiler Support
Section titled “Required Compiler Support”- string literals
- byte arrays
- slices
- Result
- optional heap allocation
- iteration
Completion Criteria
Section titled “Completion Criteria”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;}Phase 4 - Hydrogen.Runtime
Section titled “Phase 4 - Hydrogen.Runtime”Purpose
Section titled “Purpose”Create optional runtime services.
This layer should not be required for freestanding or kernel code unless explicitly enabled.
Modules
Section titled “Modules”Hydrogen.Runtime.StartupHydrogen.Runtime.HeapHydrogen.Runtime.GCHydrogen.Runtime.PanicHydrogen.Runtime.TypeInfoHydrogen.Runtime.DebugHydrogen.Runtime.ConsoleHydrogen.Runtime.ThreadingFeatures
Section titled “Features”Startup
Section titled “Startup”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)Optional Garbage Collection
Section titled “Optional Garbage Collection”GC should be optional.
Project config example:
{ "runtime": "native", "gc": false}or:
{ "runtime": "managed", "gc": true}Panic Handling
Section titled “Panic Handling”Runtime-enabled panic can include:
- message
- file
- line
- stack trace
- process termination
Type Info
Section titled “Type Info”Optional future feature:
typeof<T>()value.GetType()Should not be required for low-level builds.
Console
Section titled “Console”Runtime-level console for debugging:
Console.Write("Hello");Console.WriteLine("Hydrogen");In freestanding builds, this should either be unavailable or target-specific.
Required Compiler Support
Section titled “Required Compiler Support”- runtime profile selection
- entrypoint generation
- optional metadata
- optional GC hooks
- build modes
Completion Criteria
Section titled “Completion Criteria”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;}Phase 5 - Australis.Kernel
Section titled “Phase 5 - Australis.Kernel”Purpose
Section titled “Purpose”Create the APIs required to write Australis OS kernel components in Hydrogen.
This layer should be available only in kernel/freestanding targets.
Modules
Section titled “Modules”Australis.Kernel.BootAustralis.Kernel.CPUAustralis.Kernel.InterruptsAustralis.Kernel.MemoryAustralis.Kernel.PagingAustralis.Kernel.PortsAustralis.Kernel.DevicesAustralis.Kernel.DebugAustralis.Kernel.SchedulerAustralis.Kernel.SyscallsAustralis.Kernel.PanicFeatures
Section titled “Features”@entryfunction 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)Interrupts
Section titled “Interrupts”@interrupt(14)function PageFault(frame: ptr<InterruptFrame>): void { Panic.Fatal("Page fault");}APIs:
Interrupts.Register(vector, handler)Interrupts.Enable()Interrupts.Disable()Kernel Memory
Section titled “Kernel Memory”PhysicalMemory.AllocatePage()PhysicalMemory.FreePage(page)VirtualMemory.Map(...)VirtualMemory.Unmap(...)Paging
Section titled “Paging”Paging.MapPage(virtualAddress, physicalAddress, flags)Paging.UnmapPage(virtualAddress)Paging.Flush(address)Debug Output
Section titled “Debug Output”KernelDebug.WriteLine("Booting Australis...");This might write to serial, framebuffer, or debug console.
Kernel.Panic("Fatal kernel error");Should halt safely.
Required Compiler Support
Section titled “Required Compiler Support”- freestanding mode
- no libc
- no mandatory heap
- inline assembly or compiler intrinsics
- interrupt attributes
- section attributes
- packed structs
- fixed memory layout
Completion Criteria
Section titled “Completion Criteria”You can write a minimal kernel entry in Hydrogen:
use Australis.Kernel;
@entryfunction KernelStart(info: ptr<BootInfo>): void { KernelDebug.WriteLine("Australis booted from Hydrogen"); CPU.HaltLoop();}Phase 6 - Hydrogen.IO
Section titled “Phase 6 - Hydrogen.IO”Purpose
Section titled “Purpose”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.
Modules
Section titled “Modules”Hydrogen.IO.FileHydrogen.IO.DirectoryHydrogen.IO.PathHydrogen.IO.StreamHydrogen.IO.ConsoleHydrogen.IO.DeviceFeatures
Section titled “Features”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
Section titled “Directory”Directory.Exists(path)Directory.Create(path)Directory.List(path)Path.Join(a, b)Path.Extension(path)Path.FileName(path)Path.DirectoryName(path)Stream
Section titled “Stream”interface Stream { function Read(buffer: slice<byte>): Result<usize, IOError>; function Write(buffer: slice<byte>): Result<usize, IOError>; function Close(): void;}Console
Section titled “Console”Console.WriteLine("Hello");Console.ReadLine()Required Compiler Support
Section titled “Required Compiler Support”- Result
- strings
- slices
- runtime or platform syscall support
- interfaces or traits
Completion Criteria
Section titled “Completion Criteria”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;}Phase 7 - Australis.Userspace
Section titled “Phase 7 - Australis.Userspace”Purpose
Section titled “Purpose”Create the standard APIs for Australis OS applications and services.
This layer should wrap Australis system calls in safe Hydrogen APIs.
Modules
Section titled “Modules”Australis.Userspace.ProcessAustralis.Userspace.ThreadAustralis.Userspace.SyscallAustralis.Userspace.PermissionsAustralis.Userspace.EnvironmentAustralis.Userspace.TimeAustralis.Userspace.ServicesAustralis.Userspace.AppFeatures
Section titled “Features”Process
Section titled “Process”Process.CurrentId()Process.Exit(code)Process.Spawn(path, args)Thread
Section titled “Thread”Thread.Sleep(ms)Thread.Start(function)Thread.CurrentId()Syscall
Section titled “Syscall”Low-level syscall wrapper:
Syscall.Invoke(number, arg1, arg2, arg3)Most users should not need this directly.
Permissions
Section titled “Permissions”Permissions.Has("filesystem.read")Permissions.Request("network")Environment
Section titled “Environment”Environment.Get("HOME")Environment.Args()Environment.CurrentDirectory()Time.Now()Time.UtcNow()Time.Sleep(ms)App Metadata
Section titled “App Metadata”App.Name()App.PackageId()App.Version()Required Compiler Support
Section titled “Required Compiler Support”- target-aware builds
- syscall attributes or wrappers
- project/app metadata
- Result
- optional async later
Completion Criteria
Section titled “Completion Criteria”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;}Phase 8 - Australis.UI
Section titled “Phase 8 - Australis.UI”Purpose
Section titled “Purpose”Create the standard UI layer for Hydrogen applications on Australis OS.
This should come after userspace APIs are stable.
Modules
Section titled “Modules”Australis.UI.AppAustralis.UI.WindowAustralis.UI.ViewAustralis.UI.ControlsAustralis.UI.LayoutAustralis.UI.InputAustralis.UI.GraphicsAustralis.UI.ThemeAustralis.UI.EventsFeatures
Section titled “Features”Application
Section titled “Application”var app = UIApp.Create();app.Run();Window
Section titled “Window”var window = Window.Create("My App", 800, 600);window.Show();Controls
Section titled “Controls”Start small:
ButtonLabelTextBoxPanelImageListViewExample:
var button = Button.Create("Click me");button.OnClick += function() { Console.WriteLine("Clicked");};Layout
Section titled “Layout”StackPanelGridDockPanelCanvasMouse.Position()Keyboard.IsKeyDown(Key.Enter)Graphics
Section titled “Graphics”Canvas.DrawRect(...)Canvas.DrawText(...)Canvas.DrawImage(...)Theme.Current()Theme.SetAccentColor(...)Required Compiler Support
Section titled “Required Compiler Support”- delegates/events or function references
- objects or structs with methods
- userspace runtime
- strings
- memory management
- app manifest support
Completion Criteria
Section titled “Completion Criteria”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();}Phase 9 - Full Standard Library Hardening
Section titled “Phase 9 - Full Standard Library Hardening”Purpose
Section titled “Purpose”Make the standard library reliable, documented, tested, and pleasant to use.
Work Items
Section titled “Work Items”Documentation
Section titled “Documentation”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- InvalidUtf8Create tests for:
- Core
- Memory
- Text
- Runtime
- IO
- Kernel APIs where testable
- Userspace APIs
- UI basics
Build Matrix
Section titled “Build Matrix”Test standard library under:
freestanding-debugfreestanding-releasekernel-debugkernel-releaseuserspace-debuguserspace-releasehosted-debughosted-releaseExamples
Section titled “Examples”Create example projects:
examples/hello-worldexamples/file-readerexamples/memory-bufferexamples/kernel-helloexamples/userspace-appexamples/ui-counterDiagnostics
Section titled “Diagnostics”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 outputCompletion Criteria
Section titled “Completion Criteria”The standard library feels usable by someone other than you.
Phase 10 - Complete v1 Standard Library
Section titled “Phase 10 - Complete v1 Standard Library”Purpose
Section titled “Purpose”Declare a stable first version.
This does not mean the library is finished forever. It means users can trust the core APIs.
v1 Requirements
Section titled “v1 Requirements”Hydrogen.Core
Section titled “Hydrogen.Core”- Result
- Option
- Math
- Panic
- conversions
- bit helpers
- primitive helpers
Hydrogen.Memory
Section titled “Hydrogen.Memory”- pointers
- slices
- buffers
- allocator interface
- memory copy/move/set/zero
- layout helpers
Hydrogen.Text
Section titled “Hydrogen.Text”- UTF-8 validation
- byte/rune APIs
- formatting
- parsing
- basic StringBuilder
Hydrogen.Runtime
Section titled “Hydrogen.Runtime”- startup
- heap
- panic handling
- console
- debug support
- optional GC hooks, even if GC is not complete
Hydrogen.IO
Section titled “Hydrogen.IO”- files
- directories
- paths
- streams
- console
Australis.Kernel
Section titled “Australis.Kernel”- boot
- CPU
- interrupts
- ports
- paging
- physical memory
- panic/debug
Australis.Userspace
Section titled “Australis.Userspace”- process
- thread
- syscalls
- environment
- time
- permissions
- app metadata
Australis.UI
Section titled “Australis.UI”- app
- window
- controls
- events
- basic layout
- input
- drawing basics
v1 Completion Criteria
Section titled “v1 Completion Criteria”Hydrogen is v1-standard-library-ready when you can build:
- A freestanding kernel component
- A userspace command-line tool
- A file-reading utility
- A graphical Australis app
- A small library/package used by another Hydrogen project
All without relying on libc, .NET, CLR, or another language runtime.
Suggested Build Order
Section titled “Suggested Build Order”First Working Target
Section titled “First Working Target”Build this first:
Hydrogen.CoreHydrogen.MemoryHydrogen.Text minimalAustralis.Kernel.DebugThis lets you write kernel-level proof-of-concept code.
Second Working Target
Section titled “Second Working Target”Then build:
Hydrogen.Runtime minimalHydrogen.IO.ConsoleAustralis.Userspace.ProcessAustralis.Userspace.SyscallThis lets you write userspace command-line apps.
Third Working Target
Section titled “Third Working Target”Then build:
Hydrogen.IO.FileHydrogen.Text formatting/parsingHydrogen.Memory.BufferThis lets you write real tools.
Fourth Working Target
Section titled “Fourth Working Target”Then build:
Australis.UIAustralis.Userspace.AppAustralis.Userspace.PermissionsThis lets you write graphical Australis applications.
Final Direction
Section titled “Final Direction”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 -> UIEach phase should produce something usable, even before the whole roadmap is finished.