authorgravatar for liam@bumblebee.net.nzMovingtoMars <liam@bumblebee.net.nz> 2016-01-20 21:27:53+13:00
committergravatar for liam@bumblebee.net.nzMovingtoMars <liam@bumblebee.net.nz> 2016-01-20 21:27:53+13:00
log26b9d709aa579c16251796ae59defc799ccfaf39
treeff4eb314415839262c301feb2fa02022da31b9e0
parent3eca42c17be1105dbc76c22fdc8447bccf11de0d

start working on lang spec


1 files changed, 140 insertions(+), 57 deletions(-)

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