| ... | @@ -1,32 +1,5 @@ | ... | @@ -1,32 +1,5 @@ |
| 1 | # Language Reference | 1 | # Language Reference |
| 2 | | 2 | |
| 3 | ## Primitive Numeric Types: | | |
| 4 | | | |
| 5 | zig | C equivalent | Description | | |
| 6 | -------------|------------------------|------------------------------- | | |
| 7 | bool | bool | unsigned 1-bit integer | | |
| 8 | i8 | int8_t | signed 8-bit integer | | |
| 9 | u8 | uint8_t | unsigned 8-bit integer | | |
| 10 | i16 | int16_t | signed 16-bit integer | | |
| 11 | u16 | uint16_t | unsigned 16-bit integer | | |
| 12 | i32 | int32_t | signed 32-bit integer | | |
| 13 | u32 | uint32_t | unsigned 32-bit integer | | |
| 14 | i64 | int64_t | signed 64-bit integer | | |
| 15 | u64 | uint64_t | unsigned 64-bit integer | | |
| 16 | f32 | float | 32-bit IEE754 floating point | | |
| 17 | f64 | double | 64-bit IEE754 floating point | | |
| 18 | f128 | long double | 128-bit IEE754 floating point | | |
| 19 | isize | intptr_t | signed pointer sized integer | | |
| 20 | usize | uintptr_t | unsigned pointer sized integer | | |
| 21 | c_short | short | for API compatibility with C | | |
| 22 | c_ushort | unsigned short | for API compatibility with C | | |
| 23 | c_int | int | for API compatibility with C | | |
| 24 | c_uint | unsigned int | for API compatibility with C | | |
| 25 | c_long | long | for API compatibility with C | | |
| 26 | c_ulong | unsigned long | for API compatibility with C | | |
| 27 | c_longlong | long long | for API compatibility with C | | |
| 28 | c_ulonglong | unsigned long long | for API compatibility with C | | |
| 29 | | | |
| 30 | ## Grammar | 3 | ## Grammar |
| 31 | | 4 | |
| 32 | ``` | 5 | ``` |
| ... | @@ -190,42 +163,152 @@ x{} | ... | @@ -190,42 +163,152 @@ x{} |
| 190 | = *= /= %= += -= <<= >>= &= ^= |= &&= ||= | 163 | = *= /= %= += -= <<= >>= &= ^= |= &&= ||= |
| 191 | ``` | 164 | ``` |
| 192 | | 165 | |
| 193 | ## Literals | 166 | ## Types |
| | 167 | |
| | 168 | ### Numeric Types |
| | 169 | |
| | 170 | ``` |
| | 171 | Type name C equivalent Description |
| | 172 | |
| | 173 | i8 int8_t signed 8-bit integer |
| | 174 | u8 uint8_t unsigned 8-bit integer |
| | 175 | i16 int16_t signed 16-bit integer |
| | 176 | u16 uint16_t unsigned 16-bit integer |
| | 177 | i32 int32_t signed 32-bit integer |
| | 178 | u32 uint32_t unsigned 32-bit integer |
| | 179 | i64 int64_t signed 64-bit integer |
| | 180 | u64 uint64_t unsigned 64-bit integer |
| | 181 | |
| | 182 | f32 float 32-bit IEE754 floating point |
| | 183 | f64 double 64-bit IEE754 floating point |
| | 184 | f128 long double 128-bit IEE754 floating point |
| | 185 | |
| | 186 | isize intptr_t signed pointer sized integer |
| | 187 | usize uintptr_t unsigned pointer sized integer |
| | 188 | |
| | 189 | c_short short for ABI compatibility with C |
| | 190 | c_ushort unsigned short for ABI compatibility with C |
| | 191 | c_int int for ABI compatibility with C |
| | 192 | c_uint unsigned int for ABI compatibility with C |
| | 193 | c_long long for ABI compatibility with C |
| | 194 | c_ulong unsigned long for ABI compatibility with C |
| | 195 | c_longlong long long for ABI compatibility with C |
| | 196 | c_ulonglong unsigned long long for ABI compatibility with C |
| | 197 | ``` |
| | 198 | |
| | 199 | ### Boolean Type |
| | 200 | The boolean type has the name `bool` and represents either true or false. |
| | 201 | |
| | 202 | ### Function Types |
| | 203 | TODO |
| | 204 | |
| | 205 | ### Array Types |
| | 206 | TODO |
| | 207 | Also, are there slices? |
| | 208 | |
| | 209 | ### Struct Types |
| | 210 | TODO |
| | 211 | |
| | 212 | ### Pointer Types |
| | 213 | TODO |
| 194 | | 214 | |
| 195 | ### Characters and Strings | 215 | ### Unreachable Type |
| | 216 | The unreachable type has the name `unreachable`. TODO explanation |
| 196 | | 217 | |
| 197 | | Example | Characters | Escapes | Null Term | Type | 218 | ### Void Type |
| 198 | ----------------|----------|-------------|----------------|-----------|---------- | 219 | The void type has the name `void`. TODO explanation |
| 199 | Byte | 'H' | All ASCII | Byte | No | u8 | | |
| 200 | UTF-8 Bytes | "hello" | All Unicode | Byte & Unicode | No | [5; u8] | | |
| 201 | UTF-8 C string | c"hello" | All Unicode | Byte & Unicode | Yes | *const u8 | | |
| 202 | | 220 | |
| 203 | ### Byte Escapes | | |
| 204 | | 221 | |
| 205 | | Name | 222 | ## Expressions |
| 206 | ------|---------------------------------------- | 223 | |
| 207 | \x7F | 8-bit character code (exactly 2 digits) | 224 | ### Literals |
| 208 | \n | Newline | 225 | |
| 209 | \r | Carriage return | 226 | #### Character and String Literals |
| 210 | \t | Tab | 227 | ``` |
| 211 | \\ | Backslash | 228 | Literal Example Characters Escapes Null Term Type |
| 212 | \0 | Null | 229 | |
| 213 | \' | Single quote | 230 | Byte 'H' All ASCII Byte No u8 |
| 214 | \" | Double quote | 231 | UTF-8 Bytes "hello" All Unicode Byte & Unicode No [5; u8] |
| | 232 | UTF-8 C string c"hello" All Unicode Byte & Unicode Yes const u8 |
| | 233 | ``` |
| | 234 | |
| | 235 | ``` |
| | 236 | Escape Name |
| | 237 | |
| | 238 | \xNN hexadecimal 8-bit character code (exactly 2 digits) |
| | 239 | \n Newline |
| | 240 | \r Carriage return |
| | 241 | \t Tab |
| | 242 | \\ Backslash |
| | 243 | \0 Null |
| | 244 | \' Single quote |
| | 245 | \" Double quote |
| | 246 | ``` |
| 215 | | 247 | |
| 216 | ### Unicode Escapes | 248 | ### Unicode Escapes |
| 217 | | 249 | |
| 218 | | Name | 250 | Escape | Name |
| 219 | ----------|----------------------------------------------- | 251 | ------------|----------------------------------------------- |
| 220 | \u{7FFF} | 24-bit Unicode character code (up to 6 digits) | 252 | \u{NNNNNN} | hexadecimal 24-bit Unicode character code (up to 6 digits) |
| | 253 | |
| | 254 | #### Numeric Literals |
| | 255 | |
| | 256 | ``` |
| | 257 | Number literals Example Exponentiation |
| | 258 | |
| | 259 | Decimal integer 98222 N/A |
| | 260 | Hex integer 0xff N/A |
| | 261 | Octal integer 0o77 N/A |
| | 262 | Binary integer 0b11110000 N/A |
| | 263 | Floating-point 123.0E+77 Optional |
| | 264 | Hex floating point TODO TODO |
| | 265 | ``` |
| | 266 | |
| | 267 | ### Identifiers |
| | 268 | TODO |
| | 269 | |
| | 270 | ### Declarations |
| | 271 | Declarations have type `void`. |
| | 272 | |
| | 273 | #### Function Declarations |
| | 274 | TODO |
| | 275 | |
| | 276 | #### Variable Declarations |
| | 277 | TODO |
| | 278 | |
| | 279 | #### Struct Declarations |
| | 280 | TODO |
| | 281 | |
| | 282 | #### Enum Declarations |
| | 283 | TODO |
| | 284 | |
| | 285 | |
| | 286 | ## Built-in Functions |
| | 287 | Built-in functions are prefixed with `@`. |
| | 288 | |
| | 289 | ### Typeof |
| | 290 | TODO |
| | 291 | |
| | 292 | ### Sizeof |
| | 293 | TODO |
| | 294 | |
| | 295 | ### Overflow Arithmetic |
| | 296 | Overflow arithmetic functions have defined behavior on overflow or underflow. TODO what is that behaviour? |
| | 297 | |
| | 298 | The functions take an integer (TODO float?) type, two variables of the specified type, and a pointer to a variable of the specified type where the result is stored. The functions return a boolean value: true of overflow/underflow occurred, false otherwise. |
| | 299 | |
| | 300 | ``` |
| | 301 | Function Operation |
| | 302 | bool add_with_overflow(type, a: type, b: type, x: &type) *x = a + b |
| | 303 | bool sub_with_overflow(type, a: type, b: type, x: &type) *x = a - b |
| | 304 | bool mul_with_overflow(type, a: type, b: type, x: &type) *x = a * b |
| | 305 | ``` |
| | 306 | |
| | 307 | ### Memory Operations |
| | 308 | TODO memset and memcpy |
| 221 | | 309 | |
| 222 | ### Numbers | 310 | ### Value Count |
| | 311 | TODO |
| 223 | | 312 | |
| 224 | Number literals | Example | Exponentiation | 313 | ### Max and Min Value |
| 225 | --------------------|-------------|--------------- | 314 | TODO |
| 226 | Decimal integer | 98222 | N/A | | |
| 227 | Hex integer | 0xff | N/A | | |
| 228 | Octal integer | 0o77 | N/A | | |
| 229 | Binary integer | 0b11110000 | N/A | | |
| 230 | Floating-point | 123.0E+77 | Optional | | |
| 231 | Hex floating point | TODO | TODO | | |