Source src/silo:std.core
1##! Core primitive types and lang-item bindings for the Silo stdlib. 2##! 3##! Covers numeric ranges and aliases (U8..U64, I8..I64, F16..F64, 4##! D32..D128), the `Bool` enum, the foundational containers (`Option`, 5##! `Result`, `Pair`, `Ordering`), and host-provided method stubs for 6##! `Vec`. 7##! 8##! `HashMap` / `HashSet` method surfaces live in 9##! `silo:std.collections.hashmap` and `silo:std.collections.hashset`. 10 11# Primitive types — runtime-provided, declared via @lang on :impl 12@lang(int) 13:impl (Int range) :end 14@lang(float) 15:impl (Float bits) :end 16@lang(decimal) 17:impl (Decimal bits) :end 18@lang(str) 19:impl Str :end 20@lang(symbol) 21:impl Symbol :end 22@lang(unit) 23:impl Unit :end 24@lang(never) 25:impl Never :end 26 27# Range type 28## Represents a half-open range over an ordered element type. 29## Variants cover both-bounded, from-only, to-only, and unbounded forms. 30@lang(range) 31:union(pub) Range a | RangeBoth a a | RangeFrom a | RangeTo a | RangeFull :end 32 33# Integer type aliases 34## Alias for an integer of any signed range (existential lower/upper bounds). 35:alias(pub) AnyInt (Int ..) 36## Alias for an unsigned integer (any range starting at zero or higher). 37## Non-negative subset of AnyInt — `(Int 0..)` means "any non-negative Int". 38:alias(pub) AnyUInt (Int 0..) 39## Alias for a float of any bit-width. 40:alias(pub) AnyFloat (Float _) 41## Alias for a decimal of any bit-width. 42:alias(pub) AnyDecimal (Decimal _) 43## Unsigned 8-bit integer (range 0..256). 44:type(pub) U8 (Int 0..256) 45## Unsigned 16-bit integer (range 0..65536). 46:type(pub) U16 (Int 0..65536) 47## Unsigned 32-bit integer (range 0..2^32). 48:type(pub) U32 (Int 0..4294967296) 49## Unsigned 64-bit integer (range 0..2^64). 50:type(pub) U64 (Int 0..18446744073709551616) 51## Signed 8-bit integer (range -128..128). 52:type(pub) I8 (Int -128..128) 53## Signed 16-bit integer (range -32768..32768). 54:type(pub) I16 (Int -32768..32768) 55## Signed 32-bit integer (range -2^31..2^31). 56:type(pub) I32 (Int -2147483648..2147483648) 57## Signed 64-bit integer (range -2^63..2^63). 58:type(pub) I64 (Int -9223372036854775808..9223372036854775808) 59## Alias for an unsigned 8-bit byte (same range as U8). 60:type(pub) Byte U8 61## Unicode scalar value (code point in 0..0x110000). 62:type(pub) Codepoint (Int 0..1114112) 63## Back-compat alias for `Codepoint`. 64:alias(pub) Char Codepoint 65 66# Float type aliases 67## IEEE 754 binary16 half-precision float. 68:type(pub) F16 (Float 16) 69## IEEE 754 binary32 single-precision float. 70:type(pub) F32 (Float 32) 71## IEEE 754 binary64 double-precision float. 72:type(pub) F64 (Float 64) 73## IEEE 754-2008 decimal32. 74:type(pub) D32 (Decimal 32) 75## IEEE 754-2008 decimal64. 76:type(pub) D64 (Decimal 64) 77## IEEE 754-2008 decimal128. 78:type(pub) D128 (Decimal 128) 79 80# Bool enum 81## Two-valued boolean; variants are `false` and `true`. 82@lang(bool) 83:enum(pub) Bool 84 | false 85 | true 86:end 87 88# Core types 89## Optional value: `Some` carries an element, `None` represents absence. 90@lang(option) 91:union(pub) Option elem | None | Some elem :end 92## Result of a fallible computation: `Ok` on success, `Err` on failure. 93@lang(result) 94:union(pub) Result ok err | Ok ok | Err err :end 95## Ordered pair of two typed components, `.a` and `.b`. 96@lang(pair) 97:record(pub) Pair a b .a a .b b :end 98 99## Three-way comparison result, returned by `Ord`-adjacent APIs. 100@lang(ordering) 101:union(pub) Ordering 102 | Less 103 | Equal 104 | Greater 105:end 106 107# NOTE: Conversion impls (From/Into) for primitives are in silo:std.traits (lib/std/src/traits.si) 108 109# Vec methods 110# si[impl lang.vec+1] — `len` is an associated parameter (after the `|` 111# wall), so most callers write `(Vec elem)` and let the size get inferred. 112# Method bodies still write `(Vec elem len)` positionally at use sites. 113@lang(vec) 114:impl (Vec elem | len) 115 .push ( (Vec elem len) elem -> (Vec elem len) ) vec-push-intrinsic ; 116 .get ( AnyInt (Vec elem len) -> elem ) vec-get-intrinsic ; 117 .len ( (Vec elem len) -> AnyInt ) vec-len-intrinsic ; 118:end 119 120# Bytes — distinct type backed by (Vec Byte). Declared here (after the 121# Vec lang impl) because the `:type` form resolves its backing at 122# declaration time and needs `Vec` to already be in scope. 123# si[impl stdlib.bytes.type] 124## Nominal byte-sequence type. Runtime layout is the same as `(Vec Byte)` but 125## `Bytes` and `(Vec Byte)` are distinct types for dispatch purposes so that 126## byte-oriented methods live on a dedicated trait surface (`BytesOps`) and 127## don't collide with the generic `Vec` surface. 128:type(pub) Bytes (Vec Byte) 129