| author | |
| committer | |
| log | 698829b772fe39c4311a75b20324256b8d7392b1 |
| tree | c1434e819ef38698a79a711c164ca62d9418a9c7 |
| parent | 644ea2dde9fbb1f948cf12115df2a15e908f3c29 |
Old:
```
while (condition; expression) {}
```
New:
```
while (condition) : (expression) {}
```
This is in preparation to allow nullable and
error union types as the condition. See #35725 files changed, 97 insertions(+), 65 deletions(-)
doc/langref.md+2-2| ... | ... | @@ -79,8 +79,6 @@ SwitchProng = (list(SwitchItem, ",") | "else") "=>" option("|" option("*") Symbo |
| 79 | 79 | |
| 80 | 80 | SwitchItem = Expression | (Expression "..." Expression) |
| 81 | 81 | |
| 82 | WhileExpression(body) = "while" "(" Expression option(";" Expression) ")" body | |
| 83 | ||
| 84 | 82 | ForExpression(body) = "for" "(" Expression ")" option("|" option("*") Symbol option("," Symbol) "|") body |
| 85 | 83 | |
| 86 | 84 | BoolOrExpression = BoolAndExpression "or" BoolOrExpression | BoolAndExpression |
| ... | ... | @@ -95,6 +93,8 @@ TryExpression(body) = "if" "(" Expression ")" option("|" option("*") Symbol "|") |
| 95 | 93 | |
| 96 | 94 | TestExpression(body) = "if" "(" Expression ")" option("|" option("*") Symbol "|") body option("else" BlockExpression(body)) |
| 97 | 95 | |
| 96 | WhileExpression(body) = "while" "(" Expression ")" option("|" option("*") Symbol "|") option(":" "(" Expression ")") body option("else" option("|" Symbol "|") BlockExpression(body)) | |
| 97 | ||
| 98 | 98 | BoolAndExpression = ComparisonExpression "and" BoolAndExpression | ComparisonExpression |
| 99 | 99 | |
| 100 | 100 | ComparisonExpression = BinaryOrExpression ComparisonOperator BinaryOrExpression | BinaryOrExpression |
example/cat/main.zig+1-1| ... | ... | @@ -7,7 +7,7 @@ pub fn main() -> %void { |
| 7 | 7 | const exe = os.args.at(0); |
| 8 | 8 | var catted_anything = false; |
| 9 | 9 | var arg_i: usize = 1; |
| 10 | while (arg_i < os.args.count(); arg_i += 1) { | |
| 10 | while (arg_i < os.args.count()) : (arg_i += 1) { | |
| 11 | 11 | const arg = os.args.at(arg_i); |
| 12 | 12 | if (mem.eql(u8, arg, "-")) { |
| 13 | 13 | catted_anything = true; |
src/all_types.hpp+4| ... | ... | @@ -609,8 +609,12 @@ struct AstNodeTestExpr { |
| 609 | 609 | |
| 610 | 610 | struct AstNodeWhileExpr { |
| 611 | 611 | AstNode *condition; |
| 612 | Buf *var_symbol; | |
| 613 | bool var_is_ptr; | |
| 612 | 614 | AstNode *continue_expr; |
| 613 | 615 | AstNode *body; |
| 616 | AstNode *else_node; | |
| 617 | Buf *err_symbol; | |
| 614 | 618 | bool is_inline; |
| 615 | 619 | }; |
| 616 | 620 |
src/parser.cpp+37-9| ... | ... | @@ -1580,7 +1580,7 @@ static AstNode *ast_parse_bool_or_expr(ParseContext *pc, size_t *token_index, bo |
| 1580 | 1580 | } |
| 1581 | 1581 | |
| 1582 | 1582 | /* |
| 1583 | WhileExpression(body) = option("inline") "while" "(" Expression option(";" Expression) ")" body | |
| 1583 | WhileExpression(body) = option("inline") "while" "(" Expression ")" option("|" option("*") Symbol "|") option(":" "(" Expression ")") body option("else" option("|" Symbol "|") BlockExpression(body)) | |
| 1584 | 1584 | */ |
| 1585 | 1585 | static AstNode *ast_parse_while_expr(ParseContext *pc, size_t *token_index, bool mandatory) { |
| 1586 | 1586 | Token *first_token = &pc->tokens->at(*token_index); |
| ... | ... | @@ -1613,21 +1613,49 @@ static AstNode *ast_parse_while_expr(ParseContext *pc, size_t *token_index, bool |
| 1613 | 1613 | |
| 1614 | 1614 | ast_eat_token(pc, token_index, TokenIdLParen); |
| 1615 | 1615 | node->data.while_expr.condition = ast_parse_expression(pc, token_index, true); |
| 1616 | ast_eat_token(pc, token_index, TokenIdRParen); | |
| 1616 | 1617 | |
| 1617 | Token *semi_or_rparen = &pc->tokens->at(*token_index); | |
| 1618 | ||
| 1619 | if (semi_or_rparen->id == TokenIdRParen) { | |
| 1618 | Token *open_bar_tok = &pc->tokens->at(*token_index); | |
| 1619 | if (open_bar_tok->id == TokenIdBinOr) { | |
| 1620 | 1620 | *token_index += 1; |
| 1621 | node->data.while_expr.body = ast_parse_block_or_expression(pc, token_index, true); | |
| 1622 | } else if (semi_or_rparen->id == TokenIdSemicolon) { | |
| 1621 | ||
| 1622 | Token *star_tok = &pc->tokens->at(*token_index); | |
| 1623 | if (star_tok->id == TokenIdStar) { | |
| 1624 | *token_index += 1; | |
| 1625 | node->data.while_expr.var_is_ptr = true; | |
| 1626 | } | |
| 1627 | ||
| 1628 | Token *var_name_tok = ast_eat_token(pc, token_index, TokenIdSymbol); | |
| 1629 | node->data.while_expr.var_symbol = token_buf(var_name_tok); | |
| 1630 | ast_eat_token(pc, token_index, TokenIdBinOr); | |
| 1631 | } | |
| 1632 | ||
| 1633 | Token *colon_tok = &pc->tokens->at(*token_index); | |
| 1634 | if (colon_tok->id == TokenIdColon) { | |
| 1623 | 1635 | *token_index += 1; |
| 1636 | ast_eat_token(pc, token_index, TokenIdLParen); | |
| 1624 | 1637 | node->data.while_expr.continue_expr = ast_parse_expression(pc, token_index, true); |
| 1625 | 1638 | ast_eat_token(pc, token_index, TokenIdRParen); |
| 1626 | node->data.while_expr.body = ast_parse_block_or_expression(pc, token_index, true); | |
| 1627 | } else { | |
| 1628 | ast_invalid_token_error(pc, semi_or_rparen); | |
| 1629 | 1639 | } |
| 1630 | 1640 | |
| 1641 | node->data.while_expr.body = ast_parse_block_or_expression(pc, token_index, true); | |
| 1642 | ||
| 1643 | Token *else_tok = &pc->tokens->at(*token_index); | |
| 1644 | if (else_tok->id == TokenIdKeywordElse) { | |
| 1645 | *token_index += 1; | |
| 1646 | ||
| 1647 | Token *else_bar_tok = &pc->tokens->at(*token_index); | |
| 1648 | if (else_bar_tok->id == TokenIdBinOr) { | |
| 1649 | *token_index += 1; | |
| 1650 | ||
| 1651 | Token *err_name_tok = ast_eat_token(pc, token_index, TokenIdSymbol); | |
| 1652 | node->data.while_expr.err_symbol = token_buf(err_name_tok); | |
| 1653 | ||
| 1654 | ast_eat_token(pc, token_index, TokenIdBinOr); | |
| 1655 | } | |
| 1656 | ||
| 1657 | node->data.while_expr.body = ast_parse_block_or_expression(pc, token_index, true); | |
| 1658 | } | |
| 1631 | 1659 | |
| 1632 | 1660 | return node; |
| 1633 | 1661 | } |
std/base64.zig+1-1| ... | ... | @@ -17,7 +17,7 @@ pub fn encodeWithAlphabet(dest: []u8, source: []const u8, alphabet: []const u8) |
| 17 | 17 | |
| 18 | 18 | var i: usize = 0; |
| 19 | 19 | var out_index: usize = 0; |
| 20 | while (i + 2 < source.len; i += 3) { | |
| 20 | while (i + 2 < source.len) : (i += 3) { | |
| 21 | 21 | dest[out_index] = alphabet[(source[i] >> 2) & 0x3f]; |
| 22 | 22 | out_index += 1; |
| 23 | 23 |
std/cstr.zig+2-2| ... | ... | @@ -3,13 +3,13 @@ const assert = debug.assert; |
| 3 | 3 | |
| 4 | 4 | pub fn len(ptr: &const u8) -> usize { |
| 5 | 5 | var count: usize = 0; |
| 6 | while (ptr[count] != 0; count += 1) {} | |
| 6 | while (ptr[count] != 0) : (count += 1) {} | |
| 7 | 7 | return count; |
| 8 | 8 | } |
| 9 | 9 | |
| 10 | 10 | pub fn cmp(a: &const u8, b: &const u8) -> i8 { |
| 11 | 11 | var index: usize = 0; |
| 12 | while (a[index] == b[index] and a[index] != 0; index += 1) {} | |
| 12 | while (a[index] == b[index] and a[index] != 0) : (index += 1) {} | |
| 13 | 13 | if (a[index] > b[index]) { |
| 14 | 14 | return 1; |
| 15 | 15 | } else if (a[index] < b[index]) { |
std/debug.zig+4-4| ... | ... | @@ -79,7 +79,7 @@ pub fn writeStackTrace(out_stream: &io.OutStream, allocator: &mem.Allocator, tty |
| 79 | 79 | var ignored_count: usize = 0; |
| 80 | 80 | |
| 81 | 81 | var fp = usize(@frameAddress()); |
| 82 | while (fp != 0; fp = *@intToPtr(&const usize, fp)) { | |
| 82 | while (fp != 0) : (fp = *@intToPtr(&const usize, fp)) { | |
| 83 | 83 | if (ignored_count < ignore_frame_count) { |
| 84 | 84 | ignored_count += 1; |
| 85 | 85 | continue; |
| ... | ... | @@ -108,7 +108,7 @@ pub fn writeStackTrace(out_stream: &io.OutStream, allocator: &mem.Allocator, tty |
| 108 | 108 | if (line_info.column == 0) { |
| 109 | 109 | %return out_stream.write("\n"); |
| 110 | 110 | } else { |
| 111 | {var col_i: usize = 1; while (col_i < line_info.column; col_i += 1) { | |
| 111 | {var col_i: usize = 1; while (col_i < line_info.column) : (col_i += 1) { | |
| 112 | 112 | %return out_stream.writeByte(' '); |
| 113 | 113 | }} |
| 114 | 114 | %return out_stream.write(GREEN ++ "^" ++ RESET ++ "\n"); |
| ... | ... | @@ -594,7 +594,7 @@ fn getLineNumberInfo(st: &ElfStackTrace, compile_unit: &const CompileUnit, targe |
| 594 | 594 | var this_offset = st.debug_line.offset; |
| 595 | 595 | var this_index: usize = 0; |
| 596 | 596 | |
| 597 | while (this_offset < debug_line_end; this_index += 1) { | |
| 597 | while (this_offset < debug_line_end) : (this_index += 1) { | |
| 598 | 598 | %return in_stream.seekTo(this_offset); |
| 599 | 599 | |
| 600 | 600 | var is_64: bool = undefined; |
| ... | ... | @@ -628,7 +628,7 @@ fn getLineNumberInfo(st: &ElfStackTrace, compile_unit: &const CompileUnit, targe |
| 628 | 628 | |
| 629 | 629 | const standard_opcode_lengths = %return st.allocator().alloc(u8, opcode_base - 1); |
| 630 | 630 | |
| 631 | {var i: usize = 0; while (i < opcode_base - 1; i += 1) { | |
| 631 | {var i: usize = 0; while (i < opcode_base - 1) : (i += 1) { | |
| 632 | 632 | standard_opcode_lengths[i] = %return in_stream.readByte(); |
| 633 | 633 | }} |
| 634 | 634 |
std/fmt.zig+1-1| ... | ... | @@ -200,7 +200,7 @@ pub fn formatBuf(buf: []const u8, width: usize, |
| 200 | 200 | |
| 201 | 201 | var leftover_padding = if (width > buf.len) (width - buf.len) else return true; |
| 202 | 202 | const pad_byte: u8 = ' '; |
| 203 | while (leftover_padding > 0; leftover_padding -= 1) { | |
| 203 | while (leftover_padding > 0) : (leftover_padding -= 1) { | |
| 204 | 204 | if (!output(context, (&pad_byte)[0...1])) |
| 205 | 205 | return false; |
| 206 | 206 | } |
std/hash_map.zig+5-5| ... | ... | @@ -43,7 +43,7 @@ pub fn HashMap(comptime K: type, comptime V: type, |
| 43 | 43 | assert(it.initial_modification_count == it.hm.modification_count); // concurrent modification |
| 44 | 44 | } |
| 45 | 45 | if (it.count >= it.hm.size) return null; |
| 46 | while (it.index < it.hm.entries.len; it.index += 1) { | |
| 46 | while (it.index < it.hm.entries.len) : (it.index += 1) { | |
| 47 | 47 | const entry = &it.hm.entries[it.index]; |
| 48 | 48 | if (entry.used) { |
| 49 | 49 | it.index += 1; |
| ... | ... | @@ -112,7 +112,7 @@ pub fn HashMap(comptime K: type, comptime V: type, |
| 112 | 112 | pub fn remove(hm: &Self, key: K) -> ?&Entry { |
| 113 | 113 | hm.incrementModificationCount(); |
| 114 | 114 | const start_index = hm.keyToIndex(key); |
| 115 | {var roll_over: usize = 0; while (roll_over <= hm.max_distance_from_start_index; roll_over += 1) { | |
| 115 | {var roll_over: usize = 0; while (roll_over <= hm.max_distance_from_start_index) : (roll_over += 1) { | |
| 116 | 116 | const index = (start_index + roll_over) % hm.entries.len; |
| 117 | 117 | var entry = &hm.entries[index]; |
| 118 | 118 | |
| ... | ... | @@ -121,7 +121,7 @@ pub fn HashMap(comptime K: type, comptime V: type, |
| 121 | 121 | |
| 122 | 122 | if (!eql(entry.key, key)) continue; |
| 123 | 123 | |
| 124 | while (roll_over < hm.entries.len; roll_over += 1) { | |
| 124 | while (roll_over < hm.entries.len) : (roll_over += 1) { | |
| 125 | 125 | const next_index = (start_index + roll_over + 1) % hm.entries.len; |
| 126 | 126 | const next_entry = &hm.entries[next_index]; |
| 127 | 127 | if (!next_entry.used or next_entry.distance_from_start_index == 0) { |
| ... | ... | @@ -169,7 +169,7 @@ pub fn HashMap(comptime K: type, comptime V: type, |
| 169 | 169 | const start_index = hm.keyToIndex(key); |
| 170 | 170 | var roll_over: usize = 0; |
| 171 | 171 | var distance_from_start_index: usize = 0; |
| 172 | while (roll_over < hm.entries.len; {roll_over += 1; distance_from_start_index += 1}) { | |
| 172 | while (roll_over < hm.entries.len) : ({roll_over += 1; distance_from_start_index += 1}) { | |
| 173 | 173 | const index = (start_index + roll_over) % hm.entries.len; |
| 174 | 174 | const entry = &hm.entries[index]; |
| 175 | 175 | |
| ... | ... | @@ -215,7 +215,7 @@ pub fn HashMap(comptime K: type, comptime V: type, |
| 215 | 215 | |
| 216 | 216 | fn internalGet(hm: &Self, key: K) -> ?&Entry { |
| 217 | 217 | const start_index = hm.keyToIndex(key); |
| 218 | {var roll_over: usize = 0; while (roll_over <= hm.max_distance_from_start_index; roll_over += 1) { | |
| 218 | {var roll_over: usize = 0; while (roll_over <= hm.max_distance_from_start_index) : (roll_over += 1) { | |
| 219 | 219 | const index = (start_index + roll_over) % hm.entries.len; |
| 220 | 220 | const entry = &hm.entries[index]; |
| 221 | 221 |
std/list.zig+2-2| ... | ... | @@ -78,11 +78,11 @@ test "basic list test" { |
| 78 | 78 | var list = List(i32).init(&debug.global_allocator); |
| 79 | 79 | defer list.deinit(); |
| 80 | 80 | |
| 81 | {var i: usize = 0; while (i < 10; i += 1) { | |
| 81 | {var i: usize = 0; while (i < 10) : (i += 1) { | |
| 82 | 82 | %%list.append(i32(i + 1)); |
| 83 | 83 | }} |
| 84 | 84 | |
| 85 | {var i: usize = 0; while (i < 10; i += 1) { | |
| 85 | {var i: usize = 0; while (i < 10) : (i += 1) { | |
| 86 | 86 | assert(list.items[i] == i32(i + 1)); |
| 87 | 87 | }} |
| 88 | 88 |
std/mem.zig+5-5| ... | ... | @@ -123,7 +123,7 @@ pub fn set(comptime T: type, dest: []T, value: T) { |
| 123 | 123 | pub fn cmp(comptime T: type, a: []const T, b: []const T) -> Cmp { |
| 124 | 124 | const n = math.min(a.len, b.len); |
| 125 | 125 | var i: usize = 0; |
| 126 | while (i < n; i += 1) { | |
| 126 | while (i < n) : (i += 1) { | |
| 127 | 127 | if (a[i] == b[i]) continue; |
| 128 | 128 | return if (a[i] > b[i]) Cmp.Greater else if (a[i] < b[i]) Cmp.Less else Cmp.Equal; |
| 129 | 129 | } |
| ... | ... | @@ -164,7 +164,7 @@ pub fn indexOf(comptime T: type, haystack: []const T, needle: []const T) -> ?usi |
| 164 | 164 | |
| 165 | 165 | var i: usize = 0; |
| 166 | 166 | const end = haystack.len - needle.len; |
| 167 | while (i <= end; i += 1) { | |
| 167 | while (i <= end) : (i += 1) { | |
| 168 | 168 | if (eql(T, haystack[i...i + needle.len], needle)) |
| 169 | 169 | return i; |
| 170 | 170 | } |
| ... | ... | @@ -263,14 +263,14 @@ const SplitIterator = struct { |
| 263 | 263 | |
| 264 | 264 | pub fn next(self: &SplitIterator) -> ?[]const u8 { |
| 265 | 265 | // move to beginning of token |
| 266 | while (self.index < self.s.len and self.s[self.index] == self.c; self.index += 1) {} | |
| 266 | while (self.index < self.s.len and self.s[self.index] == self.c) : (self.index += 1) {} | |
| 267 | 267 | const start = self.index; |
| 268 | 268 | if (start == self.s.len) { |
| 269 | 269 | return null; |
| 270 | 270 | } |
| 271 | 271 | |
| 272 | 272 | // move to end of token |
| 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 | 274 | const end = self.index; |
| 275 | 275 | |
| 276 | 276 | return self.s[start...end]; |
| ... | ... | @@ -280,7 +280,7 @@ const SplitIterator = struct { |
| 280 | 280 | pub fn rest(self: &const SplitIterator) -> []const u8 { |
| 281 | 281 | // move to beginning of token |
| 282 | 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 | 284 | return self.s[index...]; |
| 285 | 285 | } |
| 286 | 286 | }; |
std/os/index.zig+5-5| ... | ... | @@ -276,7 +276,7 @@ pub fn posixExecve(exe_path: []const u8, argv: []const []const u8, env_map: &con |
| 276 | 276 | { |
| 277 | 277 | var it = env_map.iterator(); |
| 278 | 278 | var i: usize = 0; |
| 279 | while (true; i += 1) { | |
| 279 | while (true) : (i += 1) { | |
| 280 | 280 | const pair = it.next() ?? break; |
| 281 | 281 | |
| 282 | 282 | const env_buf = %return allocator.alloc(u8, pair.key.len + pair.value.len + 2); |
| ... | ... | @@ -354,11 +354,11 @@ pub fn getEnvMap(allocator: &Allocator) -> %BufMap { |
| 354 | 354 | |
| 355 | 355 | for (environ_raw) |ptr| { |
| 356 | 356 | var line_i: usize = 0; |
| 357 | while (ptr[line_i] != 0 and ptr[line_i] != '='; line_i += 1) {} | |
| 357 | while (ptr[line_i] != 0 and ptr[line_i] != '=') : (line_i += 1) {} | |
| 358 | 358 | const key = ptr[0...line_i]; |
| 359 | 359 | |
| 360 | 360 | var end_i: usize = line_i; |
| 361 | while (ptr[end_i] != 0; end_i += 1) {} | |
| 361 | while (ptr[end_i] != 0) : (end_i += 1) {} | |
| 362 | 362 | const value = ptr[line_i + 1...end_i]; |
| 363 | 363 | |
| 364 | 364 | %return result.set(key, value); |
| ... | ... | @@ -369,13 +369,13 @@ pub fn getEnvMap(allocator: &Allocator) -> %BufMap { |
| 369 | 369 | pub fn getEnv(key: []const u8) -> ?[]const u8 { |
| 370 | 370 | for (environ_raw) |ptr| { |
| 371 | 371 | var line_i: usize = 0; |
| 372 | while (ptr[line_i] != 0 and ptr[line_i] != '='; line_i += 1) {} | |
| 372 | while (ptr[line_i] != 0 and ptr[line_i] != '=') : (line_i += 1) {} | |
| 373 | 373 | const this_key = ptr[0...line_i]; |
| 374 | 374 | if (!mem.eql(u8, key, this_key)) |
| 375 | 375 | continue; |
| 376 | 376 | |
| 377 | 377 | var end_i: usize = line_i; |
| 378 | while (ptr[end_i] != 0; end_i += 1) {} | |
| 378 | while (ptr[end_i] != 0) : (end_i += 1) {} | |
| 379 | 379 | const this_value = ptr[line_i + 1...end_i]; |
| 380 | 380 | |
| 381 | 381 | return this_value; |
std/os/path.zig+2-2| ... | ... | @@ -25,7 +25,7 @@ pub fn join(allocator: &Allocator, paths: ...) -> %[]u8 { |
| 25 | 25 | var total_paths_len: usize = paths.len; // 1 slash per path |
| 26 | 26 | { |
| 27 | 27 | comptime var path_i = 0; |
| 28 | inline while (path_i < paths.len; path_i += 1) { | |
| 28 | inline while (path_i < paths.len) : (path_i += 1) { | |
| 29 | 29 | const arg = ([]const u8)(paths[path_i]); |
| 30 | 30 | total_paths_len += arg.len; |
| 31 | 31 | } |
| ... | ... | @@ -74,7 +74,7 @@ pub fn isAbsolute(path: []const u8) -> bool { |
| 74 | 74 | pub fn resolve(allocator: &Allocator, args: ...) -> %[]u8 { |
| 75 | 75 | var paths: [args.len][]const u8 = undefined; |
| 76 | 76 | comptime var arg_i = 0; |
| 77 | inline while (arg_i < args.len; arg_i += 1) { | |
| 77 | inline while (arg_i < args.len) : (arg_i += 1) { | |
| 78 | 78 | paths[arg_i] = args[arg_i]; |
| 79 | 79 | } |
| 80 | 80 | return resolveSlice(allocator, paths); |
std/rand.zig+4-4| ... | ... | @@ -121,7 +121,7 @@ fn MersenneTwister( |
| 121 | 121 | var prev_value = seed; |
| 122 | 122 | mt.array[0] = prev_value; |
| 123 | 123 | var i: usize = 1; |
| 124 | while (i < n; i += 1) { | |
| 124 | while (i < n) : (i += 1) { | |
| 125 | 125 | prev_value = int(i) +% f *% (prev_value ^ (prev_value >> (int.bit_count - 2))); |
| 126 | 126 | mt.array[i] = prev_value; |
| 127 | 127 | } |
| ... | ... | @@ -136,12 +136,12 @@ fn MersenneTwister( |
| 136 | 136 | if (mt.index >= n) { |
| 137 | 137 | var i: usize = 0; |
| 138 | 138 | |
| 139 | while (i < n - m; i += 1) { | |
| 139 | while (i < n - m) : (i += 1) { | |
| 140 | 140 | const x = (mt.array[i] & UM) | (mt.array[i + 1] & LM); |
| 141 | 141 | mt.array[i] = mt.array[i + m] ^ (x >> 1) ^ mag01[x & 0x1]; |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | while (i < n - 1; i += 1) { | |
| 144 | while (i < n - 1) : (i += 1) { | |
| 145 | 145 | const x = (mt.array[i] & UM) | (mt.array[i + 1] & LM); |
| 146 | 146 | mt.array[i] = mt.array[i + m - n] ^ (x >> 1) ^ mag01[x & 0x1]; |
| 147 | 147 | |
| ... | ... | @@ -168,7 +168,7 @@ fn MersenneTwister( |
| 168 | 168 | test "rand float 32" { |
| 169 | 169 | var r = Rand.init(42); |
| 170 | 170 | var i: usize = 0; |
| 171 | while (i < 1000; i += 1) { | |
| 171 | while (i < 1000) : (i += 1) { | |
| 172 | 172 | const val = r.float(f32); |
| 173 | 173 | assert(val >= 0.0); |
| 174 | 174 | assert(val < 1.0); |
std/special/bootstrap.zig+1-1| ... | ... | @@ -42,7 +42,7 @@ fn callMain(argc: usize, argv: &&u8, envp: &?&u8) -> %void { |
| 42 | 42 | std.os.args.raw = argv[0...argc]; |
| 43 | 43 | |
| 44 | 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 | 46 | std.os.environ_raw = @ptrCast(&&u8, envp)[0...env_count]; |
| 47 | 47 | |
| 48 | 48 | std.debug.user_main_fn = root.main; |
std/special/build_runner.zig+1-1| ... | ... | @@ -55,7 +55,7 @@ pub fn main() -> %void { |
| 55 | 55 | |
| 56 | 56 | var prefix: ?[]const u8 = null; |
| 57 | 57 | |
| 58 | while (arg_i < os.args.count(); arg_i += 1) { | |
| 58 | while (arg_i < os.args.count()) : (arg_i += 1) { | |
| 59 | 59 | const arg = os.args.at(arg_i); |
| 60 | 60 | if (mem.startsWith(u8, arg, "-D")) { |
| 61 | 61 | const option_contents = arg[2...]; |
std/special/builtin.zig+2-2| ... | ... | @@ -10,7 +10,7 @@ export fn memset(dest: ?&u8, c: u8, n: usize) { |
| 10 | 10 | @setDebugSafety(this, false); |
| 11 | 11 | |
| 12 | 12 | var index: usize = 0; |
| 13 | while (index != n; index += 1) | |
| 13 | while (index != n) : (index += 1) | |
| 14 | 14 | (??dest)[index] = c; |
| 15 | 15 | } |
| 16 | 16 | |
| ... | ... | @@ -18,7 +18,7 @@ export fn memcpy(noalias dest: ?&u8, noalias src: ?&const u8, n: usize) { |
| 18 | 18 | @setDebugSafety(this, false); |
| 19 | 19 | |
| 20 | 20 | var index: usize = 0; |
| 21 | while (index != n; index += 1) | |
| 21 | while (index != n) : (index += 1) | |
| 22 | 22 | (??dest)[index] = (??src)[index]; |
| 23 | 23 | } |
| 24 | 24 |
std/special/compiler_rt.zig+1-1| ... | ... | @@ -296,7 +296,7 @@ export fn __udivsi3(n: su_int, d: su_int) -> su_int { |
| 296 | 296 | var q: su_int = n << (n_uword_bits - sr); |
| 297 | 297 | var r: su_int = n >> sr; |
| 298 | 298 | var carry: su_int = 0; |
| 299 | while (sr > 0; sr -= 1) { | |
| 299 | while (sr > 0) : (sr -= 1) { | |
| 300 | 300 | // r:q = ((r:q) << 1) | carry |
| 301 | 301 | r = (r << 1) | (q >> (n_uword_bits - 1)); |
| 302 | 302 | q = (q << 1) | carry; |
test/cases/const_slice_child.zig+1-1| ... | ... | @@ -31,7 +31,7 @@ fn bar(argc: usize) { |
| 31 | 31 | |
| 32 | 32 | fn strlen(ptr: &const u8) -> usize { |
| 33 | 33 | var count: usize = 0; |
| 34 | while (ptr[count] != 0; count += 1) {} | |
| 34 | while (ptr[count] != 0) : (count += 1) {} | |
| 35 | 35 | return count; |
| 36 | 36 | } |
| 37 | 37 |
test/cases/eval.zig+3-3| ... | ... | @@ -22,7 +22,7 @@ test "testStaticAddOne" { |
| 22 | 22 | test "inlinedLoop" { |
| 23 | 23 | comptime var i = 0; |
| 24 | 24 | comptime var sum = 0; |
| 25 | inline while (i <= 5; i += 1) | |
| 25 | inline while (i <= 5) : (i += 1) | |
| 26 | 26 | sum += i; |
| 27 | 27 | assert(sum == 15); |
| 28 | 28 | } |
| ... | ... | @@ -157,7 +157,7 @@ test "tryToTrickEvalWithRuntimeIf" { |
| 157 | 157 | |
| 158 | 158 | fn testTryToTrickEvalWithRuntimeIf(b: bool) -> usize { |
| 159 | 159 | comptime var i: usize = 0; |
| 160 | inline while (i < 10; i += 1) { | |
| 160 | inline while (i < 10) : (i += 1) { | |
| 161 | 161 | const result = if (b) false else true; |
| 162 | 162 | } |
| 163 | 163 | comptime { |
| ... | ... | @@ -208,7 +208,7 @@ fn three(value: i32) -> i32 { value + 3 } |
| 208 | 208 | fn performFn(comptime prefix_char: u8, start_value: i32) -> i32 { |
| 209 | 209 | var result: i32 = start_value; |
| 210 | 210 | comptime var i = 0; |
| 211 | inline while (i < cmd_fns.len; i += 1) { | |
| 211 | inline while (i < cmd_fns.len) : (i += 1) { | |
| 212 | 212 | if (cmd_fns[i].name[0] == prefix_char) { |
| 213 | 213 | result = cmd_fns[i].func(result); |
| 214 | 214 | } |
test/cases/misc.zig+1-1| ... | ... | @@ -380,7 +380,7 @@ test "cStringConcatenation" { |
| 380 | 380 | |
| 381 | 381 | const len = cstr.len(b); |
| 382 | 382 | const len_with_null = len + 1; |
| 383 | {var i: u32 = 0; while (i < len_with_null; i += 1) { | |
| 383 | {var i: u32 = 0; while (i < len_with_null) : (i += 1) { | |
| 384 | 384 | assert(a[i] == b[i]); |
| 385 | 385 | }} |
| 386 | 386 | assert(a[len] == 0); |
test/cases/var_args.zig+1-1| ... | ... | @@ -2,7 +2,7 @@ const assert = @import("std").debug.assert; |
| 2 | 2 | |
| 3 | 3 | fn add(args: ...) -> i32 { |
| 4 | 4 | var sum = i32(0); |
| 5 | {comptime var i: usize = 0; inline while (i < args.len; i += 1) { | |
| 5 | {comptime var i: usize = 0; inline while (i < args.len) : (i += 1) { | |
| 6 | 6 | sum += args[i]; |
| 7 | 7 | }} |
| 8 | 8 | return sum; |
test/cases/while.zig+1-1| ... | ... | @@ -58,7 +58,7 @@ fn returnWithImplicitCastFromWhileLoopTest() -> %void { |
| 58 | 58 | |
| 59 | 59 | test "whileWithContinueExpr" { |
| 60 | 60 | var sum: i32 = 0; |
| 61 | {var i: i32 = 0; while (i < 10; i += 1) { | |
| 61 | {var i: i32 = 0; while (i < 10) : (i += 1) { | |
| 62 | 62 | if (i == 5) continue; |
| 63 | 63 | sum += i; |
| 64 | 64 | }} |
test/compile_errors.zig+8-8| ... | ... | @@ -156,18 +156,18 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 156 | 156 | |
| 157 | 157 | cases.add("implicit semicolon - while-continue statement", |
| 158 | 158 | \\export fn entry() { |
| 159 | \\ while(true;{}) {} | |
| 159 | \\ while(true):({}) {} | |
| 160 | 160 | \\ var good = {}; |
| 161 | \\ while(true;{}) ({}) | |
| 161 | \\ while(true):({}) ({}) | |
| 162 | 162 | \\ var bad = {}; |
| 163 | 163 | \\} |
| 164 | 164 | , ".tmp_source.zig:5:5: error: invalid token: 'var'"); |
| 165 | 165 | |
| 166 | 166 | cases.add("implicit semicolon - while-continue expression", |
| 167 | 167 | \\export fn entry() { |
| 168 | \\ _ = while(true;{}) {}; | |
| 168 | \\ _ = while(true):({}) {}; | |
| 169 | 169 | \\ var good = {}; |
| 170 | \\ _ = while(true;{}) {} | |
| 170 | \\ _ = while(true):({}) {} | |
| 171 | 171 | \\ var bad = {}; |
| 172 | 172 | \\} |
| 173 | 173 | , ".tmp_source.zig:5:5: error: invalid token: 'var'"); |
| ... | ... | @@ -1231,7 +1231,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1231 | 1231 | cases.add("pass integer literal to var args", |
| 1232 | 1232 | \\fn add(args: ...) -> i32 { |
| 1233 | 1233 | \\ var sum = i32(0); |
| 1234 | \\ {comptime var i: usize = 0; inline while (i < args.len; i += 1) { | |
| 1234 | \\ {comptime var i: usize = 0; inline while (i < args.len) : (i += 1) { | |
| 1235 | 1235 | \\ sum += args[i]; |
| 1236 | 1236 | \\ }} |
| 1237 | 1237 | \\ return sum; |
| ... | ... | @@ -1315,7 +1315,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1315 | 1315 | cases.add("control flow uses comptime var at runtime", |
| 1316 | 1316 | \\export fn foo() { |
| 1317 | 1317 | \\ comptime var i = 0; |
| 1318 | \\ while (i < 5; i += 1) { | |
| 1318 | \\ while (i < 5) : (i += 1) { | |
| 1319 | 1319 | \\ bar(); |
| 1320 | 1320 | \\ } |
| 1321 | 1321 | \\} |
| ... | ... | @@ -1323,7 +1323,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1323 | 1323 | \\fn bar() { } |
| 1324 | 1324 | , |
| 1325 | 1325 | ".tmp_source.zig:3:5: error: control flow attempts to use compile-time variable at runtime", |
| 1326 | ".tmp_source.zig:3:21: note: compile-time variable assigned here"); | |
| 1326 | ".tmp_source.zig:3:24: note: compile-time variable assigned here"); | |
| 1327 | 1327 | |
| 1328 | 1328 | cases.add("ignored return value", |
| 1329 | 1329 | \\export fn foo() { |
| ... | ... | @@ -1373,7 +1373,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) { |
| 1373 | 1373 | cases.add("integer literal on a non-comptime var", |
| 1374 | 1374 | \\export fn foo() { |
| 1375 | 1375 | \\ var i = 0; |
| 1376 | \\ while (i < 10; i += 1) { } | |
| 1376 | \\ while (i < 10) : (i += 1) { } | |
| 1377 | 1377 | \\} |
| 1378 | 1378 | , ".tmp_source.zig:2:5: error: unable to infer variable type"); |
| 1379 | 1379 |
test/tests.zig+2-2| ... | ... | @@ -590,7 +590,7 @@ pub const CompileErrorContext = struct { |
| 590 | 590 | }; |
| 591 | 591 | tc.addSourceFile(".tmp_source.zig", source); |
| 592 | 592 | comptime var arg_i = 0; |
| 593 | inline while (arg_i < expected_lines.len; arg_i += 1) { | |
| 593 | inline while (arg_i < expected_lines.len) : (arg_i += 1) { | |
| 594 | 594 | // TODO mem.dupe is because of issue #336 |
| 595 | 595 | tc.addExpectedError(%%mem.dupe(self.b.allocator, u8, expected_lines[arg_i])); |
| 596 | 596 | } |
| ... | ... | @@ -853,7 +853,7 @@ pub const ParseHContext = struct { |
| 853 | 853 | }; |
| 854 | 854 | tc.addSourceFile("source.h", source); |
| 855 | 855 | comptime var arg_i = 0; |
| 856 | inline while (arg_i < expected_lines.len; arg_i += 1) { | |
| 856 | inline while (arg_i < expected_lines.len) : (arg_i += 1) { | |
| 857 | 857 | // TODO mem.dupe is because of issue #336 |
| 858 | 858 | tc.addExpectedError(%%mem.dupe(self.b.allocator, u8, expected_lines[arg_i])); |
| 859 | 859 | } |