authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-12-22 00:50:30-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-12-22 00:50:30-05:00
logd917815d8111b98dc237cbe2c723fa63018e02b1
treece12771a86b2412ee9692ca73d3ca49abe5da3ce
parent8bc523219c66427951e5339550502871547f2138

explicitly return from blocks

instead of last statement being expression value closes #629

114 files changed, 1202 insertions(+), 1230 deletions(-)

doc/docgen.zig+1-1
......@@ -49,7 +49,7 @@ fn gen(in: &io.InStream, out: &io.OutStream) {
4949 if (err == error.EndOfStream) {
5050 return;
5151 }
52 std.debug.panic("{}", err)
52 std.debug.panic("{}", err);
5353 };
5454 switch (state) {
5555 State.Start => switch (byte) {
doc/langref.html.in+2-3
......@@ -3021,14 +3021,13 @@ const assert = @import("std").debug.assert;</code></pre>
30213021 <pre><code class="zig">const assert = @import("std").debug.assert;
30223022
30233023// Functions are declared like this
3024// The last expression in the function can be used as the return value.
30253024fn add(a: i8, b: i8) -&gt; i8 {
30263025 if (a == 0) {
30273026 // You can still return manually if needed.
30283027 return b;
30293028 }
30303029
3031 a + b
3030 return a + b;
30323031}
30333032
30343033// The export specifier makes a function externally visible in the generated
......@@ -5847,7 +5846,7 @@ ParamDeclList = "(" list(ParamDecl, ",") ")"
58475846
58485847ParamDecl = option("noalias" | "comptime") option(Symbol ":") (TypeExpr | "...")
58495848
5850Block = option(Symbol ":") "{" many(Statement) option(Expression) "}"
5849Block = option(Symbol ":") "{" many(Statement) "}"
58515850
58525851Statement = LocalVarDecl ";" | Defer(Block) | Defer(Expression) ";" | BlockExpression(Block) | Expression ";" | ";"
58535852
example/shared_library/mathtest.zig+1-1
......@@ -1,3 +1,3 @@
11export fn add(a: i32, b: i32) -> i32 {
2 a + b
2 return a + b;
33}
src-self-hosted/parser.zig+12-12
......@@ -111,11 +111,11 @@ pub const Parser = struct {
111111 }
112112
113113 pub fn parse(self: &Parser) -> %&ast.NodeRoot {
114 const result = self.parseInner() %% |err| {
114 const result = self.parseInner() %% |err| x: {
115115 if (self.cleanup_root_node) |root_node| {
116116 self.freeAst(root_node);
117117 }
118 err
118 break :x err;
119119 };
120120 self.cleanup_root_node = null;
121121 return result;
......@@ -125,12 +125,12 @@ pub const Parser = struct {
125125 var stack = self.initUtilityArrayList(State);
126126 defer self.deinitUtilityArrayList(stack);
127127
128 const root_node = {
128 const root_node = x: {
129129 const root_node = %return self.createRoot();
130130 %defer self.allocator.destroy(root_node);
131131 // This stack append has to succeed for freeAst to work
132132 %return stack.append(State.TopLevel);
133 root_node
133 break :x root_node;
134134 };
135135 assert(self.cleanup_root_node == null);
136136 self.cleanup_root_node = root_node;
......@@ -462,7 +462,7 @@ pub const Parser = struct {
462462 } else if (token.id == Token.Id.Keyword_noalias) {
463463 param_decl.noalias_token = token;
464464 token = self.getNextToken();
465 };
465 }
466466 if (token.id == Token.Id.Identifier) {
467467 const next_token = self.getNextToken();
468468 if (next_token.id == Token.Id.Colon) {
......@@ -793,14 +793,14 @@ pub const Parser = struct {
793793 }
794794
795795 fn getNextToken(self: &Parser) -> Token {
796 return if (self.put_back_count != 0) {
796 if (self.put_back_count != 0) {
797797 const put_back_index = self.put_back_count - 1;
798798 const put_back_token = self.put_back_tokens[put_back_index];
799799 self.put_back_count = put_back_index;
800 put_back_token
800 return put_back_token;
801801 } else {
802 self.tokenizer.next()
803 };
802 return self.tokenizer.next();
803 }
804804 }
805805
806806 const RenderAstFrame = struct {
......@@ -873,7 +873,7 @@ pub const Parser = struct {
873873 Token.Id.Keyword_pub => %return stream.print("pub "),
874874 Token.Id.Keyword_export => %return stream.print("export "),
875875 else => unreachable,
876 };
876 }
877877 }
878878 if (fn_proto.extern_token) |extern_token| {
879879 %return stream.print("{} ", self.tokenizer.getTokenSlice(extern_token));
......@@ -1102,7 +1102,7 @@ fn testParse(source: []const u8, allocator: &mem.Allocator) -> %[]u8 {
11021102// TODO test for memory leaks
11031103// TODO test for valid frees
11041104fn testCanonical(source: []const u8) {
1105 const needed_alloc_count = {
1105 const needed_alloc_count = x: {
11061106 // Try it once with unlimited memory, make sure it works
11071107 var fixed_allocator = mem.FixedBufferAllocator.init(fixed_buffer_mem[0..]);
11081108 var failing_allocator = std.debug.FailingAllocator.init(&fixed_allocator.allocator, @maxValue(usize));
......@@ -1116,7 +1116,7 @@ fn testCanonical(source: []const u8) {
11161116 @panic("test failed");
11171117 }
11181118 failing_allocator.allocator.free(result_source);
1119 failing_allocator.index
1119 break :x failing_allocator.index;
11201120 };
11211121
11221122 // TODO make this pass
src/all_types.hpp+6-10
......@@ -26,7 +26,6 @@ struct ScopeFnDef;
2626struct TypeTableEntry;
2727struct VariableTableEntry;
2828struct ErrorTableEntry;
29struct LabelTableEntry;
3029struct BuiltinFnEntry;
3130struct TypeStructField;
3231struct CodeGen;
......@@ -54,7 +53,6 @@ struct IrExecutable {
5453 size_t *backward_branch_count;
5554 size_t backward_branch_quota;
5655 bool invalid;
57 ZigList<LabelTableEntry *> all_labels;
5856 ZigList<IrGotoItem> goto_list;
5957 bool is_inline;
6058 FnTableEntry *fn_entry;
......@@ -452,7 +450,6 @@ struct AstNodeParamDecl {
452450struct AstNodeBlock {
453451 Buf *name;
454452 ZigList<AstNode *> statements;
455 bool last_statement_is_result_expression;
456453};
457454
458455enum ReturnKind {
......@@ -1644,12 +1641,6 @@ struct ErrorTableEntry {
16441641 ConstExprValue *cached_error_name_val;
16451642};
16461643
1647struct LabelTableEntry {
1648 AstNode *decl_node;
1649 IrBasicBlock *bb;
1650 bool used;
1651};
1652
16531644enum ScopeId {
16541645 ScopeIdDecls,
16551646 ScopeIdBlock,
......@@ -1693,7 +1684,12 @@ struct ScopeDecls {
16931684struct ScopeBlock {
16941685 Scope base;
16951686
1696 HashMap<Buf *, LabelTableEntry *, buf_hash, buf_eql_buf> label_table;
1687 Buf *name;
1688 IrBasicBlock *end_block;
1689 IrInstruction *is_comptime;
1690 ZigList<IrInstruction *> *incoming_values;
1691 ZigList<IrBasicBlock *> *incoming_blocks;
1692
16971693 bool safety_off;
16981694 AstNode *safety_set_node;
16991695 bool fast_math_off;
src/analyze.cpp+1-1
......@@ -110,7 +110,7 @@ ScopeBlock *create_block_scope(AstNode *node, Scope *parent) {
110110 assert(node->type == NodeTypeBlock);
111111 ScopeBlock *scope = allocate<ScopeBlock>(1);
112112 init_scope(&scope->base, ScopeIdBlock, node, parent);
113 scope->label_table.init(1);
113 scope->name = node->data.block.name;
114114 return scope;
115115}
116116
src/ast_render.cpp+1-4
......@@ -478,10 +478,7 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) {
478478 AstNode *statement = node->data.block.statements.at(i);
479479 print_indent(ar);
480480 render_node_grouped(ar, statement);
481 if (!(i == node->data.block.statements.length - 1 &&
482 node->data.block.last_statement_is_result_expression)) {
483 fprintf(ar->f, ";");
484 }
481 fprintf(ar->f, ";");
485482 fprintf(ar->f, "\n");
486483 }
487484 ar->indent -= ar->indent_size;
src/ir.cpp+64-32
......@@ -3514,7 +3514,11 @@ static VariableTableEntry *ir_create_var(IrBuilder *irb, AstNode *node, Scope *s
35143514static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode *block_node) {
35153515 assert(block_node->type == NodeTypeBlock);
35163516
3517 ZigList<IrInstruction *> incoming_values = {0};
3518 ZigList<IrBasicBlock *> incoming_blocks = {0};
3519
35173520 ScopeBlock *scope_block = create_block_scope(block_node, parent_scope);
3521
35183522 Scope *outer_block_scope = &scope_block->base;
35193523 Scope *child_scope = outer_block_scope;
35203524
......@@ -3528,9 +3532,15 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode
35283532 return ir_mark_gen(ir_build_const_void(irb, child_scope, block_node));
35293533 }
35303534
3535 if (block_node->data.block.name != nullptr) {
3536 scope_block->incoming_blocks = &incoming_blocks;
3537 scope_block->incoming_values = &incoming_values;
3538 scope_block->end_block = ir_build_basic_block(irb, parent_scope, "BlockEnd");
3539 scope_block->is_comptime = ir_build_const_bool(irb, parent_scope, block_node, ir_should_inline(irb->exec, parent_scope));
3540 }
3541
35313542 bool is_continuation_unreachable = false;
35323543 IrInstruction *noreturn_return_value = nullptr;
3533 IrInstruction *return_value = nullptr;
35343544 for (size_t i = 0; i < block_node->data.block.statements.length; i += 1) {
35353545 AstNode *statement_node = block_node->data.block.statements.at(i);
35363546
......@@ -3548,39 +3558,31 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode
35483558 // variable declarations start a new scope
35493559 IrInstructionDeclVar *decl_var_instruction = (IrInstructionDeclVar *)statement_value;
35503560 child_scope = decl_var_instruction->var->child_scope;
3551 } else {
3552 // label, defer, variable declaration will never be the result expression
3553 if (block_node->data.block.last_statement_is_result_expression &&
3554 i == block_node->data.block.statements.length - 1) {
3555 // this is the result value statement
3556 return_value = statement_value;
3557 } else {
3558 // there are more statements ahead of this one. this statement's value must be void
3559 if (statement_value != irb->codegen->invalid_instruction) {
3560 ir_mark_gen(ir_build_check_statement_is_void(irb, child_scope, statement_node, statement_value));
3561 }
3562 }
3561 } else if (statement_value != irb->codegen->invalid_instruction) {
3562 // this statement's value must be void
3563 ir_mark_gen(ir_build_check_statement_is_void(irb, child_scope, statement_node, statement_value));
35633564 }
35643565 }
35653566
35663567 if (is_continuation_unreachable) {
35673568 assert(noreturn_return_value != nullptr);
3568 return noreturn_return_value;
3569 if (block_node->data.block.name == nullptr || incoming_blocks.length == 0) {
3570 return noreturn_return_value;
3571 }
3572 } else {
3573 incoming_blocks.append(irb->current_basic_block);
3574 incoming_values.append(ir_mark_gen(ir_build_const_void(irb, parent_scope, block_node)));
35693575 }
3570 // control flow falls out of block
35713576
3572 if (block_node->data.block.last_statement_is_result_expression) {
3573 // return value was determined by the last statement
3574 assert(return_value != nullptr);
3577 if (block_node->data.block.name != nullptr) {
3578 ir_gen_defers_for_block(irb, child_scope, outer_block_scope, false);
3579 ir_mark_gen(ir_build_br(irb, parent_scope, block_node, scope_block->end_block, scope_block->is_comptime));
3580 ir_set_cursor_at_end(irb, scope_block->end_block);
3581 return ir_build_phi(irb, parent_scope, block_node, incoming_blocks.length, incoming_blocks.items, incoming_values.items);
35753582 } else {
3576 // return value is implicitly void
3577 assert(return_value == nullptr);
3578 return_value = ir_mark_gen(ir_build_const_void(irb, child_scope, block_node));
3583 ir_gen_defers_for_block(irb, child_scope, outer_block_scope, false);
3584 return ir_mark_gen(ir_mark_gen(ir_build_const_void(irb, child_scope, block_node)));
35793585 }
3580
3581 ir_gen_defers_for_block(irb, child_scope, outer_block_scope, false);
3582
3583 return return_value;
35843586}
35853587
35863588static IrInstruction *ir_gen_bin_op_id(IrBuilder *irb, Scope *scope, AstNode *node, IrBinOp op_id) {
......@@ -5952,6 +5954,31 @@ static IrInstruction *ir_gen_comptime(IrBuilder *irb, Scope *parent_scope, AstNo
59525954 return ir_gen_node_extra(irb, node->data.comptime_expr.expr, child_scope, lval);
59535955}
59545956
5957static IrInstruction *ir_gen_return_from_block(IrBuilder *irb, Scope *break_scope, AstNode *node, ScopeBlock *block_scope) {
5958 IrInstruction *is_comptime;
5959 if (ir_should_inline(irb->exec, break_scope)) {
5960 is_comptime = ir_build_const_bool(irb, break_scope, node, true);
5961 } else {
5962 is_comptime = block_scope->is_comptime;
5963 }
5964
5965 IrInstruction *result_value;
5966 if (node->data.break_expr.expr) {
5967 result_value = ir_gen_node(irb, node->data.break_expr.expr, break_scope);
5968 if (result_value == irb->codegen->invalid_instruction)
5969 return irb->codegen->invalid_instruction;
5970 } else {
5971 result_value = ir_build_const_void(irb, break_scope, node);
5972 }
5973
5974 IrBasicBlock *dest_block = block_scope->end_block;
5975 ir_gen_defers_for_block(irb, break_scope, dest_block->scope, false);
5976
5977 block_scope->incoming_blocks->append(irb->current_basic_block);
5978 block_scope->incoming_values->append(result_value);
5979 return ir_build_br(irb, break_scope, node, dest_block, is_comptime);
5980}
5981
59555982static IrInstruction *ir_gen_break(IrBuilder *irb, Scope *break_scope, AstNode *node) {
59565983 assert(node->type == NodeTypeBreak);
59575984
......@@ -5959,14 +5986,14 @@ static IrInstruction *ir_gen_break(IrBuilder *irb, Scope *break_scope, AstNode *
59595986 // * function definition scope or global scope => error, break outside loop
59605987 // * defer expression scope => error, cannot break out of defer expression
59615988 // * loop scope => OK
5989 // * (if it's a labeled break) labeled block => OK
59625990
59635991 Scope *search_scope = break_scope;
59645992 ScopeLoop *loop_scope;
5965 bool saw_any_loop_scope = false;
59665993 for (;;) {
59675994 if (search_scope == nullptr || search_scope->id == ScopeIdFnDef) {
5968 if (saw_any_loop_scope) {
5969 add_node_error(irb->codegen, node, buf_sprintf("labeled loop not found: '%s'", buf_ptr(node->data.break_expr.name)));
5995 if (node->data.break_expr.name != nullptr) {
5996 add_node_error(irb->codegen, node, buf_sprintf("label not found: '%s'", buf_ptr(node->data.break_expr.name)));
59705997 return irb->codegen->invalid_instruction;
59715998 } else {
59725999 add_node_error(irb->codegen, node, buf_sprintf("break expression outside loop"));
......@@ -5977,13 +6004,20 @@ static IrInstruction *ir_gen_break(IrBuilder *irb, Scope *break_scope, AstNode *
59776004 return irb->codegen->invalid_instruction;
59786005 } else if (search_scope->id == ScopeIdLoop) {
59796006 ScopeLoop *this_loop_scope = (ScopeLoop *)search_scope;
5980 saw_any_loop_scope = true;
59816007 if (node->data.break_expr.name == nullptr ||
59826008 (this_loop_scope->name != nullptr && buf_eql_buf(node->data.break_expr.name, this_loop_scope->name)))
59836009 {
59846010 loop_scope = this_loop_scope;
59856011 break;
59866012 }
6013 } else if (search_scope->id == ScopeIdBlock) {
6014 ScopeBlock *this_block_scope = (ScopeBlock *)search_scope;
6015 if (node->data.break_expr.name != nullptr &&
6016 (this_block_scope->name != nullptr && buf_eql_buf(node->data.break_expr.name, this_block_scope->name)))
6017 {
6018 assert(this_block_scope->end_block != nullptr);
6019 return ir_gen_return_from_block(irb, break_scope, node, this_block_scope);
6020 }
59876021 }
59886022 search_scope = search_scope->parent;
59896023 }
......@@ -6022,10 +6056,9 @@ static IrInstruction *ir_gen_continue(IrBuilder *irb, Scope *continue_scope, Ast
60226056
60236057 Scope *search_scope = continue_scope;
60246058 ScopeLoop *loop_scope;
6025 bool saw_any_loop_scope = false;
60266059 for (;;) {
60276060 if (search_scope == nullptr || search_scope->id == ScopeIdFnDef) {
6028 if (saw_any_loop_scope) {
6061 if (node->data.continue_expr.name != nullptr) {
60296062 add_node_error(irb->codegen, node, buf_sprintf("labeled loop not found: '%s'", buf_ptr(node->data.continue_expr.name)));
60306063 return irb->codegen->invalid_instruction;
60316064 } else {
......@@ -6037,7 +6070,6 @@ static IrInstruction *ir_gen_continue(IrBuilder *irb, Scope *continue_scope, Ast
60376070 return irb->codegen->invalid_instruction;
60386071 } else if (search_scope->id == ScopeIdLoop) {
60396072 ScopeLoop *this_loop_scope = (ScopeLoop *)search_scope;
6040 saw_any_loop_scope = true;
60416073 if (node->data.continue_expr.name == nullptr ||
60426074 (this_loop_scope->name != nullptr && buf_eql_buf(node->data.continue_expr.name, this_loop_scope->name)))
60436075 {
src/parser.cpp+20-33
......@@ -748,7 +748,14 @@ static AstNode *ast_parse_primary_expr(ParseContext *pc, size_t *token_index, bo
748748 node->data.fn_call_expr.is_builtin = true;
749749
750750 return node;
751 } else if (token->id == TokenIdSymbol) {
751 }
752
753 AstNode *block_expr_node = ast_parse_block_expr(pc, token_index, false);
754 if (block_expr_node) {
755 return block_expr_node;
756 }
757
758 if (token->id == TokenIdSymbol) {
752759 *token_index += 1;
753760 AstNode *node = ast_create_node(pc, NodeTypeSymbol, token);
754761 node->data.symbol_expr.symbol = token_buf(token);
......@@ -760,11 +767,6 @@ static AstNode *ast_parse_primary_expr(ParseContext *pc, size_t *token_index, bo
760767 return grouped_expr_node;
761768 }
762769
763 AstNode *block_expr_node = ast_parse_block_expr(pc, token_index, false);
764 if (block_expr_node) {
765 return block_expr_node;
766 }
767
768770 AstNode *array_type_node = ast_parse_array_type_expr(pc, token_index, false);
769771 if (array_type_node) {
770772 return array_type_node;
......@@ -2145,9 +2147,6 @@ static AstNode *ast_parse_expression(ParseContext *pc, size_t *token_index, bool
21452147 return nullptr;
21462148}
21472149
2148/*
2149Label: token(Symbol) token(Colon)
2150*/
21512150static bool statement_terminates_without_semicolon(AstNode *node) {
21522151 switch (node->type) {
21532152 case NodeTypeIfBoolExpr:
......@@ -2179,7 +2178,7 @@ static bool statement_terminates_without_semicolon(AstNode *node) {
21792178}
21802179
21812180/*
2182Block = option(Symbol ":") "{" many(Statement) option(Expression) "}"
2181Block = option(Symbol ":") "{" many(Statement) "}"
21832182Statement = Label | VariableDeclaration ";" | Defer(Block) | Defer(Expression) ";" | BlockExpression(Block) | Expression ";" | ";" | ExportDecl
21842183*/
21852184static AstNode *ast_parse_block(ParseContext *pc, size_t *token_index, bool mandatory) {
......@@ -2220,6 +2219,12 @@ static AstNode *ast_parse_block(ParseContext *pc, size_t *token_index, bool mand
22202219 }
22212220
22222221 for (;;) {
2222 last_token = &pc->tokens->at(*token_index);
2223 if (last_token->id == TokenIdRBrace) {
2224 *token_index += 1;
2225 return node;
2226 }
2227
22232228 AstNode *statement_node = ast_parse_local_var_decl(pc, token_index);
22242229 if (!statement_node)
22252230 statement_node = ast_parse_defer_expr(pc, token_index);
......@@ -2228,32 +2233,14 @@ static AstNode *ast_parse_block(ParseContext *pc, size_t *token_index, bool mand
22282233 if (!statement_node)
22292234 statement_node = ast_parse_expression(pc, token_index, false);
22302235
2231 bool semicolon_expected = true;
2232 if (statement_node) {
2233 node->data.block.statements.append(statement_node);
2234 if (statement_terminates_without_semicolon(statement_node)) {
2235 semicolon_expected = false;
2236 } else {
2237 if (statement_node->type == NodeTypeDefer) {
2238 // defer without a block body requires a semicolon
2239 Token *token = &pc->tokens->at(*token_index);
2240 ast_expect_token(pc, token, TokenIdSemicolon);
2241 }
2242 }
2236 if (!statement_node) {
2237 ast_invalid_token_error(pc, last_token);
22432238 }
22442239
2245 node->data.block.last_statement_is_result_expression = statement_node && statement_node->type != NodeTypeDefer;
2240 node->data.block.statements.append(statement_node);
22462241
2247 last_token = &pc->tokens->at(*token_index);
2248 if (last_token->id == TokenIdRBrace) {
2249 *token_index += 1;
2250 return node;
2251 } else if (!semicolon_expected) {
2252 continue;
2253 } else if (last_token->id == TokenIdSemicolon) {
2254 *token_index += 1;
2255 } else {
2256 ast_invalid_token_error(pc, last_token);
2242 if (!statement_terminates_without_semicolon(statement_node)) {
2243 ast_eat_token(pc, token_index, TokenIdSemicolon);
22572244 }
22582245 }
22592246 zig_unreachable();
src/translate_c.cpp+54-32
......@@ -171,6 +171,20 @@ static AstNode * trans_create_node(Context *c, NodeType id) {
171171 return node;
172172}
173173
174static AstNode *trans_create_node_break(Context *c, Buf *label_name, AstNode *value_node) {
175 AstNode *node = trans_create_node(c, NodeTypeBreak);
176 node->data.break_expr.name = label_name;
177 node->data.break_expr.expr = value_node;
178 return node;
179}
180
181static AstNode *trans_create_node_return(Context *c, AstNode *value_node) {
182 AstNode *node = trans_create_node(c, NodeTypeReturnExpr);
183 node->data.return_expr.kind = ReturnKindUnconditional;
184 node->data.return_expr.expr = value_node;
185 return node;
186}
187
174188static AstNode *trans_create_node_if(Context *c, AstNode *cond_node, AstNode *then_node, AstNode *else_node) {
175189 AstNode *node = trans_create_node(c, NodeTypeIfBoolExpr);
176190 node->data.if_bool_expr.condition = cond_node;
......@@ -372,8 +386,7 @@ static AstNode *trans_create_node_inline_fn(Context *c, Buf *fn_name, AstNode *r
372386
373387 AstNode *block = trans_create_node(c, NodeTypeBlock);
374388 block->data.block.statements.resize(1);
375 block->data.block.statements.items[0] = fn_call_node;
376 block->data.block.last_statement_is_result_expression = true;
389 block->data.block.statements.items[0] = trans_create_node_return(c, fn_call_node);
377390
378391 fn_def->data.fn_def.body = block;
379392 return fn_def;
......@@ -1140,13 +1153,15 @@ static AstNode *trans_create_assign(Context *c, ResultUsed result_used, TransSco
11401153 } else {
11411154 // worst case
11421155 // c: lhs = rhs
1143 // zig: {
1156 // zig: x: {
11441157 // zig: const _tmp = rhs;
11451158 // zig: lhs = _tmp;
1146 // zig: _tmp
1159 // zig: break :x _tmp
11471160 // zig: }
11481161
11491162 TransScopeBlock *child_scope = trans_scope_block_create(c, scope);
1163 Buf *label_name = buf_create_from_str("x");
1164 child_scope->node->data.block.name = label_name;
11501165
11511166 // const _tmp = rhs;
11521167 AstNode *rhs_node = trans_expr(c, ResultUsedYes, &child_scope->base, rhs, TransRValue);
......@@ -1163,9 +1178,9 @@ static AstNode *trans_create_assign(Context *c, ResultUsed result_used, TransSco
11631178 trans_create_node_bin_op(c, lhs_node, BinOpTypeAssign,
11641179 trans_create_node_symbol(c, tmp_var_name)));
11651180
1166 // _tmp
1167 child_scope->node->data.block.statements.append(trans_create_node_symbol(c, tmp_var_name));
1168 child_scope->node->data.block.last_statement_is_result_expression = true;
1181 // break :x _tmp
1182 AstNode *tmp_symbol_node = trans_create_node_symbol(c, tmp_var_name);
1183 child_scope->node->data.block.statements.append(trans_create_node_break(c, label_name, tmp_symbol_node));
11691184
11701185 return child_scope->node;
11711186 }
......@@ -1270,6 +1285,9 @@ static AstNode *trans_binary_operator(Context *c, ResultUsed result_used, TransS
12701285 case BO_Comma:
12711286 {
12721287 TransScopeBlock *scope_block = trans_scope_block_create(c, scope);
1288 Buf *label_name = buf_create_from_str("x");
1289 scope_block->node->data.block.name = label_name;
1290
12731291 AstNode *lhs = trans_expr(c, ResultUsedNo, &scope_block->base, stmt->getLHS(), TransRValue);
12741292 if (lhs == nullptr)
12751293 return nullptr;
......@@ -1278,9 +1296,7 @@ static AstNode *trans_binary_operator(Context *c, ResultUsed result_used, TransS
12781296 AstNode *rhs = trans_expr(c, result_used, &scope_block->base, stmt->getRHS(), TransRValue);
12791297 if (rhs == nullptr)
12801298 return nullptr;
1281 scope_block->node->data.block.statements.append(maybe_suppress_result(c, result_used, rhs));
1282
1283 scope_block->node->data.block.last_statement_is_result_expression = true;
1299 scope_block->node->data.block.statements.append(trans_create_node_break(c, label_name, maybe_suppress_result(c, result_used, rhs)));
12841300 return scope_block->node;
12851301 }
12861302 case BO_MulAssign:
......@@ -1320,14 +1336,16 @@ static AstNode *trans_create_compound_assign_shift(Context *c, ResultUsed result
13201336 } else {
13211337 // need more complexity. worst case, this looks like this:
13221338 // c: lhs >>= rhs
1323 // zig: {
1339 // zig: x: {
13241340 // zig: const _ref = &lhs;
13251341 // zig: *_ref = result_type(operation_type(*_ref) >> u5(rhs));
1326 // zig: *_ref
1342 // zig: break :x *_ref
13271343 // zig: }
13281344 // where u5 is the appropriate type
13291345
13301346 TransScopeBlock *child_scope = trans_scope_block_create(c, scope);
1347 Buf *label_name = buf_create_from_str("x");
1348 child_scope->node->data.block.name = label_name;
13311349
13321350 // const _ref = &lhs;
13331351 AstNode *lhs = trans_expr(c, ResultUsedYes, &child_scope->base, stmt->getLHS(), TransLValue);
......@@ -1369,11 +1387,11 @@ static AstNode *trans_create_compound_assign_shift(Context *c, ResultUsed result
13691387 child_scope->node->data.block.statements.append(assign_statement);
13701388
13711389 if (result_used == ResultUsedYes) {
1372 // *_ref
1390 // break :x *_ref
13731391 child_scope->node->data.block.statements.append(
1374 trans_create_node_prefix_op(c, PrefixOpDereference,
1375 trans_create_node_symbol(c, tmp_var_name)));
1376 child_scope->node->data.block.last_statement_is_result_expression = true;
1392 trans_create_node_break(c, label_name,
1393 trans_create_node_prefix_op(c, PrefixOpDereference,
1394 trans_create_node_symbol(c, tmp_var_name))));
13771395 }
13781396
13791397 return child_scope->node;
......@@ -1394,13 +1412,15 @@ static AstNode *trans_create_compound_assign(Context *c, ResultUsed result_used,
13941412 } else {
13951413 // need more complexity. worst case, this looks like this:
13961414 // c: lhs += rhs
1397 // zig: {
1415 // zig: x: {
13981416 // zig: const _ref = &lhs;
13991417 // zig: *_ref = *_ref + rhs;
1400 // zig: *_ref
1418 // zig: break :x *_ref
14011419 // zig: }
14021420
14031421 TransScopeBlock *child_scope = trans_scope_block_create(c, scope);
1422 Buf *label_name = buf_create_from_str("x");
1423 child_scope->node->data.block.name = label_name;
14041424
14051425 // const _ref = &lhs;
14061426 AstNode *lhs = trans_expr(c, ResultUsedYes, &child_scope->base, stmt->getLHS(), TransLValue);
......@@ -1427,11 +1447,11 @@ static AstNode *trans_create_compound_assign(Context *c, ResultUsed result_used,
14271447 rhs));
14281448 child_scope->node->data.block.statements.append(assign_statement);
14291449
1430 // *_ref
1450 // break :x *_ref
14311451 child_scope->node->data.block.statements.append(
1432 trans_create_node_prefix_op(c, PrefixOpDereference,
1433 trans_create_node_symbol(c, tmp_var_name)));
1434 child_scope->node->data.block.last_statement_is_result_expression = true;
1452 trans_create_node_break(c, label_name,
1453 trans_create_node_prefix_op(c, PrefixOpDereference,
1454 trans_create_node_symbol(c, tmp_var_name))));
14351455
14361456 return child_scope->node;
14371457 }
......@@ -1726,13 +1746,15 @@ static AstNode *trans_create_post_crement(Context *c, ResultUsed result_used, Tr
17261746 }
17271747 // worst case
17281748 // c: expr++
1729 // zig: {
1749 // zig: x: {
17301750 // zig: const _ref = &expr;
17311751 // zig: const _tmp = *_ref;
17321752 // zig: *_ref += 1;
1733 // zig: _tmp
1753 // zig: break :x _tmp
17341754 // zig: }
17351755 TransScopeBlock *child_scope = trans_scope_block_create(c, scope);
1756 Buf *label_name = buf_create_from_str("x");
1757 child_scope->node->data.block.name = label_name;
17361758
17371759 // const _ref = &expr;
17381760 AstNode *expr = trans_expr(c, ResultUsedYes, &child_scope->base, op_expr, TransLValue);
......@@ -1758,9 +1780,8 @@ static AstNode *trans_create_post_crement(Context *c, ResultUsed result_used, Tr
17581780 trans_create_node_unsigned(c, 1));
17591781 child_scope->node->data.block.statements.append(assign_statement);
17601782
1761 // _tmp
1762 child_scope->node->data.block.statements.append(trans_create_node_symbol(c, tmp_var_name));
1763 child_scope->node->data.block.last_statement_is_result_expression = true;
1783 // break :x _tmp
1784 child_scope->node->data.block.statements.append(trans_create_node_break(c, label_name, trans_create_node_symbol(c, tmp_var_name)));
17641785
17651786 return child_scope->node;
17661787}
......@@ -1781,12 +1802,14 @@ static AstNode *trans_create_pre_crement(Context *c, ResultUsed result_used, Tra
17811802 }
17821803 // worst case
17831804 // c: ++expr
1784 // zig: {
1805 // zig: x: {
17851806 // zig: const _ref = &expr;
17861807 // zig: *_ref += 1;
1787 // zig: *_ref
1808 // zig: break :x *_ref
17881809 // zig: }
17891810 TransScopeBlock *child_scope = trans_scope_block_create(c, scope);
1811 Buf *label_name = buf_create_from_str("x");
1812 child_scope->node->data.block.name = label_name;
17901813
17911814 // const _ref = &expr;
17921815 AstNode *expr = trans_expr(c, ResultUsedYes, &child_scope->base, op_expr, TransLValue);
......@@ -1805,11 +1828,10 @@ static AstNode *trans_create_pre_crement(Context *c, ResultUsed result_used, Tra
18051828 trans_create_node_unsigned(c, 1));
18061829 child_scope->node->data.block.statements.append(assign_statement);
18071830
1808 // *_ref
1831 // break :x *_ref
18091832 AstNode *deref_expr = trans_create_node_prefix_op(c, PrefixOpDereference,
18101833 trans_create_node_symbol(c, ref_var_name));
1811 child_scope->node->data.block.statements.append(deref_expr);
1812 child_scope->node->data.block.last_statement_is_result_expression = true;
1834 child_scope->node->data.block.statements.append(trans_create_node_break(c, label_name, deref_expr));
18131835
18141836 return child_scope->node;
18151837}
std/array_list.zig+4-4
......@@ -8,7 +8,7 @@ pub fn ArrayList(comptime T: type) -> type {
88}
99
1010pub fn AlignedArrayList(comptime T: type, comptime A: u29) -> type{
11 struct {
11 return struct {
1212 const Self = this;
1313
1414 /// Use toSlice instead of slicing this directly, because if you don't
......@@ -20,11 +20,11 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) -> type{
2020
2121 /// Deinitialize with `deinit` or use `toOwnedSlice`.
2222 pub fn init(allocator: &Allocator) -> Self {
23 Self {
23 return Self {
2424 .items = []align(A) T{},
2525 .len = 0,
2626 .allocator = allocator,
27 }
27 };
2828 }
2929
3030 pub fn deinit(l: &Self) {
......@@ -107,7 +107,7 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) -> type{
107107 return null;
108108 return self.pop();
109109 }
110 }
110 };
111111}
112112
113113test "basic ArrayList test" {
std/buffer.zig+3-3
......@@ -30,9 +30,9 @@ pub const Buffer = struct {
3030 /// * ::replaceContentsBuffer
3131 /// * ::resize
3232 pub fn initNull(allocator: &Allocator) -> Buffer {
33 Buffer {
33 return Buffer {
3434 .list = ArrayList(u8).init(allocator),
35 }
35 };
3636 }
3737
3838 /// Must deinitialize with deinit.
......@@ -120,7 +120,7 @@ pub const Buffer = struct {
120120 }
121121
122122 pub fn eql(self: &const Buffer, m: []const u8) -> bool {
123 mem.eql(u8, self.toSliceConst(), m)
123 return mem.eql(u8, self.toSliceConst(), m);
124124 }
125125
126126 pub fn startsWith(self: &const Buffer, m: []const u8) -> bool {
std/build.zig+26-30
......@@ -221,11 +221,11 @@ pub const Builder = struct {
221221 }
222222
223223 pub fn version(self: &const Builder, major: u32, minor: u32, patch: u32) -> Version {
224 Version {
224 return Version {
225225 .major = major,
226226 .minor = minor,
227227 .patch = patch,
228 }
228 };
229229 }
230230
231231 pub fn addCIncludePath(self: &Builder, path: []const u8) {
......@@ -432,16 +432,16 @@ pub const Builder = struct {
432432 const release_safe = self.option(bool, "release-safe", "optimizations on and safety on") ?? false;
433433 const release_fast = self.option(bool, "release-fast", "optimizations on and safety off") ?? false;
434434
435 const mode = if (release_safe and !release_fast) {
435 const mode = if (release_safe and !release_fast)
436436 builtin.Mode.ReleaseSafe
437 } else if (release_fast and !release_safe) {
437 else if (release_fast and !release_safe)
438438 builtin.Mode.ReleaseFast
439 } else if (!release_fast and !release_safe) {
439 else if (!release_fast and !release_safe)
440440 builtin.Mode.Debug
441 } else {
441 else x: {
442442 warn("Both -Drelease-safe and -Drelease-fast specified");
443443 self.markInvalidUserInput();
444 builtin.Mode.Debug
444 break :x builtin.Mode.Debug;
445445 };
446446 self.release_mode = mode;
447447 return mode;
......@@ -506,7 +506,7 @@ pub const Builder = struct {
506506 }
507507
508508 fn typeToEnum(comptime T: type) -> TypeId {
509 switch (@typeId(T)) {
509 return switch (@typeId(T)) {
510510 builtin.TypeId.Int => TypeId.Int,
511511 builtin.TypeId.Float => TypeId.Float,
512512 builtin.TypeId.Bool => TypeId.Bool,
......@@ -515,7 +515,7 @@ pub const Builder = struct {
515515 []const []const u8 => TypeId.List,
516516 else => @compileError("Unsupported type: " ++ @typeName(T)),
517517 },
518 }
518 };
519519 }
520520
521521 fn markInvalidUserInput(self: &Builder) {
......@@ -590,8 +590,7 @@ pub const Builder = struct {
590590
591591 return error.UncleanExit;
592592 },
593 };
594
593 }
595594 }
596595
597596 pub fn makePath(self: &Builder, path: []const u8) -> %void {
......@@ -662,13 +661,12 @@ pub const Builder = struct {
662661 if (builtin.environ == builtin.Environ.msvc) {
663662 return "cl.exe";
664663 } else {
665 return os.getEnvVarOwned(self.allocator, "CC") %% |err| {
666 if (err == error.EnvironmentVariableNotFound) {
664 return os.getEnvVarOwned(self.allocator, "CC") %% |err|
665 if (err == error.EnvironmentVariableNotFound)
667666 ([]const u8)("cc")
668 } else {
669 debug.panic("Unable to get environment variable: {}", err);
670 }
671 };
667 else
668 debug.panic("Unable to get environment variable: {}", err)
669 ;
672670 }
673671 }
674672
......@@ -1079,11 +1077,10 @@ pub const LibExeObjStep = struct {
10791077 }
10801078
10811079 pub fn getOutputPath(self: &LibExeObjStep) -> []const u8 {
1082 if (self.output_path) |output_path| {
1080 return if (self.output_path) |output_path|
10831081 output_path
1084 } else {
1085 %%os.path.join(self.builder.allocator, self.builder.cache_root, self.out_filename)
1086 }
1082 else
1083 %%os.path.join(self.builder.allocator, self.builder.cache_root, self.out_filename);
10871084 }
10881085
10891086 pub fn setOutputHPath(self: &LibExeObjStep, file_path: []const u8) {
......@@ -1096,11 +1093,10 @@ pub const LibExeObjStep = struct {
10961093 }
10971094
10981095 pub fn getOutputHPath(self: &LibExeObjStep) -> []const u8 {
1099 if (self.output_h_path) |output_h_path| {
1096 return if (self.output_h_path) |output_h_path|
11001097 output_h_path
1101 } else {
1102 %%os.path.join(self.builder.allocator, self.builder.cache_root, self.out_h_filename)
1103 }
1098 else
1099 %%os.path.join(self.builder.allocator, self.builder.cache_root, self.out_h_filename);
11041100 }
11051101
11061102 pub fn addAssemblyFile(self: &LibExeObjStep, path: []const u8) {
......@@ -1618,7 +1614,7 @@ pub const TestStep = struct {
16181614
16191615 pub fn init(builder: &Builder, root_src: []const u8) -> TestStep {
16201616 const step_name = builder.fmt("test {}", root_src);
1621 TestStep {
1617 return TestStep {
16221618 .step = Step.init(step_name, builder.allocator, make),
16231619 .builder = builder,
16241620 .root_src = root_src,
......@@ -1629,7 +1625,7 @@ pub const TestStep = struct {
16291625 .link_libs = BufSet.init(builder.allocator),
16301626 .target = Target { .Native = {} },
16311627 .exec_cmd_args = null,
1632 }
1628 };
16331629 }
16341630
16351631 pub fn setVerbose(self: &TestStep, value: bool) {
......@@ -1936,16 +1932,16 @@ pub const Step = struct {
19361932 done_flag: bool,
19371933
19381934 pub fn init(name: []const u8, allocator: &Allocator, makeFn: fn (&Step)->%void) -> Step {
1939 Step {
1935 return Step {
19401936 .name = name,
19411937 .makeFn = makeFn,
19421938 .dependencies = ArrayList(&Step).init(allocator),
19431939 .loop_flag = false,
19441940 .done_flag = false,
1945 }
1941 };
19461942 }
19471943 pub fn initNoOp(name: []const u8, allocator: &Allocator) -> Step {
1948 init(name, allocator, makeNoOp)
1944 return init(name, allocator, makeNoOp);
19491945 }
19501946
19511947 pub fn make(self: &Step) -> %void {
std/cstr.zig+1-1
......@@ -17,7 +17,7 @@ pub fn cmp(a: &const u8, b: &const u8) -> i8 {
1717 return -1;
1818 } else {
1919 return 0;
20 };
20 }
2121}
2222
2323pub fn toSliceConst(str: &const u8) -> []const u8 {
std/debug.zig+37-49
......@@ -32,7 +32,7 @@ fn getStderrStream() -> %&io.OutStream {
3232 const st = &stderr_file_out_stream.stream;
3333 stderr_stream = st;
3434 return st;
35 };
35 }
3636}
3737
3838/// Tries to print a stack trace to stderr, unbuffered, and ignores any error returned.
......@@ -52,9 +52,9 @@ pub fn assert(ok: bool) {
5252 // we insert an explicit call to @panic instead of unreachable.
5353 // TODO we should use `assertOrPanic` in tests and remove this logic.
5454 if (builtin.is_test) {
55 @panic("assertion failure")
55 @panic("assertion failure");
5656 } else {
57 unreachable // assertion failure
57 unreachable; // assertion failure
5858 }
5959 }
6060}
......@@ -175,7 +175,7 @@ pub fn writeStackTrace(out_stream: &io.OutStream, allocator: &mem.Allocator, tty
175175 return_address, compile_unit_name);
176176 },
177177 else => return err,
178 };
178 }
179179 }
180180 },
181181 builtin.ObjectFormat.coff => {
......@@ -357,7 +357,7 @@ const Die = struct {
357357 FormValue.String => |value| value,
358358 FormValue.StrPtr => |offset| getString(st, offset),
359359 else => error.InvalidDebugInfo,
360 }
360 };
361361 }
362362};
363363
......@@ -403,7 +403,7 @@ const LineNumberProgram = struct {
403403 pub fn init(is_stmt: bool, include_dirs: []const []const u8,
404404 file_entries: &ArrayList(FileEntry), target_address: usize) -> LineNumberProgram
405405 {
406 LineNumberProgram {
406 return LineNumberProgram {
407407 .address = 0,
408408 .file = 1,
409409 .line = 1,
......@@ -421,7 +421,7 @@ const LineNumberProgram = struct {
421421 .prev_is_stmt = undefined,
422422 .prev_basic_block = undefined,
423423 .prev_end_sequence = undefined,
424 }
424 };
425425 }
426426
427427 pub fn checkLineMatch(self: &LineNumberProgram) -> %?LineInfo {
......@@ -430,14 +430,11 @@ const LineNumberProgram = struct {
430430 return error.MissingDebugInfo;
431431 } else if (self.prev_file - 1 >= self.file_entries.len) {
432432 return error.InvalidDebugInfo;
433 } else {
434 &self.file_entries.items[self.prev_file - 1]
435 };
433 } else &self.file_entries.items[self.prev_file - 1];
434
436435 const dir_name = if (file_entry.dir_index >= self.include_dirs.len) {
437436 return error.InvalidDebugInfo;
438 } else {
439 self.include_dirs[file_entry.dir_index]
440 };
437 } else self.include_dirs[file_entry.dir_index];
441438 const file_name = %return os.path.join(self.file_entries.allocator, dir_name, file_entry.file_name);
442439 %defer self.file_entries.allocator.free(file_name);
443440 return LineInfo {
......@@ -494,28 +491,21 @@ fn parseFormValueBlock(allocator: &mem.Allocator, in_stream: &io.InStream, size:
494491}
495492
496493fn parseFormValueConstant(allocator: &mem.Allocator, in_stream: &io.InStream, signed: bool, size: usize) -> %FormValue {
497 FormValue { .Const = Constant {
494 return FormValue { .Const = Constant {
498495 .signed = signed,
499496 .payload = %return readAllocBytes(allocator, in_stream, size),
500 }}
497 }};
501498}
502499
503500fn parseFormValueDwarfOffsetSize(in_stream: &io.InStream, is_64: bool) -> %u64 {
504 return if (is_64) {
505 %return in_stream.readIntLe(u64)
506 } else {
507 u64(%return in_stream.readIntLe(u32))
508 };
501 return if (is_64) %return in_stream.readIntLe(u64)
502 else u64(%return in_stream.readIntLe(u32)) ;
509503}
510504
511505fn parseFormValueTargetAddrSize(in_stream: &io.InStream) -> %u64 {
512 return if (@sizeOf(usize) == 4) {
513 u64(%return in_stream.readIntLe(u32))
514 } else if (@sizeOf(usize) == 8) {
515 %return in_stream.readIntLe(u64)
516 } else {
517 unreachable;
518 };
506 return if (@sizeOf(usize) == 4) u64(%return in_stream.readIntLe(u32))
507 else if (@sizeOf(usize) == 8) %return in_stream.readIntLe(u64)
508 else unreachable;
519509}
520510
521511fn parseFormValueRefLen(allocator: &mem.Allocator, in_stream: &io.InStream, size: usize) -> %FormValue {
......@@ -534,9 +524,9 @@ fn parseFormValue(allocator: &mem.Allocator, in_stream: &io.InStream, form_id: u
534524 DW.FORM_block1 => parseFormValueBlock(allocator, in_stream, 1),
535525 DW.FORM_block2 => parseFormValueBlock(allocator, in_stream, 2),
536526 DW.FORM_block4 => parseFormValueBlock(allocator, in_stream, 4),
537 DW.FORM_block => {
527 DW.FORM_block => x: {
538528 const block_len = %return readULeb128(in_stream);
539 parseFormValueBlockLen(allocator, in_stream, block_len)
529 return parseFormValueBlockLen(allocator, in_stream, block_len);
540530 },
541531 DW.FORM_data1 => parseFormValueConstant(allocator, in_stream, false, 1),
542532 DW.FORM_data2 => parseFormValueConstant(allocator, in_stream, false, 2),
......@@ -545,7 +535,7 @@ fn parseFormValue(allocator: &mem.Allocator, in_stream: &io.InStream, form_id: u
545535 DW.FORM_udata, DW.FORM_sdata => {
546536 const block_len = %return readULeb128(in_stream);
547537 const signed = form_id == DW.FORM_sdata;
548 parseFormValueConstant(allocator, in_stream, signed, block_len)
538 return parseFormValueConstant(allocator, in_stream, signed, block_len);
549539 },
550540 DW.FORM_exprloc => {
551541 const size = %return readULeb128(in_stream);
......@@ -562,7 +552,7 @@ fn parseFormValue(allocator: &mem.Allocator, in_stream: &io.InStream, form_id: u
562552 DW.FORM_ref8 => parseFormValueRef(allocator, in_stream, u64),
563553 DW.FORM_ref_udata => {
564554 const ref_len = %return readULeb128(in_stream);
565 parseFormValueRefLen(allocator, in_stream, ref_len)
555 return parseFormValueRefLen(allocator, in_stream, ref_len);
566556 },
567557
568558 DW.FORM_ref_addr => FormValue { .RefAddr = %return parseFormValueDwarfOffsetSize(in_stream, is_64) },
......@@ -572,10 +562,10 @@ fn parseFormValue(allocator: &mem.Allocator, in_stream: &io.InStream, form_id: u
572562 DW.FORM_strp => FormValue { .StrPtr = %return parseFormValueDwarfOffsetSize(in_stream, is_64) },
573563 DW.FORM_indirect => {
574564 const child_form_id = %return readULeb128(in_stream);
575 parseFormValue(allocator, in_stream, child_form_id, is_64)
565 return parseFormValue(allocator, in_stream, child_form_id, is_64);
576566 },
577567 else => error.InvalidDebugInfo,
578 }
568 };
579569}
580570
581571fn parseAbbrevTable(st: &ElfStackTrace) -> %AbbrevTable {
......@@ -852,11 +842,9 @@ fn scanAllCompileUnits(st: &ElfStackTrace) -> %void {
852842 const version = %return in_stream.readInt(st.elf.endian, u16);
853843 if (version < 2 or version > 5) return error.InvalidDebugInfo;
854844
855 const debug_abbrev_offset = if (is_64) {
856 %return in_stream.readInt(st.elf.endian, u64)
857 } else {
858 %return in_stream.readInt(st.elf.endian, u32)
859 };
845 const debug_abbrev_offset =
846 if (is_64) %return in_stream.readInt(st.elf.endian, u64)
847 else %return in_stream.readInt(st.elf.endian, u32);
860848
861849 const address_size = %return in_stream.readByte();
862850 if (address_size != @sizeOf(usize)) return error.InvalidDebugInfo;
......@@ -872,28 +860,28 @@ fn scanAllCompileUnits(st: &ElfStackTrace) -> %void {
872860 if (compile_unit_die.tag_id != DW.TAG_compile_unit)
873861 return error.InvalidDebugInfo;
874862
875 const pc_range = {
863 const pc_range = x: {
876864 if (compile_unit_die.getAttrAddr(DW.AT_low_pc)) |low_pc| {
877865 if (compile_unit_die.getAttr(DW.AT_high_pc)) |high_pc_value| {
878866 const pc_end = switch (*high_pc_value) {
879867 FormValue.Address => |value| value,
880 FormValue.Const => |value| {
868 FormValue.Const => |value| b: {
881869 const offset = %return value.asUnsignedLe();
882 low_pc + offset
870 break :b (low_pc + offset);
883871 },
884872 else => return error.InvalidDebugInfo,
885873 };
886 PcRange {
874 break :x PcRange {
887875 .start = low_pc,
888876 .end = pc_end,
889 }
877 };
890878 } else {
891 null
879 break :x null;
892880 }
893881 } else |err| {
894882 if (err != error.MissingDebugInfo)
895883 return err;
896 null
884 break :x null;
897885 }
898886 };
899887
......@@ -949,12 +937,12 @@ fn findCompileUnit(st: &ElfStackTrace, target_address: u64) -> %&const CompileUn
949937fn readInitialLength(in_stream: &io.InStream, is_64: &bool) -> %u64 {
950938 const first_32_bits = %return in_stream.readIntLe(u32);
951939 *is_64 = (first_32_bits == 0xffffffff);
952 return if (*is_64) {
953 %return in_stream.readIntLe(u64)
940 if (*is_64) {
941 return in_stream.readIntLe(u64);
954942 } else {
955943 if (first_32_bits >= 0xfffffff0) return error.InvalidDebugInfo;
956 u64(first_32_bits)
957 };
944 return u64(first_32_bits);
945 }
958946}
959947
960948fn readULeb128(in_stream: &io.InStream) -> %u64 {
std/endian.zig+3-3
......@@ -2,15 +2,15 @@ const mem = @import("mem.zig");
22const builtin = @import("builtin");
33
44pub fn swapIfLe(comptime T: type, x: T) -> T {
5 swapIf(false, T, x)
5 return swapIf(false, T, x);
66}
77
88pub fn swapIfBe(comptime T: type, x: T) -> T {
9 swapIf(true, T, x)
9 return swapIf(true, T, x);
1010}
1111
1212pub fn swapIf(endian: builtin.Endian, comptime T: type, x: T) -> T {
13 if (builtin.endian == endian) swap(T, x) else x
13 return if (builtin.endian == endian) swap(T, x) else x;
1414}
1515
1616pub fn swap(comptime T: type, x: T) -> T {
std/fmt/errol/enum3.zig+2-2
......@@ -439,10 +439,10 @@ const Slab = struct {
439439};
440440
441441fn slab(str: []const u8, exp: i32) -> Slab {
442 Slab {
442 return Slab {
443443 .str = str,
444444 .exp = exp,
445 }
445 };
446446}
447447
448448pub const enum3_data = []Slab {
std/fmt/index.zig+3-4
......@@ -251,11 +251,10 @@ pub fn formatFloat(value: var, context: var, output: fn(@typeOf(context), []cons
251251 %return output(context, float_decimal.digits[0..1]);
252252 %return output(context, ".");
253253 if (float_decimal.digits.len > 1) {
254 const num_digits = if (@typeOf(value) == f32) {
254 const num_digits = if (@typeOf(value) == f32)
255255 math.min(usize(9), float_decimal.digits.len)
256 } else {
257 float_decimal.digits.len
258 };
256 else
257 float_decimal.digits.len;
259258 %return output(context, float_decimal.digits[1 .. num_digits]);
260259 } else {
261260 %return output(context, "0");
std/hash_map.zig+10-10
......@@ -12,7 +12,7 @@ pub fn HashMap(comptime K: type, comptime V: type,
1212 comptime hash: fn(key: K)->u32,
1313 comptime eql: fn(a: K, b: K)->bool) -> type
1414{
15 struct {
15 return struct {
1616 entries: []Entry,
1717 size: usize,
1818 max_distance_from_start_index: usize,
......@@ -51,19 +51,19 @@ pub fn HashMap(comptime K: type, comptime V: type,
5151 return entry;
5252 }
5353 }
54 unreachable // no next item
54 unreachable; // no next item
5555 }
5656 };
5757
5858 pub fn init(allocator: &Allocator) -> Self {
59 Self {
59 return Self {
6060 .entries = []Entry{},
6161 .allocator = allocator,
6262 .size = 0,
6363 .max_distance_from_start_index = 0,
6464 // it doesn't actually matter what we set this to since we use wrapping integer arithmetic
6565 .modification_count = undefined,
66 }
66 };
6767 }
6868
6969 pub fn deinit(hm: &Self) {
......@@ -133,7 +133,7 @@ pub fn HashMap(comptime K: type, comptime V: type,
133133 entry.distance_from_start_index -= 1;
134134 entry = next_entry;
135135 }
136 unreachable // shifting everything in the table
136 unreachable; // shifting everything in the table
137137 }}
138138 return null;
139139 }
......@@ -169,7 +169,7 @@ pub fn HashMap(comptime K: type, comptime V: type,
169169 const start_index = hm.keyToIndex(key);
170170 var roll_over: usize = 0;
171171 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;}) {
173173 const index = (start_index + roll_over) % hm.entries.len;
174174 const entry = &hm.entries[index];
175175
......@@ -210,7 +210,7 @@ pub fn HashMap(comptime K: type, comptime V: type,
210210 };
211211 return result;
212212 }
213 unreachable // put into a full map
213 unreachable; // put into a full map
214214 }
215215
216216 fn internalGet(hm: &Self, key: K) -> ?&Entry {
......@@ -228,7 +228,7 @@ pub fn HashMap(comptime K: type, comptime V: type,
228228 fn keyToIndex(hm: &Self, key: K) -> usize {
229229 return usize(hash(key)) % hm.entries.len;
230230 }
231 }
231 };
232232}
233233
234234test "basicHashMapTest" {
......@@ -251,9 +251,9 @@ test "basicHashMapTest" {
251251}
252252
253253fn hash_i32(x: i32) -> u32 {
254 @bitCast(u32, x)
254 return @bitCast(u32, x);
255255}
256256
257257fn eql_i32(a: i32, b: i32) -> bool {
258 a == b
258 return a == b;
259259}
std/heap.zig+6-7
......@@ -17,22 +17,21 @@ pub var c_allocator = Allocator {
1717};
1818
1919fn cAlloc(self: &Allocator, n: usize, alignment: u29) -> %[]u8 {
20 if (c.malloc(usize(n))) |buf| {
20 return if (c.malloc(usize(n))) |buf|
2121 @ptrCast(&u8, buf)[0..n]
22 } else {
23 error.OutOfMemory
24 }
22 else
23 error.OutOfMemory;
2524}
2625
2726fn cRealloc(self: &Allocator, old_mem: []u8, new_size: usize, alignment: u29) -> %[]u8 {
2827 if (new_size <= old_mem.len) {
29 old_mem[0..new_size]
28 return old_mem[0..new_size];
3029 } else {
3130 const old_ptr = @ptrCast(&c_void, old_mem.ptr);
3231 if (c.realloc(old_ptr, usize(new_size))) |buf| {
33 @ptrCast(&u8, buf)[0..new_size]
32 return @ptrCast(&u8, buf)[0..new_size];
3433 } else {
35 error.OutOfMemory
34 return error.OutOfMemory;
3635 }
3736 }
3837}
std/io.zig+13-16
......@@ -50,35 +50,32 @@ error Unseekable;
5050error EndOfFile;
5151
5252pub fn getStdErr() -> %File {
53 const handle = if (is_windows) {
53 const handle = if (is_windows)
5454 %return os.windowsGetStdHandle(system.STD_ERROR_HANDLE)
55 } else if (is_posix) {
55 else if (is_posix)
5656 system.STDERR_FILENO
57 } else {
58 unreachable
59 };
57 else
58 unreachable;
6059 return File.openHandle(handle);
6160}
6261
6362pub fn getStdOut() -> %File {
64 const handle = if (is_windows) {
63 const handle = if (is_windows)
6564 %return os.windowsGetStdHandle(system.STD_OUTPUT_HANDLE)
66 } else if (is_posix) {
65 else if (is_posix)
6766 system.STDOUT_FILENO
68 } else {
69 unreachable
70 };
67 else
68 unreachable;
7169 return File.openHandle(handle);
7270}
7371
7472pub fn getStdIn() -> %File {
75 const handle = if (is_windows) {
73 const handle = if (is_windows)
7674 %return os.windowsGetStdHandle(system.STD_INPUT_HANDLE)
77 } else if (is_posix) {
75 else if (is_posix)
7876 system.STDIN_FILENO
79 } else {
80 unreachable
81 };
77 else
78 unreachable;
8279 return File.openHandle(handle);
8380}
8481
......@@ -261,7 +258,7 @@ pub const File = struct {
261258 system.EBADF => error.BadFd,
262259 system.ENOMEM => error.SystemResources,
263260 else => os.unexpectedErrorPosix(err),
264 }
261 };
265262 }
266263
267264 return usize(stat.size);
std/linked_list.zig+7-7
......@@ -5,7 +5,7 @@ const Allocator = mem.Allocator;
55
66/// Generic doubly linked list.
77pub fn LinkedList(comptime T: type) -> type {
8 struct {
8 return struct {
99 const Self = this;
1010
1111 /// Node inside the linked list wrapping the actual data.
......@@ -15,11 +15,11 @@ pub fn LinkedList(comptime T: type) -> type {
1515 data: T,
1616
1717 pub fn init(data: &const T) -> Node {
18 Node {
18 return Node {
1919 .prev = null,
2020 .next = null,
2121 .data = *data,
22 }
22 };
2323 }
2424 };
2525
......@@ -32,11 +32,11 @@ pub fn LinkedList(comptime T: type) -> type {
3232 /// Returns:
3333 /// An empty linked list.
3434 pub fn init() -> Self {
35 Self {
35 return Self {
3636 .first = null,
3737 .last = null,
3838 .len = 0,
39 }
39 };
4040 }
4141
4242 /// Insert a new node after an existing one.
......@@ -166,7 +166,7 @@ pub fn LinkedList(comptime T: type) -> type {
166166 /// Returns:
167167 /// A pointer to the new node.
168168 pub fn allocateNode(list: &Self, allocator: &Allocator) -> %&Node {
169 allocator.create(Node)
169 return allocator.create(Node);
170170 }
171171
172172 /// Deallocate a node.
......@@ -191,7 +191,7 @@ pub fn LinkedList(comptime T: type) -> type {
191191 *node = Node.init(data);
192192 return node;
193193 }
194 }
194 };
195195}
196196
197197test "basic linked list test" {
std/math/acos.zig+6-6
......@@ -7,11 +7,11 @@ const assert = @import("../debug.zig").assert;
77
88pub fn acos(x: var) -> @typeOf(x) {
99 const T = @typeOf(x);
10 switch (T) {
10 return switch (T) {
1111 f32 => @inlineCall(acos32, x),
1212 f64 => @inlineCall(acos64, x),
1313 else => @compileError("acos not implemented for " ++ @typeName(T)),
14 }
14 };
1515}
1616
1717fn r32(z: f32) -> f32 {
......@@ -22,7 +22,7 @@ fn r32(z: f32) -> f32 {
2222
2323 const p = z * (pS0 + z * (pS1 + z * pS2));
2424 const q = 1.0 + z * qS1;
25 p / q
25 return p / q;
2626}
2727
2828fn acos32(x: f32) -> f32 {
......@@ -69,7 +69,7 @@ fn acos32(x: f32) -> f32 {
6969 const df = @bitCast(f32, jx & 0xFFFFF000);
7070 const c = (z - df * df) / (s + df);
7171 const w = r32(z) * s + c;
72 2 * (df + w)
72 return 2 * (df + w);
7373}
7474
7575fn r64(z: f64) -> f64 {
......@@ -86,7 +86,7 @@ fn r64(z: f64) -> f64 {
8686
8787 const p = z * (pS0 + z * (pS1 + z * (pS2 + z * (pS3 + z * (pS4 + z * pS5)))));
8888 const q = 1.0 + z * (qS1 + z * (qS2 + z * (qS3 + z * qS4)));
89 p / q
89 return p / q;
9090}
9191
9292fn acos64(x: f64) -> f64 {
......@@ -138,7 +138,7 @@ fn acos64(x: f64) -> f64 {
138138 const df = @bitCast(f64, jx & 0xFFFFFFFF00000000);
139139 const c = (z - df * df) / (s + df);
140140 const w = r64(z) * s + c;
141 2 * (df + w)
141 return 2 * (df + w);
142142}
143143
144144test "math.acos" {
std/math/acosh.zig+8-8
......@@ -9,11 +9,11 @@ const assert = @import("../debug.zig").assert;
99
1010pub fn acosh(x: var) -> @typeOf(x) {
1111 const T = @typeOf(x);
12 switch (T) {
12 return switch (T) {
1313 f32 => @inlineCall(acosh32, x),
1414 f64 => @inlineCall(acosh64, x),
1515 else => @compileError("acosh not implemented for " ++ @typeName(T)),
16 }
16 };
1717}
1818
1919// acosh(x) = log(x + sqrt(x * x - 1))
......@@ -23,15 +23,15 @@ fn acosh32(x: f32) -> f32 {
2323
2424 // |x| < 2, invalid if x < 1 or nan
2525 if (i < 0x3F800000 + (1 << 23)) {
26 math.log1p(x - 1 + math.sqrt((x - 1) * (x - 1) + 2 * (x - 1)))
26 return math.log1p(x - 1 + math.sqrt((x - 1) * (x - 1) + 2 * (x - 1)));
2727 }
2828 // |x| < 0x1p12
2929 else if (i < 0x3F800000 + (12 << 23)) {
30 math.ln(2 * x - 1 / (x + math.sqrt(x * x - 1)))
30 return math.ln(2 * x - 1 / (x + math.sqrt(x * x - 1)));
3131 }
3232 // |x| >= 0x1p12
3333 else {
34 math.ln(x) + 0.693147180559945309417232121458176568
34 return math.ln(x) + 0.693147180559945309417232121458176568;
3535 }
3636}
3737
......@@ -41,15 +41,15 @@ fn acosh64(x: f64) -> f64 {
4141
4242 // |x| < 2, invalid if x < 1 or nan
4343 if (e < 0x3FF + 1) {
44 math.log1p(x - 1 + math.sqrt((x - 1) * (x - 1) + 2 * (x - 1)))
44 return math.log1p(x - 1 + math.sqrt((x - 1) * (x - 1) + 2 * (x - 1)));
4545 }
4646 // |x| < 0x1p26
4747 else if (e < 0x3FF + 26) {
48 math.ln(2 * x - 1 / (x + math.sqrt(x * x - 1)))
48 return math.ln(2 * x - 1 / (x + math.sqrt(x * x - 1)));
4949 }
5050 // |x| >= 0x1p26 or nan
5151 else {
52 math.ln(x) + 0.693147180559945309417232121458176568
52 return math.ln(x) + 0.693147180559945309417232121458176568;
5353 }
5454}
5555
std/math/asin.zig+9-9
......@@ -8,11 +8,11 @@ const assert = @import("../debug.zig").assert;
88
99pub fn asin(x: var) -> @typeOf(x) {
1010 const T = @typeOf(x);
11 switch (T) {
11 return switch (T) {
1212 f32 => @inlineCall(asin32, x),
1313 f64 => @inlineCall(asin64, x),
1414 else => @compileError("asin not implemented for " ++ @typeName(T)),
15 }
15 };
1616}
1717
1818fn r32(z: f32) -> f32 {
......@@ -23,7 +23,7 @@ fn r32(z: f32) -> f32 {
2323
2424 const p = z * (pS0 + z * (pS1 + z * pS2));
2525 const q = 1.0 + z * qS1;
26 p / q
26 return p / q;
2727}
2828
2929fn asin32(x: f32) -> f32 {
......@@ -58,9 +58,9 @@ fn asin32(x: f32) -> f32 {
5858 const fx = pio2 - 2 * (s + s * r32(z));
5959
6060 if (hx >> 31 != 0) {
61 -fx
61 return -fx;
6262 } else {
63 fx
63 return fx;
6464 }
6565}
6666
......@@ -78,7 +78,7 @@ fn r64(z: f64) -> f64 {
7878
7979 const p = z * (pS0 + z * (pS1 + z * (pS2 + z * (pS3 + z * (pS4 + z * pS5)))));
8080 const q = 1.0 + z * (qS1 + z * (qS2 + z * (qS3 + z * qS4)));
81 p / q
81 return p / q;
8282}
8383
8484fn asin64(x: f64) -> f64 {
......@@ -119,7 +119,7 @@ fn asin64(x: f64) -> f64 {
119119
120120 // |x| > 0.975
121121 if (ix >= 0x3FEF3333) {
122 fx = pio2_hi - 2 * (s + s * r)
122 fx = pio2_hi - 2 * (s + s * r);
123123 } else {
124124 const jx = @bitCast(u64, s);
125125 const df = @bitCast(f64, jx & 0xFFFFFFFF00000000);
......@@ -128,9 +128,9 @@ fn asin64(x: f64) -> f64 {
128128 }
129129
130130 if (hx >> 31 != 0) {
131 -fx
131 return -fx;
132132 } else {
133 fx
133 return fx;
134134 }
135135}
136136
std/math/asinh.zig+4-4
......@@ -9,11 +9,11 @@ const assert = @import("../debug.zig").assert;
99
1010pub fn asinh(x: var) -> @typeOf(x) {
1111 const T = @typeOf(x);
12 switch (T) {
12 return switch (T) {
1313 f32 => @inlineCall(asinh32, x),
1414 f64 => @inlineCall(asinh64, x),
1515 else => @compileError("asinh not implemented for " ++ @typeName(T)),
16 }
16 };
1717}
1818
1919// asinh(x) = sign(x) * log(|x| + sqrt(x * x + 1)) ~= x - x^3/6 + o(x^5)
......@@ -46,7 +46,7 @@ fn asinh32(x: f32) -> f32 {
4646 math.forceEval(x + 0x1.0p120);
4747 }
4848
49 if (s != 0) -rx else rx
49 return if (s != 0) -rx else rx;
5050}
5151
5252fn asinh64(x: f64) -> f64 {
......@@ -77,7 +77,7 @@ fn asinh64(x: f64) -> f64 {
7777 math.forceEval(x + 0x1.0p120);
7878 }
7979
80 if (s != 0) -rx else rx
80 return if (s != 0) -rx else rx;
8181}
8282
8383test "math.asinh" {
std/math/atan.zig+6-6
......@@ -8,11 +8,11 @@ const assert = @import("../debug.zig").assert;
88
99pub fn atan(x: var) -> @typeOf(x) {
1010 const T = @typeOf(x);
11 switch (T) {
11 return switch (T) {
1212 f32 => @inlineCall(atan32, x),
1313 f64 => @inlineCall(atan64, x),
1414 else => @compileError("atan not implemented for " ++ @typeName(T)),
15 }
15 };
1616}
1717
1818fn atan32(x_: f32) -> f32 {
......@@ -100,10 +100,10 @@ fn atan32(x_: f32) -> f32 {
100100 const s2 = w * (aT[1] + w * aT[3]);
101101
102102 if (id == null) {
103 x - x * (s1 + s2)
103 return x - x * (s1 + s2);
104104 } else {
105105 const zz = atanhi[??id] - ((x * (s1 + s2) - atanlo[??id]) - x);
106 if (sign != 0) -zz else zz
106 return if (sign != 0) -zz else zz;
107107 }
108108}
109109
......@@ -199,10 +199,10 @@ fn atan64(x_: f64) -> f64 {
199199 const s2 = w * (aT[1] + w * (aT[3] + w * (aT[5] + w * (aT[7] + w * aT[9]))));
200200
201201 if (id == null) {
202 x - x * (s1 + s2)
202 return x - x * (s1 + s2);
203203 } else {
204204 const zz = atanhi[??id] - ((x * (s1 + s2) - atanlo[??id]) - x);
205 if (sign != 0) -zz else zz
205 return if (sign != 0) -zz else zz;
206206 }
207207}
208208
std/math/atan2.zig+8-8
......@@ -22,11 +22,11 @@ const math = @import("index.zig");
2222const assert = @import("../debug.zig").assert;
2323
2424fn atan2(comptime T: type, x: T, y: T) -> T {
25 switch (T) {
25 return switch (T) {
2626 f32 => @inlineCall(atan2_32, x, y),
2727 f64 => @inlineCall(atan2_64, x, y),
2828 else => @compileError("atan2 not implemented for " ++ @typeName(T)),
29 }
29 };
3030}
3131
3232fn atan2_32(y: f32, x: f32) -> f32 {
......@@ -97,11 +97,11 @@ fn atan2_32(y: f32, x: f32) -> f32 {
9797 }
9898
9999 // z = atan(|y / x|) with correct underflow
100 var z = {
100 var z = z: {
101101 if ((m & 2) != 0 and iy + (26 << 23) < ix) {
102 0.0
102 break :z 0.0;
103103 } else {
104 math.atan(math.fabs(y / x))
104 break :z math.atan(math.fabs(y / x));
105105 }
106106 };
107107
......@@ -187,11 +187,11 @@ fn atan2_64(y: f64, x: f64) -> f64 {
187187 }
188188
189189 // z = atan(|y / x|) with correct underflow
190 var z = {
190 var z = z: {
191191 if ((m & 2) != 0 and iy +% (64 << 20) < ix) {
192 0.0
192 break :z 0.0;
193193 } else {
194 math.atan(math.fabs(y / x))
194 break :z math.atan(math.fabs(y / x));
195195 }
196196 };
197197
std/math/atanh.zig+5-5
......@@ -9,11 +9,11 @@ const assert = @import("../debug.zig").assert;
99
1010pub fn atanh(x: var) -> @typeOf(x) {
1111 const T = @typeOf(x);
12 switch (T) {
12 return switch (T) {
1313 f32 => @inlineCall(atanh_32, x),
1414 f64 => @inlineCall(atanh_64, x),
1515 else => @compileError("atanh not implemented for " ++ @typeName(T)),
16 }
16 };
1717}
1818
1919// atanh(x) = log((1 + x) / (1 - x)) / 2 = log1p(2x / (1 - x)) / 2 ~= x + x^3 / 3 + o(x^5)
......@@ -32,7 +32,7 @@ fn atanh_32(x: f32) -> f32 {
3232 if (u < 0x3F800000 - (32 << 23)) {
3333 // underflow
3434 if (u < (1 << 23)) {
35 math.forceEval(y * y)
35 math.forceEval(y * y);
3636 }
3737 }
3838 // |x| < 0.5
......@@ -43,7 +43,7 @@ fn atanh_32(x: f32) -> f32 {
4343 y = 0.5 * math.log1p(2 * (y / (1 - y)));
4444 }
4545
46 if (s != 0) -y else y
46 return if (s != 0) -y else y;
4747}
4848
4949fn atanh_64(x: f64) -> f64 {
......@@ -72,7 +72,7 @@ fn atanh_64(x: f64) -> f64 {
7272 y = 0.5 * math.log1p(2 * (y / (1 - y)));
7373 }
7474
75 if (s != 0) -y else y
75 return if (s != 0) -y else y;
7676}
7777
7878test "math.atanh" {
std/math/cbrt.zig+4-4
......@@ -9,11 +9,11 @@ const assert = @import("../debug.zig").assert;
99
1010pub fn cbrt(x: var) -> @typeOf(x) {
1111 const T = @typeOf(x);
12 switch (T) {
12 return switch (T) {
1313 f32 => @inlineCall(cbrt32, x),
1414 f64 => @inlineCall(cbrt64, x),
1515 else => @compileError("cbrt not implemented for " ++ @typeName(T)),
16 }
16 };
1717}
1818
1919fn cbrt32(x: f32) -> f32 {
......@@ -53,7 +53,7 @@ fn cbrt32(x: f32) -> f32 {
5353 r = t * t * t;
5454 t = t * (f64(x) + x + r) / (x + r + r);
5555
56 f32(t)
56 return f32(t);
5757}
5858
5959fn cbrt64(x: f64) -> f64 {
......@@ -109,7 +109,7 @@ fn cbrt64(x: f64) -> f64 {
109109 var w = t + t;
110110 q = (q - t) / (w + q);
111111
112 t + t * q
112 return t + t * q;
113113}
114114
115115test "math.cbrt" {
std/math/ceil.zig+8-8
......@@ -10,11 +10,11 @@ const assert = @import("../debug.zig").assert;
1010
1111pub fn ceil(x: var) -> @typeOf(x) {
1212 const T = @typeOf(x);
13 switch (T) {
13 return switch (T) {
1414 f32 => @inlineCall(ceil32, x),
1515 f64 => @inlineCall(ceil64, x),
1616 else => @compileError("ceil not implemented for " ++ @typeName(T)),
17 }
17 };
1818}
1919
2020fn ceil32(x: f32) -> f32 {
......@@ -39,13 +39,13 @@ fn ceil32(x: f32) -> f32 {
3939 u += m;
4040 }
4141 u &= ~m;
42 @bitCast(f32, u)
42 return @bitCast(f32, u);
4343 } else {
4444 math.forceEval(x + 0x1.0p120);
4545 if (u >> 31 != 0) {
4646 return -0.0;
4747 } else {
48 1.0
48 return 1.0;
4949 }
5050 }
5151}
......@@ -70,14 +70,14 @@ fn ceil64(x: f64) -> f64 {
7070 if (e <= 0x3FF-1) {
7171 math.forceEval(y);
7272 if (u >> 63 != 0) {
73 return -0.0; // Compiler requires return.
73 return -0.0;
7474 } else {
75 1.0
75 return 1.0;
7676 }
7777 } else if (y < 0) {
78 x + y + 1
78 return x + y + 1;
7979 } else {
80 x + y
80 return x + y;
8181 }
8282}
8383
std/math/copysign.zig+4-4
......@@ -2,11 +2,11 @@ const math = @import("index.zig");
22const assert = @import("../debug.zig").assert;
33
44pub fn copysign(comptime T: type, x: T, y: T) -> T {
5 switch (T) {
5 return switch (T) {
66 f32 => @inlineCall(copysign32, x, y),
77 f64 => @inlineCall(copysign64, x, y),
88 else => @compileError("copysign not implemented for " ++ @typeName(T)),
9 }
9 };
1010}
1111
1212fn copysign32(x: f32, y: f32) -> f32 {
......@@ -15,7 +15,7 @@ fn copysign32(x: f32, y: f32) -> f32 {
1515
1616 const h1 = ux & (@maxValue(u32) / 2);
1717 const h2 = uy & (u32(1) << 31);
18 @bitCast(f32, h1 | h2)
18 return @bitCast(f32, h1 | h2);
1919}
2020
2121fn copysign64(x: f64, y: f64) -> f64 {
......@@ -24,7 +24,7 @@ fn copysign64(x: f64, y: f64) -> f64 {
2424
2525 const h1 = ux & (@maxValue(u64) / 2);
2626 const h2 = uy & (u64(1) << 63);
27 @bitCast(f64, h1 | h2)
27 return @bitCast(f64, h1 | h2);
2828}
2929
3030test "math.copysign" {
std/math/cos.zig+12-12
......@@ -9,11 +9,11 @@ const assert = @import("../debug.zig").assert;
99
1010pub fn cos(x: var) -> @typeOf(x) {
1111 const T = @typeOf(x);
12 switch (T) {
12 return switch (T) {
1313 f32 => @inlineCall(cos32, x),
1414 f64 => @inlineCall(cos64, x),
1515 else => @compileError("cos not implemented for " ++ @typeName(T)),
16 }
16 };
1717}
1818
1919// sin polynomial coefficients
......@@ -73,18 +73,18 @@ fn cos32(x_: f32) -> f32 {
7373 const z = ((x - y * pi4a) - y * pi4b) - y * pi4c;
7474 const w = z * z;
7575
76 const r = {
76 const r = r: {
7777 if (j == 1 or j == 2) {
78 z + z * w * (S5 + w * (S4 + w * (S3 + w * (S2 + w * (S1 + w * S0)))))
78 break :r z + z * w * (S5 + w * (S4 + w * (S3 + w * (S2 + w * (S1 + w * S0)))));
7979 } else {
80 1.0 - 0.5 * w + w * w * (C5 + w * (C4 + w * (C3 + w * (C2 + w * (C1 + w * C0)))))
80 break :r 1.0 - 0.5 * w + w * w * (C5 + w * (C4 + w * (C3 + w * (C2 + w * (C1 + w * C0)))));
8181 }
8282 };
8383
8484 if (sign) {
85 -r
85 return -r;
8686 } else {
87 r
87 return r;
8888 }
8989}
9090
......@@ -124,18 +124,18 @@ fn cos64(x_: f64) -> f64 {
124124 const z = ((x - y * pi4a) - y * pi4b) - y * pi4c;
125125 const w = z * z;
126126
127 const r = {
127 const r = r: {
128128 if (j == 1 or j == 2) {
129 z + z * w * (S5 + w * (S4 + w * (S3 + w * (S2 + w * (S1 + w * S0)))))
129 break :r z + z * w * (S5 + w * (S4 + w * (S3 + w * (S2 + w * (S1 + w * S0)))));
130130 } else {
131 1.0 - 0.5 * w + w * w * (C5 + w * (C4 + w * (C3 + w * (C2 + w * (C1 + w * C0)))))
131 break :r 1.0 - 0.5 * w + w * w * (C5 + w * (C4 + w * (C3 + w * (C2 + w * (C1 + w * C0)))));
132132 }
133133 };
134134
135135 if (sign) {
136 -r
136 return -r;
137137 } else {
138 r
138 return r;
139139 }
140140}
141141
std/math/cosh.zig+4-4
......@@ -11,11 +11,11 @@ const assert = @import("../debug.zig").assert;
1111
1212pub fn cosh(x: var) -> @typeOf(x) {
1313 const T = @typeOf(x);
14 switch (T) {
14 return switch (T) {
1515 f32 => @inlineCall(cosh32, x),
1616 f64 => @inlineCall(cosh64, x),
1717 else => @compileError("cosh not implemented for " ++ @typeName(T)),
18 }
18 };
1919}
2020
2121// cosh(x) = (exp(x) + 1 / exp(x)) / 2
......@@ -43,7 +43,7 @@ fn cosh32(x: f32) -> f32 {
4343 }
4444
4545 // |x| > log(FLT_MAX) or nan
46 expo2(ax)
46 return expo2(ax);
4747}
4848
4949fn cosh64(x: f64) -> f64 {
......@@ -76,7 +76,7 @@ fn cosh64(x: f64) -> f64 {
7676 }
7777
7878 // |x| > log(CBL_MAX) or nan
79 expo2(ax)
79 return expo2(ax);
8080}
8181
8282test "math.cosh" {
std/math/exp.zig+6-6
......@@ -8,11 +8,11 @@ const assert = @import("../debug.zig").assert;
88
99pub fn exp(x: var) -> @typeOf(x) {
1010 const T = @typeOf(x);
11 switch (T) {
11 return switch (T) {
1212 f32 => @inlineCall(exp32, x),
1313 f64 => @inlineCall(exp64, x),
1414 else => @compileError("exp not implemented for " ++ @typeName(T)),
15 }
15 };
1616}
1717
1818fn exp32(x_: f32) -> f32 {
......@@ -86,9 +86,9 @@ fn exp32(x_: f32) -> f32 {
8686 const y = 1 + (x * c / (2 - c) - lo + hi);
8787
8888 if (k == 0) {
89 y
89 return y;
9090 } else {
91 math.scalbn(y, k)
91 return math.scalbn(y, k);
9292 }
9393}
9494
......@@ -172,9 +172,9 @@ fn exp64(x_: f64) -> f64 {
172172 const y = 1 + (x * c / (2 - c) - lo + hi);
173173
174174 if (k == 0) {
175 y
175 return y;
176176 } else {
177 math.scalbn(y, k)
177 return math.scalbn(y, k);
178178 }
179179}
180180
std/math/exp2.zig+4-4
......@@ -8,11 +8,11 @@ const assert = @import("../debug.zig").assert;
88
99pub fn exp2(x: var) -> @typeOf(x) {
1010 const T = @typeOf(x);
11 switch (T) {
11 return switch (T) {
1212 f32 => @inlineCall(exp2_32, x),
1313 f64 => @inlineCall(exp2_64, x),
1414 else => @compileError("exp2 not implemented for " ++ @typeName(T)),
15 }
15 };
1616}
1717
1818const exp2ft = []const f64 {
......@@ -88,7 +88,7 @@ fn exp2_32(x: f32) -> f32 {
8888 var r: f64 = exp2ft[i0];
8989 const t: f64 = r * z;
9090 r = r + t * (P1 + z * P2) + t * (z * z) * (P3 + z * P4);
91 f32(r * uk)
91 return f32(r * uk);
9292}
9393
9494const exp2dt = []f64 {
......@@ -414,7 +414,7 @@ fn exp2_64(x: f64) -> f64 {
414414 z -= exp2dt[2 * i0 + 1];
415415 const r = t + t * z * (P1 + z * (P2 + z * (P3 + z * (P4 + z * P5))));
416416
417 math.scalbn(r, ik)
417 return math.scalbn(r, ik);
418418}
419419
420420test "math.exp2" {
std/math/expm1.zig+2-2
......@@ -9,11 +9,11 @@ const assert = @import("../debug.zig").assert;
99
1010pub fn expm1(x: var) -> @typeOf(x) {
1111 const T = @typeOf(x);
12 switch (T) {
12 return switch (T) {
1313 f32 => @inlineCall(expm1_32, x),
1414 f64 => @inlineCall(expm1_64, x),
1515 else => @compileError("exp1m not implemented for " ++ @typeName(T)),
16 }
16 };
1717}
1818
1919fn expm1_32(x_: f32) -> f32 {
std/math/expo2.zig+4-4
......@@ -2,11 +2,11 @@ const math = @import("index.zig");
22
33pub fn expo2(x: var) -> @typeOf(x) {
44 const T = @typeOf(x);
5 switch (T) {
5 return switch (T) {
66 f32 => expo2f(x),
77 f64 => expo2d(x),
88 else => @compileError("expo2 not implemented for " ++ @typeName(T)),
9 }
9 };
1010}
1111
1212fn expo2f(x: f32) -> f32 {
......@@ -15,7 +15,7 @@ fn expo2f(x: f32) -> f32 {
1515
1616 const u = (0x7F + k / 2) << 23;
1717 const scale = @bitCast(f32, u);
18 math.exp(x - kln2) * scale * scale
18 return math.exp(x - kln2) * scale * scale;
1919}
2020
2121fn expo2d(x: f64) -> f64 {
......@@ -24,5 +24,5 @@ fn expo2d(x: f64) -> f64 {
2424
2525 const u = (0x3FF + k / 2) << 20;
2626 const scale = @bitCast(f64, u64(u) << 32);
27 math.exp(x - kln2) * scale * scale
27 return math.exp(x - kln2) * scale * scale;
2828}
std/math/fabs.zig+4-4
......@@ -8,23 +8,23 @@ const assert = @import("../debug.zig").assert;
88
99pub fn fabs(x: var) -> @typeOf(x) {
1010 const T = @typeOf(x);
11 switch (T) {
11 return switch (T) {
1212 f32 => @inlineCall(fabs32, x),
1313 f64 => @inlineCall(fabs64, x),
1414 else => @compileError("fabs not implemented for " ++ @typeName(T)),
15 }
15 };
1616}
1717
1818fn fabs32(x: f32) -> f32 {
1919 var u = @bitCast(u32, x);
2020 u &= 0x7FFFFFFF;
21 @bitCast(f32, u)
21 return @bitCast(f32, u);
2222}
2323
2424fn fabs64(x: f64) -> f64 {
2525 var u = @bitCast(u64, x);
2626 u &= @maxValue(u64) >> 1;
27 @bitCast(f64, u)
27 return @bitCast(f64, u);
2828}
2929
3030test "math.fabs" {
std/math/floor.zig+9-9
......@@ -10,11 +10,11 @@ const math = @import("index.zig");
1010
1111pub fn floor(x: var) -> @typeOf(x) {
1212 const T = @typeOf(x);
13 switch (T) {
13 return switch (T) {
1414 f32 => @inlineCall(floor32, x),
1515 f64 => @inlineCall(floor64, x),
1616 else => @compileError("floor not implemented for " ++ @typeName(T)),
17 }
17 };
1818}
1919
2020fn floor32(x: f32) -> f32 {
......@@ -40,13 +40,13 @@ fn floor32(x: f32) -> f32 {
4040 if (u >> 31 != 0) {
4141 u += m;
4242 }
43 @bitCast(f32, u & ~m)
43 return @bitCast(f32, u & ~m);
4444 } else {
4545 math.forceEval(x + 0x1.0p120);
4646 if (u >> 31 == 0) {
47 return 0.0; // Compiler requires return
47 return 0.0;
4848 } else {
49 -1.0
49 return -1.0;
5050 }
5151 }
5252}
......@@ -71,14 +71,14 @@ fn floor64(x: f64) -> f64 {
7171 if (e <= 0x3FF-1) {
7272 math.forceEval(y);
7373 if (u >> 63 != 0) {
74 return -1.0; // Compiler requires return.
74 return -1.0;
7575 } else {
76 0.0
76 return 0.0;
7777 }
7878 } else if (y > 0) {
79 x + y - 1
79 return x + y - 1;
8080 } else {
81 x + y
81 return x + y;
8282 }
8383}
8484
std/math/fma.zig+10-10
......@@ -2,11 +2,11 @@ const math = @import("index.zig");
22const assert = @import("../debug.zig").assert;
33
44pub fn fma(comptime T: type, x: T, y: T, z: T) -> T {
5 switch (T) {
5 return switch (T) {
66 f32 => @inlineCall(fma32, x, y, z),
77 f64 => @inlineCall(fma64, x, y ,z),
88 else => @compileError("fma not implemented for " ++ @typeName(T)),
9 }
9 };
1010}
1111
1212fn fma32(x: f32, y: f32, z: f32) -> f32 {
......@@ -16,10 +16,10 @@ fn fma32(x: f32, y: f32, z: f32) -> f32 {
1616 const e = (u >> 52) & 0x7FF;
1717
1818 if ((u & 0x1FFFFFFF) != 0x10000000 or e == 0x7FF or xy_z - xy == z) {
19 f32(xy_z)
19 return f32(xy_z);
2020 } else {
2121 // TODO: Handle inexact case with double-rounding
22 f32(xy_z)
22 return f32(xy_z);
2323 }
2424}
2525
......@@ -64,9 +64,9 @@ fn fma64(x: f64, y: f64, z: f64) -> f64 {
6464
6565 const adj = add_adjusted(r.lo, xy.lo);
6666 if (spread + math.ilogb(r.hi) > -1023) {
67 math.scalbn(r.hi + adj, spread)
67 return math.scalbn(r.hi + adj, spread);
6868 } else {
69 add_and_denorm(r.hi, adj, spread)
69 return add_and_denorm(r.hi, adj, spread);
7070 }
7171}
7272
......@@ -77,7 +77,7 @@ fn dd_add(a: f64, b: f64) -> dd {
7777 ret.hi = a + b;
7878 const s = ret.hi - a;
7979 ret.lo = (a - (ret.hi - s)) + (b - s);
80 ret
80 return ret;
8181}
8282
8383fn dd_mul(a: f64, b: f64) -> dd {
......@@ -99,7 +99,7 @@ fn dd_mul(a: f64, b: f64) -> dd {
9999
100100 ret.hi = p + q;
101101 ret.lo = p - ret.hi + q + la * lb;
102 ret
102 return ret;
103103}
104104
105105fn add_adjusted(a: f64, b: f64) -> f64 {
......@@ -113,7 +113,7 @@ fn add_adjusted(a: f64, b: f64) -> f64 {
113113 sum.hi = @bitCast(f64, uhii);
114114 }
115115 }
116 sum.hi
116 return sum.hi;
117117}
118118
119119fn add_and_denorm(a: f64, b: f64, scale: i32) -> f64 {
......@@ -127,7 +127,7 @@ fn add_and_denorm(a: f64, b: f64, scale: i32) -> f64 {
127127 sum.hi = @bitCast(f64, uhii);
128128 }
129129 }
130 math.scalbn(sum.hi, scale)
130 return math.scalbn(sum.hi, scale);
131131}
132132
133133test "math.fma" {
std/math/frexp.zig+6-6
......@@ -8,21 +8,21 @@ const math = @import("index.zig");
88const assert = @import("../debug.zig").assert;
99
1010fn frexp_result(comptime T: type) -> type {
11 struct {
11 return struct {
1212 significand: T,
1313 exponent: i32,
14 }
14 };
1515}
1616pub const frexp32_result = frexp_result(f32);
1717pub const frexp64_result = frexp_result(f64);
1818
1919pub fn frexp(x: var) -> frexp_result(@typeOf(x)) {
2020 const T = @typeOf(x);
21 switch (T) {
21 return switch (T) {
2222 f32 => @inlineCall(frexp32, x),
2323 f64 => @inlineCall(frexp64, x),
2424 else => @compileError("frexp not implemented for " ++ @typeName(T)),
25 }
25 };
2626}
2727
2828fn frexp32(x: f32) -> frexp32_result {
......@@ -59,7 +59,7 @@ fn frexp32(x: f32) -> frexp32_result {
5959 y &= 0x807FFFFF;
6060 y |= 0x3F000000;
6161 result.significand = @bitCast(f32, y);
62 result
62 return result;
6363}
6464
6565fn frexp64(x: f64) -> frexp64_result {
......@@ -96,7 +96,7 @@ fn frexp64(x: f64) -> frexp64_result {
9696 y &= 0x800FFFFFFFFFFFFF;
9797 y |= 0x3FE0000000000000;
9898 result.significand = @bitCast(f64, y);
99 result
99 return result;
100100}
101101
102102test "math.frexp" {
std/math/hypot.zig+4-4
......@@ -9,11 +9,11 @@ const math = @import("index.zig");
99const assert = @import("../debug.zig").assert;
1010
1111pub fn hypot(comptime T: type, x: T, y: T) -> T {
12 switch (T) {
12 return switch (T) {
1313 f32 => @inlineCall(hypot32, x, y),
1414 f64 => @inlineCall(hypot64, x, y),
1515 else => @compileError("hypot not implemented for " ++ @typeName(T)),
16 }
16 };
1717}
1818
1919fn hypot32(x: f32, y: f32) -> f32 {
......@@ -48,7 +48,7 @@ fn hypot32(x: f32, y: f32) -> f32 {
4848 yy *= 0x1.0p-90;
4949 }
5050
51 z * math.sqrt(f32(f64(x) * x + f64(y) * y))
51 return z * math.sqrt(f32(f64(x) * x + f64(y) * y));
5252}
5353
5454fn sq(hi: &f64, lo: &f64, x: f64) {
......@@ -109,7 +109,7 @@ fn hypot64(x: f64, y: f64) -> f64 {
109109 sq(&hx, &lx, x);
110110 sq(&hy, &ly, y);
111111
112 z * math.sqrt(ly + lx + hy + hx)
112 return z * math.sqrt(ly + lx + hy + hx);
113113}
114114
115115test "math.hypot" {
std/math/ilogb.zig+4-4
......@@ -9,11 +9,11 @@ const assert = @import("../debug.zig").assert;
99
1010pub fn ilogb(x: var) -> i32 {
1111 const T = @typeOf(x);
12 switch (T) {
12 return switch (T) {
1313 f32 => @inlineCall(ilogb32, x),
1414 f64 => @inlineCall(ilogb64, x),
1515 else => @compileError("ilogb not implemented for " ++ @typeName(T)),
16 }
16 };
1717}
1818
1919// NOTE: Should these be exposed publically?
......@@ -53,7 +53,7 @@ fn ilogb32(x: f32) -> i32 {
5353 }
5454 }
5555
56 e - 0x7F
56 return e - 0x7F;
5757}
5858
5959fn ilogb64(x: f64) -> i32 {
......@@ -88,7 +88,7 @@ fn ilogb64(x: f64) -> i32 {
8888 }
8989 }
9090
91 e - 0x3FF
91 return e - 0x3FF;
9292}
9393
9494test "math.ilogb" {
std/math/index.zig+8-8
......@@ -36,7 +36,7 @@ pub const inf = @import("inf.zig").inf;
3636
3737pub fn approxEq(comptime T: type, x: T, y: T, epsilon: T) -> bool {
3838 assert(@typeId(T) == TypeId.Float);
39 fabs(x - y) < epsilon
39 return fabs(x - y) < epsilon;
4040}
4141
4242// TODO: Hide the following in an internal module.
......@@ -175,7 +175,7 @@ test "math" {
175175
176176
177177pub fn min(x: var, y: var) -> @typeOf(x + y) {
178 if (x < y) x else y
178 return if (x < y) x else y;
179179}
180180
181181test "math.min" {
......@@ -183,7 +183,7 @@ test "math.min" {
183183}
184184
185185pub fn max(x: var, y: var) -> @typeOf(x + y) {
186 if (x > y) x else y
186 return if (x > y) x else y;
187187}
188188
189189test "math.max" {
......@@ -193,19 +193,19 @@ test "math.max" {
193193error Overflow;
194194pub fn mul(comptime T: type, a: T, b: T) -> %T {
195195 var answer: T = undefined;
196 if (@mulWithOverflow(T, a, b, &answer)) error.Overflow else answer
196 return if (@mulWithOverflow(T, a, b, &answer)) error.Overflow else answer;
197197}
198198
199199error Overflow;
200200pub fn add(comptime T: type, a: T, b: T) -> %T {
201201 var answer: T = undefined;
202 if (@addWithOverflow(T, a, b, &answer)) error.Overflow else answer
202 return if (@addWithOverflow(T, a, b, &answer)) error.Overflow else answer;
203203}
204204
205205error Overflow;
206206pub fn sub(comptime T: type, a: T, b: T) -> %T {
207207 var answer: T = undefined;
208 if (@subWithOverflow(T, a, b, &answer)) error.Overflow else answer
208 return if (@subWithOverflow(T, a, b, &answer)) error.Overflow else answer;
209209}
210210
211211pub fn negate(x: var) -> %@typeOf(x) {
......@@ -215,7 +215,7 @@ pub fn negate(x: var) -> %@typeOf(x) {
215215error Overflow;
216216pub fn shlExact(comptime T: type, a: T, shift_amt: Log2Int(T)) -> %T {
217217 var answer: T = undefined;
218 if (@shlWithOverflow(T, a, shift_amt, &answer)) error.Overflow else answer
218 return if (@shlWithOverflow(T, a, shift_amt, &answer)) error.Overflow else answer;
219219}
220220
221221/// Shifts left. Overflowed bits are truncated.
......@@ -267,7 +267,7 @@ test "math.shr" {
267267}
268268
269269pub fn Log2Int(comptime T: type) -> type {
270 @IntType(false, log2(T.bit_count))
270 return @IntType(false, log2(T.bit_count));
271271}
272272
273273test "math overflow functions" {
std/math/inf.zig+2-2
......@@ -2,9 +2,9 @@ const math = @import("index.zig");
22const assert = @import("../debug.zig").assert;
33
44pub fn inf(comptime T: type) -> T {
5 switch (T) {
5 return switch (T) {
66 f32 => @bitCast(f32, math.inf_u32),
77 f64 => @bitCast(f64, math.inf_u64),
88 else => @compileError("inf not implemented for " ++ @typeName(T)),
9 }
9 };
1010}
std/math/isfinite.zig+2-2
......@@ -6,11 +6,11 @@ pub fn isFinite(x: var) -> bool {
66 switch (T) {
77 f32 => {
88 const bits = @bitCast(u32, x);
9 bits & 0x7FFFFFFF < 0x7F800000
9 return bits & 0x7FFFFFFF < 0x7F800000;
1010 },
1111 f64 => {
1212 const bits = @bitCast(u64, x);
13 bits & (@maxValue(u64) >> 1) < (0x7FF << 52)
13 return bits & (@maxValue(u64) >> 1) < (0x7FF << 52);
1414 },
1515 else => {
1616 @compileError("isFinite not implemented for " ++ @typeName(T));
std/math/isinf.zig+6-6
......@@ -6,11 +6,11 @@ pub fn isInf(x: var) -> bool {
66 switch (T) {
77 f32 => {
88 const bits = @bitCast(u32, x);
9 bits & 0x7FFFFFFF == 0x7F800000
9 return bits & 0x7FFFFFFF == 0x7F800000;
1010 },
1111 f64 => {
1212 const bits = @bitCast(u64, x);
13 bits & (@maxValue(u64) >> 1) == (0x7FF << 52)
13 return bits & (@maxValue(u64) >> 1) == (0x7FF << 52);
1414 },
1515 else => {
1616 @compileError("isInf not implemented for " ++ @typeName(T));
......@@ -22,10 +22,10 @@ pub fn isPositiveInf(x: var) -> bool {
2222 const T = @typeOf(x);
2323 switch (T) {
2424 f32 => {
25 @bitCast(u32, x) == 0x7F800000
25 return @bitCast(u32, x) == 0x7F800000;
2626 },
2727 f64 => {
28 @bitCast(u64, x) == 0x7FF << 52
28 return @bitCast(u64, x) == 0x7FF << 52;
2929 },
3030 else => {
3131 @compileError("isPositiveInf not implemented for " ++ @typeName(T));
......@@ -37,10 +37,10 @@ pub fn isNegativeInf(x: var) -> bool {
3737 const T = @typeOf(x);
3838 switch (T) {
3939 f32 => {
40 @bitCast(u32, x) == 0xFF800000
40 return @bitCast(u32, x) == 0xFF800000;
4141 },
4242 f64 => {
43 @bitCast(u64, x) == 0xFFF << 52
43 return @bitCast(u64, x) == 0xFFF << 52;
4444 },
4545 else => {
4646 @compileError("isNegativeInf not implemented for " ++ @typeName(T));
std/math/isnan.zig+3-3
......@@ -6,11 +6,11 @@ pub fn isNan(x: var) -> bool {
66 switch (T) {
77 f32 => {
88 const bits = @bitCast(u32, x);
9 bits & 0x7FFFFFFF > 0x7F800000
9 return bits & 0x7FFFFFFF > 0x7F800000;
1010 },
1111 f64 => {
1212 const bits = @bitCast(u64, x);
13 (bits & (@maxValue(u64) >> 1)) > (u64(0x7FF) << 52)
13 return (bits & (@maxValue(u64) >> 1)) > (u64(0x7FF) << 52);
1414 },
1515 else => {
1616 @compileError("isNan not implemented for " ++ @typeName(T));
......@@ -21,7 +21,7 @@ pub fn isNan(x: var) -> bool {
2121// Note: A signalling nan is identical to a standard right now by may have a different bit
2222// representation in the future when required.
2323pub fn isSignalNan(x: var) -> bool {
24 isNan(x)
24 return isNan(x);
2525}
2626
2727test "math.isNan" {
std/math/isnormal.zig+2-2
......@@ -6,11 +6,11 @@ pub fn isNormal(x: var) -> bool {
66 switch (T) {
77 f32 => {
88 const bits = @bitCast(u32, x);
9 (bits + 0x00800000) & 0x7FFFFFFF >= 0x01000000
9 return (bits + 0x00800000) & 0x7FFFFFFF >= 0x01000000;
1010 },
1111 f64 => {
1212 const bits = @bitCast(u64, x);
13 (bits + (1 << 52)) & (@maxValue(u64) >> 1) >= (1 << 53)
13 return (bits + (1 << 52)) & (@maxValue(u64) >> 1) >= (1 << 53);
1414 },
1515 else => {
1616 @compileError("isNormal not implemented for " ++ @typeName(T));
std/math/ln.zig+4-4
......@@ -14,7 +14,7 @@ pub fn ln(x: var) -> @typeOf(x) {
1414 const T = @typeOf(x);
1515 switch (@typeId(T)) {
1616 TypeId.FloatLiteral => {
17 return @typeOf(1.0)(ln_64(x))
17 return @typeOf(1.0)(ln_64(x));
1818 },
1919 TypeId.Float => {
2020 return switch (T) {
......@@ -84,7 +84,7 @@ pub fn ln_32(x_: f32) -> f32 {
8484 const hfsq = 0.5 * f * f;
8585 const dk = f32(k);
8686
87 s * (hfsq + R) + dk * ln2_lo - hfsq + f + dk * ln2_hi
87 return s * (hfsq + R) + dk * ln2_lo - hfsq + f + dk * ln2_hi;
8888}
8989
9090pub fn ln_64(x_: f64) -> f64 {
......@@ -116,7 +116,7 @@ pub fn ln_64(x_: f64) -> f64 {
116116 // subnormal, scale x
117117 k -= 54;
118118 x *= 0x1.0p54;
119 hx = u32(@bitCast(u64, ix) >> 32)
119 hx = u32(@bitCast(u64, ix) >> 32);
120120 }
121121 else if (hx >= 0x7FF00000) {
122122 return x;
......@@ -142,7 +142,7 @@ pub fn ln_64(x_: f64) -> f64 {
142142 const R = t2 + t1;
143143 const dk = f64(k);
144144
145 s * (hfsq + R) + dk * ln2_lo - hfsq + f + dk * ln2_hi
145 return s * (hfsq + R) + dk * ln2_lo - hfsq + f + dk * ln2_hi;
146146}
147147
148148test "math.ln" {
std/math/log.zig+1-1
......@@ -29,7 +29,7 @@ pub fn log(comptime T: type, base: T, x: T) -> T {
2929 f32 => return f32(math.ln(f64(x)) / math.ln(f64(base))),
3030 f64 => return math.ln(x) / math.ln(f64(base)),
3131 else => @compileError("log not implemented for " ++ @typeName(T)),
32 };
32 }
3333 },
3434
3535 else => {
std/math/log10.zig+4-4
......@@ -14,7 +14,7 @@ pub fn log10(x: var) -> @typeOf(x) {
1414 const T = @typeOf(x);
1515 switch (@typeId(T)) {
1616 TypeId.FloatLiteral => {
17 return @typeOf(1.0)(log10_64(x))
17 return @typeOf(1.0)(log10_64(x));
1818 },
1919 TypeId.Float => {
2020 return switch (T) {
......@@ -90,7 +90,7 @@ pub fn log10_32(x_: f32) -> f32 {
9090 const lo = f - hi - hfsq + s * (hfsq + R);
9191 const dk = f32(k);
9292
93 dk * log10_2lo + (lo + hi) * ivln10lo + lo * ivln10hi + hi * ivln10hi + dk * log10_2hi
93 return dk * log10_2lo + (lo + hi) * ivln10lo + lo * ivln10hi + hi * ivln10hi + dk * log10_2hi;
9494}
9595
9696pub fn log10_64(x_: f64) -> f64 {
......@@ -124,7 +124,7 @@ pub fn log10_64(x_: f64) -> f64 {
124124 // subnormal, scale x
125125 k -= 54;
126126 x *= 0x1.0p54;
127 hx = u32(@bitCast(u64, x) >> 32)
127 hx = u32(@bitCast(u64, x) >> 32);
128128 }
129129 else if (hx >= 0x7FF00000) {
130130 return x;
......@@ -167,7 +167,7 @@ pub fn log10_64(x_: f64) -> f64 {
167167 val_lo += (y - ww) + val_hi;
168168 val_hi = ww;
169169
170 val_lo + val_hi
170 return val_lo + val_hi;
171171}
172172
173173test "math.log10" {
std/math/log1p.zig+4-4
......@@ -11,11 +11,11 @@ const assert = @import("../debug.zig").assert;
1111
1212pub fn log1p(x: var) -> @typeOf(x) {
1313 const T = @typeOf(x);
14 switch (T) {
14 return switch (T) {
1515 f32 => @inlineCall(log1p_32, x),
1616 f64 => @inlineCall(log1p_64, x),
1717 else => @compileError("log1p not implemented for " ++ @typeName(T)),
18 }
18 };
1919}
2020
2121fn log1p_32(x: f32) -> f32 {
......@@ -91,7 +91,7 @@ fn log1p_32(x: f32) -> f32 {
9191 const hfsq = 0.5 * f * f;
9292 const dk = f32(k);
9393
94 s * (hfsq + R) + (dk * ln2_lo + c) - hfsq + f + dk * ln2_hi
94 return s * (hfsq + R) + (dk * ln2_lo + c) - hfsq + f + dk * ln2_hi;
9595}
9696
9797fn log1p_64(x: f64) -> f64 {
......@@ -172,7 +172,7 @@ fn log1p_64(x: f64) -> f64 {
172172 const R = t2 + t1;
173173 const dk = f64(k);
174174
175 s * (hfsq + R) + (dk * ln2_lo + c) - hfsq + f + dk * ln2_hi
175 return s * (hfsq + R) + (dk * ln2_lo + c) - hfsq + f + dk * ln2_hi;
176176}
177177
178178test "math.log1p" {
std/math/log2.zig+4-4
......@@ -14,7 +14,7 @@ pub fn log2(x: var) -> @typeOf(x) {
1414 const T = @typeOf(x);
1515 switch (@typeId(T)) {
1616 TypeId.FloatLiteral => {
17 return @typeOf(1.0)(log2_64(x))
17 return @typeOf(1.0)(log2_64(x));
1818 },
1919 TypeId.Float => {
2020 return switch (T) {
......@@ -26,7 +26,7 @@ pub fn log2(x: var) -> @typeOf(x) {
2626 TypeId.IntLiteral => comptime {
2727 var result = 0;
2828 var x_shifted = x;
29 while ({x_shifted >>= 1; x_shifted != 0}) : (result += 1) {}
29 while (b: {x_shifted >>= 1; break :b x_shifted != 0;}) : (result += 1) {}
3030 return result;
3131 },
3232 TypeId.Int => {
......@@ -94,7 +94,7 @@ pub fn log2_32(x_: f32) -> f32 {
9494 u &= 0xFFFFF000;
9595 hi = @bitCast(f32, u);
9696 const lo = f - hi - hfsq + s * (hfsq + R);
97 (lo + hi) * ivln2lo + lo * ivln2hi + hi * ivln2hi + f32(k)
97 return (lo + hi) * ivln2lo + lo * ivln2hi + hi * ivln2hi + f32(k);
9898}
9999
100100pub fn log2_64(x_: f64) -> f64 {
......@@ -165,7 +165,7 @@ pub fn log2_64(x_: f64) -> f64 {
165165 val_lo += (y - ww) + val_hi;
166166 val_hi = ww;
167167
168 val_lo + val_hi
168 return val_lo + val_hi;
169169}
170170
171171test "math.log2" {
std/math/modf.zig+6-6
......@@ -7,21 +7,21 @@ const math = @import("index.zig");
77const assert = @import("../debug.zig").assert;
88
99fn modf_result(comptime T: type) -> type {
10 struct {
10 return struct {
1111 fpart: T,
1212 ipart: T,
13 }
13 };
1414}
1515pub const modf32_result = modf_result(f32);
1616pub const modf64_result = modf_result(f64);
1717
1818pub fn modf(x: var) -> modf_result(@typeOf(x)) {
1919 const T = @typeOf(x);
20 switch (T) {
20 return switch (T) {
2121 f32 => @inlineCall(modf32, x),
2222 f64 => @inlineCall(modf64, x),
2323 else => @compileError("modf not implemented for " ++ @typeName(T)),
24 }
24 };
2525}
2626
2727fn modf32(x: f32) -> modf32_result {
......@@ -66,7 +66,7 @@ fn modf32(x: f32) -> modf32_result {
6666 const uf = @bitCast(f32, u & ~mask);
6767 result.ipart = uf;
6868 result.fpart = x - uf;
69 result
69 return result;
7070}
7171
7272fn modf64(x: f64) -> modf64_result {
......@@ -110,7 +110,7 @@ fn modf64(x: f64) -> modf64_result {
110110 const uf = @bitCast(f64, u & ~mask);
111111 result.ipart = uf;
112112 result.fpart = x - uf;
113 result
113 return result;
114114}
115115
116116test "math.modf" {
std/math/nan.zig+4-4
......@@ -1,19 +1,19 @@
11const math = @import("index.zig");
22
33pub fn nan(comptime T: type) -> T {
4 switch (T) {
4 return switch (T) {
55 f32 => @bitCast(f32, math.nan_u32),
66 f64 => @bitCast(f64, math.nan_u64),
77 else => @compileError("nan not implemented for " ++ @typeName(T)),
8 }
8 };
99}
1010
1111// Note: A signalling nan is identical to a standard right now by may have a different bit
1212// representation in the future when required.
1313pub fn snan(comptime T: type) -> T {
14 switch (T) {
14 return switch (T) {
1515 f32 => @bitCast(f32, math.nan_u32),
1616 f64 => @bitCast(f64, math.nan_u64),
1717 else => @compileError("snan not implemented for " ++ @typeName(T)),
18 }
18 };
1919}
std/math/pow.zig+2-2
......@@ -166,12 +166,12 @@ pub fn pow(comptime T: type, x: T, y: T) -> T {
166166 ae = -ae;
167167 }
168168
169 math.scalbn(a1, ae)
169 return math.scalbn(a1, ae);
170170}
171171
172172fn isOddInteger(x: f64) -> bool {
173173 const r = math.modf(x);
174 r.fpart == 0.0 and i64(r.ipart) & 1 == 1
174 return r.fpart == 0.0 and i64(r.ipart) & 1 == 1;
175175}
176176
177177test "math.pow" {
std/math/round.zig+6-6
......@@ -10,11 +10,11 @@ const math = @import("index.zig");
1010
1111pub fn round(x: var) -> @typeOf(x) {
1212 const T = @typeOf(x);
13 switch (T) {
13 return switch (T) {
1414 f32 => @inlineCall(round32, x),
1515 f64 => @inlineCall(round64, x),
1616 else => @compileError("round not implemented for " ++ @typeName(T)),
17 }
17 };
1818}
1919
2020fn round32(x_: f32) -> f32 {
......@@ -48,9 +48,9 @@ fn round32(x_: f32) -> f32 {
4848 }
4949
5050 if (u >> 31 != 0) {
51 -y
51 return -y;
5252 } else {
53 y
53 return y;
5454 }
5555}
5656
......@@ -85,9 +85,9 @@ fn round64(x_: f64) -> f64 {
8585 }
8686
8787 if (u >> 63 != 0) {
88 -y
88 return -y;
8989 } else {
90 y
90 return y;
9191 }
9292}
9393
std/math/scalbn.zig+4-4
......@@ -3,11 +3,11 @@ const assert = @import("../debug.zig").assert;
33
44pub fn scalbn(x: var, n: i32) -> @typeOf(x) {
55 const T = @typeOf(x);
6 switch (T) {
6 return switch (T) {
77 f32 => @inlineCall(scalbn32, x, n),
88 f64 => @inlineCall(scalbn64, x, n),
99 else => @compileError("scalbn not implemented for " ++ @typeName(T)),
10 }
10 };
1111}
1212
1313fn scalbn32(x: f32, n_: i32) -> f32 {
......@@ -37,7 +37,7 @@ fn scalbn32(x: f32, n_: i32) -> f32 {
3737 }
3838
3939 const u = u32(n +% 0x7F) << 23;
40 y * @bitCast(f32, u)
40 return y * @bitCast(f32, u);
4141}
4242
4343fn scalbn64(x: f64, n_: i32) -> f64 {
......@@ -67,7 +67,7 @@ fn scalbn64(x: f64, n_: i32) -> f64 {
6767 }
6868
6969 const u = u64(n +% 0x3FF) << 52;
70 y * @bitCast(f64, u)
70 return y * @bitCast(f64, u);
7171}
7272
7373test "math.scalbn" {
std/math/signbit.zig+4-4
......@@ -3,21 +3,21 @@ const assert = @import("../debug.zig").assert;
33
44pub fn signbit(x: var) -> bool {
55 const T = @typeOf(x);
6 switch (T) {
6 return switch (T) {
77 f32 => @inlineCall(signbit32, x),
88 f64 => @inlineCall(signbit64, x),
99 else => @compileError("signbit not implemented for " ++ @typeName(T)),
10 }
10 };
1111}
1212
1313fn signbit32(x: f32) -> bool {
1414 const bits = @bitCast(u32, x);
15 bits >> 31 != 0
15 return bits >> 31 != 0;
1616}
1717
1818fn signbit64(x: f64) -> bool {
1919 const bits = @bitCast(u64, x);
20 bits >> 63 != 0
20 return bits >> 63 != 0;
2121}
2222
2323test "math.signbit" {
std/math/sin.zig+13-13
......@@ -10,11 +10,11 @@ const assert = @import("../debug.zig").assert;
1010
1111pub fn sin(x: var) -> @typeOf(x) {
1212 const T = @typeOf(x);
13 switch (T) {
13 return switch (T) {
1414 f32 => @inlineCall(sin32, x),
1515 f64 => @inlineCall(sin64, x),
1616 else => @compileError("sin not implemented for " ++ @typeName(T)),
17 }
17 };
1818}
1919
2020// sin polynomial coefficients
......@@ -75,18 +75,18 @@ fn sin32(x_: f32) -> f32 {
7575 const z = ((x - y * pi4a) - y * pi4b) - y * pi4c;
7676 const w = z * z;
7777
78 const r = {
78 const r = r: {
7979 if (j == 1 or j == 2) {
80 1.0 - 0.5 * w + w * w * (C5 + w * (C4 + w * (C3 + w * (C2 + w * (C1 + w * C0)))))
80 break :r 1.0 - 0.5 * w + w * w * (C5 + w * (C4 + w * (C3 + w * (C2 + w * (C1 + w * C0)))));
8181 } else {
82 z + z * w * (S5 + w * (S4 + w * (S3 + w * (S2 + w * (S1 + w * S0)))))
82 break :r z + z * w * (S5 + w * (S4 + w * (S3 + w * (S2 + w * (S1 + w * S0)))));
8383 }
8484 };
8585
8686 if (sign) {
87 -r
87 return -r;
8888 } else {
89 r
89 return r;
9090 }
9191}
9292
......@@ -127,25 +127,25 @@ fn sin64(x_: f64) -> f64 {
127127 const z = ((x - y * pi4a) - y * pi4b) - y * pi4c;
128128 const w = z * z;
129129
130 const r = {
130 const r = r: {
131131 if (j == 1 or j == 2) {
132 1.0 - 0.5 * w + w * w * (C5 + w * (C4 + w * (C3 + w * (C2 + w * (C1 + w * C0)))))
132 break :r 1.0 - 0.5 * w + w * w * (C5 + w * (C4 + w * (C3 + w * (C2 + w * (C1 + w * C0)))));
133133 } else {
134 z + z * w * (S5 + w * (S4 + w * (S3 + w * (S2 + w * (S1 + w * S0)))))
134 break :r z + z * w * (S5 + w * (S4 + w * (S3 + w * (S2 + w * (S1 + w * S0)))));
135135 }
136136 };
137137
138138 if (sign) {
139 -r
139 return -r;
140140 } else {
141 r
141 return r;
142142 }
143143}
144144
145145test "math.sin" {
146146 assert(sin(f32(0.0)) == sin32(0.0));
147147 assert(sin(f64(0.0)) == sin64(0.0));
148 assert(comptime {math.sin(f64(2))} == math.sin(f64(2)));
148 assert(comptime (math.sin(f64(2))) == math.sin(f64(2)));
149149}
150150
151151test "math.sin32" {
std/math/sinh.zig+4-4
......@@ -11,11 +11,11 @@ const expo2 = @import("expo2.zig").expo2;
1111
1212pub fn sinh(x: var) -> @typeOf(x) {
1313 const T = @typeOf(x);
14 switch (T) {
14 return switch (T) {
1515 f32 => @inlineCall(sinh32, x),
1616 f64 => @inlineCall(sinh64, x),
1717 else => @compileError("sinh not implemented for " ++ @typeName(T)),
18 }
18 };
1919}
2020
2121// sinh(x) = (exp(x) - 1 / exp(x)) / 2
......@@ -49,7 +49,7 @@ fn sinh32(x: f32) -> f32 {
4949 }
5050
5151 // |x| > log(FLT_MAX) or nan
52 2 * h * expo2(ax)
52 return 2 * h * expo2(ax);
5353}
5454
5555fn sinh64(x: f64) -> f64 {
......@@ -83,7 +83,7 @@ fn sinh64(x: f64) -> f64 {
8383 }
8484
8585 // |x| > log(DBL_MAX) or nan
86 2 * h * expo2(ax)
86 return 2 * h * expo2(ax);
8787}
8888
8989test "math.sinh" {
std/math/sqrt.zig+5-5
......@@ -14,7 +14,7 @@ pub fn sqrt(x: var) -> (if (@typeId(@typeOf(x)) == TypeId.Int) @IntType(false, @
1414 const T = @typeOf(x);
1515 switch (@typeId(T)) {
1616 TypeId.FloatLiteral => {
17 return T(sqrt64(x))
17 return T(sqrt64(x));
1818 },
1919 TypeId.Float => {
2020 return switch (T) {
......@@ -64,7 +64,7 @@ fn sqrt32(x: f32) -> f32 {
6464 // subnormal
6565 var i: i32 = 0;
6666 while (ix & 0x00800000 == 0) : (i += 1) {
67 ix <<= 1
67 ix <<= 1;
6868 }
6969 m -= i - 1;
7070 }
......@@ -112,7 +112,7 @@ fn sqrt32(x: f32) -> f32 {
112112
113113 ix = (q >> 1) + 0x3f000000;
114114 ix += m << 23;
115 @bitCast(f32, ix)
115 return @bitCast(f32, ix);
116116}
117117
118118// NOTE: The original code is full of implicit signed -> unsigned assumptions and u32 wraparound
......@@ -153,7 +153,7 @@ fn sqrt64(x: f64) -> f64 {
153153 // subnormal
154154 var i: u32 = 0;
155155 while (ix0 & 0x00100000 == 0) : (i += 1) {
156 ix0 <<= 1
156 ix0 <<= 1;
157157 }
158158 m -= i32(i) - 1;
159159 ix0 |= ix1 >> u5(32 - i);
......@@ -245,7 +245,7 @@ fn sqrt64(x: f64) -> f64 {
245245 iix0 = iix0 +% (m << 20);
246246
247247 const uz = (u64(iix0) << 32) | ix1;
248 @bitCast(f64, uz)
248 return @bitCast(f64, uz);
249249}
250250
251251test "math.sqrt" {
std/math/tan.zig+10-10
......@@ -10,11 +10,11 @@ const assert = @import("../debug.zig").assert;
1010
1111pub fn tan(x: var) -> @typeOf(x) {
1212 const T = @typeOf(x);
13 switch (T) {
13 return switch (T) {
1414 f32 => @inlineCall(tan32, x),
1515 f64 => @inlineCall(tan64, x),
1616 else => @compileError("tan not implemented for " ++ @typeName(T)),
17 }
17 };
1818}
1919
2020const Tp0 = -1.30936939181383777646E4;
......@@ -62,11 +62,11 @@ fn tan32(x_: f32) -> f32 {
6262 const z = ((x - y * pi4a) - y * pi4b) - y * pi4c;
6363 const w = z * z;
6464
65 var r = {
65 var r = r: {
6666 if (w > 1e-14) {
67 z + z * (w * ((Tp0 * w + Tp1) * w + Tp2) / ((((w + Tq1) * w + Tq2) * w + Tq3) * w + Tq4))
67 break :r z + z * (w * ((Tp0 * w + Tp1) * w + Tp2) / ((((w + Tq1) * w + Tq2) * w + Tq3) * w + Tq4));
6868 } else {
69 z
69 break :r z;
7070 }
7171 };
7272
......@@ -77,7 +77,7 @@ fn tan32(x_: f32) -> f32 {
7777 r = -r;
7878 }
7979
80 r
80 return r;
8181}
8282
8383fn tan64(x_: f64) -> f64 {
......@@ -111,11 +111,11 @@ fn tan64(x_: f64) -> f64 {
111111 const z = ((x - y * pi4a) - y * pi4b) - y * pi4c;
112112 const w = z * z;
113113
114 var r = {
114 var r = r: {
115115 if (w > 1e-14) {
116 z + z * (w * ((Tp0 * w + Tp1) * w + Tp2) / ((((w + Tq1) * w + Tq2) * w + Tq3) * w + Tq4))
116 break :r z + z * (w * ((Tp0 * w + Tp1) * w + Tp2) / ((((w + Tq1) * w + Tq2) * w + Tq3) * w + Tq4));
117117 } else {
118 z
118 break :r z;
119119 }
120120 };
121121
......@@ -126,7 +126,7 @@ fn tan64(x_: f64) -> f64 {
126126 r = -r;
127127 }
128128
129 r
129 return r;
130130}
131131
132132test "math.tan" {
std/math/tanh.zig+6-6
......@@ -11,11 +11,11 @@ const expo2 = @import("expo2.zig").expo2;
1111
1212pub fn tanh(x: var) -> @typeOf(x) {
1313 const T = @typeOf(x);
14 switch (T) {
14 return switch (T) {
1515 f32 => @inlineCall(tanh32, x),
1616 f64 => @inlineCall(tanh64, x),
1717 else => @compileError("tanh not implemented for " ++ @typeName(T)),
18 }
18 };
1919}
2020
2121// tanh(x) = (exp(x) - exp(-x)) / (exp(x) + exp(-x))
......@@ -59,9 +59,9 @@ fn tanh32(x: f32) -> f32 {
5959 }
6060
6161 if (u >> 31 != 0) {
62 -t
62 return -t;
6363 } else {
64 t
64 return t;
6565 }
6666}
6767
......@@ -104,9 +104,9 @@ fn tanh64(x: f64) -> f64 {
104104 }
105105
106106 if (u >> 63 != 0) {
107 -t
107 return -t;
108108 } else {
109 t
109 return t;
110110 }
111111}
112112
std/math/trunc.zig+6-6
......@@ -9,11 +9,11 @@ const assert = @import("../debug.zig").assert;
99
1010pub fn trunc(x: var) -> @typeOf(x) {
1111 const T = @typeOf(x);
12 switch (T) {
12 return switch (T) {
1313 f32 => @inlineCall(trunc32, x),
1414 f64 => @inlineCall(trunc64, x),
1515 else => @compileError("trunc not implemented for " ++ @typeName(T)),
16 }
16 };
1717}
1818
1919fn trunc32(x: f32) -> f32 {
......@@ -30,10 +30,10 @@ fn trunc32(x: f32) -> f32 {
3030
3131 m = u32(@maxValue(u32)) >> u5(e);
3232 if (u & m == 0) {
33 x
33 return x;
3434 } else {
3535 math.forceEval(x + 0x1p120);
36 @bitCast(f32, u & ~m)
36 return @bitCast(f32, u & ~m);
3737 }
3838}
3939
......@@ -51,10 +51,10 @@ fn trunc64(x: f64) -> f64 {
5151
5252 m = u64(@maxValue(u64)) >> u6(e);
5353 if (u & m == 0) {
54 x
54 return x;
5555 } else {
5656 math.forceEval(x + 0x1p120);
57 @bitCast(f64, u & ~m)
57 return @bitCast(f64, u & ~m);
5858 }
5959}
6060
std/mem.zig+4-4
......@@ -354,11 +354,11 @@ pub fn eql_slice_u8(a: []const u8, b: []const u8) -> bool {
354354/// split(" abc def ghi ", " ")
355355/// Will return slices for "abc", "def", "ghi", null, in that order.
356356pub fn split(buffer: []const u8, split_bytes: []const u8) -> SplitIterator {
357 SplitIterator {
357 return SplitIterator {
358358 .index = 0,
359359 .buffer = buffer,
360360 .split_bytes = split_bytes,
361 }
361 };
362362}
363363
364364test "mem.split" {
......@@ -552,7 +552,7 @@ test "std.mem.reverse" {
552552 var arr = []i32{ 5, 3, 1, 2, 4 };
553553 reverse(i32, arr[0..]);
554554
555 assert(eql(i32, arr, []i32{ 4, 2, 1, 3, 5 }))
555 assert(eql(i32, arr, []i32{ 4, 2, 1, 3, 5 }));
556556}
557557
558558/// In-place rotation of the values in an array ([0 1 2 3] becomes [1 2 3 0] if we rotate by 1)
......@@ -567,5 +567,5 @@ test "std.mem.rotate" {
567567 var arr = []i32{ 5, 3, 1, 2, 4 };
568568 rotate(i32, arr[0..], 2);
569569
570 assert(eql(i32, arr, []i32{ 1, 2, 4, 5, 3 }))
570 assert(eql(i32, arr, []i32{ 1, 2, 4, 5, 3 }));
571571}
std/net.zig+11-11
......@@ -72,7 +72,7 @@ pub fn lookup(hostname: []const u8, out_addrs: []Address) -> %[]Address {
7272// if (family != AF_INET)
7373// buf[cnt++] = (struct address){ .family = AF_INET6, .addr = { [15] = 1 } };
7474//
75 unreachable // TODO
75 unreachable; // TODO
7676 }
7777
7878 // TODO
......@@ -84,7 +84,7 @@ pub fn lookup(hostname: []const u8, out_addrs: []Address) -> %[]Address {
8484 // else => {},
8585 //};
8686
87 unreachable // TODO
87 unreachable; // TODO
8888}
8989
9090pub fn connectAddr(addr: &Address, port: u16) -> %Connection {
......@@ -96,23 +96,23 @@ pub fn connectAddr(addr: &Address, port: u16) -> %Connection {
9696 }
9797 const socket_fd = i32(socket_ret);
9898
99 const connect_ret = if (addr.family == linux.AF_INET) {
99 const connect_ret = if (addr.family == linux.AF_INET) x: {
100100 var os_addr: linux.sockaddr_in = undefined;
101101 os_addr.family = addr.family;
102102 os_addr.port = endian.swapIfLe(u16, port);
103103 @memcpy((&u8)(&os_addr.addr), &addr.addr[0], 4);
104104 @memset(&os_addr.zero[0], 0, @sizeOf(@typeOf(os_addr.zero)));
105 linux.connect(socket_fd, (&linux.sockaddr)(&os_addr), @sizeOf(linux.sockaddr_in))
106 } else if (addr.family == linux.AF_INET6) {
105 break :x linux.connect(socket_fd, (&linux.sockaddr)(&os_addr), @sizeOf(linux.sockaddr_in));
106 } else if (addr.family == linux.AF_INET6) x: {
107107 var os_addr: linux.sockaddr_in6 = undefined;
108108 os_addr.family = addr.family;
109109 os_addr.port = endian.swapIfLe(u16, port);
110110 os_addr.flowinfo = 0;
111111 os_addr.scope_id = addr.scope_id;
112112 @memcpy(&os_addr.addr[0], &addr.addr[0], 16);
113 linux.connect(socket_fd, (&linux.sockaddr)(&os_addr), @sizeOf(linux.sockaddr_in6))
113 break :x linux.connect(socket_fd, (&linux.sockaddr)(&os_addr), @sizeOf(linux.sockaddr_in6));
114114 } else {
115 unreachable
115 unreachable;
116116 };
117117 const connect_err = linux.getErrno(connect_ret);
118118 if (connect_err > 0) {
......@@ -165,13 +165,13 @@ pub fn parseIpLiteral(buf: []const u8) -> %Address {
165165fn hexDigit(c: u8) -> u8 {
166166 // TODO use switch with range
167167 if ('0' <= c and c <= '9') {
168 c - '0'
168 return c - '0';
169169 } else if ('A' <= c and c <= 'Z') {
170 c - 'A' + 10
170 return c - 'A' + 10;
171171 } else if ('a' <= c and c <= 'z') {
172 c - 'a' + 10
172 return c - 'a' + 10;
173173 } else {
174 @maxValue(u8)
174 return @maxValue(u8);
175175 }
176176}
177177
std/os/child_process.zig+35-35
......@@ -115,7 +115,7 @@ pub const ChildProcess = struct {
115115 return self.spawnWindows();
116116 } else {
117117 return self.spawnPosix();
118 };
118 }
119119 }
120120
121121 pub fn spawnAndWait(self: &ChildProcess) -> %Term {
......@@ -249,12 +249,12 @@ pub const ChildProcess = struct {
249249 fn waitUnwrappedWindows(self: &ChildProcess) -> %void {
250250 const result = os.windowsWaitSingle(self.handle, windows.INFINITE);
251251
252 self.term = (%Term)({
252 self.term = (%Term)(x: {
253253 var exit_code: windows.DWORD = undefined;
254254 if (windows.GetExitCodeProcess(self.handle, &exit_code) == 0) {
255 Term { .Unknown = 0 }
255 break :x Term { .Unknown = 0 };
256256 } else {
257 Term { .Exited = @bitCast(i32, exit_code)}
257 break :x Term { .Exited = @bitCast(i32, exit_code)};
258258 }
259259 });
260260
......@@ -300,7 +300,7 @@ pub const ChildProcess = struct {
300300 defer {
301301 os.close(self.err_pipe[0]);
302302 os.close(self.err_pipe[1]);
303 };
303 }
304304
305305 // Write @maxValue(ErrInt) to the write end of the err_pipe. This is after
306306 // waitpid, so this write is guaranteed to be after the child
......@@ -319,15 +319,15 @@ pub const ChildProcess = struct {
319319 }
320320
321321 fn statusToTerm(status: i32) -> Term {
322 return if (posix.WIFEXITED(status)) {
322 return if (posix.WIFEXITED(status))
323323 Term { .Exited = posix.WEXITSTATUS(status) }
324 } else if (posix.WIFSIGNALED(status)) {
324 else if (posix.WIFSIGNALED(status))
325325 Term { .Signal = posix.WTERMSIG(status) }
326 } else if (posix.WIFSTOPPED(status)) {
326 else if (posix.WIFSTOPPED(status))
327327 Term { .Stopped = posix.WSTOPSIG(status) }
328 } else {
328 else
329329 Term { .Unknown = status }
330 };
330 ;
331331 }
332332
333333 fn spawnPosix(self: &ChildProcess) -> %void {
......@@ -344,22 +344,22 @@ pub const ChildProcess = struct {
344344 %defer if (self.stderr_behavior == StdIo.Pipe) { destroyPipe(stderr_pipe); };
345345
346346 const any_ignore = (self.stdin_behavior == StdIo.Ignore or self.stdout_behavior == StdIo.Ignore or self.stderr_behavior == StdIo.Ignore);
347 const dev_null_fd = if (any_ignore) {
347 const dev_null_fd = if (any_ignore)
348348 %return os.posixOpen("/dev/null", posix.O_RDWR, 0, null)
349 } else {
349 else
350350 undefined
351 };
352 defer { if (any_ignore) os.close(dev_null_fd); };
351 ;
352 defer { if (any_ignore) os.close(dev_null_fd); }
353353
354354 var env_map_owned: BufMap = undefined;
355355 var we_own_env_map: bool = undefined;
356 const env_map = if (self.env_map) |env_map| {
356 const env_map = if (self.env_map) |env_map| x: {
357357 we_own_env_map = false;
358 env_map
359 } else {
358 break :x env_map;
359 } else x: {
360360 we_own_env_map = true;
361361 env_map_owned = %return os.getEnvMap(self.allocator);
362 &env_map_owned
362 break :x &env_map_owned;
363363 };
364364 defer { if (we_own_env_map) env_map_owned.deinit(); }
365365
......@@ -450,13 +450,13 @@ pub const ChildProcess = struct {
450450 self.stdout_behavior == StdIo.Ignore or
451451 self.stderr_behavior == StdIo.Ignore);
452452
453 const nul_handle = if (any_ignore) {
453 const nul_handle = if (any_ignore)
454454 %return os.windowsOpen("NUL", windows.GENERIC_READ, windows.FILE_SHARE_READ,
455455 windows.OPEN_EXISTING, windows.FILE_ATTRIBUTE_NORMAL, null)
456 } else {
456 else
457457 undefined
458 };
459 defer { if (any_ignore) os.close(nul_handle); };
458 ;
459 defer { if (any_ignore) os.close(nul_handle); }
460460 if (any_ignore) {
461461 %return windowsSetHandleInfo(nul_handle, windows.HANDLE_FLAG_INHERIT, 0);
462462 }
......@@ -542,30 +542,30 @@ pub const ChildProcess = struct {
542542 };
543543 var piProcInfo: windows.PROCESS_INFORMATION = undefined;
544544
545 const cwd_slice = if (self.cwd) |cwd| {
545 const cwd_slice = if (self.cwd) |cwd|
546546 %return cstr.addNullByte(self.allocator, cwd)
547 } else {
547 else
548548 null
549 };
549 ;
550550 defer if (cwd_slice) |cwd| self.allocator.free(cwd);
551551 const cwd_ptr = if (cwd_slice) |cwd| cwd.ptr else null;
552552
553 const maybe_envp_buf = if (self.env_map) |env_map| {
553 const maybe_envp_buf = if (self.env_map) |env_map|
554554 %return os.createWindowsEnvBlock(self.allocator, env_map)
555 } else {
555 else
556556 null
557 };
557 ;
558558 defer if (maybe_envp_buf) |envp_buf| self.allocator.free(envp_buf);
559559 const envp_ptr = if (maybe_envp_buf) |envp_buf| envp_buf.ptr else null;
560560
561561 // the cwd set in ChildProcess is in effect when choosing the executable path
562562 // to match posix semantics
563 const app_name = if (self.cwd) |cwd| {
563 const app_name = if (self.cwd) |cwd| x: {
564564 const resolved = %return os.path.resolve(self.allocator, cwd, self.argv[0]);
565565 defer self.allocator.free(resolved);
566 %return cstr.addNullByte(self.allocator, resolved)
567 } else {
568 %return cstr.addNullByte(self.allocator, self.argv[0])
566 break :x %return cstr.addNullByte(self.allocator, resolved);
567 } else x: {
568 break :x %return cstr.addNullByte(self.allocator, self.argv[0]);
569569 };
570570 defer self.allocator.free(app_name);
571571
......@@ -741,7 +741,7 @@ fn makePipe() -> %[2]i32 {
741741 return switch (err) {
742742 posix.EMFILE, posix.ENFILE => error.SystemResources,
743743 else => os.unexpectedErrorPosix(err),
744 }
744 };
745745 }
746746 return fds;
747747}
......@@ -800,10 +800,10 @@ fn handleTerm(pid: i32, status: i32) {
800800 }
801801}
802802
803const sigchld_set = {
803const sigchld_set = x: {
804804 var signal_set = posix.empty_sigset;
805805 posix.sigaddset(&signal_set, posix.SIGCHLD);
806 signal_set
806 break :x signal_set;
807807};
808808
809809fn block_SIGCHLD() {
std/os/darwin.zig+38-42
......@@ -97,63 +97,63 @@ pub const SIGINFO = 29; /// information request
9797pub const SIGUSR1 = 30; /// user defined signal 1
9898pub const SIGUSR2 = 31; /// user defined signal 2
9999
100fn wstatus(x: i32) -> i32 { x & 0o177 }
100fn wstatus(x: i32) -> i32 { return x & 0o177; }
101101const wstopped = 0o177;
102pub fn WEXITSTATUS(x: i32) -> i32 { x >> 8 }
103pub fn WTERMSIG(x: i32) -> i32 { wstatus(x) }
104pub fn WSTOPSIG(x: i32) -> i32 { x >> 8 }
105pub fn WIFEXITED(x: i32) -> bool { wstatus(x) == 0 }
106pub fn WIFSTOPPED(x: i32) -> bool { wstatus(x) == wstopped and WSTOPSIG(x) != 0x13 }
107pub fn WIFSIGNALED(x: i32) -> bool { wstatus(x) != wstopped and wstatus(x) != 0 }
102pub fn WEXITSTATUS(x: i32) -> i32 { return x >> 8; }
103pub fn WTERMSIG(x: i32) -> i32 { return wstatus(x); }
104pub fn WSTOPSIG(x: i32) -> i32 { return x >> 8; }
105pub fn WIFEXITED(x: i32) -> bool { return wstatus(x) == 0; }
106pub fn WIFSTOPPED(x: i32) -> bool { return wstatus(x) == wstopped and WSTOPSIG(x) != 0x13; }
107pub fn WIFSIGNALED(x: i32) -> bool { return wstatus(x) != wstopped and wstatus(x) != 0; }
108108
109109/// Get the errno from a syscall return value, or 0 for no error.
110110pub fn getErrno(r: usize) -> usize {
111111 const signed_r = @bitCast(isize, r);
112 if (signed_r > -4096 and signed_r < 0) usize(-signed_r) else 0
112 return if (signed_r > -4096 and signed_r < 0) usize(-signed_r) else 0;
113113}
114114
115115pub fn close(fd: i32) -> usize {
116 errnoWrap(c.close(fd))
116 return errnoWrap(c.close(fd));
117117}
118118
119119pub fn abort() -> noreturn {
120 c.abort()
120 return c.abort();
121121}
122122
123123pub fn exit(code: i32) -> noreturn {
124 c.exit(code)
124 return c.exit(code);
125125}
126126
127127pub fn isatty(fd: i32) -> bool {
128 c.isatty(fd) != 0
128 return c.isatty(fd) != 0;
129129}
130130
131131pub fn fstat(fd: i32, buf: &c.Stat) -> usize {
132 errnoWrap(c.@"fstat$INODE64"(fd, buf))
132 return errnoWrap(c.@"fstat$INODE64"(fd, buf));
133133}
134134
135135pub fn lseek(fd: i32, offset: isize, whence: c_int) -> usize {
136 errnoWrap(c.lseek(fd, offset, whence))
136 return errnoWrap(c.lseek(fd, offset, whence));
137137}
138138
139139pub fn open(path: &const u8, flags: u32, mode: usize) -> usize {
140 errnoWrap(c.open(path, @bitCast(c_int, flags), mode))
140 return errnoWrap(c.open(path, @bitCast(c_int, flags), mode));
141141}
142142
143143pub fn raise(sig: i32) -> usize {
144 errnoWrap(c.raise(sig))
144 return errnoWrap(c.raise(sig));
145145}
146146
147147pub fn read(fd: i32, buf: &u8, nbyte: usize) -> usize {
148 errnoWrap(c.read(fd, @ptrCast(&c_void, buf), nbyte))
148 return errnoWrap(c.read(fd, @ptrCast(&c_void, buf), nbyte));
149149}
150150
151151pub fn stat(noalias path: &const u8, noalias buf: &stat) -> usize {
152 errnoWrap(c.stat(path, buf))
152 return errnoWrap(c.stat(path, buf));
153153}
154154
155155pub fn write(fd: i32, buf: &const u8, nbyte: usize) -> usize {
156 errnoWrap(c.write(fd, @ptrCast(&const c_void, buf), nbyte))
156 return errnoWrap(c.write(fd, @ptrCast(&const c_void, buf), nbyte));
157157}
158158
159159pub fn mmap(address: ?&u8, length: usize, prot: usize, flags: usize, fd: i32,
......@@ -166,79 +166,79 @@ pub fn mmap(address: ?&u8, length: usize, prot: usize, flags: usize, fd: i32,
166166}
167167
168168pub fn munmap(address: &u8, length: usize) -> usize {
169 errnoWrap(c.munmap(@ptrCast(&c_void, address), length))
169 return errnoWrap(c.munmap(@ptrCast(&c_void, address), length));
170170}
171171
172172pub fn unlink(path: &const u8) -> usize {
173 errnoWrap(c.unlink(path))
173 return errnoWrap(c.unlink(path));
174174}
175175
176176pub fn getcwd(buf: &u8, size: usize) -> usize {
177 if (c.getcwd(buf, size) == null) @bitCast(usize, -isize(*c._errno())) else 0
177 return if (c.getcwd(buf, size) == null) @bitCast(usize, -isize(*c._errno())) else 0;
178178}
179179
180180pub fn waitpid(pid: i32, status: &i32, options: u32) -> usize {
181181 comptime assert(i32.bit_count == c_int.bit_count);
182 errnoWrap(c.waitpid(pid, @ptrCast(&c_int, status), @bitCast(c_int, options)))
182 return errnoWrap(c.waitpid(pid, @ptrCast(&c_int, status), @bitCast(c_int, options)));
183183}
184184
185185pub fn fork() -> usize {
186 errnoWrap(c.fork())
186 return errnoWrap(c.fork());
187187}
188188
189189pub fn pipe(fds: &[2]i32) -> usize {
190190 comptime assert(i32.bit_count == c_int.bit_count);
191 errnoWrap(c.pipe(@ptrCast(&c_int, fds)))
191 return errnoWrap(c.pipe(@ptrCast(&c_int, fds)));
192192}
193193
194194pub fn mkdir(path: &const u8, mode: u32) -> usize {
195 errnoWrap(c.mkdir(path, mode))
195 return errnoWrap(c.mkdir(path, mode));
196196}
197197
198198pub fn symlink(existing: &const u8, new: &const u8) -> usize {
199 errnoWrap(c.symlink(existing, new))
199 return errnoWrap(c.symlink(existing, new));
200200}
201201
202202pub fn rename(old: &const u8, new: &const u8) -> usize {
203 errnoWrap(c.rename(old, new))
203 return errnoWrap(c.rename(old, new));
204204}
205205
206206pub fn chdir(path: &const u8) -> usize {
207 errnoWrap(c.chdir(path))
207 return errnoWrap(c.chdir(path));
208208}
209209
210210pub fn execve(path: &const u8, argv: &const ?&const u8, envp: &const ?&const u8)
211211 -> usize
212212{
213 errnoWrap(c.execve(path, argv, envp))
213 return errnoWrap(c.execve(path, argv, envp));
214214}
215215
216216pub fn dup2(old: i32, new: i32) -> usize {
217 errnoWrap(c.dup2(old, new))
217 return errnoWrap(c.dup2(old, new));
218218}
219219
220220pub fn readlink(noalias path: &const u8, noalias buf_ptr: &u8, buf_len: usize) -> usize {
221 errnoWrap(c.readlink(path, buf_ptr, buf_len))
221 return errnoWrap(c.readlink(path, buf_ptr, buf_len));
222222}
223223
224224pub fn nanosleep(req: &const timespec, rem: ?&timespec) -> usize {
225 errnoWrap(c.nanosleep(req, rem))
225 return errnoWrap(c.nanosleep(req, rem));
226226}
227227
228228pub fn realpath(noalias filename: &const u8, noalias resolved_name: &u8) -> usize {
229 if (c.realpath(filename, resolved_name) == null) @bitCast(usize, -isize(*c._errno())) else 0
229 return if (c.realpath(filename, resolved_name) == null) @bitCast(usize, -isize(*c._errno())) else 0;
230230}
231231
232232pub fn setreuid(ruid: u32, euid: u32) -> usize {
233 errnoWrap(c.setreuid(ruid, euid))
233 return errnoWrap(c.setreuid(ruid, euid));
234234}
235235
236236pub fn setregid(rgid: u32, egid: u32) -> usize {
237 errnoWrap(c.setregid(rgid, egid))
237 return errnoWrap(c.setregid(rgid, egid));
238238}
239239
240240pub fn sigprocmask(flags: u32, noalias set: &const sigset_t, noalias oldset: ?&sigset_t) -> usize {
241 errnoWrap(c.sigprocmask(@bitCast(c_int, flags), set, oldset))
241 return errnoWrap(c.sigprocmask(@bitCast(c_int, flags), set, oldset));
242242}
243243
244244pub fn sigaction(sig: u5, noalias act: &const Sigaction, noalias oact: ?&Sigaction) -> usize {
......@@ -285,9 +285,5 @@ pub fn sigaddset(set: &sigset_t, signo: u5) {
285285/// that the kernel represents it to libc. Errno was a mistake, let's make
286286/// it go away forever.
287287fn errnoWrap(value: isize) -> usize {
288 @bitCast(usize, if (value == -1) {
289 -isize(*c._errno())
290 } else {
291 value
292 })
288 return @bitCast(usize, if (value == -1) -isize(*c._errno()) else value);
293289}
std/os/index.zig+9-10
......@@ -84,7 +84,7 @@ pub fn getRandomBytes(buf: []u8) -> %void {
8484 posix.EFAULT => unreachable,
8585 posix.EINTR => continue,
8686 else => unexpectedErrorPosix(err),
87 }
87 };
8888 }
8989 return;
9090 },
......@@ -151,18 +151,17 @@ pub coldcc fn exit(status: i32) -> noreturn {
151151 }
152152 switch (builtin.os) {
153153 Os.linux, Os.darwin, Os.macosx, Os.ios => {
154 posix.exit(status)
154 posix.exit(status);
155155 },
156156 Os.windows => {
157157 // Map a possibly negative status code to a non-negative status for the systems default
158158 // integer width.
159 const p_status = if (@sizeOf(c_uint) < @sizeOf(u32)) {
159 const p_status = if (@sizeOf(c_uint) < @sizeOf(u32))
160160 @truncate(c_uint, @bitCast(u32, status))
161 } else {
162 c_uint(@bitCast(u32, status))
163 };
161 else
162 c_uint(@bitCast(u32, status));
164163
165 windows.ExitProcess(p_status)
164 windows.ExitProcess(p_status);
166165 },
167166 else => @compileError("Unsupported OS"),
168167 }
......@@ -289,7 +288,7 @@ pub fn posixOpen(file_path: []const u8, flags: u32, perm: usize, allocator: ?&Al
289288 posix.EPERM => error.AccessDenied,
290289 posix.EEXIST => error.PathAlreadyExists,
291290 else => unexpectedErrorPosix(err),
292 }
291 };
293292 }
294293 return i32(result);
295294 }
......@@ -680,7 +679,7 @@ pub fn deleteFileWindows(allocator: &Allocator, file_path: []const u8) -> %void
680679 windows.ERROR.ACCESS_DENIED => error.AccessDenied,
681680 windows.ERROR.FILENAME_EXCED_RANGE, windows.ERROR.INVALID_PARAMETER => error.NameTooLong,
682681 else => unexpectedErrorWindows(err),
683 }
682 };
684683 }
685684}
686685
......@@ -1006,7 +1005,7 @@ pub const Dir = struct {
10061005 continue;
10071006 },
10081007 else => return unexpectedErrorPosix(err),
1009 };
1008 }
10101009 }
10111010 if (result == 0)
10121011 return null;
std/os/linux.zig+68-68
......@@ -367,14 +367,14 @@ pub const TFD_CLOEXEC = O_CLOEXEC;
367367pub const TFD_TIMER_ABSTIME = 1;
368368pub const TFD_TIMER_CANCEL_ON_SET = (1 << 1);
369369
370fn unsigned(s: i32) -> u32 { @bitCast(u32, s) }
371fn signed(s: u32) -> i32 { @bitCast(i32, s) }
372pub fn WEXITSTATUS(s: i32) -> i32 { signed((unsigned(s) & 0xff00) >> 8) }
373pub fn WTERMSIG(s: i32) -> i32 { signed(unsigned(s) & 0x7f) }
374pub fn WSTOPSIG(s: i32) -> i32 { WEXITSTATUS(s) }
375pub fn WIFEXITED(s: i32) -> bool { WTERMSIG(s) == 0 }
376pub fn WIFSTOPPED(s: i32) -> bool { (u16)(((unsigned(s)&0xffff)*%0x10001)>>8) > 0x7f00 }
377pub fn WIFSIGNALED(s: i32) -> bool { (unsigned(s)&0xffff)-%1 < 0xff }
370fn unsigned(s: i32) -> u32 { return @bitCast(u32, s); }
371fn signed(s: u32) -> i32 { return @bitCast(i32, s); }
372pub fn WEXITSTATUS(s: i32) -> i32 { return signed((unsigned(s) & 0xff00) >> 8); }
373pub fn WTERMSIG(s: i32) -> i32 { return signed(unsigned(s) & 0x7f); }
374pub fn WSTOPSIG(s: i32) -> i32 { return WEXITSTATUS(s); }
375pub fn WIFEXITED(s: i32) -> bool { return WTERMSIG(s) == 0; }
376pub fn WIFSTOPPED(s: i32) -> bool { return (u16)(((unsigned(s)&0xffff)*%0x10001)>>8) > 0x7f00; }
377pub fn WIFSIGNALED(s: i32) -> bool { return (unsigned(s)&0xffff)-%1 < 0xff; }
378378
379379
380380pub const winsize = extern struct {
......@@ -387,31 +387,31 @@ pub const winsize = extern struct {
387387/// Get the errno from a syscall return value, or 0 for no error.
388388pub fn getErrno(r: usize) -> usize {
389389 const signed_r = @bitCast(isize, r);
390 if (signed_r > -4096 and signed_r < 0) usize(-signed_r) else 0
390 return if (signed_r > -4096 and signed_r < 0) usize(-signed_r) else 0;
391391}
392392
393393pub fn dup2(old: i32, new: i32) -> usize {
394 arch.syscall2(arch.SYS_dup2, usize(old), usize(new))
394 return arch.syscall2(arch.SYS_dup2, usize(old), usize(new));
395395}
396396
397397pub fn chdir(path: &const u8) -> usize {
398 arch.syscall1(arch.SYS_chdir, @ptrToInt(path))
398 return arch.syscall1(arch.SYS_chdir, @ptrToInt(path));
399399}
400400
401401pub fn execve(path: &const u8, argv: &const ?&const u8, envp: &const ?&const u8) -> usize {
402 arch.syscall3(arch.SYS_execve, @ptrToInt(path), @ptrToInt(argv), @ptrToInt(envp))
402 return arch.syscall3(arch.SYS_execve, @ptrToInt(path), @ptrToInt(argv), @ptrToInt(envp));
403403}
404404
405405pub fn fork() -> usize {
406 arch.syscall0(arch.SYS_fork)
406 return arch.syscall0(arch.SYS_fork);
407407}
408408
409409pub fn getcwd(buf: &u8, size: usize) -> usize {
410 arch.syscall2(arch.SYS_getcwd, @ptrToInt(buf), size)
410 return arch.syscall2(arch.SYS_getcwd, @ptrToInt(buf), size);
411411}
412412
413413pub fn getdents(fd: i32, dirp: &u8, count: usize) -> usize {
414 arch.syscall3(arch.SYS_getdents, usize(fd), @ptrToInt(dirp), count)
414 return arch.syscall3(arch.SYS_getdents, usize(fd), @ptrToInt(dirp), count);
415415}
416416
417417pub fn isatty(fd: i32) -> bool {
......@@ -420,123 +420,123 @@ pub fn isatty(fd: i32) -> bool {
420420}
421421
422422pub fn readlink(noalias path: &const u8, noalias buf_ptr: &u8, buf_len: usize) -> usize {
423 arch.syscall3(arch.SYS_readlink, @ptrToInt(path), @ptrToInt(buf_ptr), buf_len)
423 return arch.syscall3(arch.SYS_readlink, @ptrToInt(path), @ptrToInt(buf_ptr), buf_len);
424424}
425425
426426pub fn mkdir(path: &const u8, mode: u32) -> usize {
427 arch.syscall2(arch.SYS_mkdir, @ptrToInt(path), mode)
427 return arch.syscall2(arch.SYS_mkdir, @ptrToInt(path), mode);
428428}
429429
430430pub fn mmap(address: ?&u8, length: usize, prot: usize, flags: usize, fd: i32, offset: isize)
431431 -> usize
432432{
433 arch.syscall6(arch.SYS_mmap, @ptrToInt(address), length, prot, flags, usize(fd),
434 @bitCast(usize, offset))
433 return arch.syscall6(arch.SYS_mmap, @ptrToInt(address), length, prot, flags, usize(fd),
434 @bitCast(usize, offset));
435435}
436436
437437pub fn munmap(address: &u8, length: usize) -> usize {
438 arch.syscall2(arch.SYS_munmap, @ptrToInt(address), length)
438 return arch.syscall2(arch.SYS_munmap, @ptrToInt(address), length);
439439}
440440
441441pub fn read(fd: i32, buf: &u8, count: usize) -> usize {
442 arch.syscall3(arch.SYS_read, usize(fd), @ptrToInt(buf), count)
442 return arch.syscall3(arch.SYS_read, usize(fd), @ptrToInt(buf), count);
443443}
444444
445445pub fn rmdir(path: &const u8) -> usize {
446 arch.syscall1(arch.SYS_rmdir, @ptrToInt(path))
446 return arch.syscall1(arch.SYS_rmdir, @ptrToInt(path));
447447}
448448
449449pub fn symlink(existing: &const u8, new: &const u8) -> usize {
450 arch.syscall2(arch.SYS_symlink, @ptrToInt(existing), @ptrToInt(new))
450 return arch.syscall2(arch.SYS_symlink, @ptrToInt(existing), @ptrToInt(new));
451451}
452452
453453pub fn pread(fd: i32, buf: &u8, count: usize, offset: usize) -> usize {
454 arch.syscall4(arch.SYS_pread, usize(fd), @ptrToInt(buf), count, offset)
454 return arch.syscall4(arch.SYS_pread, usize(fd), @ptrToInt(buf), count, offset);
455455}
456456
457457pub fn pipe(fd: &[2]i32) -> usize {
458 pipe2(fd, 0)
458 return pipe2(fd, 0);
459459}
460460
461461pub fn pipe2(fd: &[2]i32, flags: usize) -> usize {
462 arch.syscall2(arch.SYS_pipe2, @ptrToInt(fd), flags)
462 return arch.syscall2(arch.SYS_pipe2, @ptrToInt(fd), flags);
463463}
464464
465465pub fn write(fd: i32, buf: &const u8, count: usize) -> usize {
466 arch.syscall3(arch.SYS_write, usize(fd), @ptrToInt(buf), count)
466 return arch.syscall3(arch.SYS_write, usize(fd), @ptrToInt(buf), count);
467467}
468468
469469pub fn pwrite(fd: i32, buf: &const u8, count: usize, offset: usize) -> usize {
470 arch.syscall4(arch.SYS_pwrite, usize(fd), @ptrToInt(buf), count, offset)
470 return arch.syscall4(arch.SYS_pwrite, usize(fd), @ptrToInt(buf), count, offset);
471471}
472472
473473pub fn rename(old: &const u8, new: &const u8) -> usize {
474 arch.syscall2(arch.SYS_rename, @ptrToInt(old), @ptrToInt(new))
474 return arch.syscall2(arch.SYS_rename, @ptrToInt(old), @ptrToInt(new));
475475}
476476
477477pub fn open(path: &const u8, flags: u32, perm: usize) -> usize {
478 arch.syscall3(arch.SYS_open, @ptrToInt(path), flags, perm)
478 return arch.syscall3(arch.SYS_open, @ptrToInt(path), flags, perm);
479479}
480480
481481pub fn create(path: &const u8, perm: usize) -> usize {
482 arch.syscall2(arch.SYS_creat, @ptrToInt(path), perm)
482 return arch.syscall2(arch.SYS_creat, @ptrToInt(path), perm);
483483}
484484
485485pub fn openat(dirfd: i32, path: &const u8, flags: usize, mode: usize) -> usize {
486 arch.syscall4(arch.SYS_openat, usize(dirfd), @ptrToInt(path), flags, mode)
486 return arch.syscall4(arch.SYS_openat, usize(dirfd), @ptrToInt(path), flags, mode);
487487}
488488
489489pub fn close(fd: i32) -> usize {
490 arch.syscall1(arch.SYS_close, usize(fd))
490 return arch.syscall1(arch.SYS_close, usize(fd));
491491}
492492
493493pub fn lseek(fd: i32, offset: isize, ref_pos: usize) -> usize {
494 arch.syscall3(arch.SYS_lseek, usize(fd), @bitCast(usize, offset), ref_pos)
494 return arch.syscall3(arch.SYS_lseek, usize(fd), @bitCast(usize, offset), ref_pos);
495495}
496496
497497pub fn exit(status: i32) -> noreturn {
498498 _ = arch.syscall1(arch.SYS_exit, @bitCast(usize, isize(status)));
499 unreachable
499 unreachable;
500500}
501501
502502pub fn getrandom(buf: &u8, count: usize, flags: u32) -> usize {
503 arch.syscall3(arch.SYS_getrandom, @ptrToInt(buf), count, usize(flags))
503 return arch.syscall3(arch.SYS_getrandom, @ptrToInt(buf), count, usize(flags));
504504}
505505
506506pub fn kill(pid: i32, sig: i32) -> usize {
507 arch.syscall2(arch.SYS_kill, @bitCast(usize, isize(pid)), usize(sig))
507 return arch.syscall2(arch.SYS_kill, @bitCast(usize, isize(pid)), usize(sig));
508508}
509509
510510pub fn unlink(path: &const u8) -> usize {
511 arch.syscall1(arch.SYS_unlink, @ptrToInt(path))
511 return arch.syscall1(arch.SYS_unlink, @ptrToInt(path));
512512}
513513
514514pub fn waitpid(pid: i32, status: &i32, options: i32) -> usize {
515 arch.syscall4(arch.SYS_wait4, @bitCast(usize, isize(pid)), @ptrToInt(status), @bitCast(usize, isize(options)), 0)
515 return arch.syscall4(arch.SYS_wait4, @bitCast(usize, isize(pid)), @ptrToInt(status), @bitCast(usize, isize(options)), 0);
516516}
517517
518518pub fn nanosleep(req: &const timespec, rem: ?&timespec) -> usize {
519 arch.syscall2(arch.SYS_nanosleep, @ptrToInt(req), @ptrToInt(rem))
519 return arch.syscall2(arch.SYS_nanosleep, @ptrToInt(req), @ptrToInt(rem));
520520}
521521
522522pub fn setuid(uid: u32) -> usize {
523 arch.syscall1(arch.SYS_setuid, uid)
523 return arch.syscall1(arch.SYS_setuid, uid);
524524}
525525
526526pub fn setgid(gid: u32) -> usize {
527 arch.syscall1(arch.SYS_setgid, gid)
527 return arch.syscall1(arch.SYS_setgid, gid);
528528}
529529
530530pub fn setreuid(ruid: u32, euid: u32) -> usize {
531 arch.syscall2(arch.SYS_setreuid, ruid, euid)
531 return arch.syscall2(arch.SYS_setreuid, ruid, euid);
532532}
533533
534534pub fn setregid(rgid: u32, egid: u32) -> usize {
535 arch.syscall2(arch.SYS_setregid, rgid, egid)
535 return arch.syscall2(arch.SYS_setregid, rgid, egid);
536536}
537537
538538pub fn sigprocmask(flags: u32, noalias set: &const sigset_t, noalias oldset: ?&sigset_t) -> usize {
539 arch.syscall4(arch.SYS_rt_sigprocmask, flags, @ptrToInt(set), @ptrToInt(oldset), NSIG/8)
539 return arch.syscall4(arch.SYS_rt_sigprocmask, flags, @ptrToInt(set), @ptrToInt(oldset), NSIG/8);
540540}
541541
542542pub fn sigaction(sig: u6, noalias act: &const Sigaction, noalias oact: ?&Sigaction) -> usize {
......@@ -652,69 +652,69 @@ pub const iovec = extern struct {
652652};
653653
654654pub fn getsockname(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) -> usize {
655 arch.syscall3(arch.SYS_getsockname, usize(fd), @ptrToInt(addr), @ptrToInt(len))
655 return arch.syscall3(arch.SYS_getsockname, usize(fd), @ptrToInt(addr), @ptrToInt(len));
656656}
657657
658658pub fn getpeername(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) -> usize {
659 arch.syscall3(arch.SYS_getpeername, usize(fd), @ptrToInt(addr), @ptrToInt(len))
659 return arch.syscall3(arch.SYS_getpeername, usize(fd), @ptrToInt(addr), @ptrToInt(len));
660660}
661661
662662pub fn socket(domain: i32, socket_type: i32, protocol: i32) -> usize {
663 arch.syscall3(arch.SYS_socket, usize(domain), usize(socket_type), usize(protocol))
663 return arch.syscall3(arch.SYS_socket, usize(domain), usize(socket_type), usize(protocol));
664664}
665665
666666pub fn setsockopt(fd: i32, level: i32, optname: i32, optval: &const u8, optlen: socklen_t) -> usize {
667 arch.syscall5(arch.SYS_setsockopt, usize(fd), usize(level), usize(optname), usize(optval), @ptrToInt(optlen))
667 return arch.syscall5(arch.SYS_setsockopt, usize(fd), usize(level), usize(optname), usize(optval), @ptrToInt(optlen));
668668}
669669
670670pub fn getsockopt(fd: i32, level: i32, optname: i32, noalias optval: &u8, noalias optlen: &socklen_t) -> usize {
671 arch.syscall5(arch.SYS_getsockopt, usize(fd), usize(level), usize(optname), @ptrToInt(optval), @ptrToInt(optlen))
671 return arch.syscall5(arch.SYS_getsockopt, usize(fd), usize(level), usize(optname), @ptrToInt(optval), @ptrToInt(optlen));
672672}
673673
674674pub fn sendmsg(fd: i32, msg: &const arch.msghdr, flags: u32) -> usize {
675 arch.syscall3(arch.SYS_sendmsg, usize(fd), @ptrToInt(msg), flags)
675 return arch.syscall3(arch.SYS_sendmsg, usize(fd), @ptrToInt(msg), flags);
676676}
677677
678678pub fn connect(fd: i32, addr: &const sockaddr, len: socklen_t) -> usize {
679 arch.syscall3(arch.SYS_connect, usize(fd), @ptrToInt(addr), usize(len))
679 return arch.syscall3(arch.SYS_connect, usize(fd), @ptrToInt(addr), usize(len));
680680}
681681
682682pub fn recvmsg(fd: i32, msg: &arch.msghdr, flags: u32) -> usize {
683 arch.syscall3(arch.SYS_recvmsg, usize(fd), @ptrToInt(msg), flags)
683 return arch.syscall3(arch.SYS_recvmsg, usize(fd), @ptrToInt(msg), flags);
684684}
685685
686686pub fn recvfrom(fd: i32, noalias buf: &u8, len: usize, flags: u32,
687687 noalias addr: ?&sockaddr, noalias alen: ?&socklen_t) -> usize
688688{
689 arch.syscall6(arch.SYS_recvfrom, usize(fd), @ptrToInt(buf), len, flags, @ptrToInt(addr), @ptrToInt(alen))
689 return arch.syscall6(arch.SYS_recvfrom, usize(fd), @ptrToInt(buf), len, flags, @ptrToInt(addr), @ptrToInt(alen));
690690}
691691
692692pub fn shutdown(fd: i32, how: i32) -> usize {
693 arch.syscall2(arch.SYS_shutdown, usize(fd), usize(how))
693 return arch.syscall2(arch.SYS_shutdown, usize(fd), usize(how));
694694}
695695
696696pub fn bind(fd: i32, addr: &const sockaddr, len: socklen_t) -> usize {
697 arch.syscall3(arch.SYS_bind, usize(fd), @ptrToInt(addr), usize(len))
697 return arch.syscall3(arch.SYS_bind, usize(fd), @ptrToInt(addr), usize(len));
698698}
699699
700700pub fn listen(fd: i32, backlog: i32) -> usize {
701 arch.syscall2(arch.SYS_listen, usize(fd), usize(backlog))
701 return arch.syscall2(arch.SYS_listen, usize(fd), usize(backlog));
702702}
703703
704704pub fn sendto(fd: i32, buf: &const u8, len: usize, flags: u32, addr: ?&const sockaddr, alen: socklen_t) -> usize {
705 arch.syscall6(arch.SYS_sendto, usize(fd), @ptrToInt(buf), len, flags, @ptrToInt(addr), usize(alen))
705 return arch.syscall6(arch.SYS_sendto, usize(fd), @ptrToInt(buf), len, flags, @ptrToInt(addr), usize(alen));
706706}
707707
708708pub fn socketpair(domain: i32, socket_type: i32, protocol: i32, fd: [2]i32) -> usize {
709 arch.syscall4(arch.SYS_socketpair, usize(domain), usize(socket_type), usize(protocol), @ptrToInt(&fd[0]))
709 return arch.syscall4(arch.SYS_socketpair, usize(domain), usize(socket_type), usize(protocol), @ptrToInt(&fd[0]));
710710}
711711
712712pub fn accept(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) -> usize {
713 accept4(fd, addr, len, 0)
713 return accept4(fd, addr, len, 0);
714714}
715715
716716pub fn accept4(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t, flags: u32) -> usize {
717 arch.syscall4(arch.SYS_accept4, usize(fd), @ptrToInt(addr), @ptrToInt(len), flags)
717 return arch.syscall4(arch.SYS_accept4, usize(fd), @ptrToInt(addr), @ptrToInt(len), flags);
718718}
719719
720720// error NameTooLong;
......@@ -749,7 +749,7 @@ pub const Stat = arch.Stat;
749749pub const timespec = arch.timespec;
750750
751751pub fn fstat(fd: i32, stat_buf: &Stat) -> usize {
752 arch.syscall2(arch.SYS_fstat, usize(fd), @ptrToInt(stat_buf))
752 return arch.syscall2(arch.SYS_fstat, usize(fd), @ptrToInt(stat_buf));
753753}
754754
755755pub const epoll_data = u64;
......@@ -760,19 +760,19 @@ pub const epoll_event = extern struct {
760760};
761761
762762pub fn epoll_create() -> usize {
763 arch.syscall1(arch.SYS_epoll_create, usize(1))
763 return arch.syscall1(arch.SYS_epoll_create, usize(1));
764764}
765765
766766pub fn epoll_ctl(epoll_fd: i32, op: i32, fd: i32, ev: &epoll_event) -> usize {
767 arch.syscall4(arch.SYS_epoll_ctl, usize(epoll_fd), usize(op), usize(fd), @ptrToInt(ev))
767 return arch.syscall4(arch.SYS_epoll_ctl, usize(epoll_fd), usize(op), usize(fd), @ptrToInt(ev));
768768}
769769
770770pub fn epoll_wait(epoll_fd: i32, events: &epoll_event, maxevents: i32, timeout: i32) -> usize {
771 arch.syscall4(arch.SYS_epoll_wait, usize(epoll_fd), @ptrToInt(events), usize(maxevents), usize(timeout))
771 return arch.syscall4(arch.SYS_epoll_wait, usize(epoll_fd), @ptrToInt(events), usize(maxevents), usize(timeout));
772772}
773773
774774pub fn timerfd_create(clockid: i32, flags: u32) -> usize {
775 arch.syscall2(arch.SYS_timerfd_create, usize(clockid), usize(flags))
775 return arch.syscall2(arch.SYS_timerfd_create, usize(clockid), usize(flags));
776776}
777777
778778pub const itimerspec = extern struct {
......@@ -781,11 +781,11 @@ pub const itimerspec = extern struct {
781781};
782782
783783pub fn timerfd_gettime(fd: i32, curr_value: &itimerspec) -> usize {
784 arch.syscall2(arch.SYS_timerfd_gettime, usize(fd), @ptrToInt(curr_value))
784 return arch.syscall2(arch.SYS_timerfd_gettime, usize(fd), @ptrToInt(curr_value));
785785}
786786
787787pub fn timerfd_settime(fd: i32, flags: u32, new_value: &const itimerspec, old_value: ?&itimerspec) -> usize {
788 arch.syscall4(arch.SYS_timerfd_settime, usize(fd), usize(flags), @ptrToInt(new_value), @ptrToInt(old_value))
788 return arch.syscall4(arch.SYS_timerfd_settime, usize(fd), usize(flags), @ptrToInt(new_value), @ptrToInt(old_value));
789789}
790790
791791test "import linux_test" {
std/os/linux_x86_64.zig+16-16
......@@ -371,52 +371,52 @@ pub const F_GETOWN_EX = 16;
371371pub const F_GETOWNER_UIDS = 17;
372372
373373pub fn syscall0(number: usize) -> usize {
374 asm volatile ("syscall"
374 return asm volatile ("syscall"
375375 : [ret] "={rax}" (-> usize)
376376 : [number] "{rax}" (number)
377 : "rcx", "r11")
377 : "rcx", "r11");
378378}
379379
380380pub fn syscall1(number: usize, arg1: usize) -> usize {
381 asm volatile ("syscall"
381 return asm volatile ("syscall"
382382 : [ret] "={rax}" (-> usize)
383383 : [number] "{rax}" (number),
384384 [arg1] "{rdi}" (arg1)
385 : "rcx", "r11")
385 : "rcx", "r11");
386386}
387387
388388pub fn syscall2(number: usize, arg1: usize, arg2: usize) -> usize {
389 asm volatile ("syscall"
389 return asm volatile ("syscall"
390390 : [ret] "={rax}" (-> usize)
391391 : [number] "{rax}" (number),
392392 [arg1] "{rdi}" (arg1),
393393 [arg2] "{rsi}" (arg2)
394 : "rcx", "r11")
394 : "rcx", "r11");
395395}
396396
397397pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) -> usize {
398 asm volatile ("syscall"
398 return asm volatile ("syscall"
399399 : [ret] "={rax}" (-> usize)
400400 : [number] "{rax}" (number),
401401 [arg1] "{rdi}" (arg1),
402402 [arg2] "{rsi}" (arg2),
403403 [arg3] "{rdx}" (arg3)
404 : "rcx", "r11")
404 : "rcx", "r11");
405405}
406406
407407pub fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) -> usize {
408 asm volatile ("syscall"
408 return asm volatile ("syscall"
409409 : [ret] "={rax}" (-> usize)
410410 : [number] "{rax}" (number),
411411 [arg1] "{rdi}" (arg1),
412412 [arg2] "{rsi}" (arg2),
413413 [arg3] "{rdx}" (arg3),
414414 [arg4] "{r10}" (arg4)
415 : "rcx", "r11")
415 : "rcx", "r11");
416416}
417417
418418pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) -> usize {
419 asm volatile ("syscall"
419 return asm volatile ("syscall"
420420 : [ret] "={rax}" (-> usize)
421421 : [number] "{rax}" (number),
422422 [arg1] "{rdi}" (arg1),
......@@ -424,13 +424,13 @@ pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usiz
424424 [arg3] "{rdx}" (arg3),
425425 [arg4] "{r10}" (arg4),
426426 [arg5] "{r8}" (arg5)
427 : "rcx", "r11")
427 : "rcx", "r11");
428428}
429429
430430pub fn syscall6(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize,
431431 arg5: usize, arg6: usize) -> usize
432432{
433 asm volatile ("syscall"
433 return asm volatile ("syscall"
434434 : [ret] "={rax}" (-> usize)
435435 : [number] "{rax}" (number),
436436 [arg1] "{rdi}" (arg1),
......@@ -439,14 +439,14 @@ pub fn syscall6(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usiz
439439 [arg4] "{r10}" (arg4),
440440 [arg5] "{r8}" (arg5),
441441 [arg6] "{r9}" (arg6)
442 : "rcx", "r11")
442 : "rcx", "r11");
443443}
444444
445445pub nakedcc fn restore_rt() {
446 asm volatile ("syscall"
446 return asm volatile ("syscall"
447447 :
448448 : [number] "{rax}" (usize(SYS_rt_sigreturn))
449 : "rcx", "r11")
449 : "rcx", "r11");
450450}
451451
452452
std/os/path.zig+18-18
......@@ -749,21 +749,19 @@ pub fn relativeWindows(allocator: &Allocator, from: []const u8, to: []const u8)
749749 const resolved_to = %return resolveWindows(allocator, [][]const u8{to});
750750 defer if (clean_up_resolved_to) allocator.free(resolved_to);
751751
752 const result_is_to = if (drive(resolved_to)) |to_drive| {
753 if (drive(resolved_from)) |from_drive| {
752 const result_is_to = if (drive(resolved_to)) |to_drive|
753 if (drive(resolved_from)) |from_drive|
754754 asciiUpper(from_drive[0]) != asciiUpper(to_drive[0])
755 } else {
755 else
756756 true
757 }
758 } else if (networkShare(resolved_to)) |to_ns| {
759 if (networkShare(resolved_from)) |from_ns| {
757 else if (networkShare(resolved_to)) |to_ns|
758 if (networkShare(resolved_from)) |from_ns|
760759 !networkShareServersEql(to_ns, from_ns)
761 } else {
760 else
762761 true
763 }
764 } else {
765 unreachable
766 };
762 else
763 unreachable;
764
767765 if (result_is_to) {
768766 clean_up_resolved_to = false;
769767 return resolved_to;
......@@ -964,14 +962,16 @@ pub fn real(allocator: &Allocator, pathname: []const u8) -> %[]u8 {
964962
965963 // windows returns \\?\ prepended to the path
966964 // we strip it because nobody wants \\?\ prepended to their path
967 const final_len = if (result > 4 and mem.startsWith(u8, buf, "\\\\?\\")) {
968 var i: usize = 4;
969 while (i < result) : (i += 1) {
970 buf[i - 4] = buf[i];
965 const final_len = x: {
966 if (result > 4 and mem.startsWith(u8, buf, "\\\\?\\")) {
967 var i: usize = 4;
968 while (i < result) : (i += 1) {
969 buf[i - 4] = buf[i];
970 }
971 break :x result - 4;
972 } else {
973 break :x result;
971974 }
972 result - 4
973 } else {
974 result
975975 };
976976
977977 return allocator.shrink(u8, buf, final_len);
std/os/windows/util.zig+2-2
......@@ -122,7 +122,7 @@ pub fn windowsOpen(file_path: []const u8, desired_access: windows.DWORD, share_m
122122/// Caller must free result.
123123pub fn createWindowsEnvBlock(allocator: &mem.Allocator, env_map: &const BufMap) -> %[]u8 {
124124 // count bytes needed
125 const bytes_needed = {
125 const bytes_needed = x: {
126126 var bytes_needed: usize = 1; // 1 for the final null byte
127127 var it = env_map.iterator();
128128 while (it.next()) |pair| {
......@@ -130,7 +130,7 @@ pub fn createWindowsEnvBlock(allocator: &mem.Allocator, env_map: &const BufMap)
130130 // +1 for null byte
131131 bytes_needed += pair.key.len + pair.value.len + 2;
132132 }
133 bytes_needed
133 break :x bytes_needed;
134134 };
135135 const result = %return allocator.alloc(u8, bytes_needed);
136136 %defer allocator.free(result);
std/rand.zig+14-14
......@@ -28,9 +28,9 @@ pub const Rand = struct {
2828
2929 /// Initialize random state with the given seed.
3030 pub fn init(seed: usize) -> Rand {
31 Rand {
31 return Rand {
3232 .rng = Rng.init(seed),
33 }
33 };
3434 }
3535
3636 /// Get an integer or boolean with random bits.
......@@ -78,13 +78,13 @@ pub const Rand = struct {
7878 const end_uint = uint(end);
7979 const total_range = math.absCast(start) + end_uint;
8080 const value = r.range(uint, 0, total_range);
81 const result = if (value < end_uint) {
82 T(value)
83 } else if (value == end_uint) {
84 start
85 } else {
81 const result = if (value < end_uint) x: {
82 break :x T(value);
83 } else if (value == end_uint) x: {
84 break :x start;
85 } else x: {
8686 // Can't overflow because the range is over signed ints
87 %%math.negateCast(value - end_uint)
87 break :x %%math.negateCast(value - end_uint);
8888 };
8989 return result;
9090 } else {
......@@ -114,13 +114,13 @@ pub const Rand = struct {
114114 // const rand_bits = r.rng.scalar(int) & mask;
115115 // return @float_compose(T, false, 0, rand_bits) - 1.0
116116 const int_type = @IntType(false, @sizeOf(T) * 8);
117 const precision = if (T == f32) {
117 const precision = if (T == f32)
118118 16777216
119 } else if (T == f64) {
119 else if (T == f64)
120120 9007199254740992
121 } else {
121 else
122122 @compileError("unknown floating point type")
123 };
123 ;
124124 return T(r.range(int_type, 0, precision)) / T(precision);
125125 }
126126};
......@@ -133,7 +133,7 @@ fn MersenneTwister(
133133 comptime t: math.Log2Int(int), comptime c: int,
134134 comptime l: math.Log2Int(int), comptime f: int) -> type
135135{
136 struct {
136 return struct {
137137 const Self = this;
138138
139139 array: [n]int,
......@@ -189,7 +189,7 @@ fn MersenneTwister(
189189
190190 return x;
191191 }
192 }
192 };
193193}
194194
195195test "rand float 32" {
std/sort.zig+4-4
......@@ -355,7 +355,7 @@ pub fn sort(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &cons
355355 // these values will be pulled out to the start of A
356356 last = A.start;
357357 count = 1;
358 while (count < find) : ({last = index; count += 1}) {
358 while (count < find) : ({last = index; count += 1;}) {
359359 index = findLastForward(T, items, items[last], Range.init(last + 1, A.end), lessThan, find - count);
360360 if (index == A.end) break;
361361 }
......@@ -410,7 +410,7 @@ pub fn sort(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &cons
410410 // these values will be pulled out to the end of B
411411 last = B.end - 1;
412412 count = 1;
413 while (count < find) : ({last = index - 1; count += 1}) {
413 while (count < find) : ({last = index - 1; count += 1;}) {
414414 index = findFirstBackward(T, items, items[last], Range.init(B.start, last), lessThan, find - count);
415415 if (index == B.start) break;
416416 }
......@@ -547,7 +547,7 @@ pub fn sort(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &cons
547547 // swap the first value of each A block with the value in buffer1
548548 var indexA = buffer1.start;
549549 index = firstA.end;
550 while (index < blockA.end) : ({indexA += 1; index += block_size}) {
550 while (index < blockA.end) : ({indexA += 1; index += block_size;}) {
551551 mem.swap(T, &items[indexA], &items[index]);
552552 }
553553
......@@ -1093,7 +1093,7 @@ test "another sort case" {
10931093 var arr = []i32{ 5, 3, 1, 2, 4 };
10941094 sort(i32, arr[0..], i32asc);
10951095
1096 assert(mem.eql(i32, arr, []i32{ 1, 2, 3, 4, 5 }))
1096 assert(mem.eql(i32, arr, []i32{ 1, 2, 3, 4, 5 }));
10971097}
10981098
10991099test "sort fuzz testing" {
std/special/build_runner.zig+6-10
......@@ -45,21 +45,17 @@ pub fn main() -> %void {
4545
4646 var stderr_file = io.getStdErr();
4747 var stderr_file_stream: io.FileOutStream = undefined;
48 var stderr_stream: %&io.OutStream = if (stderr_file) |*f| {
48 var stderr_stream: %&io.OutStream = if (stderr_file) |*f| x: {
4949 stderr_file_stream = io.FileOutStream.init(f);
50 &stderr_file_stream.stream
51 } else |err| {
52 err
53 };
50 break :x &stderr_file_stream.stream;
51 } else |err| err;
5452
5553 var stdout_file = io.getStdOut();
5654 var stdout_file_stream: io.FileOutStream = undefined;
57 var stdout_stream: %&io.OutStream = if (stdout_file) |*f| {
55 var stdout_stream: %&io.OutStream = if (stdout_file) |*f| x: {
5856 stdout_file_stream = io.FileOutStream.init(f);
59 &stdout_file_stream.stream
60 } else |err| {
61 err
62 };
57 break :x &stdout_file_stream.stream;
58 } else |err| err;
6359
6460 while (arg_it.next(allocator)) |err_or_arg| {
6561 const arg = %return unwrapArg(err_or_arg);
std/special/builtin.zig+9-9
......@@ -46,15 +46,15 @@ extern fn __stack_chk_fail() -> noreturn {
4646
4747const math = @import("../math/index.zig");
4848
49export fn fmodf(x: f32, y: f32) -> f32 { generic_fmod(f32, x, y) }
50export fn fmod(x: f64, y: f64) -> f64 { generic_fmod(f64, x, y) }
49export fn fmodf(x: f32, y: f32) -> f32 { return generic_fmod(f32, x, y); }
50export fn fmod(x: f64, y: f64) -> f64 { return generic_fmod(f64, x, y); }
5151
5252// TODO add intrinsics for these (and probably the double version too)
5353// and have the math stuff use the intrinsic. same as @mod and @rem
54export fn floorf(x: f32) -> f32 { math.floor(x) }
55export fn ceilf(x: f32) -> f32 { math.ceil(x) }
56export fn floor(x: f64) -> f64 { math.floor(x) }
57export fn ceil(x: f64) -> f64 { math.ceil(x) }
54export fn floorf(x: f32) -> f32 { return math.floor(x); }
55export fn ceilf(x: f32) -> f32 { return math.ceil(x); }
56export fn floor(x: f64) -> f64 { return math.floor(x); }
57export fn ceil(x: f64) -> f64 { return math.ceil(x); }
5858
5959fn generic_fmod(comptime T: type, x: T, y: T) -> T {
6060 @setDebugSafety(this, false);
......@@ -84,7 +84,7 @@ fn generic_fmod(comptime T: type, x: T, y: T) -> T {
8484 // normalize x and y
8585 if (ex == 0) {
8686 i = ux << exp_bits;
87 while (i >> bits_minus_1 == 0) : ({ex -= 1; i <<= 1}) {}
87 while (i >> bits_minus_1 == 0) : (b: {ex -= 1; break :b i <<= 1;}) {}
8888 ux <<= log2uint(@bitCast(u32, -ex + 1));
8989 } else {
9090 ux &= @maxValue(uint) >> exp_bits;
......@@ -92,7 +92,7 @@ fn generic_fmod(comptime T: type, x: T, y: T) -> T {
9292 }
9393 if (ey == 0) {
9494 i = uy << exp_bits;
95 while (i >> bits_minus_1 == 0) : ({ey -= 1; i <<= 1}) {}
95 while (i >> bits_minus_1 == 0) : (b: {ey -= 1; break :b i <<= 1;}) {}
9696 uy <<= log2uint(@bitCast(u32, -ey + 1));
9797 } else {
9898 uy &= @maxValue(uint) >> exp_bits;
......@@ -115,7 +115,7 @@ fn generic_fmod(comptime T: type, x: T, y: T) -> T {
115115 return 0 * x;
116116 ux = i;
117117 }
118 while (ux >> digits == 0) : ({ux <<= 1; ex -= 1}) {}
118 while (ux >> digits == 0) : (b: {ux <<= 1; break :b ex -= 1;}) {}
119119
120120 // scale result up
121121 if (ex > 0) {
std/special/compiler_rt/comparetf2.zig+18-22
......@@ -38,27 +38,25 @@ pub extern fn __letf2(a: f128, b: f128) -> c_int {
3838
3939 // If at least one of a and b is positive, we get the same result comparing
4040 // a and b as signed integers as we would with a floating-point compare.
41 return if ((aInt & bInt) >= 0) {
42 if (aInt < bInt) {
41 return if ((aInt & bInt) >= 0)
42 if (aInt < bInt)
4343 LE_LESS
44 } else if (aInt == bInt) {
44 else if (aInt == bInt)
4545 LE_EQUAL
46 } else {
46 else
4747 LE_GREATER
48 }
49 } else {
48 else
5049 // Otherwise, both are negative, so we need to flip the sense of the
5150 // comparison to get the correct result. (This assumes a twos- or ones-
5251 // complement integer representation; if integers are represented in a
5352 // sign-magnitude representation, then this flip is incorrect).
54 if (aInt > bInt) {
53 if (aInt > bInt)
5554 LE_LESS
56 } else if (aInt == bInt) {
55 else if (aInt == bInt)
5756 LE_EQUAL
58 } else {
57 else
5958 LE_GREATER
60 }
61 };
59 ;
6260}
6361
6462// TODO https://github.com/zig-lang/zig/issues/305
......@@ -78,23 +76,21 @@ pub extern fn __getf2(a: f128, b: f128) -> c_int {
7876
7977 if (aAbs > infRep or bAbs > infRep) return GE_UNORDERED;
8078 if ((aAbs | bAbs) == 0) return GE_EQUAL;
81 return if ((aInt & bInt) >= 0) {
82 if (aInt < bInt) {
79 return if ((aInt & bInt) >= 0)
80 if (aInt < bInt)
8381 GE_LESS
84 } else if (aInt == bInt) {
82 else if (aInt == bInt)
8583 GE_EQUAL
86 } else {
84 else
8785 GE_GREATER
88 }
89 } else {
90 if (aInt > bInt) {
86 else
87 if (aInt > bInt)
9188 GE_LESS
92 } else if (aInt == bInt) {
89 else if (aInt == bInt)
9390 GE_EQUAL
94 } else {
91 else
9592 GE_GREATER
96 }
97 };
93 ;
9894}
9995
10096pub extern fn __unordtf2(a: f128, b: f128) -> c_int {
test/cases/align.zig+9-9
......@@ -10,7 +10,7 @@ test "global variable alignment" {
1010 assert(@typeOf(slice) == []align(4) u8);
1111}
1212
13fn derp() align(@sizeOf(usize) * 2) -> i32 { 1234 }
13fn derp() align(@sizeOf(usize) * 2) -> i32 { return 1234; }
1414fn noop1() align(1) {}
1515fn noop4() align(4) {}
1616
......@@ -53,14 +53,14 @@ test "implicitly decreasing pointer alignment" {
5353 assert(addUnaligned(&a, &b) == 7);
5454}
5555
56fn addUnaligned(a: &align(1) const u32, b: &align(1) const u32) -> u32 { *a + *b }
56fn addUnaligned(a: &align(1) const u32, b: &align(1) const u32) -> u32 { return *a + *b; }
5757
5858test "implicitly decreasing slice alignment" {
5959 const a: u32 align(4) = 3;
6060 const b: u32 align(8) = 4;
6161 assert(addUnalignedSlice((&a)[0..1], (&b)[0..1]) == 7);
6262}
63fn addUnalignedSlice(a: []align(1) const u32, b: []align(1) const u32) -> u32 { a[0] + b[0] }
63fn addUnalignedSlice(a: []align(1) const u32, b: []align(1) const u32) -> u32 { return a[0] + b[0]; }
6464
6565test "specifying alignment allows pointer cast" {
6666 testBytesAlign(0x33);
......@@ -115,20 +115,20 @@ fn testImplicitlyDecreaseFnAlign(ptr: fn () align(1) -> i32, answer: i32) {
115115 assert(ptr() == answer);
116116}
117117
118fn alignedSmall() align(8) -> i32 { 1234 }
119fn alignedBig() align(16) -> i32 { 5678 }
118fn alignedSmall() align(8) -> i32 { return 1234; }
119fn alignedBig() align(16) -> i32 { return 5678; }
120120
121121
122122test "@alignCast functions" {
123123 assert(fnExpectsOnly1(simple4) == 0x19);
124124}
125125fn fnExpectsOnly1(ptr: fn()align(1) -> i32) -> i32 {
126 fnExpects4(@alignCast(4, ptr))
126 return fnExpects4(@alignCast(4, ptr));
127127}
128128fn fnExpects4(ptr: fn()align(4) -> i32) -> i32 {
129 ptr()
129 return ptr();
130130}
131fn simple4() align(4) -> i32 { 0x19 }
131fn simple4() align(4) -> i32 { return 0x19; }
132132
133133
134134test "generic function with align param" {
......@@ -137,7 +137,7 @@ test "generic function with align param" {
137137 assert(whyWouldYouEverDoThis(8) == 0x1);
138138}
139139
140fn whyWouldYouEverDoThis(comptime align_bytes: u8) align(align_bytes) -> u8 { 0x1 }
140fn whyWouldYouEverDoThis(comptime align_bytes: u8) align(align_bytes) -> u8 { return 0x1; }
141141
142142
143143test "@ptrCast preserves alignment of bigger source" {
test/cases/array.zig+2-2
......@@ -22,7 +22,7 @@ test "arrays" {
2222 assert(getArrayLen(array) == 5);
2323}
2424fn getArrayLen(a: []const u32) -> usize {
25 a.len
25 return a.len;
2626}
2727
2828test "void arrays" {
......@@ -41,7 +41,7 @@ test "array literal" {
4141}
4242
4343test "array dot len const expr" {
44 assert(comptime {some_array.len == 4});
44 assert(comptime x: {break :x some_array.len == 4;});
4545}
4646
4747const ArrayDotLenConstExpr = struct {
test/cases/bitcast.zig+2-2
......@@ -10,5 +10,5 @@ fn testBitCast_i32_u32() {
1010 assert(conv2(@maxValue(u32)) == -1);
1111}
1212
13fn conv(x: i32) -> u32 { @bitCast(u32, x) }
14fn conv2(x: u32) -> i32 { @bitCast(i32, x) }
13fn conv(x: i32) -> u32 { return @bitCast(u32, x); }
14fn conv2(x: u32) -> i32 { return @bitCast(i32, x); }
test/cases/bool.zig+1-1
......@@ -22,7 +22,7 @@ test "bool cmp" {
2222 assert(testBoolCmp(true, false) == false);
2323}
2424fn testBoolCmp(a: bool, b: bool) -> bool {
25 a == b
25 return a == b;
2626}
2727
2828const global_f = false;
test/cases/cast.zig+7-7
......@@ -50,7 +50,7 @@ test "peer resolve arrays of different size to const slice" {
5050 comptime assert(mem.eql(u8, boolToStr(false), "false"));
5151}
5252fn boolToStr(b: bool) -> []const u8 {
53 if (b) "true" else "false"
53 return if (b) "true" else "false";
5454}
5555
5656
......@@ -239,17 +239,17 @@ test "peer type resolution: error and [N]T" {
239239
240240error BadValue;
241241fn testPeerErrorAndArray(x: u8) -> %[]const u8 {
242 switch (x) {
242 return switch (x) {
243243 0x00 => "OK",
244244 else => error.BadValue,
245 }
245 };
246246}
247247fn testPeerErrorAndArray2(x: u8) -> %[]const u8 {
248 switch (x) {
248 return switch (x) {
249249 0x00 => "OK",
250250 0x01 => "OKK",
251251 else => error.BadValue,
252 }
252 };
253253}
254254
255255test "explicit cast float number literal to integer if no fraction component" {
......@@ -269,11 +269,11 @@ fn testCast128() {
269269}
270270
271271fn cast128Int(x: f128) -> u128 {
272 @bitCast(u128, x)
272 return @bitCast(u128, x);
273273}
274274
275275fn cast128Float(x: u128) -> f128 {
276 @bitCast(f128, x)
276 return @bitCast(f128, x);
277277}
278278
279279test "const slice widen cast" {
test/cases/defer.zig+6-6
......@@ -7,9 +7,9 @@ error FalseNotAllowed;
77
88fn runSomeErrorDefers(x: bool) -> %bool {
99 index = 0;
10 defer {result[index] = 'a'; index += 1;};
11 %defer {result[index] = 'b'; index += 1;};
12 defer {result[index] = 'c'; index += 1;};
10 defer {result[index] = 'a'; index += 1;}
11 %defer {result[index] = 'b'; index += 1;}
12 defer {result[index] = 'c'; index += 1;}
1313 return if (x) x else error.FalseNotAllowed;
1414}
1515
......@@ -18,9 +18,9 @@ test "mixing normal and error defers" {
1818 assert(result[0] == 'c');
1919 assert(result[1] == 'a');
2020
21 const ok = runSomeErrorDefers(false) %% |err| {
21 const ok = runSomeErrorDefers(false) %% |err| x: {
2222 assert(err == error.FalseNotAllowed);
23 true
23 break :x true;
2424 };
2525 assert(ok);
2626 assert(result[0] == 'c');
......@@ -41,5 +41,5 @@ fn testBreakContInDefer(x: usize) {
4141 if (i == 5) break;
4242 }
4343 assert(i == 5);
44 };
44 }
4545}
test/cases/enum.zig+1-1
......@@ -41,7 +41,7 @@ const Bar = enum {
4141};
4242
4343fn returnAnInt(x: i32) -> Foo {
44 Foo { .One = x }
44 return Foo { .One = x };
4545}
4646
4747
test/cases/enum_with_members.zig+3-3
......@@ -8,9 +8,9 @@ const ET = union(enum) {
88
99 pub fn print(a: &const ET, buf: []u8) -> %usize {
1010 return switch (*a) {
11 ET.SINT => |x| { fmt.formatIntBuf(buf, x, 10, false, 0) },
12 ET.UINT => |x| { fmt.formatIntBuf(buf, x, 10, false, 0) },
13 }
11 ET.SINT => |x| fmt.formatIntBuf(buf, x, 10, false, 0),
12 ET.UINT => |x| fmt.formatIntBuf(buf, x, 10, false, 0),
13 };
1414 }
1515};
1616
test/cases/error.zig+5-9
......@@ -3,7 +3,7 @@ const mem = @import("std").mem;
33
44pub fn foo() -> %i32 {
55 const x = %return bar();
6 return x + 1
6 return x + 1;
77}
88
99pub fn bar() -> %i32 {
......@@ -21,7 +21,7 @@ test "error wrapping" {
2121
2222error ItBroke;
2323fn gimmeItBroke() -> []const u8 {
24 @errorName(error.ItBroke)
24 return @errorName(error.ItBroke);
2525}
2626
2727test "@errorName" {
......@@ -48,7 +48,7 @@ error AnError;
4848error AnError;
4949error SecondError;
5050fn shouldBeNotEqual(a: error, b: error) {
51 if (a == b) unreachable
51 if (a == b) unreachable;
5252}
5353
5454
......@@ -60,11 +60,7 @@ test "error binary operator" {
6060}
6161error ItBroke;
6262fn errBinaryOperatorG(x: bool) -> %isize {
63 if (x) {
64 error.ItBroke
65 } else {
66 isize(10)
67 }
63 return if (x) error.ItBroke else isize(10);
6864}
6965
7066
......@@ -72,7 +68,7 @@ test "unwrap simple value from error" {
7268 const i = %%unwrapSimpleValueFromErrorDo();
7369 assert(i == 13);
7470}
75fn unwrapSimpleValueFromErrorDo() -> %isize { 13 }
71fn unwrapSimpleValueFromErrorDo() -> %isize { return 13; }
7672
7773
7874test "error return in assignment" {
test/cases/eval.zig+13-13
......@@ -44,7 +44,7 @@ test "static function evaluation" {
4444 assert(statically_added_number == 3);
4545}
4646const statically_added_number = staticAdd(1, 2);
47fn staticAdd(a: i32, b: i32) -> i32 { a + b }
47fn staticAdd(a: i32, b: i32) -> i32 { return a + b; }
4848
4949
5050test "const expr eval on single expr blocks" {
......@@ -54,10 +54,10 @@ test "const expr eval on single expr blocks" {
5454fn constExprEvalOnSingleExprBlocksFn(x: i32, b: bool) -> i32 {
5555 const literal = 3;
5656
57 const result = if (b) {
58 literal
59 } else {
60 x
57 const result = if (b) b: {
58 break :b literal;
59 } else b: {
60 break :b x;
6161 };
6262
6363 return result;
......@@ -94,9 +94,9 @@ pub const Vec3 = struct {
9494 data: [3]f32,
9595};
9696pub fn vec3(x: f32, y: f32, z: f32) -> Vec3 {
97 Vec3 {
97 return Vec3 {
9898 .data = []f32 { x, y, z, },
99 }
99 };
100100}
101101
102102
......@@ -176,7 +176,7 @@ fn max(comptime T: type, a: T, b: T) -> T {
176176 }
177177}
178178fn letsTryToCompareBools(a: bool, b: bool) -> bool {
179 max(bool, a, b)
179 return max(bool, a, b);
180180}
181181test "inlined block and runtime block phi" {
182182 assert(letsTryToCompareBools(true, true));
......@@ -202,9 +202,9 @@ const cmd_fns = []CmdFn{
202202 CmdFn {.name = "two", .func = two},
203203 CmdFn {.name = "three", .func = three},
204204};
205fn one(value: i32) -> i32 { value + 1 }
206fn two(value: i32) -> i32 { value + 2 }
207fn three(value: i32) -> i32 { value + 3 }
205fn one(value: i32) -> i32 { return value + 1; }
206fn two(value: i32) -> i32 { return value + 2; }
207fn three(value: i32) -> i32 { return value + 3; }
208208
209209fn performFn(comptime prefix_char: u8, start_value: i32) -> i32 {
210210 var result: i32 = start_value;
......@@ -317,12 +317,12 @@ test "create global array with for loop" {
317317 assert(global_array[9] == 9 * 9);
318318}
319319
320const global_array = {
320const global_array = x: {
321321 var result: [10]usize = undefined;
322322 for (result) |*item, index| {
323323 *item = index * index;
324324 }
325 result
325 break :x result;
326326};
327327
328328test "compile-time downcast when the bits fit" {
test/cases/fn.zig+10-10
......@@ -4,7 +4,7 @@ test "params" {
44 assert(testParamsAdd(22, 11) == 33);
55}
66fn testParamsAdd(a: i32, b: i32) -> i32 {
7 a + b
7 return a + b;
88}
99
1010
......@@ -22,7 +22,7 @@ test "void parameters" {
2222}
2323fn voidFun(a: i32, b: void, c: i32, d: void) {
2424 const v = b;
25 const vv: void = if (a == 1) {v} else {};
25 const vv: void = if (a == 1) v else {};
2626 assert(a + c == 3);
2727 return vv;
2828}
......@@ -45,9 +45,9 @@ test "separate block scopes" {
4545 assert(no_conflict == 5);
4646 }
4747
48 const c = {
48 const c = x: {
4949 const no_conflict = i32(10);
50 no_conflict
50 break :x no_conflict;
5151 };
5252 assert(c == 10);
5353}
......@@ -73,7 +73,7 @@ test "implicit cast function unreachable return" {
7373fn wantsFnWithVoid(f: fn()) { }
7474
7575fn fnWithUnreachable() -> noreturn {
76 unreachable
76 unreachable;
7777}
7878
7979
......@@ -83,14 +83,14 @@ test "function pointers" {
8383 assert(f() == u32(i) + 5);
8484 }
8585}
86fn fn1() -> u32 {5}
87fn fn2() -> u32 {6}
88fn fn3() -> u32 {7}
89fn fn4() -> u32 {8}
86fn fn1() -> u32 {return 5;}
87fn fn2() -> u32 {return 6;}
88fn fn3() -> u32 {return 7;}
89fn fn4() -> u32 {return 8;}
9090
9191
9292test "inline function call" {
9393 assert(@inlineCall(add, 3, 9) == 12);
9494}
9595
96fn add(a: i32, b: i32) -> i32 { a + b }
96fn add(a: i32, b: i32) -> i32 { return a + b; }
test/cases/for.zig+1-1
......@@ -12,7 +12,7 @@ test "continue in for loop" {
1212 }
1313 break;
1414 }
15 if (sum != 6) unreachable
15 if (sum != 6) unreachable;
1616}
1717
1818test "for loop with pointer elem var" {
test/cases/generics.zig+19-19
......@@ -11,7 +11,7 @@ fn max(comptime T: type, a: T, b: T) -> T {
1111}
1212
1313fn add(comptime a: i32, b: i32) -> i32 {
14 return (comptime {a}) + b;
14 return (comptime a) + b;
1515}
1616
1717const the_max = max(u32, 1234, 5678);
......@@ -20,15 +20,15 @@ test "compile time generic eval" {
2020}
2121
2222fn gimmeTheBigOne(a: u32, b: u32) -> u32 {
23 max(u32, a, b)
23 return max(u32, a, b);
2424}
2525
2626fn shouldCallSameInstance(a: u32, b: u32) -> u32 {
27 max(u32, a, b)
27 return max(u32, a, b);
2828}
2929
3030fn sameButWithFloats(a: f64, b: f64) -> f64 {
31 max(f64, a, b)
31 return max(f64, a, b);
3232}
3333
3434test "fn with comptime args" {
......@@ -49,28 +49,28 @@ comptime {
4949}
5050
5151fn max_var(a: var, b: var) -> @typeOf(a + b) {
52 if (a > b) a else b
52 return if (a > b) a else b;
5353}
5454
5555fn max_i32(a: i32, b: i32) -> i32 {
56 max_var(a, b)
56 return max_var(a, b);
5757}
5858
5959fn max_f64(a: f64, b: f64) -> f64 {
60 max_var(a, b)
60 return max_var(a, b);
6161}
6262
6363
6464pub fn List(comptime T: type) -> type {
65 SmallList(T, 8)
65 return SmallList(T, 8);
6666}
6767
6868pub fn SmallList(comptime T: type, comptime STATIC_SIZE: usize) -> type {
69 struct {
69 return struct {
7070 items: []T,
7171 length: usize,
7272 prealloc_items: [STATIC_SIZE]T,
73 }
73 };
7474}
7575
7676test "function with return type type" {
......@@ -91,20 +91,20 @@ test "generic struct" {
9191 assert(b1.getVal());
9292}
9393fn GenNode(comptime T: type) -> type {
94 struct {
94 return struct {
9595 value: T,
9696 next: ?&GenNode(T),
97 fn getVal(n: &const GenNode(T)) -> T { n.value }
98 }
97 fn getVal(n: &const GenNode(T)) -> T { return n.value; }
98 };
9999}
100100
101101test "const decls in struct" {
102102 assert(GenericDataThing(3).count_plus_one == 4);
103103}
104104fn GenericDataThing(comptime count: isize) -> type {
105 struct {
105 return struct {
106106 const count_plus_one = count + 1;
107 }
107 };
108108}
109109
110110
......@@ -120,16 +120,16 @@ test "generic fn with implicit cast" {
120120 assert(getFirstByte(u8, []u8 {13}) == 13);
121121 assert(getFirstByte(u16, []u16 {0, 13}) == 0);
122122}
123fn getByte(ptr: ?&const u8) -> u8 {*??ptr}
123fn getByte(ptr: ?&const u8) -> u8 {return *??ptr;}
124124fn getFirstByte(comptime T: type, mem: []const T) -> u8 {
125 getByte(@ptrCast(&const u8, &mem[0]))
125 return getByte(@ptrCast(&const u8, &mem[0]));
126126}
127127
128128
129129const foos = []fn(var) -> bool { foo1, foo2 };
130130
131fn foo1(arg: var) -> bool { arg }
132fn foo2(arg: var) -> bool { !arg }
131fn foo1(arg: var) -> bool { return arg; }
132fn foo2(arg: var) -> bool { return !arg; }
133133
134134test "array of generic fns" {
135135 assert(foos[0](true));
test/cases/if.zig+3-3
......@@ -29,10 +29,10 @@ test "else if expression" {
2929}
3030fn elseIfExpressionF(c: u8) -> u8 {
3131 if (c == 0) {
32 0
32 return 0;
3333 } else if (c == 1) {
34 1
34 return 1;
3535 } else {
36 u8(2)
36 return u8(2);
3737 }
3838}
test/cases/import/a_namespace.zig+1-1
......@@ -1 +1 @@
1pub fn foo() -> i32 { 1234 }
1pub fn foo() -> i32 { return 1234; }
test/cases/ir_block_deps.zig+2-2
......@@ -8,10 +8,10 @@ fn foo(id: u64) -> %i32 {
88 return %return getErrInt();
99 },
1010 else => error.ItBroke,
11 }
11 };
1212}
1313
14fn getErrInt() -> %i32 { 0 }
14fn getErrInt() -> %i32 { return 0; }
1515
1616error ItBroke;
1717
test/cases/math.zig+11-11
......@@ -28,16 +28,16 @@ fn testDivision() {
2828 assert(divTrunc(f32, -5.0, 3.0) == -1.0);
2929}
3030fn div(comptime T: type, a: T, b: T) -> T {
31 a / b
31 return a / b;
3232}
3333fn divExact(comptime T: type, a: T, b: T) -> T {
34 @divExact(a, b)
34 return @divExact(a, b);
3535}
3636fn divFloor(comptime T: type, a: T, b: T) -> T {
37 @divFloor(a, b)
37 return @divFloor(a, b);
3838}
3939fn divTrunc(comptime T: type, a: T, b: T) -> T {
40 @divTrunc(a, b)
40 return @divTrunc(a, b);
4141}
4242
4343test "@addWithOverflow" {
......@@ -71,7 +71,7 @@ fn testClz() {
7171}
7272
7373fn clz(x: var) -> usize {
74 @clz(x)
74 return @clz(x);
7575}
7676
7777test "@ctz" {
......@@ -86,7 +86,7 @@ fn testCtz() {
8686}
8787
8888fn ctz(x: var) -> usize {
89 @ctz(x)
89 return @ctz(x);
9090}
9191
9292test "assignment operators" {
......@@ -180,10 +180,10 @@ fn test_u64_div() {
180180 assert(result.remainder == 100663296);
181181}
182182fn divWithResult(a: u64, b: u64) -> DivResult {
183 DivResult {
183 return DivResult {
184184 .quotient = a / b,
185185 .remainder = a % b,
186 }
186 };
187187}
188188const DivResult = struct {
189189 quotient: u64,
......@@ -191,8 +191,8 @@ const DivResult = struct {
191191};
192192
193193test "binary not" {
194 assert(comptime {~u16(0b1010101010101010) == 0b0101010101010101});
195 assert(comptime {~u64(2147483647) == 18446744071562067968});
194 assert(comptime x: {break :x ~u16(0b1010101010101010) == 0b0101010101010101;});
195 assert(comptime x: {break :x ~u64(2147483647) == 18446744071562067968;});
196196 testBinaryNot(0b1010101010101010);
197197}
198198
......@@ -331,7 +331,7 @@ test "f128" {
331331 comptime test_f128();
332332}
333333
334fn make_f128(x: f128) -> f128 { x }
334fn make_f128(x: f128) -> f128 { return x; }
335335
336336fn test_f128() {
337337 assert(@sizeOf(f128) == 16);
test/cases/misc.zig+15-15
......@@ -110,17 +110,17 @@ fn testShortCircuit(f: bool, t: bool) {
110110 var hit_3 = f;
111111 var hit_4 = f;
112112
113 if (t or {assert(f); f}) {
113 if (t or x: {assert(f); break :x f;}) {
114114 hit_1 = t;
115115 }
116 if (f or { hit_2 = t; f }) {
116 if (f or x: { hit_2 = t; break :x f; }) {
117117 assert(f);
118118 }
119119
120 if (t and { hit_3 = t; f }) {
120 if (t and x: { hit_3 = t; break :x f; }) {
121121 assert(f);
122122 }
123 if (f and {assert(f); f}) {
123 if (f and x: {assert(f); break :x f;}) {
124124 assert(f);
125125 } else {
126126 hit_4 = t;
......@@ -135,11 +135,11 @@ test "truncate" {
135135 assert(testTruncate(0x10fd) == 0xfd);
136136}
137137fn testTruncate(x: u32) -> u8 {
138 @truncate(u8, x)
138 return @truncate(u8, x);
139139}
140140
141141fn first4KeysOfHomeRow() -> []const u8 {
142 "aoeu"
142 return "aoeu";
143143}
144144
145145test "return string from function" {
......@@ -167,7 +167,7 @@ test "memcpy and memset intrinsics" {
167167}
168168
169169test "builtin static eval" {
170 const x : i32 = comptime {1 + 2 + 3};
170 const x : i32 = comptime x: {break :x 1 + 2 + 3;};
171171 assert(x == comptime 6);
172172}
173173
......@@ -190,7 +190,7 @@ test "slicing" {
190190
191191test "constant equal function pointers" {
192192 const alias = emptyFn;
193 assert(comptime {emptyFn == alias});
193 assert(comptime x: {break :x emptyFn == alias;});
194194}
195195
196196fn emptyFn() {}
......@@ -280,14 +280,14 @@ test "cast small unsigned to larger signed" {
280280 assert(castSmallUnsignedToLargerSigned1(200) == i16(200));
281281 assert(castSmallUnsignedToLargerSigned2(9999) == i64(9999));
282282}
283fn castSmallUnsignedToLargerSigned1(x: u8) -> i16 { x }
284fn castSmallUnsignedToLargerSigned2(x: u16) -> i64 { x }
283fn castSmallUnsignedToLargerSigned1(x: u8) -> i16 { return x; }
284fn castSmallUnsignedToLargerSigned2(x: u16) -> i64 { return x; }
285285
286286
287287test "implicit cast after unreachable" {
288288 assert(outer() == 1234);
289289}
290fn inner() -> i32 { 1234 }
290fn inner() -> i32 { return 1234; }
291291fn outer() -> i64 {
292292 return inner();
293293}
......@@ -310,8 +310,8 @@ test "call result of if else expression" {
310310fn f2(x: bool) -> []const u8 {
311311 return (if (x) fA else fB)();
312312}
313fn fA() -> []const u8 { "a" }
314fn fB() -> []const u8 { "b" }
313fn fA() -> []const u8 { return "a"; }
314fn fB() -> []const u8 { return "b"; }
315315
316316
317317test "const expression eval handling of variables" {
......@@ -379,7 +379,7 @@ test "pointer comparison" {
379379 assert(ptrEql(b, b));
380380}
381381fn ptrEql(a: &const []const u8, b: &const []const u8) -> bool {
382 a == b
382 return a == b;
383383}
384384
385385
......@@ -483,7 +483,7 @@ test "@typeId" {
483483 assert(@typeId(AUnion) == Tid.Union);
484484 assert(@typeId(fn()) == Tid.Fn);
485485 assert(@typeId(@typeOf(builtin)) == Tid.Namespace);
486 assert(@typeId(@typeOf({this})) == Tid.Block);
486 assert(@typeId(@typeOf(x: {break :x this;})) == Tid.Block);
487487 // TODO bound fn
488488 // TODO arg tuple
489489 // TODO opaque
test/cases/reflection.zig+1-1
......@@ -22,7 +22,7 @@ test "reflection: function return type, var args, and param types" {
2222 }
2323}
2424
25fn dummy(a: bool, b: i32, c: f32) -> i32 { 1234 }
25fn dummy(a: bool, b: i32, c: f32) -> i32 { return 1234; }
2626fn dummy_varargs(args: ...) {}
2727
2828test "reflection: struct member types and names" {
test/cases/struct.zig+9-9
......@@ -2,7 +2,7 @@ const assert = @import("std").debug.assert;
22const builtin = @import("builtin");
33
44const StructWithNoFields = struct {
5 fn add(a: i32, b: i32) -> i32 { a + b }
5 fn add(a: i32, b: i32) -> i32 { return a + b; }
66};
77const empty_global_instance = StructWithNoFields {};
88
......@@ -109,7 +109,7 @@ const Foo = struct {
109109 ptr: fn() -> i32,
110110};
111111
112fn aFunc() -> i32 { 13 }
112fn aFunc() -> i32 { return 13; }
113113
114114fn callStructField(foo: &const Foo) -> i32 {
115115 return foo.ptr();
......@@ -124,7 +124,7 @@ test "store member function in variable" {
124124}
125125const MemberFnTestFoo = struct {
126126 x: i32,
127 fn member(foo: &const MemberFnTestFoo) -> i32 { foo.x }
127 fn member(foo: &const MemberFnTestFoo) -> i32 { return foo.x; }
128128};
129129
130130
......@@ -141,7 +141,7 @@ test "member functions" {
141141const MemberFnRand = struct {
142142 seed: u32,
143143 pub fn getSeed(r: &const MemberFnRand) -> u32 {
144 r.seed
144 return r.seed;
145145 }
146146};
147147
......@@ -154,10 +154,10 @@ const Bar = struct {
154154 y: i32,
155155};
156156fn makeBar(x: i32, y: i32) -> Bar {
157 Bar {
157 return Bar {
158158 .x = x,
159159 .y = y,
160 }
160 };
161161}
162162
163163test "empty struct method call" {
......@@ -166,7 +166,7 @@ test "empty struct method call" {
166166}
167167const EmptyStruct = struct {
168168 fn method(es: &const EmptyStruct) -> i32 {
169 1234
169 return 1234;
170170 }
171171};
172172
......@@ -176,14 +176,14 @@ test "return empty struct from fn" {
176176}
177177const EmptyStruct2 = struct {};
178178fn testReturnEmptyStructFromFn() -> EmptyStruct2 {
179 EmptyStruct2 {}
179 return EmptyStruct2 {};
180180}
181181
182182test "pass slice of empty struct to fn" {
183183 assert(testPassSliceOfEmptyStructToFn([]EmptyStruct2{ EmptyStruct2{} }) == 1);
184184}
185185fn testPassSliceOfEmptyStructToFn(slice: []const EmptyStruct2) -> usize {
186 slice.len
186 return slice.len;
187187}
188188
189189const APackedStruct = packed struct {
test/cases/switch.zig+9-9
......@@ -21,12 +21,12 @@ test "switch with all ranges" {
2121}
2222
2323fn testSwitchWithAllRanges(x: u32, y: u32) -> u32 {
24 switch (x) {
24 return switch (x) {
2525 0 ... 100 => 1,
2626 101 ... 200 => 2,
2727 201 ... 300 => 3,
2828 else => y,
29 }
29 };
3030}
3131
3232test "implicit comptime switch" {
......@@ -132,7 +132,7 @@ test "switch with multiple expressions" {
132132 assert(x == 2);
133133}
134134fn returnsFive() -> i32 {
135 5
135 return 5;
136136}
137137
138138
......@@ -161,10 +161,10 @@ test "switch on type" {
161161}
162162
163163fn trueIfBoolFalseOtherwise(comptime T: type) -> bool {
164 switch (T) {
164 return switch (T) {
165165 bool => true,
166166 else => false,
167 }
167 };
168168}
169169
170170test "switch handles all cases of number" {
......@@ -186,22 +186,22 @@ fn testSwitchHandleAllCases() {
186186}
187187
188188fn testSwitchHandleAllCasesExhaustive(x: u2) -> u2 {
189 switch (x) {
189 return switch (x) {
190190 0 => u2(3),
191191 1 => 2,
192192 2 => 1,
193193 3 => 0,
194 }
194 };
195195}
196196
197197fn testSwitchHandleAllCasesRange(x: u8) -> u8 {
198 switch (x) {
198 return switch (x) {
199199 0 ... 100 => u8(0),
200200 101 ... 200 => 1,
201201 201, 203 => 2,
202202 202 => 4,
203203 204 ... 255 => 3,
204 }
204 };
205205}
206206
207207test "switch all prongs unreachable" {
test/cases/switch_prong_err_enum.zig+1-1
......@@ -18,7 +18,7 @@ fn doThing(form_id: u64) -> %FormValue {
1818 return switch (form_id) {
1919 17 => FormValue { .Address = %return readOnce() },
2020 else => error.InvalidDebugInfo,
21 }
21 };
2222}
2323
2424test "switch prong returns error enum" {
test/cases/switch_prong_implicit_cast.zig+2-2
......@@ -8,11 +8,11 @@ const FormValue = union(enum) {
88error Whatever;
99
1010fn foo(id: u64) -> %FormValue {
11 switch (id) {
11 return switch (id) {
1212 2 => FormValue { .Two = true },
1313 1 => FormValue { .One = {} },
1414 else => return error.Whatever,
15 }
15 };
1616}
1717
1818test "switch prong implicit cast" {
test/cases/this.zig+4-8
......@@ -3,7 +3,7 @@ const assert = @import("std").debug.assert;
33const module = this;
44
55fn Point(comptime T: type) -> type {
6 struct {
6 return struct {
77 const Self = this;
88 x: T,
99 y: T,
......@@ -12,20 +12,16 @@ fn Point(comptime T: type) -> type {
1212 self.x += 1;
1313 self.y += 1;
1414 }
15 }
15 };
1616}
1717
1818fn add(x: i32, y: i32) -> i32 {
19 x + y
19 return x + y;
2020}
2121
2222fn factorial(x: i32) -> i32 {
2323 const selfFn = this;
24 if (x == 0) {
25 1
26 } else {
27 x * selfFn(x - 1)
28 }
24 return if (x == 0) 1 else x * selfFn(x - 1);
2925}
3026
3127test "this refer to module call private fn" {
test/cases/try.zig+5-13
......@@ -7,9 +7,9 @@ test "try on error union" {
77}
88
99fn tryOnErrorUnionImpl() {
10 const x = if (returnsTen()) |val| {
10 const x = if (returnsTen()) |val|
1111 val + 1
12 } else |err| switch (err) {
12 else |err| switch (err) {
1313 error.ItBroke, error.NoMem => 1,
1414 error.CrappedOut => i32(2),
1515 else => unreachable,
......@@ -21,22 +21,14 @@ error ItBroke;
2121error NoMem;
2222error CrappedOut;
2323fn returnsTen() -> %i32 {
24 10
24 return 10;
2525}
2626
2727test "try without vars" {
28 const result1 = if (failIfTrue(true)) {
29 1
30 } else |_| {
31 i32(2)
32 };
28 const result1 = if (failIfTrue(true)) 1 else |_| i32(2);
3329 assert(result1 == 2);
3430
35 const result2 = if (failIfTrue(false)) {
36 1
37 } else |_| {
38 i32(2)
39 };
31 const result2 = if (failIfTrue(false)) 1 else |_| i32(2);
4032 assert(result2 == 1);
4133}
4234
test/cases/var_args.zig+2-2
......@@ -58,8 +58,8 @@ fn extraFn(extra: u32, args: ...) -> usize {
5858
5959const foos = []fn(...) -> bool { foo1, foo2 };
6060
61fn foo1(args: ...) -> bool { true }
62fn foo2(args: ...) -> bool { false }
61fn foo1(args: ...) -> bool { return true; }
62fn foo2(args: ...) -> bool { return false; }
6363
6464test "array of var args functions" {
6565 assert(foos[0]());
test/cases/while.zig+18-30
......@@ -118,73 +118,61 @@ test "while with error union condition" {
118118var numbers_left: i32 = undefined;
119119error OutOfNumbers;
120120fn getNumberOrErr() -> %i32 {
121 return if (numbers_left == 0) {
121 return if (numbers_left == 0)
122122 error.OutOfNumbers
123 } else {
123 else x: {
124124 numbers_left -= 1;
125 numbers_left
125 break :x numbers_left;
126126 };
127127}
128128fn getNumberOrNull() -> ?i32 {
129 return if (numbers_left == 0) {
129 return if (numbers_left == 0)
130130 null
131 } else {
131 else x: {
132132 numbers_left -= 1;
133 numbers_left
133 break :x numbers_left;
134134 };
135135}
136136
137137test "while on nullable with else result follow else prong" {
138138 const result = while (returnNull()) |value| {
139139 break value;
140 } else {
141 i32(2)
142 };
140 } else i32(2);
143141 assert(result == 2);
144142}
145143
146144test "while on nullable with else result follow break prong" {
147145 const result = while (returnMaybe(10)) |value| {
148146 break value;
149 } else {
150 i32(2)
151 };
147 } else i32(2);
152148 assert(result == 10);
153149}
154150
155151test "while on error union with else result follow else prong" {
156152 const result = while (returnError()) |value| {
157153 break value;
158 } else |err| {
159 i32(2)
160 };
154 } else |err| i32(2);
161155 assert(result == 2);
162156}
163157
164158test "while on error union with else result follow break prong" {
165159 const result = while (returnSuccess(10)) |value| {
166160 break value;
167 } else |err| {
168 i32(2)
169 };
161 } else |err| i32(2);
170162 assert(result == 10);
171163}
172164
173165test "while on bool with else result follow else prong" {
174166 const result = while (returnFalse()) {
175167 break i32(10);
176 } else {
177 i32(2)
178 };
168 } else i32(2);
179169 assert(result == 2);
180170}
181171
182172test "while on bool with else result follow break prong" {
183173 const result = while (returnTrue()) {
184174 break i32(10);
185 } else {
186 i32(2)
187 };
175 } else i32(2);
188176 assert(result == 10);
189177}
190178
......@@ -215,10 +203,10 @@ fn testContinueOuter() {
215203 }
216204}
217205
218fn returnNull() -> ?i32 { null }
219fn returnMaybe(x: i32) -> ?i32 { x }
206fn returnNull() -> ?i32 { return null; }
207fn returnMaybe(x: i32) -> ?i32 { return x; }
220208error YouWantedAnError;
221fn returnError() -> %i32 { error.YouWantedAnError }
222fn returnSuccess(x: i32) -> %i32 { x }
223fn returnFalse() -> bool { false }
224fn returnTrue() -> bool { true }
209fn returnError() -> %i32 { return error.YouWantedAnError; }
210fn returnSuccess(x: i32) -> %i32 { return x; }
211fn returnFalse() -> bool { return false; }
212fn returnTrue() -> bool { return true; }
test/compare_output.zig+17-17
......@@ -10,7 +10,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
1010 \\}
1111 , "Hello, world!" ++ os.line_sep);
1212
13 cases.addCase({
13 cases.addCase(x: {
1414 var tc = cases.create("multiple files with private function",
1515 \\use @import("std").io;
1616 \\use @import("foo.zig");
......@@ -41,10 +41,10 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
4141 \\}
4242 );
4343
44 tc
44 break :x tc;
4545 });
4646
47 cases.addCase({
47 cases.addCase(x: {
4848 var tc = cases.create("import segregation",
4949 \\use @import("foo.zig");
5050 \\use @import("bar.zig");
......@@ -82,10 +82,10 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
8282 \\}
8383 );
8484
85 tc
85 break :x tc;
8686 });
8787
88 cases.addCase({
88 cases.addCase(x: {
8989 var tc = cases.create("two files use import each other",
9090 \\use @import("a.zig");
9191 \\
......@@ -112,7 +112,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
112112 \\pub const b_text = a_text;
113113 );
114114
115 tc
115 break :x tc;
116116 });
117117
118118 cases.add("hello world without libc",
......@@ -286,11 +286,11 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
286286 \\ const a_int = @ptrCast(&align(1) i32, a ?? unreachable);
287287 \\ const b_int = @ptrCast(&align(1) i32, b ?? unreachable);
288288 \\ if (*a_int < *b_int) {
289 \\ -1
289 \\ return -1;
290290 \\ } else if (*a_int > *b_int) {
291 \\ 1
291 \\ return 1;
292292 \\ } else {
293 \\ c_int(0)
293 \\ return 0;
294294 \\ }
295295 \\}
296296 \\
......@@ -342,13 +342,13 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
342342 \\const Foo = struct {
343343 \\ field1: Bar,
344344 \\
345 \\ fn method(a: &const Foo) -> bool { true }
345 \\ fn method(a: &const Foo) -> bool { return true; }
346346 \\};
347347 \\
348348 \\const Bar = struct {
349349 \\ field2: i32,
350350 \\
351 \\ fn method(b: &const Bar) -> bool { true }
351 \\ fn method(b: &const Bar) -> bool { return true; }
352352 \\};
353353 \\
354354 \\pub fn main() -> %void {
......@@ -429,7 +429,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
429429 \\fn its_gonna_pass() -> %void { }
430430 , "before\nafter\ndefer3\ndefer1\n");
431431
432 cases.addCase({
432 cases.addCase(x: {
433433 var tc = cases.create("@embedFile",
434434 \\const foo_txt = @embedFile("foo.txt");
435435 \\const io = @import("std").io;
......@@ -442,10 +442,10 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
442442
443443 tc.addSourceFile("foo.txt", "1234\nabcd\n");
444444
445 tc
445 break :x tc;
446446 });
447447
448 cases.addCase({
448 cases.addCase(x: {
449449 var tc = cases.create("parsing args",
450450 \\const std = @import("std");
451451 \\const io = std.io;
......@@ -483,10 +483,10 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
483483 "last arg",
484484 });
485485
486 tc
486 break :x tc;
487487 });
488488
489 cases.addCase({
489 cases.addCase(x: {
490490 var tc = cases.create("parsing args new API",
491491 \\const std = @import("std");
492492 \\const io = std.io;
......@@ -524,6 +524,6 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
524524 "last arg",
525525 });
526526
527 tc
527 break :x tc;
528528 });
529529}
test/compile_errors.zig+179-178
......@@ -9,7 +9,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
99 \\ }
1010 \\ }
1111 \\}
12 , ".tmp_source.zig:4:13: error: labeled loop not found: 'outer'");
12 , ".tmp_source.zig:4:13: error: label not found: 'outer'");
1313
1414 cases.add("labeled continue not found",
1515 \\export fn entry() {
......@@ -39,7 +39,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
3939 \\ ({})
4040 \\ var bad = {};
4141 \\}
42 , ".tmp_source.zig:5:5: error: invalid token: 'var'");
42 , ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
4343
4444 cases.add("implicit semicolon - block expr",
4545 \\export fn entry() {
......@@ -48,7 +48,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
4848 \\ _ = {}
4949 \\ var bad = {};
5050 \\}
51 , ".tmp_source.zig:5:5: error: invalid token: 'var'");
51 , ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
5252
5353 cases.add("implicit semicolon - comptime statement",
5454 \\export fn entry() {
......@@ -57,7 +57,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
5757 \\ comptime ({})
5858 \\ var bad = {};
5959 \\}
60 , ".tmp_source.zig:5:5: error: invalid token: 'var'");
60 , ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
6161
6262 cases.add("implicit semicolon - comptime expression",
6363 \\export fn entry() {
......@@ -66,7 +66,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
6666 \\ _ = comptime {}
6767 \\ var bad = {};
6868 \\}
69 , ".tmp_source.zig:5:5: error: invalid token: 'var'");
69 , ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
7070
7171 cases.add("implicit semicolon - defer",
7272 \\export fn entry() {
......@@ -84,7 +84,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
8484 \\ if(true) ({})
8585 \\ var bad = {};
8686 \\}
87 , ".tmp_source.zig:5:5: error: invalid token: 'var'");
87 , ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
8888
8989 cases.add("implicit semicolon - if expression",
9090 \\export fn entry() {
......@@ -93,7 +93,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
9393 \\ _ = if(true) {}
9494 \\ var bad = {};
9595 \\}
96 , ".tmp_source.zig:5:5: error: invalid token: 'var'");
96 , ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
9797
9898 cases.add("implicit semicolon - if-else statement",
9999 \\export fn entry() {
......@@ -102,7 +102,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
102102 \\ if(true) ({}) else ({})
103103 \\ var bad = {};
104104 \\}
105 , ".tmp_source.zig:5:5: error: invalid token: 'var'");
105 , ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
106106
107107 cases.add("implicit semicolon - if-else expression",
108108 \\export fn entry() {
......@@ -111,7 +111,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
111111 \\ _ = if(true) {} else {}
112112 \\ var bad = {};
113113 \\}
114 , ".tmp_source.zig:5:5: error: invalid token: 'var'");
114 , ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
115115
116116 cases.add("implicit semicolon - if-else-if statement",
117117 \\export fn entry() {
......@@ -120,7 +120,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
120120 \\ if(true) ({}) else if(true) ({})
121121 \\ var bad = {};
122122 \\}
123 , ".tmp_source.zig:5:5: error: invalid token: 'var'");
123 , ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
124124
125125 cases.add("implicit semicolon - if-else-if expression",
126126 \\export fn entry() {
......@@ -129,7 +129,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
129129 \\ _ = if(true) {} else if(true) {}
130130 \\ var bad = {};
131131 \\}
132 , ".tmp_source.zig:5:5: error: invalid token: 'var'");
132 , ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
133133
134134 cases.add("implicit semicolon - if-else-if-else statement",
135135 \\export fn entry() {
......@@ -138,7 +138,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
138138 \\ if(true) ({}) else if(true) ({}) else ({})
139139 \\ var bad = {};
140140 \\}
141 , ".tmp_source.zig:5:5: error: invalid token: 'var'");
141 , ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
142142
143143 cases.add("implicit semicolon - if-else-if-else expression",
144144 \\export fn entry() {
......@@ -147,7 +147,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
147147 \\ _ = if(true) {} else if(true) {} else {}
148148 \\ var bad = {};
149149 \\}
150 , ".tmp_source.zig:5:5: error: invalid token: 'var'");
150 , ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
151151
152152 cases.add("implicit semicolon - test statement",
153153 \\export fn entry() {
......@@ -156,7 +156,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
156156 \\ if (foo()) |_| ({})
157157 \\ var bad = {};
158158 \\}
159 , ".tmp_source.zig:5:5: error: invalid token: 'var'");
159 , ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
160160
161161 cases.add("implicit semicolon - test expression",
162162 \\export fn entry() {
......@@ -165,7 +165,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
165165 \\ _ = if (foo()) |_| {}
166166 \\ var bad = {};
167167 \\}
168 , ".tmp_source.zig:5:5: error: invalid token: 'var'");
168 , ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
169169
170170 cases.add("implicit semicolon - while statement",
171171 \\export fn entry() {
......@@ -174,7 +174,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
174174 \\ while(true) ({})
175175 \\ var bad = {};
176176 \\}
177 , ".tmp_source.zig:5:5: error: invalid token: 'var'");
177 , ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
178178
179179 cases.add("implicit semicolon - while expression",
180180 \\export fn entry() {
......@@ -183,7 +183,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
183183 \\ _ = while(true) {}
184184 \\ var bad = {};
185185 \\}
186 , ".tmp_source.zig:5:5: error: invalid token: 'var'");
186 , ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
187187
188188 cases.add("implicit semicolon - while-continue statement",
189189 \\export fn entry() {
......@@ -192,7 +192,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
192192 \\ while(true):({}) ({})
193193 \\ var bad = {};
194194 \\}
195 , ".tmp_source.zig:5:5: error: invalid token: 'var'");
195 , ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
196196
197197 cases.add("implicit semicolon - while-continue expression",
198198 \\export fn entry() {
......@@ -201,7 +201,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
201201 \\ _ = while(true):({}) {}
202202 \\ var bad = {};
203203 \\}
204 , ".tmp_source.zig:5:5: error: invalid token: 'var'");
204 , ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
205205
206206 cases.add("implicit semicolon - for statement",
207207 \\export fn entry() {
......@@ -210,7 +210,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
210210 \\ for(foo()) ({})
211211 \\ var bad = {};
212212 \\}
213 , ".tmp_source.zig:5:5: error: invalid token: 'var'");
213 , ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
214214
215215 cases.add("implicit semicolon - for expression",
216216 \\export fn entry() {
......@@ -219,7 +219,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
219219 \\ _ = for(foo()) {}
220220 \\ var bad = {};
221221 \\}
222 , ".tmp_source.zig:5:5: error: invalid token: 'var'");
222 , ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
223223
224224 cases.add("multiple function definitions",
225225 \\fn a() {}
......@@ -276,12 +276,13 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
276276
277277 cases.add("undeclared identifier",
278278 \\export fn a() {
279 \\ return
279280 \\ b +
280 \\ c
281 \\ c;
281282 \\}
282283 ,
283 ".tmp_source.zig:2:5: error: use of undeclared identifier 'b'",
284 ".tmp_source.zig:3:5: error: use of undeclared identifier 'c'");
284 ".tmp_source.zig:3:5: error: use of undeclared identifier 'b'",
285 ".tmp_source.zig:4:5: error: use of undeclared identifier 'c'");
285286
286287 cases.add("parameter redeclaration",
287288 \\fn f(a : i32, a : i32) {
......@@ -306,9 +307,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
306307 cases.add("variable has wrong type",
307308 \\export fn f() -> i32 {
308309 \\ const a = c"a";
309 \\ a
310 \\ return a;
310311 \\}
311 , ".tmp_source.zig:3:5: error: expected type 'i32', found '&const u8'");
312 , ".tmp_source.zig:3:12: error: expected type 'i32', found '&const u8'");
312313
313314 cases.add("if condition is bool, not int",
314315 \\export fn f() {
......@@ -393,23 +394,23 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
393394
394395 cases.add("missing else clause",
395396 \\fn f(b: bool) {
396 \\ const x : i32 = if (b) { 1 };
397 \\ const y = if (b) { i32(1) };
397 \\ const x : i32 = if (b) h: { break :h 1; };
398 \\ const y = if (b) h: { break :h i32(1); };
398399 \\}
399400 \\export fn entry() { f(true); }
400 , ".tmp_source.zig:2:30: error: integer value 1 cannot be implicitly casted to type 'void'",
401 , ".tmp_source.zig:2:42: error: integer value 1 cannot be implicitly casted to type 'void'",
401402 ".tmp_source.zig:3:15: error: incompatible types: 'i32' and 'void'");
402403
403404 cases.add("direct struct loop",
404405 \\const A = struct { a : A, };
405 \\export fn entry() -> usize { @sizeOf(A) }
406 \\export fn entry() -> usize { return @sizeOf(A); }
406407 , ".tmp_source.zig:1:11: error: struct 'A' contains itself");
407408
408409 cases.add("indirect struct loop",
409410 \\const A = struct { b : B, };
410411 \\const B = struct { c : C, };
411412 \\const C = struct { a : A, };
412 \\export fn entry() -> usize { @sizeOf(A) }
413 \\export fn entry() -> usize { return @sizeOf(A); }
413414 , ".tmp_source.zig:1:11: error: struct 'A' contains itself");
414415
415416 cases.add("invalid struct field",
......@@ -507,10 +508,10 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
507508
508509 cases.add("cast unreachable",
509510 \\fn f() -> i32 {
510 \\ i32(return 1)
511 \\ return i32(return 1);
511512 \\}
512513 \\export fn entry() { _ = f(); }
513 , ".tmp_source.zig:2:8: error: unreachable code");
514 , ".tmp_source.zig:2:15: error: unreachable code");
514515
515516 cases.add("invalid builtin fn",
516517 \\fn f() -> @bogus(foo) {
......@@ -533,7 +534,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
533534
534535 cases.add("struct init syntax for array",
535536 \\const foo = []u16{.x = 1024,};
536 \\export fn entry() -> usize { @sizeOf(@typeOf(foo)) }
537 \\export fn entry() -> usize { return @sizeOf(@typeOf(foo)); }
537538 , ".tmp_source.zig:1:18: error: type '[]u16' does not support struct initialization syntax");
538539
539540 cases.add("type variables must be constant",
......@@ -576,7 +577,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
576577 \\ }
577578 \\}
578579 \\
579 \\export fn entry() -> usize { @sizeOf(@typeOf(f)) }
580 \\export fn entry() -> usize { return @sizeOf(@typeOf(f)); }
580581 , ".tmp_source.zig:8:5: error: enumeration value 'Number.Four' not handled in switch");
581582
582583 cases.add("switch expression - duplicate enumeration prong",
......@@ -596,7 +597,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
596597 \\ }
597598 \\}
598599 \\
599 \\export fn entry() -> usize { @sizeOf(@typeOf(f)) }
600 \\export fn entry() -> usize { return @sizeOf(@typeOf(f)); }
600601 , ".tmp_source.zig:13:15: error: duplicate switch value",
601602 ".tmp_source.zig:10:15: note: other value is here");
602603
......@@ -618,7 +619,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
618619 \\ }
619620 \\}
620621 \\
621 \\export fn entry() -> usize { @sizeOf(@typeOf(f)) }
622 \\export fn entry() -> usize { return @sizeOf(@typeOf(f)); }
622623 , ".tmp_source.zig:13:15: error: duplicate switch value",
623624 ".tmp_source.zig:10:15: note: other value is here");
624625
......@@ -641,20 +642,20 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
641642 \\ 0 => {},
642643 \\ }
643644 \\}
644 \\export fn entry() -> usize { @sizeOf(@typeOf(foo)) }
645 \\export fn entry() -> usize { return @sizeOf(@typeOf(foo)); }
645646 ,
646647 ".tmp_source.zig:2:5: error: switch must handle all possibilities");
647648
648649 cases.add("switch expression - duplicate or overlapping integer value",
649650 \\fn foo(x: u8) -> u8 {
650 \\ switch (x) {
651 \\ return switch (x) {
651652 \\ 0 ... 100 => u8(0),
652653 \\ 101 ... 200 => 1,
653654 \\ 201, 203 ... 207 => 2,
654655 \\ 206 ... 255 => 3,
655 \\ }
656 \\ };
656657 \\}
657 \\export fn entry() -> usize { @sizeOf(@typeOf(foo)) }
658 \\export fn entry() -> usize { return @sizeOf(@typeOf(foo)); }
658659 ,
659660 ".tmp_source.zig:6:9: error: duplicate switch value",
660661 ".tmp_source.zig:5:14: note: previous value is here");
......@@ -666,14 +667,14 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
666667 \\ }
667668 \\}
668669 \\const y: u8 = 100;
669 \\export fn entry() -> usize { @sizeOf(@typeOf(foo)) }
670 \\export fn entry() -> usize { return @sizeOf(@typeOf(foo)); }
670671 ,
671672 ".tmp_source.zig:2:5: error: else prong required when switching on type '&u8'");
672673
673674 cases.add("global variable initializer must be constant expression",
674675 \\extern fn foo() -> i32;
675676 \\const x = foo();
676 \\export fn entry() -> i32 { x }
677 \\export fn entry() -> i32 { return x; }
677678 , ".tmp_source.zig:2:11: error: unable to evaluate constant expression");
678679
679680 cases.add("array concatenation with wrong type",
......@@ -681,38 +682,38 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
681682 \\const derp = usize(1234);
682683 \\const a = derp ++ "foo";
683684 \\
684 \\export fn entry() -> usize { @sizeOf(@typeOf(a)) }
685 \\export fn entry() -> usize { return @sizeOf(@typeOf(a)); }
685686 , ".tmp_source.zig:3:11: error: expected array or C string literal, found 'usize'");
686687
687688 cases.add("non compile time array concatenation",
688689 \\fn f() -> []u8 {
689 \\ s ++ "foo"
690 \\ return s ++ "foo";
690691 \\}
691692 \\var s: [10]u8 = undefined;
692 \\export fn entry() -> usize { @sizeOf(@typeOf(f)) }
693 , ".tmp_source.zig:2:5: error: unable to evaluate constant expression");
693 \\export fn entry() -> usize { return @sizeOf(@typeOf(f)); }
694 , ".tmp_source.zig:2:12: error: unable to evaluate constant expression");
694695
695696 cases.add("@cImport with bogus include",
696697 \\const c = @cImport(@cInclude("bogus.h"));
697 \\export fn entry() -> usize { @sizeOf(@typeOf(c.bogo)) }
698 \\export fn entry() -> usize { return @sizeOf(@typeOf(c.bogo)); }
698699 , ".tmp_source.zig:1:11: error: C import failed",
699700 ".h:1:10: note: 'bogus.h' file not found");
700701
701702 cases.add("address of number literal",
702703 \\const x = 3;
703704 \\const y = &x;
704 \\fn foo() -> &const i32 { y }
705 \\export fn entry() -> usize { @sizeOf(@typeOf(foo)) }
706 , ".tmp_source.zig:3:26: error: expected type '&const i32', found '&const (integer literal)'");
705 \\fn foo() -> &const i32 { return y; }
706 \\export fn entry() -> usize { return @sizeOf(@typeOf(foo)); }
707 , ".tmp_source.zig:3:33: error: expected type '&const i32', found '&const (integer literal)'");
707708
708709 cases.add("integer overflow error",
709710 \\const x : u8 = 300;
710 \\export fn entry() -> usize { @sizeOf(@typeOf(x)) }
711 \\export fn entry() -> usize { return @sizeOf(@typeOf(x)); }
711712 , ".tmp_source.zig:1:16: error: integer value 300 cannot be implicitly casted to type 'u8'");
712713
713714 cases.add("incompatible number literals",
714715 \\const x = 2 == 2.0;
715 \\export fn entry() -> usize { @sizeOf(@typeOf(x)) }
716 \\export fn entry() -> usize { return @sizeOf(@typeOf(x)); }
716717 , ".tmp_source.zig:1:11: error: integer value 2 cannot be implicitly casted to type '(float literal)'");
717718
718719 cases.add("missing function call param",
......@@ -738,32 +739,32 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
738739 \\ const result = members[index]();
739740 \\}
740741 \\
741 \\export fn entry() -> usize { @sizeOf(@typeOf(f)) }
742 \\export fn entry() -> usize { return @sizeOf(@typeOf(f)); }
742743 , ".tmp_source.zig:20:34: error: expected 1 arguments, found 0");
743744
744745 cases.add("missing function name and param name",
745746 \\fn () {}
746747 \\fn f(i32) {}
747 \\export fn entry() -> usize { @sizeOf(@typeOf(f)) }
748 \\export fn entry() -> usize { return @sizeOf(@typeOf(f)); }
748749 ,
749750 ".tmp_source.zig:1:1: error: missing function name",
750751 ".tmp_source.zig:2:6: error: missing parameter name");
751752
752753 cases.add("wrong function type",
753754 \\const fns = []fn(){ a, b, c };
754 \\fn a() -> i32 {0}
755 \\fn b() -> i32 {1}
756 \\fn c() -> i32 {2}
757 \\export fn entry() -> usize { @sizeOf(@typeOf(fns)) }
755 \\fn a() -> i32 {return 0;}
756 \\fn b() -> i32 {return 1;}
757 \\fn c() -> i32 {return 2;}
758 \\export fn entry() -> usize { return @sizeOf(@typeOf(fns)); }
758759 , ".tmp_source.zig:1:21: error: expected type 'fn()', found 'fn() -> i32'");
759760
760761 cases.add("extern function pointer mismatch",
761762 \\const fns = [](fn(i32)->i32){ a, b, c };
762 \\pub fn a(x: i32) -> i32 {x + 0}
763 \\pub fn b(x: i32) -> i32 {x + 1}
764 \\export fn c(x: i32) -> i32 {x + 2}
763 \\pub fn a(x: i32) -> i32 {return x + 0;}
764 \\pub fn b(x: i32) -> i32 {return x + 1;}
765 \\export fn c(x: i32) -> i32 {return x + 2;}
765766 \\
766 \\export fn entry() -> usize { @sizeOf(@typeOf(fns)) }
767 \\export fn entry() -> usize { return @sizeOf(@typeOf(fns)); }
767768 , ".tmp_source.zig:1:37: error: expected type 'fn(i32) -> i32', found 'extern fn(i32) -> i32'");
768769
769770
......@@ -771,14 +772,14 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
771772 \\const x : f64 = 1.0;
772773 \\const y : f32 = x;
773774 \\
774 \\export fn entry() -> usize { @sizeOf(@typeOf(y)) }
775 \\export fn entry() -> usize { return @sizeOf(@typeOf(y)); }
775776 , ".tmp_source.zig:2:17: error: expected type 'f32', found 'f64'");
776777
777778
778779 cases.add("colliding invalid top level functions",
779780 \\fn func() -> bogus {}
780781 \\fn func() -> bogus {}
781 \\export fn entry() -> usize { @sizeOf(@typeOf(func)) }
782 \\export fn entry() -> usize { return @sizeOf(@typeOf(func)); }
782783 ,
783784 ".tmp_source.zig:2:1: error: redefinition of 'func'",
784785 ".tmp_source.zig:1:14: error: use of undeclared identifier 'bogus'");
......@@ -786,7 +787,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
786787
787788 cases.add("bogus compile var",
788789 \\const x = @import("builtin").bogus;
789 \\export fn entry() -> usize { @sizeOf(@typeOf(x)) }
790 \\export fn entry() -> usize { return @sizeOf(@typeOf(x)); }
790791 , ".tmp_source.zig:1:29: error: no member named 'bogus' in '");
791792
792793
......@@ -795,11 +796,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
795796 \\ y: [get()]u8,
796797 \\};
797798 \\var global_var: usize = 1;
798 \\fn get() -> usize { global_var }
799 \\fn get() -> usize { return global_var; }
799800 \\
800 \\export fn entry() -> usize { @sizeOf(@typeOf(Foo)) }
801 \\export fn entry() -> usize { return @sizeOf(@typeOf(Foo)); }
801802 ,
802 ".tmp_source.zig:5:21: error: unable to evaluate constant expression",
803 ".tmp_source.zig:5:28: error: unable to evaluate constant expression",
803804 ".tmp_source.zig:2:12: note: called from here",
804805 ".tmp_source.zig:2:8: note: called from here");
805806
......@@ -810,7 +811,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
810811 \\};
811812 \\const x = Foo {.field = 1} + Foo {.field = 2};
812813 \\
813 \\export fn entry() -> usize { @sizeOf(@typeOf(x)) }
814 \\export fn entry() -> usize { return @sizeOf(@typeOf(x)); }
814815 , ".tmp_source.zig:4:28: error: invalid operands to binary expression: 'Foo' and 'Foo'");
815816
816817
......@@ -820,10 +821,10 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
820821 \\const int_x = u32(1) / u32(0);
821822 \\const float_x = f32(1.0) / f32(0.0);
822823 \\
823 \\export fn entry1() -> usize { @sizeOf(@typeOf(lit_int_x)) }
824 \\export fn entry2() -> usize { @sizeOf(@typeOf(lit_float_x)) }
825 \\export fn entry3() -> usize { @sizeOf(@typeOf(int_x)) }
826 \\export fn entry4() -> usize { @sizeOf(@typeOf(float_x)) }
824 \\export fn entry1() -> usize { return @sizeOf(@typeOf(lit_int_x)); }
825 \\export fn entry2() -> usize { return @sizeOf(@typeOf(lit_float_x)); }
826 \\export fn entry3() -> usize { return @sizeOf(@typeOf(int_x)); }
827 \\export fn entry4() -> usize { return @sizeOf(@typeOf(float_x)); }
827828 ,
828829 ".tmp_source.zig:1:21: error: division by zero is undefined",
829830 ".tmp_source.zig:2:25: error: division by zero is undefined",
......@@ -835,14 +836,14 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
835836 \\const foo = "a
836837 \\b";
837838 \\
838 \\export fn entry() -> usize { @sizeOf(@typeOf(foo)) }
839 \\export fn entry() -> usize { return @sizeOf(@typeOf(foo)); }
839840 , ".tmp_source.zig:1:13: error: newline not allowed in string literal");
840841
841842 cases.add("invalid comparison for function pointers",
842843 \\fn foo() {}
843844 \\const invalid = foo > foo;
844845 \\
845 \\export fn entry() -> usize { @sizeOf(@typeOf(invalid)) }
846 \\export fn entry() -> usize { return @sizeOf(@typeOf(invalid)); }
846847 , ".tmp_source.zig:2:21: error: operator not allowed for type 'fn()'");
847848
848849 cases.add("generic function instance with non-constant expression",
......@@ -851,13 +852,13 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
851852 \\ return foo(a, b);
852853 \\}
853854 \\
854 \\export fn entry() -> usize { @sizeOf(@typeOf(test1)) }
855 \\export fn entry() -> usize { return @sizeOf(@typeOf(test1)); }
855856 , ".tmp_source.zig:3:16: error: unable to evaluate constant expression");
856857
857858 cases.add("assign null to non-nullable pointer",
858859 \\const a: &u8 = null;
859860 \\
860 \\export fn entry() -> usize { @sizeOf(@typeOf(a)) }
861 \\export fn entry() -> usize { return @sizeOf(@typeOf(a)); }
861862 , ".tmp_source.zig:1:16: error: expected type '&u8', found '(null)'");
862863
863864 cases.add("indexing an array of size zero",
......@@ -870,18 +871,18 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
870871 cases.add("compile time division by zero",
871872 \\const y = foo(0);
872873 \\fn foo(x: u32) -> u32 {
873 \\ 1 / x
874 \\ return 1 / x;
874875 \\}
875876 \\
876 \\export fn entry() -> usize { @sizeOf(@typeOf(y)) }
877 \\export fn entry() -> usize { return @sizeOf(@typeOf(y)); }
877878 ,
878 ".tmp_source.zig:3:7: error: division by zero is undefined",
879 ".tmp_source.zig:3:14: error: division by zero is undefined",
879880 ".tmp_source.zig:1:14: note: called from here");
880881
881882 cases.add("branch on undefined value",
882883 \\const x = if (undefined) true else false;
883884 \\
884 \\export fn entry() -> usize { @sizeOf(@typeOf(x)) }
885 \\export fn entry() -> usize { return @sizeOf(@typeOf(x)); }
885886 , ".tmp_source.zig:1:15: error: use of undefined value");
886887
887888
......@@ -891,7 +892,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
891892 \\ return fibbonaci(x - 1) + fibbonaci(x - 2);
892893 \\}
893894 \\
894 \\export fn entry() -> usize { @sizeOf(@typeOf(seventh_fib_number)) }
895 \\export fn entry() -> usize { return @sizeOf(@typeOf(seventh_fib_number)); }
895896 ,
896897 ".tmp_source.zig:3:21: error: evaluation exceeded 1000 backwards branches",
897898 ".tmp_source.zig:3:21: note: called from here");
......@@ -899,7 +900,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
899900 cases.add("@embedFile with bogus file",
900901 \\const resource = @embedFile("bogus.txt");
901902 \\
902 \\export fn entry() -> usize { @sizeOf(@typeOf(resource)) }
903 \\export fn entry() -> usize { return @sizeOf(@typeOf(resource)); }
903904 , ".tmp_source.zig:1:29: error: unable to find '", "bogus.txt'");
904905
905906 cases.add("non-const expression in struct literal outside function",
......@@ -909,7 +910,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
909910 \\const a = Foo {.x = get_it()};
910911 \\extern fn get_it() -> i32;
911912 \\
912 \\export fn entry() -> usize { @sizeOf(@typeOf(a)) }
913 \\export fn entry() -> usize { return @sizeOf(@typeOf(a)); }
913914 , ".tmp_source.zig:4:21: error: unable to evaluate constant expression");
914915
915916 cases.add("non-const expression function call with struct return value outside function",
......@@ -919,11 +920,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
919920 \\const a = get_it();
920921 \\fn get_it() -> Foo {
921922 \\ global_side_effect = true;
922 \\ Foo {.x = 13}
923 \\ return Foo {.x = 13};
923924 \\}
924925 \\var global_side_effect = false;
925926 \\
926 \\export fn entry() -> usize { @sizeOf(@typeOf(a)) }
927 \\export fn entry() -> usize { return @sizeOf(@typeOf(a)); }
927928 ,
928929 ".tmp_source.zig:6:24: error: unable to evaluate constant expression",
929930 ".tmp_source.zig:4:17: note: called from here");
......@@ -939,21 +940,21 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
939940
940941 cases.add("illegal comparison of types",
941942 \\fn bad_eql_1(a: []u8, b: []u8) -> bool {
942 \\ a == b
943 \\ return a == b;
943944 \\}
944945 \\const EnumWithData = union(enum) {
945946 \\ One: void,
946947 \\ Two: i32,
947948 \\};
948949 \\fn bad_eql_2(a: &const EnumWithData, b: &const EnumWithData) -> bool {
949 \\ *a == *b
950 \\ return *a == *b;
950951 \\}
951952 \\
952 \\export fn entry1() -> usize { @sizeOf(@typeOf(bad_eql_1)) }
953 \\export fn entry2() -> usize { @sizeOf(@typeOf(bad_eql_2)) }
953 \\export fn entry1() -> usize { return @sizeOf(@typeOf(bad_eql_1)); }
954 \\export fn entry2() -> usize { return @sizeOf(@typeOf(bad_eql_2)); }
954955 ,
955 ".tmp_source.zig:2:7: error: operator not allowed for type '[]u8'",
956 ".tmp_source.zig:9:8: error: operator not allowed for type 'EnumWithData'");
956 ".tmp_source.zig:2:14: error: operator not allowed for type '[]u8'",
957 ".tmp_source.zig:9:15: error: operator not allowed for type 'EnumWithData'");
957958
958959 cases.add("non-const switch number literal",
959960 \\export fn foo() {
......@@ -964,7 +965,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
964965 \\ };
965966 \\}
966967 \\fn bar() -> i32 {
967 \\ 2
968 \\ return 2;
968969 \\}
969970 , ".tmp_source.zig:2:15: error: unable to infer expression type");
970971
......@@ -987,56 +988,56 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
987988 cases.add("negation overflow in function evaluation",
988989 \\const y = neg(-128);
989990 \\fn neg(x: i8) -> i8 {
990 \\ -x
991 \\ return -x;
991992 \\}
992993 \\
993 \\export fn entry() -> usize { @sizeOf(@typeOf(y)) }
994 \\export fn entry() -> usize { return @sizeOf(@typeOf(y)); }
994995 ,
995 ".tmp_source.zig:3:5: error: negation caused overflow",
996 ".tmp_source.zig:3:12: error: negation caused overflow",
996997 ".tmp_source.zig:1:14: note: called from here");
997998
998999 cases.add("add overflow in function evaluation",
9991000 \\const y = add(65530, 10);
10001001 \\fn add(a: u16, b: u16) -> u16 {
1001 \\ a + b
1002 \\ return a + b;
10021003 \\}
10031004 \\
1004 \\export fn entry() -> usize { @sizeOf(@typeOf(y)) }
1005 \\export fn entry() -> usize { return @sizeOf(@typeOf(y)); }
10051006 ,
1006 ".tmp_source.zig:3:7: error: operation caused overflow",
1007 ".tmp_source.zig:3:14: error: operation caused overflow",
10071008 ".tmp_source.zig:1:14: note: called from here");
10081009
10091010
10101011 cases.add("sub overflow in function evaluation",
10111012 \\const y = sub(10, 20);
10121013 \\fn sub(a: u16, b: u16) -> u16 {
1013 \\ a - b
1014 \\ return a - b;
10141015 \\}
10151016 \\
1016 \\export fn entry() -> usize { @sizeOf(@typeOf(y)) }
1017 \\export fn entry() -> usize { return @sizeOf(@typeOf(y)); }
10171018 ,
1018 ".tmp_source.zig:3:7: error: operation caused overflow",
1019 ".tmp_source.zig:3:14: error: operation caused overflow",
10191020 ".tmp_source.zig:1:14: note: called from here");
10201021
10211022 cases.add("mul overflow in function evaluation",
10221023 \\const y = mul(300, 6000);
10231024 \\fn mul(a: u16, b: u16) -> u16 {
1024 \\ a * b
1025 \\ return a * b;
10251026 \\}
10261027 \\
1027 \\export fn entry() -> usize { @sizeOf(@typeOf(y)) }
1028 \\export fn entry() -> usize { return @sizeOf(@typeOf(y)); }
10281029 ,
1029 ".tmp_source.zig:3:7: error: operation caused overflow",
1030 ".tmp_source.zig:3:14: error: operation caused overflow",
10301031 ".tmp_source.zig:1:14: note: called from here");
10311032
10321033 cases.add("truncate sign mismatch",
10331034 \\fn f() -> i8 {
10341035 \\ const x: u32 = 10;
1035 \\ @truncate(i8, x)
1036 \\ return @truncate(i8, x);
10361037 \\}
10371038 \\
1038 \\export fn entry() -> usize { @sizeOf(@typeOf(f)) }
1039 , ".tmp_source.zig:3:19: error: expected signed integer type, found 'u32'");
1039 \\export fn entry() -> usize { return @sizeOf(@typeOf(f)); }
1040 , ".tmp_source.zig:3:26: error: expected signed integer type, found 'u32'");
10401041
10411042 cases.add("%return in function with non error return type",
10421043 \\export fn f() {
......@@ -1067,16 +1068,16 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
10671068
10681069 cases.add("export function with comptime parameter",
10691070 \\export fn foo(comptime x: i32, y: i32) -> i32{
1070 \\ x + y
1071 \\ return x + y;
10711072 \\}
10721073 , ".tmp_source.zig:1:15: error: comptime parameter not allowed in function with calling convention 'ccc'");
10731074
10741075 cases.add("extern function with comptime parameter",
10751076 \\extern fn foo(comptime x: i32, y: i32) -> i32;
10761077 \\fn f() -> i32 {
1077 \\ foo(1, 2)
1078 \\ return foo(1, 2);
10781079 \\}
1079 \\export fn entry() -> usize { @sizeOf(@typeOf(f)) }
1080 \\export fn entry() -> usize { return @sizeOf(@typeOf(f)); }
10801081 , ".tmp_source.zig:1:15: error: comptime parameter not allowed in function with calling convention 'ccc'");
10811082
10821083 cases.add("convert fixed size array to slice with invalid size",
......@@ -1090,15 +1091,15 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
10901091 \\var a: u32 = 0;
10911092 \\pub fn List(comptime T: type) -> type {
10921093 \\ a += 1;
1093 \\ SmallList(T, 8)
1094 \\ return SmallList(T, 8);
10941095 \\}
10951096 \\
10961097 \\pub fn SmallList(comptime T: type, comptime STATIC_SIZE: usize) -> type {
1097 \\ struct {
1098 \\ return struct {
10981099 \\ items: []T,
10991100 \\ length: usize,
11001101 \\ prealloc_items: [STATIC_SIZE]T,
1101 \\ }
1102 \\ };
11021103 \\}
11031104 \\
11041105 \\export fn function_with_return_type_type() {
......@@ -1113,7 +1114,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
11131114 \\fn f(m: []const u8) {
11141115 \\ m.copy(u8, self[0..], m);
11151116 \\}
1116 \\export fn entry() -> usize { @sizeOf(@typeOf(f)) }
1117 \\export fn entry() -> usize { return @sizeOf(@typeOf(f)); }
11171118 , ".tmp_source.zig:3:6: error: no member named 'copy' in '[]const u8'");
11181119
11191120 cases.add("wrong number of arguments for method fn call",
......@@ -1124,7 +1125,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
11241125 \\
11251126 \\ foo.method(1, 2);
11261127 \\}
1127 \\export fn entry() -> usize { @sizeOf(@typeOf(f)) }
1128 \\export fn entry() -> usize { return @sizeOf(@typeOf(f)); }
11281129 , ".tmp_source.zig:6:15: error: expected 2 arguments, found 3");
11291130
11301131 cases.add("assign through constant pointer",
......@@ -1149,7 +1150,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
11491150 \\fn foo(blah: []u8) {
11501151 \\ for (blah) { }
11511152 \\}
1152 \\export fn entry() -> usize { @sizeOf(@typeOf(foo)) }
1153 \\export fn entry() -> usize { return @sizeOf(@typeOf(foo)); }
11531154 , ".tmp_source.zig:2:5: error: for loop expression missing element parameter");
11541155
11551156 cases.add("misspelled type with pointer only reference",
......@@ -1182,7 +1183,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
11821183 \\ var jd = JsonNode {.kind = JsonType.JSONArray , .jobject = JsonOA.JSONArray {jll} };
11831184 \\}
11841185 \\
1185 \\export fn entry() -> usize { @sizeOf(@typeOf(foo)) }
1186 \\export fn entry() -> usize { return @sizeOf(@typeOf(foo)); }
11861187 , ".tmp_source.zig:5:16: error: use of undeclared identifier 'JsonList'");
11871188
11881189 cases.add("method call with first arg type primitive",
......@@ -1190,9 +1191,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
11901191 \\ x: i32,
11911192 \\
11921193 \\ fn init(x: i32) -> Foo {
1193 \\ Foo {
1194 \\ return Foo {
11941195 \\ .x = x,
1195 \\ }
1196 \\ };
11961197 \\ }
11971198 \\};
11981199 \\
......@@ -1209,10 +1210,10 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
12091210 \\ allocator: &Allocator,
12101211 \\
12111212 \\ pub fn init(allocator: &Allocator) -> List {
1212 \\ List {
1213 \\ return List {
12131214 \\ .len = 0,
12141215 \\ .allocator = allocator,
1215 \\ }
1216 \\ };
12161217 \\ }
12171218 \\};
12181219 \\
......@@ -1235,10 +1236,10 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
12351236 \\const TINY_QUANTUM_SIZE = 1 << TINY_QUANTUM_SHIFT;
12361237 \\var block_aligned_stuff: usize = (4 + TINY_QUANTUM_SIZE) & ~(TINY_QUANTUM_SIZE - 1);
12371238 \\
1238 \\export fn entry() -> usize { @sizeOf(@typeOf(block_aligned_stuff)) }
1239 \\export fn entry() -> usize { return @sizeOf(@typeOf(block_aligned_stuff)); }
12391240 , ".tmp_source.zig:3:60: error: unable to perform binary not operation on type '(integer literal)'");
12401241
1241 cases.addCase({
1242 cases.addCase(x: {
12421243 const tc = cases.create("multiple files with private function error",
12431244 \\const foo = @import("foo.zig");
12441245 \\
......@@ -1253,14 +1254,14 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
12531254 \\fn privateFunction() { }
12541255 );
12551256
1256 tc
1257 break :x tc;
12571258 });
12581259
12591260 cases.add("container init with non-type",
12601261 \\const zero: i32 = 0;
12611262 \\const a = zero{1};
12621263 \\
1263 \\export fn entry() -> usize { @sizeOf(@typeOf(a)) }
1264 \\export fn entry() -> usize { return @sizeOf(@typeOf(a)); }
12641265 , ".tmp_source.zig:2:11: error: expected type, found 'i32'");
12651266
12661267 cases.add("assign to constant field",
......@@ -1288,22 +1289,22 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
12881289 \\ return 0;
12891290 \\}
12901291 \\
1291 \\export fn entry() -> usize { @sizeOf(@typeOf(testTrickyDefer)) }
1292 \\export fn entry() -> usize { return @sizeOf(@typeOf(testTrickyDefer)); }
12921293 , ".tmp_source.zig:4:11: error: cannot return from defer expression");
12931294
12941295 cases.add("attempt to access var args out of bounds",
12951296 \\fn add(args: ...) -> i32 {
1296 \\ args[0] + args[1]
1297 \\ return args[0] + args[1];
12971298 \\}
12981299 \\
12991300 \\fn foo() -> i32 {
1300 \\ add(i32(1234))
1301 \\ return add(i32(1234));
13011302 \\}
13021303 \\
1303 \\export fn entry() -> usize { @sizeOf(@typeOf(foo)) }
1304 \\export fn entry() -> usize { return @sizeOf(@typeOf(foo)); }
13041305 ,
1305 ".tmp_source.zig:2:19: error: index 1 outside argument list of size 1",
1306 ".tmp_source.zig:6:8: note: called from here");
1306 ".tmp_source.zig:2:26: error: index 1 outside argument list of size 1",
1307 ".tmp_source.zig:6:15: note: called from here");
13071308
13081309 cases.add("pass integer literal to var args",
13091310 \\fn add(args: ...) -> i32 {
......@@ -1315,11 +1316,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
13151316 \\}
13161317 \\
13171318 \\fn bar() -> i32 {
1318 \\ add(1, 2, 3, 4)
1319 \\ return add(1, 2, 3, 4);
13191320 \\}
13201321 \\
1321 \\export fn entry() -> usize { @sizeOf(@typeOf(bar)) }
1322 , ".tmp_source.zig:10:9: error: parameter of type '(integer literal)' requires comptime");
1322 \\export fn entry() -> usize { return @sizeOf(@typeOf(bar)); }
1323 , ".tmp_source.zig:10:16: error: parameter of type '(integer literal)' requires comptime");
13231324
13241325 cases.add("assign too big number to u16",
13251326 \\export fn foo() {
......@@ -1329,12 +1330,12 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
13291330
13301331 cases.add("global variable alignment non power of 2",
13311332 \\const some_data: [100]u8 align(3) = undefined;
1332 \\export fn entry() -> usize { @sizeOf(@typeOf(some_data)) }
1333 \\export fn entry() -> usize { return @sizeOf(@typeOf(some_data)); }
13331334 , ".tmp_source.zig:1:32: error: alignment value 3 is not a power of 2");
13341335
13351336 cases.add("function alignment non power of 2",
13361337 \\extern fn foo() align(3);
1337 \\export fn entry() { foo() }
1338 \\export fn entry() { return foo(); }
13381339 , ".tmp_source.zig:1:23: error: alignment value 3 is not a power of 2");
13391340
13401341 cases.add("compile log",
......@@ -1369,7 +1370,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
13691370 \\ return *x;
13701371 \\}
13711372 \\
1372 \\export fn entry() -> usize { @sizeOf(@typeOf(foo)) }
1373 \\export fn entry() -> usize { return @sizeOf(@typeOf(foo)); }
13731374 , ".tmp_source.zig:8:26: error: expected type '&const u3', found '&align(1:3:6) const u3'");
13741375
13751376 cases.add("referring to a struct that is invalid",
......@@ -1405,14 +1406,14 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
14051406 \\export fn foo() {
14061407 \\ bar();
14071408 \\}
1408 \\fn bar() -> i32 { 0 }
1409 \\fn bar() -> i32 { return 0; }
14091410 , ".tmp_source.zig:2:8: error: expression value is ignored");
14101411
14111412 cases.add("ignored assert-err-ok return value",
14121413 \\export fn foo() {
14131414 \\ %%bar();
14141415 \\}
1415 \\fn bar() -> %i32 { 0 }
1416 \\fn bar() -> %i32 { return 0; }
14161417 , ".tmp_source.zig:2:5: error: expression value is ignored");
14171418
14181419 cases.add("ignored statement value",
......@@ -1439,11 +1440,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
14391440 \\}
14401441 , ".tmp_source.zig:2:12: error: expression value is ignored");
14411442
1442 cases.add("ignored defered statement value",
1443 cases.add("ignored defered function call",
14431444 \\export fn foo() {
14441445 \\ defer bar();
14451446 \\}
1446 \\fn bar() -> %i32 { 0 }
1447 \\fn bar() -> %i32 { return 0; }
14471448 , ".tmp_source.zig:2:14: error: expression value is ignored");
14481449
14491450 cases.add("dereference an array",
......@@ -1454,7 +1455,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
14541455 \\ return (*out)[0..1];
14551456 \\}
14561457 \\
1457 \\export fn entry() -> usize { @sizeOf(@typeOf(pass)) }
1458 \\export fn entry() -> usize { return @sizeOf(@typeOf(pass)); }
14581459 , ".tmp_source.zig:4:5: error: attempt to dereference non pointer type '[10]u8'");
14591460
14601461 cases.add("pass const ptr to mutable ptr fn",
......@@ -1467,10 +1468,10 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
14671468 \\ return true;
14681469 \\}
14691470 \\
1470 \\export fn entry() -> usize { @sizeOf(@typeOf(foo)) }
1471 \\export fn entry() -> usize { return @sizeOf(@typeOf(foo)); }
14711472 , ".tmp_source.zig:4:19: error: expected type '&[]const u8', found '&const []const u8'");
14721473
1473 cases.addCase({
1474 cases.addCase(x: {
14741475 const tc = cases.create("export collision",
14751476 \\const foo = @import("foo.zig");
14761477 \\
......@@ -1486,13 +1487,13 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
14861487 \\pub const baz = 1234;
14871488 );
14881489
1489 tc
1490 break :x tc;
14901491 });
14911492
14921493 cases.add("pass non-copyable type by value to function",
14931494 \\const Point = struct { x: i32, y: i32, };
14941495 \\fn foo(p: Point) { }
1495 \\export fn entry() -> usize { @sizeOf(@typeOf(foo)) }
1496 \\export fn entry() -> usize { return @sizeOf(@typeOf(foo)); }
14961497 , ".tmp_source.zig:2:11: error: type 'Point' is not copyable; cannot pass by value");
14971498
14981499 cases.add("implicit cast from array to mutable slice",
......@@ -1515,7 +1516,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
15151516 \\fn foo(e: error) -> u2 {
15161517 \\ return u2(e);
15171518 \\}
1518 \\export fn entry() -> usize { @sizeOf(@typeOf(foo)) }
1519 \\export fn entry() -> usize { return @sizeOf(@typeOf(foo)); }
15191520 , ".tmp_source.zig:4:14: error: too many error values to fit in 'u2'");
15201521
15211522 cases.add("asm at compile time",
......@@ -1665,17 +1666,17 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
16651666
16661667 cases.add("inner struct member shadowing outer struct member",
16671668 \\fn A() -> type {
1668 \\ struct {
1669 \\ return struct {
16691670 \\ b: B(),
16701671 \\
16711672 \\ const Self = this;
16721673 \\
16731674 \\ fn B() -> type {
1674 \\ struct {
1675 \\ return struct {
16751676 \\ const Self = this;
1676 \\ }
1677 \\ };
16771678 \\ }
1678 \\ }
1679 \\ };
16791680 \\}
16801681 \\comptime {
16811682 \\ assert(A().B().Self != A().Self);
......@@ -1691,7 +1692,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
16911692 \\export fn foo() {
16921693 \\ while (bar()) {}
16931694 \\}
1694 \\fn bar() -> ?i32 { 1 }
1695 \\fn bar() -> ?i32 { return 1; }
16951696 ,
16961697 ".tmp_source.zig:2:15: error: expected type 'bool', found '?i32'");
16971698
......@@ -1699,7 +1700,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
16991700 \\export fn foo() {
17001701 \\ while (bar()) {}
17011702 \\}
1702 \\fn bar() -> %i32 { 1 }
1703 \\fn bar() -> %i32 { return 1; }
17031704 ,
17041705 ".tmp_source.zig:2:15: error: expected type 'bool', found '%i32'");
17051706
......@@ -1707,7 +1708,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
17071708 \\export fn foo() {
17081709 \\ while (bar()) |x| {}
17091710 \\}
1710 \\fn bar() -> bool { true }
1711 \\fn bar() -> bool { return true; }
17111712 ,
17121713 ".tmp_source.zig:2:15: error: expected nullable type, found 'bool'");
17131714
......@@ -1715,7 +1716,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
17151716 \\export fn foo() {
17161717 \\ while (bar()) |x| {}
17171718 \\}
1718 \\fn bar() -> %i32 { 1 }
1719 \\fn bar() -> %i32 { return 1; }
17191720 ,
17201721 ".tmp_source.zig:2:15: error: expected nullable type, found '%i32'");
17211722
......@@ -1723,7 +1724,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
17231724 \\export fn foo() {
17241725 \\ while (bar()) |x| {} else |err| {}
17251726 \\}
1726 \\fn bar() -> bool { true }
1727 \\fn bar() -> bool { return true; }
17271728 ,
17281729 ".tmp_source.zig:2:15: error: expected error union type, found 'bool'");
17291730
......@@ -1731,7 +1732,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
17311732 \\export fn foo() {
17321733 \\ while (bar()) |x| {} else |err| {}
17331734 \\}
1734 \\fn bar() -> ?i32 { 1 }
1735 \\fn bar() -> ?i32 { return 1; }
17351736 ,
17361737 ".tmp_source.zig:2:15: error: expected error union type, found '?i32'");
17371738
......@@ -1762,17 +1763,17 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
17621763
17631764 cases.add("signed integer division",
17641765 \\export fn foo(a: i32, b: i32) -> i32 {
1765 \\ a / b
1766 \\ return a / b;
17661767 \\}
17671768 ,
1768 ".tmp_source.zig:2:7: error: division with 'i32' and 'i32': signed integers must use @divTrunc, @divFloor, or @divExact");
1769 ".tmp_source.zig:2:14: error: division with 'i32' and 'i32': signed integers must use @divTrunc, @divFloor, or @divExact");
17691770
17701771 cases.add("signed integer remainder division",
17711772 \\export fn foo(a: i32, b: i32) -> i32 {
1772 \\ a % b
1773 \\ return a % b;
17731774 \\}
17741775 ,
1775 ".tmp_source.zig:2:7: error: remainder division with 'i32' and 'i32': signed integers and floats must use @rem or @mod");
1776 ".tmp_source.zig:2:14: error: remainder division with 'i32' and 'i32': signed integers and floats must use @rem or @mod");
17761777
17771778 cases.add("cast negative value to unsigned integer",
17781779 \\comptime {
......@@ -1922,17 +1923,17 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
19221923
19231924 cases.add("explicit cast float literal to integer when there is a fraction component",
19241925 \\export fn entry() -> i32 {
1925 \\ i32(12.34)
1926 \\ return i32(12.34);
19261927 \\}
19271928 ,
1928 ".tmp_source.zig:2:9: error: fractional component prevents float value 12.340000 from being casted to type 'i32'");
1929 ".tmp_source.zig:2:16: error: fractional component prevents float value 12.340000 from being casted to type 'i32'");
19291930
19301931 cases.add("non pointer given to @ptrToInt",
19311932 \\export fn entry(x: i32) -> usize {
1932 \\ @ptrToInt(x)
1933 \\ return @ptrToInt(x);
19331934 \\}
19341935 ,
1935 ".tmp_source.zig:2:15: error: expected pointer, found 'i32'");
1936 ".tmp_source.zig:2:22: error: expected pointer, found 'i32'");
19361937
19371938 cases.add("@shlExact shifts out 1 bits",
19381939 \\comptime {
......@@ -2028,7 +2029,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
20282029
20292030 cases.add("@alignCast expects pointer or slice",
20302031 \\export fn entry() {
2031 \\ @alignCast(4, u32(3))
2032 \\ @alignCast(4, u32(3));
20322033 \\}
20332034 ,
20342035 ".tmp_source.zig:2:22: error: expected pointer or slice, found 'u32'");
......@@ -2040,7 +2041,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
20402041 \\fn testImplicitlyDecreaseFnAlign(ptr: fn () align(8) -> i32, answer: i32) {
20412042 \\ if (ptr() != answer) unreachable;
20422043 \\}
2043 \\fn alignedSmall() align(4) -> i32 { 1234 }
2044 \\fn alignedSmall() align(4) -> i32 { return 1234; }
20442045 ,
20452046 ".tmp_source.zig:2:35: error: expected type 'fn() align(8) -> i32', found 'fn() align(4) -> i32'");
20462047
......@@ -2206,17 +2207,17 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
22062207 \\const Mode = @import("builtin").Mode;
22072208 \\
22082209 \\fn Free(comptime filename: []const u8) -> TestCase {
2209 \\ TestCase {
2210 \\ return TestCase {
22102211 \\ .filename = filename,
22112212 \\ .problem_type = ProblemType.Free,
2212 \\ }
2213 \\ };
22132214 \\}
22142215 \\
22152216 \\fn LibC(comptime filename: []const u8) -> TestCase {
2216 \\ TestCase {
2217 \\ return TestCase {
22172218 \\ .filename = filename,
22182219 \\ .problem_type = ProblemType.LinkLibC,
2219 \\ }
2220 \\ };
22202221 \\}
22212222 \\
22222223 \\const TestCase = struct {
......@@ -2374,9 +2375,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
23742375 \\pub fn MemoryPool(comptime T: type) -> type {
23752376 \\ const free_list_t = @compileError("aoeu");
23762377 \\
2377 \\ struct {
2378 \\ return struct {
23782379 \\ free_list: free_list_t,
2379 \\ }
2380 \\ };
23802381 \\}
23812382 \\
23822383 \\export fn entry() {
......@@ -2651,7 +2652,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
26512652 \\ C: bool,
26522653 \\};
26532654 \\export fn entry() {
2654 \\ var a = Payload { .A = { 1234 } };
2655 \\ var a = Payload { .A = 1234 };
26552656 \\}
26562657 ,
26572658 ".tmp_source.zig:6:29: error: extern union does not support enum tag type");
......@@ -2668,7 +2669,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
26682669 \\ C: bool,
26692670 \\};
26702671 \\export fn entry() {
2671 \\ var a = Payload { .A = { 1234 } };
2672 \\ var a = Payload { .A = 1234 };
26722673 \\}
26732674 ,
26742675 ".tmp_source.zig:6:29: error: packed union does not support enum tag type");
......@@ -2680,7 +2681,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
26802681 \\ C: bool,
26812682 \\};
26822683 \\export fn entry() {
2683 \\ const a = Payload { .A = { 1234 } };
2684 \\ const a = Payload { .A = 1234 };
26842685 \\ foo(a);
26852686 \\}
26862687 \\fn foo(a: &const Payload) {
test/debug_safety.zig+15-15
......@@ -19,7 +19,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
1919 \\ baz(bar(a));
2020 \\}
2121 \\fn bar(a: []const i32) -> i32 {
22 \\ a[4]
22 \\ return a[4];
2323 \\}
2424 \\fn baz(a: i32) { }
2525 );
......@@ -34,7 +34,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
3434 \\ if (x == 0) return error.Whatever;
3535 \\}
3636 \\fn add(a: u16, b: u16) -> u16 {
37 \\ a + b
37 \\ return a + b;
3838 \\}
3939 );
4040
......@@ -48,7 +48,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
4848 \\ if (x == 0) return error.Whatever;
4949 \\}
5050 \\fn sub(a: u16, b: u16) -> u16 {
51 \\ a - b
51 \\ return a - b;
5252 \\}
5353 );
5454
......@@ -62,7 +62,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
6262 \\ if (x == 0) return error.Whatever;
6363 \\}
6464 \\fn mul(a: u16, b: u16) -> u16 {
65 \\ a * b
65 \\ return a * b;
6666 \\}
6767 );
6868
......@@ -76,7 +76,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
7676 \\ if (x == 32767) return error.Whatever;
7777 \\}
7878 \\fn neg(a: i16) -> i16 {
79 \\ -a
79 \\ return -a;
8080 \\}
8181 );
8282
......@@ -90,7 +90,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
9090 \\ if (x == 32767) return error.Whatever;
9191 \\}
9292 \\fn div(a: i16, b: i16) -> i16 {
93 \\ @divTrunc(a, b)
93 \\ return @divTrunc(a, b);
9494 \\}
9595 );
9696
......@@ -104,7 +104,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
104104 \\ if (x == 0) return error.Whatever;
105105 \\}
106106 \\fn shl(a: i16, b: u4) -> i16 {
107 \\ @shlExact(a, b)
107 \\ return @shlExact(a, b);
108108 \\}
109109 );
110110
......@@ -118,7 +118,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
118118 \\ if (x == 0) return error.Whatever;
119119 \\}
120120 \\fn shl(a: u16, b: u4) -> u16 {
121 \\ @shlExact(a, b)
121 \\ return @shlExact(a, b);
122122 \\}
123123 );
124124
......@@ -132,7 +132,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
132132 \\ if (x == 0) return error.Whatever;
133133 \\}
134134 \\fn shr(a: i16, b: u4) -> i16 {
135 \\ @shrExact(a, b)
135 \\ return @shrExact(a, b);
136136 \\}
137137 );
138138
......@@ -146,7 +146,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
146146 \\ if (x == 0) return error.Whatever;
147147 \\}
148148 \\fn shr(a: u16, b: u4) -> u16 {
149 \\ @shrExact(a, b)
149 \\ return @shrExact(a, b);
150150 \\}
151151 );
152152
......@@ -159,7 +159,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
159159 \\ const x = div0(999, 0);
160160 \\}
161161 \\fn div0(a: i32, b: i32) -> i32 {
162 \\ @divTrunc(a, b)
162 \\ return @divTrunc(a, b);
163163 \\}
164164 );
165165
......@@ -173,7 +173,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
173173 \\ if (x == 0) return error.Whatever;
174174 \\}
175175 \\fn divExact(a: i32, b: i32) -> i32 {
176 \\ @divExact(a, b)
176 \\ return @divExact(a, b);
177177 \\}
178178 );
179179
......@@ -187,7 +187,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
187187 \\ if (x.len == 0) return error.Whatever;
188188 \\}
189189 \\fn widenSlice(slice: []align(1) const u8) -> []align(1) const i32 {
190 \\ ([]align(1) const i32)(slice)
190 \\ return ([]align(1) const i32)(slice);
191191 \\}
192192 );
193193
......@@ -201,7 +201,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
201201 \\ if (x == 0) return error.Whatever;
202202 \\}
203203 \\fn shorten_cast(x: i32) -> i8 {
204 \\ i8(x)
204 \\ return i8(x);
205205 \\}
206206 );
207207
......@@ -215,7 +215,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
215215 \\ if (x == 0) return error.Whatever;
216216 \\}
217217 \\fn unsigned_cast(x: i32) -> u32 {
218 \\ u32(x)
218 \\ return u32(x);
219219 \\}
220220 );
221221
test/standalone/pkg_import/pkg.zig+1-1
......@@ -1 +1 @@
1pub fn add(a: i32, b: i32) -> i32 { a + b }
1pub fn add(a: i32, b: i32) -> i32 { return a + b; }
test/tests.zig+3-3
......@@ -284,7 +284,7 @@ pub const CompareOutputContext = struct {
284284 warn("Process {} terminated unexpectedly\n", full_exe_path);
285285 return error.TestFailed;
286286 },
287 };
287 }
288288
289289
290290 if (!mem.eql(u8, self.expected_output, stdout.toSliceConst())) {
......@@ -615,7 +615,7 @@ pub const CompileErrorContext = struct {
615615 warn("Process {} terminated unexpectedly\n", b.zig_exe);
616616 return error.TestFailed;
617617 },
618 };
618 }
619619
620620
621621 const stdout = stdout_buf.toSliceConst();
......@@ -891,7 +891,7 @@ pub const TranslateCContext = struct {
891891 warn("Compilation terminated unexpectedly\n");
892892 return error.TestFailed;
893893 },
894 };
894 }
895895
896896 const stdout = stdout_buf.toSliceConst();
897897 const stderr = stderr_buf.toSliceConst();
test/translate_c.zig+55-55
......@@ -203,13 +203,13 @@ pub fn addCases(cases: &tests.TranslateCContext) {
203203 \\pub extern var fn_ptr: ?extern fn();
204204 ,
205205 \\pub inline fn foo() {
206 \\ (??fn_ptr)()
206 \\ return (??fn_ptr)();
207207 \\}
208208 ,
209209 \\pub extern var fn_ptr2: ?extern fn(c_int, f32) -> u8;
210210 ,
211211 \\pub inline fn bar(arg0: c_int, arg1: f32) -> u8 {
212 \\ (??fn_ptr2)(arg0, arg1)
212 \\ return (??fn_ptr2)(arg0, arg1);
213213 \\}
214214 );
215215
......@@ -475,10 +475,10 @@ pub fn addCases(cases: &tests.TranslateCContext) {
475475 \\pub export fn max(a: c_int) {
476476 \\ var b: c_int;
477477 \\ var c: c_int;
478 \\ c = {
478 \\ c = x: {
479479 \\ const _tmp = a;
480480 \\ b = _tmp;
481 \\ _tmp
481 \\ break :x _tmp;
482482 \\ };
483483 \\}
484484 );
......@@ -613,9 +613,9 @@ pub fn addCases(cases: &tests.TranslateCContext) {
613613 \\}
614614 ,
615615 \\pub export fn foo() -> c_int {
616 \\ return {
616 \\ return x: {
617617 \\ _ = 1;
618 \\ 2
618 \\ break :x 2;
619619 \\ };
620620 \\}
621621 );
......@@ -645,45 +645,45 @@ pub fn addCases(cases: &tests.TranslateCContext) {
645645 ,
646646 \\pub export fn foo() {
647647 \\ var a: c_int = 0;
648 \\ a += {
648 \\ a += x: {
649649 \\ const _ref = &a;
650650 \\ (*_ref) = ((*_ref) + 1);
651 \\ *_ref
651 \\ break :x *_ref;
652652 \\ };
653 \\ a -= {
653 \\ a -= x: {
654654 \\ const _ref = &a;
655655 \\ (*_ref) = ((*_ref) - 1);
656 \\ *_ref
656 \\ break :x *_ref;
657657 \\ };
658 \\ a *= {
658 \\ a *= x: {
659659 \\ const _ref = &a;
660660 \\ (*_ref) = ((*_ref) * 1);
661 \\ *_ref
661 \\ break :x *_ref;
662662 \\ };
663 \\ a &= {
663 \\ a &= x: {
664664 \\ const _ref = &a;
665665 \\ (*_ref) = ((*_ref) & 1);
666 \\ *_ref
666 \\ break :x *_ref;
667667 \\ };
668 \\ a |= {
668 \\ a |= x: {
669669 \\ const _ref = &a;
670670 \\ (*_ref) = ((*_ref) | 1);
671 \\ *_ref
671 \\ break :x *_ref;
672672 \\ };
673 \\ a ^= {
673 \\ a ^= x: {
674674 \\ const _ref = &a;
675675 \\ (*_ref) = ((*_ref) ^ 1);
676 \\ *_ref
676 \\ break :x *_ref;
677677 \\ };
678 \\ a >>= @import("std").math.Log2Int(c_int)({
678 \\ a >>= @import("std").math.Log2Int(c_int)(x: {
679679 \\ const _ref = &a;
680680 \\ (*_ref) = ((*_ref) >> @import("std").math.Log2Int(c_int)(1));
681 \\ *_ref
681 \\ break :x *_ref;
682682 \\ });
683 \\ a <<= @import("std").math.Log2Int(c_int)({
683 \\ a <<= @import("std").math.Log2Int(c_int)(x: {
684684 \\ const _ref = &a;
685685 \\ (*_ref) = ((*_ref) << @import("std").math.Log2Int(c_int)(1));
686 \\ *_ref
686 \\ break :x *_ref;
687687 \\ });
688688 \\}
689689 );
......@@ -703,45 +703,45 @@ pub fn addCases(cases: &tests.TranslateCContext) {
703703 ,
704704 \\pub export fn foo() {
705705 \\ var a: c_uint = c_uint(0);
706 \\ a +%= {
706 \\ a +%= x: {
707707 \\ const _ref = &a;
708708 \\ (*_ref) = ((*_ref) +% c_uint(1));
709 \\ *_ref
709 \\ break :x *_ref;
710710 \\ };
711 \\ a -%= {
711 \\ a -%= x: {
712712 \\ const _ref = &a;
713713 \\ (*_ref) = ((*_ref) -% c_uint(1));
714 \\ *_ref
714 \\ break :x *_ref;
715715 \\ };
716 \\ a *%= {
716 \\ a *%= x: {
717717 \\ const _ref = &a;
718718 \\ (*_ref) = ((*_ref) *% c_uint(1));
719 \\ *_ref
719 \\ break :x *_ref;
720720 \\ };
721 \\ a &= {
721 \\ a &= x: {
722722 \\ const _ref = &a;
723723 \\ (*_ref) = ((*_ref) & c_uint(1));
724 \\ *_ref
724 \\ break :x *_ref;
725725 \\ };
726 \\ a |= {
726 \\ a |= x: {
727727 \\ const _ref = &a;
728728 \\ (*_ref) = ((*_ref) | c_uint(1));
729 \\ *_ref
729 \\ break :x *_ref;
730730 \\ };
731 \\ a ^= {
731 \\ a ^= x: {
732732 \\ const _ref = &a;
733733 \\ (*_ref) = ((*_ref) ^ c_uint(1));
734 \\ *_ref
734 \\ break :x *_ref;
735735 \\ };
736 \\ a >>= @import("std").math.Log2Int(c_uint)({
736 \\ a >>= @import("std").math.Log2Int(c_uint)(x: {
737737 \\ const _ref = &a;
738738 \\ (*_ref) = ((*_ref) >> @import("std").math.Log2Int(c_uint)(1));
739 \\ *_ref
739 \\ break :x *_ref;
740740 \\ });
741 \\ a <<= @import("std").math.Log2Int(c_uint)({
741 \\ a <<= @import("std").math.Log2Int(c_uint)(x: {
742742 \\ const _ref = &a;
743743 \\ (*_ref) = ((*_ref) << @import("std").math.Log2Int(c_uint)(1));
744 \\ *_ref
744 \\ break :x *_ref;
745745 \\ });
746746 \\}
747747 );
......@@ -778,29 +778,29 @@ pub fn addCases(cases: &tests.TranslateCContext) {
778778 \\ i -= 1;
779779 \\ u +%= 1;
780780 \\ u -%= 1;
781 \\ i = {
781 \\ i = x: {
782782 \\ const _ref = &i;
783783 \\ const _tmp = *_ref;
784784 \\ (*_ref) += 1;
785 \\ _tmp
785 \\ break :x _tmp;
786786 \\ };
787 \\ i = {
787 \\ i = x: {
788788 \\ const _ref = &i;
789789 \\ const _tmp = *_ref;
790790 \\ (*_ref) -= 1;
791 \\ _tmp
791 \\ break :x _tmp;
792792 \\ };
793 \\ u = {
793 \\ u = x: {
794794 \\ const _ref = &u;
795795 \\ const _tmp = *_ref;
796796 \\ (*_ref) +%= 1;
797 \\ _tmp
797 \\ break :x _tmp;
798798 \\ };
799 \\ u = {
799 \\ u = x: {
800800 \\ const _ref = &u;
801801 \\ const _tmp = *_ref;
802802 \\ (*_ref) -%= 1;
803 \\ _tmp
803 \\ break :x _tmp;
804804 \\ };
805805 \\}
806806 );
......@@ -826,25 +826,25 @@ pub fn addCases(cases: &tests.TranslateCContext) {
826826 \\ i -= 1;
827827 \\ u +%= 1;
828828 \\ u -%= 1;
829 \\ i = {
829 \\ i = x: {
830830 \\ const _ref = &i;
831831 \\ (*_ref) += 1;
832 \\ *_ref
832 \\ break :x *_ref;
833833 \\ };
834 \\ i = {
834 \\ i = x: {
835835 \\ const _ref = &i;
836836 \\ (*_ref) -= 1;
837 \\ *_ref
837 \\ break :x *_ref;
838838 \\ };
839 \\ u = {
839 \\ u = x: {
840840 \\ const _ref = &u;
841841 \\ (*_ref) +%= 1;
842 \\ *_ref
842 \\ break :x *_ref;
843843 \\ };
844 \\ u = {
844 \\ u = x: {
845845 \\ const _ref = &u;
846846 \\ (*_ref) -%= 1;
847 \\ *_ref
847 \\ break :x *_ref;
848848 \\ };
849849 \\}
850850 );
......@@ -1037,7 +1037,7 @@ pub fn addCases(cases: &tests.TranslateCContext) {
10371037 \\pub const glClearPFN = PFNGLCLEARPROC;
10381038 ,
10391039 \\pub inline fn glClearUnion(arg0: GLbitfield) {
1040 \\ (??glProcs.gl.Clear)(arg0)
1040 \\ return (??glProcs.gl.Clear)(arg0);
10411041 \\}
10421042 ,
10431043 \\pub const OpenGLProcs = union_OpenGLProcs;