| ... | ... | @@ -8,7 +8,7 @@ |
| 8 | 8 | <link rel="icon" href="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxNTMgMTQwIj48ZyBmaWxsPSIjRjdBNDFEIj48Zz48cG9seWdvbiBwb2ludHM9IjQ2LDIyIDI4LDQ0IDE5LDMwIi8+PHBvbHlnb24gcG9pbnRzPSI0NiwyMiAzMywzMyAyOCw0NCAyMiw0NCAyMiw5NSAzMSw5NSAyMCwxMDAgMTIsMTE3IDAsMTE3IDAsMjIiIHNoYXBlLXJlbmRlcmluZz0iY3Jpc3BFZGdlcyIvPjxwb2x5Z29uIHBvaW50cz0iMzEsOTUgMTIsMTE3IDQsMTA2Ii8+PC9nPjxnPjxwb2x5Z29uIHBvaW50cz0iNTYsMjIgNjIsMzYgMzcsNDQiLz48cG9seWdvbiBwb2ludHM9IjU2LDIyIDExMSwyMiAxMTEsNDQgMzcsNDQgNTYsMzIiIHNoYXBlLXJlbmRlcmluZz0iY3Jpc3BFZGdlcyIvPjxwb2x5Z29uIHBvaW50cz0iMTE2LDk1IDk3LDExNyA5MCwxMDQiLz48cG9seWdvbiBwb2ludHM9IjExNiw5NSAxMDAsMTA0IDk3LDExNyA0MiwxMTcgNDIsOTUiIHNoYXBlLXJlbmRlcmluZz0iY3Jpc3BFZGdlcyIvPjxwb2x5Z29uIHBvaW50cz0iMTUwLDAgNTIsMTE3IDMsMTQwIDEwMSwyMiIvPjwvZz48Zz48cG9seWdvbiBwb2ludHM9IjE0MSwyMiAxNDAsNDAgMTIyLDQ1Ii8+PHBvbHlnb24gcG9pbnRzPSIxNTMsMjIgMTUzLDExNyAxMDYsMTE3IDEyMCwxMDUgMTI1LDk1IDEzMSw5NSAxMzEsNDUgMTIyLDQ1IDEzMiwzNiAxNDEsMjIiIHNoYXBlLXJlbmRlcmluZz0iY3Jpc3BFZGdlcyIvPjxwb2x5Z29uIHBvaW50cz0iMTI1LDk1IDEzMCwxMTAgMTA2LDExNyIvPjwvZz48L2c+PC9zdmc+"> |
| 9 | 9 | <style> |
| 10 | 10 | :root{ |
| 11 | | --nav-width: 24em; |
| 11 | --nav-width: 26em; |
| 12 | 12 | --nav-margin-l: 1em; |
| 13 | 13 | } |
| 14 | 14 | body{ |
| ... | ... | @@ -27,6 +27,25 @@ |
| 27 | 27 | #navigation { |
| 28 | 28 | padding: 0 1em; |
| 29 | 29 | } |
| 30 | table ul { |
| 31 | list-style-type: none; |
| 32 | padding: 0em; |
| 33 | } |
| 34 | table li { |
| 35 | padding-bottom: 1em; |
| 36 | line-height:1.2em; |
| 37 | } |
| 38 | table, th, td { |
| 39 | border-collapse: collapse; |
| 40 | border: 1px solid grey; |
| 41 | } |
| 42 | th, td { |
| 43 | padding: 0.5em; |
| 44 | } |
| 45 | th[scope=row] { |
| 46 | text-align: left; |
| 47 | font-weight: normal; |
| 48 | } |
| 30 | 49 | |
| 31 | 50 | @media screen and (min-width: 1025px) { |
| 32 | 51 | header { |
| ... | ... | @@ -61,17 +80,6 @@ |
| 61 | 80 | dt { |
| 62 | 81 | font-weight: bold; |
| 63 | 82 | } |
| 64 | | table, th, td { |
| 65 | | border-collapse: collapse; |
| 66 | | border: 1px solid grey; |
| 67 | | } |
| 68 | | th, td { |
| 69 | | padding: 0.1em; |
| 70 | | } |
| 71 | | th[scope=row] { |
| 72 | | text-align: left; |
| 73 | | font-weight: normal; |
| 74 | | } |
| 75 | 83 | .sgr-1m { |
| 76 | 84 | font-weight: bold; |
| 77 | 85 | } |
| ... | ... | @@ -200,24 +208,9 @@ |
| 200 | 208 | visibility: visible; |
| 201 | 209 | } |
| 202 | 210 | |
| 203 | | pre { |
| 204 | | counter-reset: line; |
| 205 | | } |
| 206 | | pre .line:before { |
| 207 | | counter-increment: line; |
| 208 | | content: counter(line); |
| 209 | | display: inline-block; |
| 210 | | padding-right: 1em; |
| 211 | | width: 2em; |
| 212 | | text-align: right; |
| 213 | | color: #999; |
| 214 | | } |
| 215 | 211 | th pre code { |
| 216 | 212 | background: none; |
| 217 | 213 | } |
| 218 | | th .line:before { |
| 219 | | display: none; |
| 220 | | } |
| 221 | 214 | |
| 222 | 215 | @media (prefers-color-scheme: dark) { |
| 223 | 216 | body{ |
| ... | ... | @@ -301,39 +294,6 @@ |
| 301 | 294 | color: #fff; |
| 302 | 295 | } |
| 303 | 296 | } |
| 304 | | |
| 305 | | @media all { |
| 306 | | main { |
| 307 | | counter-reset: section-2; |
| 308 | | } |
| 309 | | h2 { |
| 310 | | counter-reset: section-3; |
| 311 | | } |
| 312 | | h2::before { |
| 313 | | counter-increment: section-2; |
| 314 | | content: counter(section-2) ". "; |
| 315 | | font-weight: normal; |
| 316 | | } |
| 317 | | h3 { |
| 318 | | counter-reset: section-4; |
| 319 | | } |
| 320 | | h3::before { |
| 321 | | counter-increment: section-3; |
| 322 | | content: counter(section-2) "." counter(section-3) ". "; |
| 323 | | font-weight: normal; |
| 324 | | } |
| 325 | | h4::before { |
| 326 | | counter-increment: section-4; |
| 327 | | content: counter(section-2) "." counter(section-3) "." counter(section-4) ". "; |
| 328 | | font-weight: normal; |
| 329 | | } |
| 330 | | #zig-version::before { |
| 331 | | content: ""; |
| 332 | | } |
| 333 | | #table-of-contents::before { |
| 334 | | content: ""; |
| 335 | | } |
| 336 | | } |
| 337 | 297 | </style> |
| 338 | 298 | </head> |
| 339 | 299 | <body> |
| ... | ... | @@ -410,109 +370,20 @@ pub fn main() !void { |
| 410 | 370 | } |
| 411 | 371 | {#code_end#} |
| 412 | 372 | <p> |
| 413 | | The Zig code sample above demonstrates one way to create a program that will output: <samp>Hello, world!</samp>. |
| 414 | | </p> |
| 415 | | <p> |
| 416 | | The code sample shows the contents of a file named <code class="file">hello.zig</code>. Files storing Zig |
| 417 | | source code are {#link|UTF-8 encoded|Source Encoding#} text files. The files storing |
| 418 | | Zig source code must be named with the <code class="file"><em>.zig</em></code> extension. |
| 419 | | </p> |
| 420 | | <p> |
| 421 | | Following the <code class="file">hello.zig</code> Zig code sample, the {#link|Zig Build System#} is used |
| 422 | | to build an executable program from the <code class="file">hello.zig</code> source code. Then, the |
| 423 | | <code class="file">hello</code> program is executed showing its output <samp>Hello, world!</samp>. The |
| 424 | | lines beginning with <samp>$</samp> represent command line prompts and a command. |
| 425 | | Everything else is program output. |
| 426 | | </p> |
| 427 | | <p> |
| 428 | | The code sample begins by adding the {#link|Zig Standard Library#} to the build using the {#link|@import#} builtin function. |
| 429 | | The {#syntax#}@import("std"){#endsyntax#} function call creates a structure that represents the Zig Standard Library. |
| 430 | | The code then {#link|declares|Container Level Variables#} a |
| 431 | | {#link|constant identifier|Assignment#}, named {#syntax#}std{#endsyntax#}, that gives access to the features of the Zig Standard Library. |
| 432 | | </p> |
| 433 | | <p> |
| 434 | | Next, a {#link|public function|Functions#}, {#syntax#}pub fn{#endsyntax#}, named {#syntax#}main{#endsyntax#} |
| 435 | | is declared. The {#syntax#}main{#endsyntax#} function is necessary because it tells the Zig compiler where the program starts. Programs |
| 436 | | designed to be executed will need a {#syntax#}pub fn main{#endsyntax#} function. |
| 437 | | </p> |
| 438 | | <aside role="note" aria-label="Note about main function"> |
| 439 | | <p> |
| 440 | | For more advanced use cases, Zig offers other features to inform the compiler where the program starts. Also, libraries do not need a |
| 441 | | {#syntax#}pub fn main{#endsyntax#} function because library code is called by other programs or libraries. |
| 442 | | </p> |
| 443 | | </aside> |
| 444 | | <p> |
| 445 | | A function is a block of any number of statements and expressions, that as a whole, perform a task. |
| 446 | | Functions may or may not return data after they are done performing their task. If a function |
| 447 | | cannot perform its task, it might return an error. Zig makes all of this explicit. |
| 448 | | </p> |
| 449 | | <p> |
| 450 | | In the <code class="file">hello.zig</code> code sample, the <code>main</code> function is declared |
| 451 | | with the {#syntax#}!void{#endsyntax#} return type. This return type is known as an {#link|Error Union Type#}. |
| 452 | | This syntax tells the Zig compiler that the function will either return an |
| 453 | | error or a value. An error union type combines an {#link|Error Set Type#} and any other data type |
| 454 | | (e.g. a {#link|Primitive Type|Primitive Types#} or a user-defined type such as a {#link|struct#}, {#link|enum#}, or {#link|union#}). |
| 455 | | The full form of an error union type is |
| 456 | | <code>&lt;error set type&gt;</code>{#syntax#}!{#endsyntax#}<code>&lt;any data type&gt;</code>. In the code |
| 457 | | sample, the error set type is not explicitly written on the left side of the {#syntax#}!{#endsyntax#} operator. |
| 458 | | When written this way, the error set type is an {#link|inferred error set type|Inferred Error Sets#}. The |
| 459 | | {#syntax#}void{#endsyntax#} after the {#syntax#}!{#endsyntax#} operator |
| 460 | | tells the compiler that the function will not return a value under normal circumstances (i.e. when no errors occur). |
| 461 | | </p> |
| 462 | | <aside role="note" aria-label="Note to disambiguate exclamation mark operator"> |
| 463 | | <p> |
| 464 | | Note to experienced programmers: Zig also has the boolean {#link|operator|Operators#} {#syntax#}!a{#endsyntax#} |
| 465 | | where {#syntax#}a{#endsyntax#} is a value of type {#syntax#}bool{#endsyntax#}. Error union types contain the |
| 466 | | name of the type in the syntax: {#syntax#}!{#endsyntax#}<code>&lt;any data type&gt;</code>. |
| 467 | | </p> |
| 468 | | </aside> |
| 469 | | <p> |
| 470 | | In Zig, a function's block of statements and expressions are surrounded by an open curly-brace <code>{</code> and |
| 471 | | close curly-brace <code>}</code>. In <code class="file">hello.zig</code>, the {#syntax#}main{#endsyntax#} function |
| 472 | | contains two statements. |
| 473 | | </p> |
| 474 | | <p> |
| 475 | | In the first statement, a constant identifier, {#syntax#}stdout{#endsyntax#}, is initialized to represent standard output's |
| 476 | | writer. In the second statement, the program tries to print the <samp>Hello, world!</samp> message to standard output. |
| 477 | | </p> |
| 478 | | <p> |
| 479 | | Functions sometimes need inputs to perform their task. Inputs are passed, in between parentheses, to functions. These |
| 480 | | inputs are also known as arguments. When multiple arguments are passed to a function, they are separated by commas. |
| 481 | | </p> |
| 482 | | <p> |
| 483 | | Two arguments are passed to the {#syntax#}stdout.print(){#endsyntax#} function: {#syntax#}"Hello, {s}!\n"{#endsyntax#} |
| 484 | | and {#syntax#}.{"world"}{#endsyntax#}. The first argument is called a format string, which is a string containing one or |
| 485 | | more placeholders. {#syntax#}"Hello, {s}!\n"{#endsyntax#} contains the placeholder {#syntax#}{s}{#endsyntax#}, which is |
| 486 | | replaced with {#syntax#}"world"{#endsyntax#} from the second argument. The file <code class="file">string_literals.zig</code> in |
| 487 | | {#link|String Literals and Unicode Code Point Literals|String Literals and Unicode Code Point Literals#} contains examples of format |
| 488 | | strings that can be used with the {#syntax#}stdout.print(){#endsyntax#} function. The <code>\n</code> inside of |
| 489 | | {#syntax#}"Hello, {s}!\n"{#endsyntax#} is the {#link|escape sequence|Escape Sequences#} for the newline character. |
| 490 | | </p> |
| 491 | | <p> |
| 492 | | The {#link|try#} expression evaluates the result of {#syntax#}stdout.print{#endsyntax#}. If the result is an error, then the |
| 493 | | {#syntax#}try{#endsyntax#} expression will return from {#syntax#}main{#endsyntax#} with the error. Otherwise, the program will continue. |
| 494 | | In this case, there are no more statements or expressions left to execute in the {#syntax#}main{#endsyntax#} function, so the program exits. |
| 495 | | </p> |
| 496 | | <p> |
| 497 | | In Zig, the standard output writer's {#syntax#}print{#endsyntax#} function is allowed to fail because |
| 498 | | it is actually a function defined as part of a generic Writer. Consider a generic Writer that |
| 499 | | represents writing data to a file. When the disk is full, a write to the file will fail. |
| 500 | | However, we typically do not expect writing text to the standard output to fail. To avoid having |
| 501 | | to handle the failure case of printing to standard output, you can use alternate functions: the |
| 502 | | functions in {#syntax#}std.log{#endsyntax#} for proper logging or the {#syntax#}std.debug.print{#endsyntax#} function. |
| 503 | | This documentation will use the latter option to print to standard error (stderr) and silently return |
| 504 | | on failure. The next code sample, <code class="file">hello_again.zig</code> demonstrates the use of |
| 505 | | {#syntax#}std.debug.print{#endsyntax#}. |
| 373 | Most of the time, it more appropriate to write to stderr rather than stdout, and |
| 374 | whether or not the message is successfully written to the stream is irrelevant. |
| 375 | For this common case, there is a simpler API: |
| 506 | 376 | </p> |
| 507 | 377 | {#code_begin|exe|hello_again#} |
| 508 | | const print = @import("std").debug.print; |
| 378 | const std = @import("std"); |
| 509 | 379 | |
| 510 | 380 | pub fn main() void { |
| 511 | | print("Hello, world!\n", .{}); |
| 381 | std.debug.print("Hello, world!\n", .{}); |
| 512 | 382 | } |
| 513 | 383 | {#code_end#} |
| 514 | 384 | <p> |
| 515 | | Note that you can leave off the {#syntax#}!{#endsyntax#} from the return type because {#syntax#}std.debug.print{#endsyntax#} cannot fail. |
| 385 | In this case, the {#syntax#}!{#endsyntax#} may be omitted from the return |
| 386 | type because no errors are returned from the function. |
| 516 | 387 | </p> |
| 517 | 388 | {#see_also|Values|@import|Errors|Root Source File|Source Encoding#} |
| 518 | 389 | {#header_close#} |
| ... | ... | @@ -896,42 +767,22 @@ pub fn main() void { |
| 896 | 767 | The type of string literals encodes both the length, and the fact that they are null-terminated, |
| 897 | 768 | and thus they can be {#link|coerced|Type Coercion#} to both {#link|Slices#} and |
| 898 | 769 | {#link|Null-Terminated Pointers|Sentinel-Terminated Pointers#}. |
| 770 | Dereferencing string literals converts them to {#link|Arrays#}. |
| 899 | 771 | </p> |
| 900 | 772 | <p> |
| 901 | | Dereferencing string literals converts them to {#link|Arrays#}, allowing you to initialize a buffer with the contents of a string literal. |
| 902 | | </p> |
| 903 | | {#code_begin|syntax|mutable_string_buffer#} |
| 904 | | test { |
| 905 | | var buffer = [_]u8{0}**256; |
| 906 | | const home_dir = "C:/Users/root"; |
| 907 | | buffer[0..home_dir.len].* = home_dir.*; |
| 908 | | } |
| 909 | | {#code_end#} |
| 910 | | <p> |
| 911 | | The encoding of a string in Zig is de-facto assumed to be UTF-8. |
| 912 | | Because Zig source code is {#link|UTF-8 encoded|Source Encoding#}, any non-ASCII bytes appearing within a string literal |
| 913 | | in source code carry their UTF-8 meaning into the content of the string in the Zig program; |
| 914 | | the bytes are not modified by the compiler. |
| 915 | | However, it is possible to embed non-UTF-8 bytes into a string literal using <code>\xNN</code> notation. |
| 916 | | </p> |
| 917 | | <p> |
| 918 | | Indexing into a string containing non-ASCII bytes will return individual bytes, whether valid |
| 919 | | UTF-8 or not. |
| 920 | | The {#link|Zig Standard Library#} provides routines for checking the validity of UTF-8 encoded |
| 921 | | strings, accessing their code points and other encoding/decoding related tasks in |
| 922 | | {#syntax#}std.unicode{#endsyntax#}. |
| 773 | Because Zig source code is {#link|UTF-8 encoded|Source Encoding#}, any |
| 774 | non-ASCII bytes appearing within a string literal in source code carry |
| 775 | their UTF-8 meaning into the content of the string in the Zig program; |
| 776 | the bytes are not modified by the compiler. It is possible to embed |
| 777 | non-UTF-8 bytes into a string literal using <code>\xNN</code> notation. |
| 923 | 778 | </p> |
| 779 | <p>Indexing into a string containing non-ASCII bytes returns individual |
| 780 | bytes, whether valid UTF-8 or not.</p> |
| 924 | 781 | <p> |
| 925 | 782 | Unicode code point literals have type {#syntax#}comptime_int{#endsyntax#}, the same as |
| 926 | 783 | {#link|Integer Literals#}. All {#link|Escape Sequences#} are valid in both string literals |
| 927 | 784 | and Unicode code point literals. |
| 928 | 785 | </p> |
| 929 | | <p> |
| 930 | | In many other programming languages, a Unicode code point literal is called a "character literal". |
| 931 | | However, there is <a href="https://unicode.org/glossary">no precise technical definition of a "character"</a> |
| 932 | | in recent versions of the Unicode specification (as of Unicode 13.0). |
| 933 | | In Zig, a Unicode code point literal corresponds to the Unicode definition of a code point. |
| 934 | | </p> |
| 935 | 786 | {#code_begin|exe|string_literals#} |
| 936 | 787 | const print = @import("std").debug.print; |
| 937 | 788 | const mem = @import("std").mem; // will be used to compare bytes |
| ... | ... | @@ -1632,26 +1483,27 @@ pub fn main() void { |
| 1632 | 1483 | {#header_open|Table of Operators#} |
| 1633 | 1484 | <div class="table-wrapper"> |
| 1634 | 1485 | <table> |
| 1635 | | <caption>Table of Operators</caption> |
| 1636 | 1486 | <thead> |
| 1637 | 1487 | <tr> |
| 1488 | <th scope="col">Name</th> |
| 1638 | 1489 | <th scope="col">Syntax</th> |
| 1639 | | <th scope="col">Relevant Types</th> |
| 1640 | | <th scope="col">Description</th> |
| 1490 | <th scope="col">Types</th> |
| 1491 | <th scope="col">Remarks</th> |
| 1641 | 1492 | <th scope="col">Example</th> |
| 1642 | 1493 | </tr> |
| 1643 | 1494 | </thead> |
| 1644 | 1495 | <tbody> |
| 1645 | 1496 | <tr> |
| 1646 | | <th scope="row"><pre>{#syntax#}a + b |
| 1647 | | a += b{#endsyntax#}</pre></th> |
| 1497 | <td>Addition</td> |
| 1498 | <td><pre>{#syntax#}a + b |
| 1499 | a += b{#endsyntax#}</pre></td> |
| 1648 | 1500 | <td> |
| 1649 | 1501 | <ul> |
| 1650 | 1502 | <li>{#link|Integers#}</li> |
| 1651 | 1503 | <li>{#link|Floats#}</li> |
| 1652 | 1504 | </ul> |
| 1653 | 1505 | </td> |
| 1654 | | <td>Addition. |
| 1506 | <td> |
| 1655 | 1507 | <ul> |
| 1656 | 1508 | <li>Can cause {#link|overflow|Default Operations#} for integers.</li> |
| 1657 | 1509 | <li>Invokes {#link|Peer Type Resolution#} for the operands.</li> |
| ... | ... | @@ -1663,51 +1515,54 @@ a += b{#endsyntax#}</pre></th> |
| 1663 | 1515 | </td> |
| 1664 | 1516 | </tr> |
| 1665 | 1517 | <tr> |
| 1666 | | <th scope="row"><pre>{#syntax#}a +% b |
| 1667 | | a +%= b{#endsyntax#}</pre></th> |
| 1518 | <td>Wrapping Addition</td> |
| 1519 | <td><pre>{#syntax#}a +% b |
| 1520 | a +%= b{#endsyntax#}</pre></td> |
| 1668 | 1521 | <td> |
| 1669 | 1522 | <ul> |
| 1670 | 1523 | <li>{#link|Integers#}</li> |
| 1671 | 1524 | </ul> |
| 1672 | 1525 | </td> |
| 1673 | | <td>Wrapping Addition. |
| 1526 | <td> |
| 1674 | 1527 | <ul> |
| 1675 | | <li>Guaranteed to have twos-complement wrapping behavior.</li> |
| 1528 | <li>Twos-complement wrapping behavior.</li> |
| 1676 | 1529 | <li>Invokes {#link|Peer Type Resolution#} for the operands.</li> |
| 1677 | 1530 | <li>See also {#link|@addWithOverflow#}.</li> |
| 1678 | 1531 | </ul> |
| 1679 | 1532 | </td> |
| 1680 | 1533 | <td> |
| 1681 | | <pre>{#syntax#}@as(u32, std.math.maxInt(u32)) +% 1 == 0{#endsyntax#}</pre> |
| 1534 | <pre>{#syntax#}@as(u32, 0xffffffff) +% 1 == 0{#endsyntax#}</pre> |
| 1682 | 1535 | </td> |
| 1683 | 1536 | </tr> |
| 1684 | 1537 | <tr> |
| 1685 | | <th scope="row"><pre>{#syntax#}a +| b |
| 1686 | | a +|= b{#endsyntax#}</pre></th> |
| 1538 | <td>Saturating Addition</td> |
| 1539 | <td><pre>{#syntax#}a +| b |
| 1540 | a +|= b{#endsyntax#}</pre></td> |
| 1687 | 1541 | <td> |
| 1688 | 1542 | <ul> |
| 1689 | 1543 | <li>{#link|Integers#}</li> |
| 1690 | 1544 | </ul> |
| 1691 | 1545 | </td> |
| 1692 | | <td>Saturating Addition. |
| 1546 | <td> |
| 1693 | 1547 | <ul> |
| 1694 | 1548 | <li>Invokes {#link|Peer Type Resolution#} for the operands.</li> |
| 1695 | 1549 | </ul> |
| 1696 | 1550 | </td> |
| 1697 | 1551 | <td> |
| 1698 | | <pre>{#syntax#}@as(u32, std.math.maxInt(u32)) +| 1 == @as(u32, std.math.maxInt(u32)){#endsyntax#}</pre> |
| 1552 | <pre>{#syntax#}@as(u8, 255) +| 1 == @as(u8, 255){#endsyntax#}</pre> |
| 1699 | 1553 | </td> |
| 1700 | 1554 | </tr> |
| 1701 | 1555 | <tr> |
| 1702 | | <th scope="row"><pre>{#syntax#}a - b |
| 1703 | | a -= b{#endsyntax#}</pre></th> |
| 1556 | <td>Subtraction</td> |
| 1557 | <td><pre>{#syntax#}a - b |
| 1558 | a -= b{#endsyntax#}</pre></td> |
| 1704 | 1559 | <td> |
| 1705 | 1560 | <ul> |
| 1706 | 1561 | <li>{#link|Integers#}</li> |
| 1707 | 1562 | <li>{#link|Floats#}</li> |
| 1708 | 1563 | </ul> |
| 1709 | 1564 | </td> |
| 1710 | | <td>Subtraction. |
| 1565 | <td> |
| 1711 | 1566 | <ul> |
| 1712 | 1567 | <li>Can cause {#link|overflow|Default Operations#} for integers.</li> |
| 1713 | 1568 | <li>Invokes {#link|Peer Type Resolution#} for the operands.</li> |
| ... | ... | @@ -1719,33 +1574,35 @@ a -= b{#endsyntax#}</pre></th> |
| 1719 | 1574 | </td> |
| 1720 | 1575 | </tr> |
| 1721 | 1576 | <tr> |
| 1722 | | <th scope="row"><pre>{#syntax#}a -% b |
| 1723 | | a -%= b{#endsyntax#}</pre></th> |
| 1577 | <td>Wrapping Subtraction</td> |
| 1578 | <td><pre>{#syntax#}a -% b |
| 1579 | a -%= b{#endsyntax#}</pre></td> |
| 1724 | 1580 | <td> |
| 1725 | 1581 | <ul> |
| 1726 | 1582 | <li>{#link|Integers#}</li> |
| 1727 | 1583 | </ul> |
| 1728 | 1584 | </td> |
| 1729 | | <td>Wrapping Subtraction. |
| 1585 | <td> |
| 1730 | 1586 | <ul> |
| 1731 | | <li>Guaranteed to have twos-complement wrapping behavior.</li> |
| 1587 | <li>Twos-complement wrapping behavior.</li> |
| 1732 | 1588 | <li>Invokes {#link|Peer Type Resolution#} for the operands.</li> |
| 1733 | 1589 | <li>See also {#link|@subWithOverflow#}.</li> |
| 1734 | 1590 | </ul> |
| 1735 | 1591 | </td> |
| 1736 | 1592 | <td> |
| 1737 | | <pre>{#syntax#}@as(u32, 0) -% 1 == std.math.maxInt(u32){#endsyntax#}</pre> |
| 1593 | <pre>{#syntax#}@as(u8, 0) -% 1 == 255{#endsyntax#}</pre> |
| 1738 | 1594 | </td> |
| 1739 | 1595 | </tr> |
| 1740 | 1596 | <tr> |
| 1741 | | <th scope="row"><pre>{#syntax#}a -| b |
| 1742 | | a -|= b{#endsyntax#}</pre></th> |
| 1597 | <td>Saturating Subtraction</td> |
| 1598 | <td><pre>{#syntax#}a -| b |
| 1599 | a -|= b{#endsyntax#}</pre></td> |
| 1743 | 1600 | <td> |
| 1744 | 1601 | <ul> |
| 1745 | 1602 | <li>{#link|Integers#}</li> |
| 1746 | 1603 | </ul> |
| 1747 | 1604 | </td> |
| 1748 | | <td>Saturating Subtraction. |
| 1605 | <td> |
| 1749 | 1606 | <ul> |
| 1750 | 1607 | <li>Invokes {#link|Peer Type Resolution#} for the operands.</li> |
| 1751 | 1608 | </ul> |
| ... | ... | @@ -1755,7 +1612,8 @@ a -|= b{#endsyntax#}</pre></th> |
| 1755 | 1612 | </td> |
| 1756 | 1613 | </tr> |
| 1757 | 1614 | <tr> |
| 1758 | | <th scope="row"><pre>{#syntax#}-a{#endsyntax#}</pre></th> |
| 1615 | <td>Negation</td> |
| 1616 | <td><pre>{#syntax#}-a{#endsyntax#}</pre></td> |
| 1759 | 1617 | <td> |
| 1760 | 1618 | <ul> |
| 1761 | 1619 | <li>{#link|Integers#}</li> |
| ... | ... | @@ -1763,7 +1621,6 @@ a -|= b{#endsyntax#}</pre></th> |
| 1763 | 1621 | </ul> |
| 1764 | 1622 | </td> |
| 1765 | 1623 | <td> |
| 1766 | | Negation. |
| 1767 | 1624 | <ul> |
| 1768 | 1625 | <li>Can cause {#link|overflow|Default Operations#} for integers.</li> |
| 1769 | 1626 | </ul> |
| ... | ... | @@ -1773,32 +1630,33 @@ a -|= b{#endsyntax#}</pre></th> |
| 1773 | 1630 | </td> |
| 1774 | 1631 | </tr> |
| 1775 | 1632 | <tr> |
| 1776 | | <th scope="row"><pre>{#syntax#}-%a{#endsyntax#}</pre></th> |
| 1633 | <td>Wrapping Negation</td> |
| 1634 | <td><pre>{#syntax#}-%a{#endsyntax#}</pre></td> |
| 1777 | 1635 | <td> |
| 1778 | 1636 | <ul> |
| 1779 | 1637 | <li>{#link|Integers#}</li> |
| 1780 | 1638 | </ul> |
| 1781 | 1639 | </td> |
| 1782 | 1640 | <td> |
| 1783 | | Wrapping Negation. |
| 1784 | 1641 | <ul> |
| 1785 | | <li>Guaranteed to have twos-complement wrapping behavior.</li> |
| 1642 | <li>Twos-complement wrapping behavior.</li> |
| 1786 | 1643 | </ul> |
| 1787 | 1644 | </td> |
| 1788 | 1645 | <td> |
| 1789 | | <pre>{#syntax#}-%@as(i32, std.math.minInt(i32)) == std.math.minInt(i32){#endsyntax#}</pre> |
| 1646 | <pre>{#syntax#}-%@as(i8, -127) == -127{#endsyntax#}</pre> |
| 1790 | 1647 | </td> |
| 1791 | 1648 | </tr> |
| 1792 | 1649 | <tr> |
| 1793 | | <th scope="row"><pre>{#syntax#}a * b |
| 1794 | | a *= b{#endsyntax#}</pre></th> |
| 1650 | <td>Multiplication</td> |
| 1651 | <td><pre>{#syntax#}a * b |
| 1652 | a *= b{#endsyntax#}</pre></td> |
| 1795 | 1653 | <td> |
| 1796 | 1654 | <ul> |
| 1797 | 1655 | <li>{#link|Integers#}</li> |
| 1798 | 1656 | <li>{#link|Floats#}</li> |
| 1799 | 1657 | </ul> |
| 1800 | 1658 | </td> |
| 1801 | | <td>Multiplication. |
| 1659 | <td> |
| 1802 | 1660 | <ul> |
| 1803 | 1661 | <li>Can cause {#link|overflow|Default Operations#} for integers.</li> |
| 1804 | 1662 | <li>Invokes {#link|Peer Type Resolution#} for the operands.</li> |
| ... | ... | @@ -1810,16 +1668,17 @@ a *= b{#endsyntax#}</pre></th> |
| 1810 | 1668 | </td> |
| 1811 | 1669 | </tr> |
| 1812 | 1670 | <tr> |
| 1813 | | <th scope="row"><pre>{#syntax#}a *% b |
| 1814 | | a *%= b{#endsyntax#}</pre></th> |
| 1671 | <td>Wrapping Multiplication</td> |
| 1672 | <td><pre>{#syntax#}a *% b |
| 1673 | a *%= b{#endsyntax#}</pre></td> |
| 1815 | 1674 | <td> |
| 1816 | 1675 | <ul> |
| 1817 | 1676 | <li>{#link|Integers#}</li> |
| 1818 | 1677 | </ul> |
| 1819 | 1678 | </td> |
| 1820 | | <td>Wrapping Multiplication. |
| 1679 | <td> |
| 1821 | 1680 | <ul> |
| 1822 | | <li>Guaranteed to have twos-complement wrapping behavior.</li> |
| 1681 | <li>Twos-complement wrapping behavior.</li> |
| 1823 | 1682 | <li>Invokes {#link|Peer Type Resolution#} for the operands.</li> |
| 1824 | 1683 | <li>See also {#link|@mulWithOverflow#}.</li> |
| 1825 | 1684 | </ul> |
| ... | ... | @@ -1829,14 +1688,15 @@ a *%= b{#endsyntax#}</pre></th> |
| 1829 | 1688 | </td> |
| 1830 | 1689 | </tr> |
| 1831 | 1690 | <tr> |
| 1832 | | <th scope="row"><pre>{#syntax#}a *| b |
| 1833 | | a *|= b{#endsyntax#}</pre></th> |
| 1691 | <td>Saturating Multiplication</td> |
| 1692 | <td><pre>{#syntax#}a *| b |
| 1693 | a *|= b{#endsyntax#}</pre></td> |
| 1834 | 1694 | <td> |
| 1835 | 1695 | <ul> |
| 1836 | 1696 | <li>{#link|Integers#}</li> |
| 1837 | 1697 | </ul> |
| 1838 | 1698 | </td> |
| 1839 | | <td>Saturating Multiplication. |
| 1699 | <td> |
| 1840 | 1700 | <ul> |
| 1841 | 1701 | <li>Invokes {#link|Peer Type Resolution#} for the operands.</li> |
| 1842 | 1702 | </ul> |
| ... | ... | @@ -1846,15 +1706,16 @@ a *|= b{#endsyntax#}</pre></th> |
| 1846 | 1706 | </td> |
| 1847 | 1707 | </tr> |
| 1848 | 1708 | <tr> |
| 1849 | | <th scope="row"><pre>{#syntax#}a / b |
| 1850 | | a /= b{#endsyntax#}</pre></th> |
| 1709 | <td>Division</td> |
| 1710 | <td><pre>{#syntax#}a / b |
| 1711 | a /= b{#endsyntax#}</pre></td> |
| 1851 | 1712 | <td> |
| 1852 | 1713 | <ul> |
| 1853 | 1714 | <li>{#link|Integers#}</li> |
| 1854 | 1715 | <li>{#link|Floats#}</li> |
| 1855 | 1716 | </ul> |
| 1856 | 1717 | </td> |
| 1857 | | <td>Division. |
| 1718 | <td> |
| 1858 | 1719 | <ul> |
| 1859 | 1720 | <li>Can cause {#link|overflow|Default Operations#} for integers.</li> |
| 1860 | 1721 | <li>Can cause {#link|Division by Zero#} for integers.</li> |
| ... | ... | @@ -1872,15 +1733,16 @@ a /= b{#endsyntax#}</pre></th> |
| 1872 | 1733 | </td> |
| 1873 | 1734 | </tr> |
| 1874 | 1735 | <tr> |
| 1875 | | <th scope="row"><pre>{#syntax#}a % b |
| 1876 | | a %= b{#endsyntax#}</pre></th> |
| 1736 | <td>Remainder Division</td> |
| 1737 | <td><pre>{#syntax#}a % b |
| 1738 | a %= b{#endsyntax#}</pre></td> |
| 1877 | 1739 | <td> |
| 1878 | 1740 | <ul> |
| 1879 | 1741 | <li>{#link|Integers#}</li> |
| 1880 | 1742 | <li>{#link|Floats#}</li> |
| 1881 | 1743 | </ul> |
| 1882 | 1744 | </td> |
| 1883 | | <td>Remainder Division. |
| 1745 | <td> |
| 1884 | 1746 | <ul> |
| 1885 | 1747 | <li>Can cause {#link|Division by Zero#} for integers.</li> |
| 1886 | 1748 | <li>Can cause {#link|Division by Zero#} for floats in {#link|FloatMode.Optimized Mode|Floating Point Operations#}.</li> |
| ... | ... | @@ -1896,33 +1758,39 @@ a %= b{#endsyntax#}</pre></th> |
| 1896 | 1758 | </td> |
| 1897 | 1759 | </tr> |
| 1898 | 1760 | <tr> |
| 1899 | | <th scope="row"><pre>{#syntax#}a << b |
| 1900 | | a <<= b{#endsyntax#}</pre></th> |
| 1761 | <td>Bit Shift Left</td> |
| 1762 | <td><pre>{#syntax#}a << b |
| 1763 | a <<= b{#endsyntax#}</pre></td> |
| 1901 | 1764 | <td> |
| 1902 | 1765 | <ul> |
| 1903 | 1766 | <li>{#link|Integers#}</li> |
| 1904 | 1767 | </ul> |
| 1905 | 1768 | </td> |
| 1906 | | <td>Bit Shift Left. |
| 1769 | <td> |
| 1907 | 1770 | <ul> |
| 1908 | | <li>{#syntax#}b{#endsyntax#} must be {#link|comptime-known|comptime#} or have a type with log2 number of bits as {#syntax#}a{#endsyntax#}.</li> |
| 1771 | <li>Moves all bits to the left, inserting new zeroes at the |
| 1772 | least-significant bit.</li> |
| 1773 | <li>{#syntax#}b{#endsyntax#} must be |
| 1774 | {#link|comptime-known|comptime#} or have a type with log2 number |
| 1775 | of bits as {#syntax#}a{#endsyntax#}.</li> |
| 1909 | 1776 | <li>See also {#link|@shlExact#}.</li> |
| 1910 | 1777 | <li>See also {#link|@shlWithOverflow#}.</li> |
| 1911 | 1778 | </ul> |
| 1912 | 1779 | </td> |
| 1913 | 1780 | <td> |
| 1914 | | <pre>{#syntax#}1 << 8 == 256{#endsyntax#}</pre> |
| 1781 | <pre>{#syntax#}0b1 << 8 == 0b100000000{#endsyntax#}</pre> |
| 1915 | 1782 | </td> |
| 1916 | 1783 | </tr> |
| 1917 | 1784 | <tr> |
| 1918 | | <th scope="row"><pre>{#syntax#}a <<| b |
| 1919 | | a <<|= b{#endsyntax#}</pre></th> |
| 1785 | <td>Saturating Bit Shift Left</td> |
| 1786 | <td><pre>{#syntax#}a <<| b |
| 1787 | a <<|= b{#endsyntax#}</pre></td> |
| 1920 | 1788 | <td> |
| 1921 | 1789 | <ul> |
| 1922 | 1790 | <li>{#link|Integers#}</li> |
| 1923 | 1791 | </ul> |
| 1924 | 1792 | </td> |
| 1925 | | <td>Saturating Bit Shift Left. |
| 1793 | <td> |
| 1926 | 1794 | <ul> |
| 1927 | 1795 | <li>See also {#link|@shlExact#}.</li> |
| 1928 | 1796 | <li>See also {#link|@shlWithOverflow#}.</li> |
| ... | ... | @@ -1933,32 +1801,37 @@ a <<|= b{#endsyntax#}</pre></th> |
| 1933 | 1801 | </td> |
| 1934 | 1802 | </tr> |
| 1935 | 1803 | <tr> |
| 1936 | | <th scope="row"><pre>{#syntax#}a >> b |
| 1937 | | a >>= b{#endsyntax#}</pre></th> |
| 1804 | <td>Bit Shift Right</td> |
| 1805 | <td><pre>{#syntax#}a >> b |
| 1806 | a >>= b{#endsyntax#}</pre></td> |
| 1938 | 1807 | <td> |
| 1939 | 1808 | <ul> |
| 1940 | 1809 | <li>{#link|Integers#}</li> |
| 1941 | 1810 | </ul> |
| 1942 | 1811 | </td> |
| 1943 | | <td>Bit Shift Right. |
| 1812 | <td> |
| 1944 | 1813 | <ul> |
| 1945 | | <li>{#syntax#}b{#endsyntax#} must be {#link|comptime-known|comptime#} or have a type with log2 number of bits as {#syntax#}a{#endsyntax#}.</li> |
| 1814 | <li>Moves all bits to the right, inserting zeroes at the most-significant bit.</li> |
| 1815 | <li>{#syntax#}b{#endsyntax#} must be |
| 1816 | {#link|comptime-known|comptime#} or have a type with log2 number |
| 1817 | of bits as {#syntax#}a{#endsyntax#}.</li> |
| 1946 | 1818 | <li>See also {#link|@shrExact#}.</li> |
| 1947 | 1819 | </ul> |
| 1948 | 1820 | </td> |
| 1949 | 1821 | <td> |
| 1950 | | <pre>{#syntax#}10 >> 1 == 5{#endsyntax#}</pre> |
| 1822 | <pre>{#syntax#}0b1010 >> 1 == 0b101{#endsyntax#}</pre> |
| 1951 | 1823 | </td> |
| 1952 | 1824 | </tr> |
| 1953 | 1825 | <tr> |
| 1954 | | <th scope="row"><pre>{#syntax#}a & b |
| 1955 | | a &= b{#endsyntax#}</pre></th> |
| 1826 | <td>Bitwise And</td> |
| 1827 | <td><pre>{#syntax#}a & b |
| 1828 | a &= b{#endsyntax#}</pre></td> |
| 1956 | 1829 | <td> |
| 1957 | 1830 | <ul> |
| 1958 | 1831 | <li>{#link|Integers#}</li> |
| 1959 | 1832 | </ul> |
| 1960 | 1833 | </td> |
| 1961 | | <td>Bitwise AND. |
| 1834 | <td> |
| 1962 | 1835 | <ul> |
| 1963 | 1836 | <li>Invokes {#link|Peer Type Resolution#} for the operands.</li> |
| 1964 | 1837 | </ul> |
| ... | ... | @@ -1968,14 +1841,15 @@ a &= b{#endsyntax#}</pre></th> |
| 1968 | 1841 | </td> |
| 1969 | 1842 | </tr> |
| 1970 | 1843 | <tr> |
| 1971 | | <th scope="row"><pre>{#syntax#}a | b |
| 1972 | | a |= b{#endsyntax#}</pre></th> |
| 1844 | <td>Bitwise Or</td> |
| 1845 | <td><pre>{#syntax#}a | b |
| 1846 | a |= b{#endsyntax#}</pre></td> |
| 1973 | 1847 | <td> |
| 1974 | 1848 | <ul> |
| 1975 | 1849 | <li>{#link|Integers#}</li> |
| 1976 | 1850 | </ul> |
| 1977 | 1851 | </td> |
| 1978 | | <td>Bitwise OR. |
| 1852 | <td> |
| 1979 | 1853 | <ul> |
| 1980 | 1854 | <li>Invokes {#link|Peer Type Resolution#} for the operands.</li> |
| 1981 | 1855 | </ul> |
| ... | ... | @@ -1985,14 +1859,15 @@ a |= b{#endsyntax#}</pre></th> |
| 1985 | 1859 | </td> |
| 1986 | 1860 | </tr> |
| 1987 | 1861 | <tr> |
| 1988 | | <th scope="row"><pre>{#syntax#}a ^ b |
| 1989 | | a ^= b{#endsyntax#}</pre></th> |
| 1862 | <td>Bitwise Xor</td> |
| 1863 | <td><pre>{#syntax#}a ^ b |
| 1864 | a ^= b{#endsyntax#}</pre></td> |
| 1990 | 1865 | <td> |
| 1991 | 1866 | <ul> |
| 1992 | 1867 | <li>{#link|Integers#}</li> |
| 1993 | 1868 | </ul> |
| 1994 | 1869 | </td> |
| 1995 | | <td>Bitwise XOR. |
| 1870 | <td> |
| 1996 | 1871 | <ul> |
| 1997 | 1872 | <li>Invokes {#link|Peer Type Resolution#} for the operands.</li> |
| 1998 | 1873 | </ul> |
| ... | ... | @@ -2002,30 +1877,30 @@ a ^= b{#endsyntax#}</pre></th> |
| 2002 | 1877 | </td> |
| 2003 | 1878 | </tr> |
| 2004 | 1879 | <tr> |
| 2005 | | <th scope="row"><pre>{#syntax#}~a{#endsyntax#}</pre></th> |
| 1880 | <td>Bitwise Not</td> |
| 1881 | <td><pre>{#syntax#}~a{#endsyntax#}</pre></td> |
| 2006 | 1882 | <td> |
| 2007 | 1883 | <ul> |
| 2008 | 1884 | <li>{#link|Integers#}</li> |
| 2009 | 1885 | </ul> |
| 2010 | 1886 | </td> |
| 2011 | | <td> |
| 2012 | | Bitwise NOT. |
| 2013 | | </td> |
| 1887 | <td></td> |
| 2014 | 1888 | <td> |
| 2015 | 1889 | <pre>{#syntax#}~@as(u8, 0b10101111) == 0b01010000{#endsyntax#}</pre> |
| 2016 | 1890 | </td> |
| 2017 | 1891 | </tr> |
| 2018 | 1892 | <tr> |
| 2019 | | <th scope="row"><pre>{#syntax#}a orelse b{#endsyntax#}</pre></th> |
| 1893 | <td>Defaulting Optional Unwrap</td> |
| 1894 | <td><pre>{#syntax#}a orelse b{#endsyntax#}</pre></td> |
| 2020 | 1895 | <td> |
| 2021 | 1896 | <ul> |
| 2022 | 1897 | <li>{#link|Optionals#}</li> |
| 2023 | 1898 | </ul> |
| 2024 | 1899 | </td> |
| 2025 | 1900 | <td>If {#syntax#}a{#endsyntax#} is {#syntax#}null{#endsyntax#}, |
| 2026 | | returns {#syntax#}b{#endsyntax#} ("default value"), |
| 2027 | | otherwise returns the unwrapped value of {#syntax#}a{#endsyntax#}. |
| 2028 | | Note that {#syntax#}b{#endsyntax#} may be a value of type {#link|noreturn#}. |
| 1901 | returns {#syntax#}b{#endsyntax#} ("default value"), |
| 1902 | otherwise returns the unwrapped value of {#syntax#}a{#endsyntax#}. |
| 1903 | Note that {#syntax#}b{#endsyntax#} may be a value of type {#link|noreturn#}. |
| 2029 | 1904 | </td> |
| 2030 | 1905 | <td> |
| 2031 | 1906 | <pre>{#syntax#}const value: ?u32 = null; |
| ... | ... | @@ -2034,7 +1909,8 @@ unwrapped == 1234{#endsyntax#}</pre> |
| 2034 | 1909 | </td> |
| 2035 | 1910 | </tr> |
| 2036 | 1911 | <tr> |
| 2037 | | <th scope="row"><pre>{#syntax#}a.?{#endsyntax#}</pre></th> |
| 1912 | <td>Optional Unwrap</td> |
| 1913 | <td><pre>{#syntax#}a.?{#endsyntax#}</pre></td> |
| 2038 | 1914 | <td> |
| 2039 | 1915 | <ul> |
| 2040 | 1916 | <li>{#link|Optionals#}</li> |
| ... | ... | @@ -2050,18 +1926,19 @@ value.? == 5678{#endsyntax#}</pre> |
| 2050 | 1926 | </td> |
| 2051 | 1927 | </tr> |
| 2052 | 1928 | <tr> |
| 2053 | | <th scope="row"><pre>{#syntax#}a catch b |
| 2054 | | a catch |err| b{#endsyntax#}</pre></th> |
| 1929 | <td>Defaulting Error Unwrap</td> |
| 1930 | <td><pre>{#syntax#}a catch b |
| 1931 | a catch |err| b{#endsyntax#}</pre></td> |
| 2055 | 1932 | <td> |
| 2056 | 1933 | <ul> |
| 2057 | 1934 | <li>{#link|Error Unions|Errors#}</li> |
| 2058 | 1935 | </ul> |
| 2059 | 1936 | </td> |
| 2060 | 1937 | <td>If {#syntax#}a{#endsyntax#} is an {#syntax#}error{#endsyntax#}, |
| 2061 | | returns {#syntax#}b{#endsyntax#} ("default value"), |
| 2062 | | otherwise returns the unwrapped value of {#syntax#}a{#endsyntax#}. |
| 2063 | | Note that {#syntax#}b{#endsyntax#} may be a value of type {#link|noreturn#}. |
| 2064 | | {#syntax#}err{#endsyntax#} is the {#syntax#}error{#endsyntax#} and is in scope of the expression {#syntax#}b{#endsyntax#}. |
| 1938 | returns {#syntax#}b{#endsyntax#} ("default value"), |
| 1939 | otherwise returns the unwrapped value of {#syntax#}a{#endsyntax#}. |
| 1940 | Note that {#syntax#}b{#endsyntax#} may be a value of type {#link|noreturn#}. |
| 1941 | {#syntax#}err{#endsyntax#} is the {#syntax#}error{#endsyntax#} and is in scope of the expression {#syntax#}b{#endsyntax#}. |
| 2065 | 1942 | </td> |
| 2066 | 1943 | <td> |
| 2067 | 1944 | <pre>{#syntax#}const value: anyerror!u32 = error.Broken; |
| ... | ... | @@ -2070,51 +1947,55 @@ unwrapped == 1234{#endsyntax#}</pre> |
| 2070 | 1947 | </td> |
| 2071 | 1948 | </tr> |
| 2072 | 1949 | <tr> |
| 2073 | | <th scope="row"><pre>{#syntax#}a and b{#endsyntax#}</pre></th> |
| 1950 | <td>Logical And</td> |
| 1951 | <td><pre>{#syntax#}a and b{#endsyntax#}</pre></td> |
| 2074 | 1952 | <td> |
| 2075 | 1953 | <ul> |
| 2076 | 1954 | <li>{#link|bool|Primitive Types#}</li> |
| 2077 | 1955 | </ul> |
| 2078 | 1956 | </td> |
| 2079 | 1957 | <td> |
| 2080 | | If {#syntax#}a{#endsyntax#} is {#syntax#}false{#endsyntax#}, returns {#syntax#}false{#endsyntax#} |
| 2081 | | without evaluating {#syntax#}b{#endsyntax#}. Otherwise, returns {#syntax#}b{#endsyntax#}. |
| 1958 | If {#syntax#}a{#endsyntax#} is {#syntax#}false{#endsyntax#}, returns {#syntax#}false{#endsyntax#} |
| 1959 | without evaluating {#syntax#}b{#endsyntax#}. Otherwise, returns {#syntax#}b{#endsyntax#}. |
| 2082 | 1960 | </td> |
| 2083 | 1961 | <td> |
| 2084 | 1962 | <pre>{#syntax#}(false and true) == false{#endsyntax#}</pre> |
| 2085 | 1963 | </td> |
| 2086 | 1964 | </tr> |
| 2087 | 1965 | <tr> |
| 2088 | | <th scope="row"><pre>{#syntax#}a or b{#endsyntax#}</pre></th> |
| 1966 | <td>Logical Or</td> |
| 1967 | <td><pre>{#syntax#}a or b{#endsyntax#}</pre></td> |
| 2089 | 1968 | <td> |
| 2090 | 1969 | <ul> |
| 2091 | 1970 | <li>{#link|bool|Primitive Types#}</li> |
| 2092 | 1971 | </ul> |
| 2093 | 1972 | </td> |
| 2094 | 1973 | <td> |
| 2095 | | If {#syntax#}a{#endsyntax#} is {#syntax#}true{#endsyntax#}, returns {#syntax#}true{#endsyntax#} |
| 2096 | | without evaluating {#syntax#}b{#endsyntax#}. Otherwise, returns {#syntax#}b{#endsyntax#}. |
| 1974 | If {#syntax#}a{#endsyntax#} is {#syntax#}true{#endsyntax#}, |
| 1975 | returns {#syntax#}true{#endsyntax#} without evaluating |
| 1976 | {#syntax#}b{#endsyntax#}. Otherwise, returns |
| 1977 | {#syntax#}b{#endsyntax#}. |
| 2097 | 1978 | </td> |
| 2098 | 1979 | <td> |
| 2099 | 1980 | <pre>{#syntax#}(false or true) == true{#endsyntax#}</pre> |
| 2100 | 1981 | </td> |
| 2101 | 1982 | </tr> |
| 2102 | 1983 | <tr> |
| 2103 | | <th scope="row"><pre>{#syntax#}!a{#endsyntax#}</pre></th> |
| 1984 | <td>Boolean Not</td> |
| 1985 | <td><pre>{#syntax#}!a{#endsyntax#}</pre></td> |
| 2104 | 1986 | <td> |
| 2105 | 1987 | <ul> |
| 2106 | 1988 | <li>{#link|bool|Primitive Types#}</li> |
| 2107 | 1989 | </ul> |
| 2108 | 1990 | </td> |
| 2109 | | <td> |
| 2110 | | Boolean NOT. |
| 2111 | | </td> |
| 1991 | <td></td> |
| 2112 | 1992 | <td> |
| 2113 | 1993 | <pre>{#syntax#}!false == true{#endsyntax#}</pre> |
| 2114 | 1994 | </td> |
| 2115 | 1995 | </tr> |
| 2116 | 1996 | <tr> |
| 2117 | | <th scope="row"><pre>{#syntax#}a == b{#endsyntax#}</pre></th> |
| 1997 | <td>Equality</td> |
| 1998 | <td><pre>{#syntax#}a == b{#endsyntax#}</pre></td> |
| 2118 | 1999 | <td> |
| 2119 | 2000 | <ul> |
| 2120 | 2001 | <li>{#link|Integers#}</li> |
| ... | ... | @@ -2132,7 +2013,8 @@ unwrapped == 1234{#endsyntax#}</pre> |
| 2132 | 2013 | </td> |
| 2133 | 2014 | </tr> |
| 2134 | 2015 | <tr> |
| 2135 | | <th scope="row"><pre>{#syntax#}a == null{#endsyntax#}</pre></th> |
| 2016 | <td>Null Check</td> |
| 2017 | <td><pre>{#syntax#}a == null{#endsyntax#}</pre></td> |
| 2136 | 2018 | <td> |
| 2137 | 2019 | <ul> |
| 2138 | 2020 | <li>{#link|Optionals#}</li> |
| ... | ... | @@ -2147,7 +2029,8 @@ unwrapped == 1234{#endsyntax#}</pre> |
| 2147 | 2029 | </td> |
| 2148 | 2030 | </tr> |
| 2149 | 2031 | <tr> |
| 2150 | | <th scope="row"><pre>{#syntax#}a != b{#endsyntax#}</pre></th> |
| 2032 | <td>Inequality</td> |
| 2033 | <td><pre>{#syntax#}a != b{#endsyntax#}</pre></td> |
| 2151 | 2034 | <td> |
| 2152 | 2035 | <ul> |
| 2153 | 2036 | <li>{#link|Integers#}</li> |
| ... | ... | @@ -2165,7 +2048,8 @@ unwrapped == 1234{#endsyntax#}</pre> |
| 2165 | 2048 | </td> |
| 2166 | 2049 | </tr> |
| 2167 | 2050 | <tr> |
| 2168 | | <th scope="row"><pre>{#syntax#}a != null{#endsyntax#}</pre></th> |
| 2051 | <td>Non-Null Check</td> |
| 2052 | <td><pre>{#syntax#}a != null{#endsyntax#}</pre></td> |
| 2169 | 2053 | <td> |
| 2170 | 2054 | <ul> |
| 2171 | 2055 | <li>{#link|Optionals#}</li> |
| ... | ... | @@ -2180,7 +2064,8 @@ unwrapped == 1234{#endsyntax#}</pre> |
| 2180 | 2064 | </td> |
| 2181 | 2065 | </tr> |
| 2182 | 2066 | <tr> |
| 2183 | | <th scope="row"><pre>{#syntax#}a > b{#endsyntax#}</pre></th> |
| 2067 | <td>Greater Than</td> |
| 2068 | <td><pre>{#syntax#}a > b{#endsyntax#}</pre></td> |
| 2184 | 2069 | <td> |
| 2185 | 2070 | <ul> |
| 2186 | 2071 | <li>{#link|Integers#}</li> |
| ... | ... | @@ -2196,7 +2081,8 @@ unwrapped == 1234{#endsyntax#}</pre> |
| 2196 | 2081 | </td> |
| 2197 | 2082 | </tr> |
| 2198 | 2083 | <tr> |
| 2199 | | <th scope="row"><pre>{#syntax#}a >= b{#endsyntax#}</pre></th> |
| 2084 | <td>Greater or Equal</td> |
| 2085 | <td><pre>{#syntax#}a >= b{#endsyntax#}</pre></td> |
| 2200 | 2086 | <td> |
| 2201 | 2087 | <ul> |
| 2202 | 2088 | <li>{#link|Integers#}</li> |
| ... | ... | @@ -2212,7 +2098,8 @@ unwrapped == 1234{#endsyntax#}</pre> |
| 2212 | 2098 | </td> |
| 2213 | 2099 | </tr> |
| 2214 | 2100 | <tr> |
| 2215 | | <th scope="row"><pre>{#syntax#}a < b{#endsyntax#}</pre></th> |
| 2101 | <td>Less Than</td> |
| 2102 | <td><pre>{#syntax#}a < b{#endsyntax#}</pre></td> |
| 2216 | 2103 | <td> |
| 2217 | 2104 | <ul> |
| 2218 | 2105 | <li>{#link|Integers#}</li> |
| ... | ... | @@ -2228,7 +2115,8 @@ unwrapped == 1234{#endsyntax#}</pre> |
| 2228 | 2115 | </td> |
| 2229 | 2116 | </tr> |
| 2230 | 2117 | <tr> |
| 2231 | | <th scope="row"><pre>{#syntax#}a <= b{#endsyntax#}</pre></th> |
| 2118 | <td>Lesser or Equal</td> |
| 2119 | <td><pre>{#syntax#}a <= b{#endsyntax#}</pre></td> |
| 2232 | 2120 | <td> |
| 2233 | 2121 | <ul> |
| 2234 | 2122 | <li>{#link|Integers#}</li> |
| ... | ... | @@ -2244,14 +2132,14 @@ unwrapped == 1234{#endsyntax#}</pre> |
| 2244 | 2132 | </td> |
| 2245 | 2133 | </tr> |
| 2246 | 2134 | <tr> |
| 2247 | | <th scope="row"><pre>{#syntax#}a ++ b{#endsyntax#}</pre></th> |
| 2135 | <td>Array Concatenation</td> |
| 2136 | <td><pre>{#syntax#}a ++ b{#endsyntax#}</pre></td> |
| 2248 | 2137 | <td> |
| 2249 | 2138 | <ul> |
| 2250 | 2139 | <li>{#link|Arrays#}</li> |
| 2251 | 2140 | </ul> |
| 2252 | 2141 | </td> |
| 2253 | 2142 | <td> |
| 2254 | | Array concatenation. |
| 2255 | 2143 | <ul> |
| 2256 | 2144 | <li>Only available when the lengths of both {#syntax#}a{#endsyntax#} and {#syntax#}b{#endsyntax#} are {#link|compile-time known|comptime#}.</li> |
| 2257 | 2145 | </ul> |
| ... | ... | @@ -2265,14 +2153,14 @@ mem.eql(u32, &together, &[_]u32{1,2,3,4}){#endsyntax#}</pre> |
| 2265 | 2153 | </td> |
| 2266 | 2154 | </tr> |
| 2267 | 2155 | <tr> |
| 2268 | | <th scope="row"><pre>{#syntax#}a ** b{#endsyntax#}</pre></th> |
| 2156 | <td>Array Multiplication</td> |
| 2157 | <td><pre>{#syntax#}a ** b{#endsyntax#}</pre></td> |
| 2269 | 2158 | <td> |
| 2270 | 2159 | <ul> |
| 2271 | 2160 | <li>{#link|Arrays#}</li> |
| 2272 | 2161 | </ul> |
| 2273 | 2162 | </td> |
| 2274 | 2163 | <td> |
| 2275 | | Array multiplication. |
| 2276 | 2164 | <ul> |
| 2277 | 2165 | <li>Only available when the length of {#syntax#}a{#endsyntax#} and {#syntax#}b{#endsyntax#} are {#link|compile-time known|comptime#}.</li> |
| 2278 | 2166 | </ul> |
| ... | ... | @@ -2284,7 +2172,8 @@ mem.eql(u8, pattern, "ababab"){#endsyntax#}</pre> |
| 2284 | 2172 | </td> |
| 2285 | 2173 | </tr> |
| 2286 | 2174 | <tr> |
| 2287 | | <th scope="row"><pre>{#syntax#}a.*{#endsyntax#}</pre></th> |
| 2175 | <td>Pointer Dereference</td> |
| 2176 | <td><pre>{#syntax#}a.*{#endsyntax#}</pre></td> |
| 2288 | 2177 | <td> |
| 2289 | 2178 | <ul> |
| 2290 | 2179 | <li>{#link|Pointers#}</li> |
| ... | ... | @@ -2300,12 +2189,12 @@ ptr.* == 1234{#endsyntax#}</pre> |
| 2300 | 2189 | </td> |
| 2301 | 2190 | </tr> |
| 2302 | 2191 | <tr> |
| 2303 | | <th scope="row"><pre>{#syntax#}&a{#endsyntax#}</pre></th> |
| 2192 | <td>Address Of</td> |
| 2193 | <td><pre>{#syntax#}&a{#endsyntax#}</pre></td> |
| 2304 | 2194 | <td> |
| 2305 | 2195 | All types |
| 2306 | 2196 | </td> |
| 2307 | 2197 | <td> |
| 2308 | | Address of. |
| 2309 | 2198 | </td> |
| 2310 | 2199 | <td> |
| 2311 | 2200 | <pre>{#syntax#}const x: u32 = 1234; |
| ... | ... | @@ -2314,7 +2203,8 @@ ptr.* == 1234{#endsyntax#}</pre> |
| 2314 | 2203 | </td> |
| 2315 | 2204 | </tr> |
| 2316 | 2205 | <tr> |
| 2317 | | <th scope="row"><pre>{#syntax#}a || b{#endsyntax#}</pre></th> |
| 2206 | <td>Error Set Merge</td> |
| 2207 | <td><pre>{#syntax#}a || b{#endsyntax#}</pre></td> |
| 2318 | 2208 | <td> |
| 2319 | 2209 | <ul> |
| 2320 | 2210 | <li>{#link|Error Set Type#}</li> |
| ... | ... | @@ -4311,10 +4201,11 @@ test "enum literals with switch" { |
| 4311 | 4201 | {#code_end#} |
| 4312 | 4202 | {#header_close#} |
| 4313 | 4203 | |
| 4314 | | {#header_open|Inline switch#} |
| 4204 | {#header_open|Inline Switch Prongs#} |
| 4315 | 4205 | <p> |
| 4316 | 4206 | Switch prongs can be marked as {#syntax#}inline{#endsyntax#} to generate |
| 4317 | | the prong's body for each possible value it could have: |
| 4207 | the prong's body for each possible value it could have, making the |
| 4208 | captured value {#link|comptime#}. |
| 4318 | 4209 | </p> |
| 4319 | 4210 | {#code_begin|test|test_inline_switch#} |
| 4320 | 4211 | const std = @import("std"); |
| ... | ... | @@ -4324,9 +4215,9 @@ const expectError = std.testing.expectError; |
| 4324 | 4215 | fn isFieldOptional(comptime T: type, field_index: usize) !bool { |
| 4325 | 4216 | const fields = @typeInfo(T).Struct.fields; |
| 4326 | 4217 | return switch (field_index) { |
| 4327 | | // This prong is analyzed `fields.len - 1` times with `idx` being a |
| 4328 | | // unique comptime-known value each time. |
| 4329 | | inline 0...fields.len - 1 => |idx| @typeInfo(fields[idx].type) == .Optional, |
| 4218 | // This prong is analyzed twice with `idx` being a |
| 4219 | // comptime-known value each time. |
| 4220 | inline 0, 1 => |idx| @typeInfo(fields[idx].type) == .Optional, |
| 4330 | 4221 | else => return error.IndexOutOfBounds, |
| 4331 | 4222 | }; |
| 4332 | 4223 | } |
| ... | ... | @@ -4350,6 +4241,16 @@ fn isFieldOptionalUnrolled(field_index: usize) !bool { |
| 4350 | 4241 | 1 => true, |
| 4351 | 4242 | else => return error.IndexOutOfBounds, |
| 4352 | 4243 | }; |
| 4244 | } |
| 4245 | {#code_end#} |
| 4246 | <p>The {#syntax#}inline{#endsyntax#} keyword may also be combined with ranges:</p> |
| 4247 | {#code_begin|syntax|inline_prong_range#} |
| 4248 | fn isFieldOptional(comptime T: type, field_index: usize) !bool { |
| 4249 | const fields = @typeInfo(T).Struct.fields; |
| 4250 | return switch (field_index) { |
| 4251 | inline 0...fields.len - 1 => |idx| @typeInfo(fields[idx].type) == .Optional, |
| 4252 | else => return error.IndexOutOfBounds, |
| 4253 | }; |
| 4353 | 4254 | } |
| 4354 | 4255 | {#code_end#} |
| 4355 | 4256 | <p> |
| ... | ... | @@ -7853,7 +7754,7 @@ comptime { |
| 7853 | 7754 | {#header_close#} |
| 7854 | 7755 | |
| 7855 | 7756 | {#header_open|@atomicLoad#} |
| 7856 | | <pre>{#syntax#}@atomicLoad(comptime T: type, ptr: *const T, comptime ordering: builtin.AtomicOrder) T{#endsyntax#}</pre> |
| 7757 | <pre>{#syntax#}@atomicLoad(comptime T: type, ptr: *const T, comptime ordering: AtomicOrder) T{#endsyntax#}</pre> |
| 7857 | 7758 | <p> |
| 7858 | 7759 | This builtin function atomically dereferences a pointer to a {#syntax#}T{#endsyntax#} and returns the value. |
| 7859 | 7760 | </p> |
| ... | ... | @@ -7861,11 +7762,12 @@ comptime { |
| 7861 | 7762 | {#syntax#}T{#endsyntax#} must be a pointer, a {#syntax#}bool{#endsyntax#}, a float, |
| 7862 | 7763 | an integer or an enum. |
| 7863 | 7764 | </p> |
| 7765 | <p>{#syntax#}AtomicOrder{#endsyntax#} can be found with {#syntax#}@import("std").builtin.AtomicOrder{#endsyntax#}.</p> |
| 7864 | 7766 | {#see_also|@atomicStore|@atomicRmw|@fence|@cmpxchgWeak|@cmpxchgStrong#} |
| 7865 | 7767 | {#header_close#} |
| 7866 | 7768 | |
| 7867 | 7769 | {#header_open|@atomicRmw#} |
| 7868 | | <pre>{#syntax#}@atomicRmw(comptime T: type, ptr: *T, comptime op: builtin.AtomicRmwOp, operand: T, comptime ordering: builtin.AtomicOrder) T{#endsyntax#}</pre> |
| 7770 | <pre>{#syntax#}@atomicRmw(comptime T: type, ptr: *T, comptime op: AtomicRmwOp, operand: T, comptime ordering: AtomicOrder) T{#endsyntax#}</pre> |
| 7869 | 7771 | <p> |
| 7870 | 7772 | This builtin function dereferences a pointer to a {#syntax#}T{#endsyntax#} and atomically |
| 7871 | 7773 | modifies the value and returns the previous value. |
| ... | ... | @@ -7874,27 +7776,13 @@ comptime { |
| 7874 | 7776 | {#syntax#}T{#endsyntax#} must be a pointer, a {#syntax#}bool{#endsyntax#}, a float, |
| 7875 | 7777 | an integer or an enum. |
| 7876 | 7778 | </p> |
| 7877 | | <p> |
| 7878 | | Supported values for the {#syntax#}op{#endsyntax#} parameter: |
| 7879 | | </p> |
| 7880 | | <ul> |
| 7881 | | <li>{#syntax#}.Xchg{#endsyntax#} - stores the operand unmodified. Supports enums, integers and floats.</li> |
| 7882 | | <li>{#syntax#}.Add{#endsyntax#} - for integers, twos complement wraparound addition. |
| 7883 | | Also supports {#link|Floats#}.</li> |
| 7884 | | <li>{#syntax#}.Sub{#endsyntax#} - for integers, twos complement wraparound subtraction. |
| 7885 | | Also supports {#link|Floats#}.</li> |
| 7886 | | <li>{#syntax#}.And{#endsyntax#} - bitwise and</li> |
| 7887 | | <li>{#syntax#}.Nand{#endsyntax#} - bitwise nand</li> |
| 7888 | | <li>{#syntax#}.Or{#endsyntax#} - bitwise or</li> |
| 7889 | | <li>{#syntax#}.Xor{#endsyntax#} - bitwise xor</li> |
| 7890 | | <li>{#syntax#}.Max{#endsyntax#} - stores the operand if it is larger. Supports integers and floats.</li> |
| 7891 | | <li>{#syntax#}.Min{#endsyntax#} - stores the operand if it is smaller. Supports integers and floats.</li> |
| 7892 | | </ul> |
| 7779 | <p>{#syntax#}AtomicOrder{#endsyntax#} can be found with {#syntax#}@import("std").builtin.AtomicOrder{#endsyntax#}.</p> |
| 7780 | <p>{#syntax#}AtomicRmwOp{#endsyntax#} can be found with {#syntax#}@import("std").builtin.AtomicRmwOp{#endsyntax#}.</p> |
| 7893 | 7781 | {#see_also|@atomicStore|@atomicLoad|@fence|@cmpxchgWeak|@cmpxchgStrong#} |
| 7894 | 7782 | {#header_close#} |
| 7895 | 7783 | |
| 7896 | 7784 | {#header_open|@atomicStore#} |
| 7897 | | <pre>{#syntax#}@atomicStore(comptime T: type, ptr: *T, value: T, comptime ordering: builtin.AtomicOrder) void{#endsyntax#}</pre> |
| 7785 | <pre>{#syntax#}@atomicStore(comptime T: type, ptr: *T, value: T, comptime ordering: AtomicOrder) void{#endsyntax#}</pre> |
| 7898 | 7786 | <p> |
| 7899 | 7787 | This builtin function dereferences a pointer to a {#syntax#}T{#endsyntax#} and atomically stores the given value. |
| 7900 | 7788 | </p> |
| ... | ... | @@ -7902,6 +7790,7 @@ comptime { |
| 7902 | 7790 | {#syntax#}T{#endsyntax#} must be a pointer, a {#syntax#}bool{#endsyntax#}, a float, |
| 7903 | 7791 | an integer or an enum. |
| 7904 | 7792 | </p> |
| 7793 | <p>{#syntax#}AtomicOrder{#endsyntax#} can be found with {#syntax#}@import("std").builtin.AtomicOrder{#endsyntax#}.</p> |
| 7905 | 7794 | {#see_also|@atomicLoad|@atomicRmw|@fence|@cmpxchgWeak|@cmpxchgStrong#} |
| 7906 | 7795 | {#header_close#} |
| 7907 | 7796 | |
| ... | ... | @@ -8178,6 +8067,7 @@ fn cmpxchgStrongButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_v |
| 8178 | 8067 | an integer or an enum. |
| 8179 | 8068 | </p> |
| 8180 | 8069 | <p>{#syntax#}@typeInfo(@TypeOf(ptr)).Pointer.alignment{#endsyntax#} must be {#syntax#}>= @sizeOf(T).{#endsyntax#}</p> |
| 8070 | <p>{#syntax#}AtomicOrder{#endsyntax#} can be found with {#syntax#}@import("std").builtin.AtomicOrder{#endsyntax#}.</p> |
| 8181 | 8071 | {#see_also|@atomicStore|@atomicLoad|@atomicRmw|@fence|@cmpxchgWeak#} |
| 8182 | 8072 | {#header_close#} |
| 8183 | 8073 | |
| ... | ... | @@ -8209,6 +8099,7 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val |
| 8209 | 8099 | an integer or an enum. |
| 8210 | 8100 | </p> |
| 8211 | 8101 | <p>{#syntax#}@typeInfo(@TypeOf(ptr)).Pointer.alignment{#endsyntax#} must be {#syntax#}>= @sizeOf(T).{#endsyntax#}</p> |
| 8102 | <p>{#syntax#}AtomicOrder{#endsyntax#} can be found with {#syntax#}@import("std").builtin.AtomicOrder{#endsyntax#}.</p> |
| 8212 | 8103 | {#see_also|@atomicStore|@atomicLoad|@atomicRmw|@fence|@cmpxchgStrong#} |
| 8213 | 8104 | {#header_close#} |
| 8214 | 8105 | |
| ... | ... | @@ -8499,9 +8390,7 @@ export fn @"A function name that is a complete sentence."() void {} |
| 8499 | 8390 | <p> |
| 8500 | 8391 | The {#syntax#}fence{#endsyntax#} function is used to introduce happens-before edges between operations. |
| 8501 | 8392 | </p> |
| 8502 | | <p> |
| 8503 | | {#syntax#}AtomicOrder{#endsyntax#} can be found with {#syntax#}@import("std").builtin.AtomicOrder{#endsyntax#}. |
| 8504 | | </p> |
| 8393 | <p>{#syntax#}AtomicOrder{#endsyntax#} can be found with {#syntax#}@import("std").builtin.AtomicOrder{#endsyntax#}.</p> |
| 8505 | 8394 | {#see_also|@atomicStore|@atomicLoad|@atomicRmw|@cmpxchgWeak|@cmpxchgStrong#} |
| 8506 | 8395 | {#header_close#} |
| 8507 | 8396 | |
| ... | ... | @@ -8909,7 +8798,7 @@ test "@wasmMemoryGrow" { |
| 8909 | 8798 | {#header_close#} |
| 8910 | 8799 | |
| 8911 | 8800 | {#header_open|@prefetch#} |
| 8912 | | <pre>{#syntax#}@prefetch(ptr: anytype, comptime options: std.builtin.PrefetchOptions) void{#endsyntax#}</pre> |
| 8801 | <pre>{#syntax#}@prefetch(ptr: anytype, comptime options: PrefetchOptions) void{#endsyntax#}</pre> |
| 8913 | 8802 | <p> |
| 8914 | 8803 | This builtin tells the compiler to emit a prefetch instruction if supported by the |
| 8915 | 8804 | target CPU. If the target CPU does not support the requested prefetch instruction, |
| ... | ... | @@ -8921,37 +8810,7 @@ test "@wasmMemoryGrow" { |
| 8921 | 8810 | address to prefetch. This function does not dereference the pointer, it is perfectly legal |
| 8922 | 8811 | to pass a pointer to invalid memory to this function and no illegal behavior will result. |
| 8923 | 8812 | </p> |
| 8924 | | <p> |
| 8925 | | The {#syntax#}options{#endsyntax#} argument is the following struct: |
| 8926 | | </p> |
| 8927 | | {#code_begin|syntax|builtin#} |
| 8928 | | /// This data structure is used by the Zig language code generation and |
| 8929 | | /// therefore must be kept in sync with the compiler implementation. |
| 8930 | | pub const PrefetchOptions = struct { |
| 8931 | | /// Whether the prefetch should prepare for a read or a write. |
| 8932 | | rw: Rw = .read, |
| 8933 | | /// The data's locality in an inclusive range from 0 to 3. |
| 8934 | | /// |
| 8935 | | /// 0 means no temporal locality. That is, the data can be immediately |
| 8936 | | /// dropped from the cache after it is accessed. |
| 8937 | | /// |
| 8938 | | /// 3 means high temporal locality. That is, the data should be kept in |
| 8939 | | /// the cache as it is likely to be accessed again soon. |
| 8940 | | locality: u2 = 3, |
| 8941 | | /// The cache that the prefetch should be preformed on. |
| 8942 | | cache: Cache = .data, |
| 8943 | | |
| 8944 | | pub const Rw = enum(u1) { |
| 8945 | | read, |
| 8946 | | write, |
| 8947 | | }; |
| 8948 | | |
| 8949 | | pub const Cache = enum(u1) { |
| 8950 | | instruction, |
| 8951 | | data, |
| 8952 | | }; |
| 8953 | | }; |
| 8954 | | {#code_end#} |
| 8813 | <p>{#syntax#}PrefetchOptions{#endsyntax#} can be found with {#syntax#}@import("std").builtin.PrefetchOptions{#endsyntax#}.</p> |
| 8955 | 8814 | {#header_close#} |
| 8956 | 8815 | |
| 8957 | 8816 | {#header_open|@ptrCast#} |
| ... | ... | @@ -9080,16 +8939,8 @@ test "foo" { |
| 9080 | 8939 | {#header_close#} |
| 9081 | 8940 | |
| 9082 | 8941 | {#header_open|@setFloatMode#} |
| 9083 | | <pre>{#syntax#}@setFloatMode(comptime mode: @import("std").builtin.FloatMode) void{#endsyntax#}</pre> |
| 9084 | | <p> |
| 9085 | | Sets the floating point mode of the current scope. Possible values are: |
| 9086 | | </p> |
| 9087 | | {#code_begin|syntax|FloatMode#} |
| 9088 | | pub const FloatMode = enum { |
| 9089 | | Strict, |
| 9090 | | Optimized, |
| 9091 | | }; |
| 9092 | | {#code_end#} |
| 8942 | <pre>{#syntax#}@setFloatMode(comptime mode: FloatMode) void{#endsyntax#}</pre> |
| 8943 | <p>Changes the current scope's rules about how floating point operations are defined.</p> |
| 9093 | 8944 | <ul> |
| 9094 | 8945 | <li> |
| 9095 | 8946 | {#syntax#}Strict{#endsyntax#} (default) - Floating point operations follow strict IEEE compliance. |
| ... | ... | @@ -9111,6 +8962,7 @@ pub const FloatMode = enum { |
| 9111 | 8962 | The floating point mode is inherited by child scopes, and can be overridden in any scope. |
| 9112 | 8963 | You can set the floating point mode in a struct or module scope by using a comptime block. |
| 9113 | 8964 | </p> |
| 8965 | <p>{#syntax#}FloatMode{#endsyntax#} can be found with {#syntax#}@import("std").builtin.FloatMode{#endsyntax#}.</p> |
| 9114 | 8966 | {#see_also|Floating Point Operations#} |
| 9115 | 8967 | {#header_close#} |
| 9116 | 8968 | |
| ... | ... | @@ -11522,7 +11374,6 @@ fn readU32Be() u32 {} |
| 11522 | 11374 | {#header_open|Keyword Reference#} |
| 11523 | 11375 | <div class="table-wrapper"> |
| 11524 | 11376 | <table> |
| 11525 | | <caption>Keywords</caption> |
| 11526 | 11377 | <thead> |
| 11527 | 11378 | <tr> |
| 11528 | 11379 | <th scope="col">Keyword</th> |