# As a condition of accessing this website, you agree to abide by the following # content signals: # (a) If a Content-Signal = yes, you may collect content for the corresponding # use. # (b) If a Content-Signal = no, you may not collect content for the # corresponding use. # (c) If the website operator does not include a Content-Signal for a # corresponding use, the website operator neither grants nor restricts # permission via Content-Signal with respect to the corresponding use. # The content signals and their meanings are: # search: building a search index and providing search results (e.g., returning # hyperlinks and short excerpts from your website's contents). Search does not # include providing AI-generated search summaries. # ai-input: inputting content into one or more AI models (e.g., retrieval # augmented generation, grounding, or other real-time taking of content for # generative AI search answers). # ai-train: training or fine-tuning AI models. # ANY RESTRICTIONS EXPRESSED VIA CONTENT SIGNALS ARE EXPRESS RESERVATIONS OF # RIGHTS UNDER ARTICLE 4 OF THE EUROPEAN UNION DIRECTIVE 2019/790 ON COPYRIGHT # AND RELATED RIGHTS IN THE DIGITAL SINGLE MARKET. # BEGIN Cloudflare Managed content User-agent: * Content-Signal: search=yes,ai-train=no Allow: / User-agent: Amazonbot Disallow: / User-agent: Applebot-Extended Disallow: / User-agent: Bytespider Disallow: / User-agent: CCBot Disallow: / User-agent: ClaudeBot Disallow: / User-agent: CloudflareBrowserRenderingCrawler Disallow: / User-agent: Google-Extended Disallow: / User-agent: GPTBot Disallow: / User-agent: meta-externalagent Disallow: / # END Cloudflare Managed Content Spectre Programming Language

Spectre

A statically typed, design-by-contract programming language for building simple, scalable, and maintainable systems.

Spectre is a statically typed, DbC programming language built for low-level control in combination with verifiably safe constructs.

It features a contract system integrated into the language grammar. Functions carry named preconditions and postconditions that participate in compilation and, depending on their form, in the generated binary. The programming language offers explicit control over which checks survive into release builds through the use of the guarded construct. More notably there is a type-level invariant system, wherein conditions in type invariants are evaluated at compile time.

Spectre compiles to QBE IR which lowers to assembly, though there are also experimental LLVM and C99 backends as per v0.0.5.

val math = use("std/math") union Shape = { Circle(f64) | Rect(f64, f64) | Triangle(f64, f64, f64) } fn area(s: Shape) f64 = { match s { Circle r => { return 3.14159 * r * r } Rect w, h => { return w * h } Triangle a, b, c => { val sp = (a + b + c) / 2.0 return math.sqrt(sp * (sp - a) * (sp - b) * (sp - c)) } } }
/// Return bytes remaining. Subtraction is safe because used <= cap. pub fn (Arena) remaining(arena: self) usize = { pre { used_le_cap : trust @load(@ptradd(arena, 8)) <= trust @load(@ptradd(arena, 16)) } val off: usize = trust @load(@ptradd(arena, 8)) val cap: usize = trust @load(@ptradd(arena, 16)) post { result_le_cap : off <= cap } return cap - off }
enum Status = { Ok, NotFound, PermissionDenied } union Payload = { i32 | i64 | ref char } fn describe(x: Payload) void! = { match x { i32 => { std.stdio.puts("32-bit integer") } i64 => { std.stdio.puts("64-bit integer") } else => { std.stdio.puts("string pointer") } } }
/// Open a file; mode must be non-empty in all build configurations. pub fn open(path: ref char, mode: ref char) option[ref void] = { guarded pre { mode_nonempty : mode != "" } val f: ref void = trust fopen(path, mode) if f == none { return none } return some f }

Installation

The installer sets up the compiler, adds the spectre binary to PATH, and verifies the build. Requires git and cmake.

POSIX (Linux, MacOS, FreeBSD, etc...)
curl https://spectrelang.org/get.sh | sh
Windows
irm https://spectrelang.org/get.ps1 | iex

Built with Spectre

A complete CHIP-8 emulator using SDL2 for display and input. Implements the full instruction set including the original COSMAC VIP opcodes, with configurable CPU speed for compatibility across ROM sets.

A devlogging CLI tool that converts markdown files into modern HTML pages. Drives the Spectre devlog.

phantom

A HTTP/1.1 server with no runtime dependencies beyond the standard library. Built to demonstrate Spectre's suitability for network programming, contract-verified buffer handling, explicit allocation, and predictable latency.

The Spectre compiler itself is written in Spectre.

A singleplayer arena shooter using raycasting rendering, uses SDL2 for graphics and input handling.

A simple flight simulator. Uses SDL2 for graphics and input handling.