working on sterling lang

This commit is contained in:
fatmeat 2025-05-18 16:37:41 +02:00
parent f2ffe70790
commit 5418892fa5
11 changed files with 903 additions and 172 deletions

477
docs/SterlingLangDoc.html Normal file
View File

@ -0,0 +1,477 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sterling Language Documentation</title>
<style>
body { font-family: monospace; background: #0f0f0f; color: #f0f0f0; padding: 2rem; }
h1, h2, h3 { color: #00ffe0; }
pre { background: #1a1a1a; padding: 1rem; overflow-x: auto; }
code { color: #d0d0ff; }
a { color: #00aaff; }
</style>
</head>
<body>
<h1>Sterling Language Documentation</h1>
<p>Version: <code>0.1.0-alpha</code></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>(placeholder, subject to change)</em></h2>
<ul>
<li>Source files: <code>.stg</code></li>
<li>Header files: <code>.sth</code></li>
</ul>
<h2>Function Qualifiers</h2>
<p>Every function must declare its linkage explicitly:</p>
<pre><code>
fn // globally visible, default linkage
fn_static // translation unit-local only
fn_inline // inline-only, no symbol emitted
fn_asm // raw assembly function, globally visible
fn_static_asm // raw assembly function, TU-local only
</code></pre>
<h2>Function Syntax</h2>
<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_extern i32 printf(const char* fmt, ...);
fn_inline u32 max(u32 a, u32 b) {
return ((a > b) ? a : b);
}
fn exit() {
// equivalent to fn void exit()
}
</code></pre>
<h2>Assembly Functions</h2>
<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>
<h2>Syscalls</h2>
<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>
<h2>Types</h2>
<p>Sterling supports explicitly sized, ABI-stable primitive types. Signed and unsigned integer types are defined as follows:</p>
<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>
<p>Pointer types:</p>
<pre><code>
T* // Pointer to type T
ptr* // Special pointer with implicit coercion allowed (e.g., for GC, reflective systems)
void* // Opaque pointer with explicit cast required
</code></pre>
<p>All types have explicitly defined size and alignment. Structs support default values and zero-initialization rules:</p>
<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 (default zero-init)
</code></pre>
<p>To opt out of default zero-initialization:</p>
<pre><code>
@raw u32 raw_val; // uninitialized
</code></pre>
<h2>Memory Model</h2>
<p>Sterling uses explicit, manual memory management by default. All variables are zero-initialized unless explicitly marked with <code>@raw</code>. Heap allocation is done via standard system or custom allocators.</p>
<ul>
<li><strong>Stack</strong>: Local automatic variables</li>
<li><strong>Heap</strong>: malloc/free or custom allocators</li>
<li><strong>Zero-cost abstraction</strong>: structs and stack values are passed by value unless explicitly passed by pointer</li>
</ul>
<p>Alignment and packing are controllable per type (TBD syntax). All layout is predictable and optimized for cache behavior. There are no hidden fields, vtables, or RTTI overhead.</p>
<h2>Operating System Development Features</h2>
<ul>
<li>Direct register access: <code>reg.rax</code>, <code>reg.cr3</code>, etc.</li>
<li>Memory barriers: <code>memory_fence_acquire()</code>, <code>memory_fence_release()</code></li>
<li>Segment descriptor support: GDT, IDT, TSS descriptors definable via built-in types</li>
<li>Interrupt handler definitions: <code>fn_isr</code> for IRQ, <code>fn_trap</code> for fault handlers</li>
<li>Syscall traps: <code>fn_syscall</code> with ABI-safe handling</li>
<li>No external ASM required: use <code>fn_asm</code> to write boot routines and context switches inline</li>
<li>Inline port I/O: <code>outb(port, val)</code>, <code>inw(port)</code>, etc.</li>
<li>MSR and control register access: readable and writable constants like <code>CR0_PG</code>, <code>MSR_EFER</code></li>
<li>Binary blob inclusion: <code>embed_binary("boot.bin")</code></li>
<li>Freestanding boot targets: no runtime required, bootloader/kernels fully supported</li>
</ul>
<h2>Metaprogramming</h2>
<p><em>TODO: Describe 'meta' keyword, templating, compile-time codegen, restrictions on type inference.</em></p>
<h2>ABI and Interop</h2>
<p><em>TODO: Specify ABI model (System V AMD64), calling convention details, struct/pointer representation rules.</em></p>
<h2>Threading</h2>
<p><em>TODO: Describe standard threading model, scheduler integration, context switching, green threads API.</em></p>
<h2>Graphics and Rendering</h2>
<p><em>TODO: Describe native rendering interface, GPU abstraction layer, and access to OpenGL/DirectX backends.</em></p>
<h2>Build and Compilation Model</h2>
<p><em>TODO: AOT compilation, linker behavior, multi-file project structure, module system (if any).</em></p>
</body>
</html>
<body>
<h2>Function Syntax</h2>
<p>Return types are mandatory and must be declared explicitly. The only exception is <code>void</code>, which can be omitted as it represents no return value.</p>
<pre><code>
fn u32 add(u32 a, u32 b) {
return a + b;
}
fn_extern i32 printf(const char* fmt, ...);
fn_inline u32 max(u32 a, u32 b) {
return (a > b) ? a : b;
}
fn exit() {
// equivalent to fn void exit()
}
</code></pre>
<h2>Assembly Functions</h2>
<p>Write raw x86_64 assembly using <code>fn_asm</code> or <code>fn_static_asm</code>. Symbol, section, and global declarations 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>
<h2>Syscalls</h2>
<p>System calls can be issued directly using <code>fn_asm</code>. Wrappers may be defined for ABI-safe interfaces.</p>
<pre><code>
fn_asm void exit() {
mov rax, 60 ; syscall: exit
mov rdi, 0 ; exit code
syscall
ret
}
</code></pre>
<h2>Types</h2>
<pre><code>
i8, i16, i32, i64 // signed integers
u8, u16, u32, u64 // unsigned integers
f32, f64 // IEEE floats
bool // 1-byte boolean
char // UTF-8 byte
</code></pre>
<p>Pointer types:</p>
<pre><code>
T* // pointer to T
ptr* // special pointer with implicit coercion
void* // opaque pointer, explicit cast only
</code></pre>
<p>Structs support defaults and zero-initialization:</p>
<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 (default)
</code></pre>
<pre><code>
u32 raw @raw; // opt-out of zero-init
</code></pre>
<h2>Memory Model</h2>
<ul>
<li>Manual memory management by default</li>
<li>Zero-initialization unless <code>@raw</code></li>
<li>Explicit control over layout, alignment, packing</li>
</ul>
<p>Arrays, strings, and bitfields are memory-safe by default with bounds-aware utility functions and type traits.</p>
<h2>Metaprogramming</h2>
<pre><code>
meta define_add(T);
T add(T a, T b) {
return a + b;
}
</code></pre>
<p>Only primitive types are allowed without explicit overloads. Structs must implement <code>meta_add</code> manually. Compile-time execution is guaranteed only for pure expressions.</p>
<h2>Control Flow Extensions</h2>
<p>Designed for structured, optimized low-level behavior:</p>
<pre><code>
match_const value {
0b0000: return EMPTY;
0b0001: return CORNER;
...
}
fallthrough_block(value) {
0b0011: case_edge;
0b1010: case_edge;
label case_edge:
// handle edge
break;
}
loop_outer: while (true) {
loop_inner: while (true) {
if (x) break loop_outer;
}
}
</code></pre>
<h2>Bitfields and Bit Types</h2>
<p>Sterling supports <code>bit</code> and <code>bitfield</code> types to define compact data structures. Useful for efficient array storage, runtime layout configuration, and manual control of field width.</p>
<pre><code>
bitfield struct TileMask {
bit corner : 1;
bit edge : 1;
bit fill : 1;
...
}
</code></pre>
<h2>Memory-Aware Structures</h2>
<p>Sterling provides tools to construct layout-aware containers like aligned arrays, flexible bitfield arrays, and layout-optimized structures that adjust at runtime.</p>
<h2>Nested Loop Control</h2>
<p>Use labeled loop exits or control redirection to break from specific nesting levels without deep stacks:</p>
<pre><code>
while (game_running) {
while (update_running) {
if (exit_to_game) break @2;
}
}
</code></pre>
<h2>Threading</h2>
<p><em>TODO: Specify green threading model, context switch ABI, thread-local storage and atomic operations.</em></p>
<h2>ABI and Interop</h2>
<p>Sterling uses the System V AMD64 ABI. C interop requires exact type and calling signature match. All exported symbols must declare calling convention and linkage explicitly. Casts must be intentional. <code>fn test() -> i32</code> syntax is not supported; return type must be declared in C form as <code>fn i32 test()</code>.</p>
<h2>Build and Compilation</h2>
<p><em>TODO: Describe Sterling to C translation, compiler phases, linking steps, macro expansion and preprocessing rules.</em></p>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sterling Language Documentation</title>
<style>
body { font-family: monospace; background: #0f0f0f; color: #f0f0f0; padding: 2rem; }
h1, h2, h3 { color: #00ffe0; }
pre { background: #1a1a1a; padding: 1rem; overflow-x: auto; }
code { color: #d0d0ff; }
a { color: #00aaff; }
</style>
</head>
<body>
<h1>Sterling Language Documentation</h1>
<p>Version: <code>0.1.0-alpha</code></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.</p>
<h2>File Extensions</h2>
<ul>
<li>Source files: <code>.stg</code></li>
<li>Header files: <code>.sth</code> <em>(placeholder, subject to change)</em></li>
</ul>
<h2>Function Qualifiers</h2>
<p>Every function must declare its linkage explicitly:</p>
<pre><code>fn // globally visible, default linkage
fn_static // translation unit-local only
fn_inline // inline-only, no symbol emitted
fn_asm // raw assembly function, globally visible
fn_static_asm // raw assembly function, TU-local only</code></pre>
<h2>Function Syntax</h2>
<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>
<h2>Assembly Functions</h2>
<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>
<h2>Syscalls</h2>
<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>
<h2>Register Access</h2>
<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>. Usage outside permitted contexts may trigger compile-time errors. Clobber rules and calling conventions must be respected.</p>
<h2>Types</h2>
<p>Sterling supports explicitly sized, ABI-stable primitive types. Signed and unsigned integer types are defined as follows:</p>
<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>
<p>Pointer types:</p>
<pre><code>T* // Pointer to type T
ptr* // Special pointer with implicit coercion allowed (e.g., for GC, reflective systems)
void* // Opaque pointer with explicit cast required</code></pre>
<p>All types have explicitly defined size and alignment. Structs support default values and zero-initialization rules:</p>
<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 (default zero-init)</code></pre>
<p>To opt out of default zero-initialization:</p>
<pre><code>u32 raw_val @raw; // uninitialized</code></pre>
<h2>Memory Model</h2>
<p>Sterling uses explicit, manual memory management by default. All variables are zero-initialized unless explicitly marked with <code>@raw</code>. Heap allocation is done via standard system or custom allocators.</p>
<ul>
<li><strong>Stack</strong>: Local automatic variables</li>
<li><strong>Heap</strong>: malloc/free or custom allocators</li>
<li><strong>Zero-cost abstraction</strong>: structs and stack values are passed by value unless explicitly passed by pointer</li>
</ul>
<p>Alignment and packing are controllable per type (TBD syntax). All layout is predictable and optimized for cache behavior. There are no hidden fields, vtables, or RTTI overhead.</p>
<h2>Metaprogramming</h2>
<p><em>TODO: Describe 'meta' keyword, templating, compile-time codegen, restrictions on type inference.</em></p>
<h2>ABI and Interop</h2>
<p><em>TODO: Specify ABI model (System V AMD64), calling convention details, struct/pointer representation rules.</em></p>
<h2>Threading</h2>
<p><em>TODO: Describe standard threading model, scheduler integration, context switching, green threads API.</em></p>
<h2>Graphics and Rendering</h2>
<p><em>TODO: Describe native rendering interface, GPU abstraction layer, and access to OpenGL/DirectX backends.</em></p>
<h2>Build and Compilation Model</h2>
<p><em>TODO: AOT compilation, linker behavior, multi-file project structure.</em></p>
</body>
</html>

17
docs/server.go Normal file
View File

@ -0,0 +1,17 @@
package main
import (
"log"
"net/http"
)
func main() {
fs := http.FileServer(http.Dir("./sterling"))
http.Handle("/", fs)
log.Println("Serving at http://localhost:8080")
err := http.ListenAndServe(":8080", nil)
if err != nil {
log.Fatal(err)
}
}

View File

@ -1,172 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sterling Language Documentation</title>
<style>
body { font-family: monospace; background: #0f0f0f; color: #f0f0f0; padding: 2rem; }
h1, h2, h3 { color: #00ffe0; }
pre { background: #1a1a1a; padding: 1rem; overflow-x: auto; }
code { color: #d0d0ff; }
a { color: #00aaff; }
</style>
</head>
<body>
<h1>Sterling Language Documentation</h1>
<p>Version: <code>0.1.0-alpha</code></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 and dynamic linking.</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</h2>
<ul>
<li>Source files: <code>.stg</code></li>
<li>Header files: <code>.sth</code> <em>(placeholder, subject to change)</em></li>
</ul>
<h2>Function Qualifiers</h2>
<p>Every function must declare its linkage explicitly:</p>
<pre><code>
fn // globally visible, default linkage
fn_static // translation unit-local only
fn_export // must be exported to dynlib/staticlib
fn_extern // declared but defined elsewhere
fn_inline // inline-only, no symbol emitted
fn_asm // raw assembly function, globally visible
fn_static_asm // raw assembly function, TU-local only
</code></pre>
<h2>Function Syntax</h2>
<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_extern i32 printf(const char* fmt, ...);
fn_inline u32 max(u32 a, u32 b) {
return ((a > b) ? a : b);
}
fn exit() {
// equivalent to fn void exit()
}
</code></pre>
<h2>Assembly Functions</h2>
<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>
<h2>Syscalls</h2>
<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>
<h2>Types</h2>
<p>Sterling supports explicitly sized, ABI-stable primitive types. Signed and unsigned integer types are defined as follows:</p>
<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>
<p>Pointer types:</p>
<pre><code>
T* // Pointer to type T
ptr* // Special pointer with implicit coercion allowed (e.g., for GC, reflective systems)
void* // Opaque pointer with explicit cast required
</code></pre>
<p>All types have explicitly defined size and alignment. Structs support default values and zero-initialization rules:</p>
<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 (default zero-init)
</code></pre>
<p>To opt out of default zero-initialization:</p>
<pre><code>
@raw u32 raw_val; // uninitialized
</code></pre>
<h2>Memory Model</h2>
<p>Sterling uses explicit, manual memory management by default. All variables are zero-initialized unless explicitly marked with <code>@raw</code>. Heap allocation is done via standard system or custom allocators.</p>
<ul>
<li><strong>Stack</strong>: Local automatic variables</li>
<li><strong>Heap</strong>: malloc/free or custom allocators</li>
<li><strong>Zero-cost abstraction</strong>: structs and stack values are passed by value unless explicitly passed by pointer</li>
</ul>
<p>Alignment and packing are controllable per type (TBD syntax). All layout is predictable and optimized for cache behavior. There are no hidden fields, vtables, or RTTI overhead.</p>
<h2>Operating System Development Features</h2>
<ul>
<li>Direct register access: <code>reg.rax</code>, <code>reg.cr3</code>, etc.</li>
<li>Memory barriers: <code>memory_fence_acquire()</code>, <code>memory_fence_release()</code></li>
<li>Segment descriptor support: GDT, IDT, TSS descriptors definable via built-in types</li>
<li>Interrupt handler definitions: <code>fn_isr</code> for IRQ, <code>fn_trap</code> for fault handlers</li>
<li>Syscall traps: <code>fn_syscall</code> with ABI-safe handling</li>
<li>No external ASM required: use <code>fn_asm</code> to write boot routines and context switches inline</li>
<li>Inline port I/O: <code>outb(port, val)</code>, <code>inw(port)</code>, etc.</li>
<li>MSR and control register access: readable and writable constants like <code>CR0_PG</code>, <code>MSR_EFER</code></li>
<li>Binary blob inclusion: <code>embed_binary("boot.bin")</code></li>
<li>Freestanding boot targets: no runtime required, bootloader/kernels fully supported</li>
</ul>
<h2>Metaprogramming</h2>
<p><em>TODO: Describe 'meta' keyword, templating, compile-time codegen, restrictions on type inference.</em></p>
<h2>ABI and Interop</h2>
<p><em>TODO: Specify ABI model (System V AMD64), calling convention details, struct/pointer representation rules.</em></p>
<h2>Threading</h2>
<p><em>TODO: Describe standard threading model, scheduler integration, context switching, green threads API.</em></p>
<h2>Graphics and Rendering</h2>
<p><em>TODO: Describe native rendering interface, GPU abstraction layer, and access to OpenGL/DirectX backends.</em></p>
<h2>Build and Compilation Model</h2>
<p><em>TODO: AOT compilation, linker behavior, multi-file project structure, module system (if any).</em></p>
</body>
</html>

Binary file not shown.

106
docs/sterling/css/base.css Normal file
View File

@ -0,0 +1,106 @@
:root {
--bg-color: #0f1117;
--fg-color: #f4f4f4;
--accent-color: #36c;
--code-bg: #1a1c22;
--section-gap: 4rem;
}
body {
margin: 0;
font-family: monospace;
background-color: var(--bg-color);
color: var(--fg-color);
transition: background 0.3s, color 0.3s;
display: flex;
}
header {
background: #000;
padding: 1rem;
color: var(--fg-color);
text-align: center;
position: sticky;
top: 0;
width: 100%;
z-index: 10;
box-shadow: 0 0 10px #0008;
display: flex;
align-items: center;
justify-content: space-around;
}
header h1 {
margin: 0;
font-size: 1.5rem;
color: var(--accent-color);
}
#searchInput {
display: block;
position: relative;
top: 100%;
right: 1rem;
padding: 0.5rem;
border: 1px solid var(--fg-color);
z-index: 5;
width: 200px;
background: none;
color: var(--fg-color);
}
.controls {
background: #111;
padding: 1rem;
border-top: 1px solid #333;
display: flex;
gap: 1rem;
justify-content: center;
}
.controls button {
background: none;
border: 1px solid var(--fg-color);
color: var(--fg-color);
padding: 0.5rem 1rem;
cursor: pointer;
}
main {
flex-grow: 1;
padding: 2rem;
}
.section {
padding-bottom: 2rem;
}
.section h2 {
color: var(--accent-color);
font-size: 1.25rem;
cursor: pointer;
}
.section-content {
display: none;
margin-top: 1rem;
}
.section.open .section-content {
display: block;
}
code {
display: block;
background: var(--code-bg);
padding: 1rem;
margin: 1rem 0;
white-space: pre-wrap;
color: #aaffaa;
}
@media print {
.controls, #searchDropdown, #searchToggle {
display: none !important;
}
}

View File

View File

View File

270
docs/sterling/index.html Normal file
View File

@ -0,0 +1,270 @@
<!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>

33
docs/sterling/js/base.js Normal file
View File

@ -0,0 +1,33 @@
function toggleTheme() {
const root = document.documentElement;
const dark = root.style.getPropertyValue('--bg-color') === '#0f1117';
root.style.setProperty('--bg-color', dark ? '#ffffff' : '#0f1117');
root.style.setProperty('--fg-color', dark ? '#000000' : '#f4f4f4');
root.style.setProperty('--code-bg', dark ? '#f0f0f0' : '#1a1c22');
}
function filterContent() {
const query = document.getElementById('searchInput').value.toLowerCase();
document.querySelectorAll('.section').forEach(section => {
const text = section.innerText.toLowerCase();
section.style.display = text.includes(query) ? 'block' : 'none';
});
}
function downloadOfflineVersion() {
const blob = new Blob([document.documentElement.outerHTML], { type: 'text/html' });
const a = document.createElement('a');
a.href = URL.createObjectURL(blob);
a.download = 'SystemsLangDocumentation.html';
a.click();
}
function toggleSection(header) {
const section = header.parentElement;
section.classList.toggle('open');
}
function toggleSearch() {
const dropdown = document.getElementById('searchDropdown');
dropdown.style.display = dropdown.style.display === 'block' ? 'none' : 'block';
}