How do I store slices in structures in Zig?
I have a function call structure that stores an array of arguments.
pub const FunCall = struct {
id: Ident,
args: ArrayList(Atom),
};
pub const Atom = union(enum) {
register: Register,
register_index: RegisterIndex,
constant: Constant,
variable: Ident,
macro_arg: Ident,
data: void, // instruction data buffer
};
Is there a better way to do it than this?
const data_id = IR.Ident{ .name = "get_data", .loc = field.id.loc };
var data_temp = [_]IR.Atom{
.{ .variable = idnoloc("data") },
.{ .variable = idnoloc("offset") },
.{ .variable = idnoloc("size") },
.{ .variable = idnoloc("alignment") },
};
var data_args = ArrayList(IR.Atom).init(ir.alloc);
try data_args.appendSlice(&data_temp);
const get_data_expr = IR.Expr{
.fun_call = .{ .id = data_id, .args = data_args },
};