| ... | ... | @@ -1,33 +0,0 @@ |
| 1 | | # Code Generation |
| 2 | | |
| 3 | | ## Data Representation |
| 4 | | |
| 5 | | Every type has a "handle". If a type is a simple primitive type such as i32 or |
| 6 | | f64, the handle is "by value", meaning that we pass around the value itself when |
| 7 | | we refer to a value of that type. |
| 8 | | |
| 9 | | If a type is a container, error union, optional type, slice, or array, then its |
| 10 | | handle is a pointer, and everywhere we refer to a value of this type we refer to |
| 11 | | a pointer. |
| 12 | | |
| 13 | | Parameters and return values are always passed as handles. |
| 14 | | |
| 15 | | Error union types are represented as: |
| 16 | | |
| 17 | | struct { |
| 18 | | error: u32, |
| 19 | | payload: T, |
| 20 | | } |
| 21 | | |
| 22 | | Optional types are represented as: |
| 23 | | |
| 24 | | struct { |
| 25 | | payload: T, |
| 26 | | is_non_null: u1, |
| 27 | | } |
| 28 | | |
| 29 | | ## Data Optimizations |
| 30 | | |
| 31 | | Optional pointer types are special: the 0x0 pointer value is used to represent a |
| 32 | | null pointer. Thus, instead of the struct above, optional pointer types are |
| 33 | | represented as a `usize` in codegen and the handle is by value. |