# stage2: progress towards basic structs · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/97d7fddfb78d17132749cae59fea36fe661bf642)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: 97d7fddfb78d17132749cae59fea36fe661bf642

Requested commit: 97d7fddfb78d17132749cae59fea36fe661bf642

Commit: 97d7fddfb78d17132749cae59fea36fe661bf642

Tree: 5b01a32f9ee35e6cef838cffb5058e5f0f777229

Author: Andrew Kelley

Committer: Andrew Kelley

## Message

````
stage2: progress towards basic structs

Introduce `ResultLoc.none_or_ref` which is used by field access
expressions to avoid unnecessary loads when the field access itself
will do the load. This turns:

```zig
p.y - p.x - p.x
```

from

```zir
  %14 = load(%4) node_offset:8:12
  %15 = field_val(%14, "y") node_offset:8:13
  %16 = load(%4) node_offset:8:18
  %17 = field_val(%16, "x") node_offset:8:19
  %18 = sub(%15, %17) node_offset:8:16
  %19 = load(%4) node_offset:8:24
  %20 = field_val(%19, "x") node_offset:8:25
```

to

```zir
  %14 = field_val(%4, "y") node_offset:8:13
  %15 = field_val(%4, "x") node_offset:8:19
  %16 = sub(%14, %15) node_offset:8:16
  %17 = field_val(%4, "x") node_offset:8:25
```

Much more compact. This requires `Sema.zirFieldVal` to support both
pointers and non-pointers.

C backend: Implement typedefs for struct types, as well as the following
TZIR instructions:
 * mul
 * mulwrap
 * addwrap
 * subwrap
 * ref
 * struct_field_ptr

Note that add, addwrap, sub, subwrap, mul, mulwrap instructions are all
incorrect currently and need to be updated to properly handle wrapping
and non wrapping for signed and unsigned.

C backend: change indentation delta to 1, to make the output smaller and
to process fewer bytes.

I promise I will add a test case as soon as I fix those warnings that
are being printed for my test case.

````

## Parents

- [43d364afef7f0609f9d897c7ff129ba6b9b3cab0](https://git.cafe/gitcafe/zig/commit/43d364afef7f0609f9d897c7ff129ba6b9b3cab0?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/97d7fddfb78d17132749cae59fea36fe661bf642?format=markdown)
