docgen: verify internal links
parent
cf39819478
commit
fa7072f3f2
|
@ -290,12 +290,19 @@ const Code = struct {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const Link = struct {
|
||||||
|
url: []const u8,
|
||||||
|
name: []const u8,
|
||||||
|
token: Token,
|
||||||
|
};
|
||||||
|
|
||||||
const Node = union(enum) {
|
const Node = union(enum) {
|
||||||
Content: []const u8,
|
Content: []const u8,
|
||||||
Nav,
|
Nav,
|
||||||
HeaderOpen: HeaderOpen,
|
HeaderOpen: HeaderOpen,
|
||||||
SeeAlso: []const SeeAlsoItem,
|
SeeAlso: []const SeeAlsoItem,
|
||||||
Code: Code,
|
Code: Code,
|
||||||
|
Link: Link,
|
||||||
};
|
};
|
||||||
|
|
||||||
const Toc = struct {
|
const Toc = struct {
|
||||||
|
@ -412,6 +419,31 @@ fn genToc(allocator: &mem.Allocator, tokenizer: &Tokenizer) -> %Toc {
|
||||||
else => return parseError(tokenizer, see_also_tok, "invalid see_also token"),
|
else => return parseError(tokenizer, see_also_tok, "invalid see_also token"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (mem.eql(u8, tag_name, "link")) {
|
||||||
|
_ = try eatToken(tokenizer, Token.Id.Separator);
|
||||||
|
const name_tok = try eatToken(tokenizer, Token.Id.TagContent);
|
||||||
|
const name = tokenizer.buffer[name_tok.start..name_tok.end];
|
||||||
|
|
||||||
|
const url_name = blk: {
|
||||||
|
const tok = tokenizer.next();
|
||||||
|
switch (tok.id) {
|
||||||
|
Token.Id.BracketClose => break :blk name,
|
||||||
|
Token.Id.Separator => {
|
||||||
|
const explicit_text = try eatToken(tokenizer, Token.Id.TagContent);
|
||||||
|
_ = try eatToken(tokenizer, Token.Id.BracketClose);
|
||||||
|
break :blk tokenizer.buffer[explicit_text.start..explicit_text.end];
|
||||||
|
},
|
||||||
|
else => return parseError(tokenizer, tok, "invalid link token"),
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
try nodes.append(Node {
|
||||||
|
.Link = Link {
|
||||||
|
.url = try urlize(allocator, url_name),
|
||||||
|
.name = name,
|
||||||
|
.token = name_tok,
|
||||||
|
},
|
||||||
|
});
|
||||||
} else if (mem.eql(u8, tag_name, "code_begin")) {
|
} else if (mem.eql(u8, tag_name, "code_begin")) {
|
||||||
_ = try eatToken(tokenizer, Token.Id.Separator);
|
_ = try eatToken(tokenizer, Token.Id.Separator);
|
||||||
const code_kind_tok = try eatToken(tokenizer, Token.Id.TagContent);
|
const code_kind_tok = try eatToken(tokenizer, Token.Id.TagContent);
|
||||||
|
@ -661,6 +693,12 @@ fn genHtml(allocator: &mem.Allocator, tokenizer: &Tokenizer, toc: &Toc, out: &io
|
||||||
Node.Content => |data| {
|
Node.Content => |data| {
|
||||||
try out.write(data);
|
try out.write(data);
|
||||||
},
|
},
|
||||||
|
Node.Link => |info| {
|
||||||
|
if (!toc.urls.contains(info.url)) {
|
||||||
|
return parseError(tokenizer, info.token, "url not found: {}", info.url);
|
||||||
|
}
|
||||||
|
try out.print("<a href=\"#{}\">{}</a>", info.url, info.name);
|
||||||
|
},
|
||||||
Node.Nav => {
|
Node.Nav => {
|
||||||
try out.write(toc.toc);
|
try out.write(toc.toc);
|
||||||
},
|
},
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
.file {
|
.file {
|
||||||
text-decoration: underline;
|
text-decoration: underline;
|
||||||
}
|
}
|
||||||
pre {
|
code {
|
||||||
font-size: 12pt;
|
font-size: 12pt;
|
||||||
}
|
}
|
||||||
@media screen and (min-width: 28.75em) {
|
@media screen and (min-width: 28.75em) {
|
||||||
|
@ -102,10 +102,14 @@ pub fn main() -> %void {
|
||||||
{#code_begin|exe|hello#}
|
{#code_begin|exe|hello#}
|
||||||
const warn = @import("std").debug.warn;
|
const warn = @import("std").debug.warn;
|
||||||
|
|
||||||
pub fn main() -> %void {
|
pub fn main() -> void {
|
||||||
warn("Hello, world!\n");
|
warn("Hello, world!\n");
|
||||||
}
|
}
|
||||||
{#code_end#}
|
{#code_end#}
|
||||||
|
<p>
|
||||||
|
Note that we also left off the <code class="zig">%</code> from the return type.
|
||||||
|
In Zig, if your main function cannot fail, you may use the <code class="zig">void</code> return type.
|
||||||
|
</p>
|
||||||
{#see_also|Values|@import|Errors|Root Source File#}
|
{#see_also|Values|@import|Errors|Root Source File#}
|
||||||
{#header_close#}
|
{#header_close#}
|
||||||
{#header_open|Source Encoding#}
|
{#header_open|Source Encoding#}
|
||||||
|
@ -621,7 +625,6 @@ fn divide(a: i32, b: i32) -> i32 {
|
||||||
{#header_close#}
|
{#header_close#}
|
||||||
{#header_close#}
|
{#header_close#}
|
||||||
{#header_open|Floats#}
|
{#header_open|Floats#}
|
||||||
{#header_close#}
|
|
||||||
{#header_open|Float Literals#}
|
{#header_open|Float Literals#}
|
||||||
{#code_begin|syntax#}
|
{#code_begin|syntax#}
|
||||||
const floating_point = 123.0E+77;
|
const floating_point = 123.0E+77;
|
||||||
|
@ -668,6 +671,7 @@ pub fn main() -> %void {
|
||||||
{#code_end#}
|
{#code_end#}
|
||||||
{#see_also|@setFloatMode|Division by Zero#}
|
{#see_also|@setFloatMode|Division by Zero#}
|
||||||
{#header_close#}
|
{#header_close#}
|
||||||
|
{#header_close#}
|
||||||
{#header_open|Operators#}
|
{#header_open|Operators#}
|
||||||
{#header_open|Table of Operators#}
|
{#header_open|Table of Operators#}
|
||||||
<table>
|
<table>
|
||||||
|
@ -690,13 +694,13 @@ pub fn main() -> %void {
|
||||||
a += b</code></pre></td>
|
a += b</code></pre></td>
|
||||||
<td>
|
<td>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="#integers">Integers</a></li>
|
<li>{#link|Integers#}</li>
|
||||||
<li><a href="#floats">Floats</a></li>
|
<li>{#link|Floats#}</li>
|
||||||
</ul>
|
</ul>
|
||||||
</td>
|
</td>
|
||||||
<td>Addition.
|
<td>Addition.
|
||||||
<ul>
|
<ul>
|
||||||
<li>Can cause <a href="#undef-integer-overflow">overflow</a> for integers.</li>
|
<li>Can cause {#link|overflow|Default Operations#} for integers.</li>
|
||||||
</ul>
|
</ul>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
|
@ -708,7 +712,7 @@ a += b</code></pre></td>
|
||||||
a +%= b</code></pre></td>
|
a +%= b</code></pre></td>
|
||||||
<td>
|
<td>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="#integers">Integers</a></li>
|
<li>{#link|Integers#}</li>
|
||||||
</ul>
|
</ul>
|
||||||
</td>
|
</td>
|
||||||
<td>Wrapping Addition.
|
<td>Wrapping Addition.
|
||||||
|
@ -725,13 +729,13 @@ a +%= b</code></pre></td>
|
||||||
a -= b</code></pre></td>
|
a -= b</code></pre></td>
|
||||||
<td>
|
<td>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="#integers">Integers</a></li>
|
<li>{#link|Integers#}</li>
|
||||||
<li><a href="#floats">Floats</a></li>
|
<li>{#link|Floats#}</li>
|
||||||
</ul>
|
</ul>
|
||||||
</td>
|
</td>
|
||||||
<td>Subtraction.
|
<td>Subtraction.
|
||||||
<ul>
|
<ul>
|
||||||
<li>Can cause <a href="#undef-integer-overflow">overflow</a> for integers.</li>
|
<li>Can cause {#link|overflow|Default Operations#} for integers.</li>
|
||||||
</ul>
|
</ul>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
|
@ -743,7 +747,7 @@ a -= b</code></pre></td>
|
||||||
a -%= b</code></pre></td>
|
a -%= b</code></pre></td>
|
||||||
<td>
|
<td>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="#integers">Integers</a></li>
|
<li>{#link|Integers#}</li>
|
||||||
</ul>
|
</ul>
|
||||||
</td>
|
</td>
|
||||||
<td>Wrapping Subtraction.
|
<td>Wrapping Subtraction.
|
||||||
|
@ -759,14 +763,14 @@ a -%= b</code></pre></td>
|
||||||
<td><pre><code class="zig">-a<code></pre></td>
|
<td><pre><code class="zig">-a<code></pre></td>
|
||||||
<td>
|
<td>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="#integers">Integers</a></li>
|
<li>{#link|Integers#}</li>
|
||||||
<li><a href="#floats">Floats</a></li>
|
<li>{#link|Floats#}</li>
|
||||||
</ul>
|
</ul>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
Negation.
|
Negation.
|
||||||
<ul>
|
<ul>
|
||||||
<li>Can cause <a href="#undef-integer-overflow">overflow</a> for integers.</li>
|
<li>Can cause {#link|overflow|Default Operations#} for integers.</li>
|
||||||
</ul>
|
</ul>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
|
@ -777,7 +781,7 @@ a -%= b</code></pre></td>
|
||||||
<td><pre><code class="zig">-%a<code></pre></td>
|
<td><pre><code class="zig">-%a<code></pre></td>
|
||||||
<td>
|
<td>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="#integers">Integers</a></li>
|
<li>{#link|Integers#}</li>
|
||||||
</ul>
|
</ul>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
|
@ -795,13 +799,13 @@ a -%= b</code></pre></td>
|
||||||
a *= b</code></pre></td>
|
a *= b</code></pre></td>
|
||||||
<td>
|
<td>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="#integers">Integers</a></li>
|
<li>{#link|Integers#}</li>
|
||||||
<li><a href="#floats">Floats</a></li>
|
<li>{#link|Floats#}</li>
|
||||||
</ul>
|
</ul>
|
||||||
</td>
|
</td>
|
||||||
<td>Multiplication.
|
<td>Multiplication.
|
||||||
<ul>
|
<ul>
|
||||||
<li>Can cause <a href="#undef-integer-overflow">overflow</a> for integers.</li>
|
<li>Can cause {#link|overflow|Default Operations#} for integers.</li>
|
||||||
</ul>
|
</ul>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
|
@ -813,7 +817,7 @@ a *= b</code></pre></td>
|
||||||
a *%= b</code></pre></td>
|
a *%= b</code></pre></td>
|
||||||
<td>
|
<td>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="#integers">Integers</a></li>
|
<li>{#link|Integers#}</li>
|
||||||
</ul>
|
</ul>
|
||||||
</td>
|
</td>
|
||||||
<td>Wrapping Multiplication.
|
<td>Wrapping Multiplication.
|
||||||
|
@ -830,19 +834,19 @@ a *%= b</code></pre></td>
|
||||||
a /= b</code></pre></td>
|
a /= b</code></pre></td>
|
||||||
<td>
|
<td>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="#integers">Integers</a></li>
|
<li>{#link|Integers#}</li>
|
||||||
<li><a href="#floats">Floats</a></li>
|
<li>{#link|Floats#}</li>
|
||||||
</ul>
|
</ul>
|
||||||
</td>
|
</td>
|
||||||
<td>Divison.
|
<td>Divison.
|
||||||
<ul>
|
<ul>
|
||||||
<li>Can cause <a href="#undef-integer-overflow">overflow</a> for integers.</li>
|
<li>Can cause {#link|overflow|Default Operations#} for integers.</li>
|
||||||
<li>Can cause <a href="#undef-division-by-zero">division by zero</a> for integers.</li>
|
<li>Can cause {#link|Division by Zero#} for integers.</li>
|
||||||
<li>Can cause <a href="#undef-division-by-zero">division by zero</a> for floats in <a href="#float-operations">FloatMode.Optimized Mode</a>.</li>
|
<li>Can cause {#link|Division by Zero#} for floats in {#link|FloatMode.Optimized Mode|Floating Point Operations#}.</li>
|
||||||
<li>For non-compile-time-known signed integers, must use
|
<li>For non-compile-time-known signed integers, must use
|
||||||
<a href="#builtin-divTrunc">@divTrunc</a>,
|
{#link|@divTrunc#},
|
||||||
<a href="#builtin-divFloor">@divFloor</a>, or
|
{#link|@divFloor#}, or
|
||||||
<a href="#builtin-divExact">@divExact</a> instead of <code>/</code>.
|
{#link|@divExact#} instead of <code>/</code>.
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</td>
|
</td>
|
||||||
|
@ -855,17 +859,17 @@ a /= b</code></pre></td>
|
||||||
a %= b</code></pre></td>
|
a %= b</code></pre></td>
|
||||||
<td>
|
<td>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="#integers">Integers</a></li>
|
<li>{#link|Integers#}</li>
|
||||||
<li><a href="#floats">Floats</a></li>
|
<li>{#link|Floats#}</li>
|
||||||
</ul>
|
</ul>
|
||||||
</td>
|
</td>
|
||||||
<td>Remainder Division.
|
<td>Remainder Division.
|
||||||
<ul>
|
<ul>
|
||||||
<li>Can cause <a href="#undef-division-by-zero">division by zero</a> for integers.</li>
|
<li>Can cause {#link|Division by Zero#} for integers.</li>
|
||||||
<li>Can cause <a href="#undef-division-by-zero">division by zero</a> for floats in <a href="#float-operations">FloatMode.Optimized Mode</a>.</li>
|
<li>Can cause {#link|Division by Zero#} for floats in {#link|FloatMode.Optimized Mode|Floating Point Operations#}.</li>
|
||||||
<li>For non-compile-time-known signed integers, must use
|
<li>For non-compile-time-known signed integers, must use
|
||||||
<a href="#builtin-rem">@rem</a> or
|
{#link|@rem#} or
|
||||||
<a href="#builtin-mod">@mod</a> instead of <code>%</code>.
|
{#link|@mod#} instead of <code>%</code>.
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</td>
|
</td>
|
||||||
|
@ -878,13 +882,13 @@ a %= b</code></pre></td>
|
||||||
a <<= b</code></pre></td>
|
a <<= b</code></pre></td>
|
||||||
<td>
|
<td>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="#integers">Integers</a></li>
|
<li>{#link|Integers#}</li>
|
||||||
</ul>
|
</ul>
|
||||||
</td>
|
</td>
|
||||||
<td>Bit Shift Left.
|
<td>Bit Shift Left.
|
||||||
<ul>
|
<ul>
|
||||||
<li>See also <a href="#builtin-shlExact">@shlExact</a>.</li>
|
<li>See also {#link|@shlExact#}.</li>
|
||||||
<li>See also <a href="#builtin-shlWithOverflow">@shlWithOverflow</a>.</li>
|
<li>See also {#link|@shlWithOverflow#}.</li>
|
||||||
</ul>
|
</ul>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
|
@ -896,12 +900,12 @@ a <<= b</code></pre></td>
|
||||||
a >>= b</code></pre></td>
|
a >>= b</code></pre></td>
|
||||||
<td>
|
<td>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="#integers">Integers</a></li>
|
<li>{#link|Integers#}</li>
|
||||||
</ul>
|
</ul>
|
||||||
</td>
|
</td>
|
||||||
<td>Bit Shift Right.
|
<td>Bit Shift Right.
|
||||||
<ul>
|
<ul>
|
||||||
<li>See also <a href="#builtin-shrExact">@shrExact</a>.</li>
|
<li>See also {#link|@shrExact#}.</li>
|
||||||
</ul>
|
</ul>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
|
@ -913,7 +917,7 @@ a >>= b</code></pre></td>
|
||||||
a &= b</code></pre></td>
|
a &= b</code></pre></td>
|
||||||
<td>
|
<td>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="#integers">Integers</a></li>
|
<li>{#link|Integers#}</li>
|
||||||
</ul>
|
</ul>
|
||||||
</td>
|
</td>
|
||||||
<td>Bitwise AND.
|
<td>Bitwise AND.
|
||||||
|
@ -927,7 +931,7 @@ a &= b</code></pre></td>
|
||||||
a |= b</code></pre></td>
|
a |= b</code></pre></td>
|
||||||
<td>
|
<td>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="#integers">Integers</a></li>
|
<li>{#link|Integers#}</li>
|
||||||
</ul>
|
</ul>
|
||||||
</td>
|
</td>
|
||||||
<td>Bitwise OR.
|
<td>Bitwise OR.
|
||||||
|
@ -941,7 +945,7 @@ a |= b</code></pre></td>
|
||||||
a ^= b</code></pre></td>
|
a ^= b</code></pre></td>
|
||||||
<td>
|
<td>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="#integers">Integers</a></li>
|
<li>{#link|Integers#}</li>
|
||||||
</ul>
|
</ul>
|
||||||
</td>
|
</td>
|
||||||
<td>Bitwise XOR.
|
<td>Bitwise XOR.
|
||||||
|
@ -954,7 +958,7 @@ a ^= b</code></pre></td>
|
||||||
<td><pre><code class="zig">~a<code></pre></td>
|
<td><pre><code class="zig">~a<code></pre></td>
|
||||||
<td>
|
<td>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="#integers">Integers</a></li>
|
<li>{#link|Integers#}</li>
|
||||||
</ul>
|
</ul>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
|
@ -968,13 +972,13 @@ a ^= b</code></pre></td>
|
||||||
<td><pre><code class="zig">a ?? b</code></pre></td>
|
<td><pre><code class="zig">a ?? b</code></pre></td>
|
||||||
<td>
|
<td>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="#nullables">Nullables</a></li>
|
<li>{#link|Nullables#}</li>
|
||||||
</ul>
|
</ul>
|
||||||
</td>
|
</td>
|
||||||
<td>If <code>a</code> is <code>null</code>,
|
<td>If <code>a</code> is <code>null</code>,
|
||||||
returns <code>b</code> ("default value"),
|
returns <code>b</code> ("default value"),
|
||||||
otherwise returns the unwrapped value of <code>a</code>.
|
otherwise returns the unwrapped value of <code>a</code>.
|
||||||
Note that <code>b</code> may be a value of type <a href="#noreturn">noreturn</a>.
|
Note that <code>b</code> may be a value of type {#link|noreturn#}.
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<pre><code class="zig">const value: ?u32 = null;
|
<pre><code class="zig">const value: ?u32 = null;
|
||||||
|
@ -986,7 +990,7 @@ unwrapped == 1234</code></pre>
|
||||||
<td><pre><code class="zig">??a</code></pre></td>
|
<td><pre><code class="zig">??a</code></pre></td>
|
||||||
<td>
|
<td>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="#nullables">Nullables</a></li>
|
<li>{#link|Nullables#}</li>
|
||||||
</ul>
|
</ul>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
|
@ -1003,13 +1007,13 @@ unwrapped == 1234</code></pre>
|
||||||
a catch |err| b</code></pre></td>
|
a catch |err| b</code></pre></td>
|
||||||
<td>
|
<td>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="#errors">Error Unions</a></li>
|
<li>{#link|Error Unions|Errors#}</li>
|
||||||
</ul>
|
</ul>
|
||||||
</td>
|
</td>
|
||||||
<td>If <code>a</code> is an <code>error</code>,
|
<td>If <code>a</code> is an <code>error</code>,
|
||||||
returns <code>b</code> ("default value"),
|
returns <code>b</code> ("default value"),
|
||||||
otherwise returns the unwrapped value of <code>a</code>.
|
otherwise returns the unwrapped value of <code>a</code>.
|
||||||
Note that <code>b</code> may be a value of type <a href="#noreturn">noreturn</a>.
|
Note that <code>b</code> may be a value of type {#link|noreturn#}.
|
||||||
<code>err</code> is the <code>error</code> and is in scope of the expression <code>b</code>.
|
<code>err</code> is the <code>error</code> and is in scope of the expression <code>b</code>.
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
|
@ -1022,7 +1026,7 @@ unwrapped == 1234</code></pre>
|
||||||
<td><pre><code class="zig">a and b<code></pre></td>
|
<td><pre><code class="zig">a and b<code></pre></td>
|
||||||
<td>
|
<td>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="#primitive-types">bool</a></li>
|
<li>{#link|bool|Primitive Types#}</li>
|
||||||
</ul>
|
</ul>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
|
@ -1037,7 +1041,7 @@ unwrapped == 1234</code></pre>
|
||||||
<td><pre><code class="zig">a or b<code></pre></td>
|
<td><pre><code class="zig">a or b<code></pre></td>
|
||||||
<td>
|
<td>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="#primitive-types">bool</a></li>
|
<li>{#link|bool|Primitive Types#}</li>
|
||||||
</ul>
|
</ul>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
|
@ -1052,7 +1056,7 @@ unwrapped == 1234</code></pre>
|
||||||
<td><pre><code class="zig">!a<code></pre></td>
|
<td><pre><code class="zig">!a<code></pre></td>
|
||||||
<td>
|
<td>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="#primitive-types">bool</a></li>
|
<li>{#link|bool|Primitive Types#}</li>
|
||||||
</ul>
|
</ul>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
|
@ -1066,10 +1070,10 @@ unwrapped == 1234</code></pre>
|
||||||
<td><pre><code class="zig">a == b<code></pre></td>
|
<td><pre><code class="zig">a == b<code></pre></td>
|
||||||
<td>
|
<td>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="#integers">Integers</a></li>
|
<li>{#link|Integers#}</li>
|
||||||
<li><a href="#floats">Floats</a></li>
|
<li>{#link|Floats#}</li>
|
||||||
<li><a href="#primitive-types">bool</a></li>
|
<li>{#link|bool|Primitive Types#}</li>
|
||||||
<li><a href="#primitive-types">type</a></li>
|
<li>{#link|type|Primitive Types#}</li>
|
||||||
</ul>
|
</ul>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
|
@ -1083,7 +1087,7 @@ unwrapped == 1234</code></pre>
|
||||||
<td><pre><code class="zig">a == null<code></pre></td>
|
<td><pre><code class="zig">a == null<code></pre></td>
|
||||||
<td>
|
<td>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="#nullables">Nullables</a></li>
|
<li>{#link|Nullables#}</li>
|
||||||
</ul>
|
</ul>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
|
@ -1098,10 +1102,10 @@ value == null</code></pre>
|
||||||
<td><pre><code class="zig">a != b<code></pre></td>
|
<td><pre><code class="zig">a != b<code></pre></td>
|
||||||
<td>
|
<td>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="#integers">Integers</a></li>
|
<li>{#link|Integers#}</li>
|
||||||
<li><a href="#floats">Floats</a></li>
|
<li>{#link|Floats#}</li>
|
||||||
<li><a href="#primitive-types">bool</a></li>
|
<li>{#link|bool|Primitive Types#}</li>
|
||||||
<li><a href="#primitive-types">type</a></li>
|
<li>{#link|type|Primitive Types#}</li>
|
||||||
</ul>
|
</ul>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
|
@ -1115,8 +1119,8 @@ value == null</code></pre>
|
||||||
<td><pre><code class="zig">a > b<code></pre></td>
|
<td><pre><code class="zig">a > b<code></pre></td>
|
||||||
<td>
|
<td>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="#integers">Integers</a></li>
|
<li>{#link|Integers#}</li>
|
||||||
<li><a href="#floats">Floats</a></li>
|
<li>{#link|Floats#}</li>
|
||||||
</ul>
|
</ul>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
|
@ -1130,8 +1134,8 @@ value == null</code></pre>
|
||||||
<td><pre><code class="zig">a >= b<code></pre></td>
|
<td><pre><code class="zig">a >= b<code></pre></td>
|
||||||
<td>
|
<td>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="#integers">Integers</a></li>
|
<li>{#link|Integers#}</li>
|
||||||
<li><a href="#floats">Floats</a></li>
|
<li>{#link|Floats#}</li>
|
||||||
</ul>
|
</ul>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
|
@ -1145,8 +1149,8 @@ value == null</code></pre>
|
||||||
<td><pre><code class="zig">a < b<code></pre></td>
|
<td><pre><code class="zig">a < b<code></pre></td>
|
||||||
<td>
|
<td>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="#integers">Integers</a></li>
|
<li>{#link|Integers#}</li>
|
||||||
<li><a href="#floats">Floats</a></li>
|
<li>{#link|Floats#}</li>
|
||||||
</ul>
|
</ul>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
|
@ -1160,8 +1164,8 @@ value == null</code></pre>
|
||||||
<td><pre><code class="zig">a <= b<code></pre></td>
|
<td><pre><code class="zig">a <= b<code></pre></td>
|
||||||
<td>
|
<td>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="#integers">Integers</a></li>
|
<li>{#link|Integers#}</li>
|
||||||
<li><a href="#floats">Floats</a></li>
|
<li>{#link|Floats#}</li>
|
||||||
</ul>
|
</ul>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
|
@ -1175,13 +1179,13 @@ value == null</code></pre>
|
||||||
<td><pre><code class="zig">a ++ b<code></pre></td>
|
<td><pre><code class="zig">a ++ b<code></pre></td>
|
||||||
<td>
|
<td>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="#arrays">Arrays</a></li>
|
<li>{#link|Arrays#}</li>
|
||||||
</ul>
|
</ul>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
Array concatenation.
|
Array concatenation.
|
||||||
<ul>
|
<ul>
|
||||||
<li>Only available when <code>a</code> and <code>b</code> are <a href="#comptime">compile-time known</a>.
|
<li>Only available when <code>a</code> and <code>b</code> are {#link|compile-time known|comptime#}.
|
||||||
</ul>
|
</ul>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
|
@ -1196,13 +1200,13 @@ mem.eql(u32, together, []u32{1,2,3,4})</code></pre>
|
||||||
<td><pre><code class="zig">a ** b<code></pre></td>
|
<td><pre><code class="zig">a ** b<code></pre></td>
|
||||||
<td>
|
<td>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="#arrays">Arrays</a></li>
|
<li>{#link|Arrays#}</li>
|
||||||
</ul>
|
</ul>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
Array multiplication.
|
Array multiplication.
|
||||||
<ul>
|
<ul>
|
||||||
<li>Only available when <code>a</code> and <code>b</code> are <a href="#comptime">compile-time known</a>.
|
<li>Only available when <code>a</code> and <code>b</code> are {#link|compile-time known|comptime#}.
|
||||||
</ul>
|
</ul>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
|
@ -1215,7 +1219,7 @@ mem.eql(u8, pattern, "ababab")</code></pre>
|
||||||
<td><pre><code class="zig">*a<code></pre></td>
|
<td><pre><code class="zig">*a<code></pre></td>
|
||||||
<td>
|
<td>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="#pointers">Pointers</a></li>
|
<li>{#link|Pointers#}</li>
|
||||||
</ul>
|
</ul>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
|
@ -1504,7 +1508,7 @@ test "pointer child type" {
|
||||||
Each type has an <strong>alignment</strong> - a number of bytes such that,
|
Each type has an <strong>alignment</strong> - a number of bytes such that,
|
||||||
when a value of the type is loaded from or stored to memory,
|
when a value of the type is loaded from or stored to memory,
|
||||||
the memory address must be evenly divisible by this number. You can use
|
the memory address must be evenly divisible by this number. You can use
|
||||||
<a href="#builtin-alignOf">@alignOf</a> to find out this value for any type.
|
{#link|@alignOf#} to find out this value for any type.
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
Alignment depends on the CPU architecture, but is always a power of two, and
|
Alignment depends on the CPU architecture, but is always a power of two, and
|
||||||
|
@ -1562,9 +1566,9 @@ test "function alignment" {
|
||||||
{#code_end#}
|
{#code_end#}
|
||||||
<p>
|
<p>
|
||||||
If you have a pointer or a slice that has a small alignment, but you know that it actually
|
If you have a pointer or a slice that has a small alignment, but you know that it actually
|
||||||
has a bigger alignment, use <a href="#builtin-alignCast">@alignCast</a> to change the
|
has a bigger alignment, use {#link|@alignCast#} to change the
|
||||||
pointer into a more aligned pointer. This is a no-op at runtime, but inserts a
|
pointer into a more aligned pointer. This is a no-op at runtime, but inserts a
|
||||||
<a href="#undef-incorrect-pointer-alignment">safety check</a>:
|
{#link|safety check|Incorrect Pointer Alignment#}:
|
||||||
</p>
|
</p>
|
||||||
{#code_begin|test_safety|incorrect alignment#}
|
{#code_begin|test_safety|incorrect alignment#}
|
||||||
const assert = @import("std").debug.assert;
|
const assert = @import("std").debug.assert;
|
||||||
|
@ -1589,7 +1593,7 @@ fn foo(bytes: []u8) -> u32 {
|
||||||
</p>
|
</p>
|
||||||
<p>As an example, this code produces undefined behavior:</p>
|
<p>As an example, this code produces undefined behavior:</p>
|
||||||
<pre><code class="zig">*@ptrCast(&u32, f32(12.34))</code></pre>
|
<pre><code class="zig">*@ptrCast(&u32, f32(12.34))</code></pre>
|
||||||
<p>Instead, use <a href="#builtin-bitCast">@bitCast</a>:
|
<p>Instead, use {#link|@bitCast#}:
|
||||||
<pre><code class="zig">@bitCast(u32, f32(12.34))</code></pre>
|
<pre><code class="zig">@bitCast(u32, f32(12.34))</code></pre>
|
||||||
<p>As an added benefit, the <code>@bitcast</code> version works at compile-time.</p>
|
<p>As an added benefit, the <code>@bitcast</code> version works at compile-time.</p>
|
||||||
{#see_also|Slices|Memory#}
|
{#see_also|Slices|Memory#}
|
||||||
|
@ -3391,7 +3395,7 @@ test "fibonacci" {
|
||||||
The compiler noticed that evaluating this function at compile-time took a long time,
|
The compiler noticed that evaluating this function at compile-time took a long time,
|
||||||
and thus emitted a compile error and gave up. If the programmer wants to increase
|
and thus emitted a compile error and gave up. If the programmer wants to increase
|
||||||
the budget for compile-time computation, they can use a built-in function called
|
the budget for compile-time computation, they can use a built-in function called
|
||||||
<a href="#builtin-setEvalBranchQuota">@setEvalBranchQuota</a> to change the default number 1000 to something else.
|
{#link|@setEvalBranchQuota#} to change the default number 1000 to something else.
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
What if we fix the base case, but put the wrong value in the <code>assert</code> line?
|
What if we fix the base case, but put the wrong value in the <code>assert</code> line?
|
||||||
|
@ -3750,7 +3754,7 @@ pub fn main() {
|
||||||
<code>?fn()</code>, or <code>[]T</code>. It returns the same type as <code>ptr</code>
|
<code>?fn()</code>, or <code>[]T</code>. It returns the same type as <code>ptr</code>
|
||||||
except with the alignment adjusted to the new value.
|
except with the alignment adjusted to the new value.
|
||||||
</p>
|
</p>
|
||||||
<p>A <a href="#undef-incorrect-pointer-alignment">pointer alignment safety check</a> is added
|
<p>A {#link|pointer alignment safety check|Incorrect Pointer Alignment#} is added
|
||||||
to the generated code to make sure the pointer is aligned as promised.</p>
|
to the generated code to make sure the pointer is aligned as promised.</p>
|
||||||
|
|
||||||
{#header_close#}
|
{#header_close#}
|
||||||
|
@ -3767,7 +3771,7 @@ comptime {
|
||||||
}</code></pre>
|
}</code></pre>
|
||||||
<p>
|
<p>
|
||||||
The result is a target-specific compile time constant. It is guaranteed to be
|
The result is a target-specific compile time constant. It is guaranteed to be
|
||||||
less than or equal to <a href="#builtin-sizeOf">@sizeOf(T)</a>.
|
less than or equal to {#link|@sizeOf(T)|@sizeOf#}.
|
||||||
</p>
|
</p>
|
||||||
{#see_also|Alignment#}
|
{#see_also|Alignment#}
|
||||||
{#header_close#}
|
{#header_close#}
|
||||||
|
@ -4109,7 +4113,7 @@ fn add(a: i32, b: i32) -> i32 { return a + b; }
|
||||||
{#header_open|@intToPtr#}
|
{#header_open|@intToPtr#}
|
||||||
<pre><code class="zig">@intToPtr(comptime DestType: type, int: usize) -> DestType</code></pre>
|
<pre><code class="zig">@intToPtr(comptime DestType: type, int: usize) -> DestType</code></pre>
|
||||||
<p>
|
<p>
|
||||||
Converts an integer to a pointer. To convert the other way, use <a href="#builtin-ptrToInt">@ptrToInt</a>.
|
Converts an integer to a pointer. To convert the other way, use {#link|@ptrToInt#}.
|
||||||
</p>
|
</p>
|
||||||
{#header_close#}
|
{#header_close#}
|
||||||
{#header_open|@IntType#}
|
{#header_open|@IntType#}
|
||||||
|
@ -4286,7 +4290,7 @@ test "call foo" {
|
||||||
<li><code>fn()</code></li>
|
<li><code>fn()</code></li>
|
||||||
<li><code>?fn()</code></li>
|
<li><code>?fn()</code></li>
|
||||||
</ul>
|
</ul>
|
||||||
<p>To convert the other way, use <a href="#builtin-intToPtr">@intToPtr</a></p>
|
<p>To convert the other way, use {#link|@intToPtr#}</p>
|
||||||
|
|
||||||
{#header_close#}
|
{#header_close#}
|
||||||
{#header_open|@rem#}
|
{#header_open|@rem#}
|
||||||
|
@ -4539,9 +4543,9 @@ pub const TypeId = enum {
|
||||||
Zig has three build modes:
|
Zig has three build modes:
|
||||||
</p>
|
</p>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="#build-mode-debug">Debug</a> (default)</li>
|
<li>{#link|Debug#} (default)</li>
|
||||||
<li><a href="#build-mode-release-fast">ReleaseFast</a></li>
|
<li>{#link|ReleaseFast#}</li>
|
||||||
<li><a href="#build-mode-release-safe">ReleaseSafe</a></li>
|
<li>{#link|ReleaseSafe#}</li>
|
||||||
</ul>
|
</ul>
|
||||||
<p>
|
<p>
|
||||||
To add standard build options to a <code>build.zig</code> file:
|
To add standard build options to a <code>build.zig</code> file:
|
||||||
|
@ -4592,7 +4596,7 @@ pub fn build(b: &Builder) -> %void {
|
||||||
detected at compile-time, Zig emits an error. Most undefined behavior that
|
detected at compile-time, Zig emits an error. Most undefined behavior that
|
||||||
cannot be detected at compile-time can be detected at runtime. In these cases,
|
cannot be detected at compile-time can be detected at runtime. In these cases,
|
||||||
Zig has safety checks. Safety checks can be disabled on a per-block basis
|
Zig has safety checks. Safety checks can be disabled on a per-block basis
|
||||||
with <code>@setDebugSafety</code>. The <a href="#build-mode-release-fast">ReleaseFast</a>
|
with <code>@setDebugSafety</code>. The {#link|ReleaseFast#}
|
||||||
build mode disables all safety checks in order to facilitate optimizations.
|
build mode disables all safety checks in order to facilitate optimizations.
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
|
|
Loading…
Reference in New Issue