| author | |
| committer | |
| log | f17e20d5fefeb9ce30a08e85c10b9449cf672112 |
| tree | 2907eae05aca64bbab1e7ca0c9c526c1f204848d |
| parent | 7dd29291853a30973c19867385514b6d807cb644 |
closes #3314 files changed, 62 insertions(+), 53 deletions(-)
doc/langref.md+2-2| ... | @@ -60,7 +60,7 @@ ParamDecl : token(Symbol) token(Colon) Type | token(Ellipsis) | ... | @@ -60,7 +60,7 @@ ParamDecl : token(Symbol) token(Colon) Type | token(Ellipsis) |
| 60 | 60 | ||
| 61 | Type : token(Symbol) | token(Unreachable) | token(Void) | PointerType | ArrayType | 61 | Type : token(Symbol) | token(Unreachable) | token(Void) | PointerType | ArrayType |
| 62 | 62 | ||
| 63 | PointerType : token(Star) (token(Const) | token(Mut)) Type | 63 | PointerType : token(Ampersand) option(token(Const)) Type |
| 64 | 64 | ||
| 65 | ArrayType : token(LBracket) Type token(Semicolon) Expression token(RBracket) | 65 | ArrayType : token(LBracket) Type token(Semicolon) Expression token(RBracket) |
| 66 | 66 | ||
| ... | @@ -114,7 +114,7 @@ BinaryOrExpression : BinaryXorExpression token(BinOr) BinaryOrExpression | Binar | ... | @@ -114,7 +114,7 @@ BinaryOrExpression : BinaryXorExpression token(BinOr) BinaryOrExpression | Binar |
| 114 | 114 | ||
| 115 | BinaryXorExpression : BinaryAndExpression token(BinXor) BinaryXorExpression | BinaryAndExpression | 115 | BinaryXorExpression : BinaryAndExpression token(BinXor) BinaryXorExpression | BinaryAndExpression |
| 116 | 116 | ||
| 117 | BinaryAndExpression : BitShiftExpression token(BinAnd) BinaryAndExpression | BitShiftExpression | 117 | BinaryAndExpression : BitShiftExpression token(Ampersand) BinaryAndExpression | BitShiftExpression |
| 118 | 118 | ||
| 119 | BitShiftExpression : AdditionExpression BitShiftOperator BitShiftExpression | AdditionExpression | 119 | BitShiftExpression : AdditionExpression BitShiftOperator BitShiftExpression | AdditionExpression |
| 120 | 120 |
example/arrays/arrays.zig+2-2| ... | @@ -2,7 +2,7 @@ export executable "arrays"; | ... | @@ -2,7 +2,7 @@ export executable "arrays"; |
| 2 | 2 | ||
| 3 | use "std.zig"; | 3 | use "std.zig"; |
| 4 | 4 | ||
| 5 | export fn main(argc: isize, argv: *mut *mut u8, env: *mut *mut u8) -> i32 { | 5 | export fn main(argc: isize, argv: &&u8, env: &&u8) -> i32 { |
| 6 | let mut array : [i32; 5]; | 6 | let mut array : [i32; 5]; |
| 7 | 7 | ||
| 8 | let mut i : i32 = 0; | 8 | let mut i : i32 = 0; |
| ... | @@ -30,7 +30,7 @@ loop_2_start: | ... | @@ -30,7 +30,7 @@ loop_2_start: |
| 30 | loop_2_end: | 30 | loop_2_end: |
| 31 | 31 | ||
| 32 | if accumulator == 15 { | 32 | if accumulator == 15 { |
| 33 | print_str("OK" as string); | 33 | print_str("OK\n" as string); |
| 34 | } | 34 | } |
| 35 | 35 | ||
| 36 | 36 |
example/expressions/expressions.zig+1-1| ... | @@ -2,7 +2,7 @@ export executable "expressions"; | ... | @@ -2,7 +2,7 @@ export executable "expressions"; |
| 2 | 2 | ||
| 3 | #link("c") | 3 | #link("c") |
| 4 | extern { | 4 | extern { |
| 5 | fn puts(s: *const u8) -> i32; | 5 | fn puts(s: &const u8) -> i32; |
| 6 | fn exit(code: i32) -> unreachable; | 6 | fn exit(code: i32) -> unreachable; |
| 7 | } | 7 | } |
| 8 | 8 |
example/hello_world/hello.zig+1-1| ... | @@ -2,7 +2,7 @@ export executable "hello"; | ... | @@ -2,7 +2,7 @@ export executable "hello"; |
| 2 | 2 | ||
| 3 | use "std.zig"; | 3 | use "std.zig"; |
| 4 | 4 | ||
| 5 | export fn main(argc: isize, argv: *mut *mut u8, env: *mut *mut u8) -> i32 { | 5 | export fn main(argc: isize, argv: &&u8, env: &&u8) -> i32 { |
| 6 | // TODO implicit coercion from array to string | 6 | // TODO implicit coercion from array to string |
| 7 | print_str("Hello, world!\n" as string); | 7 | print_str("Hello, world!\n" as string); |
| 8 | return 0; | 8 | return 0; |
example/hello_world/hello_libc.zig+1-1| ... | @@ -2,7 +2,7 @@ export executable "hello"; | ... | @@ -2,7 +2,7 @@ export executable "hello"; |
| 2 | 2 | ||
| 3 | #link("c") | 3 | #link("c") |
| 4 | extern { | 4 | extern { |
| 5 | fn printf(__format: *const u8, ...) -> i32; | 5 | fn printf(__format: &const u8, ...) -> i32; |
| 6 | fn exit(__status: i32) -> unreachable; | 6 | fn exit(__status: i32) -> unreachable; |
| 7 | } | 7 | } |
| 8 | 8 |
example/multiple_files/libc.zig+1-1| ... | @@ -1,5 +1,5 @@ | ... | @@ -1,5 +1,5 @@ |
| 1 | #link("c") | 1 | #link("c") |
| 2 | extern { | 2 | extern { |
| 3 | pub fn puts(s: *const u8) -> i32; | 3 | pub fn puts(s: &const u8) -> i32; |
| 4 | pub fn exit(code: i32) -> unreachable; | 4 | pub fn exit(code: i32) -> unreachable; |
| 5 | } | 5 | } |
example/structs/structs.zig+1-1| ... | @@ -2,7 +2,7 @@ export executable "structs"; | ... | @@ -2,7 +2,7 @@ export executable "structs"; |
| 2 | 2 | ||
| 3 | use "std.zig"; | 3 | use "std.zig"; |
| 4 | 4 | ||
| 5 | export fn main(argc : isize, argv : *mut *mut u8, env : *mut *mut u8) -> i32 { | 5 | export fn main(argc : isize, argv : &&u8, env : &&u8) -> i32 { |
| 6 | let mut foo : Foo; | 6 | let mut foo : Foo; |
| 7 | 7 | ||
| 8 | foo.a = foo.a + 1; | 8 | foo.a = foo.a + 1; |
src/analyze.cpp+1-1| ... | @@ -111,7 +111,7 @@ TypeTableEntry *get_pointer_to_type(CodeGen *g, TypeTableEntry *child_type, bool | ... | @@ -111,7 +111,7 @@ TypeTableEntry *get_pointer_to_type(CodeGen *g, TypeTableEntry *child_type, bool |
| 111 | TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdPointer); | 111 | TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdPointer); |
| 112 | entry->type_ref = LLVMPointerType(child_type->type_ref, 0); | 112 | entry->type_ref = LLVMPointerType(child_type->type_ref, 0); |
| 113 | buf_resize(&entry->name, 0); | 113 | buf_resize(&entry->name, 0); |
| 114 | buf_appendf(&entry->name, "*%s %s", is_const ? "const" : "mut", buf_ptr(&child_type->name)); | 114 | buf_appendf(&entry->name, "&%s%s", is_const ? "const " : "", buf_ptr(&child_type->name)); |
| 115 | entry->size_in_bits = g->pointer_size_bytes * 8; | 115 | entry->size_in_bits = g->pointer_size_bytes * 8; |
| 116 | entry->align_in_bits = g->pointer_size_bytes * 8; | 116 | entry->align_in_bits = g->pointer_size_bytes * 8; |
| 117 | entry->di_type = LLVMZigCreateDebugPointerType(g->dbuilder, child_type->di_type, | 117 | entry->di_type = LLVMZigCreateDebugPointerType(g->dbuilder, child_type->di_type, |
src/parseh.cpp+4-4| ... | @@ -250,9 +250,9 @@ static Buf *to_zig_type(ParseH *p, CXType raw_type) { | ... | @@ -250,9 +250,9 @@ static Buf *to_zig_type(ParseH *p, CXType raw_type) { |
| 250 | CXType pointee_type = clang_getArrayElementType(raw_type); | 250 | CXType pointee_type = clang_getArrayElementType(raw_type); |
| 251 | Buf *pointee_buf = to_zig_type(p, pointee_type); | 251 | Buf *pointee_buf = to_zig_type(p, pointee_type); |
| 252 | if (clang_isConstQualifiedType(pointee_type)) { | 252 | if (clang_isConstQualifiedType(pointee_type)) { |
| 253 | return buf_sprintf("*const %s", buf_ptr(pointee_buf)); | 253 | return buf_sprintf("&const %s", buf_ptr(pointee_buf)); |
| 254 | } else { | 254 | } else { |
| 255 | return buf_sprintf("*mut %s", buf_ptr(pointee_buf)); | 255 | return buf_sprintf("&%s", buf_ptr(pointee_buf)); |
| 256 | } | 256 | } |
| 257 | } | 257 | } |
| 258 | case CXType_Pointer: | 258 | case CXType_Pointer: |
| ... | @@ -265,9 +265,9 @@ static Buf *to_zig_type(ParseH *p, CXType raw_type) { | ... | @@ -265,9 +265,9 @@ static Buf *to_zig_type(ParseH *p, CXType raw_type) { |
| 265 | pointee_buf = to_zig_type(p, pointee_type); | 265 | pointee_buf = to_zig_type(p, pointee_type); |
| 266 | } | 266 | } |
| 267 | if (clang_isConstQualifiedType(pointee_type)) { | 267 | if (clang_isConstQualifiedType(pointee_type)) { |
| 268 | return buf_sprintf("*const %s", buf_ptr(pointee_buf)); | 268 | return buf_sprintf("&const %s", buf_ptr(pointee_buf)); |
| 269 | } else { | 269 | } else { |
| 270 | return buf_sprintf("*mut %s", buf_ptr(pointee_buf)); | 270 | return buf_sprintf("&%s", buf_ptr(pointee_buf)); |
| 271 | } | 271 | } |
| 272 | } | 272 | } |
| 273 | case CXType_Record: | 273 | case CXType_Record: |
src/parser.cpp+24-14| ... | @@ -781,6 +781,7 @@ static AstNode *ast_parse_expression(ParseContext *pc, int *token_index, bool ma | ... | @@ -781,6 +781,7 @@ static AstNode *ast_parse_expression(ParseContext *pc, int *token_index, bool ma |
| 781 | static AstNode *ast_parse_block(ParseContext *pc, int *token_index, bool mandatory); | 781 | static AstNode *ast_parse_block(ParseContext *pc, int *token_index, bool mandatory); |
| 782 | static AstNode *ast_parse_if_expr(ParseContext *pc, int *token_index, bool mandatory); | 782 | static AstNode *ast_parse_if_expr(ParseContext *pc, int *token_index, bool mandatory); |
| 783 | static AstNode *ast_parse_block_expr(ParseContext *pc, int *token_index, bool mandatory); | 783 | static AstNode *ast_parse_block_expr(ParseContext *pc, int *token_index, bool mandatory); |
| 784 | static AstNode *ast_parse_type(ParseContext *pc, int *token_index); | ||
| 784 | 785 | ||
| 785 | static void ast_expect_token(ParseContext *pc, Token *token, TokenId token_id) { | 786 | static void ast_expect_token(ParseContext *pc, Token *token, TokenId token_id) { |
| 786 | if (token->id != token_id) { | 787 | if (token->id != token_id) { |
| ... | @@ -841,10 +842,21 @@ static void ast_parse_directives(ParseContext *pc, int *token_index, | ... | @@ -841,10 +842,21 @@ static void ast_parse_directives(ParseContext *pc, int *token_index, |
| 841 | zig_unreachable(); | 842 | zig_unreachable(); |
| 842 | } | 843 | } |
| 843 | 844 | ||
| 845 | static void ast_parse_type_assume_amp(ParseContext *pc, int *token_index, AstNode *node) { | ||
| 846 | node->data.type.type = AstNodeTypeTypePointer; | ||
| 847 | Token *first_type_token = &pc->tokens->at(*token_index); | ||
| 848 | if (first_type_token->id == TokenIdKeywordConst) { | ||
| 849 | node->data.type.is_const = true; | ||
| 850 | *token_index += 1; | ||
| 851 | first_type_token = &pc->tokens->at(*token_index); | ||
| 852 | } | ||
| 853 | |||
| 854 | node->data.type.child_type = ast_parse_type(pc, token_index); | ||
| 855 | } | ||
| 844 | 856 | ||
| 845 | /* | 857 | /* |
| 846 | Type : token(Symbol) | token(Unreachable) | token(Void) | PointerType | ArrayType | 858 | Type : token(Symbol) | token(Unreachable) | token(Void) | PointerType | ArrayType |
| 847 | PointerType : token(Star) (token(Const) | token(Mut)) Type | 859 | PointerType : token(Ampersand) option(token(Const)) Type |
| 848 | ArrayType : token(LBracket) Type token(Semicolon) token(Number) token(RBracket) | 860 | ArrayType : token(LBracket) Type token(Semicolon) token(Number) token(RBracket) |
| 849 | */ | 861 | */ |
| 850 | static AstNode *ast_parse_type(ParseContext *pc, int *token_index) { | 862 | static AstNode *ast_parse_type(ParseContext *pc, int *token_index) { |
| ... | @@ -862,19 +874,17 @@ static AstNode *ast_parse_type(ParseContext *pc, int *token_index) { | ... | @@ -862,19 +874,17 @@ static AstNode *ast_parse_type(ParseContext *pc, int *token_index) { |
| 862 | } else if (token->id == TokenIdSymbol) { | 874 | } else if (token->id == TokenIdSymbol) { |
| 863 | node->data.type.type = AstNodeTypeTypePrimitive; | 875 | node->data.type.type = AstNodeTypeTypePrimitive; |
| 864 | ast_buf_from_token(pc, token, &node->data.type.primitive_name); | 876 | ast_buf_from_token(pc, token, &node->data.type.primitive_name); |
| 865 | } else if (token->id == TokenIdStar) { | 877 | } else if (token->id == TokenIdAmpersand) { |
| 878 | ast_parse_type_assume_amp(pc, token_index, node); | ||
| 879 | } else if (token->id == TokenIdBoolAnd) { | ||
| 880 | // Pretend that we got 2 ampersand tokens | ||
| 866 | node->data.type.type = AstNodeTypeTypePointer; | 881 | node->data.type.type = AstNodeTypeTypePointer; |
| 867 | Token *const_or_mut = &pc->tokens->at(*token_index); | ||
| 868 | *token_index += 1; | ||
| 869 | if (const_or_mut->id == TokenIdKeywordMut) { | ||
| 870 | node->data.type.is_const = false; | ||
| 871 | } else if (const_or_mut->id == TokenIdKeywordConst) { | ||
| 872 | node->data.type.is_const = true; | ||
| 873 | } else { | ||
| 874 | ast_invalid_token_error(pc, const_or_mut); | ||
| 875 | } | ||
| 876 | 882 | ||
| 877 | node->data.type.child_type = ast_parse_type(pc, token_index); | 883 | node->data.type.child_type = ast_create_node_no_line_info(pc, NodeTypeType); |
| 884 | node->data.type.child_type->line = token->start_line; | ||
| 885 | node->data.type.child_type->column = token->start_column + 1; | ||
| 886 | |||
| 887 | ast_parse_type_assume_amp(pc, token_index, node->data.type.child_type); | ||
| 878 | } else if (token->id == TokenIdLBracket) { | 888 | } else if (token->id == TokenIdLBracket) { |
| 879 | node->data.type.type = AstNodeTypeTypeArray; | 889 | node->data.type.type = AstNodeTypeTypeArray; |
| 880 | 890 | ||
| ... | @@ -1341,7 +1351,7 @@ static AstNode *ast_parse_bit_shift_expr(ParseContext *pc, int *token_index, boo | ... | @@ -1341,7 +1351,7 @@ static AstNode *ast_parse_bit_shift_expr(ParseContext *pc, int *token_index, boo |
| 1341 | 1351 | ||
| 1342 | 1352 | ||
| 1343 | /* | 1353 | /* |
| 1344 | BinaryAndExpression : BitShiftExpression token(BinAnd) BinaryAndExpression | BitShiftExpression | 1354 | BinaryAndExpression : BitShiftExpression token(Ampersand) BinaryAndExpression | BitShiftExpression |
| 1345 | */ | 1355 | */ |
| 1346 | static AstNode *ast_parse_bin_and_expr(ParseContext *pc, int *token_index, bool mandatory) { | 1356 | static AstNode *ast_parse_bin_and_expr(ParseContext *pc, int *token_index, bool mandatory) { |
| 1347 | AstNode *operand_1 = ast_parse_bit_shift_expr(pc, token_index, mandatory); | 1357 | AstNode *operand_1 = ast_parse_bit_shift_expr(pc, token_index, mandatory); |
| ... | @@ -1350,7 +1360,7 @@ static AstNode *ast_parse_bin_and_expr(ParseContext *pc, int *token_index, bool | ... | @@ -1350,7 +1360,7 @@ static AstNode *ast_parse_bin_and_expr(ParseContext *pc, int *token_index, bool |
| 1350 | 1360 | ||
| 1351 | while (true) { | 1361 | while (true) { |
| 1352 | Token *token = &pc->tokens->at(*token_index); | 1362 | Token *token = &pc->tokens->at(*token_index); |
| 1353 | if (token->id != TokenIdBinAnd) | 1363 | if (token->id != TokenIdAmpersand) |
| 1354 | return operand_1; | 1364 | return operand_1; |
| 1355 | *token_index += 1; | 1365 | *token_index += 1; |
| 1356 | 1366 |
src/tokenizer.cpp+2-2| ... | @@ -320,7 +320,7 @@ void tokenize(Buf *buf, Tokenization *out) { | ... | @@ -320,7 +320,7 @@ void tokenize(Buf *buf, Tokenization *out) { |
| 320 | t.state = TokenizeStateSawDash; | 320 | t.state = TokenizeStateSawDash; |
| 321 | break; | 321 | break; |
| 322 | case '&': | 322 | case '&': |
| 323 | begin_token(&t, TokenIdBinAnd); | 323 | begin_token(&t, TokenIdAmpersand); |
| 324 | t.state = TokenizeStateSawAmpersand; | 324 | t.state = TokenizeStateSawAmpersand; |
| 325 | break; | 325 | break; |
| 326 | case '^': | 326 | case '^': |
| ... | @@ -832,7 +832,7 @@ static const char * token_name(Token *token) { | ... | @@ -832,7 +832,7 @@ static const char * token_name(Token *token) { |
| 832 | case TokenIdDash: return "Dash"; | 832 | case TokenIdDash: return "Dash"; |
| 833 | case TokenIdNumberSign: return "NumberSign"; | 833 | case TokenIdNumberSign: return "NumberSign"; |
| 834 | case TokenIdBinOr: return "BinOr"; | 834 | case TokenIdBinOr: return "BinOr"; |
| 835 | case TokenIdBinAnd: return "BinAnd"; | 835 | case TokenIdAmpersand: return "Ampersand"; |
| 836 | case TokenIdBinXor: return "BinXor"; | 836 | case TokenIdBinXor: return "BinXor"; |
| 837 | case TokenIdBoolOr: return "BoolOr"; | 837 | case TokenIdBoolOr: return "BoolOr"; |
| 838 | case TokenIdBoolAnd: return "BoolAnd"; | 838 | case TokenIdBoolAnd: return "BoolAnd"; |
src/tokenizer.hpp+1-1| ... | @@ -52,7 +52,7 @@ enum TokenId { | ... | @@ -52,7 +52,7 @@ enum TokenId { |
| 52 | TokenIdBoolOr, | 52 | TokenIdBoolOr, |
| 53 | TokenIdBoolAnd, | 53 | TokenIdBoolAnd, |
| 54 | TokenIdBinOr, | 54 | TokenIdBinOr, |
| 55 | TokenIdBinAnd, | 55 | TokenIdAmpersand, |
| 56 | TokenIdBinXor, | 56 | TokenIdBinXor, |
| 57 | TokenIdEq, | 57 | TokenIdEq, |
| 58 | TokenIdTimesEq, | 58 | TokenIdTimesEq, |
std/std.zig+1-1| ... | @@ -14,7 +14,7 @@ fn syscall3(number: isize, arg1: isize, arg2: isize, arg3: isize) -> isize { | ... | @@ -14,7 +14,7 @@ fn syscall3(number: isize, arg1: isize, arg2: isize, arg3: isize) -> isize { |
| 14 | } | 14 | } |
| 15 | 15 | ||
| 16 | // TODO constants for SYS_write and stdout_fileno | 16 | // TODO constants for SYS_write and stdout_fileno |
| 17 | pub fn write(fd: isize, buf: *const u8, count: usize) -> isize { | 17 | pub fn write(fd: isize, buf: &const u8, count: usize) -> isize { |
| 18 | let SYS_write : isize = 1; | 18 | let SYS_write : isize = 1; |
| 19 | return syscall3(SYS_write, fd, buf as isize, count as isize); | 19 | return syscall3(SYS_write, fd, buf as isize, count as isize); |
| 20 | } | 20 | } |
test/run_tests.cpp+20-21| ... | @@ -99,7 +99,7 @@ static void add_compiling_test_cases(void) { | ... | @@ -99,7 +99,7 @@ static void add_compiling_test_cases(void) { |
| 99 | add_simple_case("hello world with libc", R"SOURCE( | 99 | add_simple_case("hello world with libc", R"SOURCE( |
| 100 | #link("c") | 100 | #link("c") |
| 101 | extern { | 101 | extern { |
| 102 | fn puts(s: *const u8) -> i32; | 102 | fn puts(s: &const u8) -> i32; |
| 103 | fn exit(code: i32) -> unreachable; | 103 | fn exit(code: i32) -> unreachable; |
| 104 | } | 104 | } |
| 105 | 105 | ||
| ... | @@ -112,7 +112,7 @@ static void add_compiling_test_cases(void) { | ... | @@ -112,7 +112,7 @@ static void add_compiling_test_cases(void) { |
| 112 | add_simple_case("function call", R"SOURCE( | 112 | add_simple_case("function call", R"SOURCE( |
| 113 | #link("c") | 113 | #link("c") |
| 114 | extern { | 114 | extern { |
| 115 | fn puts(s: *const u8) -> i32; | 115 | fn puts(s: &const u8) -> i32; |
| 116 | fn exit(code: i32) -> unreachable; | 116 | fn exit(code: i32) -> unreachable; |
| 117 | } | 117 | } |
| 118 | 118 | ||
| ... | @@ -134,7 +134,7 @@ static void add_compiling_test_cases(void) { | ... | @@ -134,7 +134,7 @@ static void add_compiling_test_cases(void) { |
| 134 | add_simple_case("comments", R"SOURCE( | 134 | add_simple_case("comments", R"SOURCE( |
| 135 | #link("c") | 135 | #link("c") |
| 136 | extern { | 136 | extern { |
| 137 | fn puts(s: *const u8) -> i32; | 137 | fn puts(s: &const u8) -> i32; |
| 138 | fn exit(code: i32) -> unreachable; | 138 | fn exit(code: i32) -> unreachable; |
| 139 | } | 139 | } |
| 140 | 140 | ||
| ... | @@ -169,7 +169,7 @@ static void add_compiling_test_cases(void) { | ... | @@ -169,7 +169,7 @@ static void add_compiling_test_cases(void) { |
| 169 | add_source_file(tc, "libc.zig", R"SOURCE( | 169 | add_source_file(tc, "libc.zig", R"SOURCE( |
| 170 | #link("c") | 170 | #link("c") |
| 171 | extern { | 171 | extern { |
| 172 | pub fn puts(s: *const u8) -> i32; | 172 | pub fn puts(s: &const u8) -> i32; |
| 173 | pub fn exit(code: i32) -> unreachable; | 173 | pub fn exit(code: i32) -> unreachable; |
| 174 | } | 174 | } |
| 175 | )SOURCE"); | 175 | )SOURCE"); |
| ... | @@ -192,7 +192,7 @@ static void add_compiling_test_cases(void) { | ... | @@ -192,7 +192,7 @@ static void add_compiling_test_cases(void) { |
| 192 | add_simple_case("if statements", R"SOURCE( | 192 | add_simple_case("if statements", R"SOURCE( |
| 193 | #link("c") | 193 | #link("c") |
| 194 | extern { | 194 | extern { |
| 195 | fn puts(s: *const u8) -> i32; | 195 | fn puts(s: &const u8) -> i32; |
| 196 | fn exit(code: i32) -> unreachable; | 196 | fn exit(code: i32) -> unreachable; |
| 197 | } | 197 | } |
| 198 | 198 | ||
| ... | @@ -217,7 +217,7 @@ static void add_compiling_test_cases(void) { | ... | @@ -217,7 +217,7 @@ static void add_compiling_test_cases(void) { |
| 217 | add_simple_case("params", R"SOURCE( | 217 | add_simple_case("params", R"SOURCE( |
| 218 | #link("c") | 218 | #link("c") |
| 219 | extern { | 219 | extern { |
| 220 | fn puts(s: *const u8) -> i32; | 220 | fn puts(s: &const u8) -> i32; |
| 221 | fn exit(code: i32) -> unreachable; | 221 | fn exit(code: i32) -> unreachable; |
| 222 | } | 222 | } |
| 223 | 223 | ||
| ... | @@ -236,7 +236,7 @@ static void add_compiling_test_cases(void) { | ... | @@ -236,7 +236,7 @@ static void add_compiling_test_cases(void) { |
| 236 | add_simple_case("goto", R"SOURCE( | 236 | add_simple_case("goto", R"SOURCE( |
| 237 | #link("c") | 237 | #link("c") |
| 238 | extern { | 238 | extern { |
| 239 | fn puts(s: *const u8) -> i32; | 239 | fn puts(s: &const u8) -> i32; |
| 240 | fn exit(code: i32) -> unreachable; | 240 | fn exit(code: i32) -> unreachable; |
| 241 | } | 241 | } |
| 242 | 242 | ||
| ... | @@ -260,7 +260,7 @@ static void add_compiling_test_cases(void) { | ... | @@ -260,7 +260,7 @@ static void add_compiling_test_cases(void) { |
| 260 | add_simple_case("local variables", R"SOURCE( | 260 | add_simple_case("local variables", R"SOURCE( |
| 261 | #link("c") | 261 | #link("c") |
| 262 | extern { | 262 | extern { |
| 263 | fn puts(s: *const u8) -> i32; | 263 | fn puts(s: &const u8) -> i32; |
| 264 | fn exit(code: i32) -> unreachable; | 264 | fn exit(code: i32) -> unreachable; |
| 265 | } | 265 | } |
| 266 | 266 | ||
| ... | @@ -277,7 +277,7 @@ export fn _start() -> unreachable { | ... | @@ -277,7 +277,7 @@ export fn _start() -> unreachable { |
| 277 | add_simple_case("bool literals", R"SOURCE( | 277 | add_simple_case("bool literals", R"SOURCE( |
| 278 | #link("c") | 278 | #link("c") |
| 279 | extern { | 279 | extern { |
| 280 | fn puts(s: *const u8) -> i32; | 280 | fn puts(s: &const u8) -> i32; |
| 281 | fn exit(code: i32) -> unreachable; | 281 | fn exit(code: i32) -> unreachable; |
| 282 | } | 282 | } |
| 283 | 283 | ||
| ... | @@ -293,7 +293,7 @@ export fn _start() -> unreachable { | ... | @@ -293,7 +293,7 @@ export fn _start() -> unreachable { |
| 293 | add_simple_case("separate block scopes", R"SOURCE( | 293 | add_simple_case("separate block scopes", R"SOURCE( |
| 294 | #link("c") | 294 | #link("c") |
| 295 | extern { | 295 | extern { |
| 296 | fn puts(s: *const u8) -> i32; | 296 | fn puts(s: &const u8) -> i32; |
| 297 | fn exit(code: i32) -> unreachable; | 297 | fn exit(code: i32) -> unreachable; |
| 298 | } | 298 | } |
| 299 | 299 | ||
| ... | @@ -315,7 +315,7 @@ export fn _start() -> unreachable { | ... | @@ -315,7 +315,7 @@ export fn _start() -> unreachable { |
| 315 | add_simple_case("void parameters", R"SOURCE( | 315 | add_simple_case("void parameters", R"SOURCE( |
| 316 | #link("c") | 316 | #link("c") |
| 317 | extern { | 317 | extern { |
| 318 | fn puts(s: *const u8) -> i32; | 318 | fn puts(s: &const u8) -> i32; |
| 319 | fn exit(code: i32) -> unreachable; | 319 | fn exit(code: i32) -> unreachable; |
| 320 | } | 320 | } |
| 321 | 321 | ||
| ... | @@ -335,7 +335,7 @@ fn void_fun(a : i32, b : void, c : i32) { | ... | @@ -335,7 +335,7 @@ fn void_fun(a : i32, b : void, c : i32) { |
| 335 | add_simple_case("mutable local variables", R"SOURCE( | 335 | add_simple_case("mutable local variables", R"SOURCE( |
| 336 | #link("c") | 336 | #link("c") |
| 337 | extern { | 337 | extern { |
| 338 | fn puts(s: *const u8) -> i32; | 338 | fn puts(s: &const u8) -> i32; |
| 339 | fn exit(code: i32) -> unreachable; | 339 | fn exit(code: i32) -> unreachable; |
| 340 | } | 340 | } |
| 341 | 341 | ||
| ... | @@ -359,7 +359,7 @@ done: | ... | @@ -359,7 +359,7 @@ done: |
| 359 | add_simple_case("arrays", R"SOURCE( | 359 | add_simple_case("arrays", R"SOURCE( |
| 360 | #link("c") | 360 | #link("c") |
| 361 | extern { | 361 | extern { |
| 362 | fn puts(s: *const u8) -> i32; | 362 | fn puts(s: &const u8) -> i32; |
| 363 | fn exit(code: i32) -> unreachable; | 363 | fn exit(code: i32) -> unreachable; |
| 364 | } | 364 | } |
| 365 | 365 | ||
| ... | @@ -402,7 +402,7 @@ loop_2_end: | ... | @@ -402,7 +402,7 @@ loop_2_end: |
| 402 | add_simple_case("hello world without libc", R"SOURCE( | 402 | add_simple_case("hello world without libc", R"SOURCE( |
| 403 | use "std.zig"; | 403 | use "std.zig"; |
| 404 | 404 | ||
| 405 | export fn main(argc : isize, argv : *mut *mut u8, env : *mut *mut u8) -> i32 { | 405 | export fn main(argc : isize, argv : &&u8, env : &&u8) -> i32 { |
| 406 | print_str("Hello, world!\n" as string); | 406 | print_str("Hello, world!\n" as string); |
| 407 | return 0; | 407 | return 0; |
| 408 | } | 408 | } |
| ... | @@ -412,7 +412,7 @@ export fn main(argc : isize, argv : *mut *mut u8, env : *mut *mut u8) -> i32 { | ... | @@ -412,7 +412,7 @@ export fn main(argc : isize, argv : *mut *mut u8, env : *mut *mut u8) -> i32 { |
| 412 | add_simple_case("a + b + c", R"SOURCE( | 412 | add_simple_case("a + b + c", R"SOURCE( |
| 413 | use "std.zig"; | 413 | use "std.zig"; |
| 414 | 414 | ||
| 415 | export fn main(argc : isize, argv : *mut *mut u8, env : *mut *mut u8) -> i32 { | 415 | export fn main(argc : isize, argv : &&u8, env : &&u8) -> i32 { |
| 416 | if false || false || false { print_str("BAD 1\n" as string); } | 416 | if false || false || false { print_str("BAD 1\n" as string); } |
| 417 | if true && true && false { print_str("BAD 2\n" as string); } | 417 | if true && true && false { print_str("BAD 2\n" as string); } |
| 418 | if 1 | 2 | 4 != 7 { print_str("BAD 3\n" as string); } | 418 | if 1 | 2 | 4 != 7 { print_str("BAD 3\n" as string); } |
| ... | @@ -434,7 +434,7 @@ export fn main(argc : isize, argv : *mut *mut u8, env : *mut *mut u8) -> i32 { | ... | @@ -434,7 +434,7 @@ export fn main(argc : isize, argv : *mut *mut u8, env : *mut *mut u8) -> i32 { |
| 434 | add_simple_case("short circuit", R"SOURCE( | 434 | add_simple_case("short circuit", R"SOURCE( |
| 435 | use "std.zig"; | 435 | use "std.zig"; |
| 436 | 436 | ||
| 437 | export fn main(argc : isize, argv : *mut *mut u8, env : *mut *mut u8) -> i32 { | 437 | export fn main(argc : isize, argv : &&u8, env : &&u8) -> i32 { |
| 438 | if true || { print_str("BAD 1\n" as string); false } { | 438 | if true || { print_str("BAD 1\n" as string); false } { |
| 439 | print_str("OK 1\n" as string); | 439 | print_str("OK 1\n" as string); |
| 440 | } | 440 | } |
| ... | @@ -457,7 +457,7 @@ export fn main(argc : isize, argv : *mut *mut u8, env : *mut *mut u8) -> i32 { | ... | @@ -457,7 +457,7 @@ export fn main(argc : isize, argv : *mut *mut u8, env : *mut *mut u8) -> i32 { |
| 457 | add_simple_case("modify operators", R"SOURCE( | 457 | add_simple_case("modify operators", R"SOURCE( |
| 458 | use "std.zig"; | 458 | use "std.zig"; |
| 459 | 459 | ||
| 460 | export fn main(argc : isize, argv : *mut *mut u8, env : *mut *mut u8) -> i32 { | 460 | export fn main(argc : isize, argv : &&u8, env : &&u8) -> i32 { |
| 461 | let mut i : i32 = 0; | 461 | let mut i : i32 = 0; |
| 462 | i += 5; if i != 5 { print_str("BAD +=\n" as string); } | 462 | i += 5; if i != 5 { print_str("BAD +=\n" as string); } |
| 463 | i -= 2; if i != 3 { print_str("BAD -=\n" as string); } | 463 | i -= 2; if i != 3 { print_str("BAD -=\n" as string); } |
| ... | @@ -480,7 +480,7 @@ export fn main(argc : isize, argv : *mut *mut u8, env : *mut *mut u8) -> i32 { | ... | @@ -480,7 +480,7 @@ export fn main(argc : isize, argv : *mut *mut u8, env : *mut *mut u8) -> i32 { |
| 480 | add_simple_case("structs", R"SOURCE( | 480 | add_simple_case("structs", R"SOURCE( |
| 481 | use "std.zig"; | 481 | use "std.zig"; |
| 482 | 482 | ||
| 483 | export fn main(argc : isize, argv : *mut *mut u8, env : *mut *mut u8) -> i32 { | 483 | export fn main(argc : isize, argv : &&u8, env : &&u8) -> i32 { |
| 484 | let mut foo : Foo; | 484 | let mut foo : Foo; |
| 485 | foo.a = foo.a + 1; | 485 | foo.a = foo.a + 1; |
| 486 | foo.b = foo.a == 1; | 486 | foo.b = foo.a == 1; |
| ... | @@ -542,7 +542,7 @@ fn a() -> bogus {} | ... | @@ -542,7 +542,7 @@ fn a() -> bogus {} |
| 542 | )SOURCE", 1, ".tmp_source.zig:2:11: error: invalid type name: 'bogus'"); | 542 | )SOURCE", 1, ".tmp_source.zig:2:11: error: invalid type name: 'bogus'"); |
| 543 | 543 | ||
| 544 | add_compile_fail_case("pointer to unreachable", R"SOURCE( | 544 | add_compile_fail_case("pointer to unreachable", R"SOURCE( |
| 545 | fn a() -> *mut unreachable {} | 545 | fn a() -> &unreachable {} |
| 546 | )SOURCE", 1, ".tmp_source.zig:2:11: error: pointer to unreachable not allowed"); | 546 | )SOURCE", 1, ".tmp_source.zig:2:11: error: pointer to unreachable not allowed"); |
| 547 | 547 | ||
| 548 | add_compile_fail_case("unreachable code", R"SOURCE( | 548 | add_compile_fail_case("unreachable code", R"SOURCE( |
| ... | @@ -605,7 +605,7 @@ fn f() -> i32 { | ... | @@ -605,7 +605,7 @@ fn f() -> i32 { |
| 605 | let a = c"a"; | 605 | let a = c"a"; |
| 606 | a | 606 | a |
| 607 | } | 607 | } |
| 608 | )SOURCE", 1, ".tmp_source.zig:2:15: error: expected type 'i32', got '*const u8'"); | 608 | )SOURCE", 1, ".tmp_source.zig:2:15: error: expected type 'i32', got '&const u8'"); |
| 609 | 609 | ||
| 610 | add_compile_fail_case("if condition is bool, not int", R"SOURCE( | 610 | add_compile_fail_case("if condition is bool, not int", R"SOURCE( |
| 611 | fn f() { | 611 | fn f() { |
| ... | @@ -682,7 +682,6 @@ fn f() { | ... | @@ -682,7 +682,6 @@ fn f() { |
| 682 | add_compile_fail_case("variadic functions only allowed in extern", R"SOURCE( | 682 | add_compile_fail_case("variadic functions only allowed in extern", R"SOURCE( |
| 683 | fn f(...) {} | 683 | fn f(...) {} |
| 684 | )SOURCE", 1, ".tmp_source.zig:2:1: error: variadic arguments only allowed in extern functions"); | 684 | )SOURCE", 1, ".tmp_source.zig:2:1: error: variadic arguments only allowed in extern functions"); |
| 685 | |||
| 686 | } | 685 | } |
| 687 | 686 | ||
| 688 | static void print_compiler_invocation(TestCase *test_case) { | 687 | static void print_compiler_invocation(TestCase *test_case) { |