authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-03-26 05:21:28-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-03-26 05:21:28-04:00
log7ce753a16b0c16b4c6494467f42f2d5fe9a235e6
treef88fa21d9548b0392252a1f835ae68c3ef574f24
parent451ce090674d6d5f2c23e6667047e1e479917c93

replace "&&" and "||" with "and" and "or"

closes #272

19 files changed, 46 insertions(+), 111 deletions(-)

doc/langref.md+3-3
...@@ -69,7 +69,7 @@ UnwrapError = "%%" option("|" Symbol "|") Expression...@@ -69,7 +69,7 @@ UnwrapError = "%%" option("|" Symbol "|") Expression
6969
70AssignmentExpression = UnwrapExpression AssignmentOperator UnwrapExpression | UnwrapExpression70AssignmentExpression = UnwrapExpression AssignmentOperator UnwrapExpression | UnwrapExpression
7171
72AssignmentOperator = "=" | "*=" | "/=" | "%=" | "+=" | "-=" | "<<=" | ">>=" | "&=" | "^=" | "|=" | "&&=" | "||=" | "*%=" | "+%=" | "-%=" | "<<%="72AssignmentOperator = "=" | "*=" | "/=" | "%=" | "+=" | "-=" | "<<=" | ">>=" | "&=" | "^=" | "|=" | "*%=" | "+%=" | "-%=" | "<<%="
7373
74BlockExpression = IfExpression | Block | WhileExpression | ForExpression | SwitchExpression | CompTimeExpression | TryExpression74BlockExpression = IfExpression | Block | WhileExpression | ForExpression | SwitchExpression | CompTimeExpression | TryExpression
7575
...@@ -85,7 +85,7 @@ WhileExpression = option("inline") "while" "(" Expression option(";" Expression)...@@ -85,7 +85,7 @@ WhileExpression = option("inline") "while" "(" Expression option(";" Expression)
8585
86ForExpression = option("inline") "for" "(" Expression ")" option("|" option("*") Symbol option("," Symbol) "|") Expression86ForExpression = option("inline") "for" "(" Expression ")" option("|" option("*") Symbol option("," Symbol) "|") Expression
8787
88BoolOrExpression = BoolAndExpression "||" BoolOrExpression | BoolAndExpression88BoolOrExpression = BoolAndExpression "or" BoolOrExpression | BoolAndExpression
8989
90ReturnExpression = option("%" | "?") "return" option(Expression)90ReturnExpression = option("%" | "?") "return" option(Expression)
9191
...@@ -101,7 +101,7 @@ IfVarExpression = "if" "(" ("const" | "var") option("*") Symbol option(":" TypeE...@@ -101,7 +101,7 @@ IfVarExpression = "if" "(" ("const" | "var") option("*") Symbol option(":" TypeE
101101
102Else = "else" Expression102Else = "else" Expression
103103
104BoolAndExpression = ComparisonExpression "&&" BoolAndExpression | ComparisonExpression104BoolAndExpression = ComparisonExpression "and" BoolAndExpression | ComparisonExpression
105105
106ComparisonExpression = BinaryOrExpression ComparisonOperator BinaryOrExpression | BinaryOrExpression106ComparisonExpression = BinaryOrExpression ComparisonOperator BinaryOrExpression | BinaryOrExpression
107107
doc/vim/syntax/zig.vim+2-2
...@@ -11,7 +11,7 @@ let b:current_syntax = "zig"...@@ -11,7 +11,7 @@ let b:current_syntax = "zig"
11syn keyword zigStorage const var extern packed export pub noalias inline comptime nakedcc coldcc volatile11syn keyword zigStorage const var extern packed export pub noalias inline comptime nakedcc coldcc volatile
12syn keyword zigStructure struct enum union12syn keyword zigStructure struct enum union
13syn keyword zigStatement goto break return continue asm defer unreachable13syn keyword zigStatement goto break return continue asm defer unreachable
14syn keyword zigConditional if else switch try14syn keyword zigConditional if else switch try and or
15syn keyword zigRepeat while for15syn keyword zigRepeat while for
1616
17syn keyword zigConstant null undefined this17syn keyword zigConstant null undefined this
...@@ -22,7 +22,7 @@ syn keyword zigType c_short c_ushort c_int c_uint c_long c_ulong c_longlong c_ul...@@ -22,7 +22,7 @@ syn keyword zigType c_short c_ushort c_int c_uint c_long c_ulong c_longlong c_ul
2222
23syn keyword zigBoolean true false23syn keyword zigBoolean true false
2424
25syn match zigOperator display "\%(+%\?\|-%\?\|/\|*%\?\|=\|\^\|&\|?\||\|!\|>\|<\|%\|<<%\?\|>>\|&&\|||\)=\?"25syn match zigOperator display "\%(+%\?\|-%\?\|/\|*%\?\|=\|\^\|&\|?\||\|!\|>\|<\|%\|<<%\?\|>>\)=\?"
26syn match zigArrowCharacter display "->"26syn match zigArrowCharacter display "->"
2727
28syn match zigDecNumber display "\<[0-9]*\%(.[0-9]\+\)\=\%([eE][+-]\?[0-9]\+\)\="28syn match zigDecNumber display "\<[0-9]*\%(.[0-9]\+\)\=\%([eE][+-]\?[0-9]\+\)\="
src/parser.cpp+6-17
...@@ -1007,7 +1007,6 @@ static PrefixOp tok_to_prefix_op(Token *token) {...@@ -1007,7 +1007,6 @@ static PrefixOp tok_to_prefix_op(Token *token) {
1007 case TokenIdPercent: return PrefixOpError;1007 case TokenIdPercent: return PrefixOpError;
1008 case TokenIdPercentPercent: return PrefixOpUnwrapError;1008 case TokenIdPercentPercent: return PrefixOpUnwrapError;
1009 case TokenIdDoubleQuestion: return PrefixOpUnwrapMaybe;1009 case TokenIdDoubleQuestion: return PrefixOpUnwrapMaybe;
1010 case TokenIdBoolAnd: return PrefixOpAddressOf;
1011 case TokenIdStarStar: return PrefixOpDereference;1010 case TokenIdStarStar: return PrefixOpDereference;
1012 default: return PrefixOpInvalid;1011 default: return PrefixOpInvalid;
1013 }1012 }
...@@ -1036,15 +1035,7 @@ static AstNode *ast_parse_prefix_op_expr(ParseContext *pc, size_t *token_index,...@@ -1036,15 +1035,7 @@ static AstNode *ast_parse_prefix_op_expr(ParseContext *pc, size_t *token_index,
10361035
1037 AstNode *node = ast_create_node(pc, NodeTypePrefixOpExpr, token);1036 AstNode *node = ast_create_node(pc, NodeTypePrefixOpExpr, token);
1038 AstNode *parent_node = node;1037 AstNode *parent_node = node;
1039 if (token->id == TokenIdBoolAnd) {1038 if (token->id == TokenIdStarStar) {
1040 // pretend that we got 2 ampersand tokens
1041
1042 parent_node = ast_create_node(pc, NodeTypePrefixOpExpr, token);
1043 parent_node->data.prefix_op_expr.primary_expr = node;
1044 parent_node->data.prefix_op_expr.prefix_op = PrefixOpAddressOf;
1045
1046 node->column += 1;
1047 } else if (token->id == TokenIdStarStar) {
1048 // pretend that we got 2 star tokens1039 // pretend that we got 2 star tokens
10491040
1050 parent_node = ast_create_node(pc, NodeTypePrefixOpExpr, token);1041 parent_node = ast_create_node(pc, NodeTypePrefixOpExpr, token);
...@@ -1362,7 +1353,7 @@ static AstNode *ast_parse_comparison_expr(ParseContext *pc, size_t *token_index,...@@ -1362,7 +1353,7 @@ static AstNode *ast_parse_comparison_expr(ParseContext *pc, size_t *token_index,
1362}1353}
13631354
1364/*1355/*
1365BoolAndExpression : ComparisonExpression token(BoolAnd) BoolAndExpression | ComparisonExpression1356BoolAndExpression = ComparisonExpression "and" BoolAndExpression | ComparisonExpression
1366 */1357 */
1367static AstNode *ast_parse_bool_and_expr(ParseContext *pc, size_t *token_index, bool mandatory) {1358static AstNode *ast_parse_bool_and_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
1368 AstNode *operand_1 = ast_parse_comparison_expr(pc, token_index, mandatory);1359 AstNode *operand_1 = ast_parse_comparison_expr(pc, token_index, mandatory);
...@@ -1371,7 +1362,7 @@ static AstNode *ast_parse_bool_and_expr(ParseContext *pc, size_t *token_index, b...@@ -1371,7 +1362,7 @@ static AstNode *ast_parse_bool_and_expr(ParseContext *pc, size_t *token_index, b
13711362
1372 while (true) {1363 while (true) {
1373 Token *token = &pc->tokens->at(*token_index);1364 Token *token = &pc->tokens->at(*token_index);
1374 if (token->id != TokenIdBoolAnd)1365 if (token->id != TokenIdKeywordAnd)
1375 return operand_1;1366 return operand_1;
1376 *token_index += 1;1367 *token_index += 1;
13771368
...@@ -1629,7 +1620,7 @@ static AstNode *ast_parse_variable_declaration_expr(ParseContext *pc, size_t *to...@@ -1629,7 +1620,7 @@ static AstNode *ast_parse_variable_declaration_expr(ParseContext *pc, size_t *to
1629}1620}
16301621
1631/*1622/*
1632BoolOrExpression : BoolAndExpression token(BoolOr) BoolOrExpression | BoolAndExpression1623BoolOrExpression = BoolAndExpression "or" BoolOrExpression | BoolAndExpression
1633*/1624*/
1634static AstNode *ast_parse_bool_or_expr(ParseContext *pc, size_t *token_index, bool mandatory) {1625static AstNode *ast_parse_bool_or_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
1635 AstNode *operand_1 = ast_parse_bool_and_expr(pc, token_index, mandatory);1626 AstNode *operand_1 = ast_parse_bool_and_expr(pc, token_index, mandatory);
...@@ -1638,7 +1629,7 @@ static AstNode *ast_parse_bool_or_expr(ParseContext *pc, size_t *token_index, bo...@@ -1638,7 +1629,7 @@ static AstNode *ast_parse_bool_or_expr(ParseContext *pc, size_t *token_index, bo
16381629
1639 while (true) {1630 while (true) {
1640 Token *token = &pc->tokens->at(*token_index);1631 Token *token = &pc->tokens->at(*token_index);
1641 if (token->id != TokenIdBoolOr)1632 if (token->id != TokenIdKeywordOr)
1642 return operand_1;1633 return operand_1;
1643 *token_index += 1;1634 *token_index += 1;
16441635
...@@ -1924,14 +1915,12 @@ static BinOpType tok_to_ass_op(Token *token) {...@@ -1924,14 +1915,12 @@ static BinOpType tok_to_ass_op(Token *token) {
1924 case TokenIdBitAndEq: return BinOpTypeAssignBitAnd;1915 case TokenIdBitAndEq: return BinOpTypeAssignBitAnd;
1925 case TokenIdBitXorEq: return BinOpTypeAssignBitXor;1916 case TokenIdBitXorEq: return BinOpTypeAssignBitXor;
1926 case TokenIdBitOrEq: return BinOpTypeAssignBitOr;1917 case TokenIdBitOrEq: return BinOpTypeAssignBitOr;
1927 case TokenIdBoolAndEq: return BinOpTypeAssignBoolAnd;
1928 case TokenIdBoolOrEq: return BinOpTypeAssignBoolOr;
1929 default: return BinOpTypeInvalid;1918 default: return BinOpTypeInvalid;
1930 }1919 }
1931}1920}
19321921
1933/*1922/*
1934AssignmentOperator = "=" | "*=" | "/=" | "%=" | "+=" | "-=" | "<<=" | ">>=" | "&=" | "^=" | "|=" | "&&=" | "||=" | "*%=" | "+%=" | "-%=" | "<<%="1923AssignmentOperator = "=" | "*=" | "/=" | "%=" | "+=" | "-=" | "<<=" | ">>=" | "&=" | "^=" | "|=" | "*%=" | "+%=" | "-%=" | "<<%="
1935*/1924*/
1936static BinOpType ast_parse_ass_op(ParseContext *pc, size_t *token_index, bool mandatory) {1925static BinOpType ast_parse_ass_op(ParseContext *pc, size_t *token_index, bool mandatory) {
1937 Token *token = &pc->tokens->at(*token_index);1926 Token *token = &pc->tokens->at(*token_index);
src/tokenizer.cpp+4-44
...@@ -107,6 +107,7 @@ struct ZigKeyword {...@@ -107,6 +107,7 @@ struct ZigKeyword {
107};107};
108108
109static const struct ZigKeyword zig_keywords[] = {109static const struct ZigKeyword zig_keywords[] = {
110 {"and", TokenIdKeywordAnd},
110 {"asm", TokenIdKeywordAsm},111 {"asm", TokenIdKeywordAsm},
111 {"break", TokenIdKeywordBreak},112 {"break", TokenIdKeywordBreak},
112 {"coldcc", TokenIdKeywordColdCC},113 {"coldcc", TokenIdKeywordColdCC},
...@@ -128,6 +129,7 @@ static const struct ZigKeyword zig_keywords[] = {...@@ -128,6 +129,7 @@ static const struct ZigKeyword zig_keywords[] = {
128 {"nakedcc", TokenIdKeywordNakedCC},129 {"nakedcc", TokenIdKeywordNakedCC},
129 {"noalias", TokenIdKeywordNoAlias},130 {"noalias", TokenIdKeywordNoAlias},
130 {"null", TokenIdKeywordNull},131 {"null", TokenIdKeywordNull},
132 {"or", TokenIdKeywordOr},
131 {"packed", TokenIdKeywordPacked},133 {"packed", TokenIdKeywordPacked},
132 {"pub", TokenIdKeywordPub},134 {"pub", TokenIdKeywordPub},
133 {"return", TokenIdKeywordReturn},135 {"return", TokenIdKeywordReturn},
...@@ -189,10 +191,8 @@ enum TokenizeState {...@@ -189,10 +191,8 @@ enum TokenizeState {
189 TokenizeStateSawDash,191 TokenizeStateSawDash,
190 TokenizeStateSawMinusPercent,192 TokenizeStateSawMinusPercent,
191 TokenizeStateSawAmpersand,193 TokenizeStateSawAmpersand,
192 TokenizeStateSawAmpersandAmpersand,
193 TokenizeStateSawCaret,194 TokenizeStateSawCaret,
194 TokenizeStateSawPipe,195 TokenizeStateSawPipe,
195 TokenizeStateSawPipePipe,
196 TokenizeStateLineComment,196 TokenizeStateLineComment,
197 TokenizeStateLineString,197 TokenizeStateLineString,
198 TokenizeStateLineStringEnd,198 TokenizeStateLineStringEnd,
...@@ -824,10 +824,6 @@ void tokenize(Buf *buf, Tokenization *out) {...@@ -824,10 +824,6 @@ void tokenize(Buf *buf, Tokenization *out) {
824 break;824 break;
825 case TokenizeStateSawAmpersand:825 case TokenizeStateSawAmpersand:
826 switch (c) {826 switch (c) {
827 case '&':
828 set_token_id(&t, t.cur_tok, TokenIdBoolAnd);
829 t.state = TokenizeStateSawAmpersandAmpersand;
830 break;
831 case '=':827 case '=':
832 set_token_id(&t, t.cur_tok, TokenIdBitAndEq);828 set_token_id(&t, t.cur_tok, TokenIdBitAndEq);
833 end_token(&t);829 end_token(&t);
...@@ -840,20 +836,6 @@ void tokenize(Buf *buf, Tokenization *out) {...@@ -840,20 +836,6 @@ void tokenize(Buf *buf, Tokenization *out) {
840 continue;836 continue;
841 }837 }
842 break;838 break;
843 case TokenizeStateSawAmpersandAmpersand:
844 switch (c) {
845 case '=':
846 set_token_id(&t, t.cur_tok, TokenIdBoolAndEq);
847 end_token(&t);
848 t.state = TokenizeStateStart;
849 break;
850 default:
851 t.pos -= 1;
852 end_token(&t);
853 t.state = TokenizeStateStart;
854 continue;
855 }
856 break;
857 case TokenizeStateSawCaret:839 case TokenizeStateSawCaret:
858 switch (c) {840 switch (c) {
859 case '=':841 case '=':
...@@ -870,10 +852,6 @@ void tokenize(Buf *buf, Tokenization *out) {...@@ -870,10 +852,6 @@ void tokenize(Buf *buf, Tokenization *out) {
870 break;852 break;
871 case TokenizeStateSawPipe:853 case TokenizeStateSawPipe:
872 switch (c) {854 switch (c) {
873 case '|':
874 set_token_id(&t, t.cur_tok, TokenIdBoolOr);
875 t.state = TokenizeStateSawPipePipe;
876 break;
877 case '=':855 case '=':
878 set_token_id(&t, t.cur_tok, TokenIdBitOrEq);856 set_token_id(&t, t.cur_tok, TokenIdBitOrEq);
879 end_token(&t);857 end_token(&t);
...@@ -886,20 +864,6 @@ void tokenize(Buf *buf, Tokenization *out) {...@@ -886,20 +864,6 @@ void tokenize(Buf *buf, Tokenization *out) {
886 continue;864 continue;
887 }865 }
888 break;866 break;
889 case TokenizeStateSawPipePipe:
890 switch (c) {
891 case '=':
892 set_token_id(&t, t.cur_tok, TokenIdBoolOrEq);
893 end_token(&t);
894 t.state = TokenizeStateStart;
895 break;
896 default:
897 t.pos -= 1;
898 end_token(&t);
899 t.state = TokenizeStateStart;
900 continue;
901 }
902 break;
903 case TokenizeStateSawSlash:867 case TokenizeStateSawSlash:
904 switch (c) {868 switch (c) {
905 case '/':869 case '/':
...@@ -1401,10 +1365,8 @@ void tokenize(Buf *buf, Tokenization *out) {...@@ -1401,10 +1365,8 @@ void tokenize(Buf *buf, Tokenization *out) {
1401 case TokenizeStateSawPlus:1365 case TokenizeStateSawPlus:
1402 case TokenizeStateSawDash:1366 case TokenizeStateSawDash:
1403 case TokenizeStateSawAmpersand:1367 case TokenizeStateSawAmpersand:
1404 case TokenizeStateSawAmpersandAmpersand:
1405 case TokenizeStateSawCaret:1368 case TokenizeStateSawCaret:
1406 case TokenizeStateSawPipe:1369 case TokenizeStateSawPipe:
1407 case TokenizeStateSawPipePipe:
1408 case TokenizeStateSawEq:1370 case TokenizeStateSawEq:
1409 case TokenizeStateSawBang:1371 case TokenizeStateSawBang:
1410 case TokenizeStateSawLessThan:1372 case TokenizeStateSawLessThan:
...@@ -1463,10 +1425,6 @@ const char * token_name(TokenId id) {...@@ -1463,10 +1425,6 @@ const char * token_name(TokenId id) {
1463 case TokenIdBitShiftRight: return ">>";1425 case TokenIdBitShiftRight: return ">>";
1464 case TokenIdBitShiftRightEq: return ">>=";1426 case TokenIdBitShiftRightEq: return ">>=";
1465 case TokenIdBitXorEq: return "^=";1427 case TokenIdBitXorEq: return "^=";
1466 case TokenIdBoolAnd: return "&&";
1467 case TokenIdBoolAndEq: return "&&=";
1468 case TokenIdBoolOr: return "||";
1469 case TokenIdBoolOrEq: return "||=";
1470 case TokenIdCharLiteral: return "CharLiteral";1428 case TokenIdCharLiteral: return "CharLiteral";
1471 case TokenIdCmpEq: return "==";1429 case TokenIdCmpEq: return "==";
1472 case TokenIdCmpGreaterOrEq: return ">=";1430 case TokenIdCmpGreaterOrEq: return ">=";
...@@ -1484,6 +1442,7 @@ const char * token_name(TokenId id) {...@@ -1484,6 +1442,7 @@ const char * token_name(TokenId id) {
1484 case TokenIdEof: return "EOF";1442 case TokenIdEof: return "EOF";
1485 case TokenIdEq: return "=";1443 case TokenIdEq: return "=";
1486 case TokenIdFatArrow: return "=>";1444 case TokenIdFatArrow: return "=>";
1445 case TokenIdKeywordAnd: return "and";
1487 case TokenIdKeywordAsm: return "asm";1446 case TokenIdKeywordAsm: return "asm";
1488 case TokenIdKeywordBreak: return "break";1447 case TokenIdKeywordBreak: return "break";
1489 case TokenIdKeywordColdCC: return "coldcc";1448 case TokenIdKeywordColdCC: return "coldcc";
...@@ -1505,6 +1464,7 @@ const char * token_name(TokenId id) {...@@ -1505,6 +1464,7 @@ const char * token_name(TokenId id) {
1505 case TokenIdKeywordNakedCC: return "nakedcc";1464 case TokenIdKeywordNakedCC: return "nakedcc";
1506 case TokenIdKeywordNoAlias: return "noalias";1465 case TokenIdKeywordNoAlias: return "noalias";
1507 case TokenIdKeywordNull: return "null";1466 case TokenIdKeywordNull: return "null";
1467 case TokenIdKeywordOr: return "or";
1508 case TokenIdKeywordPacked: return "packed";1468 case TokenIdKeywordPacked: return "packed";
1509 case TokenIdKeywordPub: return "pub";1469 case TokenIdKeywordPub: return "pub";
1510 case TokenIdKeywordReturn: return "return";1470 case TokenIdKeywordReturn: return "return";
src/tokenizer.hpp+2-4
...@@ -27,10 +27,6 @@ enum TokenId {...@@ -27,10 +27,6 @@ enum TokenId {
27 TokenIdBitShiftRight,27 TokenIdBitShiftRight,
28 TokenIdBitShiftRightEq,28 TokenIdBitShiftRightEq,
29 TokenIdBitXorEq,29 TokenIdBitXorEq,
30 TokenIdBoolAnd,
31 TokenIdBoolAndEq,
32 TokenIdBoolOr,
33 TokenIdBoolOrEq,
34 TokenIdCharLiteral,30 TokenIdCharLiteral,
35 TokenIdCmpEq,31 TokenIdCmpEq,
36 TokenIdCmpGreaterOrEq,32 TokenIdCmpGreaterOrEq,
...@@ -48,6 +44,7 @@ enum TokenId {...@@ -48,6 +44,7 @@ enum TokenId {
48 TokenIdEof,44 TokenIdEof,
49 TokenIdEq,45 TokenIdEq,
50 TokenIdFatArrow,46 TokenIdFatArrow,
47 TokenIdKeywordAnd,
51 TokenIdKeywordAsm,48 TokenIdKeywordAsm,
52 TokenIdKeywordBreak,49 TokenIdKeywordBreak,
53 TokenIdKeywordColdCC,50 TokenIdKeywordColdCC,
...@@ -69,6 +66,7 @@ enum TokenId {...@@ -69,6 +66,7 @@ enum TokenId {
69 TokenIdKeywordNakedCC,66 TokenIdKeywordNakedCC,
70 TokenIdKeywordNoAlias,67 TokenIdKeywordNoAlias,
71 TokenIdKeywordNull,68 TokenIdKeywordNull,
69 TokenIdKeywordOr,
72 TokenIdKeywordPacked,70 TokenIdKeywordPacked,
73 TokenIdKeywordPub,71 TokenIdKeywordPub,
74 TokenIdKeywordReturn,72 TokenIdKeywordReturn,
std/cstr.zig+1-1
...@@ -14,7 +14,7 @@ pub fn len(ptr: &const u8) -> usize {...@@ -14,7 +14,7 @@ pub fn len(ptr: &const u8) -> usize {
1414
15pub fn cmp(a: &const u8, b: &const u8) -> i8 {15pub fn cmp(a: &const u8, b: &const u8) -> i8 {
16 var index: usize = 0;16 var index: usize = 0;
17 while (a[index] == b[index] && a[index] != 0; index += 1) {}17 while (a[index] == b[index] and a[index] != 0; index += 1) {}
18 if (a[index] > b[index]) {18 if (a[index] > b[index]) {
19 return 1;19 return 1;
20 } else if (a[index] < b[index]) {20 } else if (a[index] < b[index]) {
std/darwin.zig+1-1
...@@ -56,7 +56,7 @@ pub fn exit(status: usize) -> noreturn {...@@ -56,7 +56,7 @@ pub fn exit(status: usize) -> noreturn {
56/// Get the errno from a syscall return value, or 0 for no error.56/// Get the errno from a syscall return value, or 0 for no error.
57pub fn getErrno(r: usize) -> usize {57pub fn getErrno(r: usize) -> usize {
58 const signed_r = *(&isize)(&r);58 const signed_r = *(&isize)(&r);
59 if (signed_r > -4096 && signed_r < 0) usize(-signed_r) else 059 if (signed_r > -4096 and signed_r < 0) usize(-signed_r) else 0
60}60}
6161
62pub fn write(fd: i32, buf: &const u8, count: usize) -> usize {62pub fn write(fd: i32, buf: &const u8, count: usize) -> usize {
std/debug.zig+3-3
...@@ -335,7 +335,7 @@ fn parseAbbrevTable(in_stream: &io.InStream) -> %AbbrevTable {...@@ -335,7 +335,7 @@ fn parseAbbrevTable(in_stream: &io.InStream) -> %AbbrevTable {
335 while (true) {335 while (true) {
336 const attr_id = %return readULeb128(in_stream);336 const attr_id = %return readULeb128(in_stream);
337 const form_id = %return readULeb128(in_stream);337 const form_id = %return readULeb128(in_stream);
338 if (attr_id == 0 && form_id == 0)338 if (attr_id == 0 and form_id == 0)
339 break;339 break;
340 %return attrs.append(AbbrevAttr {340 %return attrs.append(AbbrevAttr {
341 .attr_id = attr_id,341 .attr_id = attr_id,
...@@ -447,7 +447,7 @@ fn scanAllCompileUnits(st: &ElfStackTrace) -> %void {...@@ -447,7 +447,7 @@ fn scanAllCompileUnits(st: &ElfStackTrace) -> %void {
447447
448fn findCompileUnit(st: &ElfStackTrace, target_address: u64) -> ?&const CompileUnit {448fn findCompileUnit(st: &ElfStackTrace, target_address: u64) -> ?&const CompileUnit {
449 for (st.compile_unit_list.toSlice()) |*compile_unit| {449 for (st.compile_unit_list.toSlice()) |*compile_unit| {
450 if (target_address >= compile_unit.pc_start && target_address < compile_unit.pc_end)450 if (target_address >= compile_unit.pc_start and target_address < compile_unit.pc_end)
451 return compile_unit;451 return compile_unit;
452 }452 }
453 return null;453 return null;
...@@ -499,7 +499,7 @@ fn readILeb128(in_stream: &io.InStream) -> %i64 {...@@ -499,7 +499,7 @@ fn readILeb128(in_stream: &io.InStream) -> %i64 {
499 shift += 7;499 shift += 7;
500500
501 if ((byte & 0b10000000) == 0) {501 if ((byte & 0b10000000) == 0) {
502 if (shift < @sizeOf(i64) * 8 && (byte & 0b01000000) != 0)502 if (shift < @sizeOf(i64) * 8 and (byte & 0b01000000) != 0)
503 result |= -(i64(1) << shift);503 result |= -(i64(1) << shift);
504504
505 return result;505 return result;
std/elf.zig+4-4
...@@ -152,8 +152,8 @@ pub const Elf = struct {...@@ -152,8 +152,8 @@ pub const Elf = struct {
152 %return elf.in_stream.seekForward(4);152 %return elf.in_stream.seekForward(4);
153153
154 const header_size = %return elf.in_stream.readInt(elf.is_big_endian, u16);154 const header_size = %return elf.in_stream.readInt(elf.is_big_endian, u16);
155 if ((elf.is_64 && header_size != 64) ||155 if ((elf.is_64 and header_size != 64) or
156 (!elf.is_64 && header_size != 52))156 (!elf.is_64 and header_size != 52))
157 {157 {
158 return error.InvalidFormat;158 return error.InvalidFormat;
159 }159 }
...@@ -172,7 +172,7 @@ pub const Elf = struct {...@@ -172,7 +172,7 @@ pub const Elf = struct {
172 const end_ph = %return math.addOverflow(u64, elf.program_header_offset, ph_byte_count);172 const end_ph = %return math.addOverflow(u64, elf.program_header_offset, ph_byte_count);
173173
174 const stream_end = %return elf.in_stream.getEndPos();174 const stream_end = %return elf.in_stream.getEndPos();
175 if (stream_end < end_sh || stream_end < end_ph) {175 if (stream_end < end_sh or stream_end < end_ph) {
176 return error.InvalidFormat;176 return error.InvalidFormat;
177 }177 }
178178
...@@ -245,7 +245,7 @@ pub const Elf = struct {...@@ -245,7 +245,7 @@ pub const Elf = struct {
245245
246 for (name) |expected_c| {246 for (name) |expected_c| {
247 const target_c = %return elf.in_stream.readByte();247 const target_c = %return elf.in_stream.readByte();
248 if (target_c == 0 || expected_c != target_c) goto next_section;248 if (target_c == 0 or expected_c != target_c) goto next_section;
249 }249 }
250250
251 {251 {
std/fmt.zig+1-1
...@@ -33,7 +33,7 @@ pub fn format(context: var, output: fn(@typeOf(context), []const u8)->bool,...@@ -33,7 +33,7 @@ pub fn format(context: var, output: fn(@typeOf(context), []const u8)->bool,
33 switch (state) {33 switch (state) {
34 State.Start => switch (c) {34 State.Start => switch (c) {
35 '{' => {35 '{' => {
36 // TODO if you make this an if statement with && then it breaks36 // TODO if you make this an if statement with `and` then it breaks
37 if (start_index < i) {37 if (start_index < i) {
38 if (!output(context, fmt[start_index...i]))38 if (!output(context, fmt[start_index...i]))
39 return false;39 return false;
std/hash_map.zig+2-2
...@@ -116,7 +116,7 @@ pub fn HashMap(comptime K: type, comptime V: type,...@@ -116,7 +116,7 @@ pub fn HashMap(comptime K: type, comptime V: type,
116 while (roll_over < hm.entries.len; roll_over += 1) {116 while (roll_over < hm.entries.len; roll_over += 1) {
117 const next_index = (start_index + roll_over + 1) % hm.entries.len;117 const next_index = (start_index + roll_over + 1) % hm.entries.len;
118 const next_entry = &hm.entries[next_index];118 const next_entry = &hm.entries[next_index];
119 if (!next_entry.used || next_entry.distance_from_start_index == 0) {119 if (!next_entry.used or next_entry.distance_from_start_index == 0) {
120 entry.used = false;120 entry.used = false;
121 hm.size -= 1;121 hm.size -= 1;
122 return;122 return;
...@@ -164,7 +164,7 @@ pub fn HashMap(comptime K: type, comptime V: type,...@@ -164,7 +164,7 @@ pub fn HashMap(comptime K: type, comptime V: type,
164 const index = (start_index + roll_over) % hm.entries.len;164 const index = (start_index + roll_over) % hm.entries.len;
165 const entry = &hm.entries[index];165 const entry = &hm.entries[index];
166166
167 if (entry.used && !eql(entry.key, key)) {167 if (entry.used and !eql(entry.key, key)) {
168 if (entry.distance_from_start_index < distance_from_start_index) {168 if (entry.distance_from_start_index < distance_from_start_index) {
169 // robin hood to the rescue169 // robin hood to the rescue
170 const tmp = *entry;170 const tmp = *entry;
std/io.zig+1-1
...@@ -148,7 +148,7 @@ pub const OutStream = struct {...@@ -148,7 +148,7 @@ pub const OutStream = struct {
148 while (true) {148 while (true) {
149 const close_ret = system.close(self.fd);149 const close_ret = system.close(self.fd);
150 const close_err = system.getErrno(close_ret);150 const close_err = system.getErrno(close_ret);
151 if (close_err > 0 && close_err == errno.EINTR)151 if (close_err > 0 and close_err == errno.EINTR)
152 continue;152 continue;
153 return;153 return;
154 }154 }
std/linux.zig+1-1
...@@ -227,7 +227,7 @@ pub const AF_MAX = PF_MAX;...@@ -227,7 +227,7 @@ pub const AF_MAX = PF_MAX;
227/// Get the errno from a syscall return value, or 0 for no error.227/// Get the errno from a syscall return value, or 0 for no error.
228pub fn getErrno(r: usize) -> usize {228pub fn getErrno(r: usize) -> usize {
229 const signed_r = *(&isize)(&r);229 const signed_r = *(&isize)(&r);
230 if (signed_r > -4096 && signed_r < 0) usize(-signed_r) else 0230 if (signed_r > -4096 and signed_r < 0) usize(-signed_r) else 0
231}231}
232232
233pub fn mmap(address: ?&u8, length: usize, prot: usize, flags: usize, fd: i32, offset: usize)233pub fn mmap(address: ?&u8, length: usize, prot: usize, flags: usize, fd: i32, offset: usize)
std/math.zig+1-1
...@@ -49,7 +49,7 @@ pub fn log(comptime base: usize, value: var) -> @typeOf(value) {...@@ -49,7 +49,7 @@ pub fn log(comptime base: usize, value: var) -> @typeOf(value) {
4949
50/// x must be an integer or a float50/// x must be an integer or a float
51/// Note that this causes undefined behavior if51/// Note that this causes undefined behavior if
52/// @typeOf(x).is_signed && x == @minValue(@typeOf(x)).52/// @typeOf(x).is_signed and x == @minValue(@typeOf(x)).
53pub fn abs(x: var) -> @typeOf(x) {53pub fn abs(x: var) -> @typeOf(x) {
54 const T = @typeOf(x);54 const T = @typeOf(x);
55 if (@isInteger(T)) {55 if (@isInteger(T)) {
std/net.zig+7-7
...@@ -166,11 +166,11 @@ pub fn parseIpLiteral(buf: []const u8) -> %Address {...@@ -166,11 +166,11 @@ pub fn parseIpLiteral(buf: []const u8) -> %Address {
166166
167fn hexDigit(c: u8) -> u8 {167fn hexDigit(c: u8) -> u8 {
168 // TODO use switch with range168 // TODO use switch with range
169 if ('0' <= c && c <= '9') {169 if ('0' <= c and c <= '9') {
170 c - '0'170 c - '0'
171 } else if ('A' <= c && c <= 'Z') {171 } else if ('A' <= c and c <= 'Z') {
172 c - 'A' + 10172 c - 'A' + 10
173 } else if ('a' <= c && c <= 'z') {173 } else if ('a' <= c and c <= 'z') {
174 c - 'a' + 10174 c - 'a' + 10
175 } else {175 } else {
176 @maxValue(u8)176 @maxValue(u8)
...@@ -194,7 +194,7 @@ fn parseIp6(buf: []const u8) -> %Address {...@@ -194,7 +194,7 @@ fn parseIp6(buf: []const u8) -> %Address {
194 var scope_id = false;194 var scope_id = false;
195 for (buf) |c| {195 for (buf) |c| {
196 if (scope_id) {196 if (scope_id) {
197 if (c >= '0' && c <= '9') {197 if (c >= '0' and c <= '9') {
198 const digit = c - '0';198 const digit = c - '0';
199 if (@mulWithOverflow(u32, result.scope_id, 10, &result.scope_id)) {199 if (@mulWithOverflow(u32, result.scope_id, 10, &result.scope_id)) {
200 return error.Overflow;200 return error.Overflow;
...@@ -255,7 +255,7 @@ fn parseIp6(buf: []const u8) -> %Address {...@@ -255,7 +255,7 @@ fn parseIp6(buf: []const u8) -> %Address {
255// if (isdigit(*++p)) scopeid = strtoull(p, &z, 10);255// if (isdigit(*++p)) scopeid = strtoull(p, &z, 10);
256// else z = p-1;256// else z = p-1;
257// if (*z) {257// if (*z) {
258// if (!IN6_IS_ADDR_LINKLOCAL(&a6) &&258// if (!IN6_IS_ADDR_LINKLOCAL(&a6) and
259// !IN6_IS_ADDR_MC_LINKLOCAL(&a6))259// !IN6_IS_ADDR_MC_LINKLOCAL(&a6))
260// return EAI_NONAME;260// return EAI_NONAME;
261// scopeid = if_nametoindex(p);261// scopeid = if_nametoindex(p);
...@@ -297,7 +297,7 @@ fn parseIp4(buf: []const u8) -> %u32 {...@@ -297,7 +297,7 @@ fn parseIp4(buf: []const u8) -> %u32 {
297 index += 1;297 index += 1;
298 x = 0;298 x = 0;
299 saw_any_digits = false;299 saw_any_digits = false;
300 } else if (c >= '0' && c <= '9') {300 } else if (c >= '0' and c <= '9') {
301 saw_any_digits = true;301 saw_any_digits = true;
302 const digit = c - '0';302 const digit = c - '0';
303 if (@mulWithOverflow(u8, x, 10, &x)) {303 if (@mulWithOverflow(u8, x, 10, &x)) {
...@@ -310,7 +310,7 @@ fn parseIp4(buf: []const u8) -> %u32 {...@@ -310,7 +310,7 @@ fn parseIp4(buf: []const u8) -> %u32 {
310 return error.InvalidChar;310 return error.InvalidChar;
311 } 311 }
312 }312 }
313 if (index == 3 && saw_any_digits) {313 if (index == 3 and saw_any_digits) {
314 out_ptr[index] = x;314 out_ptr[index] = x;
315 return result;315 return result;
316 }316 }
test/cases/bool.zig-12
...@@ -25,18 +25,6 @@ fn testBoolCmp(a: bool, b: bool) -> bool {...@@ -25,18 +25,6 @@ fn testBoolCmp(a: bool, b: bool) -> bool {
25 a == b25 a == b
26}26}
2727
28test "shortCircuitAndOr" {
29 var a = true;
30 a &&= false;
31 assert(!a);
32 a &&= true;
33 assert(!a);
34 a ||= false;
35 assert(!a);
36 a ||= true;
37 assert(a);
38}
39
40const global_f = false;28const global_f = false;
41const global_t = true;29const global_t = true;
42const not_global_f = !global_f;30const not_global_f = !global_f;
test/cases/eval.zig+1-1
...@@ -167,7 +167,7 @@ fn testTryToTrickEvalWithRuntimeIf(b: bool) -> usize {...@@ -167,7 +167,7 @@ fn testTryToTrickEvalWithRuntimeIf(b: bool) -> usize {
167167
168fn max(comptime T: type, a: T, b: T) -> T {168fn max(comptime T: type, a: T, b: T) -> T {
169 if (T == bool) {169 if (T == bool) {
170 return a || b;170 return a or b;
171 } else if (a > b) {171 } else if (a > b) {
172 return a;172 return a;
173 } else {173 } else {
test/cases/math.zig+2-2
...@@ -59,8 +59,8 @@ test "modifyOperators" {...@@ -59,8 +59,8 @@ test "modifyOperators" {
59test "threeExprInARow" {59test "threeExprInARow" {
60}60}
61fn testThreeExprInARow(f: bool, t: bool) {61fn testThreeExprInARow(f: bool, t: bool) {
62 assertFalse(f || f || f);62 assertFalse(f or f or f);
63 assertFalse(t && t && f);63 assertFalse(t and t and f);
64 assertFalse(1 | 2 | 4 != 7);64 assertFalse(1 | 2 | 4 != 7);
65 assertFalse(3 ^ 6 ^ 8 != 13);65 assertFalse(3 ^ 6 ^ 8 != 13);
66 assertFalse(7 & 14 & 28 != 4);66 assertFalse(7 & 14 & 28 != 4);
test/cases/misc.zig+4-4
...@@ -100,17 +100,17 @@ fn testShortCircuit(f: bool, t: bool) {...@@ -100,17 +100,17 @@ fn testShortCircuit(f: bool, t: bool) {
100 var hit_3 = f;100 var hit_3 = f;
101 var hit_4 = f;101 var hit_4 = f;
102102
103 if (t || {assert(f); f}) {103 if (t or {assert(f); f}) {
104 hit_1 = t;104 hit_1 = t;
105 }105 }
106 if (f || { hit_2 = t; f }) {106 if (f or { hit_2 = t; f }) {
107 assert(f);107 assert(f);
108 }108 }
109109
110 if (t && { hit_3 = t; f }) {110 if (t and { hit_3 = t; f }) {
111 assert(f);111 assert(f);
112 }112 }
113 if (f && {assert(f); f}) {113 if (f and {assert(f); f}) {
114 assert(f);114 assert(f);
115 } else {115 } else {
116 hit_4 = t;116 hit_4 = t;