Commit Graph

30 Commits

Author SHA1 Message Date
Andrew Kelley
22e39e1e5a
fix tagged union with only 1 field tripping assertion
closes #1495

now the tag type of an enum with only 1 item is comptime_int.
2018-09-13 13:33:11 -04:00
Andrew Kelley
ffb3b1576b
stage1: fix tagged union with no payloads
closes #1478
2018-09-05 16:19:58 -04:00
Andrew Kelley
9bd8b01650 fix tagged union initialization with a runtime void
closes #1328
2018-08-03 15:21:08 -04:00
Andrew Kelley
a3ddd0826b remove enum to/from int casting syntax; add @enumToInt/@intToEnum
see #1061
2018-06-19 03:50:38 -04:00
Andrew Kelley
fcbb7426fa use * for pointer type instead of &
See #770

To help automatically translate code, see the
zig-fmt-pointer-reform-2 branch.

This will convert all & into *. Due to the syntax
ambiguity (which is why we are making this change),
even address-of & will turn into *, so you'll have
to manually fix thes instances. You will be guaranteed
to get compile errors for them - expected 'type', found 'foo'
2018-05-31 17:28:07 -04:00
Andrew Kelley
0c16cd2d0e run zig fmt on the codebase
See #1003
2018-05-29 04:23:38 -04:00
Andrew Kelley
6928badd85 Merge branch 'master' into pointer-reform 2018-05-09 23:43:07 -04:00
Andrew Kelley
77a1a216d2 tagged union field access prioritizes members over enum tags
closes #959
2018-05-07 16:43:20 -04:00
Alexandros Naskos
ff1c4e1f13 Added tests. 2018-05-01 13:00:39 +03:00
Andrew Kelley
a35b366eb6 [breaking] delete ptr deref prefix op
start using zig-fmt-pointer-reform branch build of zig fmt
to fix code to use the new syntax

all of test/cases/* are processed, but there are more left
to be done - all the std lib used by the behavior tests
2018-04-30 20:35:54 -04:00
Andrew Kelley
39d5f44863 *WI* error sets - basic support working 2018-02-02 14:26:14 -05:00
Andrew Kelley
3671582c15 syntax: functions require return type. remove ->
The purpose of this is:

 * Only one way to do things
 * Changing a function with void return type to return a possible
   error becomes a 1 character change, subtly encouraging
   people to use errors.

See #632

Here are some imperfect sed commands for performing this update:

remove arrow:

```
sed -i 's/\(\bfn\b.*\)-> /\1/g' $(find . -name "*.zig")
```

add void:

```
sed -i 's/\(\bfn\b.*\))\s*{/\1) void {/g' $(find ../ -name "*.zig")
```

Some cleanup may be necessary, but this should do the bulk of the work.
2018-01-25 04:10:11 -05:00
Andrew Kelley
cacba6f435 fix crash on union-enums with only 1 field
closes #713
2018-01-22 17:23:23 -05:00
Andrew Kelley
3c094116aa remove %% prefix operator
See #632
closes #545
closes #510

this makes #651 higher priority
2018-01-09 00:51:51 -05:00
Andrew Kelley
2a25398c86 fix segfault when passing union enum with sub byte...
...field to const slice parameter

we use a packed struct internally to represent a const array
of disparate union values, and needed to update the internal
getelementptr instruction to recognize that.

closes #664
2017-12-24 04:11:58 -05:00
Andrew Kelley
756a218e27 add implicit cast from enum tag type of union to const ptr to the union
closes #654
2017-12-08 17:49:14 -05:00
Andrew Kelley
c49ee9f632 allow union and its tag type to peer resolve to the tag type 2017-12-05 21:33:24 -05:00
Andrew Kelley
2715f6fdb8 allow implicit cast from union to its enum tag type
closes #642
2017-12-05 21:10:47 -05:00
Andrew Kelley
960914a073 add implicit cast from enum to union
when the enum is the tag type of the union and is comptime known
to be of a void field of the union

See #642
2017-12-05 20:46:58 -05:00
Andrew Kelley
76f3bdfff8 add test for casting union to tag type of union 2017-12-04 02:12:13 -05:00
Andrew Kelley
54138d9e82 add test for union with 1 void field being 0 bits 2017-12-04 02:05:33 -05:00
Andrew Kelley
084911d9b3 add test for @sizeOf on extern and packed unions 2017-12-04 02:04:08 -05:00
Andrew Kelley
fce435db26 fix abi alignment of union-enums not counting tag type
add more tests for unions

See #618
2017-12-04 00:32:12 -05:00
Andrew Kelley
5a8367e892 rename @EnumTagType to @TagType. add tests for union-enums
See #618
2017-12-03 22:36:01 -05:00
Andrew Kelley
0ad1239522 rework enums and unions and their relationship to each other
* @enumTagName renamed to @tagName and it works on enums and
   union-enums
 * Remove the EnumTag type. Now there is only enum and union,
   and the tag type of a union is always an enum.
 * unions support specifying the tag enum type, and they support
   inferring an enum tag type.
 * Enums no longer support field types but they do support
   setting the tag values. Likewise union-enums when inferring
   an enum tag type support setting the tag values.
 * It is now an error for enums and unions to have 0 fields.
 * switch statements support union-enums

closes #618
2017-12-03 20:43:56 -05:00
Andrew Kelley
5d2ba056c8 fix codegen for union init with runtime value
see #144
2017-11-16 22:06:08 -05:00
Andrew Kelley
e26ccd5166 debug safety for unions 2017-11-16 21:15:15 -05:00
Andrew Kelley
018cbff438 unions have a secret field for the type
See #144
2017-11-15 22:52:47 -05:00
Andrew Kelley
f276fd0f37 basic union support
See #144
2017-11-15 13:04:18 -05:00
Andrew Kelley
4c306af4eb add test case for previous commit 2017-10-27 01:22:48 -04:00