2025-05-18 16:37:41 +02:00

271 lines
8.1 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="preload" href="/assets/IosevkaSS15-Regular.ttf" as="font" type="font/ttf" crossorigin>
<link rel="stylesheet" href="css/base.css">
<title>Language Documentation</title>
<script src="./js/base.js"></script>
</head>
<body>
<div style="width:100%">
<header>
<h1>Sterling Documentation</h1>
<input type="text" id="searchInput" placeholder="Search..." oninput="filterContent()">
</header>
<div class="controls">
<button onclick="toggleTheme()">Toggle Theme</button>
<button onclick="window.print()">Export to PDF</button>
<button onclick="downloadOfflineVersion()">Download Offline</button>
</div>
<main id="doc-content">
<p>Version: <code>0.1.0-alpha</code></p>
<h2>Preface</h2>
<p>An Idiot admire complexity, a genius admire simplicity <em>Terry A. Davis</em></p>
<p>Master All, Ace One</p>
<h2>Overview</h2>
<p>Sterling is a low-level, strongly typed, systems programming language designed for performance, ABI stability, C interoperability, and full control over memory and hardware. It supports metaprogramming, hot-reloading, inline and raw assembly, and is built for multi-file compilation. It also introduces memory safety primitives and modern low-abstraction control flow enhancements.</p>
<h3>This Document is a work in progress, features are not yet implemented and i use this as a design document to stay true to my vision</h3>
<h2>File Extensions <em>(subject to change)</em></h2>
<ul>
<li>Source files: <code>.stg</code></li>
<li>Header files: <code>.sth</code></li>
</ul>
<section class="section">
<h2 onclick="toggleSection(this)">Function Qualifiers</h2>
<div class="section-content">
<p>Every function must declare its linkage explicitly:</p>
<pre>
<p><code>fn</code> globally visible, default linkage</p>
<p><code>fn_static</code> translation unit-local only</p>
<p><code>fn_inline</code> inline-only, no symbol emitted</p>
<p><code>fn_asm</code> raw assembly function, globally visible</p>
<p><code>fn_static_asm</code> raw assembly function, TU-local only</p>
</pre>
</div>
</section>
<section class="section">
<h2 onclick="toggleSection(this)">Function Syntax</h2>
<div class="section-content">
<p>All functions must explicitly declare their return type. The only exception is <code>void</code>, which may be omitted for brevity when no return value is intended.</p>
<pre><code>
fn u32 add(u32 a, u32 b) {
return (a + b);
}
fn_inline u32 max(u32 a, u32 b) {
return ((a > b) ? a : b);
}
fn exit() {
// equivalent to fn void exit()
}
</code></pre>
</div>
</section>
<section class="section">
<h2 onclick="toggleSection(this)">Assembly Functions</h2>
<div class="section-content">
<p>Write raw x86_64 assembly using <code>fn_asm</code> or <code>fn_static_asm</code>. Symbol, section, and global declaration are implicit.</p>
<pre><code>
fn_asm void* memset(void* dst, u8 value, u64 size) {
test rdx, rdx
je .done
mov rax, rsi
mov rdi, rdi
mov rcx, rdx
rep stosb
.done:
mov rax, rdi
ret
}
</code></pre>
</div>
</section>
<section class="section">
<h2 onclick="toggleSection(this)">Syscalls</h2>
<div class="section-content">
<p>System calls are allowed via <code>fn_asm</code> or wrapped using concrete ABI-aware interfaces. Example:</p>
<pre><code>
fn_asm void exit() {
mov rax, 60 ; syscall: exit
mov rdi, 0 ; exit code
syscall
ret
}
</code></pre>
</div>
</section>
<section class="section">
<h2 onclick="toggleSection(this)">Register Access</h2>
<div class="section-content">
<p>Sterling exposes raw CPU registers as language-level primitives. This is intended for kernel, embedded, and runtime-critical tasks.</p>
<pre><code>
fn u64 get_rbp() {
return rbp;
}
fn void set_rsp(u64 val) {
rsp = val;
}
</code></pre>
<p>Supported registers: <code>rax, rbx, rcx, rdx, rsi, rdi, rsp, rbp, r8..r15</code>.</p>
</div>
</section>
<section class="section">
<h2 onclick="toggleSection(this)">Types</h2>
<div class="section-content">
<pre><code>
i8, i16, i32, i64 // signed integers
u8, u16, u32, u64 // unsigned integers
f32, f64 // 32-bit and 64-bit IEEE floats
bool // 1-byte boolean, 0 or 1 only
char // 1-byte character (UTF-8)
</code></pre>
<pre><code>
T* // Pointer to type T
ptr* // Special pointer with implicit coercion allowed
void* // Opaque pointer with explicit cast required
</code></pre>
<pre><code>
typedef struct {
u32 x = 5;
u32 y;
} vec2u;
vec2u a = {}; // x = 5, y = 0
vec2u b = {0}; // x = 0, y = 0
vec2u c; // x = 0, y = 0
</code></pre>
<pre><code>
u32 raw_val @raw;
</code></pre>
</div>
</section>
<section class="section">
<h2 onclick="toggleSection(this)">Memory Model</h2>
<div class="section-content">
<p>Manual memory management by default. Variables are zero-initialized unless marked <code>@raw</code>. All layout is predictable and cache-friendly. Custom allocators are encouraged.</p>
<ul>
<li><strong>Stack</strong>: locals</li>
<li><strong>Heap</strong>: explicit alloc/free</li>
<li><strong>Inline</strong>: structs passed by value</li>
</ul>
</div>
</section>
<section class="section">
<h2 onclick="toggleSection(this)">Bitfields</h2>
<div class="section-content">
<pre><code>
typedef struct(bitfield) {
u8 field0 : 3;
u8 field1 : 5;
} Flags8;
</code></pre>
</div>
</section>
<section class="section">
<h2 onclick="toggleSection(this)">Control Flow</h2>
<div class="section-content">
<p>Sterling introduces tagged loops and escape blocks for structured yet flat nested loop behavior:</p>
<pre><code>
loop_outer: loop {
loop_inner: loop {
if (should_exit_inner()) break loop_inner;
if (should_exit_outer()) break loop_outer;
}
}
</code></pre>
<p>This allows control without stack-nesting or excessive flags.</p>
</div>
</section>
<section class="section">
<h2 onclick="toggleSection(this)">Dual Grid Branching Optimization</h2>
<div class="section-content">
<p>In place of traditional if-else trees for dual-tiling, prefer using precomputed lookup tables, or bitwise masks with packed branchless evaluation. Consider encoding tile states as compact u16 index and dereferencing behavior.</p>
</div>
</section>
<section class="section">
<h2 onclick="toggleSection(this)">Dynamic Arrays with Aligned Layout</h2>
<div class="section-content">
<p>Runtime-initialized aligned linear arrays can be used to simulate array-of-array structures, where all memory layout is controlled explicitly with offsets:</p>
<pre><code>
struct ArrayView {
u8* data;
u32 stride;
u32 count;
};
</code></pre>
<p>Insertions and deletions move memory explicitly, re-aligning if needed.</p>
</div>
</section>
<section class="section">
<h2 onclick="toggleSection(this)">Dynamic Linking</h2>
<div class="section-content">
<p>Sterling does not rely on dynamic linking by default. Static linking is favored for OS and runtime simplicity. Dynamic linking may be optionally implemented via host-defined facilities.</p>
</div>
</section>
<section class="section">
<h2 onclick="toggleSection(this)">Metaprogramming</h2>
<div class="section-content">
<p><em>TODO: Describe 'meta' keyword, templating, compile-time codegen, restrictions on type inference.</em></p>
</div>
</section>
<section class="section">
<h2 onclick="toggleSection(this)">ABI and Interop</h2>
<div class="section-content">
<p><em>TODO: Specify ABI model (System V AMD64), calling convention details, struct/pointer representation rules.</em></p>
</div>
</section>
<section class="section">
<h2 onclick="toggleSection(this)">Threading</h2>
<div class="section-content">
<p><em>TODO: Describe standard threading model, scheduler integration, context switching, green threads API.</em></p>
</div>
</section>
<section class="section">
<h2 onclick="toggleSection(this)">Graphics and Rendering</h2>
<div class="section-content">
<p><em>TODO: Describe native rendering interface</em></p>
</div>
</section>
<section class="section">
<h2 onclick="toggleSection(this)">Build and Compilation Model</h2>
<div class="section-content">
<p><em>TODO: AOT compilation, linker behavior, multi-file project structure, module system (if any).</em></p>
</div>
</section>
</body>
</html>