Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run: add output directory arguments #19826

Merged
merged 3 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
72 changes: 36 additions & 36 deletions doc/langref/Assembly Syntax Explained.zig
Original file line number Diff line number Diff line change
Expand Up @@ -15,44 +15,44 @@ pub fn syscall1(number: usize, arg1: usize) usize {
// the below code, this is not used. A literal `%` can be
// obtained by escaping it with a double percent: `%%`.
// Often multiline string syntax comes in handy here.
\\syscall
// Next is the output. It is possible in the future Zig will
// support multiple outputs, depending on how
// https://github.com/ziglang/zig/issues/215 is resolved.
// It is allowed for there to be no outputs, in which case
// this colon would be directly followed by the colon for the inputs.
\\syscall
// Next is the output. It is possible in the future Zig will
// support multiple outputs, depending on how
// https://github.com/ziglang/zig/issues/215 is resolved.
// It is allowed for there to be no outputs, in which case
// this colon would be directly followed by the colon for the inputs.
:
// This specifies the name to be used in `%[ret]` syntax in
// the above assembly string. This example does not use it,
// but the syntax is mandatory.
[ret]
// Next is the output constraint string. This feature is still
// considered unstable in Zig, and so LLVM/GCC documentation
// must be used to understand the semantics.
// http://releases.llvm.org/10.0.0/docs/LangRef.html#inline-asm-constraint-string
// https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html
// In this example, the constraint string means "the result value of
// this inline assembly instruction is whatever is in $rax".
"={rax}"
// Next is either a value binding, or `->` and then a type. The
// type is the result type of the inline assembly expression.
// If it is a value binding, then `%[ret]` syntax would be used
// to refer to the register bound to the value.
(-> usize),
// Next is the list of inputs.
// The constraint for these inputs means, "when the assembly code is
// executed, $rax shall have the value of `number` and $rdi shall have
// the value of `arg1`". Any number of input parameters is allowed,
// including none.
// This specifies the name to be used in `%[ret]` syntax in
// the above assembly string. This example does not use it,
// but the syntax is mandatory.
[ret]
// Next is the output constraint string. This feature is still
// considered unstable in Zig, and so LLVM/GCC documentation
// must be used to understand the semantics.
// http://releases.llvm.org/10.0.0/docs/LangRef.html#inline-asm-constraint-string
// https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html
// In this example, the constraint string means "the result value of
// this inline assembly instruction is whatever is in $rax".
"={rax}"
// Next is either a value binding, or `->` and then a type. The
// type is the result type of the inline assembly expression.
// If it is a value binding, then `%[ret]` syntax would be used
// to refer to the register bound to the value.
(-> usize),
// Next is the list of inputs.
// The constraint for these inputs means, "when the assembly code is
// executed, $rax shall have the value of `number` and $rdi shall have
// the value of `arg1`". Any number of input parameters is allowed,
// including none.
: [number] "{rax}" (number),
[arg1] "{rdi}" (arg1),
// Next is the list of clobbers. These declare a set of registers whose
// values will not be preserved by the execution of this assembly code.
// These do not include output or input registers. The special clobber
// value of "memory" means that the assembly writes to arbitrary undeclared
// memory locations - not only the memory pointed to by a declared indirect
// output. In this example we list $rcx and $r11 because it is known the
// kernel syscall does not preserve these registers.
[arg1] "{rdi}" (arg1),
// Next is the list of clobbers. These declare a set of registers whose
// values will not be preserved by the execution of this assembly code.
// These do not include output or input registers. The special clobber
// value of "memory" means that the assembly writes to arbitrary undeclared
// memory locations - not only the memory pointed to by a declared indirect
// output. In this example we list $rcx and $r11 because it is known the
// kernel syscall does not preserve these registers.
: "rcx", "r11"
);
}
Expand Down
2 changes: 1 addition & 1 deletion doc/langref/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pub fn build(b: *std.Build) void {
const optimize = b.standardOptimizeOption(.{});
const exe = b.addExecutable(.{
.name = "example",
.root_source_file = .{ .path = "example.zig" },
.root_source_file = b.path("example.zig"),
.optimize = optimize,
});
b.default_step.dependOn(&exe.step);
Expand Down
4 changes: 2 additions & 2 deletions doc/langref/build_c.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ const std = @import("std");
pub fn build(b: *std.Build) void {
const lib = b.addSharedLibrary(.{
.name = "mathtest",
.root_source_file = .{ .path = "mathtest.zig" },
.root_source_file = b.path("mathtest.zig"),
.version = .{ .major = 1, .minor = 0, .patch = 0 },
});
const exe = b.addExecutable(.{
.name = "test",
});
exe.addCSourceFile(.{ .file = .{ .path = "test.c" }, .flags = &.{"-std=c99"} });
exe.addCSourceFile(.{ .file = b.path("test.c"), .flags = &.{"-std=c99"} });
exe.linkLibrary(lib);
exe.linkSystemLibrary("c");

Expand Down
4 changes: 2 additions & 2 deletions doc/langref/build_object.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ const std = @import("std");
pub fn build(b: *std.Build) void {
const obj = b.addObject(.{
.name = "base64",
.root_source_file = .{ .path = "base64.zig" },
.root_source_file = b.path("base64.zig"),
});

const exe = b.addExecutable(.{
.name = "test",
});
exe.addCSourceFile(.{ .file = .{ .path = "test.c" }, .flags = &.{"-std=c99",} });
exe.addCSourceFile(.{ .file = b.path("test.c"), .flags = &.{"-std=c99"} });
exe.addObject(obj);
exe.linkSystemLibrary("c");
b.installArtifact(exe);
Expand Down
8 changes: 5 additions & 3 deletions doc/langref/checking_null_in_zig.zig
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
const Foo = struct{};
fn doSomethingWithFoo(foo: *Foo) void { _ = foo; }
const Foo = struct {};
fn doSomethingWithFoo(foo: *Foo) void {
_ = foo;
}

fn doAThing(optional_foo: ?*Foo) void {
// do some stuff

if (optional_foo) |foo| {
doSomethingWithFoo(foo);
doSomethingWithFoo(foo);
}

// do some stuff
Expand Down
2 changes: 1 addition & 1 deletion doc/langref/doc_comments.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/// multiline doc comment).
const Timestamp = struct {
/// The number of seconds since the epoch (this is also a doc comment).
seconds: i64, // signed so we can represent pre-1970 (not a doc comment)
seconds: i64, // signed so we can represent pre-1970 (not a doc comment)
/// The number of nanoseconds past the second (doc comment again).
nanos: u32,

Expand Down
4 changes: 3 additions & 1 deletion doc/langref/enum_export.zig
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const Foo = enum(c_int) { a, b, c };
export fn entry(foo: Foo) void { _ = foo; }
export fn entry(foo: Foo) void {
_ = foo;
}

// obj
4 changes: 3 additions & 1 deletion doc/langref/enum_export_error.zig
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const Foo = enum { a, b, c };
export fn entry(foo: Foo) void { _ = foo; }
export fn entry(foo: Foo) void {
_ = foo;
}

// obj=parameter of type 'enum_export_error.Foo' not allowed in function with calling convention 'C'
6 changes: 3 additions & 3 deletions doc/langref/error_union_parsing_u64.zig
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ pub fn parseU64(buf: []const u8, radix: u8) !u64 {

fn charToDigit(c: u8) u8 {
return switch (c) {
'0' ... '9' => c - '0',
'A' ... 'Z' => c - 'A' + 10,
'a' ... 'z' => c - 'a' + 10,
'0'...'9' => c - '0',
'A'...'Z' => c - 'A' + 10,
'a'...'z' => c - 'a' + 10,
else => maxInt(u8),
};
}
Expand Down
4 changes: 2 additions & 2 deletions doc/langref/identifiers.zig
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ pub extern "c" fn @"error"() void;
pub extern "c" fn @"fstat$INODE64"(fd: c.fd_t, buf: *c.Stat) c_int;

const Color = enum {
red,
@"really red",
red,
@"really red",
};
const color: Color = .@"really red";

Expand Down
2 changes: 1 addition & 1 deletion doc/langref/print.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const a_number: i32 = 1234;
const a_string = "foobar";

pub fn main() void {
print("here is a string: '{s}' here is a number: {}\n", .{a_string, a_number});
print("here is a string: '{s}' here is a number: {}\n", .{ a_string, a_number });
}

// exe=succeed
2 changes: 1 addition & 1 deletion doc/langref/print_comptime-known_format.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const a_string = "foobar";
const fmt = "here is a string: '{s}' here is a number: {}\n";

pub fn main() void {
print(fmt, .{a_string, a_number});
print(fmt, .{ a_string, a_number });
}

// exe=succeed
2 changes: 1 addition & 1 deletion doc/langref/single_value_error_set.zig
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
const err = (error {FileNotFound}).FileNotFound;
const err = (error{FileNotFound}).FileNotFound;

// syntax
20 changes: 10 additions & 10 deletions doc/langref/string_literals.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ const mem = @import("std").mem; // will be used to compare bytes

pub fn main() void {
const bytes = "hello";
print("{}\n", .{@TypeOf(bytes)}); // *const [5:0]u8
print("{d}\n", .{bytes.len}); // 5
print("{c}\n", .{bytes[1]}); // 'e'
print("{d}\n", .{bytes[5]}); // 0
print("{}\n", .{'e' == '\x65'}); // true
print("{d}\n", .{'\u{1f4a9}'}); // 128169
print("{d}\n", .{'💯'}); // 128175
print("{}\n", .{@TypeOf(bytes)}); // *const [5:0]u8
print("{d}\n", .{bytes.len}); // 5
print("{c}\n", .{bytes[1]}); // 'e'
print("{d}\n", .{bytes[5]}); // 0
print("{}\n", .{'e' == '\x65'}); // true
print("{d}\n", .{'\u{1f4a9}'}); // 128169
print("{d}\n", .{'💯'}); // 128175
print("{u}\n", .{'⚡'});
print("{}\n", .{mem.eql(u8, "hello", "h\x65llo")}); // true
print("{}\n", .{mem.eql(u8, "hello", "h\x65llo")}); // true
print("{}\n", .{mem.eql(u8, "💯", "\xf0\x9f\x92\xaf")}); // also true
const invalid_utf8 = "\xff\xfe"; // non-UTF-8 strings are possible with \xNN notation.
const invalid_utf8 = "\xff\xfe"; // non-UTF-8 strings are possible with \xNN notation.
print("0x{x}\n", .{invalid_utf8[1]}); // indexing them returns individual bytes...
print("0x{x}\n", .{"💯"[1]}); // ...as does indexing part-way through non-ASCII characters
print("0x{x}\n", .{"💯"[1]}); // ...as does indexing part-way through non-ASCII characters
}

// exe=succeed
2 changes: 1 addition & 1 deletion doc/langref/test_call_builtin.zig
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const expect = @import("std").testing.expect;

test "noinline function call" {
try expect(@call(.auto, add, .{3, 9}) == 12);
try expect(@call(.auto, add, .{ 3, 9 }) == 12);
}

fn add(a: i32, b: i32) i32 {
Expand Down
4 changes: 2 additions & 2 deletions doc/langref/test_coerce_error_subset_to_superset.zig
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const std = @import("std");

const FileOpenError = error {
const FileOpenError = error{
AccessDenied,
OutOfMemory,
FileNotFound,
};

const AllocationError = error {
const AllocationError = error{
OutOfMemory,
};

Expand Down
4 changes: 2 additions & 2 deletions doc/langref/test_coerce_error_superset_to_subset.zig
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const FileOpenError = error {
const FileOpenError = error{
AccessDenied,
OutOfMemory,
FileNotFound,
};

const AllocationError = error {
const AllocationError = error{
OutOfMemory,
};

Expand Down
8 changes: 4 additions & 4 deletions doc/langref/test_coerce_tuples_arrays.zig
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const std = @import("std");
const expect = std.testing.expect;

const Tuple = struct{ u8, u8 };
const Tuple = struct { u8, u8 };
test "coercion from homogenous tuple to array" {
const tuple: Tuple = .{5, 6};
const array: [2]u8 = tuple;
_ = array;
const tuple: Tuple = .{ 5, 6 };
const array: [2]u8 = tuple;
_ = array;
}

// test
20 changes: 13 additions & 7 deletions doc/langref/test_comptime_evaluation.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,23 @@ const expect = @import("std").testing.expect;

const CmdFn = struct {
name: []const u8,
func: fn(i32) i32,
func: fn (i32) i32,
};

const cmd_fns = [_]CmdFn{
CmdFn {.name = "one", .func = one},
CmdFn {.name = "two", .func = two},
CmdFn {.name = "three", .func = three},
CmdFn{ .name = "one", .func = one },
CmdFn{ .name = "two", .func = two },
CmdFn{ .name = "three", .func = three },
};
fn one(value: i32) i32 { return value + 1; }
fn two(value: i32) i32 { return value + 2; }
fn three(value: i32) i32 { return value + 3; }
fn one(value: i32) i32 {
return value + 1;
}
fn two(value: i32) i32 {
return value + 2;
}
fn three(value: i32) i32 {
return value + 3;
}

fn performFn(comptime prefix_char: u8, start_value: i32) i32 {
var result: i32 = start_value;
Expand Down
4 changes: 1 addition & 3 deletions doc/langref/test_errdefer_loop.zig
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
const std = @import("std");
const Allocator = std.mem.Allocator;

const Foo = struct {
data: *u32
};
const Foo = struct { data: *u32 };

fn getData() !u32 {
return 666;
Expand Down
6 changes: 2 additions & 4 deletions doc/langref/test_errdefer_loop_leak.zig
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
const std = @import("std");
const Allocator = std.mem.Allocator;

const Foo = struct {
data: *u32
};
const Foo = struct { data: *u32 };

fn getData() !u32 {
return 666;
Expand All @@ -19,7 +17,7 @@ fn genFoos(allocator: Allocator, num: usize) ![]Foo {
errdefer allocator.destroy(foo.data);

// The data for the first 3 foos will be leaked
if(i >= 3) return error.TooManyFoos;
if (i >= 3) return error.TooManyFoos;

foo.data.* = try getData();
}
Expand Down
4 changes: 2 additions & 2 deletions doc/langref/test_for.zig
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const expect = @import("std").testing.expect;

test "for basics" {
const items = [_]i32 { 4, 5, 3, 4, 0 };
const items = [_]i32{ 4, 5, 3, 4, 0 };
var sum: i32 = 0;

// For loops iterate over slices and arrays.
Expand Down Expand Up @@ -31,7 +31,7 @@ test "for basics" {

// To iterate over consecutive integers, use the range syntax.
// Unbounded range is always a compile error.
var sum3 : usize = 0;
var sum3: usize = 0;
for (0..5) |i| {
sum3 += i;
}
Expand Down