authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-05-19 10:39:59-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-05-19 10:39:59-04:00
log051ee8e626111445c27d6c868cb0cdec6df7409e
treed144242d665fb7eff76dc3e561989146c84690a1
parentb483db486842c6d7d348b28ca09e56673e1bd800

change slicing syntax from ... to ..

See #359

40 files changed, 164 insertions(+), 158 deletions(-)

doc/langref.md+1-1
...@@ -133,7 +133,7 @@ FnCallExpression = "(" list(Expression, ",") ")"...@@ -133,7 +133,7 @@ FnCallExpression = "(" list(Expression, ",") ")"
133133
134ArrayAccessExpression = "[" Expression "]"134ArrayAccessExpression = "[" Expression "]"
135135
136SliceExpression = "[" Expression "..." option(Expression) "]"136SliceExpression = "[" Expression ".." option(Expression) "]"
137137
138ContainerInitExpression = "{" ContainerInitBody "}"138ContainerInitExpression = "{" ContainerInitBody "}"
139139
example/cat/main.zig+2-2
...@@ -40,7 +40,7 @@ fn cat_stream(is: &io.InStream) -> %void {...@@ -40,7 +40,7 @@ fn cat_stream(is: &io.InStream) -> %void {
40 var buf: [1024 * 4]u8 = undefined;40 var buf: [1024 * 4]u8 = undefined;
4141
42 while (true) {42 while (true) {
43 const bytes_read = is.read(buf[0...]) %% |err| {43 const bytes_read = is.read(buf[0..]) %% |err| {
44 %%io.stderr.printf("Unable to read from stream: {}\n", @errorName(err));44 %%io.stderr.printf("Unable to read from stream: {}\n", @errorName(err));
45 return err;45 return err;
46 };46 };
...@@ -49,7 +49,7 @@ fn cat_stream(is: &io.InStream) -> %void {...@@ -49,7 +49,7 @@ fn cat_stream(is: &io.InStream) -> %void {
49 break;49 break;
50 }50 }
5151
52 io.stdout.write(buf[0...bytes_read]) %% |err| {52 io.stdout.write(buf[0..bytes_read]) %% |err| {
53 %%io.stderr.printf("Unable to write to stdout: {}\n", @errorName(err));53 %%io.stderr.printf("Unable to write to stdout: {}\n", @errorName(err));
54 return err;54 return err;
55 };55 };
example/guess_number/main.zig+3-3
...@@ -8,7 +8,7 @@ pub fn main() -> %void {...@@ -8,7 +8,7 @@ pub fn main() -> %void {
8 %%io.stdout.printf("Welcome to the Guess Number Game in Zig.\n");8 %%io.stdout.printf("Welcome to the Guess Number Game in Zig.\n");
99
10 var seed_bytes: [@sizeOf(usize)]u8 = undefined;10 var seed_bytes: [@sizeOf(usize)]u8 = undefined;
11 %%os.getRandomBytes(seed_bytes[0...]);11 %%os.getRandomBytes(seed_bytes[0..]);
12 const seed = std.mem.readInt(seed_bytes, usize, true);12 const seed = std.mem.readInt(seed_bytes, usize, true);
13 var rand = Rand.init(seed);13 var rand = Rand.init(seed);
1414
...@@ -18,12 +18,12 @@ pub fn main() -> %void {...@@ -18,12 +18,12 @@ pub fn main() -> %void {
18 %%io.stdout.printf("\nGuess a number between 1 and 100: ");18 %%io.stdout.printf("\nGuess a number between 1 and 100: ");
19 var line_buf : [20]u8 = undefined;19 var line_buf : [20]u8 = undefined;
2020
21 const line_len = io.stdin.read(line_buf[0...]) %% |err| {21 const line_len = io.stdin.read(line_buf[0..]) %% |err| {
22 %%io.stdout.printf("Unable to read from stdin: {}\n", @errorName(err));22 %%io.stdout.printf("Unable to read from stdin: {}\n", @errorName(err));
23 return err;23 return err;
24 };24 };
2525
26 const guess = fmt.parseUnsigned(u8, line_buf[0...line_len - 1], 10) %% {26 const guess = fmt.parseUnsigned(u8, line_buf[0..line_len - 1], 10) %% {
27 %%io.stdout.printf("Invalid number.\n");27 %%io.stdout.printf("Invalid number.\n");
28 continue;28 continue;
29 };29 };
example/mix_o_files/base64.zig+2-2
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1const base64 = @import("std").base64;1const base64 = @import("std").base64;
22
3export fn decode_base_64(dest_ptr: &u8, dest_len: usize, source_ptr: &const u8, source_len: usize) -> usize {3export fn decode_base_64(dest_ptr: &u8, dest_len: usize, source_ptr: &const u8, source_len: usize) -> usize {
4 const src = source_ptr[0...source_len];4 const src = source_ptr[0..source_len];
5 const dest = dest_ptr[0...dest_len];5 const dest = dest_ptr[0..dest_len];
6 return base64.decode(dest, src).len;6 return base64.decode(dest, src).len;
7}7}
src/parser.cpp+4-4
...@@ -284,7 +284,7 @@ static AstNode *ast_parse_param_decl(ParseContext *pc, size_t *token_index) {...@@ -284,7 +284,7 @@ static AstNode *ast_parse_param_decl(ParseContext *pc, size_t *token_index) {
284 }284 }
285285
286 Token *ellipsis_tok = &pc->tokens->at(*token_index);286 Token *ellipsis_tok = &pc->tokens->at(*token_index);
287 if (ellipsis_tok->id == TokenIdEllipsis) {287 if (ellipsis_tok->id == TokenIdEllipsis3) {
288 *token_index += 1;288 *token_index += 1;
289 node->data.param_decl.is_var_args = true;289 node->data.param_decl.is_var_args = true;
290 } else {290 } else {
...@@ -879,7 +879,7 @@ static AstNode *ast_parse_suffix_op_expr(ParseContext *pc, size_t *token_index,...@@ -879,7 +879,7 @@ static AstNode *ast_parse_suffix_op_expr(ParseContext *pc, size_t *token_index,
879879
880 Token *ellipsis_or_r_bracket = &pc->tokens->at(*token_index);880 Token *ellipsis_or_r_bracket = &pc->tokens->at(*token_index);
881881
882 if (ellipsis_or_r_bracket->id == TokenIdEllipsis) {882 if (ellipsis_or_r_bracket->id == TokenIdEllipsis2) {
883 *token_index += 1;883 *token_index += 1;
884884
885 AstNode *node = ast_create_node(pc, NodeTypeSliceExpr, first_token);885 AstNode *node = ast_create_node(pc, NodeTypeSliceExpr, first_token);
...@@ -1730,7 +1730,7 @@ static AstNode *ast_parse_for_expr(ParseContext *pc, size_t *token_index, bool m...@@ -1730,7 +1730,7 @@ static AstNode *ast_parse_for_expr(ParseContext *pc, size_t *token_index, bool m
1730/*1730/*
1731SwitchExpression = "switch" "(" Expression ")" "{" many(SwitchProng) "}"1731SwitchExpression = "switch" "(" Expression ")" "{" many(SwitchProng) "}"
1732SwitchProng = (list(SwitchItem, ",") | "else") "=>" option("|" option("*") Symbol "|") Expression ","1732SwitchProng = (list(SwitchItem, ",") | "else") "=>" option("|" option("*") Symbol "|") Expression ","
1733SwitchItem : Expression | (Expression "..." Expression)1733SwitchItem = Expression | (Expression "..." Expression)
1734*/1734*/
1735static AstNode *ast_parse_switch_expr(ParseContext *pc, size_t *token_index, bool mandatory) {1735static AstNode *ast_parse_switch_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
1736 Token *switch_token = &pc->tokens->at(*token_index);1736 Token *switch_token = &pc->tokens->at(*token_index);
...@@ -1767,7 +1767,7 @@ static AstNode *ast_parse_switch_expr(ParseContext *pc, size_t *token_index, boo...@@ -1767,7 +1767,7 @@ static AstNode *ast_parse_switch_expr(ParseContext *pc, size_t *token_index, boo
1767 } else for (;;) {1767 } else for (;;) {
1768 AstNode *expr1 = ast_parse_expression(pc, token_index, true);1768 AstNode *expr1 = ast_parse_expression(pc, token_index, true);
1769 Token *ellipsis_tok = &pc->tokens->at(*token_index);1769 Token *ellipsis_tok = &pc->tokens->at(*token_index);
1770 if (ellipsis_tok->id == TokenIdEllipsis) {1770 if (ellipsis_tok->id == TokenIdEllipsis3) {
1771 *token_index += 1;1771 *token_index += 1;
17721772
1773 AstNode *range_node = ast_create_node(pc, NodeTypeSwitchRange, ellipsis_tok);1773 AstNode *range_node = ast_create_node(pc, NodeTypeSwitchRange, ellipsis_tok);
src/tokenizer.cpp+8-3
...@@ -588,7 +588,7 @@ void tokenize(Buf *buf, Tokenization *out) {...@@ -588,7 +588,7 @@ void tokenize(Buf *buf, Tokenization *out) {
588 switch (c) {588 switch (c) {
589 case '.':589 case '.':
590 t.state = TokenizeStateSawDotDot;590 t.state = TokenizeStateSawDotDot;
591 set_token_id(&t, t.cur_tok, TokenIdEllipsis);591 set_token_id(&t, t.cur_tok, TokenIdEllipsis2);
592 break;592 break;
593 default:593 default:
594 t.pos -= 1;594 t.pos -= 1;
...@@ -601,10 +601,14 @@ void tokenize(Buf *buf, Tokenization *out) {...@@ -601,10 +601,14 @@ void tokenize(Buf *buf, Tokenization *out) {
601 switch (c) {601 switch (c) {
602 case '.':602 case '.':
603 t.state = TokenizeStateStart;603 t.state = TokenizeStateStart;
604 set_token_id(&t, t.cur_tok, TokenIdEllipsis3);
604 end_token(&t);605 end_token(&t);
605 break;606 break;
606 default:607 default:
607 tokenize_error(&t, "invalid character: '%c'", c);608 t.pos -= 1;
609 end_token(&t);
610 t.state = TokenizeStateStart;
611 continue;
608 }612 }
609 break;613 break;
610 case TokenizeStateSawGreaterThan:614 case TokenizeStateSawGreaterThan:
...@@ -1436,7 +1440,8 @@ const char * token_name(TokenId id) {...@@ -1436,7 +1440,8 @@ const char * token_name(TokenId id) {
1436 case TokenIdDivEq: return "/=";1440 case TokenIdDivEq: return "/=";
1437 case TokenIdDot: return ".";1441 case TokenIdDot: return ".";
1438 case TokenIdDoubleQuestion: return "??";1442 case TokenIdDoubleQuestion: return "??";
1439 case TokenIdEllipsis: return "...";1443 case TokenIdEllipsis3: return "...";
1444 case TokenIdEllipsis2: return "..";
1440 case TokenIdEof: return "EOF";1445 case TokenIdEof: return "EOF";
1441 case TokenIdEq: return "=";1446 case TokenIdEq: return "=";
1442 case TokenIdFatArrow: return "=>";1447 case TokenIdFatArrow: return "=>";
src/tokenizer.hpp+2-1
...@@ -40,7 +40,8 @@ enum TokenId {...@@ -40,7 +40,8 @@ enum TokenId {
40 TokenIdDivEq,40 TokenIdDivEq,
41 TokenIdDot,41 TokenIdDot,
42 TokenIdDoubleQuestion,42 TokenIdDoubleQuestion,
43 TokenIdEllipsis,43 TokenIdEllipsis3,
44 TokenIdEllipsis2,
44 TokenIdEof,45 TokenIdEof,
45 TokenIdEq,46 TokenIdEq,
46 TokenIdFatArrow,47 TokenIdFatArrow,
std/array_list.zig+2-2
...@@ -27,11 +27,11 @@ pub fn ArrayList(comptime T: type) -> type{...@@ -27,11 +27,11 @@ pub fn ArrayList(comptime T: type) -> type{
27 }27 }
2828
29 pub fn toSlice(l: &Self) -> []T {29 pub fn toSlice(l: &Self) -> []T {
30 return l.items[0...l.len];30 return l.items[0..l.len];
31 }31 }
3232
33 pub fn toSliceConst(l: &const Self) -> []const T {33 pub fn toSliceConst(l: &const Self) -> []const T {
34 return l.items[0...l.len];34 return l.items[0..l.len];
35 }35 }
3636
37 pub fn append(l: &Self, item: &const T) -> %void {37 pub fn append(l: &Self, item: &const T) -> %void {
std/base64.zig+5-5
...@@ -56,7 +56,7 @@ pub fn encodeWithAlphabet(dest: []u8, source: []const u8, alphabet: []const u8)...@@ -56,7 +56,7 @@ pub fn encodeWithAlphabet(dest: []u8, source: []const u8, alphabet: []const u8)
56 out_index += 1;56 out_index += 1;
57 }57 }
5858
59 return dest[0...out_index];59 return dest[0..out_index];
60}60}
6161
62pub fn decodeWithAlphabet(dest: []u8, source: []const u8, alphabet: []const u8) -> []u8 {62pub fn decodeWithAlphabet(dest: []u8, source: []const u8, alphabet: []const u8) -> []u8 {
...@@ -67,7 +67,7 @@ pub fn decodeWithAlphabet(dest: []u8, source: []const u8, alphabet: []const u8)...@@ -67,7 +67,7 @@ pub fn decodeWithAlphabet(dest: []u8, source: []const u8, alphabet: []const u8)
67 ascii6[c] = u8(i);67 ascii6[c] = u8(i);
68 }68 }
6969
70 return decodeWithAscii6BitMap(dest, source, ascii6[0...], alphabet[64]);70 return decodeWithAscii6BitMap(dest, source, ascii6[0..], alphabet[64]);
71}71}
7272
73pub fn decodeWithAscii6BitMap(dest: []u8, source: []const u8, ascii6: []const u8, pad_char: u8) -> []u8 {73pub fn decodeWithAscii6BitMap(dest: []u8, source: []const u8, ascii6: []const u8, pad_char: u8) -> []u8 {
...@@ -115,7 +115,7 @@ pub fn decodeWithAscii6BitMap(dest: []u8, source: []const u8, ascii6: []const u8...@@ -115,7 +115,7 @@ pub fn decodeWithAscii6BitMap(dest: []u8, source: []const u8, ascii6: []const u8
115 dest_index += 1;115 dest_index += 1;
116 }116 }
117117
118 return dest[0...dest_index];118 return dest[0..dest_index];
119}119}
120120
121pub fn calcEncodedSize(source_len: usize) -> usize {121pub fn calcEncodedSize(source_len: usize) -> usize {
...@@ -174,11 +174,11 @@ fn testBase64Case(expected_decoded: []const u8, expected_encoded: []const u8) {...@@ -174,11 +174,11 @@ fn testBase64Case(expected_decoded: []const u8, expected_encoded: []const u8) {
174174
175 var buf: [100]u8 = undefined;175 var buf: [100]u8 = undefined;
176176
177 const actual_decoded = decode(buf[0...], expected_encoded);177 const actual_decoded = decode(buf[0..], expected_encoded);
178 assert(actual_decoded.len == expected_decoded.len);178 assert(actual_decoded.len == expected_decoded.len);
179 assert(mem.eql(u8, expected_decoded, actual_decoded));179 assert(mem.eql(u8, expected_decoded, actual_decoded));
180180
181 const actual_encoded = encode(buf[0...], expected_decoded);181 const actual_encoded = encode(buf[0..], expected_decoded);
182 assert(actual_encoded.len == expected_encoded.len);182 assert(actual_encoded.len == expected_encoded.len);
183 assert(mem.eql(u8, expected_encoded, actual_encoded));183 assert(mem.eql(u8, expected_encoded, actual_encoded));
184}184}
std/buf_map.zig+1-1
...@@ -58,7 +58,7 @@ pub const BufMap = struct {...@@ -58,7 +58,7 @@ pub const BufMap = struct {
5858
59 fn free(self: &BufMap, value: []const u8) {59 fn free(self: &BufMap, value: []const u8) {
60 // remove the const60 // remove the const
61 const mut_value = @ptrCast(&u8, value.ptr)[0...value.len];61 const mut_value = @ptrCast(&u8, value.ptr)[0..value.len];
62 self.hash_map.allocator.free(mut_value);62 self.hash_map.allocator.free(mut_value);
63 }63 }
6464
std/buf_set.zig+1-1
...@@ -47,7 +47,7 @@ pub const BufSet = struct {...@@ -47,7 +47,7 @@ pub const BufSet = struct {
4747
48 fn free(self: &BufSet, value: []const u8) {48 fn free(self: &BufSet, value: []const u8) {
49 // remove the const49 // remove the const
50 const mut_value = @ptrCast(&u8, value.ptr)[0...value.len];50 const mut_value = @ptrCast(&u8, value.ptr)[0..value.len];
51 self.hash_map.allocator.free(mut_value);51 self.hash_map.allocator.free(mut_value);
52 }52 }
5353
std/buffer.zig+5-5
...@@ -43,11 +43,11 @@ pub const Buffer = struct {...@@ -43,11 +43,11 @@ pub const Buffer = struct {
43 }43 }
4444
45 pub fn toSlice(self: &Buffer) -> []u8 {45 pub fn toSlice(self: &Buffer) -> []u8 {
46 return self.list.toSlice()[0...self.len()];46 return self.list.toSlice()[0..self.len()];
47 }47 }
4848
49 pub fn toSliceConst(self: &const Buffer) -> []const u8 {49 pub fn toSliceConst(self: &const Buffer) -> []const u8 {
50 return self.list.toSliceConst()[0...self.len()];50 return self.list.toSliceConst()[0..self.len()];
51 }51 }
5252
53 pub fn resize(self: &Buffer, new_len: usize) -> %void {53 pub fn resize(self: &Buffer, new_len: usize) -> %void {
...@@ -66,7 +66,7 @@ pub const Buffer = struct {...@@ -66,7 +66,7 @@ pub const Buffer = struct {
66 pub fn append(self: &Buffer, m: []const u8) -> %void {66 pub fn append(self: &Buffer, m: []const u8) -> %void {
67 const old_len = self.len();67 const old_len = self.len();
68 %return self.resize(old_len + m.len);68 %return self.resize(old_len + m.len);
69 mem.copy(u8, self.list.toSlice()[old_len...], m);69 mem.copy(u8, self.list.toSlice()[old_len..], m);
70 }70 }
7171
72 pub fn appendByte(self: &Buffer, byte: u8) -> %void {72 pub fn appendByte(self: &Buffer, byte: u8) -> %void {
...@@ -80,14 +80,14 @@ pub const Buffer = struct {...@@ -80,14 +80,14 @@ pub const Buffer = struct {
8080
81 pub fn startsWith(self: &const Buffer, m: []const u8) -> bool {81 pub fn startsWith(self: &const Buffer, m: []const u8) -> bool {
82 if (self.len() < m.len) return false;82 if (self.len() < m.len) return false;
83 return mem.eql(u8, self.list.items[0...m.len], m);83 return mem.eql(u8, self.list.items[0..m.len], m);
84 }84 }
8585
86 pub fn endsWith(self: &const Buffer, m: []const u8) -> bool {86 pub fn endsWith(self: &const Buffer, m: []const u8) -> bool {
87 const l = self.len();87 const l = self.len();
88 if (l < m.len) return false;88 if (l < m.len) return false;
89 const start = l - m.len;89 const start = l - m.len;
90 return mem.eql(u8, self.list.items[start...], m);90 return mem.eql(u8, self.list.items[start..], m);
91 }91 }
9292
93 pub fn replaceContents(self: &const Buffer, m: []const u8) -> %void {93 pub fn replaceContents(self: &const Buffer, m: []const u8) -> %void {
std/build.zig+1-1
...@@ -335,7 +335,7 @@ pub const Builder = struct {...@@ -335,7 +335,7 @@ pub const Builder = struct {
335 };335 };
336 self.addRPath(rpath);336 self.addRPath(rpath);
337 } else if (word.len > 2 and word[0] == '-' and word[1] == 'L') {337 } else if (word.len > 2 and word[0] == '-' and word[1] == 'L') {
338 const lib_path = word[2...];338 const lib_path = word[2..];
339 self.addLibPath(lib_path);339 self.addLibPath(lib_path);
340 } else {340 } else {
341 %%io.stderr.printf("Unrecognized C flag from NIX_LDFLAGS: {}\n", word);341 %%io.stderr.printf("Unrecognized C flag from NIX_LDFLAGS: {}\n", word);
std/cstr.zig+2-2
...@@ -20,11 +20,11 @@ pub fn cmp(a: &const u8, b: &const u8) -> i8 {...@@ -20,11 +20,11 @@ pub fn cmp(a: &const u8, b: &const u8) -> i8 {
20}20}
2121
22pub fn toSliceConst(str: &const u8) -> []const u8 {22pub fn toSliceConst(str: &const u8) -> []const u8 {
23 return str[0...len(str)];23 return str[0..len(str)];
24}24}
2525
26pub fn toSlice(str: &u8) -> []u8 {26pub fn toSlice(str: &u8) -> []u8 {
27 return str[0...len(str)];27 return str[0..len(str)];
28}28}
2929
30test "cstr fns" {30test "cstr fns" {
std/debug.zig+3-3
...@@ -149,8 +149,8 @@ fn printLineFromFile(allocator: &mem.Allocator, out_stream: &io.OutStream, line_...@@ -149,8 +149,8 @@ fn printLineFromFile(allocator: &mem.Allocator, out_stream: &io.OutStream, line_
149 var column: usize = 1;149 var column: usize = 1;
150 var abs_index: usize = 0;150 var abs_index: usize = 0;
151 while (true) {151 while (true) {
152 const amt_read = %return f.read(buf[0...]);152 const amt_read = %return f.read(buf[0..]);
153 const slice = buf[0...amt_read];153 const slice = buf[0..amt_read];
154154
155 for (slice) |byte| {155 for (slice) |byte| {
156 if (line == line_info.line) {156 if (line == line_info.line) {
...@@ -939,7 +939,7 @@ var some_mem: [100 * 1024]u8 = undefined;...@@ -939,7 +939,7 @@ var some_mem: [100 * 1024]u8 = undefined;
939var some_mem_index: usize = 0;939var some_mem_index: usize = 0;
940940
941fn globalAlloc(self: &mem.Allocator, n: usize) -> %[]u8 {941fn globalAlloc(self: &mem.Allocator, n: usize) -> %[]u8 {
942 const result = some_mem[some_mem_index ... some_mem_index + n];942 const result = some_mem[some_mem_index .. some_mem_index + n];
943 some_mem_index += n;943 some_mem_index += n;
944 return result;944 return result;
945}945}
std/elf.zig+1-1
...@@ -91,7 +91,7 @@ pub const Elf = struct {...@@ -91,7 +91,7 @@ pub const Elf = struct {
91 elf.auto_close_stream = false;91 elf.auto_close_stream = false;
9292
93 var magic: [4]u8 = undefined;93 var magic: [4]u8 = undefined;
94 %return elf.in_stream.readNoEof(magic[0...]);94 %return elf.in_stream.readNoEof(magic[0..]);
95 if (!mem.eql(u8, magic, "\x7fELF")) return error.InvalidFormat;95 if (!mem.eql(u8, magic, "\x7fELF")) return error.InvalidFormat;
9696
97 elf.is_64 = switch (%return elf.in_stream.readByte()) {97 elf.is_64 = switch (%return elf.in_stream.readByte()) {
std/endian.zig+1-1
...@@ -15,6 +15,6 @@ pub fn swapIf(is_be: bool, comptime T: type, x: T) -> T {...@@ -15,6 +15,6 @@ pub fn swapIf(is_be: bool, comptime T: type, x: T) -> T {
1515
16pub fn swap(comptime T: type, x: T) -> T {16pub fn swap(comptime T: type, x: T) -> T {
17 var buf: [@sizeOf(T)]u8 = undefined;17 var buf: [@sizeOf(T)]u8 = undefined;
18 mem.writeInt(buf[0...], x, false);18 mem.writeInt(buf[0..], x, false);
19 return mem.readInt(buf, T, true);19 return mem.readInt(buf, T, true);
20}20}
std/fmt.zig+19-19
...@@ -38,14 +38,14 @@ pub fn format(context: var, output: fn(@typeOf(context), []const u8)->bool,...@@ -38,14 +38,14 @@ pub fn format(context: var, output: fn(@typeOf(context), []const u8)->bool,
38 '{' => {38 '{' => {
39 // TODO if you make this an if statement with `and` then it breaks39 // TODO if you make this an if statement with `and` then it breaks
40 if (start_index < i) {40 if (start_index < i) {
41 if (!output(context, fmt[start_index...i]))41 if (!output(context, fmt[start_index..i]))
42 return false;42 return false;
43 }43 }
44 state = State.OpenBrace;44 state = State.OpenBrace;
45 },45 },
46 '}' => {46 '}' => {
47 if (start_index < i) {47 if (start_index < i) {
48 if (!output(context, fmt[start_index...i]))48 if (!output(context, fmt[start_index..i]))
49 return false;49 return false;
50 }50 }
51 state = State.CloseBrace;51 state = State.CloseBrace;
...@@ -123,7 +123,7 @@ pub fn format(context: var, output: fn(@typeOf(context), []const u8)->bool,...@@ -123,7 +123,7 @@ pub fn format(context: var, output: fn(@typeOf(context), []const u8)->bool,
123 },123 },
124 State.IntegerWidth => switch (c) {124 State.IntegerWidth => switch (c) {
125 '}' => {125 '}' => {
126 width = comptime %%parseUnsigned(usize, fmt[width_start...i], 10);126 width = comptime %%parseUnsigned(usize, fmt[width_start..i], 10);
127 if (!formatInt(args[next_arg], radix, uppercase, width, context, output))127 if (!formatInt(args[next_arg], radix, uppercase, width, context, output))
128 return false;128 return false;
129 next_arg += 1;129 next_arg += 1;
...@@ -135,7 +135,7 @@ pub fn format(context: var, output: fn(@typeOf(context), []const u8)->bool,...@@ -135,7 +135,7 @@ pub fn format(context: var, output: fn(@typeOf(context), []const u8)->bool,
135 },135 },
136 State.BufWidth => switch (c) {136 State.BufWidth => switch (c) {
137 '}' => {137 '}' => {
138 width = comptime %%parseUnsigned(usize, fmt[width_start...i], 10);138 width = comptime %%parseUnsigned(usize, fmt[width_start..i], 10);
139 if (!formatBuf(args[next_arg], width, context, output))139 if (!formatBuf(args[next_arg], width, context, output))
140 return false;140 return false;
141 next_arg += 1;141 next_arg += 1;
...@@ -166,7 +166,7 @@ pub fn format(context: var, output: fn(@typeOf(context), []const u8)->bool,...@@ -166,7 +166,7 @@ pub fn format(context: var, output: fn(@typeOf(context), []const u8)->bool,
166 }166 }
167 }167 }
168 if (start_index < fmt.len) {168 if (start_index < fmt.len) {
169 if (!output(context, fmt[start_index...]))169 if (!output(context, fmt[start_index..]))
170 return false;170 return false;
171 }171 }
172172
...@@ -198,7 +198,7 @@ pub fn formatValue(value: var, context: var, output: fn(@typeOf(context), []cons...@@ -198,7 +198,7 @@ pub fn formatValue(value: var, context: var, output: fn(@typeOf(context), []cons
198}198}
199199
200pub fn formatAsciiChar(c: u8, context: var, output: fn(@typeOf(context), []const u8)->bool) -> bool {200pub fn formatAsciiChar(c: u8, context: var, output: fn(@typeOf(context), []const u8)->bool) -> bool {
201 return output(context, (&c)[0...1]);201 return output(context, (&c)[0..1]);
202}202}
203203
204pub fn formatBuf(buf: []const u8, width: usize,204pub fn formatBuf(buf: []const u8, width: usize,
...@@ -210,7 +210,7 @@ pub fn formatBuf(buf: []const u8, width: usize,...@@ -210,7 +210,7 @@ pub fn formatBuf(buf: []const u8, width: usize,
210 var leftover_padding = if (width > buf.len) (width - buf.len) else return true;210 var leftover_padding = if (width > buf.len) (width - buf.len) else return true;
211 const pad_byte: u8 = ' ';211 const pad_byte: u8 = ' ';
212 while (leftover_padding > 0) : (leftover_padding -= 1) {212 while (leftover_padding > 0) : (leftover_padding -= 1) {
213 if (!output(context, (&pad_byte)[0...1]))213 if (!output(context, (&pad_byte)[0..1]))
214 return false;214 return false;
215 }215 }
216216
...@@ -234,7 +234,7 @@ fn formatIntSigned(value: var, base: u8, uppercase: bool, width: usize,...@@ -234,7 +234,7 @@ fn formatIntSigned(value: var, base: u8, uppercase: bool, width: usize,
234 const uint = @IntType(false, @typeOf(value).bit_count);234 const uint = @IntType(false, @typeOf(value).bit_count);
235 if (value < 0) {235 if (value < 0) {
236 const minus_sign: u8 = '-';236 const minus_sign: u8 = '-';
237 if (!output(context, (&minus_sign)[0...1]))237 if (!output(context, (&minus_sign)[0..1]))
238 return false;238 return false;
239 const new_value = uint(-(value + 1)) + 1;239 const new_value = uint(-(value + 1)) + 1;
240 const new_width = if (width == 0) 0 else (width - 1);240 const new_width = if (width == 0) 0 else (width - 1);
...@@ -243,7 +243,7 @@ fn formatIntSigned(value: var, base: u8, uppercase: bool, width: usize,...@@ -243,7 +243,7 @@ fn formatIntSigned(value: var, base: u8, uppercase: bool, width: usize,
243 return formatIntUnsigned(uint(value), base, uppercase, width, context, output);243 return formatIntUnsigned(uint(value), base, uppercase, width, context, output);
244 } else {244 } else {
245 const plus_sign: u8 = '+';245 const plus_sign: u8 = '+';
246 if (!output(context, (&plus_sign)[0...1]))246 if (!output(context, (&plus_sign)[0..1]))
247 return false;247 return false;
248 const new_value = uint(value);248 const new_value = uint(value);
249 const new_width = if (width == 0) 0 else (width - 1);249 const new_width = if (width == 0) 0 else (width - 1);
...@@ -269,24 +269,24 @@ fn formatIntUnsigned(value: var, base: u8, uppercase: bool, width: usize,...@@ -269,24 +269,24 @@ fn formatIntUnsigned(value: var, base: u8, uppercase: bool, width: usize,
269 break;269 break;
270 }270 }
271271
272 const digits_buf = buf[index...];272 const digits_buf = buf[index..];
273 const padding = if (width > digits_buf.len) (width - digits_buf.len) else 0;273 const padding = if (width > digits_buf.len) (width - digits_buf.len) else 0;
274274
275 if (padding > index) {275 if (padding > index) {
276 const zero_byte: u8 = '0';276 const zero_byte: u8 = '0';
277 var leftover_padding = padding - index;277 var leftover_padding = padding - index;
278 while (true) {278 while (true) {
279 if (!output(context, (&zero_byte)[0...1]))279 if (!output(context, (&zero_byte)[0..1]))
280 return false;280 return false;
281 leftover_padding -= 1;281 leftover_padding -= 1;
282 if (leftover_padding == 0)282 if (leftover_padding == 0)
283 break;283 break;
284 }284 }
285 mem.set(u8, buf[0...index], '0');285 mem.set(u8, buf[0..index], '0');
286 return output(context, buf);286 return output(context, buf);
287 } else {287 } else {
288 const padded_buf = buf[index - padding...];288 const padded_buf = buf[index - padding..];
289 mem.set(u8, padded_buf[0...padding], '0');289 mem.set(u8, padded_buf[0..padding], '0');
290 return output(context, padded_buf);290 return output(context, padded_buf);
291 }291 }
292}292}
...@@ -304,7 +304,7 @@ const FormatIntBuf = struct {...@@ -304,7 +304,7 @@ const FormatIntBuf = struct {
304 index: usize,304 index: usize,
305};305};
306fn formatIntCallback(context: &FormatIntBuf, bytes: []const u8) -> bool {306fn formatIntCallback(context: &FormatIntBuf, bytes: []const u8) -> bool {
307 mem.copy(u8, context.out_buf[context.index...], bytes);307 mem.copy(u8, context.out_buf[context.index..], bytes);
308 context.index += bytes.len;308 context.index += bytes.len;
309 return true;309 return true;
310}310}
...@@ -350,14 +350,14 @@ const BufPrintContext = struct {...@@ -350,14 +350,14 @@ const BufPrintContext = struct {
350350
351fn bufPrintWrite(context: &BufPrintContext, bytes: []const u8) -> bool {351fn bufPrintWrite(context: &BufPrintContext, bytes: []const u8) -> bool {
352 mem.copy(u8, context.remaining, bytes);352 mem.copy(u8, context.remaining, bytes);
353 context.remaining = context.remaining[bytes.len...];353 context.remaining = context.remaining[bytes.len..];
354 return true;354 return true;
355}355}
356356
357pub fn bufPrint(buf: []u8, comptime fmt: []const u8, args: ...) -> []u8 {357pub fn bufPrint(buf: []u8, comptime fmt: []const u8, args: ...) -> []u8 {
358 var context = BufPrintContext { .remaining = buf, };358 var context = BufPrintContext { .remaining = buf, };
359 _ = format(&context, bufPrintWrite, fmt, args);359 _ = format(&context, bufPrintWrite, fmt, args);
360 return buf[0...buf.len - context.remaining.len];360 return buf[0..buf.len - context.remaining.len];
361}361}
362362
363pub fn allocPrint(allocator: &mem.Allocator, comptime fmt: []const u8, args: ...) -> %[]u8 {363pub fn allocPrint(allocator: &mem.Allocator, comptime fmt: []const u8, args: ...) -> %[]u8 {
...@@ -374,7 +374,7 @@ fn countSize(size: &usize, bytes: []const u8) -> bool {...@@ -374,7 +374,7 @@ fn countSize(size: &usize, bytes: []const u8) -> bool {
374374
375test "buf print int" {375test "buf print int" {
376 var buffer: [max_int_digits]u8 = undefined;376 var buffer: [max_int_digits]u8 = undefined;
377 const buf = buffer[0...];377 const buf = buffer[0..];
378 assert(mem.eql(u8, bufPrintIntToSlice(buf, i32(-12345678), 2, false, 0), "-101111000110000101001110"));378 assert(mem.eql(u8, bufPrintIntToSlice(buf, i32(-12345678), 2, false, 0), "-101111000110000101001110"));
379 assert(mem.eql(u8, bufPrintIntToSlice(buf, i32(-12345678), 10, false, 0), "-12345678"));379 assert(mem.eql(u8, bufPrintIntToSlice(buf, i32(-12345678), 10, false, 0), "-12345678"));
380 assert(mem.eql(u8, bufPrintIntToSlice(buf, i32(-12345678), 16, false, 0), "-bc614e"));380 assert(mem.eql(u8, bufPrintIntToSlice(buf, i32(-12345678), 16, false, 0), "-bc614e"));
...@@ -391,7 +391,7 @@ test "buf print int" {...@@ -391,7 +391,7 @@ test "buf print int" {
391}391}
392392
393fn bufPrintIntToSlice(buf: []u8, value: var, base: u8, uppercase: bool, width: usize) -> []u8 {393fn bufPrintIntToSlice(buf: []u8, value: var, base: u8, uppercase: bool, width: usize) -> []u8 {
394 return buf[0...formatIntBuf(buf, value, base, uppercase, width)];394 return buf[0..formatIntBuf(buf, value, base, uppercase, width)];
395}395}
396396
397test "parse u64 digit too big" {397test "parse u64 digit too big" {
std/io.zig+7-7
...@@ -113,7 +113,7 @@ pub const OutStream = struct {...@@ -113,7 +113,7 @@ pub const OutStream = struct {
113 while (src_index < bytes.len) {113 while (src_index < bytes.len) {
114 const dest_space_left = self.buffer.len - self.index;114 const dest_space_left = self.buffer.len - self.index;
115 const copy_amt = math.min(dest_space_left, bytes.len - src_index);115 const copy_amt = math.min(dest_space_left, bytes.len - src_index);
116 mem.copy(u8, self.buffer[self.index...], bytes[src_index...src_index + copy_amt]);116 mem.copy(u8, self.buffer[self.index..], bytes[src_index..src_index + copy_amt]);
117 self.index += copy_amt;117 self.index += copy_amt;
118 assert(self.index <= self.buffer.len);118 assert(self.index <= self.buffer.len);
119 if (self.index == self.buffer.len) {119 if (self.index == self.buffer.len) {
...@@ -152,7 +152,7 @@ pub const OutStream = struct {...@@ -152,7 +152,7 @@ pub const OutStream = struct {
152152
153 pub fn flush(self: &OutStream) -> %void {153 pub fn flush(self: &OutStream) -> %void {
154 if (self.index != 0) {154 if (self.index != 0) {
155 %return os.posixWrite(self.fd, self.buffer[0...self.index]);155 %return os.posixWrite(self.fd, self.buffer[0..self.index]);
156 self.index = 0;156 self.index = 0;
157 }157 }
158 }158 }
...@@ -236,13 +236,13 @@ pub const InStream = struct {...@@ -236,13 +236,13 @@ pub const InStream = struct {
236236
237 pub fn readByte(is: &InStream) -> %u8 {237 pub fn readByte(is: &InStream) -> %u8 {
238 var result: [1]u8 = undefined;238 var result: [1]u8 = undefined;
239 %return is.readNoEof(result[0...]);239 %return is.readNoEof(result[0..]);
240 return result[0];240 return result[0];
241 }241 }
242242
243 pub fn readByteSigned(is: &InStream) -> %i8 {243 pub fn readByteSigned(is: &InStream) -> %i8 {
244 var result: [1]i8 = undefined;244 var result: [1]i8 = undefined;
245 %return is.readNoEof(([]u8)(result[0...]));245 %return is.readNoEof(([]u8)(result[0..]));
246 return result[0];246 return result[0];
247 }247 }
248248
...@@ -256,7 +256,7 @@ pub const InStream = struct {...@@ -256,7 +256,7 @@ pub const InStream = struct {
256256
257 pub fn readInt(is: &InStream, is_be: bool, comptime T: type) -> %T {257 pub fn readInt(is: &InStream, is_be: bool, comptime T: type) -> %T {
258 var bytes: [@sizeOf(T)]u8 = undefined;258 var bytes: [@sizeOf(T)]u8 = undefined;
259 %return is.readNoEof(bytes[0...]);259 %return is.readNoEof(bytes[0..]);
260 return mem.readInt(bytes, T, is_be);260 return mem.readInt(bytes, T, is_be);
261 }261 }
262262
...@@ -264,7 +264,7 @@ pub const InStream = struct {...@@ -264,7 +264,7 @@ pub const InStream = struct {
264 assert(size <= @sizeOf(T));264 assert(size <= @sizeOf(T));
265 assert(size <= 8);265 assert(size <= 8);
266 var input_buf: [8]u8 = undefined;266 var input_buf: [8]u8 = undefined;
267 const input_slice = input_buf[0...size];267 const input_slice = input_buf[0..size];
268 %return is.readNoEof(input_slice);268 %return is.readNoEof(input_slice);
269 return mem.readInt(input_slice, T, is_be);269 return mem.readInt(input_slice, T, is_be);
270 }270 }
...@@ -349,7 +349,7 @@ pub const InStream = struct {...@@ -349,7 +349,7 @@ pub const InStream = struct {
349349
350 var actual_buf_len: usize = 0;350 var actual_buf_len: usize = 0;
351 while (true) {351 while (true) {
352 const dest_slice = buf.toSlice()[actual_buf_len...];352 const dest_slice = buf.toSlice()[actual_buf_len..];
353 const bytes_read = %return is.read(dest_slice);353 const bytes_read = %return is.read(dest_slice);
354 actual_buf_len += bytes_read;354 actual_buf_len += bytes_read;
355355
std/mem.zig+11-11
...@@ -31,7 +31,7 @@ pub const Allocator = struct {...@@ -31,7 +31,7 @@ pub const Allocator = struct {
31 }31 }
3232
33 fn destroy(self: &Allocator, ptr: var) {33 fn destroy(self: &Allocator, ptr: var) {
34 self.free(ptr[0...1]);34 self.free(ptr[0..1]);
35 }35 }
3636
37 fn alloc(self: &Allocator, comptime T: type, n: usize) -> %[]T {37 fn alloc(self: &Allocator, comptime T: type, n: usize) -> %[]T {
...@@ -69,7 +69,7 @@ pub const IncrementingAllocator = struct {...@@ -69,7 +69,7 @@ pub const IncrementingAllocator = struct {
69 .reallocFn = realloc,69 .reallocFn = realloc,
70 .freeFn = free,70 .freeFn = free,
71 },71 },
72 .bytes = @intToPtr(&u8, addr)[0...capacity],72 .bytes = @intToPtr(&u8, addr)[0..capacity],
73 .end_index = 0,73 .end_index = 0,
74 };74 };
75 },75 },
...@@ -87,7 +87,7 @@ pub const IncrementingAllocator = struct {...@@ -87,7 +87,7 @@ pub const IncrementingAllocator = struct {
87 if (new_end_index > self.bytes.len) {87 if (new_end_index > self.bytes.len) {
88 return error.NoMem;88 return error.NoMem;
89 }89 }
90 const result = self.bytes[self.end_index...new_end_index];90 const result = self.bytes[self.end_index..new_end_index];
91 self.end_index = new_end_index;91 self.end_index = new_end_index;
92 return result;92 return result;
93 }93 }
...@@ -165,7 +165,7 @@ pub fn indexOf(comptime T: type, haystack: []const T, needle: []const T) -> ?usi...@@ -165,7 +165,7 @@ pub fn indexOf(comptime T: type, haystack: []const T, needle: []const T) -> ?usi
165 var i: usize = 0;165 var i: usize = 0;
166 const end = haystack.len - needle.len;166 const end = haystack.len - needle.len;
167 while (i <= end) : (i += 1) {167 while (i <= end) : (i += 1) {
168 if (eql(T, haystack[i...i + needle.len], needle))168 if (eql(T, haystack[i .. i + needle.len], needle))
169 return i;169 return i;
170 }170 }
171 return null;171 return null;
...@@ -253,7 +253,7 @@ test "mem.split" {...@@ -253,7 +253,7 @@ test "mem.split" {
253}253}
254254
255pub fn startsWith(comptime T: type, haystack: []const T, needle: []const T) -> bool {255pub fn startsWith(comptime T: type, haystack: []const T, needle: []const T) -> bool {
256 return if (needle.len > haystack.len) false else eql(T, haystack[0...needle.len], needle);256 return if (needle.len > haystack.len) false else eql(T, haystack[0 .. needle.len], needle);
257}257}
258258
259const SplitIterator = struct {259const SplitIterator = struct {
...@@ -273,7 +273,7 @@ const SplitIterator = struct {...@@ -273,7 +273,7 @@ const SplitIterator = struct {
273 while (self.index < self.s.len and self.s[self.index] != self.c) : (self.index += 1) {}273 while (self.index < self.s.len and self.s[self.index] != self.c) : (self.index += 1) {}
274 const end = self.index;274 const end = self.index;
275275
276 return self.s[start...end];276 return self.s[start..end];
277 }277 }
278278
279 /// Returns a slice of the remaining bytes. Does not affect iterator state.279 /// Returns a slice of the remaining bytes. Does not affect iterator state.
...@@ -281,7 +281,7 @@ const SplitIterator = struct {...@@ -281,7 +281,7 @@ const SplitIterator = struct {
281 // move to beginning of token281 // move to beginning of token
282 var index: usize = self.index;282 var index: usize = self.index;
283 while (index < self.s.len and self.s[index] == self.c) : (index += 1) {}283 while (index < self.s.len and self.s[index] == self.c) : (index += 1) {}
284 return self.s[index...];284 return self.s[index..];
285 }285 }
286};286};
287287
...@@ -320,16 +320,16 @@ test "testWriteInt" {...@@ -320,16 +320,16 @@ test "testWriteInt" {
320fn testWriteIntImpl() {320fn testWriteIntImpl() {
321 var bytes: [4]u8 = undefined;321 var bytes: [4]u8 = undefined;
322322
323 writeInt(bytes[0...], u32(0x12345678), true);323 writeInt(bytes[0..], u32(0x12345678), true);
324 assert(eql(u8, bytes, []u8{ 0x12, 0x34, 0x56, 0x78 }));324 assert(eql(u8, bytes, []u8{ 0x12, 0x34, 0x56, 0x78 }));
325325
326 writeInt(bytes[0...], u32(0x78563412), false);326 writeInt(bytes[0..], u32(0x78563412), false);
327 assert(eql(u8, bytes, []u8{ 0x12, 0x34, 0x56, 0x78 }));327 assert(eql(u8, bytes, []u8{ 0x12, 0x34, 0x56, 0x78 }));
328328
329 writeInt(bytes[0...], u16(0x1234), true);329 writeInt(bytes[0..], u16(0x1234), true);
330 assert(eql(u8, bytes, []u8{ 0x00, 0x00, 0x12, 0x34 }));330 assert(eql(u8, bytes, []u8{ 0x00, 0x00, 0x12, 0x34 }));
331331
332 writeInt(bytes[0...], u16(0x1234), false);332 writeInt(bytes[0..], u16(0x1234), false);
333 assert(eql(u8, bytes, []u8{ 0x34, 0x12, 0x00, 0x00 }));333 assert(eql(u8, bytes, []u8{ 0x34, 0x12, 0x00, 0x00 }));
334}334}
335335
std/net.zig+5-5
...@@ -34,7 +34,7 @@ const Connection = struct {...@@ -34,7 +34,7 @@ const Connection = struct {
34 const recv_ret = linux.recvfrom(c.socket_fd, buf.ptr, buf.len, 0, null, null);34 const recv_ret = linux.recvfrom(c.socket_fd, buf.ptr, buf.len, 0, null, null);
35 const recv_err = linux.getErrno(recv_ret);35 const recv_err = linux.getErrno(recv_ret);
36 switch (recv_err) {36 switch (recv_err) {
37 0 => return buf[0...recv_ret],37 0 => return buf[0..recv_ret],
38 errno.EINVAL => unreachable,38 errno.EINVAL => unreachable,
39 errno.EFAULT => unreachable,39 errno.EFAULT => unreachable,
40 errno.ENOTSOCK => return error.NotSocket,40 errno.ENOTSOCK => return error.NotSocket,
...@@ -81,7 +81,7 @@ pub fn lookup(hostname: []const u8, out_addrs: []Address) -> %[]Address {...@@ -81,7 +81,7 @@ pub fn lookup(hostname: []const u8, out_addrs: []Address) -> %[]Address {
81 //switch (parseIpLiteral(hostname)) {81 //switch (parseIpLiteral(hostname)) {
82 // Ok => |addr| {82 // Ok => |addr| {
83 // out_addrs[0] = addr;83 // out_addrs[0] = addr;
84 // return out_addrs[0...1];84 // return out_addrs[0..1];
85 // },85 // },
86 // else => {},86 // else => {},
87 //};87 //};
...@@ -134,7 +134,7 @@ pub fn connectAddr(addr: &Address, port: u16) -> %Connection {...@@ -134,7 +134,7 @@ pub fn connectAddr(addr: &Address, port: u16) -> %Connection {
134134
135pub fn connect(hostname: []const u8, port: u16) -> %Connection {135pub fn connect(hostname: []const u8, port: u16) -> %Connection {
136 var addrs_buf: [1]Address = undefined;136 var addrs_buf: [1]Address = undefined;
137 const addrs_slice = %return lookup(hostname, addrs_buf[0...]);137 const addrs_slice = %return lookup(hostname, addrs_buf[0..]);
138 const main_addr = &addrs_slice[0];138 const main_addr = &addrs_slice[0];
139139
140 return connectAddr(main_addr, port);140 return connectAddr(main_addr, port);
...@@ -186,7 +186,7 @@ fn parseIp6(buf: []const u8) -> %Address {...@@ -186,7 +186,7 @@ fn parseIp6(buf: []const u8) -> %Address {
186 var result: Address = undefined;186 var result: Address = undefined;
187 result.family = linux.AF_INET6;187 result.family = linux.AF_INET6;
188 result.scope_id = 0;188 result.scope_id = 0;
189 const ip_slice = result.addr[0...];189 const ip_slice = result.addr[0..];
190190
191 var x: u16 = 0;191 var x: u16 = 0;
192 var saw_any_digits = false;192 var saw_any_digits = false;
...@@ -280,7 +280,7 @@ fn parseIp6(buf: []const u8) -> %Address {...@@ -280,7 +280,7 @@ fn parseIp6(buf: []const u8) -> %Address {
280280
281fn parseIp4(buf: []const u8) -> %u32 {281fn parseIp4(buf: []const u8) -> %u32 {
282 var result: u32 = undefined;282 var result: u32 = undefined;
283 const out_ptr = ([]u8)((&result)[0...1]);283 const out_ptr = ([]u8)((&result)[0..1]);
284284
285 var x: u8 = 0;285 var x: u8 = 0;
286 var index: u8 = 0;286 var index: u8 = 0;
std/os/child_process.zig+2-2
...@@ -225,7 +225,7 @@ fn forkChildErrReport(fd: i32, err: error) -> noreturn {...@@ -225,7 +225,7 @@ fn forkChildErrReport(fd: i32, err: error) -> noreturn {
225const ErrInt = @IntType(false, @sizeOf(error) * 8);225const ErrInt = @IntType(false, @sizeOf(error) * 8);
226fn writeIntFd(fd: i32, value: ErrInt) -> %void {226fn writeIntFd(fd: i32, value: ErrInt) -> %void {
227 var bytes: [@sizeOf(ErrInt)]u8 = undefined;227 var bytes: [@sizeOf(ErrInt)]u8 = undefined;
228 mem.writeInt(bytes[0...], value, true);228 mem.writeInt(bytes[0..], value, true);
229229
230 var index: usize = 0;230 var index: usize = 0;
231 while (index < bytes.len) {231 while (index < bytes.len) {
...@@ -259,6 +259,6 @@ fn readIntFd(fd: i32) -> %ErrInt {...@@ -259,6 +259,6 @@ fn readIntFd(fd: i32) -> %ErrInt {
259 index += amt_written;259 index += amt_written;
260 }260 }
261261
262 return mem.readInt(bytes[0...], ErrInt, true);262 return mem.readInt(bytes[0..], ErrInt, true);
263}263}
264264
std/os/index.zig+18-18
...@@ -172,7 +172,7 @@ pub fn posixOpen(file_path: []const u8, flags: usize, perm: usize, allocator: ?&...@@ -172,7 +172,7 @@ pub fn posixOpen(file_path: []const u8, flags: usize, perm: usize, allocator: ?&
172 var need_free = false;172 var need_free = false;
173173
174 if (file_path.len < stack_buf.len) {174 if (file_path.len < stack_buf.len) {
175 path0 = stack_buf[0...file_path.len + 1];175 path0 = stack_buf[0..file_path.len + 1];
176 } else if (allocator) |a| {176 } else if (allocator) |a| {
177 path0 = %return a.alloc(u8, file_path.len + 1);177 path0 = %return a.alloc(u8, file_path.len + 1);
178 need_free = true;178 need_free = true;
...@@ -311,7 +311,7 @@ pub fn posixExecve(exe_path: []const u8, argv: []const []const u8, env_map: &con...@@ -311,7 +311,7 @@ pub fn posixExecve(exe_path: []const u8, argv: []const []const u8, env_map: &con
311 while (it.next()) |search_path| {311 while (it.next()) |search_path| {
312 mem.copy(u8, path_buf, search_path);312 mem.copy(u8, path_buf, search_path);
313 path_buf[search_path.len] = '/';313 path_buf[search_path.len] = '/';
314 mem.copy(u8, path_buf[search_path.len + 1 ...], exe_path);314 mem.copy(u8, path_buf[search_path.len + 1 ..], exe_path);
315 path_buf[search_path.len + exe_path.len + 1] = 0;315 path_buf[search_path.len + exe_path.len + 1] = 0;
316 err = posix.getErrno(posix.execve(path_buf.ptr, argv_buf.ptr, envp_buf.ptr));316 err = posix.getErrno(posix.execve(path_buf.ptr, argv_buf.ptr, envp_buf.ptr));
317 assert(err > 0);317 assert(err > 0);
...@@ -352,11 +352,11 @@ pub fn getEnvMap(allocator: &Allocator) -> %BufMap {...@@ -352,11 +352,11 @@ pub fn getEnvMap(allocator: &Allocator) -> %BufMap {
352 for (environ_raw) |ptr| {352 for (environ_raw) |ptr| {
353 var line_i: usize = 0;353 var line_i: usize = 0;
354 while (ptr[line_i] != 0 and ptr[line_i] != '=') : (line_i += 1) {}354 while (ptr[line_i] != 0 and ptr[line_i] != '=') : (line_i += 1) {}
355 const key = ptr[0...line_i];355 const key = ptr[0..line_i];
356356
357 var end_i: usize = line_i;357 var end_i: usize = line_i;
358 while (ptr[end_i] != 0) : (end_i += 1) {}358 while (ptr[end_i] != 0) : (end_i += 1) {}
359 const value = ptr[line_i + 1...end_i];359 const value = ptr[line_i + 1..end_i];
360360
361 %return result.set(key, value);361 %return result.set(key, value);
362 }362 }
...@@ -367,13 +367,13 @@ pub fn getEnv(key: []const u8) -> ?[]const u8 {...@@ -367,13 +367,13 @@ pub fn getEnv(key: []const u8) -> ?[]const u8 {
367 for (environ_raw) |ptr| {367 for (environ_raw) |ptr| {
368 var line_i: usize = 0;368 var line_i: usize = 0;
369 while (ptr[line_i] != 0 and ptr[line_i] != '=') : (line_i += 1) {}369 while (ptr[line_i] != 0 and ptr[line_i] != '=') : (line_i += 1) {}
370 const this_key = ptr[0...line_i];370 const this_key = ptr[0..line_i];
371 if (!mem.eql(u8, key, this_key))371 if (!mem.eql(u8, key, this_key))
372 continue;372 continue;
373373
374 var end_i: usize = line_i;374 var end_i: usize = line_i;
375 while (ptr[end_i] != 0) : (end_i += 1) {}375 while (ptr[end_i] != 0) : (end_i += 1) {}
376 const this_value = ptr[line_i + 1...end_i];376 const this_value = ptr[line_i + 1..end_i];
377377
378 return this_value;378 return this_value;
379 }379 }
...@@ -417,7 +417,7 @@ pub fn symLink(allocator: &Allocator, existing_path: []const u8, new_path: []con...@@ -417,7 +417,7 @@ pub fn symLink(allocator: &Allocator, existing_path: []const u8, new_path: []con
417 mem.copy(u8, existing_buf, existing_path);417 mem.copy(u8, existing_buf, existing_path);
418 existing_buf[existing_path.len] = 0;418 existing_buf[existing_path.len] = 0;
419419
420 const new_buf = full_buf[existing_path.len + 1...];420 const new_buf = full_buf[existing_path.len + 1..];
421 mem.copy(u8, new_buf, new_path);421 mem.copy(u8, new_buf, new_path);
422 new_buf[new_path.len] = 0;422 new_buf[new_path.len] = 0;
423423
...@@ -456,10 +456,10 @@ pub fn atomicSymLink(allocator: &Allocator, existing_path: []const u8, new_path:...@@ -456,10 +456,10 @@ pub fn atomicSymLink(allocator: &Allocator, existing_path: []const u8, new_path:
456 var rand_buf: [12]u8 = undefined;456 var rand_buf: [12]u8 = undefined;
457 const tmp_path = %return allocator.alloc(u8, new_path.len + base64.calcEncodedSize(rand_buf.len));457 const tmp_path = %return allocator.alloc(u8, new_path.len + base64.calcEncodedSize(rand_buf.len));
458 defer allocator.free(tmp_path);458 defer allocator.free(tmp_path);
459 mem.copy(u8, tmp_path[0...], new_path);459 mem.copy(u8, tmp_path[0..], new_path);
460 while (true) {460 while (true) {
461 %return getRandomBytes(rand_buf[0...]);461 %return getRandomBytes(rand_buf[0..]);
462 _ = base64.encodeWithAlphabet(tmp_path[new_path.len...], rand_buf, b64_fs_alphabet);462 _ = base64.encodeWithAlphabet(tmp_path[new_path.len..], rand_buf, b64_fs_alphabet);
463 if (symLink(allocator, existing_path, tmp_path)) {463 if (symLink(allocator, existing_path, tmp_path)) {
464 return rename(allocator, tmp_path, new_path);464 return rename(allocator, tmp_path, new_path);
465 } else |err| {465 } else |err| {
...@@ -510,9 +510,9 @@ pub fn copyFileMode(allocator: &Allocator, source_path: []const u8, dest_path: [...@@ -510,9 +510,9 @@ pub fn copyFileMode(allocator: &Allocator, source_path: []const u8, dest_path: [
510 var rand_buf: [12]u8 = undefined;510 var rand_buf: [12]u8 = undefined;
511 const tmp_path = %return allocator.alloc(u8, dest_path.len + base64.calcEncodedSize(rand_buf.len));511 const tmp_path = %return allocator.alloc(u8, dest_path.len + base64.calcEncodedSize(rand_buf.len));
512 defer allocator.free(tmp_path);512 defer allocator.free(tmp_path);
513 mem.copy(u8, tmp_path[0...], dest_path);513 mem.copy(u8, tmp_path[0..], dest_path);
514 %return getRandomBytes(rand_buf[0...]);514 %return getRandomBytes(rand_buf[0..]);
515 _ = base64.encodeWithAlphabet(tmp_path[dest_path.len...], rand_buf, b64_fs_alphabet);515 _ = base64.encodeWithAlphabet(tmp_path[dest_path.len..], rand_buf, b64_fs_alphabet);
516516
517 var out_stream = %return io.OutStream.openMode(tmp_path, mode, allocator);517 var out_stream = %return io.OutStream.openMode(tmp_path, mode, allocator);
518 defer out_stream.close();518 defer out_stream.close();
...@@ -521,7 +521,7 @@ pub fn copyFileMode(allocator: &Allocator, source_path: []const u8, dest_path: [...@@ -521,7 +521,7 @@ pub fn copyFileMode(allocator: &Allocator, source_path: []const u8, dest_path: [
521 var in_stream = %return io.InStream.open(source_path, allocator);521 var in_stream = %return io.InStream.open(source_path, allocator);
522 defer in_stream.close();522 defer in_stream.close();
523523
524 const buf = out_stream.buffer[0...];524 const buf = out_stream.buffer[0..];
525 while (true) {525 while (true) {
526 const amt = %return in_stream.read(buf);526 const amt = %return in_stream.read(buf);
527 out_stream.index = amt;527 out_stream.index = amt;
...@@ -539,7 +539,7 @@ pub fn rename(allocator: &Allocator, old_path: []const u8, new_path: []const u8)...@@ -539,7 +539,7 @@ pub fn rename(allocator: &Allocator, old_path: []const u8, new_path: []const u8)
539 mem.copy(u8, old_buf, old_path);539 mem.copy(u8, old_buf, old_path);
540 old_buf[old_path.len] = 0;540 old_buf[old_path.len] = 0;
541541
542 const new_buf = full_buf[old_path.len + 1...];542 const new_buf = full_buf[old_path.len + 1..];
543 mem.copy(u8, new_buf, new_path);543 mem.copy(u8, new_buf, new_path);
544 new_buf[new_path.len] = 0;544 new_buf[new_path.len] = 0;
545545
...@@ -601,7 +601,7 @@ pub fn makePath(allocator: &Allocator, full_path: []const u8) -> %void {...@@ -601,7 +601,7 @@ pub fn makePath(allocator: &Allocator, full_path: []const u8) -> %void {
601601
602 var end_index: usize = resolved_path.len;602 var end_index: usize = resolved_path.len;
603 while (true) {603 while (true) {
604 makeDir(allocator, resolved_path[0...end_index]) %% |err| {604 makeDir(allocator, resolved_path[0..end_index]) %% |err| {
605 if (err == error.PathAlreadyExists) {605 if (err == error.PathAlreadyExists) {
606 // TODO stat the file and return an error if it's not a directory606 // TODO stat the file and return an error if it's not a directory
607 // this is important because otherwise a dangling symlink607 // this is important because otherwise a dangling symlink
...@@ -691,7 +691,7 @@ start_over:...@@ -691,7 +691,7 @@ start_over:
691 const full_entry_path = full_entry_buf.toSlice();691 const full_entry_path = full_entry_buf.toSlice();
692 mem.copy(u8, full_entry_path, full_path);692 mem.copy(u8, full_entry_path, full_path);
693 full_entry_path[full_path.len] = '/';693 full_entry_path[full_path.len] = '/';
694 mem.copy(u8, full_entry_path[full_path.len + 1...], entry.name);694 mem.copy(u8, full_entry_path[full_path.len + 1..], entry.name);
695695
696 %return deleteTree(allocator, full_entry_path);696 %return deleteTree(allocator, full_entry_path);
697 }697 }
...@@ -856,6 +856,6 @@ pub fn readLink(allocator: &Allocator, pathname: []const u8) -> %[]u8 {...@@ -856,6 +856,6 @@ pub fn readLink(allocator: &Allocator, pathname: []const u8) -> %[]u8 {
856 result_buf = %return allocator.realloc(u8, result_buf, result_buf.len * 2);856 result_buf = %return allocator.realloc(u8, result_buf, result_buf.len * 2);
857 continue;857 continue;
858 }858 }
859 return result_buf[0...ret_val];859 return result_buf[0..ret_val];
860 }860 }
861}861}
std/os/path.zig+15-15
...@@ -39,7 +39,7 @@ pub fn join(allocator: &Allocator, paths: ...) -> %[]u8 {...@@ -39,7 +39,7 @@ pub fn join(allocator: &Allocator, paths: ...) -> %[]u8 {
39 inline while (true) {39 inline while (true) {
40 const arg = ([]const u8)(paths[path_i]);40 const arg = ([]const u8)(paths[path_i]);
41 path_i += 1;41 path_i += 1;
42 mem.copy(u8, buf[buf_index...], arg);42 mem.copy(u8, buf[buf_index..], arg);
43 buf_index += arg.len;43 buf_index += arg.len;
44 if (path_i >= paths.len) break;44 if (path_i >= paths.len) break;
45 if (buf[buf_index - 1] != sep) {45 if (buf[buf_index - 1] != sep) {
...@@ -48,7 +48,7 @@ pub fn join(allocator: &Allocator, paths: ...) -> %[]u8 {...@@ -48,7 +48,7 @@ pub fn join(allocator: &Allocator, paths: ...) -> %[]u8 {
48 }48 }
49 }49 }
5050
51 return buf[0...buf_index];51 return buf[0..buf_index];
52}52}
5353
54test "os.path.join" {54test "os.path.join" {
...@@ -110,7 +110,7 @@ pub fn resolveSlice(allocator: &Allocator, paths: []const []const u8) -> %[]u8 {...@@ -110,7 +110,7 @@ pub fn resolveSlice(allocator: &Allocator, paths: []const []const u8) -> %[]u8 {
110 }110 }
111 %defer allocator.free(result);111 %defer allocator.free(result);
112112
113 for (paths[first_index...]) |p, i| {113 for (paths[first_index..]) |p, i| {
114 var it = mem.split(p, '/');114 var it = mem.split(p, '/');
115 while (it.next()) |component| {115 while (it.next()) |component| {
116 if (mem.eql(u8, component, ".")) {116 if (mem.eql(u8, component, ".")) {
...@@ -126,7 +126,7 @@ pub fn resolveSlice(allocator: &Allocator, paths: []const []const u8) -> %[]u8 {...@@ -126,7 +126,7 @@ pub fn resolveSlice(allocator: &Allocator, paths: []const []const u8) -> %[]u8 {
126 } else {126 } else {
127 result[result_index] = '/';127 result[result_index] = '/';
128 result_index += 1;128 result_index += 1;
129 mem.copy(u8, result[result_index...], component);129 mem.copy(u8, result[result_index..], component);
130 result_index += component.len;130 result_index += component.len;
131 }131 }
132 }132 }
...@@ -137,7 +137,7 @@ pub fn resolveSlice(allocator: &Allocator, paths: []const []const u8) -> %[]u8 {...@@ -137,7 +137,7 @@ pub fn resolveSlice(allocator: &Allocator, paths: []const []const u8) -> %[]u8 {
137 result_index += 1;137 result_index += 1;
138 }138 }
139139
140 return result[0...result_index];140 return result[0..result_index];
141}141}
142142
143test "os.path.resolve" {143test "os.path.resolve" {
...@@ -153,24 +153,24 @@ fn testResolve(args: ...) -> []u8 {...@@ -153,24 +153,24 @@ fn testResolve(args: ...) -> []u8 {
153153
154pub fn dirname(path: []const u8) -> []const u8 {154pub fn dirname(path: []const u8) -> []const u8 {
155 if (path.len == 0)155 if (path.len == 0)
156 return path[0...0];156 return path[0..0];
157 var end_index: usize = path.len - 1;157 var end_index: usize = path.len - 1;
158 while (path[end_index] == '/') {158 while (path[end_index] == '/') {
159 if (end_index == 0)159 if (end_index == 0)
160 return path[0...1];160 return path[0..1];
161 end_index -= 1;161 end_index -= 1;
162 }162 }
163163
164 while (path[end_index] != '/') {164 while (path[end_index] != '/') {
165 if (end_index == 0)165 if (end_index == 0)
166 return path[0...0];166 return path[0..0];
167 end_index -= 1;167 end_index -= 1;
168 }168 }
169169
170 if (end_index == 0 and path[end_index] == '/')170 if (end_index == 0 and path[end_index] == '/')
171 return path[0...1];171 return path[0..1];
172172
173 return path[0...end_index];173 return path[0..end_index];
174}174}
175175
176test "os.path.dirname" {176test "os.path.dirname" {
...@@ -202,11 +202,11 @@ pub fn basename(path: []const u8) -> []const u8 {...@@ -202,11 +202,11 @@ pub fn basename(path: []const u8) -> []const u8 {
202 end_index += 1;202 end_index += 1;
203 while (path[start_index] != '/') {203 while (path[start_index] != '/') {
204 if (start_index == 0)204 if (start_index == 0)
205 return path[0...end_index];205 return path[0..end_index];
206 start_index -= 1;206 start_index -= 1;
207 }207 }
208208
209 return path[start_index + 1...end_index];209 return path[start_index + 1..end_index];
210}210}
211211
212test "os.path.basename" {212test "os.path.basename" {
...@@ -265,10 +265,10 @@ pub fn relative(allocator: &Allocator, from: []const u8, to: []const u8) -> %[]u...@@ -265,10 +265,10 @@ pub fn relative(allocator: &Allocator, from: []const u8, to: []const u8) -> %[]u
265 }265 }
266 if (to_rest.len == 0) {266 if (to_rest.len == 0) {
267 // shave off the trailing slash267 // shave off the trailing slash
268 return result[0...result_index - 1];268 return result[0..result_index - 1];
269 }269 }
270270
271 mem.copy(u8, result[result_index...], to_rest);271 mem.copy(u8, result[result_index..], to_rest);
272 return result;272 return result;
273 }273 }
274274
...@@ -303,7 +303,7 @@ pub fn real(allocator: &Allocator, pathname: []const u8) -> %[]u8 {...@@ -303,7 +303,7 @@ pub fn real(allocator: &Allocator, pathname: []const u8) -> %[]u8 {
303 defer os.posixClose(fd);303 defer os.posixClose(fd);
304304
305 var buf: ["/proc/self/fd/-2147483648".len]u8 = undefined;305 var buf: ["/proc/self/fd/-2147483648".len]u8 = undefined;
306 const proc_path = fmt.bufPrint(buf[0...], "/proc/self/fd/{}", fd);306 const proc_path = fmt.bufPrint(buf[0..], "/proc/self/fd/{}", fd);
307307
308 return os.readLink(allocator, proc_path);308 return os.readLink(allocator, proc_path);
309}309}
std/rand.zig+4-4
...@@ -39,7 +39,7 @@ pub const Rand = struct {...@@ -39,7 +39,7 @@ pub const Rand = struct {
39 return (r.rng.get() & 0b1) == 0;39 return (r.rng.get() & 0b1) == 0;
40 } else {40 } else {
41 var result: [@sizeOf(T)]u8 = undefined;41 var result: [@sizeOf(T)]u8 = undefined;
42 r.fillBytes(result[0...]);42 r.fillBytes(result[0..]);
43 return mem.readInt(result, T, false);43 return mem.readInt(result, T, false);
44 }44 }
45 }45 }
...@@ -48,12 +48,12 @@ pub const Rand = struct {...@@ -48,12 +48,12 @@ pub const Rand = struct {
48 pub fn fillBytes(r: &Rand, buf: []u8) {48 pub fn fillBytes(r: &Rand, buf: []u8) {
49 var bytes_left = buf.len;49 var bytes_left = buf.len;
50 while (bytes_left >= @sizeOf(usize)) {50 while (bytes_left >= @sizeOf(usize)) {
51 mem.writeInt(buf[buf.len - bytes_left...], r.rng.get(), false);51 mem.writeInt(buf[buf.len - bytes_left..], r.rng.get(), false);
52 bytes_left -= @sizeOf(usize);52 bytes_left -= @sizeOf(usize);
53 }53 }
54 if (bytes_left > 0) {54 if (bytes_left > 0) {
55 var rand_val_array: [@sizeOf(usize)]u8 = undefined;55 var rand_val_array: [@sizeOf(usize)]u8 = undefined;
56 mem.writeInt(rand_val_array[0...], r.rng.get(), false);56 mem.writeInt(rand_val_array[0..], r.rng.get(), false);
57 while (bytes_left > 0) {57 while (bytes_left > 0) {
58 buf[buf.len - bytes_left] = rand_val_array[@sizeOf(usize) - bytes_left];58 buf[buf.len - bytes_left] = rand_val_array[@sizeOf(usize) - bytes_left];
59 bytes_left -= 1;59 bytes_left -= 1;
...@@ -71,7 +71,7 @@ pub const Rand = struct {...@@ -71,7 +71,7 @@ pub const Rand = struct {
71 var rand_val_array: [@sizeOf(T)]u8 = undefined;71 var rand_val_array: [@sizeOf(T)]u8 = undefined;
7272
73 while (true) {73 while (true) {
74 r.fillBytes(rand_val_array[0...]);74 r.fillBytes(rand_val_array[0..]);
75 const rand_val = mem.readInt(rand_val_array, T, false);75 const rand_val = mem.readInt(rand_val_array, T, false);
76 if (rand_val < upper_bound) {76 if (rand_val < upper_bound) {
77 return start + (rand_val % range);77 return start + (rand_val % range);
std/sort.zig+3-3
...@@ -70,7 +70,7 @@ test "testSort" {...@@ -70,7 +70,7 @@ test "testSort" {
7070
71 for (u8cases) |case| {71 for (u8cases) |case| {
72 var buf: [8]u8 = undefined;72 var buf: [8]u8 = undefined;
73 const slice = buf[0...case[0].len];73 const slice = buf[0..case[0].len];
74 mem.copy(u8, slice, case[0]);74 mem.copy(u8, slice, case[0]);
75 sort(u8, slice, u8asc);75 sort(u8, slice, u8asc);
76 assert(mem.eql(u8, slice, case[1]));76 assert(mem.eql(u8, slice, case[1]));
...@@ -87,7 +87,7 @@ test "testSort" {...@@ -87,7 +87,7 @@ test "testSort" {
8787
88 for (i32cases) |case| {88 for (i32cases) |case| {
89 var buf: [8]i32 = undefined;89 var buf: [8]i32 = undefined;
90 const slice = buf[0...case[0].len];90 const slice = buf[0..case[0].len];
91 mem.copy(i32, slice, case[0]);91 mem.copy(i32, slice, case[0]);
92 sort(i32, slice, i32asc);92 sort(i32, slice, i32asc);
93 assert(mem.eql(i32, slice, case[1]));93 assert(mem.eql(i32, slice, case[1]));
...@@ -106,7 +106,7 @@ test "testSortDesc" {...@@ -106,7 +106,7 @@ test "testSortDesc" {
106106
107 for (rev_cases) |case| {107 for (rev_cases) |case| {
108 var buf: [8]i32 = undefined;108 var buf: [8]i32 = undefined;
109 const slice = buf[0...case[0].len];109 const slice = buf[0..case[0].len];
110 mem.copy(i32, slice, case[0]);110 mem.copy(i32, slice, case[0]);
111 sort(i32, slice, i32desc);111 sort(i32, slice, i32desc);
112 assert(mem.eql(i32, slice, case[1]));112 assert(mem.eql(i32, slice, case[1]));
std/special/bootstrap.zig+2-2
...@@ -39,11 +39,11 @@ fn callMainAndExit() -> noreturn {...@@ -39,11 +39,11 @@ fn callMainAndExit() -> noreturn {
39}39}
4040
41fn callMain(argc: usize, argv: &&u8, envp: &?&u8) -> %void {41fn callMain(argc: usize, argv: &&u8, envp: &?&u8) -> %void {
42 std.os.args.raw = argv[0...argc];42 std.os.args.raw = argv[0..argc];
4343
44 var env_count: usize = 0;44 var env_count: usize = 0;
45 while (envp[env_count] != null) : (env_count += 1) {}45 while (envp[env_count] != null) : (env_count += 1) {}
46 std.os.environ_raw = @ptrCast(&&u8, envp)[0...env_count];46 std.os.environ_raw = @ptrCast(&&u8, envp)[0..env_count];
4747
48 std.debug.user_main_fn = root.main;48 std.debug.user_main_fn = root.main;
4949
std/special/build_runner.zig+3-3
...@@ -58,14 +58,14 @@ pub fn main() -> %void {...@@ -58,14 +58,14 @@ pub fn main() -> %void {
58 while (arg_i < os.args.count()) : (arg_i += 1) {58 while (arg_i < os.args.count()) : (arg_i += 1) {
59 const arg = os.args.at(arg_i);59 const arg = os.args.at(arg_i);
60 if (mem.startsWith(u8, arg, "-D")) {60 if (mem.startsWith(u8, arg, "-D")) {
61 const option_contents = arg[2...];61 const option_contents = arg[2..];
62 if (option_contents.len == 0) {62 if (option_contents.len == 0) {
63 %%io.stderr.printf("Expected option name after '-D'\n\n");63 %%io.stderr.printf("Expected option name after '-D'\n\n");
64 return usage(&builder, false, &io.stderr);64 return usage(&builder, false, &io.stderr);
65 }65 }
66 if (mem.indexOfScalar(u8, option_contents, '=')) |name_end| {66 if (mem.indexOfScalar(u8, option_contents, '=')) |name_end| {
67 const option_name = option_contents[0...name_end];67 const option_name = option_contents[0..name_end];
68 const option_value = option_contents[name_end + 1...];68 const option_value = option_contents[name_end + 1..];
69 if (builder.addUserInputOption(option_name, option_value))69 if (builder.addUserInputOption(option_name, option_value))
70 return usage(&builder, false, &io.stderr);70 return usage(&builder, false, &io.stderr);
71 } else {71 } else {
std/special/zigrt.zig+2-2
...@@ -9,10 +9,10 @@ export coldcc fn __zig_panic(message_ptr: &const u8, message_len: usize) -> nore...@@ -9,10 +9,10 @@ export coldcc fn __zig_panic(message_ptr: &const u8, message_len: usize) -> nore
9 @setDebugSafety(this, false);9 @setDebugSafety(this, false);
1010
11 if (builtin.__zig_panic_implementation_provided) {11 if (builtin.__zig_panic_implementation_provided) {
12 @import("@root").panic(message_ptr[0...message_len]);12 @import("@root").panic(message_ptr[0..message_len]);
13 } else if (builtin.os == builtin.Os.freestanding) {13 } else if (builtin.os == builtin.Os.freestanding) {
14 while (true) {}14 while (true) {}
15 } else {15 } else {
16 @import("std").debug.panic("{}", message_ptr[0...message_len]);16 @import("std").debug.panic("{}", message_ptr[0..message_len]);
17 }17 }
18}18}
test/cases/array.zig+1-1
...@@ -70,7 +70,7 @@ const Str = struct {...@@ -70,7 +70,7 @@ const Str = struct {
70 a: []Sub,70 a: []Sub,
71};71};
72test "setGlobalVarArrayViaSliceEmbeddedInStruct" {72test "setGlobalVarArrayViaSliceEmbeddedInStruct" {
73 var s = Str { .a = s_array[0...]};73 var s = Str { .a = s_array[0..]};
7474
75 s.a[0].b = 1;75 s.a[0].b = 1;
76 s.a[1].b = 2;76 s.a[1].b = 2;
test/cases/cast.zig+4-4
...@@ -148,7 +148,7 @@ fn peerTypeEmptyArrayAndSlice(a: bool, slice: []const u8) -> []const u8 {...@@ -148,7 +148,7 @@ fn peerTypeEmptyArrayAndSlice(a: bool, slice: []const u8) -> []const u8 {
148 return []const u8 {};148 return []const u8 {};
149 }149 }
150150
151 return slice[0...1];151 return slice[0..1];
152}152}
153153
154test "implicitly cast from [N]T to ?[]const T" {154test "implicitly cast from [N]T to ?[]const T" {
...@@ -177,13 +177,13 @@ fn gimmeErrOrSlice() -> %[]u8 {...@@ -177,13 +177,13 @@ fn gimmeErrOrSlice() -> %[]u8 {
177test "peer type resolution: [0]u8, []const u8, and %[]u8" {177test "peer type resolution: [0]u8, []const u8, and %[]u8" {
178 {178 {
179 var data = "hi";179 var data = "hi";
180 const slice = data[0...];180 const slice = data[0..];
181 assert((%%peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0);181 assert((%%peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0);
182 assert((%%peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1);182 assert((%%peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1);
183 }183 }
184 comptime {184 comptime {
185 var data = "hi";185 var data = "hi";
186 const slice = data[0...];186 const slice = data[0..];
187 assert((%%peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0);187 assert((%%peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0);
188 assert((%%peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1);188 assert((%%peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1);
189 }189 }
...@@ -193,7 +193,7 @@ fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) -> %[]u8 {...@@ -193,7 +193,7 @@ fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) -> %[]u8 {
193 return []u8{};193 return []u8{};
194 }194 }
195195
196 return slice[0...1];196 return slice[0..1];
197}197}
198198
199test "resolve undefined with integer" {199test "resolve undefined with integer" {
test/cases/const_slice_child.zig+1-1
...@@ -24,7 +24,7 @@ fn bar(argc: usize) {...@@ -24,7 +24,7 @@ fn bar(argc: usize) {
24 const args = %%debug.global_allocator.alloc([]const u8, argc);24 const args = %%debug.global_allocator.alloc([]const u8, argc);
25 for (args) |_, i| {25 for (args) |_, i| {
26 const ptr = argv[i];26 const ptr = argv[i];
27 args[i] = ptr[0...strlen(ptr)];27 args[i] = ptr[0..strlen(ptr)];
28 }28 }
29 foo(args);29 foo(args);
30}30}
test/cases/enum_with_members.zig+4-4
...@@ -19,9 +19,9 @@ test "enumWithMembers" {...@@ -19,9 +19,9 @@ test "enumWithMembers" {
19 const b = ET.UINT { 42 };19 const b = ET.UINT { 42 };
20 var buf: [20]u8 = undefined;20 var buf: [20]u8 = undefined;
2121
22 assert(%%a.print(buf[0...]) == 3);22 assert(%%a.print(buf[0..]) == 3);
23 assert(mem.eql(u8, buf[0...3], "-42"));23 assert(mem.eql(u8, buf[0..3], "-42"));
2424
25 assert(%%b.print(buf[0...]) == 2);25 assert(%%b.print(buf[0..]) == 2);
26 assert(mem.eql(u8, buf[0...2], "42"));26 assert(mem.eql(u8, buf[0..2], "42"));
27}27}
test/cases/eval.zig+2-2
...@@ -145,7 +145,7 @@ test "constSlice" {...@@ -145,7 +145,7 @@ test "constSlice" {
145 comptime {145 comptime {
146 const a = "1234567890";146 const a = "1234567890";
147 assert(a.len == 10);147 assert(a.len == 10);
148 const b = a[1...2];148 const b = a[1..2];
149 assert(b.len == 1);149 assert(b.len == 1);
150 assert(b[0] == '2');150 assert(b[0] == '2');
151 }151 }
...@@ -255,7 +255,7 @@ test "callMethodOnBoundFnReferringToVarInstance" {...@@ -255,7 +255,7 @@ test "callMethodOnBoundFnReferringToVarInstance" {
255test "ptrToLocalArrayArgumentAtComptime" {255test "ptrToLocalArrayArgumentAtComptime" {
256 comptime {256 comptime {
257 var bytes: [10]u8 = undefined;257 var bytes: [10]u8 = undefined;
258 modifySomeBytes(bytes[0...]);258 modifySomeBytes(bytes[0..]);
259 assert(bytes[0] == 'a');259 assert(bytes[0] == 'a');
260 assert(bytes[9] == 'b');260 assert(bytes[9] == 'b');
261 }261 }
test/cases/for.zig+3-3
...@@ -18,8 +18,8 @@ test "continueInForLoop" {...@@ -18,8 +18,8 @@ test "continueInForLoop" {
18test "forLoopWithPointerElemVar" {18test "forLoopWithPointerElemVar" {
19 const source = "abcdefg";19 const source = "abcdefg";
20 var target: [source.len]u8 = undefined;20 var target: [source.len]u8 = undefined;
21 mem.copy(u8, target[0...], source);21 mem.copy(u8, target[0..], source);
22 mangleString(target[0...]);22 mangleString(target[0..]);
23 assert(mem.eql(u8, target, "bcdefgh"));23 assert(mem.eql(u8, target, "bcdefgh"));
24}24}
25fn mangleString(s: []u8) {25fn mangleString(s: []u8) {
...@@ -53,5 +53,5 @@ test "basicForLoop" {...@@ -53,5 +53,5 @@ test "basicForLoop" {
53 buf_index += 1;53 buf_index += 1;
54 }54 }
5555
56 assert(mem.eql(u8, buffer[0...buf_index], expected_result));56 assert(mem.eql(u8, buffer[0..buf_index], expected_result));
57}57}
test/cases/misc.zig+6-6
...@@ -173,14 +173,14 @@ test "slicing" {...@@ -173,14 +173,14 @@ test "slicing" {
173173
174 array[5] = 1234;174 array[5] = 1234;
175175
176 var slice = array[5...10];176 var slice = array[5..10];
177177
178 if (slice.len != 5) unreachable;178 if (slice.len != 5) unreachable;
179179
180 const ptr = &slice[0];180 const ptr = &slice[0];
181 if (ptr[0] != 1234) unreachable;181 if (ptr[0] != 1234) unreachable;
182182
183 var slice_rest = array[10...];183 var slice_rest = array[10..];
184 if (slice_rest.len != 10) unreachable;184 if (slice_rest.len != 10) unreachable;
185}185}
186186
...@@ -260,7 +260,7 @@ test "generic malloc free" {...@@ -260,7 +260,7 @@ test "generic malloc free" {
260}260}
261const some_mem : [100]u8 = undefined;261const some_mem : [100]u8 = undefined;
262fn memAlloc(comptime T: type, n: usize) -> %[]T {262fn memAlloc(comptime T: type, n: usize) -> %[]T {
263 return @ptrCast(&T, &some_mem[0])[0...n];263 return @ptrCast(&T, &some_mem[0])[0..n];
264}264}
265fn memFree(comptime T: type, memory: []T) { }265fn memFree(comptime T: type, memory: []T) { }
266266
...@@ -396,7 +396,7 @@ test "C string concatenation" {...@@ -396,7 +396,7 @@ test "C string concatenation" {
396test "cast slice to u8 slice" {396test "cast slice to u8 slice" {
397 assert(@sizeOf(i32) == 4);397 assert(@sizeOf(i32) == 4);
398 var big_thing_array = []i32{1, 2, 3, 4};398 var big_thing_array = []i32{1, 2, 3, 4};
399 const big_thing_slice: []i32 = big_thing_array[0...];399 const big_thing_slice: []i32 = big_thing_array[0..];
400 const bytes = ([]u8)(big_thing_slice);400 const bytes = ([]u8)(big_thing_slice);
401 assert(bytes.len == 4 * 4);401 assert(bytes.len == 4 * 4);
402 bytes[4] = 0;402 bytes[4] = 0;
...@@ -509,9 +509,9 @@ test "volatile load and store" {...@@ -509,9 +509,9 @@ test "volatile load and store" {
509509
510test "slice string literal has type []const u8" {510test "slice string literal has type []const u8" {
511 comptime {511 comptime {
512 assert(@typeOf("aoeu"[0...]) == []const u8);512 assert(@typeOf("aoeu"[0..]) == []const u8);
513 const array = []i32{1, 2, 3, 4};513 const array = []i32{1, 2, 3, 4};
514 assert(@typeOf(array[0...]) == []const i32);514 assert(@typeOf(array[0..]) == []const i32);
515 }515 }
516}516}
517517
test/cases/slice.zig+2-2
...@@ -1,7 +1,7 @@...@@ -1,7 +1,7 @@
1const assert = @import("std").debug.assert;1const assert = @import("std").debug.assert;
22
3const x = @intToPtr(&i32, 0x1000)[0...0x500];3const x = @intToPtr(&i32, 0x1000)[0..0x500];
4const y = x[0x100...];4const y = x[0x100..];
5test "compile time slice of pointer to hard coded address" {5test "compile time slice of pointer to hard coded address" {
6 assert(usize(x.ptr) == 0x1000);6 assert(usize(x.ptr) == 0x1000);
7 assert(x.len == 0x500);7 assert(x.len == 0x500);
test/cases/struct.zig+2-2
...@@ -305,7 +305,7 @@ test "packedArray24Bits" {...@@ -305,7 +305,7 @@ test "packedArray24Bits" {
305305
306 var bytes = []u8{0} ** (@sizeOf(FooArray24Bits) + 1);306 var bytes = []u8{0} ** (@sizeOf(FooArray24Bits) + 1);
307 bytes[bytes.len - 1] = 0xaa;307 bytes[bytes.len - 1] = 0xaa;
308 const ptr = &([]FooArray24Bits)(bytes[0...bytes.len - 1])[0];308 const ptr = &([]FooArray24Bits)(bytes[0..bytes.len - 1])[0];
309 assert(ptr.a == 0);309 assert(ptr.a == 0);
310 assert(ptr.b[0].field == 0);310 assert(ptr.b[0].field == 0);
311 assert(ptr.b[1].field == 0);311 assert(ptr.b[1].field == 0);
...@@ -354,7 +354,7 @@ test "alignedArrayOfPackedStruct" {...@@ -354,7 +354,7 @@ test "alignedArrayOfPackedStruct" {
354 }354 }
355355
356 var bytes = []u8{0xbb} ** @sizeOf(FooArrayOfAligned);356 var bytes = []u8{0xbb} ** @sizeOf(FooArrayOfAligned);
357 const ptr = &([]FooArrayOfAligned)(bytes[0...bytes.len])[0];357 const ptr = &([]FooArrayOfAligned)(bytes[0..bytes.len])[0];
358358
359 assert(ptr.a[0].a == 0xbb);359 assert(ptr.a[0].a == 0xbb);
360 assert(ptr.a[0].b == 0xbb);360 assert(ptr.a[0].b == 0xbb);
test/cases/struct_contains_slice_of_itself.zig+2-2
...@@ -27,12 +27,12 @@ test "struct contains slice of itself" {...@@ -27,12 +27,12 @@ test "struct contains slice of itself" {
27 },27 },
28 Node {28 Node {
29 .payload = 3,29 .payload = 3,
30 .children = other_nodes[0...],30 .children = other_nodes[0..],
31 },31 },
32 };32 };
33 const root = Node {33 const root = Node {
34 .payload = 1234,34 .payload = 1234,
35 .children = nodes[0...],35 .children = nodes[0..],
36 };36 };
37 assert(root.payload == 1234);37 assert(root.payload == 1234);
38 assert(root.children[0].payload == 1);38 assert(root.children[0].payload == 1);
test/compile_errors.zig+2-2
...@@ -1112,7 +1112,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1112,7 +1112,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
1112 cases.add("bogus method call on slice",1112 cases.add("bogus method call on slice",
1113 \\var self = "aoeu";1113 \\var self = "aoeu";
1114 \\fn f(m: []const u8) {1114 \\fn f(m: []const u8) {
1115 \\ m.copy(u8, self[0...], m);1115 \\ m.copy(u8, self[0..], m);
1116 \\}1116 \\}
1117 \\export fn entry() -> usize { @sizeOf(@typeOf(f)) }1117 \\export fn entry() -> usize { @sizeOf(@typeOf(f)) }
1118 , ".tmp_source.zig:3:6: error: no member named 'copy' in '[]const u8'");1118 , ".tmp_source.zig:3:6: error: no member named 'copy' in '[]const u8'");
...@@ -1467,7 +1467,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1467,7 +1467,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
1467 \\pub fn pass(in: []u8) -> []u8 {1467 \\pub fn pass(in: []u8) -> []u8 {
1468 \\ var out = &s_buffer;1468 \\ var out = &s_buffer;
1469 \\ *out[0] = in[0];1469 \\ *out[0] = in[0];
1470 \\ return (*out)[0...1];1470 \\ return (*out)[0..1];
1471 \\}1471 \\}
1472 \\1472 \\
1473 \\export fn entry() -> usize { @sizeOf(@typeOf(pass)) }1473 \\export fn entry() -> usize { @sizeOf(@typeOf(pass)) }