Ship Language Syntax
Ship uses a strict, C-like grammar with no implicit type coercion and zero hidden allocations. This document provides the complete syntax structure of the language, easily ingestable for agents and developers.
Primitives and Types
Ship currently supports the following base types:
- int (64-bit integer)
- string (immutable UTF-8 sequence)
- bool (boolean true or false)
Variables
Variables are declared using the let keyword. Reassignments and mutability are explicit.
Functions
Functions use the fn keyword. Types must be explicitly declared for both parameters and the return value (denoted by ->).
Control Flow
Ship supports standard if and else blocks. Parentheses around conditions are required.
Structs (Data Types)
Custom data structures are defined using type ... struct. Memory alignment is strictly linear.
Contracts (Compile-Time Validation)
Ship uniquely supports contract blocks that enforce invariants at compile-time. Use require for preconditions and ensure for postconditions.
fn process(x int) -> bool {
contract {
require: x > 0
ensure: x != 100
}
// Function body...
return true;
}
Operators
- Arithmetic:
+,-,*,/ - Comparison:
==,!=,<,> - Logical: Prefix
!