aboutsummaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2020-03-19 22:19:24 -0400
committerAndrew Kelley <andrew@ziglang.org>2020-03-19 22:19:24 -0400
commit53b5aa812bd9c0229054121a1c196c9b18994d64 (patch)
tree3c2961c8b70690351a25d3cee22fd52bbb11a60f /doc
parent75bda408cd69f3d3b0cdb00caa26eb8cbeab5f3e (diff)
parent28a6c136e9dc9bcf3e04ab0aa38edc21918c78b9 (diff)
downloadzig-53b5aa812bd9c0229054121a1c196c9b18994d64.tar.gz
zig-53b5aa812bd9c0229054121a1c196c9b18994d64.zip
Merge remote-tracking branch 'origin/master' into llvm10
Diffstat (limited to 'doc')
-rw-r--r--doc/docgen.zig22
-rw-r--r--doc/langref.html.in36
2 files changed, 35 insertions, 23 deletions
diff --git a/doc/docgen.zig b/doc/docgen.zig
index 4d2625f54f..32ad0cdc5d 100644
--- a/doc/docgen.zig
+++ b/doc/docgen.zig
@@ -48,7 +48,7 @@ pub fn main() !void {
var toc = try genToc(allocator, &tokenizer);
try fs.cwd().makePath(tmp_dir_name);
- defer fs.deleteTree(tmp_dir_name) catch {};
+ defer fs.cwd().deleteTree(tmp_dir_name) catch {};
try genHtml(allocator, &tokenizer, &toc, buffered_out_stream.outStream(), zig_exe);
try buffered_out_stream.flush();
@@ -1096,6 +1096,9 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
try build_args.append("-lc");
try out.print(" -lc", .{});
}
+ const target = try std.zig.CrossTarget.parse(.{
+ .arch_os_abi = code.target_str orelse "native",
+ });
if (code.target_str) |triple| {
try build_args.appendSlice(&[_][]const u8{ "-target", triple });
if (!code.is_inline) {
@@ -1150,7 +1153,15 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
}
}
- const path_to_exe = mem.trim(u8, exec_result.stdout, " \r\n");
+ const path_to_exe_dir = mem.trim(u8, exec_result.stdout, " \r\n");
+ const path_to_exe_basename = try std.fmt.allocPrint(allocator, "{}{}", .{
+ code.name,
+ target.exeFileExt(),
+ });
+ const path_to_exe = try fs.path.join(allocator, &[_][]const u8{
+ path_to_exe_dir,
+ path_to_exe_basename,
+ });
const run_args = &[_][]const u8{path_to_exe};
var exited_with_signal = false;
@@ -1486,7 +1497,12 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
}
fn exec(allocator: *mem.Allocator, env_map: *std.BufMap, args: []const []const u8) !ChildProcess.ExecResult {
- const result = try ChildProcess.exec(allocator, args, null, env_map, max_doc_file_size);
+ const result = try ChildProcess.exec2(.{
+ .allocator = allocator,
+ .argv = args,
+ .env_map = env_map,
+ .max_output_bytes = max_doc_file_size,
+ });
switch (result.term) {
.Exited => |exit_code| {
if (exit_code != 0) {
diff --git a/doc/langref.html.in b/doc/langref.html.in
index 83e96d5c95..2e13367a00 100644
--- a/doc/langref.html.in
+++ b/doc/langref.html.in
@@ -2093,8 +2093,9 @@ var foo: u8 align(4) = 100;
test "global variable alignment" {
assert(@TypeOf(&foo).alignment == 4);
assert(@TypeOf(&foo) == *align(4) u8);
- const slice = @as(*[1]u8, &foo)[0..];
- assert(@TypeOf(slice) == []align(4) u8);
+ const as_pointer_to_array: *[1]u8 = &foo;
+ const as_slice: []u8 = as_pointer_to_array;
+ assert(@TypeOf(as_slice) == []align(4) u8);
}
fn derp() align(@sizeOf(usize) * 2) i32 { return 1234; }
@@ -2187,7 +2188,8 @@ test "basic slices" {
// a slice is that the array's length is part of the type and known at
// compile-time, whereas the slice's length is known at runtime.
// Both can be accessed with the `len` field.
- const slice = array[0..array.len];
+ var known_at_runtime_zero: usize = 0;
+ const slice = array[known_at_runtime_zero..array.len];
assert(&slice[0] == &array[0]);
assert(slice.len == array.len);
@@ -2207,13 +2209,15 @@ test "basic slices" {
{#code_end#}
<p>This is one reason we prefer slices to pointers.</p>
{#code_begin|test|slices#}
-const assert = @import("std").debug.assert;
-const mem = @import("std").mem;
-const fmt = @import("std").fmt;
+const std = @import("std");
+const assert = std.debug.assert;
+const mem = std.mem;
+const fmt = std.fmt;
test "using slices for strings" {
- // Zig has no concept of strings. String literals are arrays of u8, and
- // in general the string type is []u8 (slice of u8).
+ // Zig has no concept of strings. String literals are const pointers to
+ // arrays of u8, and by convention parameters that are "strings" are
+ // expected to be UTF-8 encoded slices of u8.
// Here we coerce [5]u8 to []const u8
const hello: []const u8 = "hello";
const world: []const u8 = "世界";
@@ -2222,7 +2226,7 @@ test "using slices for strings" {
// You can use slice syntax on an array to convert an array into a slice.
const all_together_slice = all_together[0..];
// String concatenation example.
- const hello_world = try fmt.bufPrint(all_together_slice, "{} {}", .{hello, world});
+ const hello_world = try fmt.bufPrint(all_together_slice, "{} {}", .{ hello, world });
// Generally, you can use UTF-8 and not worry about whether something is a
// string. If you don't need to deal with individual characters, no need
@@ -2239,23 +2243,15 @@ test "slice pointer" {
slice[2] = 3;
assert(slice[2] == 3);
// The slice is mutable because we sliced a mutable pointer.
- assert(@TypeOf(slice) == []u8);
+ // Furthermore, it is actually a pointer to an array, since the start
+ // and end indexes were both comptime-known.
+ assert(@TypeOf(slice) == *[5]u8);
// You can also slice a slice:
const slice2 = slice[2..3];
assert(slice2.len == 1);
assert(slice2[0] == 3);
}
-
-test "slice widening" {
- // Zig supports slice widening and slice narrowing. Cast a slice of u8
- // to a slice of anything else, and Zig will perform the length conversion.
- const array align(@alignOf(u32)) = [_]u8{ 0x12, 0x12, 0x12, 0x12, 0x13, 0x13, 0x13, 0x13 };
- const slice = mem.bytesAsSlice(u32, array[0..]);
- assert(slice.len == 2);
- assert(slice[0] == 0x12121212);
- assert(slice[1] == 0x13131313);
-}
{#code_end#}
{#see_also|Pointers|for|Arrays#}