mirror of
https://github.com/ziglang/zig.git
synced 2024-11-15 00:26:57 +00:00
delete packed enums from the language
No need for any such thing. Instead, provide an integer tag type for the enum.
This commit is contained in:
parent
329a359974
commit
8dd7378013
@ -2588,7 +2588,7 @@ test "default struct initialization fields" {
|
||||
exactly their bit width.
|
||||
</li>
|
||||
<li>{#syntax#}bool{#endsyntax#} fields use exactly 1 bit.</li>
|
||||
<li>A {#link|packed enum#} field uses exactly the bit width of its integer tag type.</li>
|
||||
<li>An {#link|enum#} field uses exactly the bit width of its integer tag type.</li>
|
||||
<li>A {#link|packed union#} field uses exactly the bit width of the union field with
|
||||
the largest bit width.</li>
|
||||
<li>Non-ABI-aligned fields are packed into the smallest possible
|
||||
@ -2983,25 +2983,6 @@ export fn entry(foo: Foo) void { }
|
||||
{#code_end#}
|
||||
{#header_close#}
|
||||
|
||||
{#header_open|packed enum#}
|
||||
<p>By default, the size of enums is not guaranteed.</p>
|
||||
<p>{#syntax#}packed enum{#endsyntax#} causes the size of the enum to be the same as the size of the
|
||||
integer tag type of the enum:</p>
|
||||
{#code_begin|test#}
|
||||
const std = @import("std");
|
||||
|
||||
test "packed enum" {
|
||||
const Number = packed enum(u8) {
|
||||
one,
|
||||
two,
|
||||
three,
|
||||
};
|
||||
std.testing.expect(@sizeOf(Number) == @sizeOf(u8));
|
||||
}
|
||||
{#code_end#}
|
||||
<p>This makes the enum eligible to be in a {#link|packed struct#}.</p>
|
||||
{#header_close#}
|
||||
|
||||
{#header_open|Enum Literals#}
|
||||
<p>
|
||||
Enum literals allow specifying the name of an enum field without specifying the enum type:
|
||||
|
@ -398,10 +398,10 @@ pub const Insn = packed struct {
|
||||
|
||||
/// r0 - r9 are general purpose 64-bit registers, r10 points to the stack
|
||||
/// frame
|
||||
pub const Reg = packed enum(u4) { r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10 };
|
||||
const Source = packed enum(u1) { reg, imm };
|
||||
pub const Reg = enum(u4) { r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10 };
|
||||
const Source = enum(u1) { reg, imm };
|
||||
|
||||
const Mode = packed enum(u8) {
|
||||
const Mode = enum(u8) {
|
||||
imm = IMM,
|
||||
abs = ABS,
|
||||
ind = IND,
|
||||
@ -410,7 +410,7 @@ pub const Insn = packed struct {
|
||||
msh = MSH,
|
||||
};
|
||||
|
||||
const AluOp = packed enum(u8) {
|
||||
const AluOp = enum(u8) {
|
||||
add = ADD,
|
||||
sub = SUB,
|
||||
mul = MUL,
|
||||
@ -426,14 +426,14 @@ pub const Insn = packed struct {
|
||||
arsh = ARSH,
|
||||
};
|
||||
|
||||
pub const Size = packed enum(u8) {
|
||||
pub const Size = enum(u8) {
|
||||
byte = B,
|
||||
half_word = H,
|
||||
word = W,
|
||||
double_word = DW,
|
||||
};
|
||||
|
||||
const JmpOp = packed enum(u8) {
|
||||
const JmpOp = enum(u8) {
|
||||
ja = JA,
|
||||
jeq = JEQ,
|
||||
jgt = JGT,
|
||||
|
Loading…
Reference in New Issue
Block a user