Skip to content

Commit

Permalink
compiler: rename "@xtoy" to "@YFromX", zig fmt: rewrite them
Browse files Browse the repository at this point in the history
Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>
  • Loading branch information
BratishkaErik authored and andrewrk committed Jun 19, 2023
1 parent e6e8cac commit a6c8ee5
Show file tree
Hide file tree
Showing 22 changed files with 339 additions and 319 deletions.
20 changes: 20 additions & 0 deletions lib/std/zig/render.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1396,6 +1396,26 @@ fn renderBuiltinCall(
try ais.writer().writeAll("@max");
} else if (mem.eql(u8, slice, "@minimum")) {
try ais.writer().writeAll("@min");
}
//
else if (mem.eql(u8, slice, "@boolToInt")) {
try ais.writer().writeAll("@intFromBool");
} else if (mem.eql(u8, slice, "@enumToInt")) {
try ais.writer().writeAll("@intFromEnum");
} else if (mem.eql(u8, slice, "@errorToInt")) {
try ais.writer().writeAll("@intFromError");
} else if (mem.eql(u8, slice, "@floatToInt")) {
try ais.writer().writeAll("@intFromFloat");
} else if (mem.eql(u8, slice, "@intToEnum")) {
try ais.writer().writeAll("@enumFromInt");
} else if (mem.eql(u8, slice, "@intToError")) {
try ais.writer().writeAll("@errorFromInt");
} else if (mem.eql(u8, slice, "@intToFloat")) {
try ais.writer().writeAll("@floatFromInt");
} else if (mem.eql(u8, slice, "@intToPtr")) {
try ais.writer().writeAll("@ptrFromInt");
} else if (mem.eql(u8, slice, "@ptrToInt")) {
try ais.writer().writeAll("@intFromPtr");
} else {
try renderToken(ais, tree, builtin_token, .none); // @name
}
Expand Down
32 changes: 16 additions & 16 deletions src/Air.zig
Original file line number Diff line number Diff line change
Expand Up @@ -478,11 +478,11 @@ pub const Inst = struct {
/// Converts a pointer to its address. Result type is always `usize`.
/// Pointer type size may be any, including slice.
/// Uses the `un_op` field.
ptrtoint,
int_from_ptr,
/// Given a boolean, returns 0 or 1.
/// Result type is always `u1`.
/// Uses the `un_op` field.
bool_to_int,
int_from_bool,
/// Return a value from a function.
/// Result type is always noreturn; no instructions in a block follow this one.
/// Uses the `un_op` field.
Expand Down Expand Up @@ -629,12 +629,12 @@ pub const Inst = struct {
array_to_slice,
/// Given a float operand, return the integer with the closest mathematical meaning.
/// Uses the `ty_op` field.
float_to_int,
/// Same as `float_to_int` with optimized float mode.
float_to_int_optimized,
int_from_float,
/// Same as `int_from_float` with optimized float mode.
int_from_float_optimized,
/// Given an integer operand, return the float with the closest mathematical meaning.
/// Uses the `ty_op` field.
int_to_float,
float_from_int,

/// Transforms a vector into a scalar value by performing a sequential
/// horizontal reduction of its elements using the specified operator.
Expand Down Expand Up @@ -1337,9 +1337,9 @@ pub fn typeOfIndex(air: Air, inst: Air.Inst.Index, ip: *const InternPool) Type {
.struct_field_ptr_index_2,
.struct_field_ptr_index_3,
.array_to_slice,
.float_to_int,
.float_to_int_optimized,
.int_to_float,
.int_from_float,
.int_from_float_optimized,
.float_from_int,
.splat,
.get_union_tag,
.clz,
Expand Down Expand Up @@ -1387,7 +1387,7 @@ pub fn typeOfIndex(air: Air, inst: Air.Inst.Index, ip: *const InternPool) Type {
.c_va_end,
=> return Type.void,

.ptrtoint,
.int_from_ptr,
.slice_len,
.ret_addr,
.frame_addr,
Expand All @@ -1397,7 +1397,7 @@ pub fn typeOfIndex(air: Air, inst: Air.Inst.Index, ip: *const InternPool) Type {
.wasm_memory_grow => return Type.i32,
.wasm_memory_size => return Type.u32,

.bool_to_int => return Type.u1,
.int_from_bool => return Type.u1,

.tag_name, .error_name => return Type.slice_const_u8_sentinel_0,

Expand Down Expand Up @@ -1687,8 +1687,8 @@ pub fn mustLower(air: Air, inst: Air.Inst.Index, ip: *const InternPool) bool {
.is_non_err_ptr,
.bool_and,
.bool_or,
.ptrtoint,
.bool_to_int,
.int_from_ptr,
.int_from_bool,
.fptrunc,
.fpext,
.intcast,
Expand Down Expand Up @@ -1718,9 +1718,9 @@ pub fn mustLower(air: Air, inst: Air.Inst.Index, ip: *const InternPool) bool {
.slice_elem_ptr,
.ptr_elem_ptr,
.array_to_slice,
.float_to_int,
.float_to_int_optimized,
.int_to_float,
.int_from_float,
.int_from_float_optimized,
.float_from_int,
.reduce,
.reduce_optimized,
.splat,
Expand Down
38 changes: 19 additions & 19 deletions src/AstGen.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2626,15 +2626,15 @@ fn addEnsureResult(gz: *GenZir, maybe_unused_result: Zir.Inst.Ref, statement: As
.error_set_decl,
.error_set_decl_anon,
.error_set_decl_func,
.int_to_enum,
.enum_to_int,
.enum_from_int,
.int_from_enum,
.type_info,
.size_of,
.bit_size_of,
.typeof_log2_int_type,
.ptr_to_int,
.int_from_ptr,
.align_of,
.bool_to_int,
.int_from_bool,
.embed_file,
.error_name,
.sqrt,
Expand All @@ -2655,9 +2655,9 @@ fn addEnsureResult(gz: *GenZir, maybe_unused_result: Zir.Inst.Ref, statement: As
.type_name,
.frame_type,
.frame_size,
.float_to_int,
.int_to_float,
.int_to_ptr,
.int_from_float,
.float_from_int,
.ptr_from_int,
.float_cast,
.int_cast,
.ptr_cast,
Expand Down Expand Up @@ -8281,11 +8281,11 @@ fn builtinCall(
.bit_size_of => return simpleUnOpType(gz, scope, ri, node, params[0], .bit_size_of),
.align_of => return simpleUnOpType(gz, scope, ri, node, params[0], .align_of),

.ptr_to_int => return simpleUnOp(gz, scope, ri, node, .{ .rl = .none }, params[0], .ptr_to_int),
.int_from_ptr => return simpleUnOp(gz, scope, ri, node, .{ .rl = .none }, params[0], .int_from_ptr),
.compile_error => return simpleUnOp(gz, scope, ri, node, .{ .rl = .{ .ty = .slice_const_u8_type } }, params[0], .compile_error),
.set_eval_branch_quota => return simpleUnOp(gz, scope, ri, node, .{ .rl = .{ .coerced_ty = .u32_type } }, params[0], .set_eval_branch_quota),
.enum_to_int => return simpleUnOp(gz, scope, ri, node, .{ .rl = .none }, params[0], .enum_to_int),
.bool_to_int => return simpleUnOp(gz, scope, ri, node, bool_ri, params[0], .bool_to_int),
.int_from_enum => return simpleUnOp(gz, scope, ri, node, .{ .rl = .none }, params[0], .int_from_enum),
.int_from_bool => return simpleUnOp(gz, scope, ri, node, bool_ri, params[0], .int_from_bool),
.embed_file => return simpleUnOp(gz, scope, ri, node, .{ .rl = .{ .ty = .slice_const_u8_type } }, params[0], .embed_file),
.error_name => return simpleUnOp(gz, scope, ri, node, .{ .rl = .{ .ty = .anyerror_type } }, params[0], .error_name),
.set_runtime_safety => return simpleUnOp(gz, scope, ri, node, bool_ri, params[0], .set_runtime_safety),
Expand All @@ -8308,10 +8308,10 @@ fn builtinCall(
.Frame => return simpleUnOp(gz, scope, ri, node, .{ .rl = .none }, params[0], .frame_type),
.frame_size => return simpleUnOp(gz, scope, ri, node, .{ .rl = .none }, params[0], .frame_size),

.float_to_int => return typeCast(gz, scope, ri, node, params[0], params[1], .float_to_int),
.int_to_float => return typeCast(gz, scope, ri, node, params[0], params[1], .int_to_float),
.int_to_ptr => return typeCast(gz, scope, ri, node, params[0], params[1], .int_to_ptr),
.int_to_enum => return typeCast(gz, scope, ri, node, params[0], params[1], .int_to_enum),
.int_from_float => return typeCast(gz, scope, ri, node, params[0], params[1], .int_from_float),
.float_from_int => return typeCast(gz, scope, ri, node, params[0], params[1], .float_from_int),
.ptr_from_int => return typeCast(gz, scope, ri, node, params[0], params[1], .ptr_from_int),
.enum_from_int => return typeCast(gz, scope, ri, node, params[0], params[1], .enum_from_int),
.float_cast => return typeCast(gz, scope, ri, node, params[0], params[1], .float_cast),
.int_cast => return typeCast(gz, scope, ri, node, params[0], params[1], .int_cast),
.ptr_cast => return typeCast(gz, scope, ri, node, params[0], params[1], .ptr_cast),
Expand Down Expand Up @@ -8352,17 +8352,17 @@ fn builtinCall(
_ = try gz.addNode(.trap, node);
return rvalue(gz, ri, .unreachable_value, node);
},
.error_to_int => {
.int_from_error => {
const operand = try expr(gz, scope, .{ .rl = .none }, params[0]);
const result = try gz.addExtendedPayload(.error_to_int, Zir.Inst.UnNode{
const result = try gz.addExtendedPayload(.int_from_error, Zir.Inst.UnNode{
.node = gz.nodeIndexToRelative(node),
.operand = operand,
});
return rvalue(gz, ri, result, node);
},
.int_to_error => {
.error_from_int => {
const operand = try expr(gz, scope, .{ .rl = .{ .coerced_ty = .u16_type } }, params[0]);
const result = try gz.addExtendedPayload(.int_to_error, Zir.Inst.UnNode{
const result = try gz.addExtendedPayload(.error_from_int, Zir.Inst.UnNode{
.node = gz.nodeIndexToRelative(node),
.operand = operand,
});
Expand Down Expand Up @@ -8769,7 +8769,7 @@ fn simpleUnOp(
else
try expr(gz, scope, operand_ri, operand_node);
switch (tag) {
.tag_name, .error_name, .ptr_to_int => try emitDbgStmt(gz, cursor),
.tag_name, .error_name, .int_from_ptr => try emitDbgStmt(gz, cursor),
else => {},
}
const result = try gz.addUnNode(tag, operand, node);
Expand Down
18 changes: 9 additions & 9 deletions src/Autodoc.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1473,7 +1473,7 @@ fn walkInstruction(

// builtin functions
.align_of,
.bool_to_int,
.int_from_bool,
.embed_file,
.error_name,
.panic,
Expand All @@ -1496,7 +1496,7 @@ fn walkInstruction(
.type_name,
.frame_type,
.frame_size,
.ptr_to_int,
.int_from_ptr,
.bit_not,
// @check
.clz,
Expand All @@ -1521,10 +1521,10 @@ fn walkInstruction(
};
},

.float_to_int,
.int_to_float,
.int_to_ptr,
.int_to_enum,
.int_from_float,
.float_from_int,
.ptr_from_int,
.enum_from_int,
.float_cast,
.int_cast,
.ptr_cast,
Expand Down Expand Up @@ -1936,7 +1936,7 @@ fn walkInstruction(
.expr = .{ .bitSizeOf = operand_index },
};
},
.enum_to_int => {
.int_from_enum => {
// not working correctly with `align()`
const un_node = data[inst_index].un_node;
const operand = try self.walkRef(
Expand Down Expand Up @@ -3021,8 +3021,8 @@ fn walkInstruction(
},
};
},
.error_to_int,
.int_to_error,
.int_from_error,
.error_from_int,
.reify,
.const_cast,
.volatile_cast,
Expand Down
Loading

0 comments on commit a6c8ee5

Please sign in to comment.