extend default to s64

This commit is contained in:
agra
2026-02-11 01:05:21 +02:00
parent 70435d3c85
commit 25e1372731
11 changed files with 754 additions and 208 deletions

View File

@@ -17,7 +17,7 @@ Line comments start with `//` and extend to end of line.
| Kind | Examples | Type |
|-----------|---------------------|---------|
| Integer | `0`, `42`, `0xFF`, `0b1010` | `s32` |
| Integer | `0`, `42`, `0xFF`, `0b1010` | `s64` |
| Float | `0.3`, `0.9` | `f32` |
| String | `"Hello"`, `"z: {z}"` | `string` |
| Boolean | `true`, `false` | `bool` |
@@ -71,14 +71,14 @@ Line comments start with `//` and extend to end of line.
## 2. Type System
### Primitive Types
- `s1`..`s64` — signed integers (1 to 64 bits). `s32` is the default for integer literals.
- `s1`..`s64` — signed integers (1 to 64 bits). `s64` is the default for integer literals.
- `u1`..`u64` — unsigned integers (1 to 64 bits).
- `f32` — 32-bit floating point
- `f64` — 64-bit floating point
- `bool` — boolean (`true` / `false`)
- `string` — string of characters
- `Any` — type-erased value, represented as `{ i32, i64 }` (type tag + payload). Used for variadic arguments and runtime type dispatch.
- `Type` — compile-time type value. At runtime, represented as an `i32` type tag (same tag space as `Any`).
- `Any` — type-erased value, represented as `{ i64, i64 }` (type tag + payload). Used for variadic arguments and runtime type dispatch.
- `Type` — compile-time type value. At runtime, represented as an `i64` type tag (same tag space as `Any`).
### Enum Types
User-defined sum types with named variants.
@@ -139,7 +139,7 @@ print("{}", v1); // Vec4{x:1.0, y:2.0, z:3.0, w:0.0}
```
### Union Types (Tagged Unions)
Sum types where each variant can carry typed data or be void. Internally represented as `{ i32, [max_payload_size x i8] }`.
Sum types where each variant can carry typed data or be void. Internally represented as `{ i64, [max_payload_size x i8] }`.
#### Declaration
```sx
@@ -182,7 +182,7 @@ Fixed-size arrays with element type and length.
```sx
buffer : [5]f32 = .[0, 2, 3.5, 4, 0];
val := buffer[2]; // 3.5
buffer.len // 5 (compile-time constant, s32)
buffer.len // 5 (compile-time constant, s64)
```
Arrays can also be constructed programmatically with the `Array` builtin:
@@ -191,7 +191,7 @@ MyArr :: Array(5, s32); // equivalent to [5]s32
```
### Slice Types
A slice `[]T` is a fat pointer `{ptr, i32}` referencing a contiguous sequence of `T` elements. Same runtime layout as `string`.
A slice `[]T` is a fat pointer `{ptr, i64}` referencing a contiguous sequence of `T` elements. Same runtime layout as `string`.
```sx
// Arrays implicitly coerce to slices at call sites
arr : [5]s32 = .[3, 1, 4, 1, 5];
@@ -200,7 +200,7 @@ sortSlice(arr); // [5]s32 → []s32 coercion
// Slice operations
items[i] // read element at index
items[i] = val; // write element at index
items.len // length (s32)
items.len // length (s64)
items.ptr // raw pointer
```
@@ -352,7 +352,7 @@ print :: (fmt: string, args: ..Any) { ... }
- `::` bindings infer type from the right-hand side
- `:=` bindings infer type from the right-hand side
- Explicit annotation overrides inference: `NAME : f64 : 0.9;`
- Integer literals default to `s32`
- Integer literals default to `s64`
- Float literals default to `f32`
- Enum literals (`.variant`) infer their enum type from context (expected type)
@@ -609,13 +609,13 @@ while i < 10 {
```sx
for iterable {
// `it` is the current element
// `it_index` is the current index (s32)
// `it_index` is the current index (s64)
print("{it}\n");
}
```
Iterates over arrays and slices. The loop body has two implicit variables:
- `it` — the current element value
- `it_index` — the current index (s32, starting at 0)
- `it_index` — the current index (s64, starting at 0)
`break;` exits the loop. `continue;` skips to the next iteration.
```sx
@@ -730,15 +730,15 @@ Built-in functions are declared in `std.sx` with the `#builtin` suffix, which te
- `sqrt(x: $T) -> T` — square root (maps to LLVM intrinsic)
### Memory
- `alloc(size: s32) -> string` — allocate `size` bytes of memory, returned as a string slice
- `size_of($T: Type) -> s32` — size of type `T` in bytes
- `alloc(size: s64) -> string` — allocate `size` bytes of memory, returned as a string slice
- `size_of($T: Type) -> s64` — size of type `T` in bytes
### Type Introspection
- `type_of(val: $T) -> Type` — returns the runtime type tag of a value
- `type_name($T: Type) -> string` — returns the name of type `T` as a string (e.g., `"Point"`)
- `field_count($T: Type) -> s32` — returns the number of fields (struct), variants (enum), or elements (vector) in type `T`
- `field_name($T: Type, idx: s32) -> string` — returns the name of the `idx`-th field (struct) or variant (enum) of type `T`
- `field_value(s: $T, idx: s32) -> Any` — returns the `idx`-th field (struct) or element (vector) of `s`, boxed as `Any`
- `field_count($T: Type) -> s64` — returns the number of fields (struct), variants (enum), or elements (vector) in type `T`
- `field_name($T: Type, idx: s64) -> string` — returns the name of the `idx`-th field (struct) or variant (enum) of type `T`
- `field_value(s: $T, idx: s64) -> Any` — returns the `idx`-th field (struct) or element (vector) of `s`, boxed as `Any`
### Type Conversion
- `cast(Type) expr` — prefix operator that converts `expr` to `Type`. Examples: `cast(s32) 3.14`, `cast(f64) n`. When `Type` is a runtime `Type` value inside a type-category match arm, the compiler generates a dispatch switch over all types in the category, monomorphizing the callee for each concrete type.