aboutsummaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2020-03-03 09:44:13 -0500
committerAndrew Kelley <andrew@ziglang.org>2020-03-03 09:44:13 -0500
commitd1cb16aace5f5996cf2556d07fd3418a951b31df (patch)
treee154f475be8de6f0b0c486cf1baa1557c3f12b65 /doc
parent3418a332ab3a120f21354d98579d7a3a2dcb523b (diff)
parent387418277a4964714ddaec3336a602ec87dde0f9 (diff)
downloadzig-d1cb16aace5f5996cf2556d07fd3418a951b31df.tar.gz
zig-d1cb16aace5f5996cf2556d07fd3418a951b31df.zip
Merge remote-tracking branch 'origin/master' into llvm10
Diffstat (limited to 'doc')
-rw-r--r--doc/docgen.zig83
-rw-r--r--doc/langref.html.in30
2 files changed, 57 insertions, 56 deletions
diff --git a/doc/docgen.zig b/doc/docgen.zig
index b429c93e65..5d7f2b7b38 100644
--- a/doc/docgen.zig
+++ b/doc/docgen.zig
@@ -1,5 +1,5 @@
-const builtin = @import("builtin");
const std = @import("std");
+const builtin = std.builtin;
const io = std.io;
const fs = std.fs;
const process = std.process;
@@ -10,8 +10,8 @@ const testing = std.testing;
const max_doc_file_size = 10 * 1024 * 1024;
-const exe_ext = @as(std.build.Target, std.build.Target.Native).exeFileExt();
-const obj_ext = @as(std.build.Target, std.build.Target.Native).oFileExt();
+const exe_ext = @as(std.zig.CrossTarget, .{}).exeFileExt();
+const obj_ext = @as(std.zig.CrossTarget, .{}).oFileExt();
const tmp_dir_name = "docgen_tmp";
const test_out_path = tmp_dir_name ++ fs.path.sep_str ++ "test" ++ exe_ext;
@@ -521,7 +521,7 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc {
return parseError(tokenizer, code_kind_tok, "unrecognized code kind: {}", .{code_kind_str});
}
- var mode = builtin.Mode.Debug;
+ var mode: builtin.Mode = .Debug;
var link_objects = std.ArrayList([]const u8).init(allocator);
defer link_objects.deinit();
var target_str: ?[]const u8 = null;
@@ -533,9 +533,9 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc {
const end_code_tag = try eatToken(tokenizer, Token.Id.TagContent);
const end_tag_name = tokenizer.buffer[end_code_tag.start..end_code_tag.end];
if (mem.eql(u8, end_tag_name, "code_release_fast")) {
- mode = builtin.Mode.ReleaseFast;
+ mode = .ReleaseFast;
} else if (mem.eql(u8, end_tag_name, "code_release_safe")) {
- mode = builtin.Mode.ReleaseSafe;
+ mode = .ReleaseSafe;
} else if (mem.eql(u8, end_tag_name, "code_link_object")) {
_ = try eatToken(tokenizer, Token.Id.Separator);
const obj_tok = try eatToken(tokenizer, Token.Id.TagContent);
@@ -1001,30 +1001,30 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
for (toc.nodes) |node| {
switch (node) {
- Node.Content => |data| {
+ .Content => |data| {
try out.write(data);
},
- Node.Link => |info| {
+ .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 => {
+ .Nav => {
try out.write(toc.toc);
},
- Node.Builtin => |tok| {
+ .Builtin => |tok| {
try out.write("<pre>");
try tokenizeAndPrintRaw(tokenizer, out, tok, builtin_code);
try out.write("</pre>");
},
- Node.HeaderOpen => |info| {
+ .HeaderOpen => |info| {
try out.print(
"<h{} id=\"{}\"><a href=\"#toc-{}\">{}</a> <a class=\"hdr\" href=\"#{}\">ยง</a></h{}>\n",
.{ info.n, info.url, info.url, info.name, info.url, info.n },
);
},
- Node.SeeAlso => |items| {
+ .SeeAlso => |items| {
try out.write("<p>See also:</p><ul>\n");
for (items) |item| {
const url = try urlize(allocator, item.name);
@@ -1035,10 +1035,10 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
}
try out.write("</ul>\n");
},
- Node.Syntax => |content_tok| {
+ .Syntax => |content_tok| {
try tokenizeAndPrint(tokenizer, out, content_tok);
},
- Node.Code => |code| {
+ .Code => |code| {
code_progress_index += 1;
warn("docgen example code {}/{}...", .{ code_progress_index, tokenizer.code_node_count });
@@ -1075,16 +1075,16 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
});
try out.print("<pre><code class=\"shell\">$ zig build-exe {}.zig", .{code.name});
switch (code.mode) {
- builtin.Mode.Debug => {},
- builtin.Mode.ReleaseSafe => {
+ .Debug => {},
+ .ReleaseSafe => {
try build_args.append("--release-safe");
try out.print(" --release-safe", .{});
},
- builtin.Mode.ReleaseFast => {
+ .ReleaseFast => {
try build_args.append("--release-fast");
try out.print(" --release-fast", .{});
},
- builtin.Mode.ReleaseSmall => {
+ .ReleaseSmall => {
try build_args.append("--release-small");
try out.print(" --release-small", .{});
},
@@ -1142,13 +1142,14 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
try out.print("\n{}</code></pre>\n", .{colored_stderr});
break :code_block;
}
- const exec_result = exec(allocator, &env_map, build_args.toSliceConst()) catch return parseError(tokenizer, code.source_token, "example failed to compile", .{});
+ const exec_result = exec(allocator, &env_map, build_args.toSliceConst()) catch
+ return parseError(tokenizer, code.source_token, "example failed to compile", .{});
if (code.target_str) |triple| {
if (mem.startsWith(u8, triple, "wasm32") or
mem.startsWith(u8, triple, "riscv64-linux") or
- mem.startsWith(u8, triple, "x86_64-linux") and
- (builtin.os != .linux or builtin.arch != .x86_64))
+ (mem.startsWith(u8, triple, "x86_64-linux") and
+ std.Target.current.os.tag != .linux or std.Target.current.cpu.arch != .x86_64))
{
// skip execution
try out.print("</code></pre>\n", .{});
@@ -1207,16 +1208,16 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
});
try out.print("<pre><code class=\"shell\">$ zig test {}.zig", .{code.name});
switch (code.mode) {
- builtin.Mode.Debug => {},
- builtin.Mode.ReleaseSafe => {
+ .Debug => {},
+ .ReleaseSafe => {
try test_args.append("--release-safe");
try out.print(" --release-safe", .{});
},
- builtin.Mode.ReleaseFast => {
+ .ReleaseFast => {
try test_args.append("--release-fast");
try out.print(" --release-fast", .{});
},
- builtin.Mode.ReleaseSmall => {
+ .ReleaseSmall => {
try test_args.append("--release-small");
try out.print(" --release-small", .{});
},
@@ -1249,16 +1250,16 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
});
try out.print("<pre><code class=\"shell\">$ zig test {}.zig", .{code.name});
switch (code.mode) {
- builtin.Mode.Debug => {},
- builtin.Mode.ReleaseSafe => {
+ .Debug => {},
+ .ReleaseSafe => {
try test_args.append("--release-safe");
try out.print(" --release-safe", .{});
},
- builtin.Mode.ReleaseFast => {
+ .ReleaseFast => {
try test_args.append("--release-fast");
try out.print(" --release-fast", .{});
},
- builtin.Mode.ReleaseSmall => {
+ .ReleaseSmall => {
try test_args.append("--release-small");
try out.print(" --release-small", .{});
},
@@ -1306,16 +1307,16 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
});
var mode_arg: []const u8 = "";
switch (code.mode) {
- builtin.Mode.Debug => {},
- builtin.Mode.ReleaseSafe => {
+ .Debug => {},
+ .ReleaseSafe => {
try test_args.append("--release-safe");
mode_arg = " --release-safe";
},
- builtin.Mode.ReleaseFast => {
+ .ReleaseFast => {
try test_args.append("--release-fast");
mode_arg = " --release-fast";
},
- builtin.Mode.ReleaseSmall => {
+ .ReleaseSmall => {
try test_args.append("--release-small");
mode_arg = " --release-small";
},
@@ -1386,20 +1387,20 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
}
switch (code.mode) {
- builtin.Mode.Debug => {},
- builtin.Mode.ReleaseSafe => {
+ .Debug => {},
+ .ReleaseSafe => {
try build_args.append("--release-safe");
if (!code.is_inline) {
try out.print(" --release-safe", .{});
}
},
- builtin.Mode.ReleaseFast => {
+ .ReleaseFast => {
try build_args.append("--release-fast");
if (!code.is_inline) {
try out.print(" --release-fast", .{});
}
},
- builtin.Mode.ReleaseSmall => {
+ .ReleaseSmall => {
try build_args.append("--release-small");
if (!code.is_inline) {
try out.print(" --release-small", .{});
@@ -1461,16 +1462,16 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
});
try out.print("<pre><code class=\"shell\">$ zig build-lib {}.zig", .{code.name});
switch (code.mode) {
- builtin.Mode.Debug => {},
- builtin.Mode.ReleaseSafe => {
+ .Debug => {},
+ .ReleaseSafe => {
try test_args.append("--release-safe");
try out.print(" --release-safe", .{});
},
- builtin.Mode.ReleaseFast => {
+ .ReleaseFast => {
try test_args.append("--release-fast");
try out.print(" --release-fast", .{});
},
- builtin.Mode.ReleaseSmall => {
+ .ReleaseSmall => {
try test_args.append("--release-small");
try out.print(" --release-small", .{});
},
diff --git a/doc/langref.html.in b/doc/langref.html.in
index e963e39af7..31def074d7 100644
--- a/doc/langref.html.in
+++ b/doc/langref.html.in
@@ -965,7 +965,8 @@ const nan = std.math.nan(f128);
but you can switch to {#syntax#}Optimized{#endsyntax#} mode on a per-block basis:</p>
{#code_begin|obj|foo#}
{#code_release_fast#}
-const builtin = @import("builtin");
+const std = @import("std");
+const builtin = std.builtin;
const big = @as(f64, 1 << 40);
export fn foo_strict(x: f64) f64 {
@@ -2063,15 +2064,15 @@ test "pointer child type" {
alignment of the underlying type, it can be omitted from the type:
</p>
{#code_begin|test#}
-const assert = @import("std").debug.assert;
-const builtin = @import("builtin");
+const std = @import("std");
+const assert = std.debug.assert;
test "variable alignment" {
var x: i32 = 1234;
const align_of_i32 = @alignOf(@TypeOf(x));
assert(@TypeOf(&x) == *i32);
assert(*i32 == *align(align_of_i32) i32);
- if (builtin.arch == builtin.Arch.x86_64) {
+ if (std.Target.current.cpu.arch == .x86_64) {
assert((*i32).alignment == 4);
}
}
@@ -2474,7 +2475,7 @@ test "default struct initialization fields" {
</p>
{#code_begin|test#}
const std = @import("std");
-const builtin = @import("builtin");
+const builtin = std.builtin;
const assert = std.debug.assert;
const Full = packed struct {
@@ -3204,8 +3205,8 @@ test "separate scopes" {
{#header_open|switch#}
{#code_begin|test|switch#}
-const assert = @import("std").debug.assert;
-const builtin = @import("builtin");
+const std = @import("std");
+const assert = std.debug.assert;
test "switch simple" {
const a: u64 = 10;
@@ -3249,16 +3250,16 @@ test "switch simple" {
}
// Switch expressions can be used outside a function:
-const os_msg = switch (builtin.os) {
- builtin.Os.linux => "we found a linux user",
+const os_msg = switch (std.Target.current.os.tag) {
+ .linux => "we found a linux user",
else => "not a linux user",
};
// Inside a function, switch statements implicitly are compile-time
// evaluated if the target expression is compile-time known.
test "switch inside function" {
- switch (builtin.os) {
- builtin.Os.fuchsia => {
+ switch (std.Target.current.os.tag) {
+ .fuchsia => {
// On an OS other than fuchsia, block is not even analyzed,
// so this compile error is not triggered.
// On fuchsia this compile error would be triggered.
@@ -7330,8 +7331,6 @@ test "main" {
the {#syntax#}export{#endsyntax#} keyword used on a function:
</p>
{#code_begin|obj#}
-const builtin = @import("builtin");
-
comptime {
@export(internalName, .{ .name = "foo", .linkage = .Strong });
}
@@ -9363,7 +9362,7 @@ const separator = if (builtin.os == builtin.Os.windows) '\\' else '/';
</p>
{#code_begin|test|detect_test#}
const std = @import("std");
-const builtin = @import("builtin");
+const builtin = std.builtin;
const assert = std.debug.assert;
test "builtin.is_test" {
@@ -9681,7 +9680,8 @@ WebAssembly.instantiate(typedArray, {
<pre><code>$ node test.js
The result is 3</code></pre>
{#header_open|WASI#}
- <p>Zig's support for WebAssembly System Interface (WASI) is under active development. Example of using the standard library and reading command line arguments:</p>
+ <p>Zig's support for WebAssembly System Interface (WASI) is under active development.
+ Example of using the standard library and reading command line arguments:</p>
{#code_begin|exe|wasi#}
{#target_wasi#}
const std = @import("std");