Types
NanoC does not invent a type system. Types are a small set of sized names, prefix pointers and your own record, enum and typedef names; other C spellings go in backticks.
Today: C types
Typedef names such as uint8_t and your own s, u, e types are passed to C as written. Prefix pointers use *T. C spellings such as unsigned long or struct stat are written in backticks, as in long .
+stdint
s Pair a,b: i32
f main
p: Pair = {84, 36}
small: uint8_t = 200
big: int64_t = 1099511627776
x := 2.5
p.a + small + (int)x - 286 != 0 || big == 0#include <stdint.h>
typedef struct Pair Pair;
struct Pair {
int a,b;
};
int main(void) {
Pair p = {84, 36};
uint8_t small = 200;
int64_t big = 1099511627776;
double x = 2.5;
return p.a + small + (int)x - 286 != 0 || big == 0;
}Inference with :=
name := literal infers a C type from a literal only: 0 gives int, 2.5 gives double, 'a' gives char, a string gives const char *. Calls, arithmetic and names need an explicit type: name: Type = expression.
Target: sized types
The new core drops platform-dependent spellings. Every scalar has one name and one size.
| Name | Meaning | C type |
|---|---|---|
i8 i16 i32 i64 | Signed integers | int8_t to int64_t |
u8 u16 u32 u64 | Unsigned integers | uint8_t to uint64_t |
f32 f64 | Floating point | float, double |
bool | Boolean | bool from stdbool |
char | Character | char |
str | Text pointer | const char * |
size | Object size | size_t |
ptr | Untyped pointer | void * |
n := 2
big: u64 = 1 << 40
f scale(x: f32, k: i32) f32
x * k