authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-01-22 23:06:07-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-01-22 23:06:07-05:00
logfa7072f3f2d7bdb82e2590f93aa702c395e1934d
tree8598ec0e58f0b802fb7b665d53dff84c7b4df897
parentcf39819478e237255109d0343e642db70e88071b

docgen: verify internal links


2 files changed, 127 insertions(+), 85 deletions(-)

doc/docgen.zig+38
...@@ -290,12 +290,19 @@ const Code = struct {...@@ -290,12 +290,19 @@ const Code = struct {
290 };290 };
291};291};
292292
293const Link = struct {
294 url: []const u8,
295 name: []const u8,
296 token: Token,
297};
298
293const Node = union(enum) {299const Node = union(enum) {
294 Content: []const u8,300 Content: []const u8,
295 Nav,301 Nav,
296 HeaderOpen: HeaderOpen,302 HeaderOpen: HeaderOpen,
297 SeeAlso: []const SeeAlsoItem,303 SeeAlso: []const SeeAlsoItem,
298 Code: Code,304 Code: Code,
305 Link: Link,
299};306};
300307
301const Toc = struct {308const Toc = struct {
...@@ -412,6 +419,31 @@ fn genToc(allocator: &mem.Allocator, tokenizer: &Tokenizer) -> %Toc {...@@ -412,6 +419,31 @@ fn genToc(allocator: &mem.Allocator, tokenizer: &Tokenizer) -> %Toc {
412 else => return parseError(tokenizer, see_also_tok, "invalid see_also token"),419 else => return parseError(tokenizer, see_also_tok, "invalid see_also token"),
413 }420 }
414 }421 }
422 } else if (mem.eql(u8, tag_name, "link")) {
423 _ = try eatToken(tokenizer, Token.Id.Separator);
424 const name_tok = try eatToken(tokenizer, Token.Id.TagContent);
425 const name = tokenizer.buffer[name_tok.start..name_tok.end];
426
427 const url_name = blk: {
428 const tok = tokenizer.next();
429 switch (tok.id) {
430 Token.Id.BracketClose => break :blk name,
431 Token.Id.Separator => {
432 const explicit_text = try eatToken(tokenizer, Token.Id.TagContent);
433 _ = try eatToken(tokenizer, Token.Id.BracketClose);
434 break :blk tokenizer.buffer[explicit_text.start..explicit_text.end];
435 },
436 else => return parseError(tokenizer, tok, "invalid link token"),
437 }
438 };
439
440 try nodes.append(Node {
441 .Link = Link {
442 .url = try urlize(allocator, url_name),
443 .name = name,
444 .token = name_tok,
445 },
446 });
415 } else if (mem.eql(u8, tag_name, "code_begin")) {447 } else if (mem.eql(u8, tag_name, "code_begin")) {
416 _ = try eatToken(tokenizer, Token.Id.Separator);448 _ = try eatToken(tokenizer, Token.Id.Separator);
417 const code_kind_tok = try eatToken(tokenizer, Token.Id.TagContent);449 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...@@ -661,6 +693,12 @@ fn genHtml(allocator: &mem.Allocator, tokenizer: &Tokenizer, toc: &Toc, out: &io
661 Node.Content => |data| {693 Node.Content => |data| {
662 try out.write(data);694 try out.write(data);
663 },695 },
696 Node.Link => |info| {
697 if (!toc.urls.contains(info.url)) {
698 return parseError(tokenizer, info.token, "url not found: {}", info.url);
699 }
700 try out.print("<a href=\"#{}\">{}</a>", info.url, info.name);
701 },
664 Node.Nav => {702 Node.Nav => {
665 try out.write(toc.toc);703 try out.write(toc.toc);
666 },704 },
doc/langref.html.in+89-85
...@@ -33,7 +33,7 @@...@@ -33,7 +33,7 @@
33 .file {33 .file {
34 text-decoration: underline;34 text-decoration: underline;
35 }35 }
36 pre {36 code {
37 font-size: 12pt;37 font-size: 12pt;
38 }38 }
39 @media screen and (min-width: 28.75em) {39 @media screen and (min-width: 28.75em) {
...@@ -102,10 +102,14 @@ pub fn main() -> %void {...@@ -102,10 +102,14 @@ pub fn main() -> %void {
102 {#code_begin|exe|hello#}102 {#code_begin|exe|hello#}
103const warn = @import("std").debug.warn;103const warn = @import("std").debug.warn;
104104
105pub fn main() -> %void {105pub fn main() -> void {
106 warn("Hello, world!\n");106 warn("Hello, world!\n");
107}107}
108 {#code_end#}108 {#code_end#}
109 <p>
110 Note that we also left off the <code class="zig">%</code> from the return type.
111 In Zig, if your main function cannot fail, you may use the <code class="zig">void</code> return type.
112 </p>
109 {#see_also|Values|@import|Errors|Root Source File#}113 {#see_also|Values|@import|Errors|Root Source File#}
110 {#header_close#}114 {#header_close#}
111 {#header_open|Source Encoding#}115 {#header_open|Source Encoding#}
...@@ -621,7 +625,6 @@ fn divide(a: i32, b: i32) -> i32 {...@@ -621,7 +625,6 @@ fn divide(a: i32, b: i32) -> i32 {
621 {#header_close#}625 {#header_close#}
622 {#header_close#}626 {#header_close#}
623 {#header_open|Floats#}627 {#header_open|Floats#}
624 {#header_close#}
625 {#header_open|Float Literals#}628 {#header_open|Float Literals#}
626 {#code_begin|syntax#}629 {#code_begin|syntax#}
627const floating_point = 123.0E+77;630const floating_point = 123.0E+77;
...@@ -668,6 +671,7 @@ pub fn main() -> %void {...@@ -668,6 +671,7 @@ pub fn main() -> %void {
668 {#code_end#}671 {#code_end#}
669 {#see_also|@setFloatMode|Division by Zero#}672 {#see_also|@setFloatMode|Division by Zero#}
670 {#header_close#}673 {#header_close#}
674 {#header_close#}
671 {#header_open|Operators#}675 {#header_open|Operators#}
672 {#header_open|Table of Operators#}676 {#header_open|Table of Operators#}
673 <table>677 <table>
...@@ -690,13 +694,13 @@ pub fn main() -> %void {...@@ -690,13 +694,13 @@ pub fn main() -> %void {
690a += b</code></pre></td>694a += b</code></pre></td>
691 <td>695 <td>
692 <ul>696 <ul>
693 <li><a href="#integers">Integers</a></li>697 <li>{#link|Integers#}</li>
694 <li><a href="#floats">Floats</a></li>698 <li>{#link|Floats#}</li>
695 </ul>699 </ul>
696 </td>700 </td>
697 <td>Addition.701 <td>Addition.
698 <ul>702 <ul>
699 <li>Can cause <a href="#undef-integer-overflow">overflow</a> for integers.</li>703 <li>Can cause {#link|overflow|Default Operations#} for integers.</li>
700 </ul>704 </ul>
701 </td>705 </td>
702 <td>706 <td>
...@@ -708,7 +712,7 @@ a += b</code></pre></td>...@@ -708,7 +712,7 @@ a += b</code></pre></td>
708a +%= b</code></pre></td>712a +%= b</code></pre></td>
709 <td>713 <td>
710 <ul>714 <ul>
711 <li><a href="#integers">Integers</a></li>715 <li>{#link|Integers#}</li>
712 </ul>716 </ul>
713 </td>717 </td>
714 <td>Wrapping Addition.718 <td>Wrapping Addition.
...@@ -725,13 +729,13 @@ a +%= b</code></pre></td>...@@ -725,13 +729,13 @@ a +%= b</code></pre></td>
725a -= b</code></pre></td>729a -= b</code></pre></td>
726 <td>730 <td>
727 <ul>731 <ul>
728 <li><a href="#integers">Integers</a></li>732 <li>{#link|Integers#}</li>
729 <li><a href="#floats">Floats</a></li>733 <li>{#link|Floats#}</li>
730 </ul>734 </ul>
731 </td>735 </td>
732 <td>Subtraction.736 <td>Subtraction.
733 <ul>737 <ul>
734 <li>Can cause <a href="#undef-integer-overflow">overflow</a> for integers.</li>738 <li>Can cause {#link|overflow|Default Operations#} for integers.</li>
735 </ul>739 </ul>
736 </td>740 </td>
737 <td>741 <td>
...@@ -743,7 +747,7 @@ a -= b</code></pre></td>...@@ -743,7 +747,7 @@ a -= b</code></pre></td>
743a -%= b</code></pre></td>747a -%= b</code></pre></td>
744 <td>748 <td>
745 <ul>749 <ul>
746 <li><a href="#integers">Integers</a></li>750 <li>{#link|Integers#}</li>
747 </ul>751 </ul>
748 </td>752 </td>
749 <td>Wrapping Subtraction.753 <td>Wrapping Subtraction.
...@@ -759,14 +763,14 @@ a -%= b</code></pre></td>...@@ -759,14 +763,14 @@ a -%= b</code></pre></td>
759 <td><pre><code class="zig">-a<code></pre></td>763 <td><pre><code class="zig">-a<code></pre></td>
760 <td>764 <td>
761 <ul>765 <ul>
762 <li><a href="#integers">Integers</a></li>766 <li>{#link|Integers#}</li>
763 <li><a href="#floats">Floats</a></li>767 <li>{#link|Floats#}</li>
764 </ul>768 </ul>
765 </td>769 </td>
766 <td>770 <td>
767 Negation.771 Negation.
768 <ul>772 <ul>
769 <li>Can cause <a href="#undef-integer-overflow">overflow</a> for integers.</li>773 <li>Can cause {#link|overflow|Default Operations#} for integers.</li>
770 </ul>774 </ul>
771 </td>775 </td>
772 <td>776 <td>
...@@ -777,7 +781,7 @@ a -%= b</code></pre></td>...@@ -777,7 +781,7 @@ a -%= b</code></pre></td>
777 <td><pre><code class="zig">-%a<code></pre></td>781 <td><pre><code class="zig">-%a<code></pre></td>
778 <td>782 <td>
779 <ul>783 <ul>
780 <li><a href="#integers">Integers</a></li>784 <li>{#link|Integers#}</li>
781 </ul>785 </ul>
782 </td>786 </td>
783 <td>787 <td>
...@@ -795,13 +799,13 @@ a -%= b</code></pre></td>...@@ -795,13 +799,13 @@ a -%= b</code></pre></td>
795a *= b</code></pre></td>799a *= b</code></pre></td>
796 <td>800 <td>
797 <ul>801 <ul>
798 <li><a href="#integers">Integers</a></li>802 <li>{#link|Integers#}</li>
799 <li><a href="#floats">Floats</a></li>803 <li>{#link|Floats#}</li>
800 </ul>804 </ul>
801 </td>805 </td>
802 <td>Multiplication.806 <td>Multiplication.
803 <ul>807 <ul>
804 <li>Can cause <a href="#undef-integer-overflow">overflow</a> for integers.</li>808 <li>Can cause {#link|overflow|Default Operations#} for integers.</li>
805 </ul>809 </ul>
806 </td>810 </td>
807 <td>811 <td>
...@@ -813,7 +817,7 @@ a *= b</code></pre></td>...@@ -813,7 +817,7 @@ a *= b</code></pre></td>
813a *%= b</code></pre></td>817a *%= b</code></pre></td>
814 <td>818 <td>
815 <ul>819 <ul>
816 <li><a href="#integers">Integers</a></li>820 <li>{#link|Integers#}</li>
817 </ul>821 </ul>
818 </td>822 </td>
819 <td>Wrapping Multiplication.823 <td>Wrapping Multiplication.
...@@ -830,19 +834,19 @@ a *%= b</code></pre></td>...@@ -830,19 +834,19 @@ a *%= b</code></pre></td>
830a /= b</code></pre></td>834a /= b</code></pre></td>
831 <td>835 <td>
832 <ul>836 <ul>
833 <li><a href="#integers">Integers</a></li>837 <li>{#link|Integers#}</li>
834 <li><a href="#floats">Floats</a></li>838 <li>{#link|Floats#}</li>
835 </ul>839 </ul>
836 </td>840 </td>
837 <td>Divison.841 <td>Divison.
838 <ul>842 <ul>
839 <li>Can cause <a href="#undef-integer-overflow">overflow</a> for integers.</li>843 <li>Can cause {#link|overflow|Default Operations#} for integers.</li>
840 <li>Can cause <a href="#undef-division-by-zero">division by zero</a> for integers.</li>844 <li>Can cause {#link|Division by Zero#} for integers.</li>
841 <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>845 <li>Can cause {#link|Division by Zero#} for floats in {#link|FloatMode.Optimized Mode|Floating Point Operations#}.</li>
842 <li>For non-compile-time-known signed integers, must use846 <li>For non-compile-time-known signed integers, must use
843 <a href="#builtin-divTrunc">@divTrunc</a>,847 {#link|@divTrunc#},
844 <a href="#builtin-divFloor">@divFloor</a>, or848 {#link|@divFloor#}, or
845 <a href="#builtin-divExact">@divExact</a> instead of <code>/</code>.849 {#link|@divExact#} instead of <code>/</code>.
846 </li>850 </li>
847 </ul>851 </ul>
848 </td>852 </td>
...@@ -855,17 +859,17 @@ a /= b</code></pre></td>...@@ -855,17 +859,17 @@ a /= b</code></pre></td>
855a %= b</code></pre></td>859a %= b</code></pre></td>
856 <td>860 <td>
857 <ul>861 <ul>
858 <li><a href="#integers">Integers</a></li>862 <li>{#link|Integers#}</li>
859 <li><a href="#floats">Floats</a></li>863 <li>{#link|Floats#}</li>
860 </ul>864 </ul>
861 </td>865 </td>
862 <td>Remainder Division.866 <td>Remainder Division.
863 <ul>867 <ul>
864 <li>Can cause <a href="#undef-division-by-zero">division by zero</a> for integers.</li>868 <li>Can cause {#link|Division by Zero#} for integers.</li>
865 <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>869 <li>Can cause {#link|Division by Zero#} for floats in {#link|FloatMode.Optimized Mode|Floating Point Operations#}.</li>
866 <li>For non-compile-time-known signed integers, must use870 <li>For non-compile-time-known signed integers, must use
867 <a href="#builtin-rem">@rem</a> or871 {#link|@rem#} or
868 <a href="#builtin-mod">@mod</a> instead of <code>%</code>.872 {#link|@mod#} instead of <code>%</code>.
869 </li>873 </li>
870 </ul>874 </ul>
871 </td>875 </td>
...@@ -878,13 +882,13 @@ a %= b</code></pre></td>...@@ -878,13 +882,13 @@ a %= b</code></pre></td>
878a &lt;&lt;= b</code></pre></td>882a &lt;&lt;= b</code></pre></td>
879 <td>883 <td>
880 <ul>884 <ul>
881 <li><a href="#integers">Integers</a></li>885 <li>{#link|Integers#}</li>
882 </ul>886 </ul>
883 </td>887 </td>
884 <td>Bit Shift Left.888 <td>Bit Shift Left.
885 <ul>889 <ul>
886 <li>See also <a href="#builtin-shlExact">@shlExact</a>.</li>890 <li>See also {#link|@shlExact#}.</li>
887 <li>See also <a href="#builtin-shlWithOverflow">@shlWithOverflow</a>.</li>891 <li>See also {#link|@shlWithOverflow#}.</li>
888 </ul>892 </ul>
889 </td>893 </td>
890 <td>894 <td>
...@@ -896,12 +900,12 @@ a &lt;&lt;= b</code></pre></td>...@@ -896,12 +900,12 @@ a &lt;&lt;= b</code></pre></td>
896a &gt;&gt;= b</code></pre></td>900a &gt;&gt;= b</code></pre></td>
897 <td>901 <td>
898 <ul>902 <ul>
899 <li><a href="#integers">Integers</a></li>903 <li>{#link|Integers#}</li>
900 </ul>904 </ul>
901 </td>905 </td>
902 <td>Bit Shift Right.906 <td>Bit Shift Right.
903 <ul>907 <ul>
904 <li>See also <a href="#builtin-shrExact">@shrExact</a>.</li>908 <li>See also {#link|@shrExact#}.</li>
905 </ul>909 </ul>
906 </td>910 </td>
907 <td>911 <td>
...@@ -913,7 +917,7 @@ a &gt;&gt;= b</code></pre></td>...@@ -913,7 +917,7 @@ a &gt;&gt;= b</code></pre></td>
913a &amp;= b</code></pre></td>917a &amp;= b</code></pre></td>
914 <td>918 <td>
915 <ul>919 <ul>
916 <li><a href="#integers">Integers</a></li>920 <li>{#link|Integers#}</li>
917 </ul>921 </ul>
918 </td>922 </td>
919 <td>Bitwise AND.923 <td>Bitwise AND.
...@@ -927,7 +931,7 @@ a &amp;= b</code></pre></td>...@@ -927,7 +931,7 @@ a &amp;= b</code></pre></td>
927a |= b</code></pre></td>931a |= b</code></pre></td>
928 <td>932 <td>
929 <ul>933 <ul>
930 <li><a href="#integers">Integers</a></li>934 <li>{#link|Integers#}</li>
931 </ul>935 </ul>
932 </td>936 </td>
933 <td>Bitwise OR.937 <td>Bitwise OR.
...@@ -941,7 +945,7 @@ a |= b</code></pre></td>...@@ -941,7 +945,7 @@ a |= b</code></pre></td>
941a ^= b</code></pre></td>945a ^= b</code></pre></td>
942 <td>946 <td>
943 <ul>947 <ul>
944 <li><a href="#integers">Integers</a></li>948 <li>{#link|Integers#}</li>
945 </ul>949 </ul>
946 </td>950 </td>
947 <td>Bitwise XOR.951 <td>Bitwise XOR.
...@@ -954,7 +958,7 @@ a ^= b</code></pre></td>...@@ -954,7 +958,7 @@ a ^= b</code></pre></td>
954 <td><pre><code class="zig">~a<code></pre></td>958 <td><pre><code class="zig">~a<code></pre></td>
955 <td>959 <td>
956 <ul>960 <ul>
957 <li><a href="#integers">Integers</a></li>961 <li>{#link|Integers#}</li>
958 </ul>962 </ul>
959 </td>963 </td>
960 <td>964 <td>
...@@ -968,13 +972,13 @@ a ^= b</code></pre></td>...@@ -968,13 +972,13 @@ a ^= b</code></pre></td>
968 <td><pre><code class="zig">a ?? b</code></pre></td>972 <td><pre><code class="zig">a ?? b</code></pre></td>
969 <td>973 <td>
970 <ul>974 <ul>
971 <li><a href="#nullables">Nullables</a></li>975 <li>{#link|Nullables#}</li>
972 </ul>976 </ul>
973 </td>977 </td>
974 <td>If <code>a</code> is <code>null</code>,978 <td>If <code>a</code> is <code>null</code>,
975 returns <code>b</code> ("default value"),979 returns <code>b</code> ("default value"),
976 otherwise returns the unwrapped value of <code>a</code>.980 otherwise returns the unwrapped value of <code>a</code>.
977 Note that <code>b</code> may be a value of type <a href="#noreturn">noreturn</a>.981 Note that <code>b</code> may be a value of type {#link|noreturn#}.
978 </td>982 </td>
979 <td>983 <td>
980 <pre><code class="zig">const value: ?u32 = null;984 <pre><code class="zig">const value: ?u32 = null;
...@@ -986,7 +990,7 @@ unwrapped == 1234</code></pre>...@@ -986,7 +990,7 @@ unwrapped == 1234</code></pre>
986 <td><pre><code class="zig">??a</code></pre></td>990 <td><pre><code class="zig">??a</code></pre></td>
987 <td>991 <td>
988 <ul>992 <ul>
989 <li><a href="#nullables">Nullables</a></li>993 <li>{#link|Nullables#}</li>
990 </ul>994 </ul>
991 </td>995 </td>
992 <td>996 <td>
...@@ -1003,13 +1007,13 @@ unwrapped == 1234</code></pre>...@@ -1003,13 +1007,13 @@ unwrapped == 1234</code></pre>
1003a catch |err| b</code></pre></td>1007a catch |err| b</code></pre></td>
1004 <td>1008 <td>
1005 <ul>1009 <ul>
1006 <li><a href="#errors">Error Unions</a></li>1010 <li>{#link|Error Unions|Errors#}</li>
1007 </ul>1011 </ul>
1008 </td>1012 </td>
1009 <td>If <code>a</code> is an <code>error</code>,1013 <td>If <code>a</code> is an <code>error</code>,
1010 returns <code>b</code> ("default value"),1014 returns <code>b</code> ("default value"),
1011 otherwise returns the unwrapped value of <code>a</code>.1015 otherwise returns the unwrapped value of <code>a</code>.
1012 Note that <code>b</code> may be a value of type <a href="#noreturn">noreturn</a>.1016 Note that <code>b</code> may be a value of type {#link|noreturn#}.
1013 <code>err</code> is the <code>error</code> and is in scope of the expression <code>b</code>.1017 <code>err</code> is the <code>error</code> and is in scope of the expression <code>b</code>.
1014 </td>1018 </td>
1015 <td>1019 <td>
...@@ -1022,7 +1026,7 @@ unwrapped == 1234</code></pre>...@@ -1022,7 +1026,7 @@ unwrapped == 1234</code></pre>
1022 <td><pre><code class="zig">a and b<code></pre></td>1026 <td><pre><code class="zig">a and b<code></pre></td>
1023 <td>1027 <td>
1024 <ul>1028 <ul>
1025 <li><a href="#primitive-types">bool</a></li>1029 <li>{#link|bool|Primitive Types#}</li>
1026 </ul>1030 </ul>
1027 </td>1031 </td>
1028 <td>1032 <td>
...@@ -1037,7 +1041,7 @@ unwrapped == 1234</code></pre>...@@ -1037,7 +1041,7 @@ unwrapped == 1234</code></pre>
1037 <td><pre><code class="zig">a or b<code></pre></td>1041 <td><pre><code class="zig">a or b<code></pre></td>
1038 <td>1042 <td>
1039 <ul>1043 <ul>
1040 <li><a href="#primitive-types">bool</a></li>1044 <li>{#link|bool|Primitive Types#}</li>
1041 </ul>1045 </ul>
1042 </td>1046 </td>
1043 <td>1047 <td>
...@@ -1052,7 +1056,7 @@ unwrapped == 1234</code></pre>...@@ -1052,7 +1056,7 @@ unwrapped == 1234</code></pre>
1052 <td><pre><code class="zig">!a<code></pre></td>1056 <td><pre><code class="zig">!a<code></pre></td>
1053 <td>1057 <td>
1054 <ul>1058 <ul>
1055 <li><a href="#primitive-types">bool</a></li>1059 <li>{#link|bool|Primitive Types#}</li>
1056 </ul>1060 </ul>
1057 </td>1061 </td>
1058 <td>1062 <td>
...@@ -1066,10 +1070,10 @@ unwrapped == 1234</code></pre>...@@ -1066,10 +1070,10 @@ unwrapped == 1234</code></pre>
1066 <td><pre><code class="zig">a == b<code></pre></td>1070 <td><pre><code class="zig">a == b<code></pre></td>
1067 <td>1071 <td>
1068 <ul>1072 <ul>
1069 <li><a href="#integers">Integers</a></li>1073 <li>{#link|Integers#}</li>
1070 <li><a href="#floats">Floats</a></li>1074 <li>{#link|Floats#}</li>
1071 <li><a href="#primitive-types">bool</a></li>1075 <li>{#link|bool|Primitive Types#}</li>
1072 <li><a href="#primitive-types">type</a></li>1076 <li>{#link|type|Primitive Types#}</li>
1073 </ul>1077 </ul>
1074 </td>1078 </td>
1075 <td>1079 <td>
...@@ -1083,7 +1087,7 @@ unwrapped == 1234</code></pre>...@@ -1083,7 +1087,7 @@ unwrapped == 1234</code></pre>
1083 <td><pre><code class="zig">a == null<code></pre></td>1087 <td><pre><code class="zig">a == null<code></pre></td>
1084 <td>1088 <td>
1085 <ul>1089 <ul>
1086 <li><a href="#nullables">Nullables</a></li>1090 <li>{#link|Nullables#}</li>
1087 </ul>1091 </ul>
1088 </td>1092 </td>
1089 <td>1093 <td>
...@@ -1098,10 +1102,10 @@ value == null</code></pre>...@@ -1098,10 +1102,10 @@ value == null</code></pre>
1098 <td><pre><code class="zig">a != b<code></pre></td>1102 <td><pre><code class="zig">a != b<code></pre></td>
1099 <td>1103 <td>
1100 <ul>1104 <ul>
1101 <li><a href="#integers">Integers</a></li>1105 <li>{#link|Integers#}</li>
1102 <li><a href="#floats">Floats</a></li>1106 <li>{#link|Floats#}</li>
1103 <li><a href="#primitive-types">bool</a></li>1107 <li>{#link|bool|Primitive Types#}</li>
1104 <li><a href="#primitive-types">type</a></li>1108 <li>{#link|type|Primitive Types#}</li>
1105 </ul>1109 </ul>
1106 </td>1110 </td>
1107 <td>1111 <td>
...@@ -1115,8 +1119,8 @@ value == null</code></pre>...@@ -1115,8 +1119,8 @@ value == null</code></pre>
1115 <td><pre><code class="zig">a &gt; b<code></pre></td>1119 <td><pre><code class="zig">a &gt; b<code></pre></td>
1116 <td>1120 <td>
1117 <ul>1121 <ul>
1118 <li><a href="#integers">Integers</a></li>1122 <li>{#link|Integers#}</li>
1119 <li><a href="#floats">Floats</a></li>1123 <li>{#link|Floats#}</li>
1120 </ul>1124 </ul>
1121 </td>1125 </td>
1122 <td>1126 <td>
...@@ -1130,8 +1134,8 @@ value == null</code></pre>...@@ -1130,8 +1134,8 @@ value == null</code></pre>
1130 <td><pre><code class="zig">a &gt;= b<code></pre></td>1134 <td><pre><code class="zig">a &gt;= b<code></pre></td>
1131 <td>1135 <td>
1132 <ul>1136 <ul>
1133 <li><a href="#integers">Integers</a></li>1137 <li>{#link|Integers#}</li>
1134 <li><a href="#floats">Floats</a></li>1138 <li>{#link|Floats#}</li>
1135 </ul>1139 </ul>
1136 </td>1140 </td>
1137 <td>1141 <td>
...@@ -1145,8 +1149,8 @@ value == null</code></pre>...@@ -1145,8 +1149,8 @@ value == null</code></pre>
1145 <td><pre><code class="zig">a &lt; b<code></pre></td>1149 <td><pre><code class="zig">a &lt; b<code></pre></td>
1146 <td>1150 <td>
1147 <ul>1151 <ul>
1148 <li><a href="#integers">Integers</a></li>1152 <li>{#link|Integers#}</li>
1149 <li><a href="#floats">Floats</a></li>1153 <li>{#link|Floats#}</li>
1150 </ul>1154 </ul>
1151 </td>1155 </td>
1152 <td>1156 <td>
...@@ -1160,8 +1164,8 @@ value == null</code></pre>...@@ -1160,8 +1164,8 @@ value == null</code></pre>
1160 <td><pre><code class="zig">a &lt;= b<code></pre></td>1164 <td><pre><code class="zig">a &lt;= b<code></pre></td>
1161 <td>1165 <td>
1162 <ul>1166 <ul>
1163 <li><a href="#integers">Integers</a></li>1167 <li>{#link|Integers#}</li>
1164 <li><a href="#floats">Floats</a></li>1168 <li>{#link|Floats#}</li>
1165 </ul>1169 </ul>
1166 </td>1170 </td>
1167 <td>1171 <td>
...@@ -1175,13 +1179,13 @@ value == null</code></pre>...@@ -1175,13 +1179,13 @@ value == null</code></pre>
1175 <td><pre><code class="zig">a ++ b<code></pre></td>1179 <td><pre><code class="zig">a ++ b<code></pre></td>
1176 <td>1180 <td>
1177 <ul>1181 <ul>
1178 <li><a href="#arrays">Arrays</a></li>1182 <li>{#link|Arrays#}</li>
1179 </ul>1183 </ul>
1180 </td>1184 </td>
1181 <td>1185 <td>
1182 Array concatenation.1186 Array concatenation.
1183 <ul>1187 <ul>
1184 <li>Only available when <code>a</code> and <code>b</code> are <a href="#comptime">compile-time known</a>.1188 <li>Only available when <code>a</code> and <code>b</code> are {#link|compile-time known|comptime#}.
1185 </ul>1189 </ul>
1186 </td>1190 </td>
1187 <td>1191 <td>
...@@ -1196,13 +1200,13 @@ mem.eql(u32, together, []u32{1,2,3,4})</code></pre>...@@ -1196,13 +1200,13 @@ mem.eql(u32, together, []u32{1,2,3,4})</code></pre>
1196 <td><pre><code class="zig">a ** b<code></pre></td>1200 <td><pre><code class="zig">a ** b<code></pre></td>
1197 <td>1201 <td>
1198 <ul>1202 <ul>
1199 <li><a href="#arrays">Arrays</a></li>1203 <li>{#link|Arrays#}</li>
1200 </ul>1204 </ul>
1201 </td>1205 </td>
1202 <td>1206 <td>
1203 Array multiplication.1207 Array multiplication.
1204 <ul>1208 <ul>
1205 <li>Only available when <code>a</code> and <code>b</code> are <a href="#comptime">compile-time known</a>.1209 <li>Only available when <code>a</code> and <code>b</code> are {#link|compile-time known|comptime#}.
1206 </ul>1210 </ul>
1207 </td>1211 </td>
1208 <td>1212 <td>
...@@ -1215,7 +1219,7 @@ mem.eql(u8, pattern, "ababab")</code></pre>...@@ -1215,7 +1219,7 @@ mem.eql(u8, pattern, "ababab")</code></pre>
1215 <td><pre><code class="zig">*a<code></pre></td>1219 <td><pre><code class="zig">*a<code></pre></td>
1216 <td>1220 <td>
1217 <ul>1221 <ul>
1218 <li><a href="#pointers">Pointers</a></li>1222 <li>{#link|Pointers#}</li>
1219 </ul>1223 </ul>
1220 </td>1224 </td>
1221 <td>1225 <td>
...@@ -1504,7 +1508,7 @@ test "pointer child type" {...@@ -1504,7 +1508,7 @@ test "pointer child type" {
1504 Each type has an <strong>alignment</strong> - a number of bytes such that,1508 Each type has an <strong>alignment</strong> - a number of bytes such that,
1505 when a value of the type is loaded from or stored to memory,1509 when a value of the type is loaded from or stored to memory,
1506 the memory address must be evenly divisible by this number. You can use1510 the memory address must be evenly divisible by this number. You can use
1507 <a href="#builtin-alignOf">@alignOf</a> to find out this value for any type.1511 {#link|@alignOf#} to find out this value for any type.
1508 </p>1512 </p>
1509 <p>1513 <p>
1510 Alignment depends on the CPU architecture, but is always a power of two, and1514 Alignment depends on the CPU architecture, but is always a power of two, and
...@@ -1562,9 +1566,9 @@ test "function alignment" {...@@ -1562,9 +1566,9 @@ test "function alignment" {
1562 {#code_end#}1566 {#code_end#}
1563 <p>1567 <p>
1564 If you have a pointer or a slice that has a small alignment, but you know that it actually1568 If you have a pointer or a slice that has a small alignment, but you know that it actually
1565 has a bigger alignment, use <a href="#builtin-alignCast">@alignCast</a> to change the1569 has a bigger alignment, use {#link|@alignCast#} to change the
1566 pointer into a more aligned pointer. This is a no-op at runtime, but inserts a1570 pointer into a more aligned pointer. This is a no-op at runtime, but inserts a
1567 <a href="#undef-incorrect-pointer-alignment">safety check</a>:1571 {#link|safety check|Incorrect Pointer Alignment#}:
1568 </p>1572 </p>
1569 {#code_begin|test_safety|incorrect alignment#}1573 {#code_begin|test_safety|incorrect alignment#}
1570const assert = @import("std").debug.assert;1574const assert = @import("std").debug.assert;
...@@ -1589,7 +1593,7 @@ fn foo(bytes: []u8) -> u32 {...@@ -1589,7 +1593,7 @@ fn foo(bytes: []u8) -> u32 {
1589 </p>1593 </p>
1590 <p>As an example, this code produces undefined behavior:</p>1594 <p>As an example, this code produces undefined behavior:</p>
1591 <pre><code class="zig">*@ptrCast(&amp;u32, f32(12.34))</code></pre>1595 <pre><code class="zig">*@ptrCast(&amp;u32, f32(12.34))</code></pre>
1592 <p>Instead, use <a href="#builtin-bitCast">@bitCast</a>:1596 <p>Instead, use {#link|@bitCast#}:
1593 <pre><code class="zig">@bitCast(u32, f32(12.34))</code></pre>1597 <pre><code class="zig">@bitCast(u32, f32(12.34))</code></pre>
1594 <p>As an added benefit, the <code>@bitcast</code> version works at compile-time.</p>1598 <p>As an added benefit, the <code>@bitcast</code> version works at compile-time.</p>
1595 {#see_also|Slices|Memory#}1599 {#see_also|Slices|Memory#}
...@@ -3391,7 +3395,7 @@ test "fibonacci" {...@@ -3391,7 +3395,7 @@ test "fibonacci" {
3391 The compiler noticed that evaluating this function at compile-time took a long time,3395 The compiler noticed that evaluating this function at compile-time took a long time,
3392 and thus emitted a compile error and gave up. If the programmer wants to increase3396 and thus emitted a compile error and gave up. If the programmer wants to increase
3393 the budget for compile-time computation, they can use a built-in function called3397 the budget for compile-time computation, they can use a built-in function called
3394 <a href="#builtin-setEvalBranchQuota">@setEvalBranchQuota</a> to change the default number 1000 to something else.3398 {#link|@setEvalBranchQuota#} to change the default number 1000 to something else.
3395 </p>3399 </p>
3396 <p>3400 <p>
3397 What if we fix the base case, but put the wrong value in the <code>assert</code> line?3401 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() {...@@ -3750,7 +3754,7 @@ pub fn main() {
3750 <code>?fn()</code>, or <code>[]T</code>. It returns the same type as <code>ptr</code>3754 <code>?fn()</code>, or <code>[]T</code>. It returns the same type as <code>ptr</code>
3751 except with the alignment adjusted to the new value.3755 except with the alignment adjusted to the new value.
3752 </p>3756 </p>
3753 <p>A <a href="#undef-incorrect-pointer-alignment">pointer alignment safety check</a> is added3757 <p>A {#link|pointer alignment safety check|Incorrect Pointer Alignment#} is added
3754 to the generated code to make sure the pointer is aligned as promised.</p>3758 to the generated code to make sure the pointer is aligned as promised.</p>
37553759
3756 {#header_close#}3760 {#header_close#}
...@@ -3767,7 +3771,7 @@ comptime {...@@ -3767,7 +3771,7 @@ comptime {
3767}</code></pre>3771}</code></pre>
3768 <p>3772 <p>
3769 The result is a target-specific compile time constant. It is guaranteed to be3773 The result is a target-specific compile time constant. It is guaranteed to be
3770 less than or equal to <a href="#builtin-sizeOf">@sizeOf(T)</a>.3774 less than or equal to {#link|@sizeOf(T)|@sizeOf#}.
3771 </p>3775 </p>
3772 {#see_also|Alignment#}3776 {#see_also|Alignment#}
3773 {#header_close#}3777 {#header_close#}
...@@ -4109,7 +4113,7 @@ fn add(a: i32, b: i32) -> i32 { return a + b; }...@@ -4109,7 +4113,7 @@ fn add(a: i32, b: i32) -> i32 { return a + b; }
4109 {#header_open|@intToPtr#}4113 {#header_open|@intToPtr#}
4110 <pre><code class="zig">@intToPtr(comptime DestType: type, int: usize) -&gt; DestType</code></pre>4114 <pre><code class="zig">@intToPtr(comptime DestType: type, int: usize) -&gt; DestType</code></pre>
4111 <p>4115 <p>
4112 Converts an integer to a pointer. To convert the other way, use <a href="#builtin-ptrToInt">@ptrToInt</a>.4116 Converts an integer to a pointer. To convert the other way, use {#link|@ptrToInt#}.
4113 </p>4117 </p>
4114 {#header_close#}4118 {#header_close#}
4115 {#header_open|@IntType#}4119 {#header_open|@IntType#}
...@@ -4286,7 +4290,7 @@ test "call foo" {...@@ -4286,7 +4290,7 @@ test "call foo" {
4286 <li><code>fn()</code></li>4290 <li><code>fn()</code></li>
4287 <li><code>?fn()</code></li>4291 <li><code>?fn()</code></li>
4288 </ul>4292 </ul>
4289 <p>To convert the other way, use <a href="#builtin-intToPtr">@intToPtr</a></p>4293 <p>To convert the other way, use {#link|@intToPtr#}</p>
42904294
4291 {#header_close#}4295 {#header_close#}
4292 {#header_open|@rem#}4296 {#header_open|@rem#}
...@@ -4539,9 +4543,9 @@ pub const TypeId = enum {...@@ -4539,9 +4543,9 @@ pub const TypeId = enum {
4539 Zig has three build modes:4543 Zig has three build modes:
4540 </p>4544 </p>
4541 <ul>4545 <ul>
4542 <li><a href="#build-mode-debug">Debug</a> (default)</li>4546 <li>{#link|Debug#} (default)</li>
4543 <li><a href="#build-mode-release-fast">ReleaseFast</a></li>4547 <li>{#link|ReleaseFast#}</li>
4544 <li><a href="#build-mode-release-safe">ReleaseSafe</a></li>4548 <li>{#link|ReleaseSafe#}</li>
4545 </ul>4549 </ul>
4546 <p>4550 <p>
4547 To add standard build options to a <code>build.zig</code> file:4551 To add standard build options to a <code>build.zig</code> file:
...@@ -4592,7 +4596,7 @@ pub fn build(b: &Builder) -> %void {...@@ -4592,7 +4596,7 @@ pub fn build(b: &Builder) -> %void {
4592 detected at compile-time, Zig emits an error. Most undefined behavior that4596 detected at compile-time, Zig emits an error. Most undefined behavior that
4593 cannot be detected at compile-time can be detected at runtime. In these cases,4597 cannot be detected at compile-time can be detected at runtime. In these cases,
4594 Zig has safety checks. Safety checks can be disabled on a per-block basis4598 Zig has safety checks. Safety checks can be disabled on a per-block basis
4595 with <code>@setDebugSafety</code>. The <a href="#build-mode-release-fast">ReleaseFast</a>4599 with <code>@setDebugSafety</code>. The {#link|ReleaseFast#}
4596 build mode disables all safety checks in order to facilitate optimizations.4600 build mode disables all safety checks in order to facilitate optimizations.
4597 </p>4601 </p>
4598 <p>4602 <p>