| author | |
| committer | |
| log | 8110639c7964fcb23c2b715f97ab6caa27506b93 |
| tree | 9556ad058e4001c0f0789a0fc82fc570e2d91d32 |
| parent | c2fb4bfff3b1a2bf4e7072cec04d67e8152900c1 |
| signature |
9 files changed, 114 insertions(+), 105 deletions(-)
doc/langref.html.in+44-43| ... | ... | @@ -1785,7 +1785,7 @@ test "fully anonymous list literal" { |
| 1785 | 1785 | dump(.{ @as(u32, 1234), @as(f64, 12.34), true, "hi"}); |
| 1786 | 1786 | } |
| 1787 | 1787 | |
| 1788 | fn dump(args: var) void { | |
| 1788 | fn dump(args: anytype) void { | |
| 1789 | 1789 | assert(args.@"0" == 1234); |
| 1790 | 1790 | assert(args.@"1" == 12.34); |
| 1791 | 1791 | assert(args.@"2"); |
| ... | ... | @@ -2717,7 +2717,7 @@ test "fully anonymous struct" { |
| 2717 | 2717 | }); |
| 2718 | 2718 | } |
| 2719 | 2719 | |
| 2720 | fn dump(args: var) void { | |
| 2720 | fn dump(args: anytype) void { | |
| 2721 | 2721 | assert(args.int == 1234); |
| 2722 | 2722 | assert(args.float == 12.34); |
| 2723 | 2723 | assert(args.b); |
| ... | ... | @@ -4181,14 +4181,14 @@ test "pass struct to function" { |
| 4181 | 4181 | {#header_close#} |
| 4182 | 4182 | {#header_open|Function Parameter Type Inference#} |
| 4183 | 4183 | <p> |
| 4184 | Function parameters can be declared with {#syntax#}var{#endsyntax#} in place of the type. | |
| 4184 | Function parameters can be declared with {#syntax#}anytype{#endsyntax#} in place of the type. | |
| 4185 | 4185 | In this case the parameter types will be inferred when the function is called. |
| 4186 | 4186 | Use {#link|@TypeOf#} and {#link|@typeInfo#} to get information about the inferred type. |
| 4187 | 4187 | </p> |
| 4188 | 4188 | {#code_begin|test#} |
| 4189 | 4189 | const assert = @import("std").debug.assert; |
| 4190 | 4190 | |
| 4191 | fn addFortyTwo(x: var) @TypeOf(x) { | |
| 4191 | fn addFortyTwo(x: anytype) @TypeOf(x) { | |
| 4192 | 4192 | return x + 42; |
| 4193 | 4193 | } |
| 4194 | 4194 | |
| ... | ... | @@ -5974,7 +5974,7 @@ pub fn main() void { |
| 5974 | 5974 | |
| 5975 | 5975 | {#code_begin|syntax#} |
| 5976 | 5976 | /// Calls print and then flushes the buffer. |
| 5977 | pub fn printf(self: *OutStream, comptime format: []const u8, args: var) anyerror!void { | |
| 5977 | pub fn printf(self: *OutStream, comptime format: []const u8, args: anytype) anyerror!void { | |
| 5978 | 5978 | const State = enum { |
| 5979 | 5979 | Start, |
| 5980 | 5980 | OpenBrace, |
| ... | ... | @@ -6060,7 +6060,7 @@ pub fn printf(self: *OutStream, arg0: i32, arg1: []const u8) !void { |
| 6060 | 6060 | on the type: |
| 6061 | 6061 | </p> |
| 6062 | 6062 | {#code_begin|syntax#} |
| 6063 | pub fn printValue(self: *OutStream, value: var) !void { | |
| 6063 | pub fn printValue(self: *OutStream, value: anytype) !void { | |
| 6064 | 6064 | switch (@typeInfo(@TypeOf(value))) { |
| 6065 | 6065 | .Int => { |
| 6066 | 6066 | return self.printInt(T, value); |
| ... | ... | @@ -6686,7 +6686,7 @@ fn readFile(allocator: *Allocator, filename: []const u8) ![]u8 { |
| 6686 | 6686 | </p> |
| 6687 | 6687 | {#header_close#} |
| 6688 | 6688 | {#header_open|@alignCast#} |
| 6689 | <pre>{#syntax#}@alignCast(comptime alignment: u29, ptr: var) var{#endsyntax#}</pre> | |
| 6689 | <pre>{#syntax#}@alignCast(comptime alignment: u29, ptr: anytype) anytype{#endsyntax#}</pre> | |
| 6690 | 6690 | <p> |
| 6691 | 6691 | {#syntax#}ptr{#endsyntax#} can be {#syntax#}*T{#endsyntax#}, {#syntax#}fn(){#endsyntax#}, {#syntax#}?*T{#endsyntax#}, |
| 6692 | 6692 | {#syntax#}?fn(){#endsyntax#}, or {#syntax#}[]T{#endsyntax#}. It returns the same type as {#syntax#}ptr{#endsyntax#} |
| ... | ... | @@ -6723,7 +6723,7 @@ comptime { |
| 6723 | 6723 | {#header_close#} |
| 6724 | 6724 | |
| 6725 | 6725 | {#header_open|@asyncCall#} |
| 6726 | <pre>{#syntax#}@asyncCall(frame_buffer: []align(@alignOf(@Frame(anyAsyncFunction))) u8, result_ptr, function_ptr, args: var) anyframe->T{#endsyntax#}</pre> | |
| 6726 | <pre>{#syntax#}@asyncCall(frame_buffer: []align(@alignOf(@Frame(anyAsyncFunction))) u8, result_ptr, function_ptr, args: anytype) anyframe->T{#endsyntax#}</pre> | |
| 6727 | 6727 | <p> |
| 6728 | 6728 | {#syntax#}@asyncCall{#endsyntax#} performs an {#syntax#}async{#endsyntax#} call on a function pointer, |
| 6729 | 6729 | which may or may not be an {#link|async function|Async Functions#}. |
| ... | ... | @@ -6811,7 +6811,7 @@ fn func(y: *i32) void { |
| 6811 | 6811 | </p> |
| 6812 | 6812 | {#header_close#} |
| 6813 | 6813 | {#header_open|@bitCast#} |
| 6814 | <pre>{#syntax#}@bitCast(comptime DestType: type, value: var) DestType{#endsyntax#}</pre> | |
| 6814 | <pre>{#syntax#}@bitCast(comptime DestType: type, value: anytype) DestType{#endsyntax#}</pre> | |
| 6815 | 6815 | <p> |
| 6816 | 6816 | Converts a value of one type to another type. |
| 6817 | 6817 | </p> |
| ... | ... | @@ -6932,7 +6932,7 @@ fn func(y: *i32) void { |
| 6932 | 6932 | {#header_close#} |
| 6933 | 6933 | |
| 6934 | 6934 | {#header_open|@call#} |
| 6935 | <pre>{#syntax#}@call(options: std.builtin.CallOptions, function: var, args: var) var{#endsyntax#}</pre> | |
| 6935 | <pre>{#syntax#}@call(options: std.builtin.CallOptions, function: anytype, args: anytype) anytype{#endsyntax#}</pre> | |
| 6936 | 6936 | <p> |
| 6937 | 6937 | Calls a function, in the same way that invoking an expression with parentheses does: |
| 6938 | 6938 | </p> |
| ... | ... | @@ -7279,7 +7279,7 @@ test "main" { |
| 7279 | 7279 | {#header_close#} |
| 7280 | 7280 | |
| 7281 | 7281 | {#header_open|@enumToInt#} |
| 7282 | <pre>{#syntax#}@enumToInt(enum_or_tagged_union: var) var{#endsyntax#}</pre> | |
| 7282 | <pre>{#syntax#}@enumToInt(enum_or_tagged_union: anytype) anytype{#endsyntax#}</pre> | |
| 7283 | 7283 | <p> |
| 7284 | 7284 | Converts an enumeration value into its integer tag type. When a tagged union is passed, |
| 7285 | 7285 | the tag value is used as the enumeration value. |
| ... | ... | @@ -7314,7 +7314,7 @@ test "main" { |
| 7314 | 7314 | {#header_close#} |
| 7315 | 7315 | |
| 7316 | 7316 | {#header_open|@errorToInt#} |
| 7317 | <pre>{#syntax#}@errorToInt(err: var) std.meta.IntType(false, @sizeOf(anyerror) * 8){#endsyntax#}</pre> | |
| 7317 | <pre>{#syntax#}@errorToInt(err: anytype) std.meta.IntType(false, @sizeOf(anyerror) * 8){#endsyntax#}</pre> | |
| 7318 | 7318 | <p> |
| 7319 | 7319 | Supports the following types: |
| 7320 | 7320 | </p> |
| ... | ... | @@ -7334,7 +7334,7 @@ test "main" { |
| 7334 | 7334 | {#header_close#} |
| 7335 | 7335 | |
| 7336 | 7336 | {#header_open|@errSetCast#} |
| 7337 | <pre>{#syntax#}@errSetCast(comptime T: DestType, value: var) DestType{#endsyntax#}</pre> | |
| 7337 | <pre>{#syntax#}@errSetCast(comptime T: DestType, value: anytype) DestType{#endsyntax#}</pre> | |
| 7338 | 7338 | <p> |
| 7339 | 7339 | Converts an error value from one error set to another error set. Attempting to convert an error |
| 7340 | 7340 | which is not in the destination error set results in safety-protected {#link|Undefined Behavior#}. |
| ... | ... | @@ -7342,7 +7342,7 @@ test "main" { |
| 7342 | 7342 | {#header_close#} |
| 7343 | 7343 | |
| 7344 | 7344 | {#header_open|@export#} |
| 7345 | <pre>{#syntax#}@export(target: var, comptime options: std.builtin.ExportOptions) void{#endsyntax#}</pre> | |
| 7345 | <pre>{#syntax#}@export(target: anytype, comptime options: std.builtin.ExportOptions) void{#endsyntax#}</pre> | |
| 7346 | 7346 | <p> |
| 7347 | 7347 | Creates a symbol in the output object file. |
| 7348 | 7348 | </p> |
| ... | ... | @@ -7387,7 +7387,7 @@ export fn @"A function name that is a complete sentence."() void {} |
| 7387 | 7387 | {#header_close#} |
| 7388 | 7388 | |
| 7389 | 7389 | {#header_open|@field#} |
| 7390 | <pre>{#syntax#}@field(lhs: var, comptime field_name: []const u8) (field){#endsyntax#}</pre> | |
| 7390 | <pre>{#syntax#}@field(lhs: anytype, comptime field_name: []const u8) (field){#endsyntax#}</pre> | |
| 7391 | 7391 | <p>Performs field access by a compile-time string. |
| 7392 | 7392 | </p> |
| 7393 | 7393 | {#code_begin|test#} |
| ... | ... | @@ -7421,7 +7421,7 @@ test "field access by string" { |
| 7421 | 7421 | {#header_close#} |
| 7422 | 7422 | |
| 7423 | 7423 | {#header_open|@floatCast#} |
| 7424 | <pre>{#syntax#}@floatCast(comptime DestType: type, value: var) DestType{#endsyntax#}</pre> | |
| 7424 | <pre>{#syntax#}@floatCast(comptime DestType: type, value: anytype) DestType{#endsyntax#}</pre> | |
| 7425 | 7425 | <p> |
| 7426 | 7426 | Convert from one float type to another. This cast is safe, but may cause the |
| 7427 | 7427 | numeric value to lose precision. |
| ... | ... | @@ -7429,7 +7429,7 @@ test "field access by string" { |
| 7429 | 7429 | {#header_close#} |
| 7430 | 7430 | |
| 7431 | 7431 | {#header_open|@floatToInt#} |
| 7432 | <pre>{#syntax#}@floatToInt(comptime DestType: type, float: var) DestType{#endsyntax#}</pre> | |
| 7432 | <pre>{#syntax#}@floatToInt(comptime DestType: type, float: anytype) DestType{#endsyntax#}</pre> | |
| 7433 | 7433 | <p> |
| 7434 | 7434 | Converts the integer part of a floating point number to the destination type. |
| 7435 | 7435 | </p> |
| ... | ... | @@ -7455,7 +7455,7 @@ test "field access by string" { |
| 7455 | 7455 | {#header_close#} |
| 7456 | 7456 | |
| 7457 | 7457 | {#header_open|@Frame#} |
| 7458 | <pre>{#syntax#}@Frame(func: var) type{#endsyntax#}</pre> | |
| 7458 | <pre>{#syntax#}@Frame(func: anytype) type{#endsyntax#}</pre> | |
| 7459 | 7459 | <p> |
| 7460 | 7460 | This function returns the frame type of a function. This works for {#link|Async Functions#} |
| 7461 | 7461 | as well as any function without a specific calling convention. |
| ... | ... | @@ -7581,7 +7581,7 @@ test "@hasDecl" { |
| 7581 | 7581 | {#header_close#} |
| 7582 | 7582 | |
| 7583 | 7583 | {#header_open|@intCast#} |
| 7584 | <pre>{#syntax#}@intCast(comptime DestType: type, int: var) DestType{#endsyntax#}</pre> | |
| 7584 | <pre>{#syntax#}@intCast(comptime DestType: type, int: anytype) DestType{#endsyntax#}</pre> | |
| 7585 | 7585 | <p> |
| 7586 | 7586 | Converts an integer to another integer while keeping the same numerical value. |
| 7587 | 7587 | Attempting to convert a number which is out of range of the destination type results in |
| ... | ... | @@ -7622,7 +7622,7 @@ test "@hasDecl" { |
| 7622 | 7622 | {#header_close#} |
| 7623 | 7623 | |
| 7624 | 7624 | {#header_open|@intToFloat#} |
| 7625 | <pre>{#syntax#}@intToFloat(comptime DestType: type, int: var) DestType{#endsyntax#}</pre> | |
| 7625 | <pre>{#syntax#}@intToFloat(comptime DestType: type, int: anytype) DestType{#endsyntax#}</pre> | |
| 7626 | 7626 | <p> |
| 7627 | 7627 | Converts an integer to the closest floating point representation. To convert the other way, use {#link|@floatToInt#}. This cast is always safe. |
| 7628 | 7628 | </p> |
| ... | ... | @@ -7773,7 +7773,7 @@ test "@wasmMemoryGrow" { |
| 7773 | 7773 | {#header_close#} |
| 7774 | 7774 | |
| 7775 | 7775 | {#header_open|@ptrCast#} |
| 7776 | <pre>{#syntax#}@ptrCast(comptime DestType: type, value: var) DestType{#endsyntax#}</pre> | |
| 7776 | <pre>{#syntax#}@ptrCast(comptime DestType: type, value: anytype) DestType{#endsyntax#}</pre> | |
| 7777 | 7777 | <p> |
| 7778 | 7778 | Converts a pointer of one type to a pointer of another type. |
| 7779 | 7779 | </p> |
| ... | ... | @@ -7784,7 +7784,7 @@ test "@wasmMemoryGrow" { |
| 7784 | 7784 | {#header_close#} |
| 7785 | 7785 | |
| 7786 | 7786 | {#header_open|@ptrToInt#} |
| 7787 | <pre>{#syntax#}@ptrToInt(value: var) usize{#endsyntax#}</pre> | |
| 7787 | <pre>{#syntax#}@ptrToInt(value: anytype) usize{#endsyntax#}</pre> | |
| 7788 | 7788 | <p> |
| 7789 | 7789 | Converts {#syntax#}value{#endsyntax#} to a {#syntax#}usize{#endsyntax#} which is the address of the pointer. {#syntax#}value{#endsyntax#} can be one of these types: |
| 7790 | 7790 | </p> |
| ... | ... | @@ -8042,7 +8042,7 @@ test "@setRuntimeSafety" { |
| 8042 | 8042 | {#header_close#} |
| 8043 | 8043 | |
| 8044 | 8044 | {#header_open|@splat#} |
| 8045 | <pre>{#syntax#}@splat(comptime len: u32, scalar: var) std.meta.Vector(len, @TypeOf(scalar)){#endsyntax#}</pre> | |
| 8045 | <pre>{#syntax#}@splat(comptime len: u32, scalar: anytype) std.meta.Vector(len, @TypeOf(scalar)){#endsyntax#}</pre> | |
| 8046 | 8046 | <p> |
| 8047 | 8047 | Produces a vector of length {#syntax#}len{#endsyntax#} where each element is the value |
| 8048 | 8048 | {#syntax#}scalar{#endsyntax#}: |
| ... | ... | @@ -8088,7 +8088,7 @@ fn doTheTest() void { |
| 8088 | 8088 | {#code_end#} |
| 8089 | 8089 | {#header_close#} |
| 8090 | 8090 | {#header_open|@sqrt#} |
| 8091 | <pre>{#syntax#}@sqrt(value: var) @TypeOf(value){#endsyntax#}</pre> | |
| 8091 | <pre>{#syntax#}@sqrt(value: anytype) @TypeOf(value){#endsyntax#}</pre> | |
| 8092 | 8092 | <p> |
| 8093 | 8093 | Performs the square root of a floating point number. Uses a dedicated hardware instruction |
| 8094 | 8094 | when available. |
| ... | ... | @@ -8099,7 +8099,7 @@ fn doTheTest() void { |
| 8099 | 8099 | </p> |
| 8100 | 8100 | {#header_close#} |
| 8101 | 8101 | {#header_open|@sin#} |
| 8102 | <pre>{#syntax#}@sin(value: var) @TypeOf(value){#endsyntax#}</pre> | |
| 8102 | <pre>{#syntax#}@sin(value: anytype) @TypeOf(value){#endsyntax#}</pre> | |
| 8103 | 8103 | <p> |
| 8104 | 8104 | Sine trigometric function on a floating point number. Uses a dedicated hardware instruction |
| 8105 | 8105 | when available. |
| ... | ... | @@ -8110,7 +8110,7 @@ fn doTheTest() void { |
| 8110 | 8110 | </p> |
| 8111 | 8111 | {#header_close#} |
| 8112 | 8112 | {#header_open|@cos#} |
| 8113 | <pre>{#syntax#}@cos(value: var) @TypeOf(value){#endsyntax#}</pre> | |
| 8113 | <pre>{#syntax#}@cos(value: anytype) @TypeOf(value){#endsyntax#}</pre> | |
| 8114 | 8114 | <p> |
| 8115 | 8115 | Cosine trigometric function on a floating point number. Uses a dedicated hardware instruction |
| 8116 | 8116 | when available. |
| ... | ... | @@ -8121,7 +8121,7 @@ fn doTheTest() void { |
| 8121 | 8121 | </p> |
| 8122 | 8122 | {#header_close#} |
| 8123 | 8123 | {#header_open|@exp#} |
| 8124 | <pre>{#syntax#}@exp(value: var) @TypeOf(value){#endsyntax#}</pre> | |
| 8124 | <pre>{#syntax#}@exp(value: anytype) @TypeOf(value){#endsyntax#}</pre> | |
| 8125 | 8125 | <p> |
| 8126 | 8126 | Base-e exponential function on a floating point number. Uses a dedicated hardware instruction |
| 8127 | 8127 | when available. |
| ... | ... | @@ -8132,7 +8132,7 @@ fn doTheTest() void { |
| 8132 | 8132 | </p> |
| 8133 | 8133 | {#header_close#} |
| 8134 | 8134 | {#header_open|@exp2#} |
| 8135 | <pre>{#syntax#}@exp2(value: var) @TypeOf(value){#endsyntax#}</pre> | |
| 8135 | <pre>{#syntax#}@exp2(value: anytype) @TypeOf(value){#endsyntax#}</pre> | |
| 8136 | 8136 | <p> |
| 8137 | 8137 | Base-2 exponential function on a floating point number. Uses a dedicated hardware instruction |
| 8138 | 8138 | when available. |
| ... | ... | @@ -8143,7 +8143,7 @@ fn doTheTest() void { |
| 8143 | 8143 | </p> |
| 8144 | 8144 | {#header_close#} |
| 8145 | 8145 | {#header_open|@log#} |
| 8146 | <pre>{#syntax#}@log(value: var) @TypeOf(value){#endsyntax#}</pre> | |
| 8146 | <pre>{#syntax#}@log(value: anytype) @TypeOf(value){#endsyntax#}</pre> | |
| 8147 | 8147 | <p> |
| 8148 | 8148 | Returns the natural logarithm of a floating point number. Uses a dedicated hardware instruction |
| 8149 | 8149 | when available. |
| ... | ... | @@ -8154,7 +8154,7 @@ fn doTheTest() void { |
| 8154 | 8154 | </p> |
| 8155 | 8155 | {#header_close#} |
| 8156 | 8156 | {#header_open|@log2#} |
| 8157 | <pre>{#syntax#}@log2(value: var) @TypeOf(value){#endsyntax#}</pre> | |
| 8157 | <pre>{#syntax#}@log2(value: anytype) @TypeOf(value){#endsyntax#}</pre> | |
| 8158 | 8158 | <p> |
| 8159 | 8159 | Returns the logarithm to the base 2 of a floating point number. Uses a dedicated hardware instruction |
| 8160 | 8160 | when available. |
| ... | ... | @@ -8165,7 +8165,7 @@ fn doTheTest() void { |
| 8165 | 8165 | </p> |
| 8166 | 8166 | {#header_close#} |
| 8167 | 8167 | {#header_open|@log10#} |
| 8168 | <pre>{#syntax#}@log10(value: var) @TypeOf(value){#endsyntax#}</pre> | |
| 8168 | <pre>{#syntax#}@log10(value: anytype) @TypeOf(value){#endsyntax#}</pre> | |
| 8169 | 8169 | <p> |
| 8170 | 8170 | Returns the logarithm to the base 10 of a floating point number. Uses a dedicated hardware instruction |
| 8171 | 8171 | when available. |
| ... | ... | @@ -8176,7 +8176,7 @@ fn doTheTest() void { |
| 8176 | 8176 | </p> |
| 8177 | 8177 | {#header_close#} |
| 8178 | 8178 | {#header_open|@fabs#} |
| 8179 | <pre>{#syntax#}@fabs(value: var) @TypeOf(value){#endsyntax#}</pre> | |
| 8179 | <pre>{#syntax#}@fabs(value: anytype) @TypeOf(value){#endsyntax#}</pre> | |
| 8180 | 8180 | <p> |
| 8181 | 8181 | Returns the absolute value of a floating point number. Uses a dedicated hardware instruction |
| 8182 | 8182 | when available. |
| ... | ... | @@ -8187,7 +8187,7 @@ fn doTheTest() void { |
| 8187 | 8187 | </p> |
| 8188 | 8188 | {#header_close#} |
| 8189 | 8189 | {#header_open|@floor#} |
| 8190 | <pre>{#syntax#}@floor(value: var) @TypeOf(value){#endsyntax#}</pre> | |
| 8190 | <pre>{#syntax#}@floor(value: anytype) @TypeOf(value){#endsyntax#}</pre> | |
| 8191 | 8191 | <p> |
| 8192 | 8192 | Returns the largest integral value not greater than the given floating point number. |
| 8193 | 8193 | Uses a dedicated hardware instruction when available. |
| ... | ... | @@ -8198,7 +8198,7 @@ fn doTheTest() void { |
| 8198 | 8198 | </p> |
| 8199 | 8199 | {#header_close#} |
| 8200 | 8200 | {#header_open|@ceil#} |
| 8201 | <pre>{#syntax#}@ceil(value: var) @TypeOf(value){#endsyntax#}</pre> | |
| 8201 | <pre>{#syntax#}@ceil(value: anytype) @TypeOf(value){#endsyntax#}</pre> | |
| 8202 | 8202 | <p> |
| 8203 | 8203 | Returns the largest integral value not less than the given floating point number. |
| 8204 | 8204 | Uses a dedicated hardware instruction when available. |
| ... | ... | @@ -8209,7 +8209,7 @@ fn doTheTest() void { |
| 8209 | 8209 | </p> |
| 8210 | 8210 | {#header_close#} |
| 8211 | 8211 | {#header_open|@trunc#} |
| 8212 | <pre>{#syntax#}@trunc(value: var) @TypeOf(value){#endsyntax#}</pre> | |
| 8212 | <pre>{#syntax#}@trunc(value: anytype) @TypeOf(value){#endsyntax#}</pre> | |
| 8213 | 8213 | <p> |
| 8214 | 8214 | Rounds the given floating point number to an integer, towards zero. |
| 8215 | 8215 | Uses a dedicated hardware instruction when available. |
| ... | ... | @@ -8220,7 +8220,7 @@ fn doTheTest() void { |
| 8220 | 8220 | </p> |
| 8221 | 8221 | {#header_close#} |
| 8222 | 8222 | {#header_open|@round#} |
| 8223 | <pre>{#syntax#}@round(value: var) @TypeOf(value){#endsyntax#}</pre> | |
| 8223 | <pre>{#syntax#}@round(value: anytype) @TypeOf(value){#endsyntax#}</pre> | |
| 8224 | 8224 | <p> |
| 8225 | 8225 | Rounds the given floating point number to an integer, away from zero. Uses a dedicated hardware instruction |
| 8226 | 8226 | when available. |
| ... | ... | @@ -8241,7 +8241,7 @@ fn doTheTest() void { |
| 8241 | 8241 | {#header_close#} |
| 8242 | 8242 | |
| 8243 | 8243 | {#header_open|@tagName#} |
| 8244 | <pre>{#syntax#}@tagName(value: var) []const u8{#endsyntax#}</pre> | |
| 8244 | <pre>{#syntax#}@tagName(value: anytype) []const u8{#endsyntax#}</pre> | |
| 8245 | 8245 | <p> |
| 8246 | 8246 | Converts an enum value or union value to a slice of bytes representing the name.</p><p>If the enum is non-exhaustive and the tag value does not map to a name, it invokes safety-checked {#link|Undefined Behavior#}. |
| 8247 | 8247 | </p> |
| ... | ... | @@ -8292,7 +8292,7 @@ fn List(comptime T: type) type { |
| 8292 | 8292 | {#header_close#} |
| 8293 | 8293 | |
| 8294 | 8294 | {#header_open|@truncate#} |
| 8295 | <pre>{#syntax#}@truncate(comptime T: type, integer: var) T{#endsyntax#}</pre> | |
| 8295 | <pre>{#syntax#}@truncate(comptime T: type, integer: anytype) T{#endsyntax#}</pre> | |
| 8296 | 8296 | <p> |
| 8297 | 8297 | This function truncates bits from an integer type, resulting in a smaller |
| 8298 | 8298 | or same-sized integer type. |
| ... | ... | @@ -10214,7 +10214,7 @@ TopLevelDecl |
| 10214 | 10214 | / (KEYWORD_export / KEYWORD_extern STRINGLITERALSINGLE?)? KEYWORD_threadlocal? VarDecl |
| 10215 | 10215 | / KEYWORD_usingnamespace Expr SEMICOLON |
| 10216 | 10216 | |
| 10217 | FnProto &lt;- KEYWORD_fn IDENTIFIER? LPAREN ParamDeclList RPAREN ByteAlign? LinkSection? EXCLAMATIONMARK? (KEYWORD_var / TypeExpr) | |
| 10217 | FnProto &lt;- KEYWORD_fn IDENTIFIER? LPAREN ParamDeclList RPAREN ByteAlign? LinkSection? EXCLAMATIONMARK? (KEYWORD_anytype / TypeExpr) | |
| 10218 | 10218 | |
| 10219 | 10219 | VarDecl &lt;- (KEYWORD_const / KEYWORD_var) IDENTIFIER (COLON TypeExpr)? ByteAlign? LinkSection? (EQUAL Expr)? SEMICOLON |
| 10220 | 10220 | |
| ... | ... | @@ -10386,7 +10386,7 @@ LinkSection &lt;- KEYWORD_linksection LPAREN Expr RPAREN |
| 10386 | 10386 | ParamDecl &lt;- (KEYWORD_noalias / KEYWORD_comptime)? (IDENTIFIER COLON)? ParamType |
| 10387 | 10387 | |
| 10388 | 10388 | ParamType |
| 10389 | &lt;- KEYWORD_var | |
| 10389 | &lt;- KEYWORD_anytype | |
| 10390 | 10390 | / DOT3 |
| 10391 | 10391 | / TypeExpr |
| 10392 | 10392 | |
| ... | ... | @@ -10624,6 +10624,7 @@ KEYWORD_align &lt;- 'align' end_of_word |
| 10624 | 10624 | KEYWORD_allowzero &lt;- 'allowzero' end_of_word |
| 10625 | 10625 | KEYWORD_and &lt;- 'and' end_of_word |
| 10626 | 10626 | KEYWORD_anyframe &lt;- 'anyframe' end_of_word |
| 10627 | KEYWORD_anytype &lt;- 'anytype' end_of_word | |
| 10627 | 10628 | KEYWORD_asm &lt;- 'asm' end_of_word |
| 10628 | 10629 | KEYWORD_async &lt;- 'async' end_of_word |
| 10629 | 10630 | KEYWORD_await &lt;- 'await' end_of_word |
| ... | ... | @@ -10669,14 +10670,14 @@ KEYWORD_var &lt;- 'var' end_of_word |
| 10669 | 10670 | KEYWORD_volatile &lt;- 'volatile' end_of_word |
| 10670 | 10671 | KEYWORD_while &lt;- 'while' end_of_word |
| 10671 | 10672 | |
| 10672 | keyword &lt;- KEYWORD_align / KEYWORD_and / KEYWORD_allowzero / KEYWORD_asm | |
| 10673 | / KEYWORD_async / KEYWORD_await / KEYWORD_break | |
| 10673 | keyword &lt;- KEYWORD_align / KEYWORD_and / KEYWORD_anyframe / KEYWORD_anytype | |
| 10674 | / KEYWORD_allowzero / KEYWORD_asm / KEYWORD_async / KEYWORD_await / KEYWORD_break | |
| 10674 | 10675 | / KEYWORD_catch / KEYWORD_comptime / KEYWORD_const / KEYWORD_continue |
| 10675 | 10676 | / KEYWORD_defer / KEYWORD_else / KEYWORD_enum / KEYWORD_errdefer |
| 10676 | 10677 | / KEYWORD_error / KEYWORD_export / KEYWORD_extern / KEYWORD_false |
| 10677 | 10678 | / KEYWORD_fn / KEYWORD_for / KEYWORD_if / KEYWORD_inline |
| 10678 | 10679 | / KEYWORD_noalias / KEYWORD_null / KEYWORD_or |
| 10679 | / KEYWORD_orelse / KEYWORD_packed / KEYWORD_anyframe / KEYWORD_pub | |
| 10680 | / KEYWORD_orelse / KEYWORD_packed / KEYWORD_pub | |
| 10680 | 10681 | / KEYWORD_resume / KEYWORD_return / KEYWORD_linksection |
| 10681 | 10682 | / KEYWORD_struct / KEYWORD_suspend |
| 10682 | 10683 | / KEYWORD_switch / KEYWORD_test / KEYWORD_threadlocal / KEYWORD_true / KEYWORD_try |
src/all_types.hpp+4-4| ... | ... | @@ -692,7 +692,7 @@ enum NodeType { |
| 692 | 692 | NodeTypeSuspend, |
| 693 | 693 | NodeTypeAnyFrameType, |
| 694 | 694 | NodeTypeEnumLiteral, |
| 695 | NodeTypeVarFieldType, | |
| 695 | NodeTypeAnyTypeField, | |
| 696 | 696 | }; |
| 697 | 697 | |
| 698 | 698 | enum FnInline { |
| ... | ... | @@ -705,7 +705,7 @@ struct AstNodeFnProto { |
| 705 | 705 | Buf *name; |
| 706 | 706 | ZigList<AstNode *> params; |
| 707 | 707 | AstNode *return_type; |
| 708 | Token *return_var_token; | |
| 708 | Token *return_anytype_token; | |
| 709 | 709 | AstNode *fn_def_node; |
| 710 | 710 | // populated if this is an extern declaration |
| 711 | 711 | Buf *lib_name; |
| ... | ... | @@ -734,7 +734,7 @@ struct AstNodeFnDef { |
| 734 | 734 | struct AstNodeParamDecl { |
| 735 | 735 | Buf *name; |
| 736 | 736 | AstNode *type; |
| 737 | Token *var_token; | |
| 737 | Token *anytype_token; | |
| 738 | 738 | Buf doc_comments; |
| 739 | 739 | bool is_noalias; |
| 740 | 740 | bool is_comptime; |
| ... | ... | @@ -2145,7 +2145,7 @@ struct CodeGen { |
| 2145 | 2145 | ZigType *entry_num_lit_float; |
| 2146 | 2146 | ZigType *entry_undef; |
| 2147 | 2147 | ZigType *entry_null; |
| 2148 | ZigType *entry_var; | |
| 2148 | ZigType *entry_anytype; | |
| 2149 | 2149 | ZigType *entry_global_error_set; |
| 2150 | 2150 | ZigType *entry_enum_literal; |
| 2151 | 2151 | ZigType *entry_any_frame; |
src/analyze.cpp+8-8| ... | ... | @@ -1129,7 +1129,7 @@ ZigValue *analyze_const_value(CodeGen *g, Scope *scope, AstNode *node, ZigType * |
| 1129 | 1129 | ZigValue *result = g->pass1_arena->create<ZigValue>(); |
| 1130 | 1130 | ZigValue *result_ptr = g->pass1_arena->create<ZigValue>(); |
| 1131 | 1131 | result->special = ConstValSpecialUndef; |
| 1132 | result->type = (type_entry == nullptr) ? g->builtin_types.entry_var : type_entry; | |
| 1132 | result->type = (type_entry == nullptr) ? g->builtin_types.entry_anytype : type_entry; | |
| 1133 | 1133 | result_ptr->special = ConstValSpecialStatic; |
| 1134 | 1134 | result_ptr->type = get_pointer_to_type(g, result->type, false); |
| 1135 | 1135 | result_ptr->data.x_ptr.mut = ConstPtrMutComptimeVar; |
| ... | ... | @@ -1230,7 +1230,7 @@ Error type_val_resolve_zero_bits(CodeGen *g, ZigValue *type_val, ZigType *parent |
| 1230 | 1230 | Error type_val_resolve_is_opaque_type(CodeGen *g, ZigValue *type_val, bool *is_opaque_type) { |
| 1231 | 1231 | if (type_val->special != ConstValSpecialLazy) { |
| 1232 | 1232 | assert(type_val->special == ConstValSpecialStatic); |
| 1233 | if (type_val->data.x_type == g->builtin_types.entry_var) { | |
| 1233 | if (type_val->data.x_type == g->builtin_types.entry_anytype) { | |
| 1234 | 1234 | *is_opaque_type = false; |
| 1235 | 1235 | return ErrorNone; |
| 1236 | 1236 | } |
| ... | ... | @@ -1853,10 +1853,10 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc |
| 1853 | 1853 | buf_sprintf("var args only allowed in functions with C calling convention")); |
| 1854 | 1854 | return g->builtin_types.entry_invalid; |
| 1855 | 1855 | } |
| 1856 | } else if (param_node->data.param_decl.var_token != nullptr) { | |
| 1856 | } else if (param_node->data.param_decl.anytype_token != nullptr) { | |
| 1857 | 1857 | if (!calling_convention_allows_zig_types(fn_type_id.cc)) { |
| 1858 | 1858 | add_node_error(g, param_node, |
| 1859 | buf_sprintf("parameter of type 'var' not allowed in function with calling convention '%s'", | |
| 1859 | buf_sprintf("parameter of type 'anytype' not allowed in function with calling convention '%s'", | |
| 1860 | 1860 | calling_convention_name(fn_type_id.cc))); |
| 1861 | 1861 | return g->builtin_types.entry_invalid; |
| 1862 | 1862 | } |
| ... | ... | @@ -1942,10 +1942,10 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc |
| 1942 | 1942 | fn_entry->align_bytes = fn_type_id.alignment; |
| 1943 | 1943 | } |
| 1944 | 1944 | |
| 1945 | if (fn_proto->return_var_token != nullptr) { | |
| 1945 | if (fn_proto->return_anytype_token != nullptr) { | |
| 1946 | 1946 | if (!calling_convention_allows_zig_types(fn_type_id.cc)) { |
| 1947 | 1947 | add_node_error(g, fn_proto->return_type, |
| 1948 | buf_sprintf("return type 'var' not allowed in function with calling convention '%s'", | |
| 1948 | buf_sprintf("return type 'anytype' not allowed in function with calling convention '%s'", | |
| 1949 | 1949 | calling_convention_name(fn_type_id.cc))); |
| 1950 | 1950 | return g->builtin_types.entry_invalid; |
| 1951 | 1951 | } |
| ... | ... | @@ -3802,7 +3802,7 @@ void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node) { |
| 3802 | 3802 | case NodeTypeEnumLiteral: |
| 3803 | 3803 | case NodeTypeAnyFrameType: |
| 3804 | 3804 | case NodeTypeErrorSetField: |
| 3805 | case NodeTypeVarFieldType: | |
| 3805 | case NodeTypeAnyTypeField: | |
| 3806 | 3806 | zig_unreachable(); |
| 3807 | 3807 | } |
| 3808 | 3808 | } |
| ... | ... | @@ -5868,7 +5868,7 @@ ZigValue *get_the_one_possible_value(CodeGen *g, ZigType *type_entry) { |
| 5868 | 5868 | |
| 5869 | 5869 | ReqCompTime type_requires_comptime(CodeGen *g, ZigType *ty) { |
| 5870 | 5870 | Error err; |
| 5871 | if (ty == g->builtin_types.entry_var) { | |
| 5871 | if (ty == g->builtin_types.entry_anytype) { | |
| 5872 | 5872 | return ReqCompTimeYes; |
| 5873 | 5873 | } |
| 5874 | 5874 | switch (ty->id) { |
src/ast_render.cpp+8-8| ... | ... | @@ -270,8 +270,8 @@ static const char *node_type_str(NodeType node_type) { |
| 270 | 270 | return "EnumLiteral"; |
| 271 | 271 | case NodeTypeErrorSetField: |
| 272 | 272 | return "ErrorSetField"; |
| 273 | case NodeTypeVarFieldType: | |
| 274 | return "VarFieldType"; | |
| 273 | case NodeTypeAnyTypeField: | |
| 274 | return "AnyTypeField"; | |
| 275 | 275 | } |
| 276 | 276 | zig_unreachable(); |
| 277 | 277 | } |
| ... | ... | @@ -466,8 +466,8 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) { |
| 466 | 466 | } |
| 467 | 467 | if (param_decl->data.param_decl.is_var_args) { |
| 468 | 468 | fprintf(ar->f, "..."); |
| 469 | } else if (param_decl->data.param_decl.var_token != nullptr) { | |
| 470 | fprintf(ar->f, "var"); | |
| 469 | } else if (param_decl->data.param_decl.anytype_token != nullptr) { | |
| 470 | fprintf(ar->f, "anytype"); | |
| 471 | 471 | } else { |
| 472 | 472 | render_node_grouped(ar, param_decl->data.param_decl.type); |
| 473 | 473 | } |
| ... | ... | @@ -496,8 +496,8 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) { |
| 496 | 496 | fprintf(ar->f, ")"); |
| 497 | 497 | } |
| 498 | 498 | |
| 499 | if (node->data.fn_proto.return_var_token != nullptr) { | |
| 500 | fprintf(ar->f, "var"); | |
| 499 | if (node->data.fn_proto.return_anytype_token != nullptr) { | |
| 500 | fprintf(ar->f, "anytype"); | |
| 501 | 501 | } else { |
| 502 | 502 | AstNode *return_type_node = node->data.fn_proto.return_type; |
| 503 | 503 | assert(return_type_node != nullptr); |
| ... | ... | @@ -1216,8 +1216,8 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) { |
| 1216 | 1216 | fprintf(ar->f, ".%s", buf_ptr(&node->data.enum_literal.identifier->data.str_lit.str)); |
| 1217 | 1217 | break; |
| 1218 | 1218 | } |
| 1219 | case NodeTypeVarFieldType: { | |
| 1220 | fprintf(ar->f, "var"); | |
| 1219 | case NodeTypeAnyTypeField: { | |
| 1220 | fprintf(ar->f, "anytype"); | |
| 1221 | 1221 | break; |
| 1222 | 1222 | } |
| 1223 | 1223 | case NodeTypeParamDecl: |
src/codegen.cpp+2-2| ... | ... | @@ -8448,8 +8448,8 @@ static void define_builtin_types(CodeGen *g) { |
| 8448 | 8448 | } |
| 8449 | 8449 | { |
| 8450 | 8450 | ZigType *entry = new_type_table_entry(ZigTypeIdOpaque); |
| 8451 | buf_init_from_str(&entry->name, "(var)"); | |
| 8452 | g->builtin_types.entry_var = entry; | |
| 8451 | buf_init_from_str(&entry->name, "(anytype)"); | |
| 8452 | g->builtin_types.entry_anytype = entry; | |
| 8453 | 8453 | } |
| 8454 | 8454 | |
| 8455 | 8455 | for (size_t i = 0; i < array_length(c_int_type_infos); i += 1) { |
src/ir.cpp+32-27| ... | ... | @@ -9942,7 +9942,7 @@ static IrInstSrc *ir_gen_fn_proto(IrBuilderSrc *irb, Scope *parent_scope, AstNod |
| 9942 | 9942 | is_var_args = true; |
| 9943 | 9943 | break; |
| 9944 | 9944 | } |
| 9945 | if (param_node->data.param_decl.var_token == nullptr) { | |
| 9945 | if (param_node->data.param_decl.anytype_token == nullptr) { | |
| 9946 | 9946 | AstNode *type_node = param_node->data.param_decl.type; |
| 9947 | 9947 | IrInstSrc *type_value = ir_gen_node(irb, type_node, parent_scope); |
| 9948 | 9948 | if (type_value == irb->codegen->invalid_inst_src) |
| ... | ... | @@ -9968,7 +9968,7 @@ static IrInstSrc *ir_gen_fn_proto(IrBuilderSrc *irb, Scope *parent_scope, AstNod |
| 9968 | 9968 | } |
| 9969 | 9969 | |
| 9970 | 9970 | IrInstSrc *return_type; |
| 9971 | if (node->data.fn_proto.return_var_token == nullptr) { | |
| 9971 | if (node->data.fn_proto.return_anytype_token == nullptr) { | |
| 9972 | 9972 | if (node->data.fn_proto.return_type == nullptr) { |
| 9973 | 9973 | return_type = ir_build_const_type(irb, parent_scope, node, irb->codegen->builtin_types.entry_void); |
| 9974 | 9974 | } else { |
| ... | ... | @@ -10226,9 +10226,9 @@ static IrInstSrc *ir_gen_node_raw(IrBuilderSrc *irb, AstNode *node, Scope *scope |
| 10226 | 10226 | add_node_error(irb->codegen, node, |
| 10227 | 10227 | buf_sprintf("inferred array size invalid here")); |
| 10228 | 10228 | return irb->codegen->invalid_inst_src; |
| 10229 | case NodeTypeVarFieldType: | |
| 10229 | case NodeTypeAnyTypeField: | |
| 10230 | 10230 | return ir_lval_wrap(irb, scope, |
| 10231 | ir_build_const_type(irb, scope, node, irb->codegen->builtin_types.entry_var), lval, result_loc); | |
| 10231 | ir_build_const_type(irb, scope, node, irb->codegen->builtin_types.entry_anytype), lval, result_loc); | |
| 10232 | 10232 | } |
| 10233 | 10233 | zig_unreachable(); |
| 10234 | 10234 | } |
| ... | ... | @@ -10296,7 +10296,7 @@ static IrInstSrc *ir_gen_node_extra(IrBuilderSrc *irb, AstNode *node, Scope *sco |
| 10296 | 10296 | case NodeTypeSuspend: |
| 10297 | 10297 | case NodeTypeEnumLiteral: |
| 10298 | 10298 | case NodeTypeInferredArrayType: |
| 10299 | case NodeTypeVarFieldType: | |
| 10299 | case NodeTypeAnyTypeField: | |
| 10300 | 10300 | case NodeTypePrefixOpExpr: |
| 10301 | 10301 | add_node_error(irb->codegen, node, |
| 10302 | 10302 | buf_sprintf("invalid left-hand side to assignment")); |
| ... | ... | @@ -10518,7 +10518,7 @@ ZigValue *const_ptr_pointee(IrAnalyze *ira, CodeGen *codegen, ZigValue *const_va |
| 10518 | 10518 | if (val == nullptr) return nullptr; |
| 10519 | 10519 | assert(const_val->type->id == ZigTypeIdPointer); |
| 10520 | 10520 | ZigType *expected_type = const_val->type->data.pointer.child_type; |
| 10521 | if (expected_type == codegen->builtin_types.entry_var) { | |
| 10521 | if (expected_type == codegen->builtin_types.entry_anytype) { | |
| 10522 | 10522 | return val; |
| 10523 | 10523 | } |
| 10524 | 10524 | switch (type_has_one_possible_value(codegen, expected_type)) { |
| ... | ... | @@ -15040,7 +15040,7 @@ static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr, |
| 15040 | 15040 | } |
| 15041 | 15041 | |
| 15042 | 15042 | // This means the wanted type is anything. |
| 15043 | if (wanted_type == ira->codegen->builtin_types.entry_var) { | |
| 15043 | if (wanted_type == ira->codegen->builtin_types.entry_anytype) { | |
| 15044 | 15044 | return value; |
| 15045 | 15045 | } |
| 15046 | 15046 | |
| ... | ... | @@ -15635,7 +15635,7 @@ static IrInstGen *ir_implicit_cast(IrAnalyze *ira, IrInstGen *value, ZigType *ex |
| 15635 | 15635 | static ZigType *get_ptr_elem_type(CodeGen *g, IrInstGen *ptr) { |
| 15636 | 15636 | ir_assert_gen(ptr->value->type->id == ZigTypeIdPointer, ptr); |
| 15637 | 15637 | ZigType *elem_type = ptr->value->type->data.pointer.child_type; |
| 15638 | if (elem_type != g->builtin_types.entry_var) | |
| 15638 | if (elem_type != g->builtin_types.entry_anytype) | |
| 15639 | 15639 | return elem_type; |
| 15640 | 15640 | |
| 15641 | 15641 | if (ir_resolve_lazy(g, ptr->base.source_node, ptr->value)) |
| ... | ... | @@ -15687,7 +15687,7 @@ static IrInstGen *ir_get_deref(IrAnalyze *ira, IrInst* source_instruction, IrIns |
| 15687 | 15687 | } |
| 15688 | 15688 | if (ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) { |
| 15689 | 15689 | ZigValue *pointee = const_ptr_pointee_unchecked(ira->codegen, ptr->value); |
| 15690 | if (child_type == ira->codegen->builtin_types.entry_var) { | |
| 15690 | if (child_type == ira->codegen->builtin_types.entry_anytype) { | |
| 15691 | 15691 | child_type = pointee->type; |
| 15692 | 15692 | } |
| 15693 | 15693 | if (pointee->special != ConstValSpecialRuntime) { |
| ... | ... | @@ -19087,7 +19087,7 @@ static Error ir_result_has_type(IrAnalyze *ira, ResultLoc *result_loc, bool *out |
| 19087 | 19087 | ZigType *dest_type = ir_resolve_type(ira, result_cast->base.source_instruction->child); |
| 19088 | 19088 | if (type_is_invalid(dest_type)) |
| 19089 | 19089 | return ErrorSemanticAnalyzeFail; |
| 19090 | *out = (dest_type != ira->codegen->builtin_types.entry_var); | |
| 19090 | *out = (dest_type != ira->codegen->builtin_types.entry_anytype); | |
| 19091 | 19091 | return ErrorNone; |
| 19092 | 19092 | } |
| 19093 | 19093 | case ResultLocIdVar: |
| ... | ... | @@ -19293,7 +19293,7 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i |
| 19293 | 19293 | if (type_is_invalid(dest_type)) |
| 19294 | 19294 | return ira->codegen->invalid_inst_gen; |
| 19295 | 19295 | |
| 19296 | if (dest_type == ira->codegen->builtin_types.entry_var) { | |
| 19296 | if (dest_type == ira->codegen->builtin_types.entry_anytype) { | |
| 19297 | 19297 | return ir_resolve_no_result_loc(ira, suspend_source_instr, result_loc, value_type); |
| 19298 | 19298 | } |
| 19299 | 19299 | |
| ... | ... | @@ -19439,7 +19439,7 @@ static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_i |
| 19439 | 19439 | return ira->codegen->invalid_inst_gen; |
| 19440 | 19440 | } |
| 19441 | 19441 | |
| 19442 | if (child_type != ira->codegen->builtin_types.entry_var) { | |
| 19442 | if (child_type != ira->codegen->builtin_types.entry_anytype) { | |
| 19443 | 19443 | if (type_size(ira->codegen, child_type) != type_size(ira->codegen, value_type)) { |
| 19444 | 19444 | // pointer cast won't work; we need a temporary location. |
| 19445 | 19445 | result_bit_cast->parent->written = parent_was_written; |
| ... | ... | @@ -19600,9 +19600,9 @@ static IrInstGen *ir_analyze_instruction_resolve_result(IrAnalyze *ira, IrInstSr |
| 19600 | 19600 | if (type_is_invalid(implicit_elem_type)) |
| 19601 | 19601 | return ira->codegen->invalid_inst_gen; |
| 19602 | 19602 | } else { |
| 19603 | implicit_elem_type = ira->codegen->builtin_types.entry_var; | |
| 19603 | implicit_elem_type = ira->codegen->builtin_types.entry_anytype; | |
| 19604 | 19604 | } |
| 19605 | if (implicit_elem_type == ira->codegen->builtin_types.entry_var) { | |
| 19605 | if (implicit_elem_type == ira->codegen->builtin_types.entry_anytype) { | |
| 19606 | 19606 | Buf *bare_name = buf_alloc(); |
| 19607 | 19607 | Buf *name = get_anon_type_name(ira->codegen, nullptr, container_string(ContainerKindStruct), |
| 19608 | 19608 | instruction->base.base.scope, instruction->base.base.source_node, bare_name); |
| ... | ... | @@ -19759,7 +19759,7 @@ static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node |
| 19759 | 19759 | assert(param_decl_node->type == NodeTypeParamDecl); |
| 19760 | 19760 | |
| 19761 | 19761 | IrInstGen *casted_arg; |
| 19762 | if (param_decl_node->data.param_decl.var_token == nullptr) { | |
| 19762 | if (param_decl_node->data.param_decl.anytype_token == nullptr) { | |
| 19763 | 19763 | AstNode *param_type_node = param_decl_node->data.param_decl.type; |
| 19764 | 19764 | ZigType *param_type = ir_analyze_type_expr(ira, *exec_scope, param_type_node); |
| 19765 | 19765 | if (type_is_invalid(param_type)) |
| ... | ... | @@ -19799,7 +19799,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod |
| 19799 | 19799 | arg_part_of_generic_id = true; |
| 19800 | 19800 | casted_arg = arg; |
| 19801 | 19801 | } else { |
| 19802 | if (param_decl_node->data.param_decl.var_token == nullptr) { | |
| 19802 | if (param_decl_node->data.param_decl.anytype_token == nullptr) { | |
| 19803 | 19803 | AstNode *param_type_node = param_decl_node->data.param_decl.type; |
| 19804 | 19804 | ZigType *param_type = ir_analyze_type_expr(ira, *child_scope, param_type_node); |
| 19805 | 19805 | if (type_is_invalid(param_type)) |
| ... | ... | @@ -20011,7 +20011,7 @@ static IrInstGen *ir_analyze_store_ptr(IrAnalyze *ira, IrInst* source_instr, |
| 20011 | 20011 | } |
| 20012 | 20012 | |
| 20013 | 20013 | if (ptr->value->type->data.pointer.inferred_struct_field != nullptr && |
| 20014 | child_type == ira->codegen->builtin_types.entry_var) | |
| 20014 | child_type == ira->codegen->builtin_types.entry_anytype) | |
| 20015 | 20015 | { |
| 20016 | 20016 | child_type = ptr->value->type->data.pointer.inferred_struct_field->inferred_struct_type; |
| 20017 | 20017 | } |
| ... | ... | @@ -20202,6 +20202,11 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr, |
| 20202 | 20202 | } |
| 20203 | 20203 | |
| 20204 | 20204 | AstNode *return_type_node = fn_proto_node->data.fn_proto.return_type; |
| 20205 | if (return_type_node == nullptr) { | |
| 20206 | ir_add_error(ira, &fn_ref->base, | |
| 20207 | buf_sprintf("TODO implement inferred return types https://github.com/ziglang/zig/issues/447")); | |
| 20208 | return ira->codegen->invalid_inst_gen; | |
| 20209 | } | |
| 20205 | 20210 | ZigType *specified_return_type = ir_analyze_type_expr(ira, exec_scope, return_type_node); |
| 20206 | 20211 | if (type_is_invalid(specified_return_type)) |
| 20207 | 20212 | return ira->codegen->invalid_inst_gen; |
| ... | ... | @@ -20364,7 +20369,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr, |
| 20364 | 20369 | inst_fn_type_id.alignment = align_bytes; |
| 20365 | 20370 | } |
| 20366 | 20371 | |
| 20367 | if (fn_proto_node->data.fn_proto.return_var_token == nullptr) { | |
| 20372 | if (fn_proto_node->data.fn_proto.return_anytype_token == nullptr) { | |
| 20368 | 20373 | AstNode *return_type_node = fn_proto_node->data.fn_proto.return_type; |
| 20369 | 20374 | ZigType *specified_return_type = ir_analyze_type_expr(ira, impl_fn->child_scope, return_type_node); |
| 20370 | 20375 | if (type_is_invalid(specified_return_type)) |
| ... | ... | @@ -20463,7 +20468,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr, |
| 20463 | 20468 | if (type_is_invalid(dummy_result->value->type)) |
| 20464 | 20469 | return ira->codegen->invalid_inst_gen; |
| 20465 | 20470 | ZigType *res_child_type = result_loc->value->type->data.pointer.child_type; |
| 20466 | if (res_child_type == ira->codegen->builtin_types.entry_var) { | |
| 20471 | if (res_child_type == ira->codegen->builtin_types.entry_anytype) { | |
| 20467 | 20472 | res_child_type = impl_fn_type_id->return_type; |
| 20468 | 20473 | } |
| 20469 | 20474 | if (!handle_is_ptr(ira->codegen, res_child_type)) { |
| ... | ... | @@ -20606,7 +20611,7 @@ static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr, |
| 20606 | 20611 | if (type_is_invalid(dummy_result->value->type)) |
| 20607 | 20612 | return ira->codegen->invalid_inst_gen; |
| 20608 | 20613 | ZigType *res_child_type = result_loc->value->type->data.pointer.child_type; |
| 20609 | if (res_child_type == ira->codegen->builtin_types.entry_var) { | |
| 20614 | if (res_child_type == ira->codegen->builtin_types.entry_anytype) { | |
| 20610 | 20615 | res_child_type = return_type; |
| 20611 | 20616 | } |
| 20612 | 20617 | if (!handle_is_ptr(ira->codegen, res_child_type)) { |
| ... | ... | @@ -22337,7 +22342,7 @@ static IrInstGen *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_name, |
| 22337 | 22342 | inferred_struct_field->inferred_struct_type = container_type; |
| 22338 | 22343 | inferred_struct_field->field_name = field_name; |
| 22339 | 22344 | |
| 22340 | ZigType *elem_type = ira->codegen->builtin_types.entry_var; | |
| 22345 | ZigType *elem_type = ira->codegen->builtin_types.entry_anytype; | |
| 22341 | 22346 | ZigType *field_ptr_type = get_pointer_to_type_extra2(ira->codegen, elem_type, |
| 22342 | 22347 | container_ptr_type->data.pointer.is_const, container_ptr_type->data.pointer.is_volatile, |
| 22343 | 22348 | PtrLenSingle, 0, 0, 0, false, VECTOR_INDEX_NONE, inferred_struct_field, nullptr); |
| ... | ... | @@ -25115,7 +25120,7 @@ static ZigValue *create_ptr_like_type_info(IrAnalyze *ira, ZigType *ptr_type_ent |
| 25115 | 25120 | fields[5]->special = ConstValSpecialStatic; |
| 25116 | 25121 | fields[5]->type = ira->codegen->builtin_types.entry_bool; |
| 25117 | 25122 | fields[5]->data.x_bool = attrs_type->data.pointer.allow_zero; |
| 25118 | // sentinel: var | |
| 25123 | // sentinel: anytype | |
| 25119 | 25124 | ensure_field_index(result->type, "sentinel", 6); |
| 25120 | 25125 | fields[6]->special = ConstValSpecialStatic; |
| 25121 | 25126 | if (attrs_type->data.pointer.child_type->id != ZigTypeIdOpaque) { |
| ... | ... | @@ -25243,7 +25248,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy |
| 25243 | 25248 | fields[1]->special = ConstValSpecialStatic; |
| 25244 | 25249 | fields[1]->type = ira->codegen->builtin_types.entry_type; |
| 25245 | 25250 | fields[1]->data.x_type = type_entry->data.array.child_type; |
| 25246 | // sentinel: var | |
| 25251 | // sentinel: anytype | |
| 25247 | 25252 | fields[2]->special = ConstValSpecialStatic; |
| 25248 | 25253 | fields[2]->type = get_optional_type(ira->codegen, type_entry->data.array.child_type); |
| 25249 | 25254 | fields[2]->data.x_optional = type_entry->data.array.sentinel; |
| ... | ... | @@ -25598,7 +25603,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy |
| 25598 | 25603 | inner_fields[2]->type = ira->codegen->builtin_types.entry_type; |
| 25599 | 25604 | inner_fields[2]->data.x_type = struct_field->type_entry; |
| 25600 | 25605 | |
| 25601 | // default_value: var | |
| 25606 | // default_value: anytype | |
| 25602 | 25607 | inner_fields[3]->special = ConstValSpecialStatic; |
| 25603 | 25608 | inner_fields[3]->type = get_optional_type2(ira->codegen, struct_field->type_entry); |
| 25604 | 25609 | if (inner_fields[3]->type == nullptr) return ErrorSemanticAnalyzeFail; |
| ... | ... | @@ -25736,7 +25741,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigTy |
| 25736 | 25741 | ZigValue **fields = alloc_const_vals_ptrs(ira->codegen, 1); |
| 25737 | 25742 | result->data.x_struct.fields = fields; |
| 25738 | 25743 | ZigFn *fn = type_entry->data.frame.fn; |
| 25739 | // function: var | |
| 25744 | // function: anytype | |
| 25740 | 25745 | ensure_field_index(result->type, "function", 0); |
| 25741 | 25746 | fields[0] = create_const_fn(ira->codegen, fn); |
| 25742 | 25747 | break; |
| ... | ... | @@ -29996,7 +30001,7 @@ static IrInstGen *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstSrcArgTy |
| 29996 | 30001 | if (arg_index >= fn_type_id->param_count) { |
| 29997 | 30002 | if (instruction->allow_var) { |
| 29998 | 30003 | // TODO remove this with var args |
| 29999 | return ir_const_type(ira, &instruction->base.base, ira->codegen->builtin_types.entry_var); | |
| 30004 | return ir_const_type(ira, &instruction->base.base, ira->codegen->builtin_types.entry_anytype); | |
| 30000 | 30005 | } |
| 30001 | 30006 | ir_add_error(ira, &arg_index_inst->base, |
| 30002 | 30007 | buf_sprintf("arg index %" ZIG_PRI_u64 " out of bounds; '%s' has %" ZIG_PRI_usize " arguments", |
| ... | ... | @@ -30010,7 +30015,7 @@ static IrInstGen *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstSrcArgTy |
| 30010 | 30015 | ir_assert(fn_type->data.fn.is_generic, &instruction->base.base); |
| 30011 | 30016 | |
| 30012 | 30017 | if (instruction->allow_var) { |
| 30013 | return ir_const_type(ira, &instruction->base.base, ira->codegen->builtin_types.entry_var); | |
| 30018 | return ir_const_type(ira, &instruction->base.base, ira->codegen->builtin_types.entry_anytype); | |
| 30014 | 30019 | } else { |
| 30015 | 30020 | ir_add_error(ira, &arg_index_inst->base, |
| 30016 | 30021 | buf_sprintf("@ArgType could not resolve the type of arg %" ZIG_PRI_u64 " because '%s' is generic", |
src/parser.cpp+13-13| ... | ... | @@ -786,7 +786,7 @@ static AstNode *ast_parse_top_level_decl(ParseContext *pc, VisibMod visib_mod, B |
| 786 | 786 | return nullptr; |
| 787 | 787 | } |
| 788 | 788 | |
| 789 | // FnProto <- KEYWORD_fn IDENTIFIER? LPAREN ParamDeclList RPAREN ByteAlign? LinkSection? EXCLAMATIONMARK? (KEYWORD_var / TypeExpr) | |
| 789 | // FnProto <- KEYWORD_fn IDENTIFIER? LPAREN ParamDeclList RPAREN ByteAlign? LinkSection? EXCLAMATIONMARK? (KEYWORD_anytype / TypeExpr) | |
| 790 | 790 | static AstNode *ast_parse_fn_proto(ParseContext *pc) { |
| 791 | 791 | Token *first = eat_token_if(pc, TokenIdKeywordFn); |
| 792 | 792 | if (first == nullptr) { |
| ... | ... | @@ -801,10 +801,10 @@ static AstNode *ast_parse_fn_proto(ParseContext *pc) { |
| 801 | 801 | AstNode *align_expr = ast_parse_byte_align(pc); |
| 802 | 802 | AstNode *section_expr = ast_parse_link_section(pc); |
| 803 | 803 | AstNode *callconv_expr = ast_parse_callconv(pc); |
| 804 | Token *var = eat_token_if(pc, TokenIdKeywordVar); | |
| 804 | Token *anytype = eat_token_if(pc, TokenIdKeywordAnyType); | |
| 805 | 805 | Token *exmark = nullptr; |
| 806 | 806 | AstNode *return_type = nullptr; |
| 807 | if (var == nullptr) { | |
| 807 | if (anytype == nullptr) { | |
| 808 | 808 | exmark = eat_token_if(pc, TokenIdBang); |
| 809 | 809 | return_type = ast_expect(pc, ast_parse_type_expr); |
| 810 | 810 | } |
| ... | ... | @@ -816,7 +816,7 @@ static AstNode *ast_parse_fn_proto(ParseContext *pc) { |
| 816 | 816 | res->data.fn_proto.align_expr = align_expr; |
| 817 | 817 | res->data.fn_proto.section_expr = section_expr; |
| 818 | 818 | res->data.fn_proto.callconv_expr = callconv_expr; |
| 819 | res->data.fn_proto.return_var_token = var; | |
| 819 | res->data.fn_proto.return_anytype_token = anytype; | |
| 820 | 820 | res->data.fn_proto.auto_err_set = exmark != nullptr; |
| 821 | 821 | res->data.fn_proto.return_type = return_type; |
| 822 | 822 | |
| ... | ... | @@ -870,9 +870,9 @@ static AstNode *ast_parse_container_field(ParseContext *pc) { |
| 870 | 870 | |
| 871 | 871 | AstNode *type_expr = nullptr; |
| 872 | 872 | if (eat_token_if(pc, TokenIdColon) != nullptr) { |
| 873 | Token *var_tok = eat_token_if(pc, TokenIdKeywordVar); | |
| 874 | if (var_tok != nullptr) { | |
| 875 | type_expr = ast_create_node(pc, NodeTypeVarFieldType, var_tok); | |
| 873 | Token *anytype_tok = eat_token_if(pc, TokenIdKeywordAnyType); | |
| 874 | if (anytype_tok != nullptr) { | |
| 875 | type_expr = ast_create_node(pc, NodeTypeAnyTypeField, anytype_tok); | |
| 876 | 876 | } else { |
| 877 | 877 | type_expr = ast_expect(pc, ast_parse_type_expr); |
| 878 | 878 | } |
| ... | ... | @@ -2191,14 +2191,14 @@ static AstNode *ast_parse_param_decl(ParseContext *pc) { |
| 2191 | 2191 | } |
| 2192 | 2192 | |
| 2193 | 2193 | // ParamType |
| 2194 | // <- KEYWORD_var | |
| 2194 | // <- KEYWORD_anytype | |
| 2195 | 2195 | // / DOT3 |
| 2196 | 2196 | // / TypeExpr |
| 2197 | 2197 | static AstNode *ast_parse_param_type(ParseContext *pc) { |
| 2198 | Token *var_token = eat_token_if(pc, TokenIdKeywordVar); | |
| 2199 | if (var_token != nullptr) { | |
| 2200 | AstNode *res = ast_create_node(pc, NodeTypeParamDecl, var_token); | |
| 2201 | res->data.param_decl.var_token = var_token; | |
| 2198 | Token *anytype_token = eat_token_if(pc, TokenIdKeywordAnyType); | |
| 2199 | if (anytype_token != nullptr) { | |
| 2200 | AstNode *res = ast_create_node(pc, NodeTypeParamDecl, anytype_token); | |
| 2201 | res->data.param_decl.anytype_token = anytype_token; | |
| 2202 | 2202 | return res; |
| 2203 | 2203 | } |
| 2204 | 2204 | |
| ... | ... | @@ -3207,7 +3207,7 @@ void ast_visit_node_children(AstNode *node, void (*visit)(AstNode **, void *cont |
| 3207 | 3207 | visit_field(&node->data.suspend.block, visit, context); |
| 3208 | 3208 | break; |
| 3209 | 3209 | case NodeTypeEnumLiteral: |
| 3210 | case NodeTypeVarFieldType: | |
| 3210 | case NodeTypeAnyTypeField: | |
| 3211 | 3211 | break; |
| 3212 | 3212 | } |
| 3213 | 3213 | } |
src/tokenizer.cpp+2| ... | ... | @@ -106,6 +106,7 @@ static const struct ZigKeyword zig_keywords[] = { |
| 106 | 106 | {"allowzero", TokenIdKeywordAllowZero}, |
| 107 | 107 | {"and", TokenIdKeywordAnd}, |
| 108 | 108 | {"anyframe", TokenIdKeywordAnyFrame}, |
| 109 | {"anytype", TokenIdKeywordAnyType}, | |
| 109 | 110 | {"asm", TokenIdKeywordAsm}, |
| 110 | 111 | {"async", TokenIdKeywordAsync}, |
| 111 | 112 | {"await", TokenIdKeywordAwait}, |
| ... | ... | @@ -1569,6 +1570,7 @@ const char * token_name(TokenId id) { |
| 1569 | 1570 | case TokenIdKeywordAlign: return "align"; |
| 1570 | 1571 | case TokenIdKeywordAnd: return "and"; |
| 1571 | 1572 | case TokenIdKeywordAnyFrame: return "anyframe"; |
| 1573 | case TokenIdKeywordAnyType: return "anytype"; | |
| 1572 | 1574 | case TokenIdKeywordAsm: return "asm"; |
| 1573 | 1575 | case TokenIdKeywordBreak: return "break"; |
| 1574 | 1576 | case TokenIdKeywordCatch: return "catch"; |
src/tokenizer.hpp+1| ... | ... | @@ -54,6 +54,7 @@ enum TokenId { |
| 54 | 54 | TokenIdKeywordAllowZero, |
| 55 | 55 | TokenIdKeywordAnd, |
| 56 | 56 | TokenIdKeywordAnyFrame, |
| 57 | TokenIdKeywordAnyType, | |
| 57 | 58 | TokenIdKeywordAsm, |
| 58 | 59 | TokenIdKeywordAsync, |
| 59 | 60 | TokenIdKeywordAwait, |