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) {...@@ -49,7 +49,7 @@ fn gen(in: &io.InStream, out: &io.OutStream) {
49 if (err == error.EndOfStream) {49 if (err == error.EndOfStream) {
50 return;50 return;
51 }51 }
52 std.debug.panic("{}", err)52 std.debug.panic("{}", err);
53 };53 };
54 switch (state) {54 switch (state) {
55 State.Start => switch (byte) {55 State.Start => switch (byte) {
doc/langref.html.in+2-3
...@@ -3021,14 +3021,13 @@ const assert = @import("std").debug.assert;</code></pre>...@@ -3021,14 +3021,13 @@ const assert = @import("std").debug.assert;</code></pre>
3021 <pre><code class="zig">const assert = @import("std").debug.assert;3021 <pre><code class="zig">const assert = @import("std").debug.assert;
30223022
3023// Functions are declared like this3023// Functions are declared like this
3024// The last expression in the function can be used as the return value.
3025fn add(a: i8, b: i8) -&gt; i8 {3024fn add(a: i8, b: i8) -&gt; i8 {
3026 if (a == 0) {3025 if (a == 0) {
3027 // You can still return manually if needed.3026 // You can still return manually if needed.
3028 return b;3027 return b;
3029 }3028 }
30303029
3031 a + b3030 return a + b;
3032}3031}
30333032
3034// The export specifier makes a function externally visible in the generated3033// The export specifier makes a function externally visible in the generated
...@@ -5847,7 +5846,7 @@ ParamDeclList = "(" list(ParamDecl, ",") ")"...@@ -5847,7 +5846,7 @@ ParamDeclList = "(" list(ParamDecl, ",") ")"
58475846
5848ParamDecl = option("noalias" | "comptime") option(Symbol ":") (TypeExpr | "...")5847ParamDecl = option("noalias" | "comptime") option(Symbol ":") (TypeExpr | "...")
58495848
5850Block = option(Symbol ":") "{" many(Statement) option(Expression) "}"5849Block = option(Symbol ":") "{" many(Statement) "}"
58515850
5852Statement = LocalVarDecl ";" | Defer(Block) | Defer(Expression) ";" | BlockExpression(Block) | Expression ";" | ";"5851Statement = LocalVarDecl ";" | Defer(Block) | Defer(Expression) ";" | BlockExpression(Block) | Expression ";" | ";"
58535852
example/shared_library/mathtest.zig+1-1
...@@ -1,3 +1,3 @@...@@ -1,3 +1,3 @@
1export fn add(a: i32, b: i32) -> i32 {1export fn add(a: i32, b: i32) -> i32 {
2 a + b2 return a + b;
3}3}
src-self-hosted/parser.zig+12-12
...@@ -111,11 +111,11 @@ pub const Parser = struct {...@@ -111,11 +111,11 @@ pub const Parser = struct {
111 }111 }
112112
113 pub fn parse(self: &Parser) -> %&ast.NodeRoot {113 pub fn parse(self: &Parser) -> %&ast.NodeRoot {
114 const result = self.parseInner() %% |err| {114 const result = self.parseInner() %% |err| x: {
115 if (self.cleanup_root_node) |root_node| {115 if (self.cleanup_root_node) |root_node| {
116 self.freeAst(root_node);116 self.freeAst(root_node);
117 }117 }
118 err118 break :x err;
119 };119 };
120 self.cleanup_root_node = null;120 self.cleanup_root_node = null;
121 return result;121 return result;
...@@ -125,12 +125,12 @@ pub const Parser = struct {...@@ -125,12 +125,12 @@ pub const Parser = struct {
125 var stack = self.initUtilityArrayList(State);125 var stack = self.initUtilityArrayList(State);
126 defer self.deinitUtilityArrayList(stack);126 defer self.deinitUtilityArrayList(stack);
127127
128 const root_node = {128 const root_node = x: {
129 const root_node = %return self.createRoot();129 const root_node = %return self.createRoot();
130 %defer self.allocator.destroy(root_node);130 %defer self.allocator.destroy(root_node);
131 // This stack append has to succeed for freeAst to work131 // This stack append has to succeed for freeAst to work
132 %return stack.append(State.TopLevel);132 %return stack.append(State.TopLevel);
133 root_node133 break :x root_node;
134 };134 };
135 assert(self.cleanup_root_node == null);135 assert(self.cleanup_root_node == null);
136 self.cleanup_root_node = root_node;136 self.cleanup_root_node = root_node;
...@@ -462,7 +462,7 @@ pub const Parser = struct {...@@ -462,7 +462,7 @@ pub const Parser = struct {
462 } else if (token.id == Token.Id.Keyword_noalias) {462 } else if (token.id == Token.Id.Keyword_noalias) {
463 param_decl.noalias_token = token;463 param_decl.noalias_token = token;
464 token = self.getNextToken();464 token = self.getNextToken();
465 };465 }
466 if (token.id == Token.Id.Identifier) {466 if (token.id == Token.Id.Identifier) {
467 const next_token = self.getNextToken();467 const next_token = self.getNextToken();
468 if (next_token.id == Token.Id.Colon) {468 if (next_token.id == Token.Id.Colon) {
...@@ -793,14 +793,14 @@ pub const Parser = struct {...@@ -793,14 +793,14 @@ pub const Parser = struct {
793 }793 }
794794
795 fn getNextToken(self: &Parser) -> Token {795 fn getNextToken(self: &Parser) -> Token {
796 return if (self.put_back_count != 0) {796 if (self.put_back_count != 0) {
797 const put_back_index = self.put_back_count - 1;797 const put_back_index = self.put_back_count - 1;
798 const put_back_token = self.put_back_tokens[put_back_index];798 const put_back_token = self.put_back_tokens[put_back_index];
799 self.put_back_count = put_back_index;799 self.put_back_count = put_back_index;
800 put_back_token800 return put_back_token;
801 } else {801 } else {
802 self.tokenizer.next()802 return self.tokenizer.next();
803 };803 }
804 }804 }
805805
806 const RenderAstFrame = struct {806 const RenderAstFrame = struct {
...@@ -873,7 +873,7 @@ pub const Parser = struct {...@@ -873,7 +873,7 @@ pub const Parser = struct {
873 Token.Id.Keyword_pub => %return stream.print("pub "),873 Token.Id.Keyword_pub => %return stream.print("pub "),
874 Token.Id.Keyword_export => %return stream.print("export "),874 Token.Id.Keyword_export => %return stream.print("export "),
875 else => unreachable,875 else => unreachable,
876 };876 }
877 }877 }
878 if (fn_proto.extern_token) |extern_token| {878 if (fn_proto.extern_token) |extern_token| {
879 %return stream.print("{} ", self.tokenizer.getTokenSlice(extern_token));879 %return stream.print("{} ", self.tokenizer.getTokenSlice(extern_token));
...@@ -1102,7 +1102,7 @@ fn testParse(source: []const u8, allocator: &mem.Allocator) -> %[]u8 {...@@ -1102,7 +1102,7 @@ fn testParse(source: []const u8, allocator: &mem.Allocator) -> %[]u8 {
1102// TODO test for memory leaks1102// TODO test for memory leaks
1103// TODO test for valid frees1103// TODO test for valid frees
1104fn testCanonical(source: []const u8) {1104fn testCanonical(source: []const u8) {
1105 const needed_alloc_count = {1105 const needed_alloc_count = x: {
1106 // Try it once with unlimited memory, make sure it works1106 // Try it once with unlimited memory, make sure it works
1107 var fixed_allocator = mem.FixedBufferAllocator.init(fixed_buffer_mem[0..]);1107 var fixed_allocator = mem.FixedBufferAllocator.init(fixed_buffer_mem[0..]);
1108 var failing_allocator = std.debug.FailingAllocator.init(&fixed_allocator.allocator, @maxValue(usize));1108 var failing_allocator = std.debug.FailingAllocator.init(&fixed_allocator.allocator, @maxValue(usize));
...@@ -1116,7 +1116,7 @@ fn testCanonical(source: []const u8) {...@@ -1116,7 +1116,7 @@ fn testCanonical(source: []const u8) {
1116 @panic("test failed");1116 @panic("test failed");
1117 }1117 }
1118 failing_allocator.allocator.free(result_source);1118 failing_allocator.allocator.free(result_source);
1119 failing_allocator.index1119 break :x failing_allocator.index;
1120 };1120 };
11211121
1122 // TODO make this pass1122 // TODO make this pass
src/all_types.hpp+6-10
...@@ -26,7 +26,6 @@ struct ScopeFnDef;...@@ -26,7 +26,6 @@ struct ScopeFnDef;
26struct TypeTableEntry;26struct TypeTableEntry;
27struct VariableTableEntry;27struct VariableTableEntry;
28struct ErrorTableEntry;28struct ErrorTableEntry;
29struct LabelTableEntry;
30struct BuiltinFnEntry;29struct BuiltinFnEntry;
31struct TypeStructField;30struct TypeStructField;
32struct CodeGen;31struct CodeGen;
...@@ -54,7 +53,6 @@ struct IrExecutable {...@@ -54,7 +53,6 @@ struct IrExecutable {
54 size_t *backward_branch_count;53 size_t *backward_branch_count;
55 size_t backward_branch_quota;54 size_t backward_branch_quota;
56 bool invalid;55 bool invalid;
57 ZigList<LabelTableEntry *> all_labels;
58 ZigList<IrGotoItem> goto_list;56 ZigList<IrGotoItem> goto_list;
59 bool is_inline;57 bool is_inline;
60 FnTableEntry *fn_entry;58 FnTableEntry *fn_entry;
...@@ -452,7 +450,6 @@ struct AstNodeParamDecl {...@@ -452,7 +450,6 @@ struct AstNodeParamDecl {
452struct AstNodeBlock {450struct AstNodeBlock {
453 Buf *name;451 Buf *name;
454 ZigList<AstNode *> statements;452 ZigList<AstNode *> statements;
455 bool last_statement_is_result_expression;
456};453};
457454
458enum ReturnKind {455enum ReturnKind {
...@@ -1644,12 +1641,6 @@ struct ErrorTableEntry {...@@ -1644,12 +1641,6 @@ struct ErrorTableEntry {
1644 ConstExprValue *cached_error_name_val;1641 ConstExprValue *cached_error_name_val;
1645};1642};
16461643
1647struct LabelTableEntry {
1648 AstNode *decl_node;
1649 IrBasicBlock *bb;
1650 bool used;
1651};
1652
1653enum ScopeId {1644enum ScopeId {
1654 ScopeIdDecls,1645 ScopeIdDecls,
1655 ScopeIdBlock,1646 ScopeIdBlock,
...@@ -1693,7 +1684,12 @@ struct ScopeDecls {...@@ -1693,7 +1684,12 @@ struct ScopeDecls {
1693struct ScopeBlock {1684struct ScopeBlock {
1694 Scope base;1685 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
1697 bool safety_off;1693 bool safety_off;
1698 AstNode *safety_set_node;1694 AstNode *safety_set_node;
1699 bool fast_math_off;1695 bool fast_math_off;
src/analyze.cpp+1-1
...@@ -110,7 +110,7 @@ ScopeBlock *create_block_scope(AstNode *node, Scope *parent) {...@@ -110,7 +110,7 @@ ScopeBlock *create_block_scope(AstNode *node, Scope *parent) {
110 assert(node->type == NodeTypeBlock);110 assert(node->type == NodeTypeBlock);
111 ScopeBlock *scope = allocate<ScopeBlock>(1);111 ScopeBlock *scope = allocate<ScopeBlock>(1);
112 init_scope(&scope->base, ScopeIdBlock, node, parent);112 init_scope(&scope->base, ScopeIdBlock, node, parent);
113 scope->label_table.init(1);113 scope->name = node->data.block.name;
114 return scope;114 return scope;
115}115}
116116
src/ast_render.cpp+1-4
...@@ -478,10 +478,7 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) {...@@ -478,10 +478,7 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) {
478 AstNode *statement = node->data.block.statements.at(i);478 AstNode *statement = node->data.block.statements.at(i);
479 print_indent(ar);479 print_indent(ar);
480 render_node_grouped(ar, statement);480 render_node_grouped(ar, statement);
481 if (!(i == node->data.block.statements.length - 1 &&481 fprintf(ar->f, ";");
482 node->data.block.last_statement_is_result_expression)) {
483 fprintf(ar->f, ";");
484 }
485 fprintf(ar->f, "\n");482 fprintf(ar->f, "\n");
486 }483 }
487 ar->indent -= ar->indent_size;484 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...@@ -3514,7 +3514,11 @@ static VariableTableEntry *ir_create_var(IrBuilder *irb, AstNode *node, Scope *s
3514static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode *block_node) {3514static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode *block_node) {
3515 assert(block_node->type == NodeTypeBlock);3515 assert(block_node->type == NodeTypeBlock);
35163516
3517 ZigList<IrInstruction *> incoming_values = {0};
3518 ZigList<IrBasicBlock *> incoming_blocks = {0};
3519
3517 ScopeBlock *scope_block = create_block_scope(block_node, parent_scope);3520 ScopeBlock *scope_block = create_block_scope(block_node, parent_scope);
3521
3518 Scope *outer_block_scope = &scope_block->base;3522 Scope *outer_block_scope = &scope_block->base;
3519 Scope *child_scope = outer_block_scope;3523 Scope *child_scope = outer_block_scope;
35203524
...@@ -3528,9 +3532,15 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode...@@ -3528,9 +3532,15 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode
3528 return ir_mark_gen(ir_build_const_void(irb, child_scope, block_node));3532 return ir_mark_gen(ir_build_const_void(irb, child_scope, block_node));
3529 }3533 }
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
3531 bool is_continuation_unreachable = false;3542 bool is_continuation_unreachable = false;
3532 IrInstruction *noreturn_return_value = nullptr;3543 IrInstruction *noreturn_return_value = nullptr;
3533 IrInstruction *return_value = nullptr;
3534 for (size_t i = 0; i < block_node->data.block.statements.length; i += 1) {3544 for (size_t i = 0; i < block_node->data.block.statements.length; i += 1) {
3535 AstNode *statement_node = block_node->data.block.statements.at(i);3545 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...@@ -3548,39 +3558,31 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode
3548 // variable declarations start a new scope3558 // variable declarations start a new scope
3549 IrInstructionDeclVar *decl_var_instruction = (IrInstructionDeclVar *)statement_value;3559 IrInstructionDeclVar *decl_var_instruction = (IrInstructionDeclVar *)statement_value;
3550 child_scope = decl_var_instruction->var->child_scope;3560 child_scope = decl_var_instruction->var->child_scope;
3551 } else {3561 } else if (statement_value != irb->codegen->invalid_instruction) {
3552 // label, defer, variable declaration will never be the result expression3562 // this statement's value must be void
3553 if (block_node->data.block.last_statement_is_result_expression &&3563 ir_mark_gen(ir_build_check_statement_is_void(irb, child_scope, statement_node, statement_value));
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 }
3563 }3564 }
3564 }3565 }
35653566
3566 if (is_continuation_unreachable) {3567 if (is_continuation_unreachable) {
3567 assert(noreturn_return_value != nullptr);3568 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)));
3569 }3575 }
3570 // control flow falls out of block
35713576
3572 if (block_node->data.block.last_statement_is_result_expression) {3577 if (block_node->data.block.name != nullptr) {
3573 // return value was determined by the last statement3578 ir_gen_defers_for_block(irb, child_scope, outer_block_scope, false);
3574 assert(return_value != nullptr);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);
3575 } else {3582 } else {
3576 // return value is implicitly void3583 ir_gen_defers_for_block(irb, child_scope, outer_block_scope, false);
3577 assert(return_value == nullptr);3584 return ir_mark_gen(ir_mark_gen(ir_build_const_void(irb, child_scope, block_node)));
3578 return_value = ir_mark_gen(ir_build_const_void(irb, child_scope, block_node));
3579 }3585 }
3580
3581 ir_gen_defers_for_block(irb, child_scope, outer_block_scope, false);
3582
3583 return return_value;
3584}3586}
35853587
3586static IrInstruction *ir_gen_bin_op_id(IrBuilder *irb, Scope *scope, AstNode *node, IrBinOp op_id) {3588static 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...@@ -5952,6 +5954,31 @@ static IrInstruction *ir_gen_comptime(IrBuilder *irb, Scope *parent_scope, AstNo
5952 return ir_gen_node_extra(irb, node->data.comptime_expr.expr, child_scope, lval);5954 return ir_gen_node_extra(irb, node->data.comptime_expr.expr, child_scope, lval);
5953}5955}
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
5955static IrInstruction *ir_gen_break(IrBuilder *irb, Scope *break_scope, AstNode *node) {5982static IrInstruction *ir_gen_break(IrBuilder *irb, Scope *break_scope, AstNode *node) {
5956 assert(node->type == NodeTypeBreak);5983 assert(node->type == NodeTypeBreak);
59575984
...@@ -5959,14 +5986,14 @@ static IrInstruction *ir_gen_break(IrBuilder *irb, Scope *break_scope, AstNode *...@@ -5959,14 +5986,14 @@ static IrInstruction *ir_gen_break(IrBuilder *irb, Scope *break_scope, AstNode *
5959 // * function definition scope or global scope => error, break outside loop5986 // * function definition scope or global scope => error, break outside loop
5960 // * defer expression scope => error, cannot break out of defer expression5987 // * defer expression scope => error, cannot break out of defer expression
5961 // * loop scope => OK5988 // * loop scope => OK
5989 // * (if it's a labeled break) labeled block => OK
59625990
5963 Scope *search_scope = break_scope;5991 Scope *search_scope = break_scope;
5964 ScopeLoop *loop_scope;5992 ScopeLoop *loop_scope;
5965 bool saw_any_loop_scope = false;
5966 for (;;) {5993 for (;;) {
5967 if (search_scope == nullptr || search_scope->id == ScopeIdFnDef) {5994 if (search_scope == nullptr || search_scope->id == ScopeIdFnDef) {
5968 if (saw_any_loop_scope) {5995 if (node->data.break_expr.name != nullptr) {
5969 add_node_error(irb->codegen, node, buf_sprintf("labeled loop not found: '%s'", buf_ptr(node->data.break_expr.name)));5996 add_node_error(irb->codegen, node, buf_sprintf("label not found: '%s'", buf_ptr(node->data.break_expr.name)));
5970 return irb->codegen->invalid_instruction;5997 return irb->codegen->invalid_instruction;
5971 } else {5998 } else {
5972 add_node_error(irb->codegen, node, buf_sprintf("break expression outside loop"));5999 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 *...@@ -5977,13 +6004,20 @@ static IrInstruction *ir_gen_break(IrBuilder *irb, Scope *break_scope, AstNode *
5977 return irb->codegen->invalid_instruction;6004 return irb->codegen->invalid_instruction;
5978 } else if (search_scope->id == ScopeIdLoop) {6005 } else if (search_scope->id == ScopeIdLoop) {
5979 ScopeLoop *this_loop_scope = (ScopeLoop *)search_scope;6006 ScopeLoop *this_loop_scope = (ScopeLoop *)search_scope;
5980 saw_any_loop_scope = true;
5981 if (node->data.break_expr.name == nullptr ||6007 if (node->data.break_expr.name == nullptr ||
5982 (this_loop_scope->name != nullptr && buf_eql_buf(node->data.break_expr.name, this_loop_scope->name)))6008 (this_loop_scope->name != nullptr && buf_eql_buf(node->data.break_expr.name, this_loop_scope->name)))
5983 {6009 {
5984 loop_scope = this_loop_scope;6010 loop_scope = this_loop_scope;
5985 break;6011 break;
5986 }6012 }
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 }
5987 }6021 }
5988 search_scope = search_scope->parent;6022 search_scope = search_scope->parent;
5989 }6023 }
...@@ -6022,10 +6056,9 @@ static IrInstruction *ir_gen_continue(IrBuilder *irb, Scope *continue_scope, Ast...@@ -6022,10 +6056,9 @@ static IrInstruction *ir_gen_continue(IrBuilder *irb, Scope *continue_scope, Ast
60226056
6023 Scope *search_scope = continue_scope;6057 Scope *search_scope = continue_scope;
6024 ScopeLoop *loop_scope;6058 ScopeLoop *loop_scope;
6025 bool saw_any_loop_scope = false;
6026 for (;;) {6059 for (;;) {
6027 if (search_scope == nullptr || search_scope->id == ScopeIdFnDef) {6060 if (search_scope == nullptr || search_scope->id == ScopeIdFnDef) {
6028 if (saw_any_loop_scope) {6061 if (node->data.continue_expr.name != nullptr) {
6029 add_node_error(irb->codegen, node, buf_sprintf("labeled loop not found: '%s'", buf_ptr(node->data.continue_expr.name)));6062 add_node_error(irb->codegen, node, buf_sprintf("labeled loop not found: '%s'", buf_ptr(node->data.continue_expr.name)));
6030 return irb->codegen->invalid_instruction;6063 return irb->codegen->invalid_instruction;
6031 } else {6064 } else {
...@@ -6037,7 +6070,6 @@ static IrInstruction *ir_gen_continue(IrBuilder *irb, Scope *continue_scope, Ast...@@ -6037,7 +6070,6 @@ static IrInstruction *ir_gen_continue(IrBuilder *irb, Scope *continue_scope, Ast
6037 return irb->codegen->invalid_instruction;6070 return irb->codegen->invalid_instruction;
6038 } else if (search_scope->id == ScopeIdLoop) {6071 } else if (search_scope->id == ScopeIdLoop) {
6039 ScopeLoop *this_loop_scope = (ScopeLoop *)search_scope;6072 ScopeLoop *this_loop_scope = (ScopeLoop *)search_scope;
6040 saw_any_loop_scope = true;
6041 if (node->data.continue_expr.name == nullptr ||6073 if (node->data.continue_expr.name == nullptr ||
6042 (this_loop_scope->name != nullptr && buf_eql_buf(node->data.continue_expr.name, this_loop_scope->name)))6074 (this_loop_scope->name != nullptr && buf_eql_buf(node->data.continue_expr.name, this_loop_scope->name)))
6043 {6075 {
src/parser.cpp+20-33
...@@ -748,7 +748,14 @@ static AstNode *ast_parse_primary_expr(ParseContext *pc, size_t *token_index, bo...@@ -748,7 +748,14 @@ static AstNode *ast_parse_primary_expr(ParseContext *pc, size_t *token_index, bo
748 node->data.fn_call_expr.is_builtin = true;748 node->data.fn_call_expr.is_builtin = true;
749749
750 return node;750 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) {
752 *token_index += 1;759 *token_index += 1;
753 AstNode *node = ast_create_node(pc, NodeTypeSymbol, token);760 AstNode *node = ast_create_node(pc, NodeTypeSymbol, token);
754 node->data.symbol_expr.symbol = token_buf(token);761 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...@@ -760,11 +767,6 @@ static AstNode *ast_parse_primary_expr(ParseContext *pc, size_t *token_index, bo
760 return grouped_expr_node;767 return grouped_expr_node;
761 }768 }
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
768 AstNode *array_type_node = ast_parse_array_type_expr(pc, token_index, false);770 AstNode *array_type_node = ast_parse_array_type_expr(pc, token_index, false);
769 if (array_type_node) {771 if (array_type_node) {
770 return array_type_node;772 return array_type_node;
...@@ -2145,9 +2147,6 @@ static AstNode *ast_parse_expression(ParseContext *pc, size_t *token_index, bool...@@ -2145,9 +2147,6 @@ static AstNode *ast_parse_expression(ParseContext *pc, size_t *token_index, bool
2145 return nullptr;2147 return nullptr;
2146}2148}
21472149
2148/*
2149Label: token(Symbol) token(Colon)
2150*/
2151static bool statement_terminates_without_semicolon(AstNode *node) {2150static bool statement_terminates_without_semicolon(AstNode *node) {
2152 switch (node->type) {2151 switch (node->type) {
2153 case NodeTypeIfBoolExpr:2152 case NodeTypeIfBoolExpr:
...@@ -2179,7 +2178,7 @@ static bool statement_terminates_without_semicolon(AstNode *node) {...@@ -2179,7 +2178,7 @@ static bool statement_terminates_without_semicolon(AstNode *node) {
2179}2178}
21802179
2181/*2180/*
2182Block = option(Symbol ":") "{" many(Statement) option(Expression) "}"2181Block = option(Symbol ":") "{" many(Statement) "}"
2183Statement = Label | VariableDeclaration ";" | Defer(Block) | Defer(Expression) ";" | BlockExpression(Block) | Expression ";" | ";" | ExportDecl2182Statement = Label | VariableDeclaration ";" | Defer(Block) | Defer(Expression) ";" | BlockExpression(Block) | Expression ";" | ";" | ExportDecl
2184*/2183*/
2185static AstNode *ast_parse_block(ParseContext *pc, size_t *token_index, bool mandatory) {2184static 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...@@ -2220,6 +2219,12 @@ static AstNode *ast_parse_block(ParseContext *pc, size_t *token_index, bool mand
2220 }2219 }
22212220
2222 for (;;) {2221 for (;;) {
2222 last_token = &pc->tokens->at(*token_index);
2223 if (last_token->id == TokenIdRBrace) {
2224 *token_index += 1;
2225 return node;
2226 }
2227
2223 AstNode *statement_node = ast_parse_local_var_decl(pc, token_index);2228 AstNode *statement_node = ast_parse_local_var_decl(pc, token_index);
2224 if (!statement_node)2229 if (!statement_node)
2225 statement_node = ast_parse_defer_expr(pc, token_index);2230 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...@@ -2228,32 +2233,14 @@ static AstNode *ast_parse_block(ParseContext *pc, size_t *token_index, bool mand
2228 if (!statement_node)2233 if (!statement_node)
2229 statement_node = ast_parse_expression(pc, token_index, false);2234 statement_node = ast_parse_expression(pc, token_index, false);
22302235
2231 bool semicolon_expected = true;2236 if (!statement_node) {
2232 if (statement_node) {2237 ast_invalid_token_error(pc, last_token);
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 }
2243 }2238 }
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);2242 if (!statement_terminates_without_semicolon(statement_node)) {
2248 if (last_token->id == TokenIdRBrace) {2243 ast_eat_token(pc, token_index, TokenIdSemicolon);
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);
2257 }2244 }
2258 }2245 }
2259 zig_unreachable();2246 zig_unreachable();
src/translate_c.cpp+54-32
...@@ -171,6 +171,20 @@ static AstNode * trans_create_node(Context *c, NodeType id) {...@@ -171,6 +171,20 @@ static AstNode * trans_create_node(Context *c, NodeType id) {
171 return node;171 return node;
172}172}
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
174static AstNode *trans_create_node_if(Context *c, AstNode *cond_node, AstNode *then_node, AstNode *else_node) {188static AstNode *trans_create_node_if(Context *c, AstNode *cond_node, AstNode *then_node, AstNode *else_node) {
175 AstNode *node = trans_create_node(c, NodeTypeIfBoolExpr);189 AstNode *node = trans_create_node(c, NodeTypeIfBoolExpr);
176 node->data.if_bool_expr.condition = cond_node;190 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...@@ -372,8 +386,7 @@ static AstNode *trans_create_node_inline_fn(Context *c, Buf *fn_name, AstNode *r
372386
373 AstNode *block = trans_create_node(c, NodeTypeBlock);387 AstNode *block = trans_create_node(c, NodeTypeBlock);
374 block->data.block.statements.resize(1);388 block->data.block.statements.resize(1);
375 block->data.block.statements.items[0] = fn_call_node;389 block->data.block.statements.items[0] = trans_create_node_return(c, fn_call_node);
376 block->data.block.last_statement_is_result_expression = true;
377390
378 fn_def->data.fn_def.body = block;391 fn_def->data.fn_def.body = block;
379 return fn_def;392 return fn_def;
...@@ -1140,13 +1153,15 @@ static AstNode *trans_create_assign(Context *c, ResultUsed result_used, TransSco...@@ -1140,13 +1153,15 @@ static AstNode *trans_create_assign(Context *c, ResultUsed result_used, TransSco
1140 } else {1153 } else {
1141 // worst case1154 // worst case
1142 // c: lhs = rhs1155 // c: lhs = rhs
1143 // zig: {1156 // zig: x: {
1144 // zig: const _tmp = rhs;1157 // zig: const _tmp = rhs;
1145 // zig: lhs = _tmp;1158 // zig: lhs = _tmp;
1146 // zig: _tmp1159 // zig: break :x _tmp
1147 // zig: }1160 // zig: }
11481161
1149 TransScopeBlock *child_scope = trans_scope_block_create(c, scope);1162 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
1151 // const _tmp = rhs;1166 // const _tmp = rhs;
1152 AstNode *rhs_node = trans_expr(c, ResultUsedYes, &child_scope->base, rhs, TransRValue);1167 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...@@ -1163,9 +1178,9 @@ static AstNode *trans_create_assign(Context *c, ResultUsed result_used, TransSco
1163 trans_create_node_bin_op(c, lhs_node, BinOpTypeAssign,1178 trans_create_node_bin_op(c, lhs_node, BinOpTypeAssign,
1164 trans_create_node_symbol(c, tmp_var_name)));1179 trans_create_node_symbol(c, tmp_var_name)));
11651180
1166 // _tmp1181 // break :x _tmp
1167 child_scope->node->data.block.statements.append(trans_create_node_symbol(c, tmp_var_name));1182 AstNode *tmp_symbol_node = trans_create_node_symbol(c, tmp_var_name);
1168 child_scope->node->data.block.last_statement_is_result_expression = true;1183 child_scope->node->data.block.statements.append(trans_create_node_break(c, label_name, tmp_symbol_node));
11691184
1170 return child_scope->node;1185 return child_scope->node;
1171 }1186 }
...@@ -1270,6 +1285,9 @@ static AstNode *trans_binary_operator(Context *c, ResultUsed result_used, TransS...@@ -1270,6 +1285,9 @@ static AstNode *trans_binary_operator(Context *c, ResultUsed result_used, TransS
1270 case BO_Comma:1285 case BO_Comma:
1271 {1286 {
1272 TransScopeBlock *scope_block = trans_scope_block_create(c, scope);1287 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
1273 AstNode *lhs = trans_expr(c, ResultUsedNo, &scope_block->base, stmt->getLHS(), TransRValue);1291 AstNode *lhs = trans_expr(c, ResultUsedNo, &scope_block->base, stmt->getLHS(), TransRValue);
1274 if (lhs == nullptr)1292 if (lhs == nullptr)
1275 return nullptr;1293 return nullptr;
...@@ -1278,9 +1296,7 @@ static AstNode *trans_binary_operator(Context *c, ResultUsed result_used, TransS...@@ -1278,9 +1296,7 @@ static AstNode *trans_binary_operator(Context *c, ResultUsed result_used, TransS
1278 AstNode *rhs = trans_expr(c, result_used, &scope_block->base, stmt->getRHS(), TransRValue);1296 AstNode *rhs = trans_expr(c, result_used, &scope_block->base, stmt->getRHS(), TransRValue);
1279 if (rhs == nullptr)1297 if (rhs == nullptr)
1280 return nullptr;1298 return nullptr;
1281 scope_block->node->data.block.statements.append(maybe_suppress_result(c, result_used, rhs));1299 scope_block->node->data.block.statements.append(trans_create_node_break(c, label_name, maybe_suppress_result(c, result_used, rhs)));
1282
1283 scope_block->node->data.block.last_statement_is_result_expression = true;
1284 return scope_block->node;1300 return scope_block->node;
1285 }1301 }
1286 case BO_MulAssign:1302 case BO_MulAssign:
...@@ -1320,14 +1336,16 @@ static AstNode *trans_create_compound_assign_shift(Context *c, ResultUsed result...@@ -1320,14 +1336,16 @@ static AstNode *trans_create_compound_assign_shift(Context *c, ResultUsed result
1320 } else {1336 } else {
1321 // need more complexity. worst case, this looks like this:1337 // need more complexity. worst case, this looks like this:
1322 // c: lhs >>= rhs1338 // c: lhs >>= rhs
1323 // zig: {1339 // zig: x: {
1324 // zig: const _ref = &lhs;1340 // zig: const _ref = &lhs;
1325 // zig: *_ref = result_type(operation_type(*_ref) >> u5(rhs));1341 // zig: *_ref = result_type(operation_type(*_ref) >> u5(rhs));
1326 // zig: *_ref1342 // zig: break :x *_ref
1327 // zig: }1343 // zig: }
1328 // where u5 is the appropriate type1344 // where u5 is the appropriate type
13291345
1330 TransScopeBlock *child_scope = trans_scope_block_create(c, scope);1346 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
1332 // const _ref = &lhs;1350 // const _ref = &lhs;
1333 AstNode *lhs = trans_expr(c, ResultUsedYes, &child_scope->base, stmt->getLHS(), TransLValue);1351 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...@@ -1369,11 +1387,11 @@ static AstNode *trans_create_compound_assign_shift(Context *c, ResultUsed result
1369 child_scope->node->data.block.statements.append(assign_statement);1387 child_scope->node->data.block.statements.append(assign_statement);
13701388
1371 if (result_used == ResultUsedYes) {1389 if (result_used == ResultUsedYes) {
1372 // *_ref1390 // break :x *_ref
1373 child_scope->node->data.block.statements.append(1391 child_scope->node->data.block.statements.append(
1374 trans_create_node_prefix_op(c, PrefixOpDereference,1392 trans_create_node_break(c, label_name,
1375 trans_create_node_symbol(c, tmp_var_name)));1393 trans_create_node_prefix_op(c, PrefixOpDereference,
1376 child_scope->node->data.block.last_statement_is_result_expression = true;1394 trans_create_node_symbol(c, tmp_var_name))));
1377 }1395 }
13781396
1379 return child_scope->node;1397 return child_scope->node;
...@@ -1394,13 +1412,15 @@ static AstNode *trans_create_compound_assign(Context *c, ResultUsed result_used,...@@ -1394,13 +1412,15 @@ static AstNode *trans_create_compound_assign(Context *c, ResultUsed result_used,
1394 } else {1412 } else {
1395 // need more complexity. worst case, this looks like this:1413 // need more complexity. worst case, this looks like this:
1396 // c: lhs += rhs1414 // c: lhs += rhs
1397 // zig: {1415 // zig: x: {
1398 // zig: const _ref = &lhs;1416 // zig: const _ref = &lhs;
1399 // zig: *_ref = *_ref + rhs;1417 // zig: *_ref = *_ref + rhs;
1400 // zig: *_ref1418 // zig: break :x *_ref
1401 // zig: }1419 // zig: }
14021420
1403 TransScopeBlock *child_scope = trans_scope_block_create(c, scope);1421 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
1405 // const _ref = &lhs;1425 // const _ref = &lhs;
1406 AstNode *lhs = trans_expr(c, ResultUsedYes, &child_scope->base, stmt->getLHS(), TransLValue);1426 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,...@@ -1427,11 +1447,11 @@ static AstNode *trans_create_compound_assign(Context *c, ResultUsed result_used,
1427 rhs));1447 rhs));
1428 child_scope->node->data.block.statements.append(assign_statement);1448 child_scope->node->data.block.statements.append(assign_statement);
14291449
1430 // *_ref1450 // break :x *_ref
1431 child_scope->node->data.block.statements.append(1451 child_scope->node->data.block.statements.append(
1432 trans_create_node_prefix_op(c, PrefixOpDereference,1452 trans_create_node_break(c, label_name,
1433 trans_create_node_symbol(c, tmp_var_name)));1453 trans_create_node_prefix_op(c, PrefixOpDereference,
1434 child_scope->node->data.block.last_statement_is_result_expression = true;1454 trans_create_node_symbol(c, tmp_var_name))));
14351455
1436 return child_scope->node;1456 return child_scope->node;
1437 }1457 }
...@@ -1726,13 +1746,15 @@ static AstNode *trans_create_post_crement(Context *c, ResultUsed result_used, Tr...@@ -1726,13 +1746,15 @@ static AstNode *trans_create_post_crement(Context *c, ResultUsed result_used, Tr
1726 }1746 }
1727 // worst case1747 // worst case
1728 // c: expr++1748 // c: expr++
1729 // zig: {1749 // zig: x: {
1730 // zig: const _ref = &expr;1750 // zig: const _ref = &expr;
1731 // zig: const _tmp = *_ref;1751 // zig: const _tmp = *_ref;
1732 // zig: *_ref += 1;1752 // zig: *_ref += 1;
1733 // zig: _tmp1753 // zig: break :x _tmp
1734 // zig: }1754 // zig: }
1735 TransScopeBlock *child_scope = trans_scope_block_create(c, scope);1755 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
1737 // const _ref = &expr;1759 // const _ref = &expr;
1738 AstNode *expr = trans_expr(c, ResultUsedYes, &child_scope->base, op_expr, TransLValue);1760 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...@@ -1758,9 +1780,8 @@ static AstNode *trans_create_post_crement(Context *c, ResultUsed result_used, Tr
1758 trans_create_node_unsigned(c, 1));1780 trans_create_node_unsigned(c, 1));
1759 child_scope->node->data.block.statements.append(assign_statement);1781 child_scope->node->data.block.statements.append(assign_statement);
17601782
1761 // _tmp1783 // break :x _tmp
1762 child_scope->node->data.block.statements.append(trans_create_node_symbol(c, tmp_var_name));1784 child_scope->node->data.block.statements.append(trans_create_node_break(c, label_name, trans_create_node_symbol(c, tmp_var_name)));
1763 child_scope->node->data.block.last_statement_is_result_expression = true;
17641785
1765 return child_scope->node;1786 return child_scope->node;
1766}1787}
...@@ -1781,12 +1802,14 @@ static AstNode *trans_create_pre_crement(Context *c, ResultUsed result_used, Tra...@@ -1781,12 +1802,14 @@ static AstNode *trans_create_pre_crement(Context *c, ResultUsed result_used, Tra
1781 }1802 }
1782 // worst case1803 // worst case
1783 // c: ++expr1804 // c: ++expr
1784 // zig: {1805 // zig: x: {
1785 // zig: const _ref = &expr;1806 // zig: const _ref = &expr;
1786 // zig: *_ref += 1;1807 // zig: *_ref += 1;
1787 // zig: *_ref1808 // zig: break :x *_ref
1788 // zig: }1809 // zig: }
1789 TransScopeBlock *child_scope = trans_scope_block_create(c, scope);1810 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
1791 // const _ref = &expr;1814 // const _ref = &expr;
1792 AstNode *expr = trans_expr(c, ResultUsedYes, &child_scope->base, op_expr, TransLValue);1815 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...@@ -1805,11 +1828,10 @@ static AstNode *trans_create_pre_crement(Context *c, ResultUsed result_used, Tra
1805 trans_create_node_unsigned(c, 1));1828 trans_create_node_unsigned(c, 1));
1806 child_scope->node->data.block.statements.append(assign_statement);1829 child_scope->node->data.block.statements.append(assign_statement);
18071830
1808 // *_ref1831 // break :x *_ref
1809 AstNode *deref_expr = trans_create_node_prefix_op(c, PrefixOpDereference,1832 AstNode *deref_expr = trans_create_node_prefix_op(c, PrefixOpDereference,
1810 trans_create_node_symbol(c, ref_var_name));1833 trans_create_node_symbol(c, ref_var_name));
1811 child_scope->node->data.block.statements.append(deref_expr);1834 child_scope->node->data.block.statements.append(trans_create_node_break(c, label_name, deref_expr));
1812 child_scope->node->data.block.last_statement_is_result_expression = true;
18131835
1814 return child_scope->node;1836 return child_scope->node;
1815}1837}
std/array_list.zig+4-4
...@@ -8,7 +8,7 @@ pub fn ArrayList(comptime T: type) -> type {...@@ -8,7 +8,7 @@ pub fn ArrayList(comptime T: type) -> type {
8}8}
99
10pub fn AlignedArrayList(comptime T: type, comptime A: u29) -> type{10pub fn AlignedArrayList(comptime T: type, comptime A: u29) -> type{
11 struct {11 return struct {
12 const Self = this;12 const Self = this;
1313
14 /// Use toSlice instead of slicing this directly, because if you don't14 /// 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{...@@ -20,11 +20,11 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) -> type{
2020
21 /// Deinitialize with `deinit` or use `toOwnedSlice`.21 /// Deinitialize with `deinit` or use `toOwnedSlice`.
22 pub fn init(allocator: &Allocator) -> Self {22 pub fn init(allocator: &Allocator) -> Self {
23 Self {23 return Self {
24 .items = []align(A) T{},24 .items = []align(A) T{},
25 .len = 0,25 .len = 0,
26 .allocator = allocator,26 .allocator = allocator,
27 }27 };
28 }28 }
2929
30 pub fn deinit(l: &Self) {30 pub fn deinit(l: &Self) {
...@@ -107,7 +107,7 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) -> type{...@@ -107,7 +107,7 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) -> type{
107 return null;107 return null;
108 return self.pop();108 return self.pop();
109 }109 }
110 }110 };
111}111}
112112
113test "basic ArrayList test" {113test "basic ArrayList test" {
std/buffer.zig+3-3
...@@ -30,9 +30,9 @@ pub const Buffer = struct {...@@ -30,9 +30,9 @@ pub const Buffer = struct {
30 /// * ::replaceContentsBuffer30 /// * ::replaceContentsBuffer
31 /// * ::resize31 /// * ::resize
32 pub fn initNull(allocator: &Allocator) -> Buffer {32 pub fn initNull(allocator: &Allocator) -> Buffer {
33 Buffer {33 return Buffer {
34 .list = ArrayList(u8).init(allocator),34 .list = ArrayList(u8).init(allocator),
35 }35 };
36 }36 }
3737
38 /// Must deinitialize with deinit.38 /// Must deinitialize with deinit.
...@@ -120,7 +120,7 @@ pub const Buffer = struct {...@@ -120,7 +120,7 @@ pub const Buffer = struct {
120 }120 }
121121
122 pub fn eql(self: &const Buffer, m: []const u8) -> bool {122 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);
124 }124 }
125125
126 pub fn startsWith(self: &const Buffer, m: []const u8) -> bool {126 pub fn startsWith(self: &const Buffer, m: []const u8) -> bool {
std/build.zig+26-30
...@@ -221,11 +221,11 @@ pub const Builder = struct {...@@ -221,11 +221,11 @@ pub const Builder = struct {
221 }221 }
222222
223 pub fn version(self: &const Builder, major: u32, minor: u32, patch: u32) -> Version {223 pub fn version(self: &const Builder, major: u32, minor: u32, patch: u32) -> Version {
224 Version {224 return Version {
225 .major = major,225 .major = major,
226 .minor = minor,226 .minor = minor,
227 .patch = patch,227 .patch = patch,
228 }228 };
229 }229 }
230230
231 pub fn addCIncludePath(self: &Builder, path: []const u8) {231 pub fn addCIncludePath(self: &Builder, path: []const u8) {
...@@ -432,16 +432,16 @@ pub const Builder = struct {...@@ -432,16 +432,16 @@ pub const Builder = struct {
432 const release_safe = self.option(bool, "release-safe", "optimizations on and safety on") ?? false;432 const release_safe = self.option(bool, "release-safe", "optimizations on and safety on") ?? false;
433 const release_fast = self.option(bool, "release-fast", "optimizations on and safety off") ?? false;433 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)
436 builtin.Mode.ReleaseSafe436 builtin.Mode.ReleaseSafe
437 } else if (release_fast and !release_safe) {437 else if (release_fast and !release_safe)
438 builtin.Mode.ReleaseFast438 builtin.Mode.ReleaseFast
439 } else if (!release_fast and !release_safe) {439 else if (!release_fast and !release_safe)
440 builtin.Mode.Debug440 builtin.Mode.Debug
441 } else {441 else x: {
442 warn("Both -Drelease-safe and -Drelease-fast specified");442 warn("Both -Drelease-safe and -Drelease-fast specified");
443 self.markInvalidUserInput();443 self.markInvalidUserInput();
444 builtin.Mode.Debug444 break :x builtin.Mode.Debug;
445 };445 };
446 self.release_mode = mode;446 self.release_mode = mode;
447 return mode;447 return mode;
...@@ -506,7 +506,7 @@ pub const Builder = struct {...@@ -506,7 +506,7 @@ pub const Builder = struct {
506 }506 }
507507
508 fn typeToEnum(comptime T: type) -> TypeId {508 fn typeToEnum(comptime T: type) -> TypeId {
509 switch (@typeId(T)) {509 return switch (@typeId(T)) {
510 builtin.TypeId.Int => TypeId.Int,510 builtin.TypeId.Int => TypeId.Int,
511 builtin.TypeId.Float => TypeId.Float,511 builtin.TypeId.Float => TypeId.Float,
512 builtin.TypeId.Bool => TypeId.Bool,512 builtin.TypeId.Bool => TypeId.Bool,
...@@ -515,7 +515,7 @@ pub const Builder = struct {...@@ -515,7 +515,7 @@ pub const Builder = struct {
515 []const []const u8 => TypeId.List,515 []const []const u8 => TypeId.List,
516 else => @compileError("Unsupported type: " ++ @typeName(T)),516 else => @compileError("Unsupported type: " ++ @typeName(T)),
517 },517 },
518 }518 };
519 }519 }
520520
521 fn markInvalidUserInput(self: &Builder) {521 fn markInvalidUserInput(self: &Builder) {
...@@ -590,8 +590,7 @@ pub const Builder = struct {...@@ -590,8 +590,7 @@ pub const Builder = struct {
590590
591 return error.UncleanExit;591 return error.UncleanExit;
592 },592 },
593 };593 }
594
595 }594 }
596595
597 pub fn makePath(self: &Builder, path: []const u8) -> %void {596 pub fn makePath(self: &Builder, path: []const u8) -> %void {
...@@ -662,13 +661,12 @@ pub const Builder = struct {...@@ -662,13 +661,12 @@ pub const Builder = struct {
662 if (builtin.environ == builtin.Environ.msvc) {661 if (builtin.environ == builtin.Environ.msvc) {
663 return "cl.exe";662 return "cl.exe";
664 } else {663 } else {
665 return os.getEnvVarOwned(self.allocator, "CC") %% |err| {664 return os.getEnvVarOwned(self.allocator, "CC") %% |err|
666 if (err == error.EnvironmentVariableNotFound) {665 if (err == error.EnvironmentVariableNotFound)
667 ([]const u8)("cc")666 ([]const u8)("cc")
668 } else {667 else
669 debug.panic("Unable to get environment variable: {}", err);668 debug.panic("Unable to get environment variable: {}", err)
670 }669 ;
671 };
672 }670 }
673 }671 }
674672
...@@ -1079,11 +1077,10 @@ pub const LibExeObjStep = struct {...@@ -1079,11 +1077,10 @@ pub const LibExeObjStep = struct {
1079 }1077 }
10801078
1081 pub fn getOutputPath(self: &LibExeObjStep) -> []const u8 {1079 pub fn getOutputPath(self: &LibExeObjStep) -> []const u8 {
1082 if (self.output_path) |output_path| {1080 return if (self.output_path) |output_path|
1083 output_path1081 output_path
1084 } else {1082 else
1085 %%os.path.join(self.builder.allocator, self.builder.cache_root, self.out_filename)1083 %%os.path.join(self.builder.allocator, self.builder.cache_root, self.out_filename);
1086 }
1087 }1084 }
10881085
1089 pub fn setOutputHPath(self: &LibExeObjStep, file_path: []const u8) {1086 pub fn setOutputHPath(self: &LibExeObjStep, file_path: []const u8) {
...@@ -1096,11 +1093,10 @@ pub const LibExeObjStep = struct {...@@ -1096,11 +1093,10 @@ pub const LibExeObjStep = struct {
1096 }1093 }
10971094
1098 pub fn getOutputHPath(self: &LibExeObjStep) -> []const u8 {1095 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|
1100 output_h_path1097 output_h_path
1101 } else {1098 else
1102 %%os.path.join(self.builder.allocator, self.builder.cache_root, self.out_h_filename)1099 %%os.path.join(self.builder.allocator, self.builder.cache_root, self.out_h_filename);
1103 }
1104 }1100 }
11051101
1106 pub fn addAssemblyFile(self: &LibExeObjStep, path: []const u8) {1102 pub fn addAssemblyFile(self: &LibExeObjStep, path: []const u8) {
...@@ -1618,7 +1614,7 @@ pub const TestStep = struct {...@@ -1618,7 +1614,7 @@ pub const TestStep = struct {
16181614
1619 pub fn init(builder: &Builder, root_src: []const u8) -> TestStep {1615 pub fn init(builder: &Builder, root_src: []const u8) -> TestStep {
1620 const step_name = builder.fmt("test {}", root_src);1616 const step_name = builder.fmt("test {}", root_src);
1621 TestStep {1617 return TestStep {
1622 .step = Step.init(step_name, builder.allocator, make),1618 .step = Step.init(step_name, builder.allocator, make),
1623 .builder = builder,1619 .builder = builder,
1624 .root_src = root_src,1620 .root_src = root_src,
...@@ -1629,7 +1625,7 @@ pub const TestStep = struct {...@@ -1629,7 +1625,7 @@ pub const TestStep = struct {
1629 .link_libs = BufSet.init(builder.allocator),1625 .link_libs = BufSet.init(builder.allocator),
1630 .target = Target { .Native = {} },1626 .target = Target { .Native = {} },
1631 .exec_cmd_args = null,1627 .exec_cmd_args = null,
1632 }1628 };
1633 }1629 }
16341630
1635 pub fn setVerbose(self: &TestStep, value: bool) {1631 pub fn setVerbose(self: &TestStep, value: bool) {
...@@ -1936,16 +1932,16 @@ pub const Step = struct {...@@ -1936,16 +1932,16 @@ pub const Step = struct {
1936 done_flag: bool,1932 done_flag: bool,
19371933
1938 pub fn init(name: []const u8, allocator: &Allocator, makeFn: fn (&Step)->%void) -> Step {1934 pub fn init(name: []const u8, allocator: &Allocator, makeFn: fn (&Step)->%void) -> Step {
1939 Step {1935 return Step {
1940 .name = name,1936 .name = name,
1941 .makeFn = makeFn,1937 .makeFn = makeFn,
1942 .dependencies = ArrayList(&Step).init(allocator),1938 .dependencies = ArrayList(&Step).init(allocator),
1943 .loop_flag = false,1939 .loop_flag = false,
1944 .done_flag = false,1940 .done_flag = false,
1945 }1941 };
1946 }1942 }
1947 pub fn initNoOp(name: []const u8, allocator: &Allocator) -> Step {1943 pub fn initNoOp(name: []const u8, allocator: &Allocator) -> Step {
1948 init(name, allocator, makeNoOp)1944 return init(name, allocator, makeNoOp);
1949 }1945 }
19501946
1951 pub fn make(self: &Step) -> %void {1947 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 {...@@ -17,7 +17,7 @@ pub fn cmp(a: &const u8, b: &const u8) -> i8 {
17 return -1;17 return -1;
18 } else {18 } else {
19 return 0;19 return 0;
20 };20 }
21}21}
2222
23pub fn toSliceConst(str: &const u8) -> []const u8 {23pub fn toSliceConst(str: &const u8) -> []const u8 {
std/debug.zig+37-49
...@@ -32,7 +32,7 @@ fn getStderrStream() -> %&io.OutStream {...@@ -32,7 +32,7 @@ fn getStderrStream() -> %&io.OutStream {
32 const st = &stderr_file_out_stream.stream;32 const st = &stderr_file_out_stream.stream;
33 stderr_stream = st;33 stderr_stream = st;
34 return st;34 return st;
35 };35 }
36}36}
3737
38/// Tries to print a stack trace to stderr, unbuffered, and ignores any error returned.38/// Tries to print a stack trace to stderr, unbuffered, and ignores any error returned.
...@@ -52,9 +52,9 @@ pub fn assert(ok: bool) {...@@ -52,9 +52,9 @@ pub fn assert(ok: bool) {
52 // we insert an explicit call to @panic instead of unreachable.52 // we insert an explicit call to @panic instead of unreachable.
53 // TODO we should use `assertOrPanic` in tests and remove this logic.53 // TODO we should use `assertOrPanic` in tests and remove this logic.
54 if (builtin.is_test) {54 if (builtin.is_test) {
55 @panic("assertion failure")55 @panic("assertion failure");
56 } else {56 } else {
57 unreachable // assertion failure57 unreachable; // assertion failure
58 }58 }
59 }59 }
60}60}
...@@ -175,7 +175,7 @@ pub fn writeStackTrace(out_stream: &io.OutStream, allocator: &mem.Allocator, tty...@@ -175,7 +175,7 @@ pub fn writeStackTrace(out_stream: &io.OutStream, allocator: &mem.Allocator, tty
175 return_address, compile_unit_name);175 return_address, compile_unit_name);
176 },176 },
177 else => return err,177 else => return err,
178 };178 }
179 }179 }
180 },180 },
181 builtin.ObjectFormat.coff => {181 builtin.ObjectFormat.coff => {
...@@ -357,7 +357,7 @@ const Die = struct {...@@ -357,7 +357,7 @@ const Die = struct {
357 FormValue.String => |value| value,357 FormValue.String => |value| value,
358 FormValue.StrPtr => |offset| getString(st, offset),358 FormValue.StrPtr => |offset| getString(st, offset),
359 else => error.InvalidDebugInfo,359 else => error.InvalidDebugInfo,
360 }360 };
361 }361 }
362};362};
363363
...@@ -403,7 +403,7 @@ const LineNumberProgram = struct {...@@ -403,7 +403,7 @@ const LineNumberProgram = struct {
403 pub fn init(is_stmt: bool, include_dirs: []const []const u8,403 pub fn init(is_stmt: bool, include_dirs: []const []const u8,
404 file_entries: &ArrayList(FileEntry), target_address: usize) -> LineNumberProgram404 file_entries: &ArrayList(FileEntry), target_address: usize) -> LineNumberProgram
405 {405 {
406 LineNumberProgram {406 return LineNumberProgram {
407 .address = 0,407 .address = 0,
408 .file = 1,408 .file = 1,
409 .line = 1,409 .line = 1,
...@@ -421,7 +421,7 @@ const LineNumberProgram = struct {...@@ -421,7 +421,7 @@ const LineNumberProgram = struct {
421 .prev_is_stmt = undefined,421 .prev_is_stmt = undefined,
422 .prev_basic_block = undefined,422 .prev_basic_block = undefined,
423 .prev_end_sequence = undefined,423 .prev_end_sequence = undefined,
424 }424 };
425 }425 }
426426
427 pub fn checkLineMatch(self: &LineNumberProgram) -> %?LineInfo {427 pub fn checkLineMatch(self: &LineNumberProgram) -> %?LineInfo {
...@@ -430,14 +430,11 @@ const LineNumberProgram = struct {...@@ -430,14 +430,11 @@ const LineNumberProgram = struct {
430 return error.MissingDebugInfo;430 return error.MissingDebugInfo;
431 } else if (self.prev_file - 1 >= self.file_entries.len) {431 } else if (self.prev_file - 1 >= self.file_entries.len) {
432 return error.InvalidDebugInfo;432 return error.InvalidDebugInfo;
433 } else {433 } else &self.file_entries.items[self.prev_file - 1];
434 &self.file_entries.items[self.prev_file - 1]434
435 };
436 const dir_name = if (file_entry.dir_index >= self.include_dirs.len) {435 const dir_name = if (file_entry.dir_index >= self.include_dirs.len) {
437 return error.InvalidDebugInfo;436 return error.InvalidDebugInfo;
438 } else {437 } else self.include_dirs[file_entry.dir_index];
439 self.include_dirs[file_entry.dir_index]
440 };
441 const file_name = %return os.path.join(self.file_entries.allocator, dir_name, file_entry.file_name);438 const file_name = %return os.path.join(self.file_entries.allocator, dir_name, file_entry.file_name);
442 %defer self.file_entries.allocator.free(file_name);439 %defer self.file_entries.allocator.free(file_name);
443 return LineInfo {440 return LineInfo {
...@@ -494,28 +491,21 @@ fn parseFormValueBlock(allocator: &mem.Allocator, in_stream: &io.InStream, size:...@@ -494,28 +491,21 @@ fn parseFormValueBlock(allocator: &mem.Allocator, in_stream: &io.InStream, size:
494}491}
495492
496fn parseFormValueConstant(allocator: &mem.Allocator, in_stream: &io.InStream, signed: bool, size: usize) -> %FormValue {493fn parseFormValueConstant(allocator: &mem.Allocator, in_stream: &io.InStream, signed: bool, size: usize) -> %FormValue {
497 FormValue { .Const = Constant {494 return FormValue { .Const = Constant {
498 .signed = signed,495 .signed = signed,
499 .payload = %return readAllocBytes(allocator, in_stream, size),496 .payload = %return readAllocBytes(allocator, in_stream, size),
500 }}497 }};
501}498}
502499
503fn parseFormValueDwarfOffsetSize(in_stream: &io.InStream, is_64: bool) -> %u64 {500fn parseFormValueDwarfOffsetSize(in_stream: &io.InStream, is_64: bool) -> %u64 {
504 return if (is_64) {501 return if (is_64) %return in_stream.readIntLe(u64)
505 %return in_stream.readIntLe(u64)502 else u64(%return in_stream.readIntLe(u32)) ;
506 } else {
507 u64(%return in_stream.readIntLe(u32))
508 };
509}503}
510504
511fn parseFormValueTargetAddrSize(in_stream: &io.InStream) -> %u64 {505fn parseFormValueTargetAddrSize(in_stream: &io.InStream) -> %u64 {
512 return if (@sizeOf(usize) == 4) {506 return if (@sizeOf(usize) == 4) u64(%return in_stream.readIntLe(u32))
513 u64(%return in_stream.readIntLe(u32))507 else if (@sizeOf(usize) == 8) %return in_stream.readIntLe(u64)
514 } else if (@sizeOf(usize) == 8) {508 else unreachable;
515 %return in_stream.readIntLe(u64)
516 } else {
517 unreachable;
518 };
519}509}
520510
521fn parseFormValueRefLen(allocator: &mem.Allocator, in_stream: &io.InStream, size: usize) -> %FormValue {511fn 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...@@ -534,9 +524,9 @@ fn parseFormValue(allocator: &mem.Allocator, in_stream: &io.InStream, form_id: u
534 DW.FORM_block1 => parseFormValueBlock(allocator, in_stream, 1),524 DW.FORM_block1 => parseFormValueBlock(allocator, in_stream, 1),
535 DW.FORM_block2 => parseFormValueBlock(allocator, in_stream, 2),525 DW.FORM_block2 => parseFormValueBlock(allocator, in_stream, 2),
536 DW.FORM_block4 => parseFormValueBlock(allocator, in_stream, 4),526 DW.FORM_block4 => parseFormValueBlock(allocator, in_stream, 4),
537 DW.FORM_block => {527 DW.FORM_block => x: {
538 const block_len = %return readULeb128(in_stream);528 const block_len = %return readULeb128(in_stream);
539 parseFormValueBlockLen(allocator, in_stream, block_len)529 return parseFormValueBlockLen(allocator, in_stream, block_len);
540 },530 },
541 DW.FORM_data1 => parseFormValueConstant(allocator, in_stream, false, 1),531 DW.FORM_data1 => parseFormValueConstant(allocator, in_stream, false, 1),
542 DW.FORM_data2 => parseFormValueConstant(allocator, in_stream, false, 2),532 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...@@ -545,7 +535,7 @@ fn parseFormValue(allocator: &mem.Allocator, in_stream: &io.InStream, form_id: u
545 DW.FORM_udata, DW.FORM_sdata => {535 DW.FORM_udata, DW.FORM_sdata => {
546 const block_len = %return readULeb128(in_stream);536 const block_len = %return readULeb128(in_stream);
547 const signed = form_id == DW.FORM_sdata;537 const signed = form_id == DW.FORM_sdata;
548 parseFormValueConstant(allocator, in_stream, signed, block_len)538 return parseFormValueConstant(allocator, in_stream, signed, block_len);
549 },539 },
550 DW.FORM_exprloc => {540 DW.FORM_exprloc => {
551 const size = %return readULeb128(in_stream);541 const size = %return readULeb128(in_stream);
...@@ -562,7 +552,7 @@ fn parseFormValue(allocator: &mem.Allocator, in_stream: &io.InStream, form_id: u...@@ -562,7 +552,7 @@ fn parseFormValue(allocator: &mem.Allocator, in_stream: &io.InStream, form_id: u
562 DW.FORM_ref8 => parseFormValueRef(allocator, in_stream, u64),552 DW.FORM_ref8 => parseFormValueRef(allocator, in_stream, u64),
563 DW.FORM_ref_udata => {553 DW.FORM_ref_udata => {
564 const ref_len = %return readULeb128(in_stream);554 const ref_len = %return readULeb128(in_stream);
565 parseFormValueRefLen(allocator, in_stream, ref_len)555 return parseFormValueRefLen(allocator, in_stream, ref_len);
566 },556 },
567557
568 DW.FORM_ref_addr => FormValue { .RefAddr = %return parseFormValueDwarfOffsetSize(in_stream, is_64) },558 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...@@ -572,10 +562,10 @@ fn parseFormValue(allocator: &mem.Allocator, in_stream: &io.InStream, form_id: u
572 DW.FORM_strp => FormValue { .StrPtr = %return parseFormValueDwarfOffsetSize(in_stream, is_64) },562 DW.FORM_strp => FormValue { .StrPtr = %return parseFormValueDwarfOffsetSize(in_stream, is_64) },
573 DW.FORM_indirect => {563 DW.FORM_indirect => {
574 const child_form_id = %return readULeb128(in_stream);564 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);
576 },566 },
577 else => error.InvalidDebugInfo,567 else => error.InvalidDebugInfo,
578 }568 };
579}569}
580570
581fn parseAbbrevTable(st: &ElfStackTrace) -> %AbbrevTable {571fn parseAbbrevTable(st: &ElfStackTrace) -> %AbbrevTable {
...@@ -852,11 +842,9 @@ fn scanAllCompileUnits(st: &ElfStackTrace) -> %void {...@@ -852,11 +842,9 @@ fn scanAllCompileUnits(st: &ElfStackTrace) -> %void {
852 const version = %return in_stream.readInt(st.elf.endian, u16);842 const version = %return in_stream.readInt(st.elf.endian, u16);
853 if (version < 2 or version > 5) return error.InvalidDebugInfo;843 if (version < 2 or version > 5) return error.InvalidDebugInfo;
854844
855 const debug_abbrev_offset = if (is_64) {845 const debug_abbrev_offset =
856 %return in_stream.readInt(st.elf.endian, u64)846 if (is_64) %return in_stream.readInt(st.elf.endian, u64)
857 } else {847 else %return in_stream.readInt(st.elf.endian, u32);
858 %return in_stream.readInt(st.elf.endian, u32)
859 };
860848
861 const address_size = %return in_stream.readByte();849 const address_size = %return in_stream.readByte();
862 if (address_size != @sizeOf(usize)) return error.InvalidDebugInfo;850 if (address_size != @sizeOf(usize)) return error.InvalidDebugInfo;
...@@ -872,28 +860,28 @@ fn scanAllCompileUnits(st: &ElfStackTrace) -> %void {...@@ -872,28 +860,28 @@ fn scanAllCompileUnits(st: &ElfStackTrace) -> %void {
872 if (compile_unit_die.tag_id != DW.TAG_compile_unit)860 if (compile_unit_die.tag_id != DW.TAG_compile_unit)
873 return error.InvalidDebugInfo;861 return error.InvalidDebugInfo;
874862
875 const pc_range = {863 const pc_range = x: {
876 if (compile_unit_die.getAttrAddr(DW.AT_low_pc)) |low_pc| {864 if (compile_unit_die.getAttrAddr(DW.AT_low_pc)) |low_pc| {
877 if (compile_unit_die.getAttr(DW.AT_high_pc)) |high_pc_value| {865 if (compile_unit_die.getAttr(DW.AT_high_pc)) |high_pc_value| {
878 const pc_end = switch (*high_pc_value) {866 const pc_end = switch (*high_pc_value) {
879 FormValue.Address => |value| value,867 FormValue.Address => |value| value,
880 FormValue.Const => |value| {868 FormValue.Const => |value| b: {
881 const offset = %return value.asUnsignedLe();869 const offset = %return value.asUnsignedLe();
882 low_pc + offset870 break :b (low_pc + offset);
883 },871 },
884 else => return error.InvalidDebugInfo,872 else => return error.InvalidDebugInfo,
885 };873 };
886 PcRange {874 break :x PcRange {
887 .start = low_pc,875 .start = low_pc,
888 .end = pc_end,876 .end = pc_end,
889 }877 };
890 } else {878 } else {
891 null879 break :x null;
892 }880 }
893 } else |err| {881 } else |err| {
894 if (err != error.MissingDebugInfo)882 if (err != error.MissingDebugInfo)
895 return err;883 return err;
896 null884 break :x null;
897 }885 }
898 };886 };
899887
...@@ -949,12 +937,12 @@ fn findCompileUnit(st: &ElfStackTrace, target_address: u64) -> %&const CompileUn...@@ -949,12 +937,12 @@ fn findCompileUnit(st: &ElfStackTrace, target_address: u64) -> %&const CompileUn
949fn readInitialLength(in_stream: &io.InStream, is_64: &bool) -> %u64 {937fn readInitialLength(in_stream: &io.InStream, is_64: &bool) -> %u64 {
950 const first_32_bits = %return in_stream.readIntLe(u32);938 const first_32_bits = %return in_stream.readIntLe(u32);
951 *is_64 = (first_32_bits == 0xffffffff);939 *is_64 = (first_32_bits == 0xffffffff);
952 return if (*is_64) {940 if (*is_64) {
953 %return in_stream.readIntLe(u64)941 return in_stream.readIntLe(u64);
954 } else {942 } else {
955 if (first_32_bits >= 0xfffffff0) return error.InvalidDebugInfo;943 if (first_32_bits >= 0xfffffff0) return error.InvalidDebugInfo;
956 u64(first_32_bits)944 return u64(first_32_bits);
957 };945 }
958}946}
959947
960fn readULeb128(in_stream: &io.InStream) -> %u64 {948fn readULeb128(in_stream: &io.InStream) -> %u64 {
std/endian.zig+3-3
...@@ -2,15 +2,15 @@ const mem = @import("mem.zig");...@@ -2,15 +2,15 @@ const mem = @import("mem.zig");
2const builtin = @import("builtin");2const builtin = @import("builtin");
33
4pub fn swapIfLe(comptime T: type, x: T) -> T {4pub fn swapIfLe(comptime T: type, x: T) -> T {
5 swapIf(false, T, x)5 return swapIf(false, T, x);
6}6}
77
8pub fn swapIfBe(comptime T: type, x: T) -> T {8pub fn swapIfBe(comptime T: type, x: T) -> T {
9 swapIf(true, T, x)9 return swapIf(true, T, x);
10}10}
1111
12pub fn swapIf(endian: builtin.Endian, comptime T: type, x: T) -> T {12pub fn swapIf(endian: builtin.Endian, comptime T: type, x: T) -> T {
13 if (builtin.endian == endian) swap(T, x) else x13 return if (builtin.endian == endian) swap(T, x) else x;
14}14}
1515
16pub fn swap(comptime T: type, x: T) -> T {16pub fn swap(comptime T: type, x: T) -> T {
std/fmt/errol/enum3.zig+2-2
...@@ -439,10 +439,10 @@ const Slab = struct {...@@ -439,10 +439,10 @@ const Slab = struct {
439};439};
440440
441fn slab(str: []const u8, exp: i32) -> Slab {441fn slab(str: []const u8, exp: i32) -> Slab {
442 Slab {442 return Slab {
443 .str = str,443 .str = str,
444 .exp = exp,444 .exp = exp,
445 }445 };
446}446}
447447
448pub const enum3_data = []Slab {448pub 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...@@ -251,11 +251,10 @@ pub fn formatFloat(value: var, context: var, output: fn(@typeOf(context), []cons
251 %return output(context, float_decimal.digits[0..1]);251 %return output(context, float_decimal.digits[0..1]);
252 %return output(context, ".");252 %return output(context, ".");
253 if (float_decimal.digits.len > 1) {253 if (float_decimal.digits.len > 1) {
254 const num_digits = if (@typeOf(value) == f32) {254 const num_digits = if (@typeOf(value) == f32)
255 math.min(usize(9), float_decimal.digits.len)255 math.min(usize(9), float_decimal.digits.len)
256 } else {256 else
257 float_decimal.digits.len257 float_decimal.digits.len;
258 };
259 %return output(context, float_decimal.digits[1 .. num_digits]);258 %return output(context, float_decimal.digits[1 .. num_digits]);
260 } else {259 } else {
261 %return output(context, "0");260 %return output(context, "0");
std/hash_map.zig+10-10
...@@ -12,7 +12,7 @@ pub fn HashMap(comptime K: type, comptime V: type,...@@ -12,7 +12,7 @@ pub fn HashMap(comptime K: type, comptime V: type,
12 comptime hash: fn(key: K)->u32,12 comptime hash: fn(key: K)->u32,
13 comptime eql: fn(a: K, b: K)->bool) -> type13 comptime eql: fn(a: K, b: K)->bool) -> type
14{14{
15 struct {15 return struct {
16 entries: []Entry,16 entries: []Entry,
17 size: usize,17 size: usize,
18 max_distance_from_start_index: usize,18 max_distance_from_start_index: usize,
...@@ -51,19 +51,19 @@ pub fn HashMap(comptime K: type, comptime V: type,...@@ -51,19 +51,19 @@ pub fn HashMap(comptime K: type, comptime V: type,
51 return entry;51 return entry;
52 }52 }
53 }53 }
54 unreachable // no next item54 unreachable; // no next item
55 }55 }
56 };56 };
5757
58 pub fn init(allocator: &Allocator) -> Self {58 pub fn init(allocator: &Allocator) -> Self {
59 Self {59 return Self {
60 .entries = []Entry{},60 .entries = []Entry{},
61 .allocator = allocator,61 .allocator = allocator,
62 .size = 0,62 .size = 0,
63 .max_distance_from_start_index = 0,63 .max_distance_from_start_index = 0,
64 // it doesn't actually matter what we set this to since we use wrapping integer arithmetic64 // it doesn't actually matter what we set this to since we use wrapping integer arithmetic
65 .modification_count = undefined,65 .modification_count = undefined,
66 }66 };
67 }67 }
6868
69 pub fn deinit(hm: &Self) {69 pub fn deinit(hm: &Self) {
...@@ -133,7 +133,7 @@ pub fn HashMap(comptime K: type, comptime V: type,...@@ -133,7 +133,7 @@ pub fn HashMap(comptime K: type, comptime V: type,
133 entry.distance_from_start_index -= 1;133 entry.distance_from_start_index -= 1;
134 entry = next_entry;134 entry = next_entry;
135 }135 }
136 unreachable // shifting everything in the table136 unreachable; // shifting everything in the table
137 }}137 }}
138 return null;138 return null;
139 }139 }
...@@ -169,7 +169,7 @@ pub fn HashMap(comptime K: type, comptime V: type,...@@ -169,7 +169,7 @@ pub fn HashMap(comptime K: type, comptime V: type,
169 const start_index = hm.keyToIndex(key);169 const start_index = hm.keyToIndex(key);
170 var roll_over: usize = 0;170 var roll_over: usize = 0;
171 var distance_from_start_index: usize = 0;171 var distance_from_start_index: usize = 0;
172 while (roll_over < hm.entries.len) : ({roll_over += 1; distance_from_start_index += 1}) {172 while (roll_over < hm.entries.len) : ({roll_over += 1; distance_from_start_index += 1;}) {
173 const index = (start_index + roll_over) % hm.entries.len;173 const index = (start_index + roll_over) % hm.entries.len;
174 const entry = &hm.entries[index];174 const entry = &hm.entries[index];
175175
...@@ -210,7 +210,7 @@ pub fn HashMap(comptime K: type, comptime V: type,...@@ -210,7 +210,7 @@ pub fn HashMap(comptime K: type, comptime V: type,
210 };210 };
211 return result;211 return result;
212 }212 }
213 unreachable // put into a full map213 unreachable; // put into a full map
214 }214 }
215215
216 fn internalGet(hm: &Self, key: K) -> ?&Entry {216 fn internalGet(hm: &Self, key: K) -> ?&Entry {
...@@ -228,7 +228,7 @@ pub fn HashMap(comptime K: type, comptime V: type,...@@ -228,7 +228,7 @@ pub fn HashMap(comptime K: type, comptime V: type,
228 fn keyToIndex(hm: &Self, key: K) -> usize {228 fn keyToIndex(hm: &Self, key: K) -> usize {
229 return usize(hash(key)) % hm.entries.len;229 return usize(hash(key)) % hm.entries.len;
230 }230 }
231 }231 };
232}232}
233233
234test "basicHashMapTest" {234test "basicHashMapTest" {
...@@ -251,9 +251,9 @@ test "basicHashMapTest" {...@@ -251,9 +251,9 @@ test "basicHashMapTest" {
251}251}
252252
253fn hash_i32(x: i32) -> u32 {253fn hash_i32(x: i32) -> u32 {
254 @bitCast(u32, x)254 return @bitCast(u32, x);
255}255}
256256
257fn eql_i32(a: i32, b: i32) -> bool {257fn eql_i32(a: i32, b: i32) -> bool {
258 a == b258 return a == b;
259}259}
std/heap.zig+6-7
...@@ -17,22 +17,21 @@ pub var c_allocator = Allocator {...@@ -17,22 +17,21 @@ pub var c_allocator = Allocator {
17};17};
1818
19fn cAlloc(self: &Allocator, n: usize, alignment: u29) -> %[]u8 {19fn cAlloc(self: &Allocator, n: usize, alignment: u29) -> %[]u8 {
20 if (c.malloc(usize(n))) |buf| {20 return if (c.malloc(usize(n))) |buf|
21 @ptrCast(&u8, buf)[0..n]21 @ptrCast(&u8, buf)[0..n]
22 } else {22 else
23 error.OutOfMemory23 error.OutOfMemory;
24 }
25}24}
2625
27fn cRealloc(self: &Allocator, old_mem: []u8, new_size: usize, alignment: u29) -> %[]u8 {26fn cRealloc(self: &Allocator, old_mem: []u8, new_size: usize, alignment: u29) -> %[]u8 {
28 if (new_size <= old_mem.len) {27 if (new_size <= old_mem.len) {
29 old_mem[0..new_size]28 return old_mem[0..new_size];
30 } else {29 } else {
31 const old_ptr = @ptrCast(&c_void, old_mem.ptr);30 const old_ptr = @ptrCast(&c_void, old_mem.ptr);
32 if (c.realloc(old_ptr, usize(new_size))) |buf| {31 if (c.realloc(old_ptr, usize(new_size))) |buf| {
33 @ptrCast(&u8, buf)[0..new_size]32 return @ptrCast(&u8, buf)[0..new_size];
34 } else {33 } else {
35 error.OutOfMemory34 return error.OutOfMemory;
36 }35 }
37 }36 }
38}37}
std/io.zig+13-16
...@@ -50,35 +50,32 @@ error Unseekable;...@@ -50,35 +50,32 @@ error Unseekable;
50error EndOfFile;50error EndOfFile;
5151
52pub fn getStdErr() -> %File {52pub fn getStdErr() -> %File {
53 const handle = if (is_windows) {53 const handle = if (is_windows)
54 %return os.windowsGetStdHandle(system.STD_ERROR_HANDLE)54 %return os.windowsGetStdHandle(system.STD_ERROR_HANDLE)
55 } else if (is_posix) {55 else if (is_posix)
56 system.STDERR_FILENO56 system.STDERR_FILENO
57 } else {57 else
58 unreachable58 unreachable;
59 };
60 return File.openHandle(handle);59 return File.openHandle(handle);
61}60}
6261
63pub fn getStdOut() -> %File {62pub fn getStdOut() -> %File {
64 const handle = if (is_windows) {63 const handle = if (is_windows)
65 %return os.windowsGetStdHandle(system.STD_OUTPUT_HANDLE)64 %return os.windowsGetStdHandle(system.STD_OUTPUT_HANDLE)
66 } else if (is_posix) {65 else if (is_posix)
67 system.STDOUT_FILENO66 system.STDOUT_FILENO
68 } else {67 else
69 unreachable68 unreachable;
70 };
71 return File.openHandle(handle);69 return File.openHandle(handle);
72}70}
7371
74pub fn getStdIn() -> %File {72pub fn getStdIn() -> %File {
75 const handle = if (is_windows) {73 const handle = if (is_windows)
76 %return os.windowsGetStdHandle(system.STD_INPUT_HANDLE)74 %return os.windowsGetStdHandle(system.STD_INPUT_HANDLE)
77 } else if (is_posix) {75 else if (is_posix)
78 system.STDIN_FILENO76 system.STDIN_FILENO
79 } else {77 else
80 unreachable78 unreachable;
81 };
82 return File.openHandle(handle);79 return File.openHandle(handle);
83}80}
8481
...@@ -261,7 +258,7 @@ pub const File = struct {...@@ -261,7 +258,7 @@ pub const File = struct {
261 system.EBADF => error.BadFd,258 system.EBADF => error.BadFd,
262 system.ENOMEM => error.SystemResources,259 system.ENOMEM => error.SystemResources,
263 else => os.unexpectedErrorPosix(err),260 else => os.unexpectedErrorPosix(err),
264 }261 };
265 }262 }
266263
267 return usize(stat.size);264 return usize(stat.size);
std/linked_list.zig+7-7
...@@ -5,7 +5,7 @@ const Allocator = mem.Allocator;...@@ -5,7 +5,7 @@ const Allocator = mem.Allocator;
55
6/// Generic doubly linked list.6/// Generic doubly linked list.
7pub fn LinkedList(comptime T: type) -> type {7pub fn LinkedList(comptime T: type) -> type {
8 struct {8 return struct {
9 const Self = this;9 const Self = this;
1010
11 /// Node inside the linked list wrapping the actual data.11 /// Node inside the linked list wrapping the actual data.
...@@ -15,11 +15,11 @@ pub fn LinkedList(comptime T: type) -> type {...@@ -15,11 +15,11 @@ pub fn LinkedList(comptime T: type) -> type {
15 data: T,15 data: T,
1616
17 pub fn init(data: &const T) -> Node {17 pub fn init(data: &const T) -> Node {
18 Node {18 return Node {
19 .prev = null,19 .prev = null,
20 .next = null,20 .next = null,
21 .data = *data,21 .data = *data,
22 }22 };
23 }23 }
24 };24 };
2525
...@@ -32,11 +32,11 @@ pub fn LinkedList(comptime T: type) -> type {...@@ -32,11 +32,11 @@ pub fn LinkedList(comptime T: type) -> type {
32 /// Returns:32 /// Returns:
33 /// An empty linked list.33 /// An empty linked list.
34 pub fn init() -> Self {34 pub fn init() -> Self {
35 Self {35 return Self {
36 .first = null,36 .first = null,
37 .last = null,37 .last = null,
38 .len = 0,38 .len = 0,
39 }39 };
40 }40 }
4141
42 /// Insert a new node after an existing one.42 /// Insert a new node after an existing one.
...@@ -166,7 +166,7 @@ pub fn LinkedList(comptime T: type) -> type {...@@ -166,7 +166,7 @@ pub fn LinkedList(comptime T: type) -> type {
166 /// Returns:166 /// Returns:
167 /// A pointer to the new node.167 /// A pointer to the new node.
168 pub fn allocateNode(list: &Self, allocator: &Allocator) -> %&Node {168 pub fn allocateNode(list: &Self, allocator: &Allocator) -> %&Node {
169 allocator.create(Node)169 return allocator.create(Node);
170 }170 }
171171
172 /// Deallocate a node.172 /// Deallocate a node.
...@@ -191,7 +191,7 @@ pub fn LinkedList(comptime T: type) -> type {...@@ -191,7 +191,7 @@ pub fn LinkedList(comptime T: type) -> type {
191 *node = Node.init(data);191 *node = Node.init(data);
192 return node;192 return node;
193 }193 }
194 }194 };
195}195}
196196
197test "basic linked list test" {197test "basic linked list test" {
std/math/acos.zig+6-6
...@@ -7,11 +7,11 @@ const assert = @import("../debug.zig").assert;...@@ -7,11 +7,11 @@ const assert = @import("../debug.zig").assert;
77
8pub fn acos(x: var) -> @typeOf(x) {8pub fn acos(x: var) -> @typeOf(x) {
9 const T = @typeOf(x);9 const T = @typeOf(x);
10 switch (T) {10 return switch (T) {
11 f32 => @inlineCall(acos32, x),11 f32 => @inlineCall(acos32, x),
12 f64 => @inlineCall(acos64, x),12 f64 => @inlineCall(acos64, x),
13 else => @compileError("acos not implemented for " ++ @typeName(T)),13 else => @compileError("acos not implemented for " ++ @typeName(T)),
14 }14 };
15}15}
1616
17fn r32(z: f32) -> f32 {17fn r32(z: f32) -> f32 {
...@@ -22,7 +22,7 @@ fn r32(z: f32) -> f32 {...@@ -22,7 +22,7 @@ fn r32(z: f32) -> f32 {
2222
23 const p = z * (pS0 + z * (pS1 + z * pS2));23 const p = z * (pS0 + z * (pS1 + z * pS2));
24 const q = 1.0 + z * qS1;24 const q = 1.0 + z * qS1;
25 p / q25 return p / q;
26}26}
2727
28fn acos32(x: f32) -> f32 {28fn acos32(x: f32) -> f32 {
...@@ -69,7 +69,7 @@ fn acos32(x: f32) -> f32 {...@@ -69,7 +69,7 @@ fn acos32(x: f32) -> f32 {
69 const df = @bitCast(f32, jx & 0xFFFFF000);69 const df = @bitCast(f32, jx & 0xFFFFF000);
70 const c = (z - df * df) / (s + df);70 const c = (z - df * df) / (s + df);
71 const w = r32(z) * s + c;71 const w = r32(z) * s + c;
72 2 * (df + w)72 return 2 * (df + w);
73}73}
7474
75fn r64(z: f64) -> f64 {75fn r64(z: f64) -> f64 {
...@@ -86,7 +86,7 @@ fn r64(z: f64) -> f64 {...@@ -86,7 +86,7 @@ fn r64(z: f64) -> f64 {
8686
87 const p = z * (pS0 + z * (pS1 + z * (pS2 + z * (pS3 + z * (pS4 + z * pS5)))));87 const p = z * (pS0 + z * (pS1 + z * (pS2 + z * (pS3 + z * (pS4 + z * pS5)))));
88 const q = 1.0 + z * (qS1 + z * (qS2 + z * (qS3 + z * qS4)));88 const q = 1.0 + z * (qS1 + z * (qS2 + z * (qS3 + z * qS4)));
89 p / q89 return p / q;
90}90}
9191
92fn acos64(x: f64) -> f64 {92fn acos64(x: f64) -> f64 {
...@@ -138,7 +138,7 @@ fn acos64(x: f64) -> f64 {...@@ -138,7 +138,7 @@ fn acos64(x: f64) -> f64 {
138 const df = @bitCast(f64, jx & 0xFFFFFFFF00000000);138 const df = @bitCast(f64, jx & 0xFFFFFFFF00000000);
139 const c = (z - df * df) / (s + df);139 const c = (z - df * df) / (s + df);
140 const w = r64(z) * s + c;140 const w = r64(z) * s + c;
141 2 * (df + w)141 return 2 * (df + w);
142}142}
143143
144test "math.acos" {144test "math.acos" {
std/math/acosh.zig+8-8
...@@ -9,11 +9,11 @@ const assert = @import("../debug.zig").assert;...@@ -9,11 +9,11 @@ const assert = @import("../debug.zig").assert;
99
10pub fn acosh(x: var) -> @typeOf(x) {10pub fn acosh(x: var) -> @typeOf(x) {
11 const T = @typeOf(x);11 const T = @typeOf(x);
12 switch (T) {12 return switch (T) {
13 f32 => @inlineCall(acosh32, x),13 f32 => @inlineCall(acosh32, x),
14 f64 => @inlineCall(acosh64, x),14 f64 => @inlineCall(acosh64, x),
15 else => @compileError("acosh not implemented for " ++ @typeName(T)),15 else => @compileError("acosh not implemented for " ++ @typeName(T)),
16 }16 };
17}17}
1818
19// acosh(x) = log(x + sqrt(x * x - 1))19// acosh(x) = log(x + sqrt(x * x - 1))
...@@ -23,15 +23,15 @@ fn acosh32(x: f32) -> f32 {...@@ -23,15 +23,15 @@ fn acosh32(x: f32) -> f32 {
2323
24 // |x| < 2, invalid if x < 1 or nan24 // |x| < 2, invalid if x < 1 or nan
25 if (i < 0x3F800000 + (1 << 23)) {25 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)));
27 }27 }
28 // |x| < 0x1p1228 // |x| < 0x1p12
29 else if (i < 0x3F800000 + (12 << 23)) {29 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)));
31 }31 }
32 // |x| >= 0x1p1232 // |x| >= 0x1p12
33 else {33 else {
34 math.ln(x) + 0.69314718055994530941723212145817656834 return math.ln(x) + 0.693147180559945309417232121458176568;
35 }35 }
36}36}
3737
...@@ -41,15 +41,15 @@ fn acosh64(x: f64) -> f64 {...@@ -41,15 +41,15 @@ fn acosh64(x: f64) -> f64 {
4141
42 // |x| < 2, invalid if x < 1 or nan42 // |x| < 2, invalid if x < 1 or nan
43 if (e < 0x3FF + 1) {43 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)));
45 }45 }
46 // |x| < 0x1p2646 // |x| < 0x1p26
47 else if (e < 0x3FF + 26) {47 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)));
49 }49 }
50 // |x| >= 0x1p26 or nan50 // |x| >= 0x1p26 or nan
51 else {51 else {
52 math.ln(x) + 0.69314718055994530941723212145817656852 return math.ln(x) + 0.693147180559945309417232121458176568;
53 }53 }
54}54}
5555
std/math/asin.zig+9-9
...@@ -8,11 +8,11 @@ const assert = @import("../debug.zig").assert;...@@ -8,11 +8,11 @@ const assert = @import("../debug.zig").assert;
88
9pub fn asin(x: var) -> @typeOf(x) {9pub fn asin(x: var) -> @typeOf(x) {
10 const T = @typeOf(x);10 const T = @typeOf(x);
11 switch (T) {11 return switch (T) {
12 f32 => @inlineCall(asin32, x),12 f32 => @inlineCall(asin32, x),
13 f64 => @inlineCall(asin64, x),13 f64 => @inlineCall(asin64, x),
14 else => @compileError("asin not implemented for " ++ @typeName(T)),14 else => @compileError("asin not implemented for " ++ @typeName(T)),
15 }15 };
16}16}
1717
18fn r32(z: f32) -> f32 {18fn r32(z: f32) -> f32 {
...@@ -23,7 +23,7 @@ fn r32(z: f32) -> f32 {...@@ -23,7 +23,7 @@ fn r32(z: f32) -> f32 {
2323
24 const p = z * (pS0 + z * (pS1 + z * pS2));24 const p = z * (pS0 + z * (pS1 + z * pS2));
25 const q = 1.0 + z * qS1;25 const q = 1.0 + z * qS1;
26 p / q26 return p / q;
27}27}
2828
29fn asin32(x: f32) -> f32 {29fn asin32(x: f32) -> f32 {
...@@ -58,9 +58,9 @@ fn asin32(x: f32) -> f32 {...@@ -58,9 +58,9 @@ fn asin32(x: f32) -> f32 {
58 const fx = pio2 - 2 * (s + s * r32(z));58 const fx = pio2 - 2 * (s + s * r32(z));
5959
60 if (hx >> 31 != 0) {60 if (hx >> 31 != 0) {
61 -fx61 return -fx;
62 } else {62 } else {
63 fx63 return fx;
64 }64 }
65}65}
6666
...@@ -78,7 +78,7 @@ fn r64(z: f64) -> f64 {...@@ -78,7 +78,7 @@ fn r64(z: f64) -> f64 {
7878
79 const p = z * (pS0 + z * (pS1 + z * (pS2 + z * (pS3 + z * (pS4 + z * pS5)))));79 const p = z * (pS0 + z * (pS1 + z * (pS2 + z * (pS3 + z * (pS4 + z * pS5)))));
80 const q = 1.0 + z * (qS1 + z * (qS2 + z * (qS3 + z * qS4)));80 const q = 1.0 + z * (qS1 + z * (qS2 + z * (qS3 + z * qS4)));
81 p / q81 return p / q;
82}82}
8383
84fn asin64(x: f64) -> f64 {84fn asin64(x: f64) -> f64 {
...@@ -119,7 +119,7 @@ fn asin64(x: f64) -> f64 {...@@ -119,7 +119,7 @@ fn asin64(x: f64) -> f64 {
119119
120 // |x| > 0.975120 // |x| > 0.975
121 if (ix >= 0x3FEF3333) {121 if (ix >= 0x3FEF3333) {
122 fx = pio2_hi - 2 * (s + s * r)122 fx = pio2_hi - 2 * (s + s * r);
123 } else {123 } else {
124 const jx = @bitCast(u64, s);124 const jx = @bitCast(u64, s);
125 const df = @bitCast(f64, jx & 0xFFFFFFFF00000000);125 const df = @bitCast(f64, jx & 0xFFFFFFFF00000000);
...@@ -128,9 +128,9 @@ fn asin64(x: f64) -> f64 {...@@ -128,9 +128,9 @@ fn asin64(x: f64) -> f64 {
128 }128 }
129129
130 if (hx >> 31 != 0) {130 if (hx >> 31 != 0) {
131 -fx131 return -fx;
132 } else {132 } else {
133 fx133 return fx;
134 }134 }
135}135}
136136
std/math/asinh.zig+4-4
...@@ -9,11 +9,11 @@ const assert = @import("../debug.zig").assert;...@@ -9,11 +9,11 @@ const assert = @import("../debug.zig").assert;
99
10pub fn asinh(x: var) -> @typeOf(x) {10pub fn asinh(x: var) -> @typeOf(x) {
11 const T = @typeOf(x);11 const T = @typeOf(x);
12 switch (T) {12 return switch (T) {
13 f32 => @inlineCall(asinh32, x),13 f32 => @inlineCall(asinh32, x),
14 f64 => @inlineCall(asinh64, x),14 f64 => @inlineCall(asinh64, x),
15 else => @compileError("asinh not implemented for " ++ @typeName(T)),15 else => @compileError("asinh not implemented for " ++ @typeName(T)),
16 }16 };
17}17}
1818
19// asinh(x) = sign(x) * log(|x| + sqrt(x * x + 1)) ~= x - x^3/6 + o(x^5)19// 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 {...@@ -46,7 +46,7 @@ fn asinh32(x: f32) -> f32 {
46 math.forceEval(x + 0x1.0p120);46 math.forceEval(x + 0x1.0p120);
47 }47 }
4848
49 if (s != 0) -rx else rx49 return if (s != 0) -rx else rx;
50}50}
5151
52fn asinh64(x: f64) -> f64 {52fn asinh64(x: f64) -> f64 {
...@@ -77,7 +77,7 @@ fn asinh64(x: f64) -> f64 {...@@ -77,7 +77,7 @@ fn asinh64(x: f64) -> f64 {
77 math.forceEval(x + 0x1.0p120);77 math.forceEval(x + 0x1.0p120);
78 }78 }
7979
80 if (s != 0) -rx else rx80 return if (s != 0) -rx else rx;
81}81}
8282
83test "math.asinh" {83test "math.asinh" {
std/math/atan.zig+6-6
...@@ -8,11 +8,11 @@ const assert = @import("../debug.zig").assert;...@@ -8,11 +8,11 @@ const assert = @import("../debug.zig").assert;
88
9pub fn atan(x: var) -> @typeOf(x) {9pub fn atan(x: var) -> @typeOf(x) {
10 const T = @typeOf(x);10 const T = @typeOf(x);
11 switch (T) {11 return switch (T) {
12 f32 => @inlineCall(atan32, x),12 f32 => @inlineCall(atan32, x),
13 f64 => @inlineCall(atan64, x),13 f64 => @inlineCall(atan64, x),
14 else => @compileError("atan not implemented for " ++ @typeName(T)),14 else => @compileError("atan not implemented for " ++ @typeName(T)),
15 }15 };
16}16}
1717
18fn atan32(x_: f32) -> f32 {18fn atan32(x_: f32) -> f32 {
...@@ -100,10 +100,10 @@ fn atan32(x_: f32) -> f32 {...@@ -100,10 +100,10 @@ fn atan32(x_: f32) -> f32 {
100 const s2 = w * (aT[1] + w * aT[3]);100 const s2 = w * (aT[1] + w * aT[3]);
101101
102 if (id == null) {102 if (id == null) {
103 x - x * (s1 + s2)103 return x - x * (s1 + s2);
104 } else {104 } else {
105 const zz = atanhi[??id] - ((x * (s1 + s2) - atanlo[??id]) - x);105 const zz = atanhi[??id] - ((x * (s1 + s2) - atanlo[??id]) - x);
106 if (sign != 0) -zz else zz106 return if (sign != 0) -zz else zz;
107 }107 }
108}108}
109109
...@@ -199,10 +199,10 @@ fn atan64(x_: f64) -> f64 {...@@ -199,10 +199,10 @@ fn atan64(x_: f64) -> f64 {
199 const s2 = w * (aT[1] + w * (aT[3] + w * (aT[5] + w * (aT[7] + w * aT[9]))));199 const s2 = w * (aT[1] + w * (aT[3] + w * (aT[5] + w * (aT[7] + w * aT[9]))));
200200
201 if (id == null) {201 if (id == null) {
202 x - x * (s1 + s2)202 return x - x * (s1 + s2);
203 } else {203 } else {
204 const zz = atanhi[??id] - ((x * (s1 + s2) - atanlo[??id]) - x);204 const zz = atanhi[??id] - ((x * (s1 + s2) - atanlo[??id]) - x);
205 if (sign != 0) -zz else zz205 return if (sign != 0) -zz else zz;
206 }206 }
207}207}
208208
std/math/atan2.zig+8-8
...@@ -22,11 +22,11 @@ const math = @import("index.zig");...@@ -22,11 +22,11 @@ const math = @import("index.zig");
22const assert = @import("../debug.zig").assert;22const assert = @import("../debug.zig").assert;
2323
24fn atan2(comptime T: type, x: T, y: T) -> T {24fn atan2(comptime T: type, x: T, y: T) -> T {
25 switch (T) {25 return switch (T) {
26 f32 => @inlineCall(atan2_32, x, y),26 f32 => @inlineCall(atan2_32, x, y),
27 f64 => @inlineCall(atan2_64, x, y),27 f64 => @inlineCall(atan2_64, x, y),
28 else => @compileError("atan2 not implemented for " ++ @typeName(T)),28 else => @compileError("atan2 not implemented for " ++ @typeName(T)),
29 }29 };
30}30}
3131
32fn atan2_32(y: f32, x: f32) -> f32 {32fn atan2_32(y: f32, x: f32) -> f32 {
...@@ -97,11 +97,11 @@ fn atan2_32(y: f32, x: f32) -> f32 {...@@ -97,11 +97,11 @@ fn atan2_32(y: f32, x: f32) -> f32 {
97 }97 }
9898
99 // z = atan(|y / x|) with correct underflow99 // z = atan(|y / x|) with correct underflow
100 var z = {100 var z = z: {
101 if ((m & 2) != 0 and iy + (26 << 23) < ix) {101 if ((m & 2) != 0 and iy + (26 << 23) < ix) {
102 0.0102 break :z 0.0;
103 } else {103 } else {
104 math.atan(math.fabs(y / x))104 break :z math.atan(math.fabs(y / x));
105 }105 }
106 };106 };
107107
...@@ -187,11 +187,11 @@ fn atan2_64(y: f64, x: f64) -> f64 {...@@ -187,11 +187,11 @@ fn atan2_64(y: f64, x: f64) -> f64 {
187 }187 }
188188
189 // z = atan(|y / x|) with correct underflow189 // z = atan(|y / x|) with correct underflow
190 var z = {190 var z = z: {
191 if ((m & 2) != 0 and iy +% (64 << 20) < ix) {191 if ((m & 2) != 0 and iy +% (64 << 20) < ix) {
192 0.0192 break :z 0.0;
193 } else {193 } else {
194 math.atan(math.fabs(y / x))194 break :z math.atan(math.fabs(y / x));
195 }195 }
196 };196 };
197197
std/math/atanh.zig+5-5
...@@ -9,11 +9,11 @@ const assert = @import("../debug.zig").assert;...@@ -9,11 +9,11 @@ const assert = @import("../debug.zig").assert;
99
10pub fn atanh(x: var) -> @typeOf(x) {10pub fn atanh(x: var) -> @typeOf(x) {
11 const T = @typeOf(x);11 const T = @typeOf(x);
12 switch (T) {12 return switch (T) {
13 f32 => @inlineCall(atanh_32, x),13 f32 => @inlineCall(atanh_32, x),
14 f64 => @inlineCall(atanh_64, x),14 f64 => @inlineCall(atanh_64, x),
15 else => @compileError("atanh not implemented for " ++ @typeName(T)),15 else => @compileError("atanh not implemented for " ++ @typeName(T)),
16 }16 };
17}17}
1818
19// atanh(x) = log((1 + x) / (1 - x)) / 2 = log1p(2x / (1 - x)) / 2 ~= x + x^3 / 3 + o(x^5)19// 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 {...@@ -32,7 +32,7 @@ fn atanh_32(x: f32) -> f32 {
32 if (u < 0x3F800000 - (32 << 23)) {32 if (u < 0x3F800000 - (32 << 23)) {
33 // underflow33 // underflow
34 if (u < (1 << 23)) {34 if (u < (1 << 23)) {
35 math.forceEval(y * y)35 math.forceEval(y * y);
36 }36 }
37 }37 }
38 // |x| < 0.538 // |x| < 0.5
...@@ -43,7 +43,7 @@ fn atanh_32(x: f32) -> f32 {...@@ -43,7 +43,7 @@ fn atanh_32(x: f32) -> f32 {
43 y = 0.5 * math.log1p(2 * (y / (1 - y)));43 y = 0.5 * math.log1p(2 * (y / (1 - y)));
44 }44 }
4545
46 if (s != 0) -y else y46 return if (s != 0) -y else y;
47}47}
4848
49fn atanh_64(x: f64) -> f64 {49fn atanh_64(x: f64) -> f64 {
...@@ -72,7 +72,7 @@ fn atanh_64(x: f64) -> f64 {...@@ -72,7 +72,7 @@ fn atanh_64(x: f64) -> f64 {
72 y = 0.5 * math.log1p(2 * (y / (1 - y)));72 y = 0.5 * math.log1p(2 * (y / (1 - y)));
73 }73 }
7474
75 if (s != 0) -y else y75 return if (s != 0) -y else y;
76}76}
7777
78test "math.atanh" {78test "math.atanh" {
std/math/cbrt.zig+4-4
...@@ -9,11 +9,11 @@ const assert = @import("../debug.zig").assert;...@@ -9,11 +9,11 @@ const assert = @import("../debug.zig").assert;
99
10pub fn cbrt(x: var) -> @typeOf(x) {10pub fn cbrt(x: var) -> @typeOf(x) {
11 const T = @typeOf(x);11 const T = @typeOf(x);
12 switch (T) {12 return switch (T) {
13 f32 => @inlineCall(cbrt32, x),13 f32 => @inlineCall(cbrt32, x),
14 f64 => @inlineCall(cbrt64, x),14 f64 => @inlineCall(cbrt64, x),
15 else => @compileError("cbrt not implemented for " ++ @typeName(T)),15 else => @compileError("cbrt not implemented for " ++ @typeName(T)),
16 }16 };
17}17}
1818
19fn cbrt32(x: f32) -> f32 {19fn cbrt32(x: f32) -> f32 {
...@@ -53,7 +53,7 @@ fn cbrt32(x: f32) -> f32 {...@@ -53,7 +53,7 @@ fn cbrt32(x: f32) -> f32 {
53 r = t * t * t;53 r = t * t * t;
54 t = t * (f64(x) + x + r) / (x + r + r);54 t = t * (f64(x) + x + r) / (x + r + r);
5555
56 f32(t)56 return f32(t);
57}57}
5858
59fn cbrt64(x: f64) -> f64 {59fn cbrt64(x: f64) -> f64 {
...@@ -109,7 +109,7 @@ fn cbrt64(x: f64) -> f64 {...@@ -109,7 +109,7 @@ fn cbrt64(x: f64) -> f64 {
109 var w = t + t;109 var w = t + t;
110 q = (q - t) / (w + q);110 q = (q - t) / (w + q);
111111
112 t + t * q112 return t + t * q;
113}113}
114114
115test "math.cbrt" {115test "math.cbrt" {
std/math/ceil.zig+8-8
...@@ -10,11 +10,11 @@ const assert = @import("../debug.zig").assert;...@@ -10,11 +10,11 @@ const assert = @import("../debug.zig").assert;
1010
11pub fn ceil(x: var) -> @typeOf(x) {11pub fn ceil(x: var) -> @typeOf(x) {
12 const T = @typeOf(x);12 const T = @typeOf(x);
13 switch (T) {13 return switch (T) {
14 f32 => @inlineCall(ceil32, x),14 f32 => @inlineCall(ceil32, x),
15 f64 => @inlineCall(ceil64, x),15 f64 => @inlineCall(ceil64, x),
16 else => @compileError("ceil not implemented for " ++ @typeName(T)),16 else => @compileError("ceil not implemented for " ++ @typeName(T)),
17 }17 };
18}18}
1919
20fn ceil32(x: f32) -> f32 {20fn ceil32(x: f32) -> f32 {
...@@ -39,13 +39,13 @@ fn ceil32(x: f32) -> f32 {...@@ -39,13 +39,13 @@ fn ceil32(x: f32) -> f32 {
39 u += m;39 u += m;
40 }40 }
41 u &= ~m;41 u &= ~m;
42 @bitCast(f32, u)42 return @bitCast(f32, u);
43 } else {43 } else {
44 math.forceEval(x + 0x1.0p120);44 math.forceEval(x + 0x1.0p120);
45 if (u >> 31 != 0) {45 if (u >> 31 != 0) {
46 return -0.0;46 return -0.0;
47 } else {47 } else {
48 1.048 return 1.0;
49 }49 }
50 }50 }
51}51}
...@@ -70,14 +70,14 @@ fn ceil64(x: f64) -> f64 {...@@ -70,14 +70,14 @@ fn ceil64(x: f64) -> f64 {
70 if (e <= 0x3FF-1) {70 if (e <= 0x3FF-1) {
71 math.forceEval(y);71 math.forceEval(y);
72 if (u >> 63 != 0) {72 if (u >> 63 != 0) {
73 return -0.0; // Compiler requires return.73 return -0.0;
74 } else {74 } else {
75 1.075 return 1.0;
76 }76 }
77 } else if (y < 0) {77 } else if (y < 0) {
78 x + y + 178 return x + y + 1;
79 } else {79 } else {
80 x + y80 return x + y;
81 }81 }
82}82}
8383
std/math/copysign.zig+4-4
...@@ -2,11 +2,11 @@ const math = @import("index.zig");...@@ -2,11 +2,11 @@ const math = @import("index.zig");
2const assert = @import("../debug.zig").assert;2const assert = @import("../debug.zig").assert;
33
4pub fn copysign(comptime T: type, x: T, y: T) -> T {4pub fn copysign(comptime T: type, x: T, y: T) -> T {
5 switch (T) {5 return switch (T) {
6 f32 => @inlineCall(copysign32, x, y),6 f32 => @inlineCall(copysign32, x, y),
7 f64 => @inlineCall(copysign64, x, y),7 f64 => @inlineCall(copysign64, x, y),
8 else => @compileError("copysign not implemented for " ++ @typeName(T)),8 else => @compileError("copysign not implemented for " ++ @typeName(T)),
9 }9 };
10}10}
1111
12fn copysign32(x: f32, y: f32) -> f32 {12fn copysign32(x: f32, y: f32) -> f32 {
...@@ -15,7 +15,7 @@ fn copysign32(x: f32, y: f32) -> f32 {...@@ -15,7 +15,7 @@ fn copysign32(x: f32, y: f32) -> f32 {
1515
16 const h1 = ux & (@maxValue(u32) / 2);16 const h1 = ux & (@maxValue(u32) / 2);
17 const h2 = uy & (u32(1) << 31);17 const h2 = uy & (u32(1) << 31);
18 @bitCast(f32, h1 | h2)18 return @bitCast(f32, h1 | h2);
19}19}
2020
21fn copysign64(x: f64, y: f64) -> f64 {21fn copysign64(x: f64, y: f64) -> f64 {
...@@ -24,7 +24,7 @@ fn copysign64(x: f64, y: f64) -> f64 {...@@ -24,7 +24,7 @@ fn copysign64(x: f64, y: f64) -> f64 {
2424
25 const h1 = ux & (@maxValue(u64) / 2);25 const h1 = ux & (@maxValue(u64) / 2);
26 const h2 = uy & (u64(1) << 63);26 const h2 = uy & (u64(1) << 63);
27 @bitCast(f64, h1 | h2)27 return @bitCast(f64, h1 | h2);
28}28}
2929
30test "math.copysign" {30test "math.copysign" {
std/math/cos.zig+12-12
...@@ -9,11 +9,11 @@ const assert = @import("../debug.zig").assert;...@@ -9,11 +9,11 @@ const assert = @import("../debug.zig").assert;
99
10pub fn cos(x: var) -> @typeOf(x) {10pub fn cos(x: var) -> @typeOf(x) {
11 const T = @typeOf(x);11 const T = @typeOf(x);
12 switch (T) {12 return switch (T) {
13 f32 => @inlineCall(cos32, x),13 f32 => @inlineCall(cos32, x),
14 f64 => @inlineCall(cos64, x),14 f64 => @inlineCall(cos64, x),
15 else => @compileError("cos not implemented for " ++ @typeName(T)),15 else => @compileError("cos not implemented for " ++ @typeName(T)),
16 }16 };
17}17}
1818
19// sin polynomial coefficients19// sin polynomial coefficients
...@@ -73,18 +73,18 @@ fn cos32(x_: f32) -> f32 {...@@ -73,18 +73,18 @@ fn cos32(x_: f32) -> f32 {
73 const z = ((x - y * pi4a) - y * pi4b) - y * pi4c;73 const z = ((x - y * pi4a) - y * pi4b) - y * pi4c;
74 const w = z * z;74 const w = z * z;
7575
76 const r = {76 const r = r: {
77 if (j == 1 or j == 2) {77 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)))));
79 } else {79 } 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)))));
81 }81 }
82 };82 };
8383
84 if (sign) {84 if (sign) {
85 -r85 return -r;
86 } else {86 } else {
87 r87 return r;
88 }88 }
89}89}
9090
...@@ -124,18 +124,18 @@ fn cos64(x_: f64) -> f64 {...@@ -124,18 +124,18 @@ fn cos64(x_: f64) -> f64 {
124 const z = ((x - y * pi4a) - y * pi4b) - y * pi4c;124 const z = ((x - y * pi4a) - y * pi4b) - y * pi4c;
125 const w = z * z;125 const w = z * z;
126126
127 const r = {127 const r = r: {
128 if (j == 1 or j == 2) {128 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)))));
130 } else {130 } 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)))));
132 }132 }
133 };133 };
134134
135 if (sign) {135 if (sign) {
136 -r136 return -r;
137 } else {137 } else {
138 r138 return r;
139 }139 }
140}140}
141141
std/math/cosh.zig+4-4
...@@ -11,11 +11,11 @@ const assert = @import("../debug.zig").assert;...@@ -11,11 +11,11 @@ const assert = @import("../debug.zig").assert;
1111
12pub fn cosh(x: var) -> @typeOf(x) {12pub fn cosh(x: var) -> @typeOf(x) {
13 const T = @typeOf(x);13 const T = @typeOf(x);
14 switch (T) {14 return switch (T) {
15 f32 => @inlineCall(cosh32, x),15 f32 => @inlineCall(cosh32, x),
16 f64 => @inlineCall(cosh64, x),16 f64 => @inlineCall(cosh64, x),
17 else => @compileError("cosh not implemented for " ++ @typeName(T)),17 else => @compileError("cosh not implemented for " ++ @typeName(T)),
18 }18 };
19}19}
2020
21// cosh(x) = (exp(x) + 1 / exp(x)) / 221// cosh(x) = (exp(x) + 1 / exp(x)) / 2
...@@ -43,7 +43,7 @@ fn cosh32(x: f32) -> f32 {...@@ -43,7 +43,7 @@ fn cosh32(x: f32) -> f32 {
43 }43 }
4444
45 // |x| > log(FLT_MAX) or nan45 // |x| > log(FLT_MAX) or nan
46 expo2(ax)46 return expo2(ax);
47}47}
4848
49fn cosh64(x: f64) -> f64 {49fn cosh64(x: f64) -> f64 {
...@@ -76,7 +76,7 @@ fn cosh64(x: f64) -> f64 {...@@ -76,7 +76,7 @@ fn cosh64(x: f64) -> f64 {
76 }76 }
7777
78 // |x| > log(CBL_MAX) or nan78 // |x| > log(CBL_MAX) or nan
79 expo2(ax)79 return expo2(ax);
80}80}
8181
82test "math.cosh" {82test "math.cosh" {
std/math/exp.zig+6-6
...@@ -8,11 +8,11 @@ const assert = @import("../debug.zig").assert;...@@ -8,11 +8,11 @@ const assert = @import("../debug.zig").assert;
88
9pub fn exp(x: var) -> @typeOf(x) {9pub fn exp(x: var) -> @typeOf(x) {
10 const T = @typeOf(x);10 const T = @typeOf(x);
11 switch (T) {11 return switch (T) {
12 f32 => @inlineCall(exp32, x),12 f32 => @inlineCall(exp32, x),
13 f64 => @inlineCall(exp64, x),13 f64 => @inlineCall(exp64, x),
14 else => @compileError("exp not implemented for " ++ @typeName(T)),14 else => @compileError("exp not implemented for " ++ @typeName(T)),
15 }15 };
16}16}
1717
18fn exp32(x_: f32) -> f32 {18fn exp32(x_: f32) -> f32 {
...@@ -86,9 +86,9 @@ fn exp32(x_: f32) -> f32 {...@@ -86,9 +86,9 @@ fn exp32(x_: f32) -> f32 {
86 const y = 1 + (x * c / (2 - c) - lo + hi);86 const y = 1 + (x * c / (2 - c) - lo + hi);
8787
88 if (k == 0) {88 if (k == 0) {
89 y89 return y;
90 } else {90 } else {
91 math.scalbn(y, k)91 return math.scalbn(y, k);
92 }92 }
93}93}
9494
...@@ -172,9 +172,9 @@ fn exp64(x_: f64) -> f64 {...@@ -172,9 +172,9 @@ fn exp64(x_: f64) -> f64 {
172 const y = 1 + (x * c / (2 - c) - lo + hi);172 const y = 1 + (x * c / (2 - c) - lo + hi);
173173
174 if (k == 0) {174 if (k == 0) {
175 y175 return y;
176 } else {176 } else {
177 math.scalbn(y, k)177 return math.scalbn(y, k);
178 }178 }
179}179}
180180
std/math/exp2.zig+4-4
...@@ -8,11 +8,11 @@ const assert = @import("../debug.zig").assert;...@@ -8,11 +8,11 @@ const assert = @import("../debug.zig").assert;
88
9pub fn exp2(x: var) -> @typeOf(x) {9pub fn exp2(x: var) -> @typeOf(x) {
10 const T = @typeOf(x);10 const T = @typeOf(x);
11 switch (T) {11 return switch (T) {
12 f32 => @inlineCall(exp2_32, x),12 f32 => @inlineCall(exp2_32, x),
13 f64 => @inlineCall(exp2_64, x),13 f64 => @inlineCall(exp2_64, x),
14 else => @compileError("exp2 not implemented for " ++ @typeName(T)),14 else => @compileError("exp2 not implemented for " ++ @typeName(T)),
15 }15 };
16}16}
1717
18const exp2ft = []const f64 {18const exp2ft = []const f64 {
...@@ -88,7 +88,7 @@ fn exp2_32(x: f32) -> f32 {...@@ -88,7 +88,7 @@ fn exp2_32(x: f32) -> f32 {
88 var r: f64 = exp2ft[i0];88 var r: f64 = exp2ft[i0];
89 const t: f64 = r * z;89 const t: f64 = r * z;
90 r = r + t * (P1 + z * P2) + t * (z * z) * (P3 + z * P4);90 r = r + t * (P1 + z * P2) + t * (z * z) * (P3 + z * P4);
91 f32(r * uk)91 return f32(r * uk);
92}92}
9393
94const exp2dt = []f64 {94const exp2dt = []f64 {
...@@ -414,7 +414,7 @@ fn exp2_64(x: f64) -> f64 {...@@ -414,7 +414,7 @@ fn exp2_64(x: f64) -> f64 {
414 z -= exp2dt[2 * i0 + 1];414 z -= exp2dt[2 * i0 + 1];
415 const r = t + t * z * (P1 + z * (P2 + z * (P3 + z * (P4 + z * P5))));415 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);
418}418}
419419
420test "math.exp2" {420test "math.exp2" {
std/math/expm1.zig+2-2
...@@ -9,11 +9,11 @@ const assert = @import("../debug.zig").assert;...@@ -9,11 +9,11 @@ const assert = @import("../debug.zig").assert;
99
10pub fn expm1(x: var) -> @typeOf(x) {10pub fn expm1(x: var) -> @typeOf(x) {
11 const T = @typeOf(x);11 const T = @typeOf(x);
12 switch (T) {12 return switch (T) {
13 f32 => @inlineCall(expm1_32, x),13 f32 => @inlineCall(expm1_32, x),
14 f64 => @inlineCall(expm1_64, x),14 f64 => @inlineCall(expm1_64, x),
15 else => @compileError("exp1m not implemented for " ++ @typeName(T)),15 else => @compileError("exp1m not implemented for " ++ @typeName(T)),
16 }16 };
17}17}
1818
19fn expm1_32(x_: f32) -> f32 {19fn expm1_32(x_: f32) -> f32 {
std/math/expo2.zig+4-4
...@@ -2,11 +2,11 @@ const math = @import("index.zig");...@@ -2,11 +2,11 @@ const math = @import("index.zig");
22
3pub fn expo2(x: var) -> @typeOf(x) {3pub fn expo2(x: var) -> @typeOf(x) {
4 const T = @typeOf(x);4 const T = @typeOf(x);
5 switch (T) {5 return switch (T) {
6 f32 => expo2f(x),6 f32 => expo2f(x),
7 f64 => expo2d(x),7 f64 => expo2d(x),
8 else => @compileError("expo2 not implemented for " ++ @typeName(T)),8 else => @compileError("expo2 not implemented for " ++ @typeName(T)),
9 }9 };
10}10}
1111
12fn expo2f(x: f32) -> f32 {12fn expo2f(x: f32) -> f32 {
...@@ -15,7 +15,7 @@ fn expo2f(x: f32) -> f32 {...@@ -15,7 +15,7 @@ fn expo2f(x: f32) -> f32 {
1515
16 const u = (0x7F + k / 2) << 23;16 const u = (0x7F + k / 2) << 23;
17 const scale = @bitCast(f32, u);17 const scale = @bitCast(f32, u);
18 math.exp(x - kln2) * scale * scale18 return math.exp(x - kln2) * scale * scale;
19}19}
2020
21fn expo2d(x: f64) -> f64 {21fn expo2d(x: f64) -> f64 {
...@@ -24,5 +24,5 @@ fn expo2d(x: f64) -> f64 {...@@ -24,5 +24,5 @@ fn expo2d(x: f64) -> f64 {
2424
25 const u = (0x3FF + k / 2) << 20;25 const u = (0x3FF + k / 2) << 20;
26 const scale = @bitCast(f64, u64(u) << 32);26 const scale = @bitCast(f64, u64(u) << 32);
27 math.exp(x - kln2) * scale * scale27 return math.exp(x - kln2) * scale * scale;
28}28}
std/math/fabs.zig+4-4
...@@ -8,23 +8,23 @@ const assert = @import("../debug.zig").assert;...@@ -8,23 +8,23 @@ const assert = @import("../debug.zig").assert;
88
9pub fn fabs(x: var) -> @typeOf(x) {9pub fn fabs(x: var) -> @typeOf(x) {
10 const T = @typeOf(x);10 const T = @typeOf(x);
11 switch (T) {11 return switch (T) {
12 f32 => @inlineCall(fabs32, x),12 f32 => @inlineCall(fabs32, x),
13 f64 => @inlineCall(fabs64, x),13 f64 => @inlineCall(fabs64, x),
14 else => @compileError("fabs not implemented for " ++ @typeName(T)),14 else => @compileError("fabs not implemented for " ++ @typeName(T)),
15 }15 };
16}16}
1717
18fn fabs32(x: f32) -> f32 {18fn fabs32(x: f32) -> f32 {
19 var u = @bitCast(u32, x);19 var u = @bitCast(u32, x);
20 u &= 0x7FFFFFFF;20 u &= 0x7FFFFFFF;
21 @bitCast(f32, u)21 return @bitCast(f32, u);
22}22}
2323
24fn fabs64(x: f64) -> f64 {24fn fabs64(x: f64) -> f64 {
25 var u = @bitCast(u64, x);25 var u = @bitCast(u64, x);
26 u &= @maxValue(u64) >> 1;26 u &= @maxValue(u64) >> 1;
27 @bitCast(f64, u)27 return @bitCast(f64, u);
28}28}
2929
30test "math.fabs" {30test "math.fabs" {
std/math/floor.zig+9-9
...@@ -10,11 +10,11 @@ const math = @import("index.zig");...@@ -10,11 +10,11 @@ const math = @import("index.zig");
1010
11pub fn floor(x: var) -> @typeOf(x) {11pub fn floor(x: var) -> @typeOf(x) {
12 const T = @typeOf(x);12 const T = @typeOf(x);
13 switch (T) {13 return switch (T) {
14 f32 => @inlineCall(floor32, x),14 f32 => @inlineCall(floor32, x),
15 f64 => @inlineCall(floor64, x),15 f64 => @inlineCall(floor64, x),
16 else => @compileError("floor not implemented for " ++ @typeName(T)),16 else => @compileError("floor not implemented for " ++ @typeName(T)),
17 }17 };
18}18}
1919
20fn floor32(x: f32) -> f32 {20fn floor32(x: f32) -> f32 {
...@@ -40,13 +40,13 @@ fn floor32(x: f32) -> f32 {...@@ -40,13 +40,13 @@ fn floor32(x: f32) -> f32 {
40 if (u >> 31 != 0) {40 if (u >> 31 != 0) {
41 u += m;41 u += m;
42 }42 }
43 @bitCast(f32, u & ~m)43 return @bitCast(f32, u & ~m);
44 } else {44 } else {
45 math.forceEval(x + 0x1.0p120);45 math.forceEval(x + 0x1.0p120);
46 if (u >> 31 == 0) {46 if (u >> 31 == 0) {
47 return 0.0; // Compiler requires return47 return 0.0;
48 } else {48 } else {
49 -1.049 return -1.0;
50 }50 }
51 }51 }
52}52}
...@@ -71,14 +71,14 @@ fn floor64(x: f64) -> f64 {...@@ -71,14 +71,14 @@ fn floor64(x: f64) -> f64 {
71 if (e <= 0x3FF-1) {71 if (e <= 0x3FF-1) {
72 math.forceEval(y);72 math.forceEval(y);
73 if (u >> 63 != 0) {73 if (u >> 63 != 0) {
74 return -1.0; // Compiler requires return.74 return -1.0;
75 } else {75 } else {
76 0.076 return 0.0;
77 }77 }
78 } else if (y > 0) {78 } else if (y > 0) {
79 x + y - 179 return x + y - 1;
80 } else {80 } else {
81 x + y81 return x + y;
82 }82 }
83}83}
8484
std/math/fma.zig+10-10
...@@ -2,11 +2,11 @@ const math = @import("index.zig");...@@ -2,11 +2,11 @@ const math = @import("index.zig");
2const assert = @import("../debug.zig").assert;2const assert = @import("../debug.zig").assert;
33
4pub fn fma(comptime T: type, x: T, y: T, z: T) -> T {4pub fn fma(comptime T: type, x: T, y: T, z: T) -> T {
5 switch (T) {5 return switch (T) {
6 f32 => @inlineCall(fma32, x, y, z),6 f32 => @inlineCall(fma32, x, y, z),
7 f64 => @inlineCall(fma64, x, y ,z),7 f64 => @inlineCall(fma64, x, y ,z),
8 else => @compileError("fma not implemented for " ++ @typeName(T)),8 else => @compileError("fma not implemented for " ++ @typeName(T)),
9 }9 };
10}10}
1111
12fn fma32(x: f32, y: f32, z: f32) -> f32 {12fn fma32(x: f32, y: f32, z: f32) -> f32 {
...@@ -16,10 +16,10 @@ fn fma32(x: f32, y: f32, z: f32) -> f32 {...@@ -16,10 +16,10 @@ fn fma32(x: f32, y: f32, z: f32) -> f32 {
16 const e = (u >> 52) & 0x7FF;16 const e = (u >> 52) & 0x7FF;
1717
18 if ((u & 0x1FFFFFFF) != 0x10000000 or e == 0x7FF or xy_z - xy == z) {18 if ((u & 0x1FFFFFFF) != 0x10000000 or e == 0x7FF or xy_z - xy == z) {
19 f32(xy_z)19 return f32(xy_z);
20 } else {20 } else {
21 // TODO: Handle inexact case with double-rounding21 // TODO: Handle inexact case with double-rounding
22 f32(xy_z)22 return f32(xy_z);
23 }23 }
24}24}
2525
...@@ -64,9 +64,9 @@ fn fma64(x: f64, y: f64, z: f64) -> f64 {...@@ -64,9 +64,9 @@ fn fma64(x: f64, y: f64, z: f64) -> f64 {
6464
65 const adj = add_adjusted(r.lo, xy.lo);65 const adj = add_adjusted(r.lo, xy.lo);
66 if (spread + math.ilogb(r.hi) > -1023) {66 if (spread + math.ilogb(r.hi) > -1023) {
67 math.scalbn(r.hi + adj, spread)67 return math.scalbn(r.hi + adj, spread);
68 } else {68 } else {
69 add_and_denorm(r.hi, adj, spread)69 return add_and_denorm(r.hi, adj, spread);
70 }70 }
71}71}
7272
...@@ -77,7 +77,7 @@ fn dd_add(a: f64, b: f64) -> dd {...@@ -77,7 +77,7 @@ fn dd_add(a: f64, b: f64) -> dd {
77 ret.hi = a + b;77 ret.hi = a + b;
78 const s = ret.hi - a;78 const s = ret.hi - a;
79 ret.lo = (a - (ret.hi - s)) + (b - s);79 ret.lo = (a - (ret.hi - s)) + (b - s);
80 ret80 return ret;
81}81}
8282
83fn dd_mul(a: f64, b: f64) -> dd {83fn dd_mul(a: f64, b: f64) -> dd {
...@@ -99,7 +99,7 @@ fn dd_mul(a: f64, b: f64) -> dd {...@@ -99,7 +99,7 @@ fn dd_mul(a: f64, b: f64) -> dd {
9999
100 ret.hi = p + q;100 ret.hi = p + q;
101 ret.lo = p - ret.hi + q + la * lb;101 ret.lo = p - ret.hi + q + la * lb;
102 ret102 return ret;
103}103}
104104
105fn add_adjusted(a: f64, b: f64) -> f64 {105fn add_adjusted(a: f64, b: f64) -> f64 {
...@@ -113,7 +113,7 @@ fn add_adjusted(a: f64, b: f64) -> f64 {...@@ -113,7 +113,7 @@ fn add_adjusted(a: f64, b: f64) -> f64 {
113 sum.hi = @bitCast(f64, uhii);113 sum.hi = @bitCast(f64, uhii);
114 }114 }
115 }115 }
116 sum.hi116 return sum.hi;
117}117}
118118
119fn add_and_denorm(a: f64, b: f64, scale: i32) -> f64 {119fn 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 {...@@ -127,7 +127,7 @@ fn add_and_denorm(a: f64, b: f64, scale: i32) -> f64 {
127 sum.hi = @bitCast(f64, uhii);127 sum.hi = @bitCast(f64, uhii);
128 }128 }
129 }129 }
130 math.scalbn(sum.hi, scale)130 return math.scalbn(sum.hi, scale);
131}131}
132132
133test "math.fma" {133test "math.fma" {
std/math/frexp.zig+6-6
...@@ -8,21 +8,21 @@ const math = @import("index.zig");...@@ -8,21 +8,21 @@ const math = @import("index.zig");
8const assert = @import("../debug.zig").assert;8const assert = @import("../debug.zig").assert;
99
10fn frexp_result(comptime T: type) -> type {10fn frexp_result(comptime T: type) -> type {
11 struct {11 return struct {
12 significand: T,12 significand: T,
13 exponent: i32,13 exponent: i32,
14 }14 };
15}15}
16pub const frexp32_result = frexp_result(f32);16pub const frexp32_result = frexp_result(f32);
17pub const frexp64_result = frexp_result(f64);17pub const frexp64_result = frexp_result(f64);
1818
19pub fn frexp(x: var) -> frexp_result(@typeOf(x)) {19pub fn frexp(x: var) -> frexp_result(@typeOf(x)) {
20 const T = @typeOf(x);20 const T = @typeOf(x);
21 switch (T) {21 return switch (T) {
22 f32 => @inlineCall(frexp32, x),22 f32 => @inlineCall(frexp32, x),
23 f64 => @inlineCall(frexp64, x),23 f64 => @inlineCall(frexp64, x),
24 else => @compileError("frexp not implemented for " ++ @typeName(T)),24 else => @compileError("frexp not implemented for " ++ @typeName(T)),
25 }25 };
26}26}
2727
28fn frexp32(x: f32) -> frexp32_result {28fn frexp32(x: f32) -> frexp32_result {
...@@ -59,7 +59,7 @@ fn frexp32(x: f32) -> frexp32_result {...@@ -59,7 +59,7 @@ fn frexp32(x: f32) -> frexp32_result {
59 y &= 0x807FFFFF;59 y &= 0x807FFFFF;
60 y |= 0x3F000000;60 y |= 0x3F000000;
61 result.significand = @bitCast(f32, y);61 result.significand = @bitCast(f32, y);
62 result62 return result;
63}63}
6464
65fn frexp64(x: f64) -> frexp64_result {65fn frexp64(x: f64) -> frexp64_result {
...@@ -96,7 +96,7 @@ fn frexp64(x: f64) -> frexp64_result {...@@ -96,7 +96,7 @@ fn frexp64(x: f64) -> frexp64_result {
96 y &= 0x800FFFFFFFFFFFFF;96 y &= 0x800FFFFFFFFFFFFF;
97 y |= 0x3FE0000000000000;97 y |= 0x3FE0000000000000;
98 result.significand = @bitCast(f64, y);98 result.significand = @bitCast(f64, y);
99 result99 return result;
100}100}
101101
102test "math.frexp" {102test "math.frexp" {
std/math/hypot.zig+4-4
...@@ -9,11 +9,11 @@ const math = @import("index.zig");...@@ -9,11 +9,11 @@ const math = @import("index.zig");
9const assert = @import("../debug.zig").assert;9const assert = @import("../debug.zig").assert;
1010
11pub fn hypot(comptime T: type, x: T, y: T) -> T {11pub fn hypot(comptime T: type, x: T, y: T) -> T {
12 switch (T) {12 return switch (T) {
13 f32 => @inlineCall(hypot32, x, y),13 f32 => @inlineCall(hypot32, x, y),
14 f64 => @inlineCall(hypot64, x, y),14 f64 => @inlineCall(hypot64, x, y),
15 else => @compileError("hypot not implemented for " ++ @typeName(T)),15 else => @compileError("hypot not implemented for " ++ @typeName(T)),
16 }16 };
17}17}
1818
19fn hypot32(x: f32, y: f32) -> f32 {19fn hypot32(x: f32, y: f32) -> f32 {
...@@ -48,7 +48,7 @@ fn hypot32(x: f32, y: f32) -> f32 {...@@ -48,7 +48,7 @@ fn hypot32(x: f32, y: f32) -> f32 {
48 yy *= 0x1.0p-90;48 yy *= 0x1.0p-90;
49 }49 }
5050
51 z * math.sqrt(f32(f64(x) * x + f64(y) * y))51 return z * math.sqrt(f32(f64(x) * x + f64(y) * y));
52}52}
5353
54fn sq(hi: &f64, lo: &f64, x: f64) {54fn sq(hi: &f64, lo: &f64, x: f64) {
...@@ -109,7 +109,7 @@ fn hypot64(x: f64, y: f64) -> f64 {...@@ -109,7 +109,7 @@ fn hypot64(x: f64, y: f64) -> f64 {
109 sq(&hx, &lx, x);109 sq(&hx, &lx, x);
110 sq(&hy, &ly, y);110 sq(&hy, &ly, y);
111111
112 z * math.sqrt(ly + lx + hy + hx)112 return z * math.sqrt(ly + lx + hy + hx);
113}113}
114114
115test "math.hypot" {115test "math.hypot" {
std/math/ilogb.zig+4-4
...@@ -9,11 +9,11 @@ const assert = @import("../debug.zig").assert;...@@ -9,11 +9,11 @@ const assert = @import("../debug.zig").assert;
99
10pub fn ilogb(x: var) -> i32 {10pub fn ilogb(x: var) -> i32 {
11 const T = @typeOf(x);11 const T = @typeOf(x);
12 switch (T) {12 return switch (T) {
13 f32 => @inlineCall(ilogb32, x),13 f32 => @inlineCall(ilogb32, x),
14 f64 => @inlineCall(ilogb64, x),14 f64 => @inlineCall(ilogb64, x),
15 else => @compileError("ilogb not implemented for " ++ @typeName(T)),15 else => @compileError("ilogb not implemented for " ++ @typeName(T)),
16 }16 };
17}17}
1818
19// NOTE: Should these be exposed publically?19// NOTE: Should these be exposed publically?
...@@ -53,7 +53,7 @@ fn ilogb32(x: f32) -> i32 {...@@ -53,7 +53,7 @@ fn ilogb32(x: f32) -> i32 {
53 }53 }
54 }54 }
5555
56 e - 0x7F56 return e - 0x7F;
57}57}
5858
59fn ilogb64(x: f64) -> i32 {59fn ilogb64(x: f64) -> i32 {
...@@ -88,7 +88,7 @@ fn ilogb64(x: f64) -> i32 {...@@ -88,7 +88,7 @@ fn ilogb64(x: f64) -> i32 {
88 }88 }
89 }89 }
9090
91 e - 0x3FF91 return e - 0x3FF;
92}92}
9393
94test "math.ilogb" {94test "math.ilogb" {
std/math/index.zig+8-8
...@@ -36,7 +36,7 @@ pub const inf = @import("inf.zig").inf;...@@ -36,7 +36,7 @@ pub const inf = @import("inf.zig").inf;
3636
37pub fn approxEq(comptime T: type, x: T, y: T, epsilon: T) -> bool {37pub fn approxEq(comptime T: type, x: T, y: T, epsilon: T) -> bool {
38 assert(@typeId(T) == TypeId.Float);38 assert(@typeId(T) == TypeId.Float);
39 fabs(x - y) < epsilon39 return fabs(x - y) < epsilon;
40}40}
4141
42// TODO: Hide the following in an internal module.42// TODO: Hide the following in an internal module.
...@@ -175,7 +175,7 @@ test "math" {...@@ -175,7 +175,7 @@ test "math" {
175175
176176
177pub fn min(x: var, y: var) -> @typeOf(x + y) {177pub fn min(x: var, y: var) -> @typeOf(x + y) {
178 if (x < y) x else y178 return if (x < y) x else y;
179}179}
180180
181test "math.min" {181test "math.min" {
...@@ -183,7 +183,7 @@ test "math.min" {...@@ -183,7 +183,7 @@ test "math.min" {
183}183}
184184
185pub fn max(x: var, y: var) -> @typeOf(x + y) {185pub fn max(x: var, y: var) -> @typeOf(x + y) {
186 if (x > y) x else y186 return if (x > y) x else y;
187}187}
188188
189test "math.max" {189test "math.max" {
...@@ -193,19 +193,19 @@ test "math.max" {...@@ -193,19 +193,19 @@ test "math.max" {
193error Overflow;193error Overflow;
194pub fn mul(comptime T: type, a: T, b: T) -> %T {194pub fn mul(comptime T: type, a: T, b: T) -> %T {
195 var answer: T = undefined;195 var answer: T = undefined;
196 if (@mulWithOverflow(T, a, b, &answer)) error.Overflow else answer196 return if (@mulWithOverflow(T, a, b, &answer)) error.Overflow else answer;
197}197}
198198
199error Overflow;199error Overflow;
200pub fn add(comptime T: type, a: T, b: T) -> %T {200pub fn add(comptime T: type, a: T, b: T) -> %T {
201 var answer: T = undefined;201 var answer: T = undefined;
202 if (@addWithOverflow(T, a, b, &answer)) error.Overflow else answer202 return if (@addWithOverflow(T, a, b, &answer)) error.Overflow else answer;
203}203}
204204
205error Overflow;205error Overflow;
206pub fn sub(comptime T: type, a: T, b: T) -> %T {206pub fn sub(comptime T: type, a: T, b: T) -> %T {
207 var answer: T = undefined;207 var answer: T = undefined;
208 if (@subWithOverflow(T, a, b, &answer)) error.Overflow else answer208 return if (@subWithOverflow(T, a, b, &answer)) error.Overflow else answer;
209}209}
210210
211pub fn negate(x: var) -> %@typeOf(x) {211pub fn negate(x: var) -> %@typeOf(x) {
...@@ -215,7 +215,7 @@ pub fn negate(x: var) -> %@typeOf(x) {...@@ -215,7 +215,7 @@ pub fn negate(x: var) -> %@typeOf(x) {
215error Overflow;215error Overflow;
216pub fn shlExact(comptime T: type, a: T, shift_amt: Log2Int(T)) -> %T {216pub fn shlExact(comptime T: type, a: T, shift_amt: Log2Int(T)) -> %T {
217 var answer: T = undefined;217 var answer: T = undefined;
218 if (@shlWithOverflow(T, a, shift_amt, &answer)) error.Overflow else answer218 return if (@shlWithOverflow(T, a, shift_amt, &answer)) error.Overflow else answer;
219}219}
220220
221/// Shifts left. Overflowed bits are truncated.221/// Shifts left. Overflowed bits are truncated.
...@@ -267,7 +267,7 @@ test "math.shr" {...@@ -267,7 +267,7 @@ test "math.shr" {
267}267}
268268
269pub fn Log2Int(comptime T: type) -> type {269pub fn Log2Int(comptime T: type) -> type {
270 @IntType(false, log2(T.bit_count))270 return @IntType(false, log2(T.bit_count));
271}271}
272272
273test "math overflow functions" {273test "math overflow functions" {
std/math/inf.zig+2-2
...@@ -2,9 +2,9 @@ const math = @import("index.zig");...@@ -2,9 +2,9 @@ const math = @import("index.zig");
2const assert = @import("../debug.zig").assert;2const assert = @import("../debug.zig").assert;
33
4pub fn inf(comptime T: type) -> T {4pub fn inf(comptime T: type) -> T {
5 switch (T) {5 return switch (T) {
6 f32 => @bitCast(f32, math.inf_u32),6 f32 => @bitCast(f32, math.inf_u32),
7 f64 => @bitCast(f64, math.inf_u64),7 f64 => @bitCast(f64, math.inf_u64),
8 else => @compileError("inf not implemented for " ++ @typeName(T)),8 else => @compileError("inf not implemented for " ++ @typeName(T)),
9 }9 };
10}10}
std/math/isfinite.zig+2-2
...@@ -6,11 +6,11 @@ pub fn isFinite(x: var) -> bool {...@@ -6,11 +6,11 @@ pub fn isFinite(x: var) -> bool {
6 switch (T) {6 switch (T) {
7 f32 => {7 f32 => {
8 const bits = @bitCast(u32, x);8 const bits = @bitCast(u32, x);
9 bits & 0x7FFFFFFF < 0x7F8000009 return bits & 0x7FFFFFFF < 0x7F800000;
10 },10 },
11 f64 => {11 f64 => {
12 const bits = @bitCast(u64, x);12 const bits = @bitCast(u64, x);
13 bits & (@maxValue(u64) >> 1) < (0x7FF << 52)13 return bits & (@maxValue(u64) >> 1) < (0x7FF << 52);
14 },14 },
15 else => {15 else => {
16 @compileError("isFinite not implemented for " ++ @typeName(T));16 @compileError("isFinite not implemented for " ++ @typeName(T));
std/math/isinf.zig+6-6
...@@ -6,11 +6,11 @@ pub fn isInf(x: var) -> bool {...@@ -6,11 +6,11 @@ pub fn isInf(x: var) -> bool {
6 switch (T) {6 switch (T) {
7 f32 => {7 f32 => {
8 const bits = @bitCast(u32, x);8 const bits = @bitCast(u32, x);
9 bits & 0x7FFFFFFF == 0x7F8000009 return bits & 0x7FFFFFFF == 0x7F800000;
10 },10 },
11 f64 => {11 f64 => {
12 const bits = @bitCast(u64, x);12 const bits = @bitCast(u64, x);
13 bits & (@maxValue(u64) >> 1) == (0x7FF << 52)13 return bits & (@maxValue(u64) >> 1) == (0x7FF << 52);
14 },14 },
15 else => {15 else => {
16 @compileError("isInf not implemented for " ++ @typeName(T));16 @compileError("isInf not implemented for " ++ @typeName(T));
...@@ -22,10 +22,10 @@ pub fn isPositiveInf(x: var) -> bool {...@@ -22,10 +22,10 @@ pub fn isPositiveInf(x: var) -> bool {
22 const T = @typeOf(x);22 const T = @typeOf(x);
23 switch (T) {23 switch (T) {
24 f32 => {24 f32 => {
25 @bitCast(u32, x) == 0x7F80000025 return @bitCast(u32, x) == 0x7F800000;
26 },26 },
27 f64 => {27 f64 => {
28 @bitCast(u64, x) == 0x7FF << 5228 return @bitCast(u64, x) == 0x7FF << 52;
29 },29 },
30 else => {30 else => {
31 @compileError("isPositiveInf not implemented for " ++ @typeName(T));31 @compileError("isPositiveInf not implemented for " ++ @typeName(T));
...@@ -37,10 +37,10 @@ pub fn isNegativeInf(x: var) -> bool {...@@ -37,10 +37,10 @@ pub fn isNegativeInf(x: var) -> bool {
37 const T = @typeOf(x);37 const T = @typeOf(x);
38 switch (T) {38 switch (T) {
39 f32 => {39 f32 => {
40 @bitCast(u32, x) == 0xFF80000040 return @bitCast(u32, x) == 0xFF800000;
41 },41 },
42 f64 => {42 f64 => {
43 @bitCast(u64, x) == 0xFFF << 5243 return @bitCast(u64, x) == 0xFFF << 52;
44 },44 },
45 else => {45 else => {
46 @compileError("isNegativeInf not implemented for " ++ @typeName(T));46 @compileError("isNegativeInf not implemented for " ++ @typeName(T));
std/math/isnan.zig+3-3
...@@ -6,11 +6,11 @@ pub fn isNan(x: var) -> bool {...@@ -6,11 +6,11 @@ pub fn isNan(x: var) -> bool {
6 switch (T) {6 switch (T) {
7 f32 => {7 f32 => {
8 const bits = @bitCast(u32, x);8 const bits = @bitCast(u32, x);
9 bits & 0x7FFFFFFF > 0x7F8000009 return bits & 0x7FFFFFFF > 0x7F800000;
10 },10 },
11 f64 => {11 f64 => {
12 const bits = @bitCast(u64, x);12 const bits = @bitCast(u64, x);
13 (bits & (@maxValue(u64) >> 1)) > (u64(0x7FF) << 52)13 return (bits & (@maxValue(u64) >> 1)) > (u64(0x7FF) << 52);
14 },14 },
15 else => {15 else => {
16 @compileError("isNan not implemented for " ++ @typeName(T));16 @compileError("isNan not implemented for " ++ @typeName(T));
...@@ -21,7 +21,7 @@ pub fn isNan(x: var) -> bool {...@@ -21,7 +21,7 @@ pub fn isNan(x: var) -> bool {
21// Note: A signalling nan is identical to a standard right now by may have a different bit21// Note: A signalling nan is identical to a standard right now by may have a different bit
22// representation in the future when required.22// representation in the future when required.
23pub fn isSignalNan(x: var) -> bool {23pub fn isSignalNan(x: var) -> bool {
24 isNan(x)24 return isNan(x);
25}25}
2626
27test "math.isNan" {27test "math.isNan" {
std/math/isnormal.zig+2-2
...@@ -6,11 +6,11 @@ pub fn isNormal(x: var) -> bool {...@@ -6,11 +6,11 @@ pub fn isNormal(x: var) -> bool {
6 switch (T) {6 switch (T) {
7 f32 => {7 f32 => {
8 const bits = @bitCast(u32, x);8 const bits = @bitCast(u32, x);
9 (bits + 0x00800000) & 0x7FFFFFFF >= 0x010000009 return (bits + 0x00800000) & 0x7FFFFFFF >= 0x01000000;
10 },10 },
11 f64 => {11 f64 => {
12 const bits = @bitCast(u64, x);12 const bits = @bitCast(u64, x);
13 (bits + (1 << 52)) & (@maxValue(u64) >> 1) >= (1 << 53)13 return (bits + (1 << 52)) & (@maxValue(u64) >> 1) >= (1 << 53);
14 },14 },
15 else => {15 else => {
16 @compileError("isNormal not implemented for " ++ @typeName(T));16 @compileError("isNormal not implemented for " ++ @typeName(T));
std/math/ln.zig+4-4
...@@ -14,7 +14,7 @@ pub fn ln(x: var) -> @typeOf(x) {...@@ -14,7 +14,7 @@ pub fn ln(x: var) -> @typeOf(x) {
14 const T = @typeOf(x);14 const T = @typeOf(x);
15 switch (@typeId(T)) {15 switch (@typeId(T)) {
16 TypeId.FloatLiteral => {16 TypeId.FloatLiteral => {
17 return @typeOf(1.0)(ln_64(x))17 return @typeOf(1.0)(ln_64(x));
18 },18 },
19 TypeId.Float => {19 TypeId.Float => {
20 return switch (T) {20 return switch (T) {
...@@ -84,7 +84,7 @@ pub fn ln_32(x_: f32) -> f32 {...@@ -84,7 +84,7 @@ pub fn ln_32(x_: f32) -> f32 {
84 const hfsq = 0.5 * f * f;84 const hfsq = 0.5 * f * f;
85 const dk = f32(k);85 const dk = f32(k);
8686
87 s * (hfsq + R) + dk * ln2_lo - hfsq + f + dk * ln2_hi87 return s * (hfsq + R) + dk * ln2_lo - hfsq + f + dk * ln2_hi;
88}88}
8989
90pub fn ln_64(x_: f64) -> f64 {90pub fn ln_64(x_: f64) -> f64 {
...@@ -116,7 +116,7 @@ pub fn ln_64(x_: f64) -> f64 {...@@ -116,7 +116,7 @@ pub fn ln_64(x_: f64) -> f64 {
116 // subnormal, scale x116 // subnormal, scale x
117 k -= 54;117 k -= 54;
118 x *= 0x1.0p54;118 x *= 0x1.0p54;
119 hx = u32(@bitCast(u64, ix) >> 32)119 hx = u32(@bitCast(u64, ix) >> 32);
120 }120 }
121 else if (hx >= 0x7FF00000) {121 else if (hx >= 0x7FF00000) {
122 return x;122 return x;
...@@ -142,7 +142,7 @@ pub fn ln_64(x_: f64) -> f64 {...@@ -142,7 +142,7 @@ pub fn ln_64(x_: f64) -> f64 {
142 const R = t2 + t1;142 const R = t2 + t1;
143 const dk = f64(k);143 const dk = f64(k);
144144
145 s * (hfsq + R) + dk * ln2_lo - hfsq + f + dk * ln2_hi145 return s * (hfsq + R) + dk * ln2_lo - hfsq + f + dk * ln2_hi;
146}146}
147147
148test "math.ln" {148test "math.ln" {
std/math/log.zig+1-1
...@@ -29,7 +29,7 @@ pub fn log(comptime T: type, base: T, x: T) -> T {...@@ -29,7 +29,7 @@ pub fn log(comptime T: type, base: T, x: T) -> T {
29 f32 => return f32(math.ln(f64(x)) / math.ln(f64(base))),29 f32 => return f32(math.ln(f64(x)) / math.ln(f64(base))),
30 f64 => return math.ln(x) / math.ln(f64(base)),30 f64 => return math.ln(x) / math.ln(f64(base)),
31 else => @compileError("log not implemented for " ++ @typeName(T)),31 else => @compileError("log not implemented for " ++ @typeName(T)),
32 };32 }
33 },33 },
3434
35 else => {35 else => {
std/math/log10.zig+4-4
...@@ -14,7 +14,7 @@ pub fn log10(x: var) -> @typeOf(x) {...@@ -14,7 +14,7 @@ pub fn log10(x: var) -> @typeOf(x) {
14 const T = @typeOf(x);14 const T = @typeOf(x);
15 switch (@typeId(T)) {15 switch (@typeId(T)) {
16 TypeId.FloatLiteral => {16 TypeId.FloatLiteral => {
17 return @typeOf(1.0)(log10_64(x))17 return @typeOf(1.0)(log10_64(x));
18 },18 },
19 TypeId.Float => {19 TypeId.Float => {
20 return switch (T) {20 return switch (T) {
...@@ -90,7 +90,7 @@ pub fn log10_32(x_: f32) -> f32 {...@@ -90,7 +90,7 @@ pub fn log10_32(x_: f32) -> f32 {
90 const lo = f - hi - hfsq + s * (hfsq + R);90 const lo = f - hi - hfsq + s * (hfsq + R);
91 const dk = f32(k);91 const dk = f32(k);
9292
93 dk * log10_2lo + (lo + hi) * ivln10lo + lo * ivln10hi + hi * ivln10hi + dk * log10_2hi93 return dk * log10_2lo + (lo + hi) * ivln10lo + lo * ivln10hi + hi * ivln10hi + dk * log10_2hi;
94}94}
9595
96pub fn log10_64(x_: f64) -> f64 {96pub fn log10_64(x_: f64) -> f64 {
...@@ -124,7 +124,7 @@ pub fn log10_64(x_: f64) -> f64 {...@@ -124,7 +124,7 @@ pub fn log10_64(x_: f64) -> f64 {
124 // subnormal, scale x124 // subnormal, scale x
125 k -= 54;125 k -= 54;
126 x *= 0x1.0p54;126 x *= 0x1.0p54;
127 hx = u32(@bitCast(u64, x) >> 32)127 hx = u32(@bitCast(u64, x) >> 32);
128 }128 }
129 else if (hx >= 0x7FF00000) {129 else if (hx >= 0x7FF00000) {
130 return x;130 return x;
...@@ -167,7 +167,7 @@ pub fn log10_64(x_: f64) -> f64 {...@@ -167,7 +167,7 @@ pub fn log10_64(x_: f64) -> f64 {
167 val_lo += (y - ww) + val_hi;167 val_lo += (y - ww) + val_hi;
168 val_hi = ww;168 val_hi = ww;
169169
170 val_lo + val_hi170 return val_lo + val_hi;
171}171}
172172
173test "math.log10" {173test "math.log10" {
std/math/log1p.zig+4-4
...@@ -11,11 +11,11 @@ const assert = @import("../debug.zig").assert;...@@ -11,11 +11,11 @@ const assert = @import("../debug.zig").assert;
1111
12pub fn log1p(x: var) -> @typeOf(x) {12pub fn log1p(x: var) -> @typeOf(x) {
13 const T = @typeOf(x);13 const T = @typeOf(x);
14 switch (T) {14 return switch (T) {
15 f32 => @inlineCall(log1p_32, x),15 f32 => @inlineCall(log1p_32, x),
16 f64 => @inlineCall(log1p_64, x),16 f64 => @inlineCall(log1p_64, x),
17 else => @compileError("log1p not implemented for " ++ @typeName(T)),17 else => @compileError("log1p not implemented for " ++ @typeName(T)),
18 }18 };
19}19}
2020
21fn log1p_32(x: f32) -> f32 {21fn log1p_32(x: f32) -> f32 {
...@@ -91,7 +91,7 @@ fn log1p_32(x: f32) -> f32 {...@@ -91,7 +91,7 @@ fn log1p_32(x: f32) -> f32 {
91 const hfsq = 0.5 * f * f;91 const hfsq = 0.5 * f * f;
92 const dk = f32(k);92 const dk = f32(k);
9393
94 s * (hfsq + R) + (dk * ln2_lo + c) - hfsq + f + dk * ln2_hi94 return s * (hfsq + R) + (dk * ln2_lo + c) - hfsq + f + dk * ln2_hi;
95}95}
9696
97fn log1p_64(x: f64) -> f64 {97fn log1p_64(x: f64) -> f64 {
...@@ -172,7 +172,7 @@ fn log1p_64(x: f64) -> f64 {...@@ -172,7 +172,7 @@ fn log1p_64(x: f64) -> f64 {
172 const R = t2 + t1;172 const R = t2 + t1;
173 const dk = f64(k);173 const dk = f64(k);
174174
175 s * (hfsq + R) + (dk * ln2_lo + c) - hfsq + f + dk * ln2_hi175 return s * (hfsq + R) + (dk * ln2_lo + c) - hfsq + f + dk * ln2_hi;
176}176}
177177
178test "math.log1p" {178test "math.log1p" {
std/math/log2.zig+4-4
...@@ -14,7 +14,7 @@ pub fn log2(x: var) -> @typeOf(x) {...@@ -14,7 +14,7 @@ pub fn log2(x: var) -> @typeOf(x) {
14 const T = @typeOf(x);14 const T = @typeOf(x);
15 switch (@typeId(T)) {15 switch (@typeId(T)) {
16 TypeId.FloatLiteral => {16 TypeId.FloatLiteral => {
17 return @typeOf(1.0)(log2_64(x))17 return @typeOf(1.0)(log2_64(x));
18 },18 },
19 TypeId.Float => {19 TypeId.Float => {
20 return switch (T) {20 return switch (T) {
...@@ -26,7 +26,7 @@ pub fn log2(x: var) -> @typeOf(x) {...@@ -26,7 +26,7 @@ pub fn log2(x: var) -> @typeOf(x) {
26 TypeId.IntLiteral => comptime {26 TypeId.IntLiteral => comptime {
27 var result = 0;27 var result = 0;
28 var x_shifted = x;28 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) {}
30 return result;30 return result;
31 },31 },
32 TypeId.Int => {32 TypeId.Int => {
...@@ -94,7 +94,7 @@ pub fn log2_32(x_: f32) -> f32 {...@@ -94,7 +94,7 @@ pub fn log2_32(x_: f32) -> f32 {
94 u &= 0xFFFFF000;94 u &= 0xFFFFF000;
95 hi = @bitCast(f32, u);95 hi = @bitCast(f32, u);
96 const lo = f - hi - hfsq + s * (hfsq + R);96 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);
98}98}
9999
100pub fn log2_64(x_: f64) -> f64 {100pub fn log2_64(x_: f64) -> f64 {
...@@ -165,7 +165,7 @@ pub fn log2_64(x_: f64) -> f64 {...@@ -165,7 +165,7 @@ pub fn log2_64(x_: f64) -> f64 {
165 val_lo += (y - ww) + val_hi;165 val_lo += (y - ww) + val_hi;
166 val_hi = ww;166 val_hi = ww;
167167
168 val_lo + val_hi168 return val_lo + val_hi;
169}169}
170170
171test "math.log2" {171test "math.log2" {
std/math/modf.zig+6-6
...@@ -7,21 +7,21 @@ const math = @import("index.zig");...@@ -7,21 +7,21 @@ const math = @import("index.zig");
7const assert = @import("../debug.zig").assert;7const assert = @import("../debug.zig").assert;
88
9fn modf_result(comptime T: type) -> type {9fn modf_result(comptime T: type) -> type {
10 struct {10 return struct {
11 fpart: T,11 fpart: T,
12 ipart: T,12 ipart: T,
13 }13 };
14}14}
15pub const modf32_result = modf_result(f32);15pub const modf32_result = modf_result(f32);
16pub const modf64_result = modf_result(f64);16pub const modf64_result = modf_result(f64);
1717
18pub fn modf(x: var) -> modf_result(@typeOf(x)) {18pub fn modf(x: var) -> modf_result(@typeOf(x)) {
19 const T = @typeOf(x);19 const T = @typeOf(x);
20 switch (T) {20 return switch (T) {
21 f32 => @inlineCall(modf32, x),21 f32 => @inlineCall(modf32, x),
22 f64 => @inlineCall(modf64, x),22 f64 => @inlineCall(modf64, x),
23 else => @compileError("modf not implemented for " ++ @typeName(T)),23 else => @compileError("modf not implemented for " ++ @typeName(T)),
24 }24 };
25}25}
2626
27fn modf32(x: f32) -> modf32_result {27fn modf32(x: f32) -> modf32_result {
...@@ -66,7 +66,7 @@ fn modf32(x: f32) -> modf32_result {...@@ -66,7 +66,7 @@ fn modf32(x: f32) -> modf32_result {
66 const uf = @bitCast(f32, u & ~mask);66 const uf = @bitCast(f32, u & ~mask);
67 result.ipart = uf;67 result.ipart = uf;
68 result.fpart = x - uf;68 result.fpart = x - uf;
69 result69 return result;
70}70}
7171
72fn modf64(x: f64) -> modf64_result {72fn modf64(x: f64) -> modf64_result {
...@@ -110,7 +110,7 @@ fn modf64(x: f64) -> modf64_result {...@@ -110,7 +110,7 @@ fn modf64(x: f64) -> modf64_result {
110 const uf = @bitCast(f64, u & ~mask);110 const uf = @bitCast(f64, u & ~mask);
111 result.ipart = uf;111 result.ipart = uf;
112 result.fpart = x - uf;112 result.fpart = x - uf;
113 result113 return result;
114}114}
115115
116test "math.modf" {116test "math.modf" {
std/math/nan.zig+4-4
...@@ -1,19 +1,19 @@...@@ -1,19 +1,19 @@
1const math = @import("index.zig");1const math = @import("index.zig");
22
3pub fn nan(comptime T: type) -> T {3pub fn nan(comptime T: type) -> T {
4 switch (T) {4 return switch (T) {
5 f32 => @bitCast(f32, math.nan_u32),5 f32 => @bitCast(f32, math.nan_u32),
6 f64 => @bitCast(f64, math.nan_u64),6 f64 => @bitCast(f64, math.nan_u64),
7 else => @compileError("nan not implemented for " ++ @typeName(T)),7 else => @compileError("nan not implemented for " ++ @typeName(T)),
8 }8 };
9}9}
1010
11// Note: A signalling nan is identical to a standard right now by may have a different bit11// Note: A signalling nan is identical to a standard right now by may have a different bit
12// representation in the future when required.12// representation in the future when required.
13pub fn snan(comptime T: type) -> T {13pub fn snan(comptime T: type) -> T {
14 switch (T) {14 return switch (T) {
15 f32 => @bitCast(f32, math.nan_u32),15 f32 => @bitCast(f32, math.nan_u32),
16 f64 => @bitCast(f64, math.nan_u64),16 f64 => @bitCast(f64, math.nan_u64),
17 else => @compileError("snan not implemented for " ++ @typeName(T)),17 else => @compileError("snan not implemented for " ++ @typeName(T)),
18 }18 };
19}19}
std/math/pow.zig+2-2
...@@ -166,12 +166,12 @@ pub fn pow(comptime T: type, x: T, y: T) -> T {...@@ -166,12 +166,12 @@ pub fn pow(comptime T: type, x: T, y: T) -> T {
166 ae = -ae;166 ae = -ae;
167 }167 }
168168
169 math.scalbn(a1, ae)169 return math.scalbn(a1, ae);
170}170}
171171
172fn isOddInteger(x: f64) -> bool {172fn isOddInteger(x: f64) -> bool {
173 const r = math.modf(x);173 const r = math.modf(x);
174 r.fpart == 0.0 and i64(r.ipart) & 1 == 1174 return r.fpart == 0.0 and i64(r.ipart) & 1 == 1;
175}175}
176176
177test "math.pow" {177test "math.pow" {
std/math/round.zig+6-6
...@@ -10,11 +10,11 @@ const math = @import("index.zig");...@@ -10,11 +10,11 @@ const math = @import("index.zig");
1010
11pub fn round(x: var) -> @typeOf(x) {11pub fn round(x: var) -> @typeOf(x) {
12 const T = @typeOf(x);12 const T = @typeOf(x);
13 switch (T) {13 return switch (T) {
14 f32 => @inlineCall(round32, x),14 f32 => @inlineCall(round32, x),
15 f64 => @inlineCall(round64, x),15 f64 => @inlineCall(round64, x),
16 else => @compileError("round not implemented for " ++ @typeName(T)),16 else => @compileError("round not implemented for " ++ @typeName(T)),
17 }17 };
18}18}
1919
20fn round32(x_: f32) -> f32 {20fn round32(x_: f32) -> f32 {
...@@ -48,9 +48,9 @@ fn round32(x_: f32) -> f32 {...@@ -48,9 +48,9 @@ fn round32(x_: f32) -> f32 {
48 }48 }
4949
50 if (u >> 31 != 0) {50 if (u >> 31 != 0) {
51 -y51 return -y;
52 } else {52 } else {
53 y53 return y;
54 }54 }
55}55}
5656
...@@ -85,9 +85,9 @@ fn round64(x_: f64) -> f64 {...@@ -85,9 +85,9 @@ fn round64(x_: f64) -> f64 {
85 }85 }
8686
87 if (u >> 63 != 0) {87 if (u >> 63 != 0) {
88 -y88 return -y;
89 } else {89 } else {
90 y90 return y;
91 }91 }
92}92}
9393
std/math/scalbn.zig+4-4
...@@ -3,11 +3,11 @@ const assert = @import("../debug.zig").assert;...@@ -3,11 +3,11 @@ const assert = @import("../debug.zig").assert;
33
4pub fn scalbn(x: var, n: i32) -> @typeOf(x) {4pub fn scalbn(x: var, n: i32) -> @typeOf(x) {
5 const T = @typeOf(x);5 const T = @typeOf(x);
6 switch (T) {6 return switch (T) {
7 f32 => @inlineCall(scalbn32, x, n),7 f32 => @inlineCall(scalbn32, x, n),
8 f64 => @inlineCall(scalbn64, x, n),8 f64 => @inlineCall(scalbn64, x, n),
9 else => @compileError("scalbn not implemented for " ++ @typeName(T)),9 else => @compileError("scalbn not implemented for " ++ @typeName(T)),
10 }10 };
11}11}
1212
13fn scalbn32(x: f32, n_: i32) -> f32 {13fn scalbn32(x: f32, n_: i32) -> f32 {
...@@ -37,7 +37,7 @@ fn scalbn32(x: f32, n_: i32) -> f32 {...@@ -37,7 +37,7 @@ fn scalbn32(x: f32, n_: i32) -> f32 {
37 }37 }
3838
39 const u = u32(n +% 0x7F) << 23;39 const u = u32(n +% 0x7F) << 23;
40 y * @bitCast(f32, u)40 return y * @bitCast(f32, u);
41}41}
4242
43fn scalbn64(x: f64, n_: i32) -> f64 {43fn scalbn64(x: f64, n_: i32) -> f64 {
...@@ -67,7 +67,7 @@ fn scalbn64(x: f64, n_: i32) -> f64 {...@@ -67,7 +67,7 @@ fn scalbn64(x: f64, n_: i32) -> f64 {
67 }67 }
6868
69 const u = u64(n +% 0x3FF) << 52;69 const u = u64(n +% 0x3FF) << 52;
70 y * @bitCast(f64, u)70 return y * @bitCast(f64, u);
71}71}
7272
73test "math.scalbn" {73test "math.scalbn" {
std/math/signbit.zig+4-4
...@@ -3,21 +3,21 @@ const assert = @import("../debug.zig").assert;...@@ -3,21 +3,21 @@ const assert = @import("../debug.zig").assert;
33
4pub fn signbit(x: var) -> bool {4pub fn signbit(x: var) -> bool {
5 const T = @typeOf(x);5 const T = @typeOf(x);
6 switch (T) {6 return switch (T) {
7 f32 => @inlineCall(signbit32, x),7 f32 => @inlineCall(signbit32, x),
8 f64 => @inlineCall(signbit64, x),8 f64 => @inlineCall(signbit64, x),
9 else => @compileError("signbit not implemented for " ++ @typeName(T)),9 else => @compileError("signbit not implemented for " ++ @typeName(T)),
10 }10 };
11}11}
1212
13fn signbit32(x: f32) -> bool {13fn signbit32(x: f32) -> bool {
14 const bits = @bitCast(u32, x);14 const bits = @bitCast(u32, x);
15 bits >> 31 != 015 return bits >> 31 != 0;
16}16}
1717
18fn signbit64(x: f64) -> bool {18fn signbit64(x: f64) -> bool {
19 const bits = @bitCast(u64, x);19 const bits = @bitCast(u64, x);
20 bits >> 63 != 020 return bits >> 63 != 0;
21}21}
2222
23test "math.signbit" {23test "math.signbit" {
std/math/sin.zig+13-13
...@@ -10,11 +10,11 @@ const assert = @import("../debug.zig").assert;...@@ -10,11 +10,11 @@ const assert = @import("../debug.zig").assert;
1010
11pub fn sin(x: var) -> @typeOf(x) {11pub fn sin(x: var) -> @typeOf(x) {
12 const T = @typeOf(x);12 const T = @typeOf(x);
13 switch (T) {13 return switch (T) {
14 f32 => @inlineCall(sin32, x),14 f32 => @inlineCall(sin32, x),
15 f64 => @inlineCall(sin64, x),15 f64 => @inlineCall(sin64, x),
16 else => @compileError("sin not implemented for " ++ @typeName(T)),16 else => @compileError("sin not implemented for " ++ @typeName(T)),
17 }17 };
18}18}
1919
20// sin polynomial coefficients20// sin polynomial coefficients
...@@ -75,18 +75,18 @@ fn sin32(x_: f32) -> f32 {...@@ -75,18 +75,18 @@ fn sin32(x_: f32) -> f32 {
75 const z = ((x - y * pi4a) - y * pi4b) - y * pi4c;75 const z = ((x - y * pi4a) - y * pi4b) - y * pi4c;
76 const w = z * z;76 const w = z * z;
7777
78 const r = {78 const r = r: {
79 if (j == 1 or j == 2) {79 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)))));
81 } else {81 } 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)))));
83 }83 }
84 };84 };
8585
86 if (sign) {86 if (sign) {
87 -r87 return -r;
88 } else {88 } else {
89 r89 return r;
90 }90 }
91}91}
9292
...@@ -127,25 +127,25 @@ fn sin64(x_: f64) -> f64 {...@@ -127,25 +127,25 @@ fn sin64(x_: f64) -> f64 {
127 const z = ((x - y * pi4a) - y * pi4b) - y * pi4c;127 const z = ((x - y * pi4a) - y * pi4b) - y * pi4c;
128 const w = z * z;128 const w = z * z;
129129
130 const r = {130 const r = r: {
131 if (j == 1 or j == 2) {131 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)))));
133 } else {133 } 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)))));
135 }135 }
136 };136 };
137137
138 if (sign) {138 if (sign) {
139 -r139 return -r;
140 } else {140 } else {
141 r141 return r;
142 }142 }
143}143}
144144
145test "math.sin" {145test "math.sin" {
146 assert(sin(f32(0.0)) == sin32(0.0));146 assert(sin(f32(0.0)) == sin32(0.0));
147 assert(sin(f64(0.0)) == sin64(0.0));147 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)));
149}149}
150150
151test "math.sin32" {151test "math.sin32" {
std/math/sinh.zig+4-4
...@@ -11,11 +11,11 @@ const expo2 = @import("expo2.zig").expo2;...@@ -11,11 +11,11 @@ const expo2 = @import("expo2.zig").expo2;
1111
12pub fn sinh(x: var) -> @typeOf(x) {12pub fn sinh(x: var) -> @typeOf(x) {
13 const T = @typeOf(x);13 const T = @typeOf(x);
14 switch (T) {14 return switch (T) {
15 f32 => @inlineCall(sinh32, x),15 f32 => @inlineCall(sinh32, x),
16 f64 => @inlineCall(sinh64, x),16 f64 => @inlineCall(sinh64, x),
17 else => @compileError("sinh not implemented for " ++ @typeName(T)),17 else => @compileError("sinh not implemented for " ++ @typeName(T)),
18 }18 };
19}19}
2020
21// sinh(x) = (exp(x) - 1 / exp(x)) / 221// sinh(x) = (exp(x) - 1 / exp(x)) / 2
...@@ -49,7 +49,7 @@ fn sinh32(x: f32) -> f32 {...@@ -49,7 +49,7 @@ fn sinh32(x: f32) -> f32 {
49 }49 }
5050
51 // |x| > log(FLT_MAX) or nan51 // |x| > log(FLT_MAX) or nan
52 2 * h * expo2(ax)52 return 2 * h * expo2(ax);
53}53}
5454
55fn sinh64(x: f64) -> f64 {55fn sinh64(x: f64) -> f64 {
...@@ -83,7 +83,7 @@ fn sinh64(x: f64) -> f64 {...@@ -83,7 +83,7 @@ fn sinh64(x: f64) -> f64 {
83 }83 }
8484
85 // |x| > log(DBL_MAX) or nan85 // |x| > log(DBL_MAX) or nan
86 2 * h * expo2(ax)86 return 2 * h * expo2(ax);
87}87}
8888
89test "math.sinh" {89test "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, @...@@ -14,7 +14,7 @@ pub fn sqrt(x: var) -> (if (@typeId(@typeOf(x)) == TypeId.Int) @IntType(false, @
14 const T = @typeOf(x);14 const T = @typeOf(x);
15 switch (@typeId(T)) {15 switch (@typeId(T)) {
16 TypeId.FloatLiteral => {16 TypeId.FloatLiteral => {
17 return T(sqrt64(x))17 return T(sqrt64(x));
18 },18 },
19 TypeId.Float => {19 TypeId.Float => {
20 return switch (T) {20 return switch (T) {
...@@ -64,7 +64,7 @@ fn sqrt32(x: f32) -> f32 {...@@ -64,7 +64,7 @@ fn sqrt32(x: f32) -> f32 {
64 // subnormal64 // subnormal
65 var i: i32 = 0;65 var i: i32 = 0;
66 while (ix & 0x00800000 == 0) : (i += 1) {66 while (ix & 0x00800000 == 0) : (i += 1) {
67 ix <<= 167 ix <<= 1;
68 }68 }
69 m -= i - 1;69 m -= i - 1;
70 }70 }
...@@ -112,7 +112,7 @@ fn sqrt32(x: f32) -> f32 {...@@ -112,7 +112,7 @@ fn sqrt32(x: f32) -> f32 {
112112
113 ix = (q >> 1) + 0x3f000000;113 ix = (q >> 1) + 0x3f000000;
114 ix += m << 23;114 ix += m << 23;
115 @bitCast(f32, ix)115 return @bitCast(f32, ix);
116}116}
117117
118// NOTE: The original code is full of implicit signed -> unsigned assumptions and u32 wraparound118// NOTE: The original code is full of implicit signed -> unsigned assumptions and u32 wraparound
...@@ -153,7 +153,7 @@ fn sqrt64(x: f64) -> f64 {...@@ -153,7 +153,7 @@ fn sqrt64(x: f64) -> f64 {
153 // subnormal153 // subnormal
154 var i: u32 = 0;154 var i: u32 = 0;
155 while (ix0 & 0x00100000 == 0) : (i += 1) {155 while (ix0 & 0x00100000 == 0) : (i += 1) {
156 ix0 <<= 1156 ix0 <<= 1;
157 }157 }
158 m -= i32(i) - 1;158 m -= i32(i) - 1;
159 ix0 |= ix1 >> u5(32 - i);159 ix0 |= ix1 >> u5(32 - i);
...@@ -245,7 +245,7 @@ fn sqrt64(x: f64) -> f64 {...@@ -245,7 +245,7 @@ fn sqrt64(x: f64) -> f64 {
245 iix0 = iix0 +% (m << 20);245 iix0 = iix0 +% (m << 20);
246246
247 const uz = (u64(iix0) << 32) | ix1;247 const uz = (u64(iix0) << 32) | ix1;
248 @bitCast(f64, uz)248 return @bitCast(f64, uz);
249}249}
250250
251test "math.sqrt" {251test "math.sqrt" {
std/math/tan.zig+10-10
...@@ -10,11 +10,11 @@ const assert = @import("../debug.zig").assert;...@@ -10,11 +10,11 @@ const assert = @import("../debug.zig").assert;
1010
11pub fn tan(x: var) -> @typeOf(x) {11pub fn tan(x: var) -> @typeOf(x) {
12 const T = @typeOf(x);12 const T = @typeOf(x);
13 switch (T) {13 return switch (T) {
14 f32 => @inlineCall(tan32, x),14 f32 => @inlineCall(tan32, x),
15 f64 => @inlineCall(tan64, x),15 f64 => @inlineCall(tan64, x),
16 else => @compileError("tan not implemented for " ++ @typeName(T)),16 else => @compileError("tan not implemented for " ++ @typeName(T)),
17 }17 };
18}18}
1919
20const Tp0 = -1.30936939181383777646E4;20const Tp0 = -1.30936939181383777646E4;
...@@ -62,11 +62,11 @@ fn tan32(x_: f32) -> f32 {...@@ -62,11 +62,11 @@ fn tan32(x_: f32) -> f32 {
62 const z = ((x - y * pi4a) - y * pi4b) - y * pi4c;62 const z = ((x - y * pi4a) - y * pi4b) - y * pi4c;
63 const w = z * z;63 const w = z * z;
6464
65 var r = {65 var r = r: {
66 if (w > 1e-14) {66 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));
68 } else {68 } else {
69 z69 break :r z;
70 }70 }
71 };71 };
7272
...@@ -77,7 +77,7 @@ fn tan32(x_: f32) -> f32 {...@@ -77,7 +77,7 @@ fn tan32(x_: f32) -> f32 {
77 r = -r;77 r = -r;
78 }78 }
7979
80 r80 return r;
81}81}
8282
83fn tan64(x_: f64) -> f64 {83fn tan64(x_: f64) -> f64 {
...@@ -111,11 +111,11 @@ fn tan64(x_: f64) -> f64 {...@@ -111,11 +111,11 @@ fn tan64(x_: f64) -> f64 {
111 const z = ((x - y * pi4a) - y * pi4b) - y * pi4c;111 const z = ((x - y * pi4a) - y * pi4b) - y * pi4c;
112 const w = z * z;112 const w = z * z;
113113
114 var r = {114 var r = r: {
115 if (w > 1e-14) {115 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));
117 } else {117 } else {
118 z118 break :r z;
119 }119 }
120 };120 };
121121
...@@ -126,7 +126,7 @@ fn tan64(x_: f64) -> f64 {...@@ -126,7 +126,7 @@ fn tan64(x_: f64) -> f64 {
126 r = -r;126 r = -r;
127 }127 }
128128
129 r129 return r;
130}130}
131131
132test "math.tan" {132test "math.tan" {
std/math/tanh.zig+6-6
...@@ -11,11 +11,11 @@ const expo2 = @import("expo2.zig").expo2;...@@ -11,11 +11,11 @@ const expo2 = @import("expo2.zig").expo2;
1111
12pub fn tanh(x: var) -> @typeOf(x) {12pub fn tanh(x: var) -> @typeOf(x) {
13 const T = @typeOf(x);13 const T = @typeOf(x);
14 switch (T) {14 return switch (T) {
15 f32 => @inlineCall(tanh32, x),15 f32 => @inlineCall(tanh32, x),
16 f64 => @inlineCall(tanh64, x),16 f64 => @inlineCall(tanh64, x),
17 else => @compileError("tanh not implemented for " ++ @typeName(T)),17 else => @compileError("tanh not implemented for " ++ @typeName(T)),
18 }18 };
19}19}
2020
21// tanh(x) = (exp(x) - exp(-x)) / (exp(x) + exp(-x))21// tanh(x) = (exp(x) - exp(-x)) / (exp(x) + exp(-x))
...@@ -59,9 +59,9 @@ fn tanh32(x: f32) -> f32 {...@@ -59,9 +59,9 @@ fn tanh32(x: f32) -> f32 {
59 }59 }
6060
61 if (u >> 31 != 0) {61 if (u >> 31 != 0) {
62 -t62 return -t;
63 } else {63 } else {
64 t64 return t;
65 }65 }
66}66}
6767
...@@ -104,9 +104,9 @@ fn tanh64(x: f64) -> f64 {...@@ -104,9 +104,9 @@ fn tanh64(x: f64) -> f64 {
104 }104 }
105105
106 if (u >> 63 != 0) {106 if (u >> 63 != 0) {
107 -t107 return -t;
108 } else {108 } else {
109 t109 return t;
110 }110 }
111}111}
112112
std/math/trunc.zig+6-6
...@@ -9,11 +9,11 @@ const assert = @import("../debug.zig").assert;...@@ -9,11 +9,11 @@ const assert = @import("../debug.zig").assert;
99
10pub fn trunc(x: var) -> @typeOf(x) {10pub fn trunc(x: var) -> @typeOf(x) {
11 const T = @typeOf(x);11 const T = @typeOf(x);
12 switch (T) {12 return switch (T) {
13 f32 => @inlineCall(trunc32, x),13 f32 => @inlineCall(trunc32, x),
14 f64 => @inlineCall(trunc64, x),14 f64 => @inlineCall(trunc64, x),
15 else => @compileError("trunc not implemented for " ++ @typeName(T)),15 else => @compileError("trunc not implemented for " ++ @typeName(T)),
16 }16 };
17}17}
1818
19fn trunc32(x: f32) -> f32 {19fn trunc32(x: f32) -> f32 {
...@@ -30,10 +30,10 @@ fn trunc32(x: f32) -> f32 {...@@ -30,10 +30,10 @@ fn trunc32(x: f32) -> f32 {
3030
31 m = u32(@maxValue(u32)) >> u5(e);31 m = u32(@maxValue(u32)) >> u5(e);
32 if (u & m == 0) {32 if (u & m == 0) {
33 x33 return x;
34 } else {34 } else {
35 math.forceEval(x + 0x1p120);35 math.forceEval(x + 0x1p120);
36 @bitCast(f32, u & ~m)36 return @bitCast(f32, u & ~m);
37 }37 }
38}38}
3939
...@@ -51,10 +51,10 @@ fn trunc64(x: f64) -> f64 {...@@ -51,10 +51,10 @@ fn trunc64(x: f64) -> f64 {
5151
52 m = u64(@maxValue(u64)) >> u6(e);52 m = u64(@maxValue(u64)) >> u6(e);
53 if (u & m == 0) {53 if (u & m == 0) {
54 x54 return x;
55 } else {55 } else {
56 math.forceEval(x + 0x1p120);56 math.forceEval(x + 0x1p120);
57 @bitCast(f64, u & ~m)57 return @bitCast(f64, u & ~m);
58 }58 }
59}59}
6060
std/mem.zig+4-4
...@@ -354,11 +354,11 @@ pub fn eql_slice_u8(a: []const u8, b: []const u8) -> bool {...@@ -354,11 +354,11 @@ pub fn eql_slice_u8(a: []const u8, b: []const u8) -> bool {
354/// split(" abc def ghi ", " ")354/// split(" abc def ghi ", " ")
355/// Will return slices for "abc", "def", "ghi", null, in that order.355/// Will return slices for "abc", "def", "ghi", null, in that order.
356pub fn split(buffer: []const u8, split_bytes: []const u8) -> SplitIterator {356pub fn split(buffer: []const u8, split_bytes: []const u8) -> SplitIterator {
357 SplitIterator {357 return SplitIterator {
358 .index = 0,358 .index = 0,
359 .buffer = buffer,359 .buffer = buffer,
360 .split_bytes = split_bytes,360 .split_bytes = split_bytes,
361 }361 };
362}362}
363363
364test "mem.split" {364test "mem.split" {
...@@ -552,7 +552,7 @@ test "std.mem.reverse" {...@@ -552,7 +552,7 @@ test "std.mem.reverse" {
552 var arr = []i32{ 5, 3, 1, 2, 4 };552 var arr = []i32{ 5, 3, 1, 2, 4 };
553 reverse(i32, arr[0..]);553 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 }));
556}556}
557557
558/// In-place rotation of the values in an array ([0 1 2 3] becomes [1 2 3 0] if we rotate by 1)558/// 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" {...@@ -567,5 +567,5 @@ test "std.mem.rotate" {
567 var arr = []i32{ 5, 3, 1, 2, 4 };567 var arr = []i32{ 5, 3, 1, 2, 4 };
568 rotate(i32, arr[0..], 2);568 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 }));
571}571}
std/net.zig+11-11
...@@ -72,7 +72,7 @@ pub fn lookup(hostname: []const u8, out_addrs: []Address) -> %[]Address {...@@ -72,7 +72,7 @@ pub fn lookup(hostname: []const u8, out_addrs: []Address) -> %[]Address {
72// if (family != AF_INET)72// if (family != AF_INET)
73// buf[cnt++] = (struct address){ .family = AF_INET6, .addr = { [15] = 1 } };73// buf[cnt++] = (struct address){ .family = AF_INET6, .addr = { [15] = 1 } };
74//74//
75 unreachable // TODO75 unreachable; // TODO
76 }76 }
7777
78 // TODO78 // TODO
...@@ -84,7 +84,7 @@ pub fn lookup(hostname: []const u8, out_addrs: []Address) -> %[]Address {...@@ -84,7 +84,7 @@ pub fn lookup(hostname: []const u8, out_addrs: []Address) -> %[]Address {
84 // else => {},84 // else => {},
85 //};85 //};
8686
87 unreachable // TODO87 unreachable; // TODO
88}88}
8989
90pub fn connectAddr(addr: &Address, port: u16) -> %Connection {90pub fn connectAddr(addr: &Address, port: u16) -> %Connection {
...@@ -96,23 +96,23 @@ pub fn connectAddr(addr: &Address, port: u16) -> %Connection {...@@ -96,23 +96,23 @@ pub fn connectAddr(addr: &Address, port: u16) -> %Connection {
96 }96 }
97 const socket_fd = i32(socket_ret);97 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: {
100 var os_addr: linux.sockaddr_in = undefined;100 var os_addr: linux.sockaddr_in = undefined;
101 os_addr.family = addr.family;101 os_addr.family = addr.family;
102 os_addr.port = endian.swapIfLe(u16, port);102 os_addr.port = endian.swapIfLe(u16, port);
103 @memcpy((&u8)(&os_addr.addr), &addr.addr[0], 4);103 @memcpy((&u8)(&os_addr.addr), &addr.addr[0], 4);
104 @memset(&os_addr.zero[0], 0, @sizeOf(@typeOf(os_addr.zero)));104 @memset(&os_addr.zero[0], 0, @sizeOf(@typeOf(os_addr.zero)));
105 linux.connect(socket_fd, (&linux.sockaddr)(&os_addr), @sizeOf(linux.sockaddr_in))105 break :x linux.connect(socket_fd, (&linux.sockaddr)(&os_addr), @sizeOf(linux.sockaddr_in));
106 } else if (addr.family == linux.AF_INET6) {106 } else if (addr.family == linux.AF_INET6) x: {
107 var os_addr: linux.sockaddr_in6 = undefined;107 var os_addr: linux.sockaddr_in6 = undefined;
108 os_addr.family = addr.family;108 os_addr.family = addr.family;
109 os_addr.port = endian.swapIfLe(u16, port);109 os_addr.port = endian.swapIfLe(u16, port);
110 os_addr.flowinfo = 0;110 os_addr.flowinfo = 0;
111 os_addr.scope_id = addr.scope_id;111 os_addr.scope_id = addr.scope_id;
112 @memcpy(&os_addr.addr[0], &addr.addr[0], 16);112 @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));
114 } else {114 } else {
115 unreachable115 unreachable;
116 };116 };
117 const connect_err = linux.getErrno(connect_ret);117 const connect_err = linux.getErrno(connect_ret);
118 if (connect_err > 0) {118 if (connect_err > 0) {
...@@ -165,13 +165,13 @@ pub fn parseIpLiteral(buf: []const u8) -> %Address {...@@ -165,13 +165,13 @@ pub fn parseIpLiteral(buf: []const u8) -> %Address {
165fn hexDigit(c: u8) -> u8 {165fn hexDigit(c: u8) -> u8 {
166 // TODO use switch with range166 // TODO use switch with range
167 if ('0' <= c and c <= '9') {167 if ('0' <= c and c <= '9') {
168 c - '0'168 return c - '0';
169 } else if ('A' <= c and c <= 'Z') {169 } else if ('A' <= c and c <= 'Z') {
170 c - 'A' + 10170 return c - 'A' + 10;
171 } else if ('a' <= c and c <= 'z') {171 } else if ('a' <= c and c <= 'z') {
172 c - 'a' + 10172 return c - 'a' + 10;
173 } else {173 } else {
174 @maxValue(u8)174 return @maxValue(u8);
175 }175 }
176}176}
177177
std/os/child_process.zig+35-35
...@@ -115,7 +115,7 @@ pub const ChildProcess = struct {...@@ -115,7 +115,7 @@ pub const ChildProcess = struct {
115 return self.spawnWindows();115 return self.spawnWindows();
116 } else {116 } else {
117 return self.spawnPosix();117 return self.spawnPosix();
118 };118 }
119 }119 }
120120
121 pub fn spawnAndWait(self: &ChildProcess) -> %Term {121 pub fn spawnAndWait(self: &ChildProcess) -> %Term {
...@@ -249,12 +249,12 @@ pub const ChildProcess = struct {...@@ -249,12 +249,12 @@ pub const ChildProcess = struct {
249 fn waitUnwrappedWindows(self: &ChildProcess) -> %void {249 fn waitUnwrappedWindows(self: &ChildProcess) -> %void {
250 const result = os.windowsWaitSingle(self.handle, windows.INFINITE);250 const result = os.windowsWaitSingle(self.handle, windows.INFINITE);
251251
252 self.term = (%Term)({252 self.term = (%Term)(x: {
253 var exit_code: windows.DWORD = undefined;253 var exit_code: windows.DWORD = undefined;
254 if (windows.GetExitCodeProcess(self.handle, &exit_code) == 0) {254 if (windows.GetExitCodeProcess(self.handle, &exit_code) == 0) {
255 Term { .Unknown = 0 }255 break :x Term { .Unknown = 0 };
256 } else {256 } else {
257 Term { .Exited = @bitCast(i32, exit_code)}257 break :x Term { .Exited = @bitCast(i32, exit_code)};
258 }258 }
259 });259 });
260260
...@@ -300,7 +300,7 @@ pub const ChildProcess = struct {...@@ -300,7 +300,7 @@ pub const ChildProcess = struct {
300 defer {300 defer {
301 os.close(self.err_pipe[0]);301 os.close(self.err_pipe[0]);
302 os.close(self.err_pipe[1]);302 os.close(self.err_pipe[1]);
303 };303 }
304304
305 // Write @maxValue(ErrInt) to the write end of the err_pipe. This is after305 // Write @maxValue(ErrInt) to the write end of the err_pipe. This is after
306 // waitpid, so this write is guaranteed to be after the child306 // waitpid, so this write is guaranteed to be after the child
...@@ -319,15 +319,15 @@ pub const ChildProcess = struct {...@@ -319,15 +319,15 @@ pub const ChildProcess = struct {
319 }319 }
320320
321 fn statusToTerm(status: i32) -> Term {321 fn statusToTerm(status: i32) -> Term {
322 return if (posix.WIFEXITED(status)) {322 return if (posix.WIFEXITED(status))
323 Term { .Exited = posix.WEXITSTATUS(status) }323 Term { .Exited = posix.WEXITSTATUS(status) }
324 } else if (posix.WIFSIGNALED(status)) {324 else if (posix.WIFSIGNALED(status))
325 Term { .Signal = posix.WTERMSIG(status) }325 Term { .Signal = posix.WTERMSIG(status) }
326 } else if (posix.WIFSTOPPED(status)) {326 else if (posix.WIFSTOPPED(status))
327 Term { .Stopped = posix.WSTOPSIG(status) }327 Term { .Stopped = posix.WSTOPSIG(status) }
328 } else {328 else
329 Term { .Unknown = status }329 Term { .Unknown = status }
330 };330 ;
331 }331 }
332332
333 fn spawnPosix(self: &ChildProcess) -> %void {333 fn spawnPosix(self: &ChildProcess) -> %void {
...@@ -344,22 +344,22 @@ pub const ChildProcess = struct {...@@ -344,22 +344,22 @@ pub const ChildProcess = struct {
344 %defer if (self.stderr_behavior == StdIo.Pipe) { destroyPipe(stderr_pipe); };344 %defer if (self.stderr_behavior == StdIo.Pipe) { destroyPipe(stderr_pipe); };
345345
346 const any_ignore = (self.stdin_behavior == StdIo.Ignore or self.stdout_behavior == StdIo.Ignore or self.stderr_behavior == StdIo.Ignore);346 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)
348 %return os.posixOpen("/dev/null", posix.O_RDWR, 0, null)348 %return os.posixOpen("/dev/null", posix.O_RDWR, 0, null)
349 } else {349 else
350 undefined350 undefined
351 };351 ;
352 defer { if (any_ignore) os.close(dev_null_fd); };352 defer { if (any_ignore) os.close(dev_null_fd); }
353353
354 var env_map_owned: BufMap = undefined;354 var env_map_owned: BufMap = undefined;
355 var we_own_env_map: bool = undefined;355 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: {
357 we_own_env_map = false;357 we_own_env_map = false;
358 env_map358 break :x env_map;
359 } else {359 } else x: {
360 we_own_env_map = true;360 we_own_env_map = true;
361 env_map_owned = %return os.getEnvMap(self.allocator);361 env_map_owned = %return os.getEnvMap(self.allocator);
362 &env_map_owned362 break :x &env_map_owned;
363 };363 };
364 defer { if (we_own_env_map) env_map_owned.deinit(); }364 defer { if (we_own_env_map) env_map_owned.deinit(); }
365365
...@@ -450,13 +450,13 @@ pub const ChildProcess = struct {...@@ -450,13 +450,13 @@ pub const ChildProcess = struct {
450 self.stdout_behavior == StdIo.Ignore or450 self.stdout_behavior == StdIo.Ignore or
451 self.stderr_behavior == StdIo.Ignore);451 self.stderr_behavior == StdIo.Ignore);
452452
453 const nul_handle = if (any_ignore) {453 const nul_handle = if (any_ignore)
454 %return os.windowsOpen("NUL", windows.GENERIC_READ, windows.FILE_SHARE_READ,454 %return os.windowsOpen("NUL", windows.GENERIC_READ, windows.FILE_SHARE_READ,
455 windows.OPEN_EXISTING, windows.FILE_ATTRIBUTE_NORMAL, null)455 windows.OPEN_EXISTING, windows.FILE_ATTRIBUTE_NORMAL, null)
456 } else {456 else
457 undefined457 undefined
458 };458 ;
459 defer { if (any_ignore) os.close(nul_handle); };459 defer { if (any_ignore) os.close(nul_handle); }
460 if (any_ignore) {460 if (any_ignore) {
461 %return windowsSetHandleInfo(nul_handle, windows.HANDLE_FLAG_INHERIT, 0);461 %return windowsSetHandleInfo(nul_handle, windows.HANDLE_FLAG_INHERIT, 0);
462 }462 }
...@@ -542,30 +542,30 @@ pub const ChildProcess = struct {...@@ -542,30 +542,30 @@ pub const ChildProcess = struct {
542 };542 };
543 var piProcInfo: windows.PROCESS_INFORMATION = undefined;543 var piProcInfo: windows.PROCESS_INFORMATION = undefined;
544544
545 const cwd_slice = if (self.cwd) |cwd| {545 const cwd_slice = if (self.cwd) |cwd|
546 %return cstr.addNullByte(self.allocator, cwd)546 %return cstr.addNullByte(self.allocator, cwd)
547 } else {547 else
548 null548 null
549 };549 ;
550 defer if (cwd_slice) |cwd| self.allocator.free(cwd);550 defer if (cwd_slice) |cwd| self.allocator.free(cwd);
551 const cwd_ptr = if (cwd_slice) |cwd| cwd.ptr else null;551 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|
554 %return os.createWindowsEnvBlock(self.allocator, env_map)554 %return os.createWindowsEnvBlock(self.allocator, env_map)
555 } else {555 else
556 null556 null
557 };557 ;
558 defer if (maybe_envp_buf) |envp_buf| self.allocator.free(envp_buf);558 defer if (maybe_envp_buf) |envp_buf| self.allocator.free(envp_buf);
559 const envp_ptr = if (maybe_envp_buf) |envp_buf| envp_buf.ptr else null;559 const envp_ptr = if (maybe_envp_buf) |envp_buf| envp_buf.ptr else null;
560560
561 // the cwd set in ChildProcess is in effect when choosing the executable path561 // the cwd set in ChildProcess is in effect when choosing the executable path
562 // to match posix semantics562 // to match posix semantics
563 const app_name = if (self.cwd) |cwd| {563 const app_name = if (self.cwd) |cwd| x: {
564 const resolved = %return os.path.resolve(self.allocator, cwd, self.argv[0]);564 const resolved = %return os.path.resolve(self.allocator, cwd, self.argv[0]);
565 defer self.allocator.free(resolved);565 defer self.allocator.free(resolved);
566 %return cstr.addNullByte(self.allocator, resolved)566 break :x %return cstr.addNullByte(self.allocator, resolved);
567 } else {567 } else x: {
568 %return cstr.addNullByte(self.allocator, self.argv[0])568 break :x %return cstr.addNullByte(self.allocator, self.argv[0]);
569 };569 };
570 defer self.allocator.free(app_name);570 defer self.allocator.free(app_name);
571571
...@@ -741,7 +741,7 @@ fn makePipe() -> %[2]i32 {...@@ -741,7 +741,7 @@ fn makePipe() -> %[2]i32 {
741 return switch (err) {741 return switch (err) {
742 posix.EMFILE, posix.ENFILE => error.SystemResources,742 posix.EMFILE, posix.ENFILE => error.SystemResources,
743 else => os.unexpectedErrorPosix(err),743 else => os.unexpectedErrorPosix(err),
744 }744 };
745 }745 }
746 return fds;746 return fds;
747}747}
...@@ -800,10 +800,10 @@ fn handleTerm(pid: i32, status: i32) {...@@ -800,10 +800,10 @@ fn handleTerm(pid: i32, status: i32) {
800 }800 }
801}801}
802802
803const sigchld_set = {803const sigchld_set = x: {
804 var signal_set = posix.empty_sigset;804 var signal_set = posix.empty_sigset;
805 posix.sigaddset(&signal_set, posix.SIGCHLD);805 posix.sigaddset(&signal_set, posix.SIGCHLD);
806 signal_set806 break :x signal_set;
807};807};
808808
809fn block_SIGCHLD() {809fn block_SIGCHLD() {
std/os/darwin.zig+38-42
...@@ -97,63 +97,63 @@ pub const SIGINFO = 29; /// information request...@@ -97,63 +97,63 @@ pub const SIGINFO = 29; /// information request
97pub const SIGUSR1 = 30; /// user defined signal 197pub const SIGUSR1 = 30; /// user defined signal 1
98pub const SIGUSR2 = 31; /// user defined signal 298pub const SIGUSR2 = 31; /// user defined signal 2
9999
100fn wstatus(x: i32) -> i32 { x & 0o177 }100fn wstatus(x: i32) -> i32 { return x & 0o177; }
101const wstopped = 0o177;101const wstopped = 0o177;
102pub fn WEXITSTATUS(x: i32) -> i32 { x >> 8 }102pub fn WEXITSTATUS(x: i32) -> i32 { return x >> 8; }
103pub fn WTERMSIG(x: i32) -> i32 { wstatus(x) }103pub fn WTERMSIG(x: i32) -> i32 { return wstatus(x); }
104pub fn WSTOPSIG(x: i32) -> i32 { x >> 8 }104pub fn WSTOPSIG(x: i32) -> i32 { return x >> 8; }
105pub fn WIFEXITED(x: i32) -> bool { wstatus(x) == 0 }105pub fn WIFEXITED(x: i32) -> bool { return wstatus(x) == 0; }
106pub fn WIFSTOPPED(x: i32) -> bool { wstatus(x) == wstopped and WSTOPSIG(x) != 0x13 }106pub fn WIFSTOPPED(x: i32) -> bool { return wstatus(x) == wstopped and WSTOPSIG(x) != 0x13; }
107pub fn WIFSIGNALED(x: i32) -> bool { wstatus(x) != wstopped and wstatus(x) != 0 }107pub fn WIFSIGNALED(x: i32) -> bool { return wstatus(x) != wstopped and wstatus(x) != 0; }
108108
109/// Get the errno from a syscall return value, or 0 for no error.109/// Get the errno from a syscall return value, or 0 for no error.
110pub fn getErrno(r: usize) -> usize {110pub fn getErrno(r: usize) -> usize {
111 const signed_r = @bitCast(isize, r);111 const signed_r = @bitCast(isize, r);
112 if (signed_r > -4096 and signed_r < 0) usize(-signed_r) else 0112 return if (signed_r > -4096 and signed_r < 0) usize(-signed_r) else 0;
113}113}
114114
115pub fn close(fd: i32) -> usize {115pub fn close(fd: i32) -> usize {
116 errnoWrap(c.close(fd))116 return errnoWrap(c.close(fd));
117}117}
118118
119pub fn abort() -> noreturn {119pub fn abort() -> noreturn {
120 c.abort()120 return c.abort();
121}121}
122122
123pub fn exit(code: i32) -> noreturn {123pub fn exit(code: i32) -> noreturn {
124 c.exit(code)124 return c.exit(code);
125}125}
126126
127pub fn isatty(fd: i32) -> bool {127pub fn isatty(fd: i32) -> bool {
128 c.isatty(fd) != 0128 return c.isatty(fd) != 0;
129}129}
130130
131pub fn fstat(fd: i32, buf: &c.Stat) -> usize {131pub fn fstat(fd: i32, buf: &c.Stat) -> usize {
132 errnoWrap(c.@"fstat$INODE64"(fd, buf))132 return errnoWrap(c.@"fstat$INODE64"(fd, buf));
133}133}
134134
135pub fn lseek(fd: i32, offset: isize, whence: c_int) -> usize {135pub 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));
137}137}
138138
139pub fn open(path: &const u8, flags: u32, mode: usize) -> usize {139pub 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));
141}141}
142142
143pub fn raise(sig: i32) -> usize {143pub fn raise(sig: i32) -> usize {
144 errnoWrap(c.raise(sig))144 return errnoWrap(c.raise(sig));
145}145}
146146
147pub fn read(fd: i32, buf: &u8, nbyte: usize) -> usize {147pub 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));
149}149}
150150
151pub fn stat(noalias path: &const u8, noalias buf: &stat) -> usize {151pub fn stat(noalias path: &const u8, noalias buf: &stat) -> usize {
152 errnoWrap(c.stat(path, buf))152 return errnoWrap(c.stat(path, buf));
153}153}
154154
155pub fn write(fd: i32, buf: &const u8, nbyte: usize) -> usize {155pub 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));
157}157}
158158
159pub fn mmap(address: ?&u8, length: usize, prot: usize, flags: usize, fd: i32,159pub 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,...@@ -166,79 +166,79 @@ pub fn mmap(address: ?&u8, length: usize, prot: usize, flags: usize, fd: i32,
166}166}
167167
168pub fn munmap(address: &u8, length: usize) -> usize {168pub 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));
170}170}
171171
172pub fn unlink(path: &const u8) -> usize {172pub fn unlink(path: &const u8) -> usize {
173 errnoWrap(c.unlink(path))173 return errnoWrap(c.unlink(path));
174}174}
175175
176pub fn getcwd(buf: &u8, size: usize) -> usize {176pub fn getcwd(buf: &u8, size: usize) -> usize {
177 if (c.getcwd(buf, size) == null) @bitCast(usize, -isize(*c._errno())) else 0177 return if (c.getcwd(buf, size) == null) @bitCast(usize, -isize(*c._errno())) else 0;
178}178}
179179
180pub fn waitpid(pid: i32, status: &i32, options: u32) -> usize {180pub fn waitpid(pid: i32, status: &i32, options: u32) -> usize {
181 comptime assert(i32.bit_count == c_int.bit_count);181 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)));
183}183}
184184
185pub fn fork() -> usize {185pub fn fork() -> usize {
186 errnoWrap(c.fork())186 return errnoWrap(c.fork());
187}187}
188188
189pub fn pipe(fds: &[2]i32) -> usize {189pub fn pipe(fds: &[2]i32) -> usize {
190 comptime assert(i32.bit_count == c_int.bit_count);190 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)));
192}192}
193193
194pub fn mkdir(path: &const u8, mode: u32) -> usize {194pub fn mkdir(path: &const u8, mode: u32) -> usize {
195 errnoWrap(c.mkdir(path, mode))195 return errnoWrap(c.mkdir(path, mode));
196}196}
197197
198pub fn symlink(existing: &const u8, new: &const u8) -> usize {198pub fn symlink(existing: &const u8, new: &const u8) -> usize {
199 errnoWrap(c.symlink(existing, new))199 return errnoWrap(c.symlink(existing, new));
200}200}
201201
202pub fn rename(old: &const u8, new: &const u8) -> usize {202pub fn rename(old: &const u8, new: &const u8) -> usize {
203 errnoWrap(c.rename(old, new))203 return errnoWrap(c.rename(old, new));
204}204}
205205
206pub fn chdir(path: &const u8) -> usize {206pub fn chdir(path: &const u8) -> usize {
207 errnoWrap(c.chdir(path))207 return errnoWrap(c.chdir(path));
208}208}
209209
210pub fn execve(path: &const u8, argv: &const ?&const u8, envp: &const ?&const u8)210pub fn execve(path: &const u8, argv: &const ?&const u8, envp: &const ?&const u8)
211 -> usize211 -> usize
212{212{
213 errnoWrap(c.execve(path, argv, envp))213 return errnoWrap(c.execve(path, argv, envp));
214}214}
215215
216pub fn dup2(old: i32, new: i32) -> usize {216pub fn dup2(old: i32, new: i32) -> usize {
217 errnoWrap(c.dup2(old, new))217 return errnoWrap(c.dup2(old, new));
218}218}
219219
220pub fn readlink(noalias path: &const u8, noalias buf_ptr: &u8, buf_len: usize) -> usize {220pub 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));
222}222}
223223
224pub fn nanosleep(req: &const timespec, rem: ?&timespec) -> usize {224pub fn nanosleep(req: &const timespec, rem: ?&timespec) -> usize {
225 errnoWrap(c.nanosleep(req, rem))225 return errnoWrap(c.nanosleep(req, rem));
226}226}
227227
228pub fn realpath(noalias filename: &const u8, noalias resolved_name: &u8) -> usize {228pub 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 0229 return if (c.realpath(filename, resolved_name) == null) @bitCast(usize, -isize(*c._errno())) else 0;
230}230}
231231
232pub fn setreuid(ruid: u32, euid: u32) -> usize {232pub fn setreuid(ruid: u32, euid: u32) -> usize {
233 errnoWrap(c.setreuid(ruid, euid))233 return errnoWrap(c.setreuid(ruid, euid));
234}234}
235235
236pub fn setregid(rgid: u32, egid: u32) -> usize {236pub fn setregid(rgid: u32, egid: u32) -> usize {
237 errnoWrap(c.setregid(rgid, egid))237 return errnoWrap(c.setregid(rgid, egid));
238}238}
239239
240pub fn sigprocmask(flags: u32, noalias set: &const sigset_t, noalias oldset: ?&sigset_t) -> usize {240pub 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));
242}242}
243243
244pub fn sigaction(sig: u5, noalias act: &const Sigaction, noalias oact: ?&Sigaction) -> usize {244pub fn sigaction(sig: u5, noalias act: &const Sigaction, noalias oact: ?&Sigaction) -> usize {
...@@ -285,9 +285,5 @@ pub fn sigaddset(set: &sigset_t, signo: u5) {...@@ -285,9 +285,5 @@ pub fn sigaddset(set: &sigset_t, signo: u5) {
285/// that the kernel represents it to libc. Errno was a mistake, let's make285/// that the kernel represents it to libc. Errno was a mistake, let's make
286/// it go away forever.286/// it go away forever.
287fn errnoWrap(value: isize) -> usize {287fn errnoWrap(value: isize) -> usize {
288 @bitCast(usize, if (value == -1) {288 return @bitCast(usize, if (value == -1) -isize(*c._errno()) else value);
289 -isize(*c._errno())
290 } else {
291 value
292 })
293}289}
std/os/index.zig+9-10
...@@ -84,7 +84,7 @@ pub fn getRandomBytes(buf: []u8) -> %void {...@@ -84,7 +84,7 @@ pub fn getRandomBytes(buf: []u8) -> %void {
84 posix.EFAULT => unreachable,84 posix.EFAULT => unreachable,
85 posix.EINTR => continue,85 posix.EINTR => continue,
86 else => unexpectedErrorPosix(err),86 else => unexpectedErrorPosix(err),
87 }87 };
88 }88 }
89 return;89 return;
90 },90 },
...@@ -151,18 +151,17 @@ pub coldcc fn exit(status: i32) -> noreturn {...@@ -151,18 +151,17 @@ pub coldcc fn exit(status: i32) -> noreturn {
151 }151 }
152 switch (builtin.os) {152 switch (builtin.os) {
153 Os.linux, Os.darwin, Os.macosx, Os.ios => {153 Os.linux, Os.darwin, Os.macosx, Os.ios => {
154 posix.exit(status)154 posix.exit(status);
155 },155 },
156 Os.windows => {156 Os.windows => {
157 // Map a possibly negative status code to a non-negative status for the systems default157 // Map a possibly negative status code to a non-negative status for the systems default
158 // integer width.158 // integer width.
159 const p_status = if (@sizeOf(c_uint) < @sizeOf(u32)) {159 const p_status = if (@sizeOf(c_uint) < @sizeOf(u32))
160 @truncate(c_uint, @bitCast(u32, status))160 @truncate(c_uint, @bitCast(u32, status))
161 } else {161 else
162 c_uint(@bitCast(u32, status))162 c_uint(@bitCast(u32, status));
163 };
164163
165 windows.ExitProcess(p_status)164 windows.ExitProcess(p_status);
166 },165 },
167 else => @compileError("Unsupported OS"),166 else => @compileError("Unsupported OS"),
168 }167 }
...@@ -289,7 +288,7 @@ pub fn posixOpen(file_path: []const u8, flags: u32, perm: usize, allocator: ?&Al...@@ -289,7 +288,7 @@ pub fn posixOpen(file_path: []const u8, flags: u32, perm: usize, allocator: ?&Al
289 posix.EPERM => error.AccessDenied,288 posix.EPERM => error.AccessDenied,
290 posix.EEXIST => error.PathAlreadyExists,289 posix.EEXIST => error.PathAlreadyExists,
291 else => unexpectedErrorPosix(err),290 else => unexpectedErrorPosix(err),
292 }291 };
293 }292 }
294 return i32(result);293 return i32(result);
295 }294 }
...@@ -680,7 +679,7 @@ pub fn deleteFileWindows(allocator: &Allocator, file_path: []const u8) -> %void...@@ -680,7 +679,7 @@ pub fn deleteFileWindows(allocator: &Allocator, file_path: []const u8) -> %void
680 windows.ERROR.ACCESS_DENIED => error.AccessDenied,679 windows.ERROR.ACCESS_DENIED => error.AccessDenied,
681 windows.ERROR.FILENAME_EXCED_RANGE, windows.ERROR.INVALID_PARAMETER => error.NameTooLong,680 windows.ERROR.FILENAME_EXCED_RANGE, windows.ERROR.INVALID_PARAMETER => error.NameTooLong,
682 else => unexpectedErrorWindows(err),681 else => unexpectedErrorWindows(err),
683 }682 };
684 }683 }
685}684}
686685
...@@ -1006,7 +1005,7 @@ pub const Dir = struct {...@@ -1006,7 +1005,7 @@ pub const Dir = struct {
1006 continue;1005 continue;
1007 },1006 },
1008 else => return unexpectedErrorPosix(err),1007 else => return unexpectedErrorPosix(err),
1009 };1008 }
1010 }1009 }
1011 if (result == 0)1010 if (result == 0)
1012 return null;1011 return null;
std/os/linux.zig+68-68
...@@ -367,14 +367,14 @@ pub const TFD_CLOEXEC = O_CLOEXEC;...@@ -367,14 +367,14 @@ pub const TFD_CLOEXEC = O_CLOEXEC;
367pub const TFD_TIMER_ABSTIME = 1;367pub const TFD_TIMER_ABSTIME = 1;
368pub const TFD_TIMER_CANCEL_ON_SET = (1 << 1);368pub const TFD_TIMER_CANCEL_ON_SET = (1 << 1);
369369
370fn unsigned(s: i32) -> u32 { @bitCast(u32, s) }370fn unsigned(s: i32) -> u32 { return @bitCast(u32, s); }
371fn signed(s: u32) -> i32 { @bitCast(i32, s) }371fn signed(s: u32) -> i32 { return @bitCast(i32, s); }
372pub fn WEXITSTATUS(s: i32) -> i32 { signed((unsigned(s) & 0xff00) >> 8) }372pub fn WEXITSTATUS(s: i32) -> i32 { return signed((unsigned(s) & 0xff00) >> 8); }
373pub fn WTERMSIG(s: i32) -> i32 { signed(unsigned(s) & 0x7f) }373pub fn WTERMSIG(s: i32) -> i32 { return signed(unsigned(s) & 0x7f); }
374pub fn WSTOPSIG(s: i32) -> i32 { WEXITSTATUS(s) }374pub fn WSTOPSIG(s: i32) -> i32 { return WEXITSTATUS(s); }
375pub fn WIFEXITED(s: i32) -> bool { WTERMSIG(s) == 0 }375pub fn WIFEXITED(s: i32) -> bool { return WTERMSIG(s) == 0; }
376pub fn WIFSTOPPED(s: i32) -> bool { (u16)(((unsigned(s)&0xffff)*%0x10001)>>8) > 0x7f00 }376pub fn WIFSTOPPED(s: i32) -> bool { return (u16)(((unsigned(s)&0xffff)*%0x10001)>>8) > 0x7f00; }
377pub fn WIFSIGNALED(s: i32) -> bool { (unsigned(s)&0xffff)-%1 < 0xff }377pub fn WIFSIGNALED(s: i32) -> bool { return (unsigned(s)&0xffff)-%1 < 0xff; }
378378
379379
380pub const winsize = extern struct {380pub const winsize = extern struct {
...@@ -387,31 +387,31 @@ pub const winsize = extern struct {...@@ -387,31 +387,31 @@ pub const winsize = extern struct {
387/// Get the errno from a syscall return value, or 0 for no error.387/// Get the errno from a syscall return value, or 0 for no error.
388pub fn getErrno(r: usize) -> usize {388pub fn getErrno(r: usize) -> usize {
389 const signed_r = @bitCast(isize, r);389 const signed_r = @bitCast(isize, r);
390 if (signed_r > -4096 and signed_r < 0) usize(-signed_r) else 0390 return if (signed_r > -4096 and signed_r < 0) usize(-signed_r) else 0;
391}391}
392392
393pub fn dup2(old: i32, new: i32) -> usize {393pub 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));
395}395}
396396
397pub fn chdir(path: &const u8) -> usize {397pub fn chdir(path: &const u8) -> usize {
398 arch.syscall1(arch.SYS_chdir, @ptrToInt(path))398 return arch.syscall1(arch.SYS_chdir, @ptrToInt(path));
399}399}
400400
401pub fn execve(path: &const u8, argv: &const ?&const u8, envp: &const ?&const u8) -> usize {401pub 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));
403}403}
404404
405pub fn fork() -> usize {405pub fn fork() -> usize {
406 arch.syscall0(arch.SYS_fork)406 return arch.syscall0(arch.SYS_fork);
407}407}
408408
409pub fn getcwd(buf: &u8, size: usize) -> usize {409pub 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);
411}411}
412412
413pub fn getdents(fd: i32, dirp: &u8, count: usize) -> usize {413pub 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);
415}415}
416416
417pub fn isatty(fd: i32) -> bool {417pub fn isatty(fd: i32) -> bool {
...@@ -420,123 +420,123 @@ pub fn isatty(fd: i32) -> bool {...@@ -420,123 +420,123 @@ pub fn isatty(fd: i32) -> bool {
420}420}
421421
422pub fn readlink(noalias path: &const u8, noalias buf_ptr: &u8, buf_len: usize) -> usize {422pub 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);
424}424}
425425
426pub fn mkdir(path: &const u8, mode: u32) -> usize {426pub 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);
428}428}
429429
430pub fn mmap(address: ?&u8, length: usize, prot: usize, flags: usize, fd: i32, offset: isize)430pub fn mmap(address: ?&u8, length: usize, prot: usize, flags: usize, fd: i32, offset: isize)
431 -> usize431 -> usize
432{432{
433 arch.syscall6(arch.SYS_mmap, @ptrToInt(address), length, prot, flags, usize(fd),433 return arch.syscall6(arch.SYS_mmap, @ptrToInt(address), length, prot, flags, usize(fd),
434 @bitCast(usize, offset))434 @bitCast(usize, offset));
435}435}
436436
437pub fn munmap(address: &u8, length: usize) -> usize {437pub 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);
439}439}
440440
441pub fn read(fd: i32, buf: &u8, count: usize) -> usize {441pub 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);
443}443}
444444
445pub fn rmdir(path: &const u8) -> usize {445pub fn rmdir(path: &const u8) -> usize {
446 arch.syscall1(arch.SYS_rmdir, @ptrToInt(path))446 return arch.syscall1(arch.SYS_rmdir, @ptrToInt(path));
447}447}
448448
449pub fn symlink(existing: &const u8, new: &const u8) -> usize {449pub 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));
451}451}
452452
453pub fn pread(fd: i32, buf: &u8, count: usize, offset: usize) -> usize {453pub 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);
455}455}
456456
457pub fn pipe(fd: &[2]i32) -> usize {457pub fn pipe(fd: &[2]i32) -> usize {
458 pipe2(fd, 0)458 return pipe2(fd, 0);
459}459}
460460
461pub fn pipe2(fd: &[2]i32, flags: usize) -> usize {461pub 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);
463}463}
464464
465pub fn write(fd: i32, buf: &const u8, count: usize) -> usize {465pub 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);
467}467}
468468
469pub fn pwrite(fd: i32, buf: &const u8, count: usize, offset: usize) -> usize {469pub 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);
471}471}
472472
473pub fn rename(old: &const u8, new: &const u8) -> usize {473pub 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));
475}475}
476476
477pub fn open(path: &const u8, flags: u32, perm: usize) -> usize {477pub 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);
479}479}
480480
481pub fn create(path: &const u8, perm: usize) -> usize {481pub 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);
483}483}
484484
485pub fn openat(dirfd: i32, path: &const u8, flags: usize, mode: usize) -> usize {485pub 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);
487}487}
488488
489pub fn close(fd: i32) -> usize {489pub fn close(fd: i32) -> usize {
490 arch.syscall1(arch.SYS_close, usize(fd))490 return arch.syscall1(arch.SYS_close, usize(fd));
491}491}
492492
493pub fn lseek(fd: i32, offset: isize, ref_pos: usize) -> usize {493pub 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);
495}495}
496496
497pub fn exit(status: i32) -> noreturn {497pub fn exit(status: i32) -> noreturn {
498 _ = arch.syscall1(arch.SYS_exit, @bitCast(usize, isize(status)));498 _ = arch.syscall1(arch.SYS_exit, @bitCast(usize, isize(status)));
499 unreachable499 unreachable;
500}500}
501501
502pub fn getrandom(buf: &u8, count: usize, flags: u32) -> usize {502pub 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));
504}504}
505505
506pub fn kill(pid: i32, sig: i32) -> usize {506pub 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));
508}508}
509509
510pub fn unlink(path: &const u8) -> usize {510pub fn unlink(path: &const u8) -> usize {
511 arch.syscall1(arch.SYS_unlink, @ptrToInt(path))511 return arch.syscall1(arch.SYS_unlink, @ptrToInt(path));
512}512}
513513
514pub fn waitpid(pid: i32, status: &i32, options: i32) -> usize {514pub 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);
516}516}
517517
518pub fn nanosleep(req: &const timespec, rem: ?&timespec) -> usize {518pub 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));
520}520}
521521
522pub fn setuid(uid: u32) -> usize {522pub fn setuid(uid: u32) -> usize {
523 arch.syscall1(arch.SYS_setuid, uid)523 return arch.syscall1(arch.SYS_setuid, uid);
524}524}
525525
526pub fn setgid(gid: u32) -> usize {526pub fn setgid(gid: u32) -> usize {
527 arch.syscall1(arch.SYS_setgid, gid)527 return arch.syscall1(arch.SYS_setgid, gid);
528}528}
529529
530pub fn setreuid(ruid: u32, euid: u32) -> usize {530pub fn setreuid(ruid: u32, euid: u32) -> usize {
531 arch.syscall2(arch.SYS_setreuid, ruid, euid)531 return arch.syscall2(arch.SYS_setreuid, ruid, euid);
532}532}
533533
534pub fn setregid(rgid: u32, egid: u32) -> usize {534pub fn setregid(rgid: u32, egid: u32) -> usize {
535 arch.syscall2(arch.SYS_setregid, rgid, egid)535 return arch.syscall2(arch.SYS_setregid, rgid, egid);
536}536}
537537
538pub fn sigprocmask(flags: u32, noalias set: &const sigset_t, noalias oldset: ?&sigset_t) -> usize {538pub 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);
540}540}
541541
542pub fn sigaction(sig: u6, noalias act: &const Sigaction, noalias oact: ?&Sigaction) -> usize {542pub fn sigaction(sig: u6, noalias act: &const Sigaction, noalias oact: ?&Sigaction) -> usize {
...@@ -652,69 +652,69 @@ pub const iovec = extern struct {...@@ -652,69 +652,69 @@ pub const iovec = extern struct {
652};652};
653653
654pub fn getsockname(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) -> usize {654pub 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));
656}656}
657657
658pub fn getpeername(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) -> usize {658pub 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));
660}660}
661661
662pub fn socket(domain: i32, socket_type: i32, protocol: i32) -> usize {662pub 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));
664}664}
665665
666pub fn setsockopt(fd: i32, level: i32, optname: i32, optval: &const u8, optlen: socklen_t) -> usize {666pub 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));
668}668}
669669
670pub fn getsockopt(fd: i32, level: i32, optname: i32, noalias optval: &u8, noalias optlen: &socklen_t) -> usize {670pub 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));
672}672}
673673
674pub fn sendmsg(fd: i32, msg: &const arch.msghdr, flags: u32) -> usize {674pub 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);
676}676}
677677
678pub fn connect(fd: i32, addr: &const sockaddr, len: socklen_t) -> usize {678pub 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));
680}680}
681681
682pub fn recvmsg(fd: i32, msg: &arch.msghdr, flags: u32) -> usize {682pub 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);
684}684}
685685
686pub fn recvfrom(fd: i32, noalias buf: &u8, len: usize, flags: u32,686pub fn recvfrom(fd: i32, noalias buf: &u8, len: usize, flags: u32,
687 noalias addr: ?&sockaddr, noalias alen: ?&socklen_t) -> usize687 noalias addr: ?&sockaddr, noalias alen: ?&socklen_t) -> usize
688{688{
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));
690}690}
691691
692pub fn shutdown(fd: i32, how: i32) -> usize {692pub 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));
694}694}
695695
696pub fn bind(fd: i32, addr: &const sockaddr, len: socklen_t) -> usize {696pub 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));
698}698}
699699
700pub fn listen(fd: i32, backlog: i32) -> usize {700pub 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));
702}702}
703703
704pub fn sendto(fd: i32, buf: &const u8, len: usize, flags: u32, addr: ?&const sockaddr, alen: socklen_t) -> usize {704pub 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));
706}706}
707707
708pub fn socketpair(domain: i32, socket_type: i32, protocol: i32, fd: [2]i32) -> usize {708pub 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]));
710}710}
711711
712pub fn accept(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t) -> usize {712pub 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);
714}714}
715715
716pub fn accept4(fd: i32, noalias addr: &sockaddr, noalias len: &socklen_t, flags: u32) -> usize {716pub 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);
718}718}
719719
720// error NameTooLong;720// error NameTooLong;
...@@ -749,7 +749,7 @@ pub const Stat = arch.Stat;...@@ -749,7 +749,7 @@ pub const Stat = arch.Stat;
749pub const timespec = arch.timespec;749pub const timespec = arch.timespec;
750750
751pub fn fstat(fd: i32, stat_buf: &Stat) -> usize {751pub 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));
753}753}
754754
755pub const epoll_data = u64;755pub const epoll_data = u64;
...@@ -760,19 +760,19 @@ pub const epoll_event = extern struct {...@@ -760,19 +760,19 @@ pub const epoll_event = extern struct {
760};760};
761761
762pub fn epoll_create() -> usize {762pub fn epoll_create() -> usize {
763 arch.syscall1(arch.SYS_epoll_create, usize(1))763 return arch.syscall1(arch.SYS_epoll_create, usize(1));
764}764}
765765
766pub fn epoll_ctl(epoll_fd: i32, op: i32, fd: i32, ev: &epoll_event) -> usize {766pub 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));
768}768}
769769
770pub fn epoll_wait(epoll_fd: i32, events: &epoll_event, maxevents: i32, timeout: i32) -> usize {770pub 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));
772}772}
773773
774pub fn timerfd_create(clockid: i32, flags: u32) -> usize {774pub 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));
776}776}
777777
778pub const itimerspec = extern struct {778pub const itimerspec = extern struct {
...@@ -781,11 +781,11 @@ pub const itimerspec = extern struct {...@@ -781,11 +781,11 @@ pub const itimerspec = extern struct {
781};781};
782782
783pub fn timerfd_gettime(fd: i32, curr_value: &itimerspec) -> usize {783pub 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));
785}785}
786786
787pub fn timerfd_settime(fd: i32, flags: u32, new_value: &const itimerspec, old_value: ?&itimerspec) -> usize {787pub 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));
789}789}
790790
791test "import linux_test" {791test "import linux_test" {
std/os/linux_x86_64.zig+16-16
...@@ -371,52 +371,52 @@ pub const F_GETOWN_EX = 16;...@@ -371,52 +371,52 @@ pub const F_GETOWN_EX = 16;
371pub const F_GETOWNER_UIDS = 17;371pub const F_GETOWNER_UIDS = 17;
372372
373pub fn syscall0(number: usize) -> usize {373pub fn syscall0(number: usize) -> usize {
374 asm volatile ("syscall"374 return asm volatile ("syscall"
375 : [ret] "={rax}" (-> usize)375 : [ret] "={rax}" (-> usize)
376 : [number] "{rax}" (number)376 : [number] "{rax}" (number)
377 : "rcx", "r11")377 : "rcx", "r11");
378}378}
379379
380pub fn syscall1(number: usize, arg1: usize) -> usize {380pub fn syscall1(number: usize, arg1: usize) -> usize {
381 asm volatile ("syscall"381 return asm volatile ("syscall"
382 : [ret] "={rax}" (-> usize)382 : [ret] "={rax}" (-> usize)
383 : [number] "{rax}" (number),383 : [number] "{rax}" (number),
384 [arg1] "{rdi}" (arg1)384 [arg1] "{rdi}" (arg1)
385 : "rcx", "r11")385 : "rcx", "r11");
386}386}
387387
388pub fn syscall2(number: usize, arg1: usize, arg2: usize) -> usize {388pub fn syscall2(number: usize, arg1: usize, arg2: usize) -> usize {
389 asm volatile ("syscall"389 return asm volatile ("syscall"
390 : [ret] "={rax}" (-> usize)390 : [ret] "={rax}" (-> usize)
391 : [number] "{rax}" (number),391 : [number] "{rax}" (number),
392 [arg1] "{rdi}" (arg1),392 [arg1] "{rdi}" (arg1),
393 [arg2] "{rsi}" (arg2)393 [arg2] "{rsi}" (arg2)
394 : "rcx", "r11")394 : "rcx", "r11");
395}395}
396396
397pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) -> usize {397pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) -> usize {
398 asm volatile ("syscall"398 return asm volatile ("syscall"
399 : [ret] "={rax}" (-> usize)399 : [ret] "={rax}" (-> usize)
400 : [number] "{rax}" (number),400 : [number] "{rax}" (number),
401 [arg1] "{rdi}" (arg1),401 [arg1] "{rdi}" (arg1),
402 [arg2] "{rsi}" (arg2),402 [arg2] "{rsi}" (arg2),
403 [arg3] "{rdx}" (arg3)403 [arg3] "{rdx}" (arg3)
404 : "rcx", "r11")404 : "rcx", "r11");
405}405}
406406
407pub fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) -> usize {407pub fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) -> usize {
408 asm volatile ("syscall"408 return asm volatile ("syscall"
409 : [ret] "={rax}" (-> usize)409 : [ret] "={rax}" (-> usize)
410 : [number] "{rax}" (number),410 : [number] "{rax}" (number),
411 [arg1] "{rdi}" (arg1),411 [arg1] "{rdi}" (arg1),
412 [arg2] "{rsi}" (arg2),412 [arg2] "{rsi}" (arg2),
413 [arg3] "{rdx}" (arg3),413 [arg3] "{rdx}" (arg3),
414 [arg4] "{r10}" (arg4)414 [arg4] "{r10}" (arg4)
415 : "rcx", "r11")415 : "rcx", "r11");
416}416}
417417
418pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) -> usize {418pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) -> usize {
419 asm volatile ("syscall"419 return asm volatile ("syscall"
420 : [ret] "={rax}" (-> usize)420 : [ret] "={rax}" (-> usize)
421 : [number] "{rax}" (number),421 : [number] "{rax}" (number),
422 [arg1] "{rdi}" (arg1),422 [arg1] "{rdi}" (arg1),
...@@ -424,13 +424,13 @@ pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usiz...@@ -424,13 +424,13 @@ pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usiz
424 [arg3] "{rdx}" (arg3),424 [arg3] "{rdx}" (arg3),
425 [arg4] "{r10}" (arg4),425 [arg4] "{r10}" (arg4),
426 [arg5] "{r8}" (arg5)426 [arg5] "{r8}" (arg5)
427 : "rcx", "r11")427 : "rcx", "r11");
428}428}
429429
430pub fn syscall6(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize,430pub fn syscall6(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize,
431 arg5: usize, arg6: usize) -> usize431 arg5: usize, arg6: usize) -> usize
432{432{
433 asm volatile ("syscall"433 return asm volatile ("syscall"
434 : [ret] "={rax}" (-> usize)434 : [ret] "={rax}" (-> usize)
435 : [number] "{rax}" (number),435 : [number] "{rax}" (number),
436 [arg1] "{rdi}" (arg1),436 [arg1] "{rdi}" (arg1),
...@@ -439,14 +439,14 @@ pub fn syscall6(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usiz...@@ -439,14 +439,14 @@ pub fn syscall6(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usiz
439 [arg4] "{r10}" (arg4),439 [arg4] "{r10}" (arg4),
440 [arg5] "{r8}" (arg5),440 [arg5] "{r8}" (arg5),
441 [arg6] "{r9}" (arg6)441 [arg6] "{r9}" (arg6)
442 : "rcx", "r11")442 : "rcx", "r11");
443}443}
444444
445pub nakedcc fn restore_rt() {445pub nakedcc fn restore_rt() {
446 asm volatile ("syscall"446 return asm volatile ("syscall"
447 :447 :
448 : [number] "{rax}" (usize(SYS_rt_sigreturn))448 : [number] "{rax}" (usize(SYS_rt_sigreturn))
449 : "rcx", "r11")449 : "rcx", "r11");
450}450}
451451
452452
std/os/path.zig+18-18
...@@ -749,21 +749,19 @@ pub fn relativeWindows(allocator: &Allocator, from: []const u8, to: []const u8)...@@ -749,21 +749,19 @@ pub fn relativeWindows(allocator: &Allocator, from: []const u8, to: []const u8)
749 const resolved_to = %return resolveWindows(allocator, [][]const u8{to});749 const resolved_to = %return resolveWindows(allocator, [][]const u8{to});
750 defer if (clean_up_resolved_to) allocator.free(resolved_to);750 defer if (clean_up_resolved_to) allocator.free(resolved_to);
751751
752 const result_is_to = if (drive(resolved_to)) |to_drive| {752 const result_is_to = if (drive(resolved_to)) |to_drive|
753 if (drive(resolved_from)) |from_drive| {753 if (drive(resolved_from)) |from_drive|
754 asciiUpper(from_drive[0]) != asciiUpper(to_drive[0])754 asciiUpper(from_drive[0]) != asciiUpper(to_drive[0])
755 } else {755 else
756 true756 true
757 }757 else if (networkShare(resolved_to)) |to_ns|
758 } else if (networkShare(resolved_to)) |to_ns| {758 if (networkShare(resolved_from)) |from_ns|
759 if (networkShare(resolved_from)) |from_ns| {
760 !networkShareServersEql(to_ns, from_ns)759 !networkShareServersEql(to_ns, from_ns)
761 } else {760 else
762 true761 true
763 }762 else
764 } else {763 unreachable;
765 unreachable764
766 };
767 if (result_is_to) {765 if (result_is_to) {
768 clean_up_resolved_to = false;766 clean_up_resolved_to = false;
769 return resolved_to;767 return resolved_to;
...@@ -964,14 +962,16 @@ pub fn real(allocator: &Allocator, pathname: []const u8) -> %[]u8 {...@@ -964,14 +962,16 @@ pub fn real(allocator: &Allocator, pathname: []const u8) -> %[]u8 {
964962
965 // windows returns \\?\ prepended to the path963 // windows returns \\?\ prepended to the path
966 // we strip it because nobody wants \\?\ prepended to their path964 // we strip it because nobody wants \\?\ prepended to their path
967 const final_len = if (result > 4 and mem.startsWith(u8, buf, "\\\\?\\")) {965 const final_len = x: {
968 var i: usize = 4;966 if (result > 4 and mem.startsWith(u8, buf, "\\\\?\\")) {
969 while (i < result) : (i += 1) {967 var i: usize = 4;
970 buf[i - 4] = buf[i];968 while (i < result) : (i += 1) {
969 buf[i - 4] = buf[i];
970 }
971 break :x result - 4;
972 } else {
973 break :x result;
971 }974 }
972 result - 4
973 } else {
974 result
975 };975 };
976976
977 return allocator.shrink(u8, buf, final_len);977 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...@@ -122,7 +122,7 @@ pub fn windowsOpen(file_path: []const u8, desired_access: windows.DWORD, share_m
122/// Caller must free result.122/// Caller must free result.
123pub fn createWindowsEnvBlock(allocator: &mem.Allocator, env_map: &const BufMap) -> %[]u8 {123pub fn createWindowsEnvBlock(allocator: &mem.Allocator, env_map: &const BufMap) -> %[]u8 {
124 // count bytes needed124 // count bytes needed
125 const bytes_needed = {125 const bytes_needed = x: {
126 var bytes_needed: usize = 1; // 1 for the final null byte126 var bytes_needed: usize = 1; // 1 for the final null byte
127 var it = env_map.iterator();127 var it = env_map.iterator();
128 while (it.next()) |pair| {128 while (it.next()) |pair| {
...@@ -130,7 +130,7 @@ pub fn createWindowsEnvBlock(allocator: &mem.Allocator, env_map: &const BufMap)...@@ -130,7 +130,7 @@ pub fn createWindowsEnvBlock(allocator: &mem.Allocator, env_map: &const BufMap)
130 // +1 for null byte130 // +1 for null byte
131 bytes_needed += pair.key.len + pair.value.len + 2;131 bytes_needed += pair.key.len + pair.value.len + 2;
132 }132 }
133 bytes_needed133 break :x bytes_needed;
134 };134 };
135 const result = %return allocator.alloc(u8, bytes_needed);135 const result = %return allocator.alloc(u8, bytes_needed);
136 %defer allocator.free(result);136 %defer allocator.free(result);
std/rand.zig+14-14
...@@ -28,9 +28,9 @@ pub const Rand = struct {...@@ -28,9 +28,9 @@ pub const Rand = struct {
2828
29 /// Initialize random state with the given seed.29 /// Initialize random state with the given seed.
30 pub fn init(seed: usize) -> Rand {30 pub fn init(seed: usize) -> Rand {
31 Rand {31 return Rand {
32 .rng = Rng.init(seed),32 .rng = Rng.init(seed),
33 }33 };
34 }34 }
3535
36 /// Get an integer or boolean with random bits.36 /// Get an integer or boolean with random bits.
...@@ -78,13 +78,13 @@ pub const Rand = struct {...@@ -78,13 +78,13 @@ pub const Rand = struct {
78 const end_uint = uint(end);78 const end_uint = uint(end);
79 const total_range = math.absCast(start) + end_uint;79 const total_range = math.absCast(start) + end_uint;
80 const value = r.range(uint, 0, total_range);80 const value = r.range(uint, 0, total_range);
81 const result = if (value < end_uint) {81 const result = if (value < end_uint) x: {
82 T(value)82 break :x T(value);
83 } else if (value == end_uint) {83 } else if (value == end_uint) x: {
84 start84 break :x start;
85 } else {85 } else x: {
86 // Can't overflow because the range is over signed ints86 // Can't overflow because the range is over signed ints
87 %%math.negateCast(value - end_uint)87 break :x %%math.negateCast(value - end_uint);
88 };88 };
89 return result;89 return result;
90 } else {90 } else {
...@@ -114,13 +114,13 @@ pub const Rand = struct {...@@ -114,13 +114,13 @@ pub const Rand = struct {
114 // const rand_bits = r.rng.scalar(int) & mask;114 // const rand_bits = r.rng.scalar(int) & mask;
115 // return @float_compose(T, false, 0, rand_bits) - 1.0115 // return @float_compose(T, false, 0, rand_bits) - 1.0
116 const int_type = @IntType(false, @sizeOf(T) * 8);116 const int_type = @IntType(false, @sizeOf(T) * 8);
117 const precision = if (T == f32) {117 const precision = if (T == f32)
118 16777216118 16777216
119 } else if (T == f64) {119 else if (T == f64)
120 9007199254740992120 9007199254740992
121 } else {121 else
122 @compileError("unknown floating point type")122 @compileError("unknown floating point type")
123 };123 ;
124 return T(r.range(int_type, 0, precision)) / T(precision);124 return T(r.range(int_type, 0, precision)) / T(precision);
125 }125 }
126};126};
...@@ -133,7 +133,7 @@ fn MersenneTwister(...@@ -133,7 +133,7 @@ fn MersenneTwister(
133 comptime t: math.Log2Int(int), comptime c: int,133 comptime t: math.Log2Int(int), comptime c: int,
134 comptime l: math.Log2Int(int), comptime f: int) -> type134 comptime l: math.Log2Int(int), comptime f: int) -> type
135{135{
136 struct {136 return struct {
137 const Self = this;137 const Self = this;
138138
139 array: [n]int,139 array: [n]int,
...@@ -189,7 +189,7 @@ fn MersenneTwister(...@@ -189,7 +189,7 @@ fn MersenneTwister(
189189
190 return x;190 return x;
191 }191 }
192 }192 };
193}193}
194194
195test "rand float 32" {195test "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...@@ -355,7 +355,7 @@ pub fn sort(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &cons
355 // these values will be pulled out to the start of A355 // these values will be pulled out to the start of A
356 last = A.start;356 last = A.start;
357 count = 1;357 count = 1;
358 while (count < find) : ({last = index; count += 1}) {358 while (count < find) : ({last = index; count += 1;}) {
359 index = findLastForward(T, items, items[last], Range.init(last + 1, A.end), lessThan, find - count);359 index = findLastForward(T, items, items[last], Range.init(last + 1, A.end), lessThan, find - count);
360 if (index == A.end) break;360 if (index == A.end) break;
361 }361 }
...@@ -410,7 +410,7 @@ pub fn sort(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &cons...@@ -410,7 +410,7 @@ pub fn sort(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &cons
410 // these values will be pulled out to the end of B410 // these values will be pulled out to the end of B
411 last = B.end - 1;411 last = B.end - 1;
412 count = 1;412 count = 1;
413 while (count < find) : ({last = index - 1; count += 1}) {413 while (count < find) : ({last = index - 1; count += 1;}) {
414 index = findFirstBackward(T, items, items[last], Range.init(B.start, last), lessThan, find - count);414 index = findFirstBackward(T, items, items[last], Range.init(B.start, last), lessThan, find - count);
415 if (index == B.start) break;415 if (index == B.start) break;
416 }416 }
...@@ -547,7 +547,7 @@ pub fn sort(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &cons...@@ -547,7 +547,7 @@ pub fn sort(comptime T: type, items: []T, lessThan: fn(lhs: &const T, rhs: &cons
547 // swap the first value of each A block with the value in buffer1547 // swap the first value of each A block with the value in buffer1
548 var indexA = buffer1.start;548 var indexA = buffer1.start;
549 index = firstA.end;549 index = firstA.end;
550 while (index < blockA.end) : ({indexA += 1; index += block_size}) {550 while (index < blockA.end) : ({indexA += 1; index += block_size;}) {
551 mem.swap(T, &items[indexA], &items[index]);551 mem.swap(T, &items[indexA], &items[index]);
552 }552 }
553 553
...@@ -1093,7 +1093,7 @@ test "another sort case" {...@@ -1093,7 +1093,7 @@ test "another sort case" {
1093 var arr = []i32{ 5, 3, 1, 2, 4 };1093 var arr = []i32{ 5, 3, 1, 2, 4 };
1094 sort(i32, arr[0..], i32asc);1094 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 }));
1097}1097}
10981098
1099test "sort fuzz testing" {1099test "sort fuzz testing" {
std/special/build_runner.zig+6-10
...@@ -45,21 +45,17 @@ pub fn main() -> %void {...@@ -45,21 +45,17 @@ pub fn main() -> %void {
4545
46 var stderr_file = io.getStdErr();46 var stderr_file = io.getStdErr();
47 var stderr_file_stream: io.FileOutStream = undefined;47 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: {
49 stderr_file_stream = io.FileOutStream.init(f);49 stderr_file_stream = io.FileOutStream.init(f);
50 &stderr_file_stream.stream50 break :x &stderr_file_stream.stream;
51 } else |err| {51 } else |err| err;
52 err
53 };
5452
55 var stdout_file = io.getStdOut();53 var stdout_file = io.getStdOut();
56 var stdout_file_stream: io.FileOutStream = undefined;54 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: {
58 stdout_file_stream = io.FileOutStream.init(f);56 stdout_file_stream = io.FileOutStream.init(f);
59 &stdout_file_stream.stream57 break :x &stdout_file_stream.stream;
60 } else |err| {58 } else |err| err;
61 err
62 };
6359
64 while (arg_it.next(allocator)) |err_or_arg| {60 while (arg_it.next(allocator)) |err_or_arg| {
65 const arg = %return unwrapArg(err_or_arg);61 const arg = %return unwrapArg(err_or_arg);
std/special/builtin.zig+9-9
...@@ -46,15 +46,15 @@ extern fn __stack_chk_fail() -> noreturn {...@@ -46,15 +46,15 @@ extern fn __stack_chk_fail() -> noreturn {
4646
47const math = @import("../math/index.zig");47const math = @import("../math/index.zig");
4848
49export fn fmodf(x: f32, y: f32) -> f32 { generic_fmod(f32, x, y) }49export fn fmodf(x: f32, y: f32) -> f32 { return generic_fmod(f32, x, y); }
50export fn fmod(x: f64, y: f64) -> f64 { generic_fmod(f64, x, y) }50export fn fmod(x: f64, y: f64) -> f64 { return generic_fmod(f64, x, y); }
5151
52// TODO add intrinsics for these (and probably the double version too)52// TODO add intrinsics for these (and probably the double version too)
53// and have the math stuff use the intrinsic. same as @mod and @rem53// and have the math stuff use the intrinsic. same as @mod and @rem
54export fn floorf(x: f32) -> f32 { math.floor(x) }54export fn floorf(x: f32) -> f32 { return math.floor(x); }
55export fn ceilf(x: f32) -> f32 { math.ceil(x) }55export fn ceilf(x: f32) -> f32 { return math.ceil(x); }
56export fn floor(x: f64) -> f64 { math.floor(x) }56export fn floor(x: f64) -> f64 { return math.floor(x); }
57export fn ceil(x: f64) -> f64 { math.ceil(x) }57export fn ceil(x: f64) -> f64 { return math.ceil(x); }
5858
59fn generic_fmod(comptime T: type, x: T, y: T) -> T {59fn generic_fmod(comptime T: type, x: T, y: T) -> T {
60 @setDebugSafety(this, false);60 @setDebugSafety(this, false);
...@@ -84,7 +84,7 @@ fn generic_fmod(comptime T: type, x: T, y: T) -> T {...@@ -84,7 +84,7 @@ fn generic_fmod(comptime T: type, x: T, y: T) -> T {
84 // normalize x and y84 // normalize x and y
85 if (ex == 0) {85 if (ex == 0) {
86 i = ux << exp_bits;86 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;}) {}
88 ux <<= log2uint(@bitCast(u32, -ex + 1));88 ux <<= log2uint(@bitCast(u32, -ex + 1));
89 } else {89 } else {
90 ux &= @maxValue(uint) >> exp_bits;90 ux &= @maxValue(uint) >> exp_bits;
...@@ -92,7 +92,7 @@ fn generic_fmod(comptime T: type, x: T, y: T) -> T {...@@ -92,7 +92,7 @@ fn generic_fmod(comptime T: type, x: T, y: T) -> T {
92 }92 }
93 if (ey == 0) {93 if (ey == 0) {
94 i = uy << exp_bits;94 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;}) {}
96 uy <<= log2uint(@bitCast(u32, -ey + 1));96 uy <<= log2uint(@bitCast(u32, -ey + 1));
97 } else {97 } else {
98 uy &= @maxValue(uint) >> exp_bits;98 uy &= @maxValue(uint) >> exp_bits;
...@@ -115,7 +115,7 @@ fn generic_fmod(comptime T: type, x: T, y: T) -> T {...@@ -115,7 +115,7 @@ fn generic_fmod(comptime T: type, x: T, y: T) -> T {
115 return 0 * x;115 return 0 * x;
116 ux = i;116 ux = i;
117 }117 }
118 while (ux >> digits == 0) : ({ux <<= 1; ex -= 1}) {}118 while (ux >> digits == 0) : (b: {ux <<= 1; break :b ex -= 1;}) {}
119119
120 // scale result up120 // scale result up
121 if (ex > 0) {121 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 {...@@ -38,27 +38,25 @@ pub extern fn __letf2(a: f128, b: f128) -> c_int {
3838
39 // If at least one of a and b is positive, we get the same result comparing39 // If at least one of a and b is positive, we get the same result comparing
40 // a and b as signed integers as we would with a floating-point compare.40 // a and b as signed integers as we would with a floating-point compare.
41 return if ((aInt & bInt) >= 0) {41 return if ((aInt & bInt) >= 0)
42 if (aInt < bInt) {42 if (aInt < bInt)
43 LE_LESS43 LE_LESS
44 } else if (aInt == bInt) {44 else if (aInt == bInt)
45 LE_EQUAL45 LE_EQUAL
46 } else {46 else
47 LE_GREATER47 LE_GREATER
48 }48 else
49 } else {
50 // Otherwise, both are negative, so we need to flip the sense of the49 // Otherwise, both are negative, so we need to flip the sense of the
51 // comparison to get the correct result. (This assumes a twos- or ones-50 // comparison to get the correct result. (This assumes a twos- or ones-
52 // complement integer representation; if integers are represented in a51 // complement integer representation; if integers are represented in a
53 // sign-magnitude representation, then this flip is incorrect).52 // sign-magnitude representation, then this flip is incorrect).
54 if (aInt > bInt) {53 if (aInt > bInt)
55 LE_LESS54 LE_LESS
56 } else if (aInt == bInt) {55 else if (aInt == bInt)
57 LE_EQUAL56 LE_EQUAL
58 } else {57 else
59 LE_GREATER58 LE_GREATER
60 }59 ;
61 };
62}60}
6361
64// TODO https://github.com/zig-lang/zig/issues/30562// TODO https://github.com/zig-lang/zig/issues/305
...@@ -78,23 +76,21 @@ pub extern fn __getf2(a: f128, b: f128) -> c_int {...@@ -78,23 +76,21 @@ pub extern fn __getf2(a: f128, b: f128) -> c_int {
7876
79 if (aAbs > infRep or bAbs > infRep) return GE_UNORDERED;77 if (aAbs > infRep or bAbs > infRep) return GE_UNORDERED;
80 if ((aAbs | bAbs) == 0) return GE_EQUAL;78 if ((aAbs | bAbs) == 0) return GE_EQUAL;
81 return if ((aInt & bInt) >= 0) {79 return if ((aInt & bInt) >= 0)
82 if (aInt < bInt) {80 if (aInt < bInt)
83 GE_LESS81 GE_LESS
84 } else if (aInt == bInt) {82 else if (aInt == bInt)
85 GE_EQUAL83 GE_EQUAL
86 } else {84 else
87 GE_GREATER85 GE_GREATER
88 }86 else
89 } else {87 if (aInt > bInt)
90 if (aInt > bInt) {
91 GE_LESS88 GE_LESS
92 } else if (aInt == bInt) {89 else if (aInt == bInt)
93 GE_EQUAL90 GE_EQUAL
94 } else {91 else
95 GE_GREATER92 GE_GREATER
96 }93 ;
97 };
98}94}
9995
100pub extern fn __unordtf2(a: f128, b: f128) -> c_int {96pub extern fn __unordtf2(a: f128, b: f128) -> c_int {
test/cases/align.zig+9-9
...@@ -10,7 +10,7 @@ test "global variable alignment" {...@@ -10,7 +10,7 @@ test "global variable alignment" {
10 assert(@typeOf(slice) == []align(4) u8);10 assert(@typeOf(slice) == []align(4) u8);
11}11}
1212
13fn derp() align(@sizeOf(usize) * 2) -> i32 { 1234 }13fn derp() align(@sizeOf(usize) * 2) -> i32 { return 1234; }
14fn noop1() align(1) {}14fn noop1() align(1) {}
15fn noop4() align(4) {}15fn noop4() align(4) {}
1616
...@@ -53,14 +53,14 @@ test "implicitly decreasing pointer alignment" {...@@ -53,14 +53,14 @@ test "implicitly decreasing pointer alignment" {
53 assert(addUnaligned(&a, &b) == 7);53 assert(addUnaligned(&a, &b) == 7);
54}54}
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
58test "implicitly decreasing slice alignment" {58test "implicitly decreasing slice alignment" {
59 const a: u32 align(4) = 3;59 const a: u32 align(4) = 3;
60 const b: u32 align(8) = 4;60 const b: u32 align(8) = 4;
61 assert(addUnalignedSlice((&a)[0..1], (&b)[0..1]) == 7);61 assert(addUnalignedSlice((&a)[0..1], (&b)[0..1]) == 7);
62}62}
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
65test "specifying alignment allows pointer cast" {65test "specifying alignment allows pointer cast" {
66 testBytesAlign(0x33);66 testBytesAlign(0x33);
...@@ -115,20 +115,20 @@ fn testImplicitlyDecreaseFnAlign(ptr: fn () align(1) -> i32, answer: i32) {...@@ -115,20 +115,20 @@ fn testImplicitlyDecreaseFnAlign(ptr: fn () align(1) -> i32, answer: i32) {
115 assert(ptr() == answer);115 assert(ptr() == answer);
116}116}
117117
118fn alignedSmall() align(8) -> i32 { 1234 }118fn alignedSmall() align(8) -> i32 { return 1234; }
119fn alignedBig() align(16) -> i32 { 5678 }119fn alignedBig() align(16) -> i32 { return 5678; }
120120
121121
122test "@alignCast functions" {122test "@alignCast functions" {
123 assert(fnExpectsOnly1(simple4) == 0x19);123 assert(fnExpectsOnly1(simple4) == 0x19);
124}124}
125fn fnExpectsOnly1(ptr: fn()align(1) -> i32) -> i32 {125fn fnExpectsOnly1(ptr: fn()align(1) -> i32) -> i32 {
126 fnExpects4(@alignCast(4, ptr))126 return fnExpects4(@alignCast(4, ptr));
127}127}
128fn fnExpects4(ptr: fn()align(4) -> i32) -> i32 {128fn fnExpects4(ptr: fn()align(4) -> i32) -> i32 {
129 ptr()129 return ptr();
130}130}
131fn simple4() align(4) -> i32 { 0x19 }131fn simple4() align(4) -> i32 { return 0x19; }
132132
133133
134test "generic function with align param" {134test "generic function with align param" {
...@@ -137,7 +137,7 @@ test "generic function with align param" {...@@ -137,7 +137,7 @@ test "generic function with align param" {
137 assert(whyWouldYouEverDoThis(8) == 0x1);137 assert(whyWouldYouEverDoThis(8) == 0x1);
138}138}
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
143test "@ptrCast preserves alignment of bigger source" {143test "@ptrCast preserves alignment of bigger source" {
test/cases/array.zig+2-2
...@@ -22,7 +22,7 @@ test "arrays" {...@@ -22,7 +22,7 @@ test "arrays" {
22 assert(getArrayLen(array) == 5);22 assert(getArrayLen(array) == 5);
23}23}
24fn getArrayLen(a: []const u32) -> usize {24fn getArrayLen(a: []const u32) -> usize {
25 a.len25 return a.len;
26}26}
2727
28test "void arrays" {28test "void arrays" {
...@@ -41,7 +41,7 @@ test "array literal" {...@@ -41,7 +41,7 @@ test "array literal" {
41}41}
4242
43test "array dot len const expr" {43test "array dot len const expr" {
44 assert(comptime {some_array.len == 4});44 assert(comptime x: {break :x some_array.len == 4;});
45}45}
4646
47const ArrayDotLenConstExpr = struct {47const ArrayDotLenConstExpr = struct {
test/cases/bitcast.zig+2-2
...@@ -10,5 +10,5 @@ fn testBitCast_i32_u32() {...@@ -10,5 +10,5 @@ fn testBitCast_i32_u32() {
10 assert(conv2(@maxValue(u32)) == -1);10 assert(conv2(@maxValue(u32)) == -1);
11}11}
1212
13fn conv(x: i32) -> u32 { @bitCast(u32, x) }13fn conv(x: i32) -> u32 { return @bitCast(u32, x); }
14fn conv2(x: u32) -> i32 { @bitCast(i32, x) }14fn conv2(x: u32) -> i32 { return @bitCast(i32, x); }
test/cases/bool.zig+1-1
...@@ -22,7 +22,7 @@ test "bool cmp" {...@@ -22,7 +22,7 @@ test "bool cmp" {
22 assert(testBoolCmp(true, false) == false);22 assert(testBoolCmp(true, false) == false);
23}23}
24fn testBoolCmp(a: bool, b: bool) -> bool {24fn testBoolCmp(a: bool, b: bool) -> bool {
25 a == b25 return a == b;
26}26}
2727
28const global_f = false;28const global_f = false;
test/cases/cast.zig+7-7
...@@ -50,7 +50,7 @@ test "peer resolve arrays of different size to const slice" {...@@ -50,7 +50,7 @@ test "peer resolve arrays of different size to const slice" {
50 comptime assert(mem.eql(u8, boolToStr(false), "false"));50 comptime assert(mem.eql(u8, boolToStr(false), "false"));
51}51}
52fn boolToStr(b: bool) -> []const u8 {52fn boolToStr(b: bool) -> []const u8 {
53 if (b) "true" else "false"53 return if (b) "true" else "false";
54}54}
5555
5656
...@@ -239,17 +239,17 @@ test "peer type resolution: error and [N]T" {...@@ -239,17 +239,17 @@ test "peer type resolution: error and [N]T" {
239239
240error BadValue;240error BadValue;
241fn testPeerErrorAndArray(x: u8) -> %[]const u8 {241fn testPeerErrorAndArray(x: u8) -> %[]const u8 {
242 switch (x) {242 return switch (x) {
243 0x00 => "OK",243 0x00 => "OK",
244 else => error.BadValue,244 else => error.BadValue,
245 }245 };
246}246}
247fn testPeerErrorAndArray2(x: u8) -> %[]const u8 {247fn testPeerErrorAndArray2(x: u8) -> %[]const u8 {
248 switch (x) {248 return switch (x) {
249 0x00 => "OK",249 0x00 => "OK",
250 0x01 => "OKK",250 0x01 => "OKK",
251 else => error.BadValue,251 else => error.BadValue,
252 }252 };
253}253}
254254
255test "explicit cast float number literal to integer if no fraction component" {255test "explicit cast float number literal to integer if no fraction component" {
...@@ -269,11 +269,11 @@ fn testCast128() {...@@ -269,11 +269,11 @@ fn testCast128() {
269}269}
270270
271fn cast128Int(x: f128) -> u128 {271fn cast128Int(x: f128) -> u128 {
272 @bitCast(u128, x)272 return @bitCast(u128, x);
273}273}
274274
275fn cast128Float(x: u128) -> f128 {275fn cast128Float(x: u128) -> f128 {
276 @bitCast(f128, x)276 return @bitCast(f128, x);
277}277}
278278
279test "const slice widen cast" {279test "const slice widen cast" {
test/cases/defer.zig+6-6
...@@ -7,9 +7,9 @@ error FalseNotAllowed;...@@ -7,9 +7,9 @@ error FalseNotAllowed;
77
8fn runSomeErrorDefers(x: bool) -> %bool {8fn runSomeErrorDefers(x: bool) -> %bool {
9 index = 0;9 index = 0;
10 defer {result[index] = 'a'; index += 1;};10 defer {result[index] = 'a'; index += 1;}
11 %defer {result[index] = 'b'; index += 1;};11 %defer {result[index] = 'b'; index += 1;}
12 defer {result[index] = 'c'; index += 1;};12 defer {result[index] = 'c'; index += 1;}
13 return if (x) x else error.FalseNotAllowed;13 return if (x) x else error.FalseNotAllowed;
14}14}
1515
...@@ -18,9 +18,9 @@ test "mixing normal and error defers" {...@@ -18,9 +18,9 @@ test "mixing normal and error defers" {
18 assert(result[0] == 'c');18 assert(result[0] == 'c');
19 assert(result[1] == 'a');19 assert(result[1] == 'a');
2020
21 const ok = runSomeErrorDefers(false) %% |err| {21 const ok = runSomeErrorDefers(false) %% |err| x: {
22 assert(err == error.FalseNotAllowed);22 assert(err == error.FalseNotAllowed);
23 true23 break :x true;
24 };24 };
25 assert(ok);25 assert(ok);
26 assert(result[0] == 'c');26 assert(result[0] == 'c');
...@@ -41,5 +41,5 @@ fn testBreakContInDefer(x: usize) {...@@ -41,5 +41,5 @@ fn testBreakContInDefer(x: usize) {
41 if (i == 5) break;41 if (i == 5) break;
42 }42 }
43 assert(i == 5);43 assert(i == 5);
44 };44 }
45}45}
test/cases/enum.zig+1-1
...@@ -41,7 +41,7 @@ const Bar = enum {...@@ -41,7 +41,7 @@ const Bar = enum {
41};41};
4242
43fn returnAnInt(x: i32) -> Foo {43fn returnAnInt(x: i32) -> Foo {
44 Foo { .One = x }44 return Foo { .One = x };
45}45}
4646
4747
test/cases/enum_with_members.zig+3-3
...@@ -8,9 +8,9 @@ const ET = union(enum) {...@@ -8,9 +8,9 @@ const ET = union(enum) {
88
9 pub fn print(a: &const ET, buf: []u8) -> %usize {9 pub fn print(a: &const ET, buf: []u8) -> %usize {
10 return switch (*a) {10 return switch (*a) {
11 ET.SINT => |x| { fmt.formatIntBuf(buf, x, 10, false, 0) },11 ET.SINT => |x| fmt.formatIntBuf(buf, x, 10, false, 0),
12 ET.UINT => |x| { fmt.formatIntBuf(buf, x, 10, false, 0) },12 ET.UINT => |x| fmt.formatIntBuf(buf, x, 10, false, 0),
13 }13 };
14 }14 }
15};15};
1616
test/cases/error.zig+5-9
...@@ -3,7 +3,7 @@ const mem = @import("std").mem;...@@ -3,7 +3,7 @@ const mem = @import("std").mem;
33
4pub fn foo() -> %i32 {4pub fn foo() -> %i32 {
5 const x = %return bar();5 const x = %return bar();
6 return x + 16 return x + 1;
7}7}
88
9pub fn bar() -> %i32 {9pub fn bar() -> %i32 {
...@@ -21,7 +21,7 @@ test "error wrapping" {...@@ -21,7 +21,7 @@ test "error wrapping" {
2121
22error ItBroke;22error ItBroke;
23fn gimmeItBroke() -> []const u8 {23fn gimmeItBroke() -> []const u8 {
24 @errorName(error.ItBroke)24 return @errorName(error.ItBroke);
25}25}
2626
27test "@errorName" {27test "@errorName" {
...@@ -48,7 +48,7 @@ error AnError;...@@ -48,7 +48,7 @@ error AnError;
48error AnError;48error AnError;
49error SecondError;49error SecondError;
50fn shouldBeNotEqual(a: error, b: error) {50fn shouldBeNotEqual(a: error, b: error) {
51 if (a == b) unreachable51 if (a == b) unreachable;
52}52}
5353
5454
...@@ -60,11 +60,7 @@ test "error binary operator" {...@@ -60,11 +60,7 @@ test "error binary operator" {
60}60}
61error ItBroke;61error ItBroke;
62fn errBinaryOperatorG(x: bool) -> %isize {62fn errBinaryOperatorG(x: bool) -> %isize {
63 if (x) {63 return if (x) error.ItBroke else isize(10);
64 error.ItBroke
65 } else {
66 isize(10)
67 }
68}64}
6965
7066
...@@ -72,7 +68,7 @@ test "unwrap simple value from error" {...@@ -72,7 +68,7 @@ test "unwrap simple value from error" {
72 const i = %%unwrapSimpleValueFromErrorDo();68 const i = %%unwrapSimpleValueFromErrorDo();
73 assert(i == 13);69 assert(i == 13);
74}70}
75fn unwrapSimpleValueFromErrorDo() -> %isize { 13 }71fn unwrapSimpleValueFromErrorDo() -> %isize { return 13; }
7672
7773
78test "error return in assignment" {74test "error return in assignment" {
test/cases/eval.zig+13-13
...@@ -44,7 +44,7 @@ test "static function evaluation" {...@@ -44,7 +44,7 @@ test "static function evaluation" {
44 assert(statically_added_number == 3);44 assert(statically_added_number == 3);
45}45}
46const statically_added_number = staticAdd(1, 2);46const 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
50test "const expr eval on single expr blocks" {50test "const expr eval on single expr blocks" {
...@@ -54,10 +54,10 @@ test "const expr eval on single expr blocks" {...@@ -54,10 +54,10 @@ test "const expr eval on single expr blocks" {
54fn constExprEvalOnSingleExprBlocksFn(x: i32, b: bool) -> i32 {54fn constExprEvalOnSingleExprBlocksFn(x: i32, b: bool) -> i32 {
55 const literal = 3;55 const literal = 3;
5656
57 const result = if (b) {57 const result = if (b) b: {
58 literal58 break :b literal;
59 } else {59 } else b: {
60 x60 break :b x;
61 };61 };
6262
63 return result;63 return result;
...@@ -94,9 +94,9 @@ pub const Vec3 = struct {...@@ -94,9 +94,9 @@ pub const Vec3 = struct {
94 data: [3]f32,94 data: [3]f32,
95};95};
96pub fn vec3(x: f32, y: f32, z: f32) -> Vec3 {96pub fn vec3(x: f32, y: f32, z: f32) -> Vec3 {
97 Vec3 {97 return Vec3 {
98 .data = []f32 { x, y, z, },98 .data = []f32 { x, y, z, },
99 }99 };
100}100}
101101
102102
...@@ -176,7 +176,7 @@ fn max(comptime T: type, a: T, b: T) -> T {...@@ -176,7 +176,7 @@ fn max(comptime T: type, a: T, b: T) -> T {
176 }176 }
177}177}
178fn letsTryToCompareBools(a: bool, b: bool) -> bool {178fn letsTryToCompareBools(a: bool, b: bool) -> bool {
179 max(bool, a, b)179 return max(bool, a, b);
180}180}
181test "inlined block and runtime block phi" {181test "inlined block and runtime block phi" {
182 assert(letsTryToCompareBools(true, true));182 assert(letsTryToCompareBools(true, true));
...@@ -202,9 +202,9 @@ const cmd_fns = []CmdFn{...@@ -202,9 +202,9 @@ const cmd_fns = []CmdFn{
202 CmdFn {.name = "two", .func = two},202 CmdFn {.name = "two", .func = two},
203 CmdFn {.name = "three", .func = three},203 CmdFn {.name = "three", .func = three},
204};204};
205fn one(value: i32) -> i32 { value + 1 }205fn one(value: i32) -> i32 { return value + 1; }
206fn two(value: i32) -> i32 { value + 2 }206fn two(value: i32) -> i32 { return value + 2; }
207fn three(value: i32) -> i32 { value + 3 }207fn three(value: i32) -> i32 { return value + 3; }
208208
209fn performFn(comptime prefix_char: u8, start_value: i32) -> i32 {209fn performFn(comptime prefix_char: u8, start_value: i32) -> i32 {
210 var result: i32 = start_value;210 var result: i32 = start_value;
...@@ -317,12 +317,12 @@ test "create global array with for loop" {...@@ -317,12 +317,12 @@ test "create global array with for loop" {
317 assert(global_array[9] == 9 * 9);317 assert(global_array[9] == 9 * 9);
318}318}
319319
320const global_array = {320const global_array = x: {
321 var result: [10]usize = undefined;321 var result: [10]usize = undefined;
322 for (result) |*item, index| {322 for (result) |*item, index| {
323 *item = index * index;323 *item = index * index;
324 }324 }
325 result325 break :x result;
326};326};
327327
328test "compile-time downcast when the bits fit" {328test "compile-time downcast when the bits fit" {
test/cases/fn.zig+10-10
...@@ -4,7 +4,7 @@ test "params" {...@@ -4,7 +4,7 @@ test "params" {
4 assert(testParamsAdd(22, 11) == 33);4 assert(testParamsAdd(22, 11) == 33);
5}5}
6fn testParamsAdd(a: i32, b: i32) -> i32 {6fn testParamsAdd(a: i32, b: i32) -> i32 {
7 a + b7 return a + b;
8}8}
99
1010
...@@ -22,7 +22,7 @@ test "void parameters" {...@@ -22,7 +22,7 @@ test "void parameters" {
22}22}
23fn voidFun(a: i32, b: void, c: i32, d: void) {23fn voidFun(a: i32, b: void, c: i32, d: void) {
24 const v = b;24 const v = b;
25 const vv: void = if (a == 1) {v} else {};25 const vv: void = if (a == 1) v else {};
26 assert(a + c == 3);26 assert(a + c == 3);
27 return vv;27 return vv;
28}28}
...@@ -45,9 +45,9 @@ test "separate block scopes" {...@@ -45,9 +45,9 @@ test "separate block scopes" {
45 assert(no_conflict == 5);45 assert(no_conflict == 5);
46 }46 }
4747
48 const c = {48 const c = x: {
49 const no_conflict = i32(10);49 const no_conflict = i32(10);
50 no_conflict50 break :x no_conflict;
51 };51 };
52 assert(c == 10);52 assert(c == 10);
53}53}
...@@ -73,7 +73,7 @@ test "implicit cast function unreachable return" {...@@ -73,7 +73,7 @@ test "implicit cast function unreachable return" {
73fn wantsFnWithVoid(f: fn()) { }73fn wantsFnWithVoid(f: fn()) { }
7474
75fn fnWithUnreachable() -> noreturn {75fn fnWithUnreachable() -> noreturn {
76 unreachable76 unreachable;
77}77}
7878
7979
...@@ -83,14 +83,14 @@ test "function pointers" {...@@ -83,14 +83,14 @@ test "function pointers" {
83 assert(f() == u32(i) + 5);83 assert(f() == u32(i) + 5);
84 }84 }
85}85}
86fn fn1() -> u32 {5}86fn fn1() -> u32 {return 5;}
87fn fn2() -> u32 {6}87fn fn2() -> u32 {return 6;}
88fn fn3() -> u32 {7}88fn fn3() -> u32 {return 7;}
89fn fn4() -> u32 {8}89fn fn4() -> u32 {return 8;}
9090
9191
92test "inline function call" {92test "inline function call" {
93 assert(@inlineCall(add, 3, 9) == 12);93 assert(@inlineCall(add, 3, 9) == 12);
94}94}
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" {...@@ -12,7 +12,7 @@ test "continue in for loop" {
12 }12 }
13 break;13 break;
14 }14 }
15 if (sum != 6) unreachable15 if (sum != 6) unreachable;
16}16}
1717
18test "for loop with pointer elem var" {18test "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 {...@@ -11,7 +11,7 @@ fn max(comptime T: type, a: T, b: T) -> T {
11}11}
1212
13fn add(comptime a: i32, b: i32) -> i32 {13fn add(comptime a: i32, b: i32) -> i32 {
14 return (comptime {a}) + b;14 return (comptime a) + b;
15}15}
1616
17const the_max = max(u32, 1234, 5678);17const the_max = max(u32, 1234, 5678);
...@@ -20,15 +20,15 @@ test "compile time generic eval" {...@@ -20,15 +20,15 @@ test "compile time generic eval" {
20}20}
2121
22fn gimmeTheBigOne(a: u32, b: u32) -> u32 {22fn gimmeTheBigOne(a: u32, b: u32) -> u32 {
23 max(u32, a, b)23 return max(u32, a, b);
24}24}
2525
26fn shouldCallSameInstance(a: u32, b: u32) -> u32 {26fn shouldCallSameInstance(a: u32, b: u32) -> u32 {
27 max(u32, a, b)27 return max(u32, a, b);
28}28}
2929
30fn sameButWithFloats(a: f64, b: f64) -> f64 {30fn sameButWithFloats(a: f64, b: f64) -> f64 {
31 max(f64, a, b)31 return max(f64, a, b);
32}32}
3333
34test "fn with comptime args" {34test "fn with comptime args" {
...@@ -49,28 +49,28 @@ comptime {...@@ -49,28 +49,28 @@ comptime {
49}49}
5050
51fn max_var(a: var, b: var) -> @typeOf(a + b) {51fn max_var(a: var, b: var) -> @typeOf(a + b) {
52 if (a > b) a else b52 return if (a > b) a else b;
53}53}
5454
55fn max_i32(a: i32, b: i32) -> i32 {55fn max_i32(a: i32, b: i32) -> i32 {
56 max_var(a, b)56 return max_var(a, b);
57}57}
5858
59fn max_f64(a: f64, b: f64) -> f64 {59fn max_f64(a: f64, b: f64) -> f64 {
60 max_var(a, b)60 return max_var(a, b);
61}61}
6262
6363
64pub fn List(comptime T: type) -> type {64pub fn List(comptime T: type) -> type {
65 SmallList(T, 8)65 return SmallList(T, 8);
66}66}
6767
68pub fn SmallList(comptime T: type, comptime STATIC_SIZE: usize) -> type {68pub fn SmallList(comptime T: type, comptime STATIC_SIZE: usize) -> type {
69 struct {69 return struct {
70 items: []T,70 items: []T,
71 length: usize,71 length: usize,
72 prealloc_items: [STATIC_SIZE]T,72 prealloc_items: [STATIC_SIZE]T,
73 }73 };
74}74}
7575
76test "function with return type type" {76test "function with return type type" {
...@@ -91,20 +91,20 @@ test "generic struct" {...@@ -91,20 +91,20 @@ test "generic struct" {
91 assert(b1.getVal());91 assert(b1.getVal());
92}92}
93fn GenNode(comptime T: type) -> type {93fn GenNode(comptime T: type) -> type {
94 struct {94 return struct {
95 value: T,95 value: T,
96 next: ?&GenNode(T),96 next: ?&GenNode(T),
97 fn getVal(n: &const GenNode(T)) -> T { n.value }97 fn getVal(n: &const GenNode(T)) -> T { return n.value; }
98 }98 };
99}99}
100100
101test "const decls in struct" {101test "const decls in struct" {
102 assert(GenericDataThing(3).count_plus_one == 4);102 assert(GenericDataThing(3).count_plus_one == 4);
103}103}
104fn GenericDataThing(comptime count: isize) -> type {104fn GenericDataThing(comptime count: isize) -> type {
105 struct {105 return struct {
106 const count_plus_one = count + 1;106 const count_plus_one = count + 1;
107 }107 };
108}108}
109109
110110
...@@ -120,16 +120,16 @@ test "generic fn with implicit cast" {...@@ -120,16 +120,16 @@ test "generic fn with implicit cast" {
120 assert(getFirstByte(u8, []u8 {13}) == 13);120 assert(getFirstByte(u8, []u8 {13}) == 13);
121 assert(getFirstByte(u16, []u16 {0, 13}) == 0);121 assert(getFirstByte(u16, []u16 {0, 13}) == 0);
122}122}
123fn getByte(ptr: ?&const u8) -> u8 {*??ptr}123fn getByte(ptr: ?&const u8) -> u8 {return *??ptr;}
124fn getFirstByte(comptime T: type, mem: []const T) -> u8 {124fn getFirstByte(comptime T: type, mem: []const T) -> u8 {
125 getByte(@ptrCast(&const u8, &mem[0]))125 return getByte(@ptrCast(&const u8, &mem[0]));
126}126}
127127
128128
129const foos = []fn(var) -> bool { foo1, foo2 };129const foos = []fn(var) -> bool { foo1, foo2 };
130130
131fn foo1(arg: var) -> bool { arg }131fn foo1(arg: var) -> bool { return arg; }
132fn foo2(arg: var) -> bool { !arg }132fn foo2(arg: var) -> bool { return !arg; }
133133
134test "array of generic fns" {134test "array of generic fns" {
135 assert(foos[0](true));135 assert(foos[0](true));
test/cases/if.zig+3-3
...@@ -29,10 +29,10 @@ test "else if expression" {...@@ -29,10 +29,10 @@ test "else if expression" {
29}29}
30fn elseIfExpressionF(c: u8) -> u8 {30fn elseIfExpressionF(c: u8) -> u8 {
31 if (c == 0) {31 if (c == 0) {
32 032 return 0;
33 } else if (c == 1) {33 } else if (c == 1) {
34 134 return 1;
35 } else {35 } else {
36 u8(2)36 return u8(2);
37 }37 }
38}38}
test/cases/import/a_namespace.zig+1-1
...@@ -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 {...@@ -8,10 +8,10 @@ fn foo(id: u64) -> %i32 {
8 return %return getErrInt();8 return %return getErrInt();
9 },9 },
10 else => error.ItBroke,10 else => error.ItBroke,
11 }11 };
12}12}
1313
14fn getErrInt() -> %i32 { 0 }14fn getErrInt() -> %i32 { return 0; }
1515
16error ItBroke;16error ItBroke;
1717
test/cases/math.zig+11-11
...@@ -28,16 +28,16 @@ fn testDivision() {...@@ -28,16 +28,16 @@ fn testDivision() {
28 assert(divTrunc(f32, -5.0, 3.0) == -1.0);28 assert(divTrunc(f32, -5.0, 3.0) == -1.0);
29}29}
30fn div(comptime T: type, a: T, b: T) -> T {30fn div(comptime T: type, a: T, b: T) -> T {
31 a / b31 return a / b;
32}32}
33fn divExact(comptime T: type, a: T, b: T) -> T {33fn divExact(comptime T: type, a: T, b: T) -> T {
34 @divExact(a, b)34 return @divExact(a, b);
35}35}
36fn divFloor(comptime T: type, a: T, b: T) -> T {36fn divFloor(comptime T: type, a: T, b: T) -> T {
37 @divFloor(a, b)37 return @divFloor(a, b);
38}38}
39fn divTrunc(comptime T: type, a: T, b: T) -> T {39fn divTrunc(comptime T: type, a: T, b: T) -> T {
40 @divTrunc(a, b)40 return @divTrunc(a, b);
41}41}
4242
43test "@addWithOverflow" {43test "@addWithOverflow" {
...@@ -71,7 +71,7 @@ fn testClz() {...@@ -71,7 +71,7 @@ fn testClz() {
71}71}
7272
73fn clz(x: var) -> usize {73fn clz(x: var) -> usize {
74 @clz(x)74 return @clz(x);
75}75}
7676
77test "@ctz" {77test "@ctz" {
...@@ -86,7 +86,7 @@ fn testCtz() {...@@ -86,7 +86,7 @@ fn testCtz() {
86}86}
8787
88fn ctz(x: var) -> usize {88fn ctz(x: var) -> usize {
89 @ctz(x)89 return @ctz(x);
90}90}
9191
92test "assignment operators" {92test "assignment operators" {
...@@ -180,10 +180,10 @@ fn test_u64_div() {...@@ -180,10 +180,10 @@ fn test_u64_div() {
180 assert(result.remainder == 100663296);180 assert(result.remainder == 100663296);
181}181}
182fn divWithResult(a: u64, b: u64) -> DivResult {182fn divWithResult(a: u64, b: u64) -> DivResult {
183 DivResult {183 return DivResult {
184 .quotient = a / b,184 .quotient = a / b,
185 .remainder = a % b,185 .remainder = a % b,
186 }186 };
187}187}
188const DivResult = struct {188const DivResult = struct {
189 quotient: u64,189 quotient: u64,
...@@ -191,8 +191,8 @@ const DivResult = struct {...@@ -191,8 +191,8 @@ const DivResult = struct {
191};191};
192192
193test "binary not" {193test "binary not" {
194 assert(comptime {~u16(0b1010101010101010) == 0b0101010101010101});194 assert(comptime x: {break :x ~u16(0b1010101010101010) == 0b0101010101010101;});
195 assert(comptime {~u64(2147483647) == 18446744071562067968});195 assert(comptime x: {break :x ~u64(2147483647) == 18446744071562067968;});
196 testBinaryNot(0b1010101010101010);196 testBinaryNot(0b1010101010101010);
197}197}
198198
...@@ -331,7 +331,7 @@ test "f128" {...@@ -331,7 +331,7 @@ test "f128" {
331 comptime test_f128();331 comptime test_f128();
332}332}
333333
334fn make_f128(x: f128) -> f128 { x }334fn make_f128(x: f128) -> f128 { return x; }
335335
336fn test_f128() {336fn test_f128() {
337 assert(@sizeOf(f128) == 16);337 assert(@sizeOf(f128) == 16);
test/cases/misc.zig+15-15
...@@ -110,17 +110,17 @@ fn testShortCircuit(f: bool, t: bool) {...@@ -110,17 +110,17 @@ fn testShortCircuit(f: bool, t: bool) {
110 var hit_3 = f;110 var hit_3 = f;
111 var hit_4 = f;111 var hit_4 = f;
112112
113 if (t or {assert(f); f}) {113 if (t or x: {assert(f); break :x f;}) {
114 hit_1 = t;114 hit_1 = t;
115 }115 }
116 if (f or { hit_2 = t; f }) {116 if (f or x: { hit_2 = t; break :x f; }) {
117 assert(f);117 assert(f);
118 }118 }
119119
120 if (t and { hit_3 = t; f }) {120 if (t and x: { hit_3 = t; break :x f; }) {
121 assert(f);121 assert(f);
122 }122 }
123 if (f and {assert(f); f}) {123 if (f and x: {assert(f); break :x f;}) {
124 assert(f);124 assert(f);
125 } else {125 } else {
126 hit_4 = t;126 hit_4 = t;
...@@ -135,11 +135,11 @@ test "truncate" {...@@ -135,11 +135,11 @@ test "truncate" {
135 assert(testTruncate(0x10fd) == 0xfd);135 assert(testTruncate(0x10fd) == 0xfd);
136}136}
137fn testTruncate(x: u32) -> u8 {137fn testTruncate(x: u32) -> u8 {
138 @truncate(u8, x)138 return @truncate(u8, x);
139}139}
140140
141fn first4KeysOfHomeRow() -> []const u8 {141fn first4KeysOfHomeRow() -> []const u8 {
142 "aoeu"142 return "aoeu";
143}143}
144144
145test "return string from function" {145test "return string from function" {
...@@ -167,7 +167,7 @@ test "memcpy and memset intrinsics" {...@@ -167,7 +167,7 @@ test "memcpy and memset intrinsics" {
167}167}
168168
169test "builtin static eval" {169test "builtin static eval" {
170 const x : i32 = comptime {1 + 2 + 3};170 const x : i32 = comptime x: {break :x 1 + 2 + 3;};
171 assert(x == comptime 6);171 assert(x == comptime 6);
172}172}
173173
...@@ -190,7 +190,7 @@ test "slicing" {...@@ -190,7 +190,7 @@ test "slicing" {
190190
191test "constant equal function pointers" {191test "constant equal function pointers" {
192 const alias = emptyFn;192 const alias = emptyFn;
193 assert(comptime {emptyFn == alias});193 assert(comptime x: {break :x emptyFn == alias;});
194}194}
195195
196fn emptyFn() {}196fn emptyFn() {}
...@@ -280,14 +280,14 @@ test "cast small unsigned to larger signed" {...@@ -280,14 +280,14 @@ test "cast small unsigned to larger signed" {
280 assert(castSmallUnsignedToLargerSigned1(200) == i16(200));280 assert(castSmallUnsignedToLargerSigned1(200) == i16(200));
281 assert(castSmallUnsignedToLargerSigned2(9999) == i64(9999));281 assert(castSmallUnsignedToLargerSigned2(9999) == i64(9999));
282}282}
283fn castSmallUnsignedToLargerSigned1(x: u8) -> i16 { x }283fn castSmallUnsignedToLargerSigned1(x: u8) -> i16 { return x; }
284fn castSmallUnsignedToLargerSigned2(x: u16) -> i64 { x }284fn castSmallUnsignedToLargerSigned2(x: u16) -> i64 { return x; }
285285
286286
287test "implicit cast after unreachable" {287test "implicit cast after unreachable" {
288 assert(outer() == 1234);288 assert(outer() == 1234);
289}289}
290fn inner() -> i32 { 1234 }290fn inner() -> i32 { return 1234; }
291fn outer() -> i64 {291fn outer() -> i64 {
292 return inner();292 return inner();
293}293}
...@@ -310,8 +310,8 @@ test "call result of if else expression" {...@@ -310,8 +310,8 @@ test "call result of if else expression" {
310fn f2(x: bool) -> []const u8 {310fn f2(x: bool) -> []const u8 {
311 return (if (x) fA else fB)();311 return (if (x) fA else fB)();
312}312}
313fn fA() -> []const u8 { "a" }313fn fA() -> []const u8 { return "a"; }
314fn fB() -> []const u8 { "b" }314fn fB() -> []const u8 { return "b"; }
315315
316316
317test "const expression eval handling of variables" {317test "const expression eval handling of variables" {
...@@ -379,7 +379,7 @@ test "pointer comparison" {...@@ -379,7 +379,7 @@ test "pointer comparison" {
379 assert(ptrEql(b, b));379 assert(ptrEql(b, b));
380}380}
381fn ptrEql(a: &const []const u8, b: &const []const u8) -> bool {381fn ptrEql(a: &const []const u8, b: &const []const u8) -> bool {
382 a == b382 return a == b;
383}383}
384384
385385
...@@ -483,7 +483,7 @@ test "@typeId" {...@@ -483,7 +483,7 @@ test "@typeId" {
483 assert(@typeId(AUnion) == Tid.Union);483 assert(@typeId(AUnion) == Tid.Union);
484 assert(@typeId(fn()) == Tid.Fn);484 assert(@typeId(fn()) == Tid.Fn);
485 assert(@typeId(@typeOf(builtin)) == Tid.Namespace);485 assert(@typeId(@typeOf(builtin)) == Tid.Namespace);
486 assert(@typeId(@typeOf({this})) == Tid.Block);486 assert(@typeId(@typeOf(x: {break :x this;})) == Tid.Block);
487 // TODO bound fn487 // TODO bound fn
488 // TODO arg tuple488 // TODO arg tuple
489 // TODO opaque489 // TODO opaque
test/cases/reflection.zig+1-1
...@@ -22,7 +22,7 @@ test "reflection: function return type, var args, and param types" {...@@ -22,7 +22,7 @@ test "reflection: function return type, var args, and param types" {
22 }22 }
23}23}
2424
25fn dummy(a: bool, b: i32, c: f32) -> i32 { 1234 }25fn dummy(a: bool, b: i32, c: f32) -> i32 { return 1234; }
26fn dummy_varargs(args: ...) {}26fn dummy_varargs(args: ...) {}
2727
28test "reflection: struct member types and names" {28test "reflection: struct member types and names" {
test/cases/struct.zig+9-9
...@@ -2,7 +2,7 @@ const assert = @import("std").debug.assert;...@@ -2,7 +2,7 @@ const assert = @import("std").debug.assert;
2const builtin = @import("builtin");2const builtin = @import("builtin");
33
4const StructWithNoFields = struct {4const StructWithNoFields = struct {
5 fn add(a: i32, b: i32) -> i32 { a + b }5 fn add(a: i32, b: i32) -> i32 { return a + b; }
6};6};
7const empty_global_instance = StructWithNoFields {};7const empty_global_instance = StructWithNoFields {};
88
...@@ -109,7 +109,7 @@ const Foo = struct {...@@ -109,7 +109,7 @@ const Foo = struct {
109 ptr: fn() -> i32,109 ptr: fn() -> i32,
110};110};
111111
112fn aFunc() -> i32 { 13 }112fn aFunc() -> i32 { return 13; }
113113
114fn callStructField(foo: &const Foo) -> i32 {114fn callStructField(foo: &const Foo) -> i32 {
115 return foo.ptr();115 return foo.ptr();
...@@ -124,7 +124,7 @@ test "store member function in variable" {...@@ -124,7 +124,7 @@ test "store member function in variable" {
124}124}
125const MemberFnTestFoo = struct {125const MemberFnTestFoo = struct {
126 x: i32,126 x: i32,
127 fn member(foo: &const MemberFnTestFoo) -> i32 { foo.x }127 fn member(foo: &const MemberFnTestFoo) -> i32 { return foo.x; }
128};128};
129129
130130
...@@ -141,7 +141,7 @@ test "member functions" {...@@ -141,7 +141,7 @@ test "member functions" {
141const MemberFnRand = struct {141const MemberFnRand = struct {
142 seed: u32,142 seed: u32,
143 pub fn getSeed(r: &const MemberFnRand) -> u32 {143 pub fn getSeed(r: &const MemberFnRand) -> u32 {
144 r.seed144 return r.seed;
145 }145 }
146};146};
147147
...@@ -154,10 +154,10 @@ const Bar = struct {...@@ -154,10 +154,10 @@ const Bar = struct {
154 y: i32,154 y: i32,
155};155};
156fn makeBar(x: i32, y: i32) -> Bar {156fn makeBar(x: i32, y: i32) -> Bar {
157 Bar {157 return Bar {
158 .x = x,158 .x = x,
159 .y = y,159 .y = y,
160 }160 };
161}161}
162162
163test "empty struct method call" {163test "empty struct method call" {
...@@ -166,7 +166,7 @@ test "empty struct method call" {...@@ -166,7 +166,7 @@ test "empty struct method call" {
166}166}
167const EmptyStruct = struct {167const EmptyStruct = struct {
168 fn method(es: &const EmptyStruct) -> i32 {168 fn method(es: &const EmptyStruct) -> i32 {
169 1234169 return 1234;
170 }170 }
171};171};
172172
...@@ -176,14 +176,14 @@ test "return empty struct from fn" {...@@ -176,14 +176,14 @@ test "return empty struct from fn" {
176}176}
177const EmptyStruct2 = struct {};177const EmptyStruct2 = struct {};
178fn testReturnEmptyStructFromFn() -> EmptyStruct2 {178fn testReturnEmptyStructFromFn() -> EmptyStruct2 {
179 EmptyStruct2 {}179 return EmptyStruct2 {};
180}180}
181181
182test "pass slice of empty struct to fn" {182test "pass slice of empty struct to fn" {
183 assert(testPassSliceOfEmptyStructToFn([]EmptyStruct2{ EmptyStruct2{} }) == 1);183 assert(testPassSliceOfEmptyStructToFn([]EmptyStruct2{ EmptyStruct2{} }) == 1);
184}184}
185fn testPassSliceOfEmptyStructToFn(slice: []const EmptyStruct2) -> usize {185fn testPassSliceOfEmptyStructToFn(slice: []const EmptyStruct2) -> usize {
186 slice.len186 return slice.len;
187}187}
188188
189const APackedStruct = packed struct {189const APackedStruct = packed struct {
test/cases/switch.zig+9-9
...@@ -21,12 +21,12 @@ test "switch with all ranges" {...@@ -21,12 +21,12 @@ test "switch with all ranges" {
21}21}
2222
23fn testSwitchWithAllRanges(x: u32, y: u32) -> u32 {23fn testSwitchWithAllRanges(x: u32, y: u32) -> u32 {
24 switch (x) {24 return switch (x) {
25 0 ... 100 => 1,25 0 ... 100 => 1,
26 101 ... 200 => 2,26 101 ... 200 => 2,
27 201 ... 300 => 3,27 201 ... 300 => 3,
28 else => y,28 else => y,
29 }29 };
30}30}
3131
32test "implicit comptime switch" {32test "implicit comptime switch" {
...@@ -132,7 +132,7 @@ test "switch with multiple expressions" {...@@ -132,7 +132,7 @@ test "switch with multiple expressions" {
132 assert(x == 2);132 assert(x == 2);
133}133}
134fn returnsFive() -> i32 {134fn returnsFive() -> i32 {
135 5135 return 5;
136}136}
137137
138138
...@@ -161,10 +161,10 @@ test "switch on type" {...@@ -161,10 +161,10 @@ test "switch on type" {
161}161}
162162
163fn trueIfBoolFalseOtherwise(comptime T: type) -> bool {163fn trueIfBoolFalseOtherwise(comptime T: type) -> bool {
164 switch (T) {164 return switch (T) {
165 bool => true,165 bool => true,
166 else => false,166 else => false,
167 }167 };
168}168}
169169
170test "switch handles all cases of number" {170test "switch handles all cases of number" {
...@@ -186,22 +186,22 @@ fn testSwitchHandleAllCases() {...@@ -186,22 +186,22 @@ fn testSwitchHandleAllCases() {
186}186}
187187
188fn testSwitchHandleAllCasesExhaustive(x: u2) -> u2 {188fn testSwitchHandleAllCasesExhaustive(x: u2) -> u2 {
189 switch (x) {189 return switch (x) {
190 0 => u2(3),190 0 => u2(3),
191 1 => 2,191 1 => 2,
192 2 => 1,192 2 => 1,
193 3 => 0,193 3 => 0,
194 }194 };
195}195}
196196
197fn testSwitchHandleAllCasesRange(x: u8) -> u8 {197fn testSwitchHandleAllCasesRange(x: u8) -> u8 {
198 switch (x) {198 return switch (x) {
199 0 ... 100 => u8(0),199 0 ... 100 => u8(0),
200 101 ... 200 => 1,200 101 ... 200 => 1,
201 201, 203 => 2,201 201, 203 => 2,
202 202 => 4,202 202 => 4,
203 204 ... 255 => 3,203 204 ... 255 => 3,
204 }204 };
205}205}
206206
207test "switch all prongs unreachable" {207test "switch all prongs unreachable" {
test/cases/switch_prong_err_enum.zig+1-1
...@@ -18,7 +18,7 @@ fn doThing(form_id: u64) -> %FormValue {...@@ -18,7 +18,7 @@ fn doThing(form_id: u64) -> %FormValue {
18 return switch (form_id) {18 return switch (form_id) {
19 17 => FormValue { .Address = %return readOnce() },19 17 => FormValue { .Address = %return readOnce() },
20 else => error.InvalidDebugInfo,20 else => error.InvalidDebugInfo,
21 }21 };
22}22}
2323
24test "switch prong returns error enum" {24test "switch prong returns error enum" {
test/cases/switch_prong_implicit_cast.zig+2-2
...@@ -8,11 +8,11 @@ const FormValue = union(enum) {...@@ -8,11 +8,11 @@ const FormValue = union(enum) {
8error Whatever;8error Whatever;
99
10fn foo(id: u64) -> %FormValue {10fn foo(id: u64) -> %FormValue {
11 switch (id) {11 return switch (id) {
12 2 => FormValue { .Two = true },12 2 => FormValue { .Two = true },
13 1 => FormValue { .One = {} },13 1 => FormValue { .One = {} },
14 else => return error.Whatever,14 else => return error.Whatever,
15 }15 };
16}16}
1717
18test "switch prong implicit cast" {18test "switch prong implicit cast" {
test/cases/this.zig+4-8
...@@ -3,7 +3,7 @@ const assert = @import("std").debug.assert;...@@ -3,7 +3,7 @@ const assert = @import("std").debug.assert;
3const module = this;3const module = this;
44
5fn Point(comptime T: type) -> type {5fn Point(comptime T: type) -> type {
6 struct {6 return struct {
7 const Self = this;7 const Self = this;
8 x: T,8 x: T,
9 y: T,9 y: T,
...@@ -12,20 +12,16 @@ fn Point(comptime T: type) -> type {...@@ -12,20 +12,16 @@ fn Point(comptime T: type) -> type {
12 self.x += 1;12 self.x += 1;
13 self.y += 1;13 self.y += 1;
14 }14 }
15 }15 };
16}16}
1717
18fn add(x: i32, y: i32) -> i32 {18fn add(x: i32, y: i32) -> i32 {
19 x + y19 return x + y;
20}20}
2121
22fn factorial(x: i32) -> i32 {22fn factorial(x: i32) -> i32 {
23 const selfFn = this;23 const selfFn = this;
24 if (x == 0) {24 return if (x == 0) 1 else x * selfFn(x - 1);
25 1
26 } else {
27 x * selfFn(x - 1)
28 }
29}25}
3026
31test "this refer to module call private fn" {27test "this refer to module call private fn" {
test/cases/try.zig+5-13
...@@ -7,9 +7,9 @@ test "try on error union" {...@@ -7,9 +7,9 @@ test "try on error union" {
7}7}
88
9fn tryOnErrorUnionImpl() {9fn tryOnErrorUnionImpl() {
10 const x = if (returnsTen()) |val| {10 const x = if (returnsTen()) |val|
11 val + 111 val + 1
12 } else |err| switch (err) {12 else |err| switch (err) {
13 error.ItBroke, error.NoMem => 1,13 error.ItBroke, error.NoMem => 1,
14 error.CrappedOut => i32(2),14 error.CrappedOut => i32(2),
15 else => unreachable,15 else => unreachable,
...@@ -21,22 +21,14 @@ error ItBroke;...@@ -21,22 +21,14 @@ error ItBroke;
21error NoMem;21error NoMem;
22error CrappedOut;22error CrappedOut;
23fn returnsTen() -> %i32 {23fn returnsTen() -> %i32 {
24 1024 return 10;
25}25}
2626
27test "try without vars" {27test "try without vars" {
28 const result1 = if (failIfTrue(true)) {28 const result1 = if (failIfTrue(true)) 1 else |_| i32(2);
29 1
30 } else |_| {
31 i32(2)
32 };
33 assert(result1 == 2);29 assert(result1 == 2);
3430
35 const result2 = if (failIfTrue(false)) {31 const result2 = if (failIfTrue(false)) 1 else |_| i32(2);
36 1
37 } else |_| {
38 i32(2)
39 };
40 assert(result2 == 1);32 assert(result2 == 1);
41}33}
4234
test/cases/var_args.zig+2-2
...@@ -58,8 +58,8 @@ fn extraFn(extra: u32, args: ...) -> usize {...@@ -58,8 +58,8 @@ fn extraFn(extra: u32, args: ...) -> usize {
5858
59const foos = []fn(...) -> bool { foo1, foo2 };59const foos = []fn(...) -> bool { foo1, foo2 };
6060
61fn foo1(args: ...) -> bool { true }61fn foo1(args: ...) -> bool { return true; }
62fn foo2(args: ...) -> bool { false }62fn foo2(args: ...) -> bool { return false; }
6363
64test "array of var args functions" {64test "array of var args functions" {
65 assert(foos[0]());65 assert(foos[0]());
test/cases/while.zig+18-30
...@@ -118,73 +118,61 @@ test "while with error union condition" {...@@ -118,73 +118,61 @@ test "while with error union condition" {
118var numbers_left: i32 = undefined;118var numbers_left: i32 = undefined;
119error OutOfNumbers;119error OutOfNumbers;
120fn getNumberOrErr() -> %i32 {120fn getNumberOrErr() -> %i32 {
121 return if (numbers_left == 0) {121 return if (numbers_left == 0)
122 error.OutOfNumbers122 error.OutOfNumbers
123 } else {123 else x: {
124 numbers_left -= 1;124 numbers_left -= 1;
125 numbers_left125 break :x numbers_left;
126 };126 };
127}127}
128fn getNumberOrNull() -> ?i32 {128fn getNumberOrNull() -> ?i32 {
129 return if (numbers_left == 0) {129 return if (numbers_left == 0)
130 null130 null
131 } else {131 else x: {
132 numbers_left -= 1;132 numbers_left -= 1;
133 numbers_left133 break :x numbers_left;
134 };134 };
135}135}
136136
137test "while on nullable with else result follow else prong" {137test "while on nullable with else result follow else prong" {
138 const result = while (returnNull()) |value| {138 const result = while (returnNull()) |value| {
139 break value;139 break value;
140 } else {140 } else i32(2);
141 i32(2)
142 };
143 assert(result == 2);141 assert(result == 2);
144}142}
145143
146test "while on nullable with else result follow break prong" {144test "while on nullable with else result follow break prong" {
147 const result = while (returnMaybe(10)) |value| {145 const result = while (returnMaybe(10)) |value| {
148 break value;146 break value;
149 } else {147 } else i32(2);
150 i32(2)
151 };
152 assert(result == 10);148 assert(result == 10);
153}149}
154150
155test "while on error union with else result follow else prong" {151test "while on error union with else result follow else prong" {
156 const result = while (returnError()) |value| {152 const result = while (returnError()) |value| {
157 break value;153 break value;
158 } else |err| {154 } else |err| i32(2);
159 i32(2)
160 };
161 assert(result == 2);155 assert(result == 2);
162}156}
163157
164test "while on error union with else result follow break prong" {158test "while on error union with else result follow break prong" {
165 const result = while (returnSuccess(10)) |value| {159 const result = while (returnSuccess(10)) |value| {
166 break value;160 break value;
167 } else |err| {161 } else |err| i32(2);
168 i32(2)
169 };
170 assert(result == 10);162 assert(result == 10);
171}163}
172164
173test "while on bool with else result follow else prong" {165test "while on bool with else result follow else prong" {
174 const result = while (returnFalse()) {166 const result = while (returnFalse()) {
175 break i32(10);167 break i32(10);
176 } else {168 } else i32(2);
177 i32(2)
178 };
179 assert(result == 2);169 assert(result == 2);
180}170}
181171
182test "while on bool with else result follow break prong" {172test "while on bool with else result follow break prong" {
183 const result = while (returnTrue()) {173 const result = while (returnTrue()) {
184 break i32(10);174 break i32(10);
185 } else {175 } else i32(2);
186 i32(2)
187 };
188 assert(result == 10);176 assert(result == 10);
189}177}
190178
...@@ -215,10 +203,10 @@ fn testContinueOuter() {...@@ -215,10 +203,10 @@ fn testContinueOuter() {
215 }203 }
216}204}
217205
218fn returnNull() -> ?i32 { null }206fn returnNull() -> ?i32 { return null; }
219fn returnMaybe(x: i32) -> ?i32 { x }207fn returnMaybe(x: i32) -> ?i32 { return x; }
220error YouWantedAnError;208error YouWantedAnError;
221fn returnError() -> %i32 { error.YouWantedAnError }209fn returnError() -> %i32 { return error.YouWantedAnError; }
222fn returnSuccess(x: i32) -> %i32 { x }210fn returnSuccess(x: i32) -> %i32 { return x; }
223fn returnFalse() -> bool { false }211fn returnFalse() -> bool { return false; }
224fn returnTrue() -> bool { true }212fn returnTrue() -> bool { return true; }
test/compare_output.zig+17-17
...@@ -10,7 +10,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {...@@ -10,7 +10,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
10 \\}10 \\}
11 , "Hello, world!" ++ os.line_sep);11 , "Hello, world!" ++ os.line_sep);
1212
13 cases.addCase({13 cases.addCase(x: {
14 var tc = cases.create("multiple files with private function",14 var tc = cases.create("multiple files with private function",
15 \\use @import("std").io;15 \\use @import("std").io;
16 \\use @import("foo.zig");16 \\use @import("foo.zig");
...@@ -41,10 +41,10 @@ pub fn addCases(cases: &tests.CompareOutputContext) {...@@ -41,10 +41,10 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
41 \\}41 \\}
42 );42 );
4343
44 tc44 break :x tc;
45 });45 });
4646
47 cases.addCase({47 cases.addCase(x: {
48 var tc = cases.create("import segregation",48 var tc = cases.create("import segregation",
49 \\use @import("foo.zig");49 \\use @import("foo.zig");
50 \\use @import("bar.zig");50 \\use @import("bar.zig");
...@@ -82,10 +82,10 @@ pub fn addCases(cases: &tests.CompareOutputContext) {...@@ -82,10 +82,10 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
82 \\}82 \\}
83 );83 );
8484
85 tc85 break :x tc;
86 });86 });
8787
88 cases.addCase({88 cases.addCase(x: {
89 var tc = cases.create("two files use import each other",89 var tc = cases.create("two files use import each other",
90 \\use @import("a.zig");90 \\use @import("a.zig");
91 \\91 \\
...@@ -112,7 +112,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {...@@ -112,7 +112,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
112 \\pub const b_text = a_text;112 \\pub const b_text = a_text;
113 );113 );
114114
115 tc115 break :x tc;
116 });116 });
117117
118 cases.add("hello world without libc",118 cases.add("hello world without libc",
...@@ -286,11 +286,11 @@ pub fn addCases(cases: &tests.CompareOutputContext) {...@@ -286,11 +286,11 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
286 \\ const a_int = @ptrCast(&align(1) i32, a ?? unreachable);286 \\ const a_int = @ptrCast(&align(1) i32, a ?? unreachable);
287 \\ const b_int = @ptrCast(&align(1) i32, b ?? unreachable);287 \\ const b_int = @ptrCast(&align(1) i32, b ?? unreachable);
288 \\ if (*a_int < *b_int) {288 \\ if (*a_int < *b_int) {
289 \\ -1289 \\ return -1;
290 \\ } else if (*a_int > *b_int) {290 \\ } else if (*a_int > *b_int) {
291 \\ 1291 \\ return 1;
292 \\ } else {292 \\ } else {
293 \\ c_int(0)293 \\ return 0;
294 \\ }294 \\ }
295 \\}295 \\}
296 \\296 \\
...@@ -342,13 +342,13 @@ pub fn addCases(cases: &tests.CompareOutputContext) {...@@ -342,13 +342,13 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
342 \\const Foo = struct {342 \\const Foo = struct {
343 \\ field1: Bar,343 \\ field1: Bar,
344 \\344 \\
345 \\ fn method(a: &const Foo) -> bool { true }345 \\ fn method(a: &const Foo) -> bool { return true; }
346 \\};346 \\};
347 \\347 \\
348 \\const Bar = struct {348 \\const Bar = struct {
349 \\ field2: i32,349 \\ field2: i32,
350 \\350 \\
351 \\ fn method(b: &const Bar) -> bool { true }351 \\ fn method(b: &const Bar) -> bool { return true; }
352 \\};352 \\};
353 \\353 \\
354 \\pub fn main() -> %void {354 \\pub fn main() -> %void {
...@@ -429,7 +429,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {...@@ -429,7 +429,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
429 \\fn its_gonna_pass() -> %void { }429 \\fn its_gonna_pass() -> %void { }
430 , "before\nafter\ndefer3\ndefer1\n");430 , "before\nafter\ndefer3\ndefer1\n");
431431
432 cases.addCase({432 cases.addCase(x: {
433 var tc = cases.create("@embedFile",433 var tc = cases.create("@embedFile",
434 \\const foo_txt = @embedFile("foo.txt");434 \\const foo_txt = @embedFile("foo.txt");
435 \\const io = @import("std").io;435 \\const io = @import("std").io;
...@@ -442,10 +442,10 @@ pub fn addCases(cases: &tests.CompareOutputContext) {...@@ -442,10 +442,10 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
442442
443 tc.addSourceFile("foo.txt", "1234\nabcd\n");443 tc.addSourceFile("foo.txt", "1234\nabcd\n");
444444
445 tc445 break :x tc;
446 });446 });
447447
448 cases.addCase({448 cases.addCase(x: {
449 var tc = cases.create("parsing args",449 var tc = cases.create("parsing args",
450 \\const std = @import("std");450 \\const std = @import("std");
451 \\const io = std.io;451 \\const io = std.io;
...@@ -483,10 +483,10 @@ pub fn addCases(cases: &tests.CompareOutputContext) {...@@ -483,10 +483,10 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
483 "last arg",483 "last arg",
484 });484 });
485485
486 tc486 break :x tc;
487 });487 });
488488
489 cases.addCase({489 cases.addCase(x: {
490 var tc = cases.create("parsing args new API",490 var tc = cases.create("parsing args new API",
491 \\const std = @import("std");491 \\const std = @import("std");
492 \\const io = std.io;492 \\const io = std.io;
...@@ -524,6 +524,6 @@ pub fn addCases(cases: &tests.CompareOutputContext) {...@@ -524,6 +524,6 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
524 "last arg",524 "last arg",
525 });525 });
526526
527 tc527 break :x tc;
528 });528 });
529}529}
test/compile_errors.zig+179-178
...@@ -9,7 +9,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -9,7 +9,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
9 \\ }9 \\ }
10 \\ }10 \\ }
11 \\}11 \\}
12 , ".tmp_source.zig:4:13: error: labeled loop not found: 'outer'");12 , ".tmp_source.zig:4:13: error: label not found: 'outer'");
1313
14 cases.add("labeled continue not found",14 cases.add("labeled continue not found",
15 \\export fn entry() {15 \\export fn entry() {
...@@ -39,7 +39,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -39,7 +39,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
39 \\ ({})39 \\ ({})
40 \\ var bad = {};40 \\ var bad = {};
41 \\}41 \\}
42 , ".tmp_source.zig:5:5: error: invalid token: 'var'");42 , ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
4343
44 cases.add("implicit semicolon - block expr",44 cases.add("implicit semicolon - block expr",
45 \\export fn entry() {45 \\export fn entry() {
...@@ -48,7 +48,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -48,7 +48,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
48 \\ _ = {}48 \\ _ = {}
49 \\ var bad = {};49 \\ var bad = {};
50 \\}50 \\}
51 , ".tmp_source.zig:5:5: error: invalid token: 'var'");51 , ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
5252
53 cases.add("implicit semicolon - comptime statement",53 cases.add("implicit semicolon - comptime statement",
54 \\export fn entry() {54 \\export fn entry() {
...@@ -57,7 +57,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -57,7 +57,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
57 \\ comptime ({})57 \\ comptime ({})
58 \\ var bad = {};58 \\ var bad = {};
59 \\}59 \\}
60 , ".tmp_source.zig:5:5: error: invalid token: 'var'");60 , ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
6161
62 cases.add("implicit semicolon - comptime expression",62 cases.add("implicit semicolon - comptime expression",
63 \\export fn entry() {63 \\export fn entry() {
...@@ -66,7 +66,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -66,7 +66,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
66 \\ _ = comptime {}66 \\ _ = comptime {}
67 \\ var bad = {};67 \\ var bad = {};
68 \\}68 \\}
69 , ".tmp_source.zig:5:5: error: invalid token: 'var'");69 , ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
7070
71 cases.add("implicit semicolon - defer",71 cases.add("implicit semicolon - defer",
72 \\export fn entry() {72 \\export fn entry() {
...@@ -84,7 +84,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -84,7 +84,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
84 \\ if(true) ({})84 \\ if(true) ({})
85 \\ var bad = {};85 \\ var bad = {};
86 \\}86 \\}
87 , ".tmp_source.zig:5:5: error: invalid token: 'var'");87 , ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
8888
89 cases.add("implicit semicolon - if expression",89 cases.add("implicit semicolon - if expression",
90 \\export fn entry() {90 \\export fn entry() {
...@@ -93,7 +93,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -93,7 +93,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
93 \\ _ = if(true) {}93 \\ _ = if(true) {}
94 \\ var bad = {};94 \\ var bad = {};
95 \\}95 \\}
96 , ".tmp_source.zig:5:5: error: invalid token: 'var'");96 , ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
9797
98 cases.add("implicit semicolon - if-else statement",98 cases.add("implicit semicolon - if-else statement",
99 \\export fn entry() {99 \\export fn entry() {
...@@ -102,7 +102,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -102,7 +102,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
102 \\ if(true) ({}) else ({})102 \\ if(true) ({}) else ({})
103 \\ var bad = {};103 \\ var bad = {};
104 \\}104 \\}
105 , ".tmp_source.zig:5:5: error: invalid token: 'var'");105 , ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
106106
107 cases.add("implicit semicolon - if-else expression",107 cases.add("implicit semicolon - if-else expression",
108 \\export fn entry() {108 \\export fn entry() {
...@@ -111,7 +111,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -111,7 +111,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
111 \\ _ = if(true) {} else {}111 \\ _ = if(true) {} else {}
112 \\ var bad = {};112 \\ var bad = {};
113 \\}113 \\}
114 , ".tmp_source.zig:5:5: error: invalid token: 'var'");114 , ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
115115
116 cases.add("implicit semicolon - if-else-if statement",116 cases.add("implicit semicolon - if-else-if statement",
117 \\export fn entry() {117 \\export fn entry() {
...@@ -120,7 +120,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -120,7 +120,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
120 \\ if(true) ({}) else if(true) ({})120 \\ if(true) ({}) else if(true) ({})
121 \\ var bad = {};121 \\ var bad = {};
122 \\}122 \\}
123 , ".tmp_source.zig:5:5: error: invalid token: 'var'");123 , ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
124124
125 cases.add("implicit semicolon - if-else-if expression",125 cases.add("implicit semicolon - if-else-if expression",
126 \\export fn entry() {126 \\export fn entry() {
...@@ -129,7 +129,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -129,7 +129,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
129 \\ _ = if(true) {} else if(true) {}129 \\ _ = if(true) {} else if(true) {}
130 \\ var bad = {};130 \\ var bad = {};
131 \\}131 \\}
132 , ".tmp_source.zig:5:5: error: invalid token: 'var'");132 , ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
133133
134 cases.add("implicit semicolon - if-else-if-else statement",134 cases.add("implicit semicolon - if-else-if-else statement",
135 \\export fn entry() {135 \\export fn entry() {
...@@ -138,7 +138,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -138,7 +138,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
138 \\ if(true) ({}) else if(true) ({}) else ({})138 \\ if(true) ({}) else if(true) ({}) else ({})
139 \\ var bad = {};139 \\ var bad = {};
140 \\}140 \\}
141 , ".tmp_source.zig:5:5: error: invalid token: 'var'");141 , ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
142142
143 cases.add("implicit semicolon - if-else-if-else expression",143 cases.add("implicit semicolon - if-else-if-else expression",
144 \\export fn entry() {144 \\export fn entry() {
...@@ -147,7 +147,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -147,7 +147,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
147 \\ _ = if(true) {} else if(true) {} else {}147 \\ _ = if(true) {} else if(true) {} else {}
148 \\ var bad = {};148 \\ var bad = {};
149 \\}149 \\}
150 , ".tmp_source.zig:5:5: error: invalid token: 'var'");150 , ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
151151
152 cases.add("implicit semicolon - test statement",152 cases.add("implicit semicolon - test statement",
153 \\export fn entry() {153 \\export fn entry() {
...@@ -156,7 +156,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -156,7 +156,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
156 \\ if (foo()) |_| ({})156 \\ if (foo()) |_| ({})
157 \\ var bad = {};157 \\ var bad = {};
158 \\}158 \\}
159 , ".tmp_source.zig:5:5: error: invalid token: 'var'");159 , ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
160160
161 cases.add("implicit semicolon - test expression",161 cases.add("implicit semicolon - test expression",
162 \\export fn entry() {162 \\export fn entry() {
...@@ -165,7 +165,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -165,7 +165,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
165 \\ _ = if (foo()) |_| {}165 \\ _ = if (foo()) |_| {}
166 \\ var bad = {};166 \\ var bad = {};
167 \\}167 \\}
168 , ".tmp_source.zig:5:5: error: invalid token: 'var'");168 , ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
169169
170 cases.add("implicit semicolon - while statement",170 cases.add("implicit semicolon - while statement",
171 \\export fn entry() {171 \\export fn entry() {
...@@ -174,7 +174,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -174,7 +174,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
174 \\ while(true) ({})174 \\ while(true) ({})
175 \\ var bad = {};175 \\ var bad = {};
176 \\}176 \\}
177 , ".tmp_source.zig:5:5: error: invalid token: 'var'");177 , ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
178178
179 cases.add("implicit semicolon - while expression",179 cases.add("implicit semicolon - while expression",
180 \\export fn entry() {180 \\export fn entry() {
...@@ -183,7 +183,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -183,7 +183,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
183 \\ _ = while(true) {}183 \\ _ = while(true) {}
184 \\ var bad = {};184 \\ var bad = {};
185 \\}185 \\}
186 , ".tmp_source.zig:5:5: error: invalid token: 'var'");186 , ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
187187
188 cases.add("implicit semicolon - while-continue statement",188 cases.add("implicit semicolon - while-continue statement",
189 \\export fn entry() {189 \\export fn entry() {
...@@ -192,7 +192,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -192,7 +192,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
192 \\ while(true):({}) ({})192 \\ while(true):({}) ({})
193 \\ var bad = {};193 \\ var bad = {};
194 \\}194 \\}
195 , ".tmp_source.zig:5:5: error: invalid token: 'var'");195 , ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
196196
197 cases.add("implicit semicolon - while-continue expression",197 cases.add("implicit semicolon - while-continue expression",
198 \\export fn entry() {198 \\export fn entry() {
...@@ -201,7 +201,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -201,7 +201,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
201 \\ _ = while(true):({}) {}201 \\ _ = while(true):({}) {}
202 \\ var bad = {};202 \\ var bad = {};
203 \\}203 \\}
204 , ".tmp_source.zig:5:5: error: invalid token: 'var'");204 , ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
205205
206 cases.add("implicit semicolon - for statement",206 cases.add("implicit semicolon - for statement",
207 \\export fn entry() {207 \\export fn entry() {
...@@ -210,7 +210,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -210,7 +210,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
210 \\ for(foo()) ({})210 \\ for(foo()) ({})
211 \\ var bad = {};211 \\ var bad = {};
212 \\}212 \\}
213 , ".tmp_source.zig:5:5: error: invalid token: 'var'");213 , ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
214214
215 cases.add("implicit semicolon - for expression",215 cases.add("implicit semicolon - for expression",
216 \\export fn entry() {216 \\export fn entry() {
...@@ -219,7 +219,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -219,7 +219,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
219 \\ _ = for(foo()) {}219 \\ _ = for(foo()) {}
220 \\ var bad = {};220 \\ var bad = {};
221 \\}221 \\}
222 , ".tmp_source.zig:5:5: error: invalid token: 'var'");222 , ".tmp_source.zig:5:5: error: expected token ';', found 'var'");
223223
224 cases.add("multiple function definitions",224 cases.add("multiple function definitions",
225 \\fn a() {}225 \\fn a() {}
...@@ -276,12 +276,13 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -276,12 +276,13 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
276276
277 cases.add("undeclared identifier",277 cases.add("undeclared identifier",
278 \\export fn a() {278 \\export fn a() {
279 \\ return
279 \\ b +280 \\ b +
280 \\ c281 \\ c;
281 \\}282 \\}
282 ,283 ,
283 ".tmp_source.zig:2:5: error: use of undeclared identifier 'b'",284 ".tmp_source.zig:3:5: error: use of undeclared identifier 'b'",
284 ".tmp_source.zig:3:5: error: use of undeclared identifier 'c'");285 ".tmp_source.zig:4:5: error: use of undeclared identifier 'c'");
285286
286 cases.add("parameter redeclaration",287 cases.add("parameter redeclaration",
287 \\fn f(a : i32, a : i32) {288 \\fn f(a : i32, a : i32) {
...@@ -306,9 +307,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -306,9 +307,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
306 cases.add("variable has wrong type",307 cases.add("variable has wrong type",
307 \\export fn f() -> i32 {308 \\export fn f() -> i32 {
308 \\ const a = c"a";309 \\ const a = c"a";
309 \\ a310 \\ return a;
310 \\}311 \\}
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
313 cases.add("if condition is bool, not int",314 cases.add("if condition is bool, not int",
314 \\export fn f() {315 \\export fn f() {
...@@ -393,23 +394,23 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -393,23 +394,23 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
393394
394 cases.add("missing else clause",395 cases.add("missing else clause",
395 \\fn f(b: bool) {396 \\fn f(b: bool) {
396 \\ const x : i32 = if (b) { 1 };397 \\ const x : i32 = if (b) h: { break :h 1; };
397 \\ const y = if (b) { i32(1) };398 \\ const y = if (b) h: { break :h i32(1); };
398 \\}399 \\}
399 \\export fn entry() { f(true); }400 \\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'",
401 ".tmp_source.zig:3:15: error: incompatible types: 'i32' and 'void'");402 ".tmp_source.zig:3:15: error: incompatible types: 'i32' and 'void'");
402403
403 cases.add("direct struct loop",404 cases.add("direct struct loop",
404 \\const A = struct { a : A, };405 \\const A = struct { a : A, };
405 \\export fn entry() -> usize { @sizeOf(A) }406 \\export fn entry() -> usize { return @sizeOf(A); }
406 , ".tmp_source.zig:1:11: error: struct 'A' contains itself");407 , ".tmp_source.zig:1:11: error: struct 'A' contains itself");
407408
408 cases.add("indirect struct loop",409 cases.add("indirect struct loop",
409 \\const A = struct { b : B, };410 \\const A = struct { b : B, };
410 \\const B = struct { c : C, };411 \\const B = struct { c : C, };
411 \\const C = struct { a : A, };412 \\const C = struct { a : A, };
412 \\export fn entry() -> usize { @sizeOf(A) }413 \\export fn entry() -> usize { return @sizeOf(A); }
413 , ".tmp_source.zig:1:11: error: struct 'A' contains itself");414 , ".tmp_source.zig:1:11: error: struct 'A' contains itself");
414415
415 cases.add("invalid struct field",416 cases.add("invalid struct field",
...@@ -507,10 +508,10 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -507,10 +508,10 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
507508
508 cases.add("cast unreachable",509 cases.add("cast unreachable",
509 \\fn f() -> i32 {510 \\fn f() -> i32 {
510 \\ i32(return 1)511 \\ return i32(return 1);
511 \\}512 \\}
512 \\export fn entry() { _ = f(); }513 \\export fn entry() { _ = f(); }
513 , ".tmp_source.zig:2:8: error: unreachable code");514 , ".tmp_source.zig:2:15: error: unreachable code");
514515
515 cases.add("invalid builtin fn",516 cases.add("invalid builtin fn",
516 \\fn f() -> @bogus(foo) {517 \\fn f() -> @bogus(foo) {
...@@ -533,7 +534,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -533,7 +534,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
533534
534 cases.add("struct init syntax for array",535 cases.add("struct init syntax for array",
535 \\const foo = []u16{.x = 1024,};536 \\const foo = []u16{.x = 1024,};
536 \\export fn entry() -> usize { @sizeOf(@typeOf(foo)) }537 \\export fn entry() -> usize { return @sizeOf(@typeOf(foo)); }
537 , ".tmp_source.zig:1:18: error: type '[]u16' does not support struct initialization syntax");538 , ".tmp_source.zig:1:18: error: type '[]u16' does not support struct initialization syntax");
538539
539 cases.add("type variables must be constant",540 cases.add("type variables must be constant",
...@@ -576,7 +577,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -576,7 +577,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
576 \\ }577 \\ }
577 \\}578 \\}
578 \\579 \\
579 \\export fn entry() -> usize { @sizeOf(@typeOf(f)) }580 \\export fn entry() -> usize { return @sizeOf(@typeOf(f)); }
580 , ".tmp_source.zig:8:5: error: enumeration value 'Number.Four' not handled in switch");581 , ".tmp_source.zig:8:5: error: enumeration value 'Number.Four' not handled in switch");
581582
582 cases.add("switch expression - duplicate enumeration prong",583 cases.add("switch expression - duplicate enumeration prong",
...@@ -596,7 +597,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -596,7 +597,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
596 \\ }597 \\ }
597 \\}598 \\}
598 \\599 \\
599 \\export fn entry() -> usize { @sizeOf(@typeOf(f)) }600 \\export fn entry() -> usize { return @sizeOf(@typeOf(f)); }
600 , ".tmp_source.zig:13:15: error: duplicate switch value",601 , ".tmp_source.zig:13:15: error: duplicate switch value",
601 ".tmp_source.zig:10:15: note: other value is here");602 ".tmp_source.zig:10:15: note: other value is here");
602603
...@@ -618,7 +619,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -618,7 +619,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
618 \\ }619 \\ }
619 \\}620 \\}
620 \\621 \\
621 \\export fn entry() -> usize { @sizeOf(@typeOf(f)) }622 \\export fn entry() -> usize { return @sizeOf(@typeOf(f)); }
622 , ".tmp_source.zig:13:15: error: duplicate switch value",623 , ".tmp_source.zig:13:15: error: duplicate switch value",
623 ".tmp_source.zig:10:15: note: other value is here");624 ".tmp_source.zig:10:15: note: other value is here");
624625
...@@ -641,20 +642,20 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -641,20 +642,20 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
641 \\ 0 => {},642 \\ 0 => {},
642 \\ }643 \\ }
643 \\}644 \\}
644 \\export fn entry() -> usize { @sizeOf(@typeOf(foo)) }645 \\export fn entry() -> usize { return @sizeOf(@typeOf(foo)); }
645 ,646 ,
646 ".tmp_source.zig:2:5: error: switch must handle all possibilities");647 ".tmp_source.zig:2:5: error: switch must handle all possibilities");
647648
648 cases.add("switch expression - duplicate or overlapping integer value",649 cases.add("switch expression - duplicate or overlapping integer value",
649 \\fn foo(x: u8) -> u8 {650 \\fn foo(x: u8) -> u8 {
650 \\ switch (x) {651 \\ return switch (x) {
651 \\ 0 ... 100 => u8(0),652 \\ 0 ... 100 => u8(0),
652 \\ 101 ... 200 => 1,653 \\ 101 ... 200 => 1,
653 \\ 201, 203 ... 207 => 2,654 \\ 201, 203 ... 207 => 2,
654 \\ 206 ... 255 => 3,655 \\ 206 ... 255 => 3,
655 \\ }656 \\ };
656 \\}657 \\}
657 \\export fn entry() -> usize { @sizeOf(@typeOf(foo)) }658 \\export fn entry() -> usize { return @sizeOf(@typeOf(foo)); }
658 ,659 ,
659 ".tmp_source.zig:6:9: error: duplicate switch value",660 ".tmp_source.zig:6:9: error: duplicate switch value",
660 ".tmp_source.zig:5:14: note: previous value is here");661 ".tmp_source.zig:5:14: note: previous value is here");
...@@ -666,14 +667,14 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -666,14 +667,14 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
666 \\ }667 \\ }
667 \\}668 \\}
668 \\const y: u8 = 100;669 \\const y: u8 = 100;
669 \\export fn entry() -> usize { @sizeOf(@typeOf(foo)) }670 \\export fn entry() -> usize { return @sizeOf(@typeOf(foo)); }
670 ,671 ,
671 ".tmp_source.zig:2:5: error: else prong required when switching on type '&u8'");672 ".tmp_source.zig:2:5: error: else prong required when switching on type '&u8'");
672673
673 cases.add("global variable initializer must be constant expression",674 cases.add("global variable initializer must be constant expression",
674 \\extern fn foo() -> i32;675 \\extern fn foo() -> i32;
675 \\const x = foo();676 \\const x = foo();
676 \\export fn entry() -> i32 { x }677 \\export fn entry() -> i32 { return x; }
677 , ".tmp_source.zig:2:11: error: unable to evaluate constant expression");678 , ".tmp_source.zig:2:11: error: unable to evaluate constant expression");
678679
679 cases.add("array concatenation with wrong type",680 cases.add("array concatenation with wrong type",
...@@ -681,38 +682,38 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -681,38 +682,38 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
681 \\const derp = usize(1234);682 \\const derp = usize(1234);
682 \\const a = derp ++ "foo";683 \\const a = derp ++ "foo";
683 \\684 \\
684 \\export fn entry() -> usize { @sizeOf(@typeOf(a)) }685 \\export fn entry() -> usize { return @sizeOf(@typeOf(a)); }
685 , ".tmp_source.zig:3:11: error: expected array or C string literal, found 'usize'");686 , ".tmp_source.zig:3:11: error: expected array or C string literal, found 'usize'");
686687
687 cases.add("non compile time array concatenation",688 cases.add("non compile time array concatenation",
688 \\fn f() -> []u8 {689 \\fn f() -> []u8 {
689 \\ s ++ "foo"690 \\ return s ++ "foo";
690 \\}691 \\}
691 \\var s: [10]u8 = undefined;692 \\var s: [10]u8 = undefined;
692 \\export fn entry() -> usize { @sizeOf(@typeOf(f)) }693 \\export fn entry() -> usize { return @sizeOf(@typeOf(f)); }
693 , ".tmp_source.zig:2:5: error: unable to evaluate constant expression");694 , ".tmp_source.zig:2:12: error: unable to evaluate constant expression");
694695
695 cases.add("@cImport with bogus include",696 cases.add("@cImport with bogus include",
696 \\const c = @cImport(@cInclude("bogus.h"));697 \\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)); }
698 , ".tmp_source.zig:1:11: error: C import failed",699 , ".tmp_source.zig:1:11: error: C import failed",
699 ".h:1:10: note: 'bogus.h' file not found");700 ".h:1:10: note: 'bogus.h' file not found");
700701
701 cases.add("address of number literal",702 cases.add("address of number literal",
702 \\const x = 3;703 \\const x = 3;
703 \\const y = &x;704 \\const y = &x;
704 \\fn foo() -> &const i32 { y }705 \\fn foo() -> &const i32 { return y; }
705 \\export fn entry() -> usize { @sizeOf(@typeOf(foo)) }706 \\export fn entry() -> usize { return @sizeOf(@typeOf(foo)); }
706 , ".tmp_source.zig:3:26: error: expected type '&const i32', found '&const (integer literal)'");707 , ".tmp_source.zig:3:33: error: expected type '&const i32', found '&const (integer literal)'");
707708
708 cases.add("integer overflow error",709 cases.add("integer overflow error",
709 \\const x : u8 = 300;710 \\const x : u8 = 300;
710 \\export fn entry() -> usize { @sizeOf(@typeOf(x)) }711 \\export fn entry() -> usize { return @sizeOf(@typeOf(x)); }
711 , ".tmp_source.zig:1:16: error: integer value 300 cannot be implicitly casted to type 'u8'");712 , ".tmp_source.zig:1:16: error: integer value 300 cannot be implicitly casted to type 'u8'");
712713
713 cases.add("incompatible number literals",714 cases.add("incompatible number literals",
714 \\const x = 2 == 2.0;715 \\const x = 2 == 2.0;
715 \\export fn entry() -> usize { @sizeOf(@typeOf(x)) }716 \\export fn entry() -> usize { return @sizeOf(@typeOf(x)); }
716 , ".tmp_source.zig:1:11: error: integer value 2 cannot be implicitly casted to type '(float literal)'");717 , ".tmp_source.zig:1:11: error: integer value 2 cannot be implicitly casted to type '(float literal)'");
717718
718 cases.add("missing function call param",719 cases.add("missing function call param",
...@@ -738,32 +739,32 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -738,32 +739,32 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
738 \\ const result = members[index]();739 \\ const result = members[index]();
739 \\}740 \\}
740 \\741 \\
741 \\export fn entry() -> usize { @sizeOf(@typeOf(f)) }742 \\export fn entry() -> usize { return @sizeOf(@typeOf(f)); }
742 , ".tmp_source.zig:20:34: error: expected 1 arguments, found 0");743 , ".tmp_source.zig:20:34: error: expected 1 arguments, found 0");
743744
744 cases.add("missing function name and param name",745 cases.add("missing function name and param name",
745 \\fn () {}746 \\fn () {}
746 \\fn f(i32) {}747 \\fn f(i32) {}
747 \\export fn entry() -> usize { @sizeOf(@typeOf(f)) }748 \\export fn entry() -> usize { return @sizeOf(@typeOf(f)); }
748 ,749 ,
749 ".tmp_source.zig:1:1: error: missing function name",750 ".tmp_source.zig:1:1: error: missing function name",
750 ".tmp_source.zig:2:6: error: missing parameter name");751 ".tmp_source.zig:2:6: error: missing parameter name");
751752
752 cases.add("wrong function type",753 cases.add("wrong function type",
753 \\const fns = []fn(){ a, b, c };754 \\const fns = []fn(){ a, b, c };
754 \\fn a() -> i32 {0}755 \\fn a() -> i32 {return 0;}
755 \\fn b() -> i32 {1}756 \\fn b() -> i32 {return 1;}
756 \\fn c() -> i32 {2}757 \\fn c() -> i32 {return 2;}
757 \\export fn entry() -> usize { @sizeOf(@typeOf(fns)) }758 \\export fn entry() -> usize { return @sizeOf(@typeOf(fns)); }
758 , ".tmp_source.zig:1:21: error: expected type 'fn()', found 'fn() -> i32'");759 , ".tmp_source.zig:1:21: error: expected type 'fn()', found 'fn() -> i32'");
759760
760 cases.add("extern function pointer mismatch",761 cases.add("extern function pointer mismatch",
761 \\const fns = [](fn(i32)->i32){ a, b, c };762 \\const fns = [](fn(i32)->i32){ a, b, c };
762 \\pub fn a(x: i32) -> i32 {x + 0}763 \\pub fn a(x: i32) -> i32 {return x + 0;}
763 \\pub fn b(x: i32) -> i32 {x + 1}764 \\pub fn b(x: i32) -> i32 {return x + 1;}
764 \\export fn c(x: i32) -> i32 {x + 2}765 \\export fn c(x: i32) -> i32 {return x + 2;}
765 \\766 \\
766 \\export fn entry() -> usize { @sizeOf(@typeOf(fns)) }767 \\export fn entry() -> usize { return @sizeOf(@typeOf(fns)); }
767 , ".tmp_source.zig:1:37: error: expected type 'fn(i32) -> i32', found 'extern fn(i32) -> i32'");768 , ".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) {...@@ -771,14 +772,14 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
771 \\const x : f64 = 1.0;772 \\const x : f64 = 1.0;
772 \\const y : f32 = x;773 \\const y : f32 = x;
773 \\774 \\
774 \\export fn entry() -> usize { @sizeOf(@typeOf(y)) }775 \\export fn entry() -> usize { return @sizeOf(@typeOf(y)); }
775 , ".tmp_source.zig:2:17: error: expected type 'f32', found 'f64'");776 , ".tmp_source.zig:2:17: error: expected type 'f32', found 'f64'");
776777
777778
778 cases.add("colliding invalid top level functions",779 cases.add("colliding invalid top level functions",
779 \\fn func() -> bogus {}780 \\fn func() -> bogus {}
780 \\fn func() -> bogus {}781 \\fn func() -> bogus {}
781 \\export fn entry() -> usize { @sizeOf(@typeOf(func)) }782 \\export fn entry() -> usize { return @sizeOf(@typeOf(func)); }
782 ,783 ,
783 ".tmp_source.zig:2:1: error: redefinition of 'func'",784 ".tmp_source.zig:2:1: error: redefinition of 'func'",
784 ".tmp_source.zig:1:14: error: use of undeclared identifier 'bogus'");785 ".tmp_source.zig:1:14: error: use of undeclared identifier 'bogus'");
...@@ -786,7 +787,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -786,7 +787,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
786787
787 cases.add("bogus compile var",788 cases.add("bogus compile var",
788 \\const x = @import("builtin").bogus;789 \\const x = @import("builtin").bogus;
789 \\export fn entry() -> usize { @sizeOf(@typeOf(x)) }790 \\export fn entry() -> usize { return @sizeOf(@typeOf(x)); }
790 , ".tmp_source.zig:1:29: error: no member named 'bogus' in '");791 , ".tmp_source.zig:1:29: error: no member named 'bogus' in '");
791792
792793
...@@ -795,11 +796,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -795,11 +796,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
795 \\ y: [get()]u8,796 \\ y: [get()]u8,
796 \\};797 \\};
797 \\var global_var: usize = 1;798 \\var global_var: usize = 1;
798 \\fn get() -> usize { global_var }799 \\fn get() -> usize { return global_var; }
799 \\800 \\
800 \\export fn entry() -> usize { @sizeOf(@typeOf(Foo)) }801 \\export fn entry() -> usize { return @sizeOf(@typeOf(Foo)); }
801 ,802 ,
802 ".tmp_source.zig:5:21: error: unable to evaluate constant expression",803 ".tmp_source.zig:5:28: error: unable to evaluate constant expression",
803 ".tmp_source.zig:2:12: note: called from here",804 ".tmp_source.zig:2:12: note: called from here",
804 ".tmp_source.zig:2:8: note: called from here");805 ".tmp_source.zig:2:8: note: called from here");
805806
...@@ -810,7 +811,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -810,7 +811,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
810 \\};811 \\};
811 \\const x = Foo {.field = 1} + Foo {.field = 2};812 \\const x = Foo {.field = 1} + Foo {.field = 2};
812 \\813 \\
813 \\export fn entry() -> usize { @sizeOf(@typeOf(x)) }814 \\export fn entry() -> usize { return @sizeOf(@typeOf(x)); }
814 , ".tmp_source.zig:4:28: error: invalid operands to binary expression: 'Foo' and 'Foo'");815 , ".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) {...@@ -820,10 +821,10 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
820 \\const int_x = u32(1) / u32(0);821 \\const int_x = u32(1) / u32(0);
821 \\const float_x = f32(1.0) / f32(0.0);822 \\const float_x = f32(1.0) / f32(0.0);
822 \\823 \\
823 \\export fn entry1() -> usize { @sizeOf(@typeOf(lit_int_x)) }824 \\export fn entry1() -> usize { return @sizeOf(@typeOf(lit_int_x)); }
824 \\export fn entry2() -> usize { @sizeOf(@typeOf(lit_float_x)) }825 \\export fn entry2() -> usize { return @sizeOf(@typeOf(lit_float_x)); }
825 \\export fn entry3() -> usize { @sizeOf(@typeOf(int_x)) }826 \\export fn entry3() -> usize { return @sizeOf(@typeOf(int_x)); }
826 \\export fn entry4() -> usize { @sizeOf(@typeOf(float_x)) }827 \\export fn entry4() -> usize { return @sizeOf(@typeOf(float_x)); }
827 ,828 ,
828 ".tmp_source.zig:1:21: error: division by zero is undefined",829 ".tmp_source.zig:1:21: error: division by zero is undefined",
829 ".tmp_source.zig:2:25: error: division by zero is undefined",830 ".tmp_source.zig:2:25: error: division by zero is undefined",
...@@ -835,14 +836,14 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -835,14 +836,14 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
835 \\const foo = "a836 \\const foo = "a
836 \\b";837 \\b";
837 \\838 \\
838 \\export fn entry() -> usize { @sizeOf(@typeOf(foo)) }839 \\export fn entry() -> usize { return @sizeOf(@typeOf(foo)); }
839 , ".tmp_source.zig:1:13: error: newline not allowed in string literal");840 , ".tmp_source.zig:1:13: error: newline not allowed in string literal");
840841
841 cases.add("invalid comparison for function pointers",842 cases.add("invalid comparison for function pointers",
842 \\fn foo() {}843 \\fn foo() {}
843 \\const invalid = foo > foo;844 \\const invalid = foo > foo;
844 \\845 \\
845 \\export fn entry() -> usize { @sizeOf(@typeOf(invalid)) }846 \\export fn entry() -> usize { return @sizeOf(@typeOf(invalid)); }
846 , ".tmp_source.zig:2:21: error: operator not allowed for type 'fn()'");847 , ".tmp_source.zig:2:21: error: operator not allowed for type 'fn()'");
847848
848 cases.add("generic function instance with non-constant expression",849 cases.add("generic function instance with non-constant expression",
...@@ -851,13 +852,13 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -851,13 +852,13 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
851 \\ return foo(a, b);852 \\ return foo(a, b);
852 \\}853 \\}
853 \\854 \\
854 \\export fn entry() -> usize { @sizeOf(@typeOf(test1)) }855 \\export fn entry() -> usize { return @sizeOf(@typeOf(test1)); }
855 , ".tmp_source.zig:3:16: error: unable to evaluate constant expression");856 , ".tmp_source.zig:3:16: error: unable to evaluate constant expression");
856857
857 cases.add("assign null to non-nullable pointer",858 cases.add("assign null to non-nullable pointer",
858 \\const a: &u8 = null;859 \\const a: &u8 = null;
859 \\860 \\
860 \\export fn entry() -> usize { @sizeOf(@typeOf(a)) }861 \\export fn entry() -> usize { return @sizeOf(@typeOf(a)); }
861 , ".tmp_source.zig:1:16: error: expected type '&u8', found '(null)'");862 , ".tmp_source.zig:1:16: error: expected type '&u8', found '(null)'");
862863
863 cases.add("indexing an array of size zero",864 cases.add("indexing an array of size zero",
...@@ -870,18 +871,18 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -870,18 +871,18 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
870 cases.add("compile time division by zero",871 cases.add("compile time division by zero",
871 \\const y = foo(0);872 \\const y = foo(0);
872 \\fn foo(x: u32) -> u32 {873 \\fn foo(x: u32) -> u32 {
873 \\ 1 / x874 \\ return 1 / x;
874 \\}875 \\}
875 \\876 \\
876 \\export fn entry() -> usize { @sizeOf(@typeOf(y)) }877 \\export fn entry() -> usize { return @sizeOf(@typeOf(y)); }
877 ,878 ,
878 ".tmp_source.zig:3:7: error: division by zero is undefined",879 ".tmp_source.zig:3:14: error: division by zero is undefined",
879 ".tmp_source.zig:1:14: note: called from here");880 ".tmp_source.zig:1:14: note: called from here");
880881
881 cases.add("branch on undefined value",882 cases.add("branch on undefined value",
882 \\const x = if (undefined) true else false;883 \\const x = if (undefined) true else false;
883 \\884 \\
884 \\export fn entry() -> usize { @sizeOf(@typeOf(x)) }885 \\export fn entry() -> usize { return @sizeOf(@typeOf(x)); }
885 , ".tmp_source.zig:1:15: error: use of undefined value");886 , ".tmp_source.zig:1:15: error: use of undefined value");
886887
887888
...@@ -891,7 +892,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -891,7 +892,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
891 \\ return fibbonaci(x - 1) + fibbonaci(x - 2);892 \\ return fibbonaci(x - 1) + fibbonaci(x - 2);
892 \\}893 \\}
893 \\894 \\
894 \\export fn entry() -> usize { @sizeOf(@typeOf(seventh_fib_number)) }895 \\export fn entry() -> usize { return @sizeOf(@typeOf(seventh_fib_number)); }
895 ,896 ,
896 ".tmp_source.zig:3:21: error: evaluation exceeded 1000 backwards branches",897 ".tmp_source.zig:3:21: error: evaluation exceeded 1000 backwards branches",
897 ".tmp_source.zig:3:21: note: called from here");898 ".tmp_source.zig:3:21: note: called from here");
...@@ -899,7 +900,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -899,7 +900,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
899 cases.add("@embedFile with bogus file",900 cases.add("@embedFile with bogus file",
900 \\const resource = @embedFile("bogus.txt");901 \\const resource = @embedFile("bogus.txt");
901 \\902 \\
902 \\export fn entry() -> usize { @sizeOf(@typeOf(resource)) }903 \\export fn entry() -> usize { return @sizeOf(@typeOf(resource)); }
903 , ".tmp_source.zig:1:29: error: unable to find '", "bogus.txt'");904 , ".tmp_source.zig:1:29: error: unable to find '", "bogus.txt'");
904905
905 cases.add("non-const expression in struct literal outside function",906 cases.add("non-const expression in struct literal outside function",
...@@ -909,7 +910,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -909,7 +910,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
909 \\const a = Foo {.x = get_it()};910 \\const a = Foo {.x = get_it()};
910 \\extern fn get_it() -> i32;911 \\extern fn get_it() -> i32;
911 \\912 \\
912 \\export fn entry() -> usize { @sizeOf(@typeOf(a)) }913 \\export fn entry() -> usize { return @sizeOf(@typeOf(a)); }
913 , ".tmp_source.zig:4:21: error: unable to evaluate constant expression");914 , ".tmp_source.zig:4:21: error: unable to evaluate constant expression");
914915
915 cases.add("non-const expression function call with struct return value outside function",916 cases.add("non-const expression function call with struct return value outside function",
...@@ -919,11 +920,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -919,11 +920,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
919 \\const a = get_it();920 \\const a = get_it();
920 \\fn get_it() -> Foo {921 \\fn get_it() -> Foo {
921 \\ global_side_effect = true;922 \\ global_side_effect = true;
922 \\ Foo {.x = 13}923 \\ return Foo {.x = 13};
923 \\}924 \\}
924 \\var global_side_effect = false;925 \\var global_side_effect = false;
925 \\926 \\
926 \\export fn entry() -> usize { @sizeOf(@typeOf(a)) }927 \\export fn entry() -> usize { return @sizeOf(@typeOf(a)); }
927 ,928 ,
928 ".tmp_source.zig:6:24: error: unable to evaluate constant expression",929 ".tmp_source.zig:6:24: error: unable to evaluate constant expression",
929 ".tmp_source.zig:4:17: note: called from here");930 ".tmp_source.zig:4:17: note: called from here");
...@@ -939,21 +940,21 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -939,21 +940,21 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
939940
940 cases.add("illegal comparison of types",941 cases.add("illegal comparison of types",
941 \\fn bad_eql_1(a: []u8, b: []u8) -> bool {942 \\fn bad_eql_1(a: []u8, b: []u8) -> bool {
942 \\ a == b943 \\ return a == b;
943 \\}944 \\}
944 \\const EnumWithData = union(enum) {945 \\const EnumWithData = union(enum) {
945 \\ One: void,946 \\ One: void,
946 \\ Two: i32,947 \\ Two: i32,
947 \\};948 \\};
948 \\fn bad_eql_2(a: &const EnumWithData, b: &const EnumWithData) -> bool {949 \\fn bad_eql_2(a: &const EnumWithData, b: &const EnumWithData) -> bool {
949 \\ *a == *b950 \\ return *a == *b;
950 \\}951 \\}
951 \\952 \\
952 \\export fn entry1() -> usize { @sizeOf(@typeOf(bad_eql_1)) }953 \\export fn entry1() -> usize { return @sizeOf(@typeOf(bad_eql_1)); }
953 \\export fn entry2() -> usize { @sizeOf(@typeOf(bad_eql_2)) }954 \\export fn entry2() -> usize { return @sizeOf(@typeOf(bad_eql_2)); }
954 ,955 ,
955 ".tmp_source.zig:2:7: error: operator not allowed for type '[]u8'",956 ".tmp_source.zig:2:14: error: operator not allowed for type '[]u8'",
956 ".tmp_source.zig:9:8: error: operator not allowed for type 'EnumWithData'");957 ".tmp_source.zig:9:15: error: operator not allowed for type 'EnumWithData'");
957958
958 cases.add("non-const switch number literal",959 cases.add("non-const switch number literal",
959 \\export fn foo() {960 \\export fn foo() {
...@@ -964,7 +965,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -964,7 +965,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
964 \\ };965 \\ };
965 \\}966 \\}
966 \\fn bar() -> i32 {967 \\fn bar() -> i32 {
967 \\ 2968 \\ return 2;
968 \\}969 \\}
969 , ".tmp_source.zig:2:15: error: unable to infer expression type");970 , ".tmp_source.zig:2:15: error: unable to infer expression type");
970971
...@@ -987,56 +988,56 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -987,56 +988,56 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
987 cases.add("negation overflow in function evaluation",988 cases.add("negation overflow in function evaluation",
988 \\const y = neg(-128);989 \\const y = neg(-128);
989 \\fn neg(x: i8) -> i8 {990 \\fn neg(x: i8) -> i8 {
990 \\ -x991 \\ return -x;
991 \\}992 \\}
992 \\993 \\
993 \\export fn entry() -> usize { @sizeOf(@typeOf(y)) }994 \\export fn entry() -> usize { return @sizeOf(@typeOf(y)); }
994 ,995 ,
995 ".tmp_source.zig:3:5: error: negation caused overflow",996 ".tmp_source.zig:3:12: error: negation caused overflow",
996 ".tmp_source.zig:1:14: note: called from here");997 ".tmp_source.zig:1:14: note: called from here");
997998
998 cases.add("add overflow in function evaluation",999 cases.add("add overflow in function evaluation",
999 \\const y = add(65530, 10);1000 \\const y = add(65530, 10);
1000 \\fn add(a: u16, b: u16) -> u16 {1001 \\fn add(a: u16, b: u16) -> u16 {
1001 \\ a + b1002 \\ return a + b;
1002 \\}1003 \\}
1003 \\1004 \\
1004 \\export fn entry() -> usize { @sizeOf(@typeOf(y)) }1005 \\export fn entry() -> usize { return @sizeOf(@typeOf(y)); }
1005 ,1006 ,
1006 ".tmp_source.zig:3:7: error: operation caused overflow",1007 ".tmp_source.zig:3:14: error: operation caused overflow",
1007 ".tmp_source.zig:1:14: note: called from here");1008 ".tmp_source.zig:1:14: note: called from here");
10081009
10091010
1010 cases.add("sub overflow in function evaluation",1011 cases.add("sub overflow in function evaluation",
1011 \\const y = sub(10, 20);1012 \\const y = sub(10, 20);
1012 \\fn sub(a: u16, b: u16) -> u16 {1013 \\fn sub(a: u16, b: u16) -> u16 {
1013 \\ a - b1014 \\ return a - b;
1014 \\}1015 \\}
1015 \\1016 \\
1016 \\export fn entry() -> usize { @sizeOf(@typeOf(y)) }1017 \\export fn entry() -> usize { return @sizeOf(@typeOf(y)); }
1017 ,1018 ,
1018 ".tmp_source.zig:3:7: error: operation caused overflow",1019 ".tmp_source.zig:3:14: error: operation caused overflow",
1019 ".tmp_source.zig:1:14: note: called from here");1020 ".tmp_source.zig:1:14: note: called from here");
10201021
1021 cases.add("mul overflow in function evaluation",1022 cases.add("mul overflow in function evaluation",
1022 \\const y = mul(300, 6000);1023 \\const y = mul(300, 6000);
1023 \\fn mul(a: u16, b: u16) -> u16 {1024 \\fn mul(a: u16, b: u16) -> u16 {
1024 \\ a * b1025 \\ return a * b;
1025 \\}1026 \\}
1026 \\1027 \\
1027 \\export fn entry() -> usize { @sizeOf(@typeOf(y)) }1028 \\export fn entry() -> usize { return @sizeOf(@typeOf(y)); }
1028 ,1029 ,
1029 ".tmp_source.zig:3:7: error: operation caused overflow",1030 ".tmp_source.zig:3:14: error: operation caused overflow",
1030 ".tmp_source.zig:1:14: note: called from here");1031 ".tmp_source.zig:1:14: note: called from here");
10311032
1032 cases.add("truncate sign mismatch",1033 cases.add("truncate sign mismatch",
1033 \\fn f() -> i8 {1034 \\fn f() -> i8 {
1034 \\ const x: u32 = 10;1035 \\ const x: u32 = 10;
1035 \\ @truncate(i8, x)1036 \\ return @truncate(i8, x);
1036 \\}1037 \\}
1037 \\1038 \\
1038 \\export fn entry() -> usize { @sizeOf(@typeOf(f)) }1039 \\export fn entry() -> usize { return @sizeOf(@typeOf(f)); }
1039 , ".tmp_source.zig:3:19: error: expected signed integer type, found 'u32'");1040 , ".tmp_source.zig:3:26: error: expected signed integer type, found 'u32'");
10401041
1041 cases.add("%return in function with non error return type",1042 cases.add("%return in function with non error return type",
1042 \\export fn f() {1043 \\export fn f() {
...@@ -1067,16 +1068,16 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1067,16 +1068,16 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
10671068
1068 cases.add("export function with comptime parameter",1069 cases.add("export function with comptime parameter",
1069 \\export fn foo(comptime x: i32, y: i32) -> i32{1070 \\export fn foo(comptime x: i32, y: i32) -> i32{
1070 \\ x + y1071 \\ return x + y;
1071 \\}1072 \\}
1072 , ".tmp_source.zig:1:15: error: comptime parameter not allowed in function with calling convention 'ccc'");1073 , ".tmp_source.zig:1:15: error: comptime parameter not allowed in function with calling convention 'ccc'");
10731074
1074 cases.add("extern function with comptime parameter",1075 cases.add("extern function with comptime parameter",
1075 \\extern fn foo(comptime x: i32, y: i32) -> i32;1076 \\extern fn foo(comptime x: i32, y: i32) -> i32;
1076 \\fn f() -> i32 {1077 \\fn f() -> i32 {
1077 \\ foo(1, 2)1078 \\ return foo(1, 2);
1078 \\}1079 \\}
1079 \\export fn entry() -> usize { @sizeOf(@typeOf(f)) }1080 \\export fn entry() -> usize { return @sizeOf(@typeOf(f)); }
1080 , ".tmp_source.zig:1:15: error: comptime parameter not allowed in function with calling convention 'ccc'");1081 , ".tmp_source.zig:1:15: error: comptime parameter not allowed in function with calling convention 'ccc'");
10811082
1082 cases.add("convert fixed size array to slice with invalid size",1083 cases.add("convert fixed size array to slice with invalid size",
...@@ -1090,15 +1091,15 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1090,15 +1091,15 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
1090 \\var a: u32 = 0;1091 \\var a: u32 = 0;
1091 \\pub fn List(comptime T: type) -> type {1092 \\pub fn List(comptime T: type) -> type {
1092 \\ a += 1;1093 \\ a += 1;
1093 \\ SmallList(T, 8)1094 \\ return SmallList(T, 8);
1094 \\}1095 \\}
1095 \\1096 \\
1096 \\pub fn SmallList(comptime T: type, comptime STATIC_SIZE: usize) -> type {1097 \\pub fn SmallList(comptime T: type, comptime STATIC_SIZE: usize) -> type {
1097 \\ struct {1098 \\ return struct {
1098 \\ items: []T,1099 \\ items: []T,
1099 \\ length: usize,1100 \\ length: usize,
1100 \\ prealloc_items: [STATIC_SIZE]T,1101 \\ prealloc_items: [STATIC_SIZE]T,
1101 \\ }1102 \\ };
1102 \\}1103 \\}
1103 \\1104 \\
1104 \\export fn function_with_return_type_type() {1105 \\export fn function_with_return_type_type() {
...@@ -1113,7 +1114,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1113,7 +1114,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
1113 \\fn f(m: []const u8) {1114 \\fn f(m: []const u8) {
1114 \\ m.copy(u8, self[0..], m);1115 \\ m.copy(u8, self[0..], m);
1115 \\}1116 \\}
1116 \\export fn entry() -> usize { @sizeOf(@typeOf(f)) }1117 \\export fn entry() -> usize { return @sizeOf(@typeOf(f)); }
1117 , ".tmp_source.zig:3:6: error: no member named 'copy' in '[]const u8'");1118 , ".tmp_source.zig:3:6: error: no member named 'copy' in '[]const u8'");
11181119
1119 cases.add("wrong number of arguments for method fn call",1120 cases.add("wrong number of arguments for method fn call",
...@@ -1124,7 +1125,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1124,7 +1125,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
1124 \\1125 \\
1125 \\ foo.method(1, 2);1126 \\ foo.method(1, 2);
1126 \\}1127 \\}
1127 \\export fn entry() -> usize { @sizeOf(@typeOf(f)) }1128 \\export fn entry() -> usize { return @sizeOf(@typeOf(f)); }
1128 , ".tmp_source.zig:6:15: error: expected 2 arguments, found 3");1129 , ".tmp_source.zig:6:15: error: expected 2 arguments, found 3");
11291130
1130 cases.add("assign through constant pointer",1131 cases.add("assign through constant pointer",
...@@ -1149,7 +1150,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1149,7 +1150,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
1149 \\fn foo(blah: []u8) {1150 \\fn foo(blah: []u8) {
1150 \\ for (blah) { }1151 \\ for (blah) { }
1151 \\}1152 \\}
1152 \\export fn entry() -> usize { @sizeOf(@typeOf(foo)) }1153 \\export fn entry() -> usize { return @sizeOf(@typeOf(foo)); }
1153 , ".tmp_source.zig:2:5: error: for loop expression missing element parameter");1154 , ".tmp_source.zig:2:5: error: for loop expression missing element parameter");
11541155
1155 cases.add("misspelled type with pointer only reference",1156 cases.add("misspelled type with pointer only reference",
...@@ -1182,7 +1183,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1182,7 +1183,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
1182 \\ var jd = JsonNode {.kind = JsonType.JSONArray , .jobject = JsonOA.JSONArray {jll} };1183 \\ var jd = JsonNode {.kind = JsonType.JSONArray , .jobject = JsonOA.JSONArray {jll} };
1183 \\}1184 \\}
1184 \\1185 \\
1185 \\export fn entry() -> usize { @sizeOf(@typeOf(foo)) }1186 \\export fn entry() -> usize { return @sizeOf(@typeOf(foo)); }
1186 , ".tmp_source.zig:5:16: error: use of undeclared identifier 'JsonList'");1187 , ".tmp_source.zig:5:16: error: use of undeclared identifier 'JsonList'");
11871188
1188 cases.add("method call with first arg type primitive",1189 cases.add("method call with first arg type primitive",
...@@ -1190,9 +1191,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1190,9 +1191,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
1190 \\ x: i32,1191 \\ x: i32,
1191 \\1192 \\
1192 \\ fn init(x: i32) -> Foo {1193 \\ fn init(x: i32) -> Foo {
1193 \\ Foo {1194 \\ return Foo {
1194 \\ .x = x,1195 \\ .x = x,
1195 \\ }1196 \\ };
1196 \\ }1197 \\ }
1197 \\};1198 \\};
1198 \\1199 \\
...@@ -1209,10 +1210,10 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1209,10 +1210,10 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
1209 \\ allocator: &Allocator,1210 \\ allocator: &Allocator,
1210 \\1211 \\
1211 \\ pub fn init(allocator: &Allocator) -> List {1212 \\ pub fn init(allocator: &Allocator) -> List {
1212 \\ List {1213 \\ return List {
1213 \\ .len = 0,1214 \\ .len = 0,
1214 \\ .allocator = allocator,1215 \\ .allocator = allocator,
1215 \\ }1216 \\ };
1216 \\ }1217 \\ }
1217 \\};1218 \\};
1218 \\1219 \\
...@@ -1235,10 +1236,10 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1235,10 +1236,10 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
1235 \\const TINY_QUANTUM_SIZE = 1 << TINY_QUANTUM_SHIFT;1236 \\const TINY_QUANTUM_SIZE = 1 << TINY_QUANTUM_SHIFT;
1236 \\var block_aligned_stuff: usize = (4 + TINY_QUANTUM_SIZE) & ~(TINY_QUANTUM_SIZE - 1);1237 \\var block_aligned_stuff: usize = (4 + TINY_QUANTUM_SIZE) & ~(TINY_QUANTUM_SIZE - 1);
1237 \\1238 \\
1238 \\export fn entry() -> usize { @sizeOf(@typeOf(block_aligned_stuff)) }1239 \\export fn entry() -> usize { return @sizeOf(@typeOf(block_aligned_stuff)); }
1239 , ".tmp_source.zig:3:60: error: unable to perform binary not operation on type '(integer literal)'");1240 , ".tmp_source.zig:3:60: error: unable to perform binary not operation on type '(integer literal)'");
12401241
1241 cases.addCase({1242 cases.addCase(x: {
1242 const tc = cases.create("multiple files with private function error",1243 const tc = cases.create("multiple files with private function error",
1243 \\const foo = @import("foo.zig");1244 \\const foo = @import("foo.zig");
1244 \\1245 \\
...@@ -1253,14 +1254,14 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1253,14 +1254,14 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
1253 \\fn privateFunction() { }1254 \\fn privateFunction() { }
1254 );1255 );
12551256
1256 tc1257 break :x tc;
1257 });1258 });
12581259
1259 cases.add("container init with non-type",1260 cases.add("container init with non-type",
1260 \\const zero: i32 = 0;1261 \\const zero: i32 = 0;
1261 \\const a = zero{1};1262 \\const a = zero{1};
1262 \\1263 \\
1263 \\export fn entry() -> usize { @sizeOf(@typeOf(a)) }1264 \\export fn entry() -> usize { return @sizeOf(@typeOf(a)); }
1264 , ".tmp_source.zig:2:11: error: expected type, found 'i32'");1265 , ".tmp_source.zig:2:11: error: expected type, found 'i32'");
12651266
1266 cases.add("assign to constant field",1267 cases.add("assign to constant field",
...@@ -1288,22 +1289,22 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1288,22 +1289,22 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
1288 \\ return 0;1289 \\ return 0;
1289 \\}1290 \\}
1290 \\1291 \\
1291 \\export fn entry() -> usize { @sizeOf(@typeOf(testTrickyDefer)) }1292 \\export fn entry() -> usize { return @sizeOf(@typeOf(testTrickyDefer)); }
1292 , ".tmp_source.zig:4:11: error: cannot return from defer expression");1293 , ".tmp_source.zig:4:11: error: cannot return from defer expression");
12931294
1294 cases.add("attempt to access var args out of bounds",1295 cases.add("attempt to access var args out of bounds",
1295 \\fn add(args: ...) -> i32 {1296 \\fn add(args: ...) -> i32 {
1296 \\ args[0] + args[1]1297 \\ return args[0] + args[1];
1297 \\}1298 \\}
1298 \\1299 \\
1299 \\fn foo() -> i32 {1300 \\fn foo() -> i32 {
1300 \\ add(i32(1234))1301 \\ return add(i32(1234));
1301 \\}1302 \\}
1302 \\1303 \\
1303 \\export fn entry() -> usize { @sizeOf(@typeOf(foo)) }1304 \\export fn entry() -> usize { return @sizeOf(@typeOf(foo)); }
1304 ,1305 ,
1305 ".tmp_source.zig:2:19: error: index 1 outside argument list of size 1",1306 ".tmp_source.zig:2:26: error: index 1 outside argument list of size 1",
1306 ".tmp_source.zig:6:8: note: called from here");1307 ".tmp_source.zig:6:15: note: called from here");
13071308
1308 cases.add("pass integer literal to var args",1309 cases.add("pass integer literal to var args",
1309 \\fn add(args: ...) -> i32 {1310 \\fn add(args: ...) -> i32 {
...@@ -1315,11 +1316,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1315,11 +1316,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
1315 \\}1316 \\}
1316 \\1317 \\
1317 \\fn bar() -> i32 {1318 \\fn bar() -> i32 {
1318 \\ add(1, 2, 3, 4)1319 \\ return add(1, 2, 3, 4);
1319 \\}1320 \\}
1320 \\1321 \\
1321 \\export fn entry() -> usize { @sizeOf(@typeOf(bar)) }1322 \\export fn entry() -> usize { return @sizeOf(@typeOf(bar)); }
1322 , ".tmp_source.zig:10:9: error: parameter of type '(integer literal)' requires comptime");1323 , ".tmp_source.zig:10:16: error: parameter of type '(integer literal)' requires comptime");
13231324
1324 cases.add("assign too big number to u16",1325 cases.add("assign too big number to u16",
1325 \\export fn foo() {1326 \\export fn foo() {
...@@ -1329,12 +1330,12 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1329,12 +1330,12 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
13291330
1330 cases.add("global variable alignment non power of 2",1331 cases.add("global variable alignment non power of 2",
1331 \\const some_data: [100]u8 align(3) = undefined;1332 \\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)); }
1333 , ".tmp_source.zig:1:32: error: alignment value 3 is not a power of 2");1334 , ".tmp_source.zig:1:32: error: alignment value 3 is not a power of 2");
13341335
1335 cases.add("function alignment non power of 2",1336 cases.add("function alignment non power of 2",
1336 \\extern fn foo() align(3);1337 \\extern fn foo() align(3);
1337 \\export fn entry() { foo() }1338 \\export fn entry() { return foo(); }
1338 , ".tmp_source.zig:1:23: error: alignment value 3 is not a power of 2");1339 , ".tmp_source.zig:1:23: error: alignment value 3 is not a power of 2");
13391340
1340 cases.add("compile log",1341 cases.add("compile log",
...@@ -1369,7 +1370,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1369,7 +1370,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
1369 \\ return *x;1370 \\ return *x;
1370 \\}1371 \\}
1371 \\1372 \\
1372 \\export fn entry() -> usize { @sizeOf(@typeOf(foo)) }1373 \\export fn entry() -> usize { return @sizeOf(@typeOf(foo)); }
1373 , ".tmp_source.zig:8:26: error: expected type '&const u3', found '&align(1:3:6) const u3'");1374 , ".tmp_source.zig:8:26: error: expected type '&const u3', found '&align(1:3:6) const u3'");
13741375
1375 cases.add("referring to a struct that is invalid",1376 cases.add("referring to a struct that is invalid",
...@@ -1405,14 +1406,14 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1405,14 +1406,14 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
1405 \\export fn foo() {1406 \\export fn foo() {
1406 \\ bar();1407 \\ bar();
1407 \\}1408 \\}
1408 \\fn bar() -> i32 { 0 }1409 \\fn bar() -> i32 { return 0; }
1409 , ".tmp_source.zig:2:8: error: expression value is ignored");1410 , ".tmp_source.zig:2:8: error: expression value is ignored");
14101411
1411 cases.add("ignored assert-err-ok return value",1412 cases.add("ignored assert-err-ok return value",
1412 \\export fn foo() {1413 \\export fn foo() {
1413 \\ %%bar();1414 \\ %%bar();
1414 \\}1415 \\}
1415 \\fn bar() -> %i32 { 0 }1416 \\fn bar() -> %i32 { return 0; }
1416 , ".tmp_source.zig:2:5: error: expression value is ignored");1417 , ".tmp_source.zig:2:5: error: expression value is ignored");
14171418
1418 cases.add("ignored statement value",1419 cases.add("ignored statement value",
...@@ -1439,11 +1440,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1439,11 +1440,11 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
1439 \\}1440 \\}
1440 , ".tmp_source.zig:2:12: error: expression value is ignored");1441 , ".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",
1443 \\export fn foo() {1444 \\export fn foo() {
1444 \\ defer bar();1445 \\ defer bar();
1445 \\}1446 \\}
1446 \\fn bar() -> %i32 { 0 }1447 \\fn bar() -> %i32 { return 0; }
1447 , ".tmp_source.zig:2:14: error: expression value is ignored");1448 , ".tmp_source.zig:2:14: error: expression value is ignored");
14481449
1449 cases.add("dereference an array",1450 cases.add("dereference an array",
...@@ -1454,7 +1455,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1454,7 +1455,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
1454 \\ return (*out)[0..1];1455 \\ return (*out)[0..1];
1455 \\}1456 \\}
1456 \\1457 \\
1457 \\export fn entry() -> usize { @sizeOf(@typeOf(pass)) }1458 \\export fn entry() -> usize { return @sizeOf(@typeOf(pass)); }
1458 , ".tmp_source.zig:4:5: error: attempt to dereference non pointer type '[10]u8'");1459 , ".tmp_source.zig:4:5: error: attempt to dereference non pointer type '[10]u8'");
14591460
1460 cases.add("pass const ptr to mutable ptr fn",1461 cases.add("pass const ptr to mutable ptr fn",
...@@ -1467,10 +1468,10 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1467,10 +1468,10 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
1467 \\ return true;1468 \\ return true;
1468 \\}1469 \\}
1469 \\1470 \\
1470 \\export fn entry() -> usize { @sizeOf(@typeOf(foo)) }1471 \\export fn entry() -> usize { return @sizeOf(@typeOf(foo)); }
1471 , ".tmp_source.zig:4:19: error: expected type '&[]const u8', found '&const []const u8'");1472 , ".tmp_source.zig:4:19: error: expected type '&[]const u8', found '&const []const u8'");
14721473
1473 cases.addCase({1474 cases.addCase(x: {
1474 const tc = cases.create("export collision",1475 const tc = cases.create("export collision",
1475 \\const foo = @import("foo.zig");1476 \\const foo = @import("foo.zig");
1476 \\1477 \\
...@@ -1486,13 +1487,13 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1486,13 +1487,13 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
1486 \\pub const baz = 1234;1487 \\pub const baz = 1234;
1487 );1488 );
14881489
1489 tc1490 break :x tc;
1490 });1491 });
14911492
1492 cases.add("pass non-copyable type by value to function",1493 cases.add("pass non-copyable type by value to function",
1493 \\const Point = struct { x: i32, y: i32, };1494 \\const Point = struct { x: i32, y: i32, };
1494 \\fn foo(p: Point) { }1495 \\fn foo(p: Point) { }
1495 \\export fn entry() -> usize { @sizeOf(@typeOf(foo)) }1496 \\export fn entry() -> usize { return @sizeOf(@typeOf(foo)); }
1496 , ".tmp_source.zig:2:11: error: type 'Point' is not copyable; cannot pass by value");1497 , ".tmp_source.zig:2:11: error: type 'Point' is not copyable; cannot pass by value");
14971498
1498 cases.add("implicit cast from array to mutable slice",1499 cases.add("implicit cast from array to mutable slice",
...@@ -1515,7 +1516,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1515,7 +1516,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
1515 \\fn foo(e: error) -> u2 {1516 \\fn foo(e: error) -> u2 {
1516 \\ return u2(e);1517 \\ return u2(e);
1517 \\}1518 \\}
1518 \\export fn entry() -> usize { @sizeOf(@typeOf(foo)) }1519 \\export fn entry() -> usize { return @sizeOf(@typeOf(foo)); }
1519 , ".tmp_source.zig:4:14: error: too many error values to fit in 'u2'");1520 , ".tmp_source.zig:4:14: error: too many error values to fit in 'u2'");
15201521
1521 cases.add("asm at compile time",1522 cases.add("asm at compile time",
...@@ -1665,17 +1666,17 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1665,17 +1666,17 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
16651666
1666 cases.add("inner struct member shadowing outer struct member",1667 cases.add("inner struct member shadowing outer struct member",
1667 \\fn A() -> type {1668 \\fn A() -> type {
1668 \\ struct {1669 \\ return struct {
1669 \\ b: B(),1670 \\ b: B(),
1670 \\1671 \\
1671 \\ const Self = this;1672 \\ const Self = this;
1672 \\1673 \\
1673 \\ fn B() -> type {1674 \\ fn B() -> type {
1674 \\ struct {1675 \\ return struct {
1675 \\ const Self = this;1676 \\ const Self = this;
1676 \\ }1677 \\ };
1677 \\ }1678 \\ }
1678 \\ }1679 \\ };
1679 \\}1680 \\}
1680 \\comptime {1681 \\comptime {
1681 \\ assert(A().B().Self != A().Self);1682 \\ assert(A().B().Self != A().Self);
...@@ -1691,7 +1692,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1691,7 +1692,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
1691 \\export fn foo() {1692 \\export fn foo() {
1692 \\ while (bar()) {}1693 \\ while (bar()) {}
1693 \\}1694 \\}
1694 \\fn bar() -> ?i32 { 1 }1695 \\fn bar() -> ?i32 { return 1; }
1695 ,1696 ,
1696 ".tmp_source.zig:2:15: error: expected type 'bool', found '?i32'");1697 ".tmp_source.zig:2:15: error: expected type 'bool', found '?i32'");
16971698
...@@ -1699,7 +1700,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1699,7 +1700,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
1699 \\export fn foo() {1700 \\export fn foo() {
1700 \\ while (bar()) {}1701 \\ while (bar()) {}
1701 \\}1702 \\}
1702 \\fn bar() -> %i32 { 1 }1703 \\fn bar() -> %i32 { return 1; }
1703 ,1704 ,
1704 ".tmp_source.zig:2:15: error: expected type 'bool', found '%i32'");1705 ".tmp_source.zig:2:15: error: expected type 'bool', found '%i32'");
17051706
...@@ -1707,7 +1708,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1707,7 +1708,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
1707 \\export fn foo() {1708 \\export fn foo() {
1708 \\ while (bar()) |x| {}1709 \\ while (bar()) |x| {}
1709 \\}1710 \\}
1710 \\fn bar() -> bool { true }1711 \\fn bar() -> bool { return true; }
1711 ,1712 ,
1712 ".tmp_source.zig:2:15: error: expected nullable type, found 'bool'");1713 ".tmp_source.zig:2:15: error: expected nullable type, found 'bool'");
17131714
...@@ -1715,7 +1716,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1715,7 +1716,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
1715 \\export fn foo() {1716 \\export fn foo() {
1716 \\ while (bar()) |x| {}1717 \\ while (bar()) |x| {}
1717 \\}1718 \\}
1718 \\fn bar() -> %i32 { 1 }1719 \\fn bar() -> %i32 { return 1; }
1719 ,1720 ,
1720 ".tmp_source.zig:2:15: error: expected nullable type, found '%i32'");1721 ".tmp_source.zig:2:15: error: expected nullable type, found '%i32'");
17211722
...@@ -1723,7 +1724,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1723,7 +1724,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
1723 \\export fn foo() {1724 \\export fn foo() {
1724 \\ while (bar()) |x| {} else |err| {}1725 \\ while (bar()) |x| {} else |err| {}
1725 \\}1726 \\}
1726 \\fn bar() -> bool { true }1727 \\fn bar() -> bool { return true; }
1727 ,1728 ,
1728 ".tmp_source.zig:2:15: error: expected error union type, found 'bool'");1729 ".tmp_source.zig:2:15: error: expected error union type, found 'bool'");
17291730
...@@ -1731,7 +1732,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1731,7 +1732,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
1731 \\export fn foo() {1732 \\export fn foo() {
1732 \\ while (bar()) |x| {} else |err| {}1733 \\ while (bar()) |x| {} else |err| {}
1733 \\}1734 \\}
1734 \\fn bar() -> ?i32 { 1 }1735 \\fn bar() -> ?i32 { return 1; }
1735 ,1736 ,
1736 ".tmp_source.zig:2:15: error: expected error union type, found '?i32'");1737 ".tmp_source.zig:2:15: error: expected error union type, found '?i32'");
17371738
...@@ -1762,17 +1763,17 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1762,17 +1763,17 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
17621763
1763 cases.add("signed integer division",1764 cases.add("signed integer division",
1764 \\export fn foo(a: i32, b: i32) -> i32 {1765 \\export fn foo(a: i32, b: i32) -> i32 {
1765 \\ a / b1766 \\ return a / b;
1766 \\}1767 \\}
1767 ,1768 ,
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
1770 cases.add("signed integer remainder division",1771 cases.add("signed integer remainder division",
1771 \\export fn foo(a: i32, b: i32) -> i32 {1772 \\export fn foo(a: i32, b: i32) -> i32 {
1772 \\ a % b1773 \\ return a % b;
1773 \\}1774 \\}
1774 ,1775 ,
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
1777 cases.add("cast negative value to unsigned integer",1778 cases.add("cast negative value to unsigned integer",
1778 \\comptime {1779 \\comptime {
...@@ -1922,17 +1923,17 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1922,17 +1923,17 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
19221923
1923 cases.add("explicit cast float literal to integer when there is a fraction component",1924 cases.add("explicit cast float literal to integer when there is a fraction component",
1924 \\export fn entry() -> i32 {1925 \\export fn entry() -> i32 {
1925 \\ i32(12.34)1926 \\ return i32(12.34);
1926 \\}1927 \\}
1927 ,1928 ,
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
1930 cases.add("non pointer given to @ptrToInt",1931 cases.add("non pointer given to @ptrToInt",
1931 \\export fn entry(x: i32) -> usize {1932 \\export fn entry(x: i32) -> usize {
1932 \\ @ptrToInt(x)1933 \\ return @ptrToInt(x);
1933 \\}1934 \\}
1934 ,1935 ,
1935 ".tmp_source.zig:2:15: error: expected pointer, found 'i32'");1936 ".tmp_source.zig:2:22: error: expected pointer, found 'i32'");
19361937
1937 cases.add("@shlExact shifts out 1 bits",1938 cases.add("@shlExact shifts out 1 bits",
1938 \\comptime {1939 \\comptime {
...@@ -2028,7 +2029,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -2028,7 +2029,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
20282029
2029 cases.add("@alignCast expects pointer or slice",2030 cases.add("@alignCast expects pointer or slice",
2030 \\export fn entry() {2031 \\export fn entry() {
2031 \\ @alignCast(4, u32(3))2032 \\ @alignCast(4, u32(3));
2032 \\}2033 \\}
2033 ,2034 ,
2034 ".tmp_source.zig:2:22: error: expected pointer or slice, found 'u32'");2035 ".tmp_source.zig:2:22: error: expected pointer or slice, found 'u32'");
...@@ -2040,7 +2041,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -2040,7 +2041,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
2040 \\fn testImplicitlyDecreaseFnAlign(ptr: fn () align(8) -> i32, answer: i32) {2041 \\fn testImplicitlyDecreaseFnAlign(ptr: fn () align(8) -> i32, answer: i32) {
2041 \\ if (ptr() != answer) unreachable;2042 \\ if (ptr() != answer) unreachable;
2042 \\}2043 \\}
2043 \\fn alignedSmall() align(4) -> i32 { 1234 }2044 \\fn alignedSmall() align(4) -> i32 { return 1234; }
2044 ,2045 ,
2045 ".tmp_source.zig:2:35: error: expected type 'fn() align(8) -> i32', found 'fn() align(4) -> i32'");2046 ".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) {...@@ -2206,17 +2207,17 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
2206 \\const Mode = @import("builtin").Mode;2207 \\const Mode = @import("builtin").Mode;
2207 \\2208 \\
2208 \\fn Free(comptime filename: []const u8) -> TestCase {2209 \\fn Free(comptime filename: []const u8) -> TestCase {
2209 \\ TestCase {2210 \\ return TestCase {
2210 \\ .filename = filename,2211 \\ .filename = filename,
2211 \\ .problem_type = ProblemType.Free,2212 \\ .problem_type = ProblemType.Free,
2212 \\ }2213 \\ };
2213 \\}2214 \\}
2214 \\2215 \\
2215 \\fn LibC(comptime filename: []const u8) -> TestCase {2216 \\fn LibC(comptime filename: []const u8) -> TestCase {
2216 \\ TestCase {2217 \\ return TestCase {
2217 \\ .filename = filename,2218 \\ .filename = filename,
2218 \\ .problem_type = ProblemType.LinkLibC,2219 \\ .problem_type = ProblemType.LinkLibC,
2219 \\ }2220 \\ };
2220 \\}2221 \\}
2221 \\2222 \\
2222 \\const TestCase = struct {2223 \\const TestCase = struct {
...@@ -2374,9 +2375,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -2374,9 +2375,9 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
2374 \\pub fn MemoryPool(comptime T: type) -> type {2375 \\pub fn MemoryPool(comptime T: type) -> type {
2375 \\ const free_list_t = @compileError("aoeu");2376 \\ const free_list_t = @compileError("aoeu");
2376 \\2377 \\
2377 \\ struct {2378 \\ return struct {
2378 \\ free_list: free_list_t,2379 \\ free_list: free_list_t,
2379 \\ }2380 \\ };
2380 \\}2381 \\}
2381 \\2382 \\
2382 \\export fn entry() {2383 \\export fn entry() {
...@@ -2651,7 +2652,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -2651,7 +2652,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
2651 \\ C: bool,2652 \\ C: bool,
2652 \\};2653 \\};
2653 \\export fn entry() {2654 \\export fn entry() {
2654 \\ var a = Payload { .A = { 1234 } };2655 \\ var a = Payload { .A = 1234 };
2655 \\}2656 \\}
2656 ,2657 ,
2657 ".tmp_source.zig:6:29: error: extern union does not support enum tag type");2658 ".tmp_source.zig:6:29: error: extern union does not support enum tag type");
...@@ -2668,7 +2669,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -2668,7 +2669,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
2668 \\ C: bool,2669 \\ C: bool,
2669 \\};2670 \\};
2670 \\export fn entry() {2671 \\export fn entry() {
2671 \\ var a = Payload { .A = { 1234 } };2672 \\ var a = Payload { .A = 1234 };
2672 \\}2673 \\}
2673 ,2674 ,
2674 ".tmp_source.zig:6:29: error: packed union does not support enum tag type");2675 ".tmp_source.zig:6:29: error: packed union does not support enum tag type");
...@@ -2680,7 +2681,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -2680,7 +2681,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
2680 \\ C: bool,2681 \\ C: bool,
2681 \\};2682 \\};
2682 \\export fn entry() {2683 \\export fn entry() {
2683 \\ const a = Payload { .A = { 1234 } };2684 \\ const a = Payload { .A = 1234 };
2684 \\ foo(a);2685 \\ foo(a);
2685 \\}2686 \\}
2686 \\fn foo(a: &const Payload) {2687 \\fn foo(a: &const Payload) {
test/debug_safety.zig+15-15
...@@ -19,7 +19,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {...@@ -19,7 +19,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
19 \\ baz(bar(a));19 \\ baz(bar(a));
20 \\}20 \\}
21 \\fn bar(a: []const i32) -> i32 {21 \\fn bar(a: []const i32) -> i32 {
22 \\ a[4]22 \\ return a[4];
23 \\}23 \\}
24 \\fn baz(a: i32) { }24 \\fn baz(a: i32) { }
25 );25 );
...@@ -34,7 +34,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {...@@ -34,7 +34,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
34 \\ if (x == 0) return error.Whatever;34 \\ if (x == 0) return error.Whatever;
35 \\}35 \\}
36 \\fn add(a: u16, b: u16) -> u16 {36 \\fn add(a: u16, b: u16) -> u16 {
37 \\ a + b37 \\ return a + b;
38 \\}38 \\}
39 );39 );
4040
...@@ -48,7 +48,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {...@@ -48,7 +48,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
48 \\ if (x == 0) return error.Whatever;48 \\ if (x == 0) return error.Whatever;
49 \\}49 \\}
50 \\fn sub(a: u16, b: u16) -> u16 {50 \\fn sub(a: u16, b: u16) -> u16 {
51 \\ a - b51 \\ return a - b;
52 \\}52 \\}
53 );53 );
5454
...@@ -62,7 +62,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {...@@ -62,7 +62,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
62 \\ if (x == 0) return error.Whatever;62 \\ if (x == 0) return error.Whatever;
63 \\}63 \\}
64 \\fn mul(a: u16, b: u16) -> u16 {64 \\fn mul(a: u16, b: u16) -> u16 {
65 \\ a * b65 \\ return a * b;
66 \\}66 \\}
67 );67 );
6868
...@@ -76,7 +76,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {...@@ -76,7 +76,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
76 \\ if (x == 32767) return error.Whatever;76 \\ if (x == 32767) return error.Whatever;
77 \\}77 \\}
78 \\fn neg(a: i16) -> i16 {78 \\fn neg(a: i16) -> i16 {
79 \\ -a79 \\ return -a;
80 \\}80 \\}
81 );81 );
8282
...@@ -90,7 +90,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {...@@ -90,7 +90,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
90 \\ if (x == 32767) return error.Whatever;90 \\ if (x == 32767) return error.Whatever;
91 \\}91 \\}
92 \\fn div(a: i16, b: i16) -> i16 {92 \\fn div(a: i16, b: i16) -> i16 {
93 \\ @divTrunc(a, b)93 \\ return @divTrunc(a, b);
94 \\}94 \\}
95 );95 );
9696
...@@ -104,7 +104,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {...@@ -104,7 +104,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
104 \\ if (x == 0) return error.Whatever;104 \\ if (x == 0) return error.Whatever;
105 \\}105 \\}
106 \\fn shl(a: i16, b: u4) -> i16 {106 \\fn shl(a: i16, b: u4) -> i16 {
107 \\ @shlExact(a, b)107 \\ return @shlExact(a, b);
108 \\}108 \\}
109 );109 );
110110
...@@ -118,7 +118,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {...@@ -118,7 +118,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
118 \\ if (x == 0) return error.Whatever;118 \\ if (x == 0) return error.Whatever;
119 \\}119 \\}
120 \\fn shl(a: u16, b: u4) -> u16 {120 \\fn shl(a: u16, b: u4) -> u16 {
121 \\ @shlExact(a, b)121 \\ return @shlExact(a, b);
122 \\}122 \\}
123 );123 );
124124
...@@ -132,7 +132,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {...@@ -132,7 +132,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
132 \\ if (x == 0) return error.Whatever;132 \\ if (x == 0) return error.Whatever;
133 \\}133 \\}
134 \\fn shr(a: i16, b: u4) -> i16 {134 \\fn shr(a: i16, b: u4) -> i16 {
135 \\ @shrExact(a, b)135 \\ return @shrExact(a, b);
136 \\}136 \\}
137 );137 );
138138
...@@ -146,7 +146,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {...@@ -146,7 +146,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
146 \\ if (x == 0) return error.Whatever;146 \\ if (x == 0) return error.Whatever;
147 \\}147 \\}
148 \\fn shr(a: u16, b: u4) -> u16 {148 \\fn shr(a: u16, b: u4) -> u16 {
149 \\ @shrExact(a, b)149 \\ return @shrExact(a, b);
150 \\}150 \\}
151 );151 );
152152
...@@ -159,7 +159,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {...@@ -159,7 +159,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
159 \\ const x = div0(999, 0);159 \\ const x = div0(999, 0);
160 \\}160 \\}
161 \\fn div0(a: i32, b: i32) -> i32 {161 \\fn div0(a: i32, b: i32) -> i32 {
162 \\ @divTrunc(a, b)162 \\ return @divTrunc(a, b);
163 \\}163 \\}
164 );164 );
165165
...@@ -173,7 +173,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {...@@ -173,7 +173,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
173 \\ if (x == 0) return error.Whatever;173 \\ if (x == 0) return error.Whatever;
174 \\}174 \\}
175 \\fn divExact(a: i32, b: i32) -> i32 {175 \\fn divExact(a: i32, b: i32) -> i32 {
176 \\ @divExact(a, b)176 \\ return @divExact(a, b);
177 \\}177 \\}
178 );178 );
179179
...@@ -187,7 +187,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {...@@ -187,7 +187,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
187 \\ if (x.len == 0) return error.Whatever;187 \\ if (x.len == 0) return error.Whatever;
188 \\}188 \\}
189 \\fn widenSlice(slice: []align(1) const u8) -> []align(1) const i32 {189 \\fn widenSlice(slice: []align(1) const u8) -> []align(1) const i32 {
190 \\ ([]align(1) const i32)(slice)190 \\ return ([]align(1) const i32)(slice);
191 \\}191 \\}
192 );192 );
193193
...@@ -201,7 +201,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {...@@ -201,7 +201,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
201 \\ if (x == 0) return error.Whatever;201 \\ if (x == 0) return error.Whatever;
202 \\}202 \\}
203 \\fn shorten_cast(x: i32) -> i8 {203 \\fn shorten_cast(x: i32) -> i8 {
204 \\ i8(x)204 \\ return i8(x);
205 \\}205 \\}
206 );206 );
207207
...@@ -215,7 +215,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {...@@ -215,7 +215,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
215 \\ if (x == 0) return error.Whatever;215 \\ if (x == 0) return error.Whatever;
216 \\}216 \\}
217 \\fn unsigned_cast(x: i32) -> u32 {217 \\fn unsigned_cast(x: i32) -> u32 {
218 \\ u32(x)218 \\ return u32(x);
219 \\}219 \\}
220 );220 );
221221
test/standalone/pkg_import/pkg.zig+1-1
...@@ -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 {...@@ -284,7 +284,7 @@ pub const CompareOutputContext = struct {
284 warn("Process {} terminated unexpectedly\n", full_exe_path);284 warn("Process {} terminated unexpectedly\n", full_exe_path);
285 return error.TestFailed;285 return error.TestFailed;
286 },286 },
287 };287 }
288288
289289
290 if (!mem.eql(u8, self.expected_output, stdout.toSliceConst())) {290 if (!mem.eql(u8, self.expected_output, stdout.toSliceConst())) {
...@@ -615,7 +615,7 @@ pub const CompileErrorContext = struct {...@@ -615,7 +615,7 @@ pub const CompileErrorContext = struct {
615 warn("Process {} terminated unexpectedly\n", b.zig_exe);615 warn("Process {} terminated unexpectedly\n", b.zig_exe);
616 return error.TestFailed;616 return error.TestFailed;
617 },617 },
618 };618 }
619619
620620
621 const stdout = stdout_buf.toSliceConst();621 const stdout = stdout_buf.toSliceConst();
...@@ -891,7 +891,7 @@ pub const TranslateCContext = struct {...@@ -891,7 +891,7 @@ pub const TranslateCContext = struct {
891 warn("Compilation terminated unexpectedly\n");891 warn("Compilation terminated unexpectedly\n");
892 return error.TestFailed;892 return error.TestFailed;
893 },893 },
894 };894 }
895895
896 const stdout = stdout_buf.toSliceConst();896 const stdout = stdout_buf.toSliceConst();
897 const stderr = stderr_buf.toSliceConst();897 const stderr = stderr_buf.toSliceConst();
test/translate_c.zig+55-55
...@@ -203,13 +203,13 @@ pub fn addCases(cases: &tests.TranslateCContext) {...@@ -203,13 +203,13 @@ pub fn addCases(cases: &tests.TranslateCContext) {
203 \\pub extern var fn_ptr: ?extern fn();203 \\pub extern var fn_ptr: ?extern fn();
204 ,204 ,
205 \\pub inline fn foo() {205 \\pub inline fn foo() {
206 \\ (??fn_ptr)()206 \\ return (??fn_ptr)();
207 \\}207 \\}
208 ,208 ,
209 \\pub extern var fn_ptr2: ?extern fn(c_int, f32) -> u8;209 \\pub extern var fn_ptr2: ?extern fn(c_int, f32) -> u8;
210 ,210 ,
211 \\pub inline fn bar(arg0: c_int, arg1: f32) -> u8 {211 \\pub inline fn bar(arg0: c_int, arg1: f32) -> u8 {
212 \\ (??fn_ptr2)(arg0, arg1)212 \\ return (??fn_ptr2)(arg0, arg1);
213 \\}213 \\}
214 );214 );
215215
...@@ -475,10 +475,10 @@ pub fn addCases(cases: &tests.TranslateCContext) {...@@ -475,10 +475,10 @@ pub fn addCases(cases: &tests.TranslateCContext) {
475 \\pub export fn max(a: c_int) {475 \\pub export fn max(a: c_int) {
476 \\ var b: c_int;476 \\ var b: c_int;
477 \\ var c: c_int;477 \\ var c: c_int;
478 \\ c = {478 \\ c = x: {
479 \\ const _tmp = a;479 \\ const _tmp = a;
480 \\ b = _tmp;480 \\ b = _tmp;
481 \\ _tmp481 \\ break :x _tmp;
482 \\ };482 \\ };
483 \\}483 \\}
484 );484 );
...@@ -613,9 +613,9 @@ pub fn addCases(cases: &tests.TranslateCContext) {...@@ -613,9 +613,9 @@ pub fn addCases(cases: &tests.TranslateCContext) {
613 \\}613 \\}
614 ,614 ,
615 \\pub export fn foo() -> c_int {615 \\pub export fn foo() -> c_int {
616 \\ return {616 \\ return x: {
617 \\ _ = 1;617 \\ _ = 1;
618 \\ 2618 \\ break :x 2;
619 \\ };619 \\ };
620 \\}620 \\}
621 );621 );
...@@ -645,45 +645,45 @@ pub fn addCases(cases: &tests.TranslateCContext) {...@@ -645,45 +645,45 @@ pub fn addCases(cases: &tests.TranslateCContext) {
645 ,645 ,
646 \\pub export fn foo() {646 \\pub export fn foo() {
647 \\ var a: c_int = 0;647 \\ var a: c_int = 0;
648 \\ a += {648 \\ a += x: {
649 \\ const _ref = &a;649 \\ const _ref = &a;
650 \\ (*_ref) = ((*_ref) + 1);650 \\ (*_ref) = ((*_ref) + 1);
651 \\ *_ref651 \\ break :x *_ref;
652 \\ };652 \\ };
653 \\ a -= {653 \\ a -= x: {
654 \\ const _ref = &a;654 \\ const _ref = &a;
655 \\ (*_ref) = ((*_ref) - 1);655 \\ (*_ref) = ((*_ref) - 1);
656 \\ *_ref656 \\ break :x *_ref;
657 \\ };657 \\ };
658 \\ a *= {658 \\ a *= x: {
659 \\ const _ref = &a;659 \\ const _ref = &a;
660 \\ (*_ref) = ((*_ref) * 1);660 \\ (*_ref) = ((*_ref) * 1);
661 \\ *_ref661 \\ break :x *_ref;
662 \\ };662 \\ };
663 \\ a &= {663 \\ a &= x: {
664 \\ const _ref = &a;664 \\ const _ref = &a;
665 \\ (*_ref) = ((*_ref) & 1);665 \\ (*_ref) = ((*_ref) & 1);
666 \\ *_ref666 \\ break :x *_ref;
667 \\ };667 \\ };
668 \\ a |= {668 \\ a |= x: {
669 \\ const _ref = &a;669 \\ const _ref = &a;
670 \\ (*_ref) = ((*_ref) | 1);670 \\ (*_ref) = ((*_ref) | 1);
671 \\ *_ref671 \\ break :x *_ref;
672 \\ };672 \\ };
673 \\ a ^= {673 \\ a ^= x: {
674 \\ const _ref = &a;674 \\ const _ref = &a;
675 \\ (*_ref) = ((*_ref) ^ 1);675 \\ (*_ref) = ((*_ref) ^ 1);
676 \\ *_ref676 \\ break :x *_ref;
677 \\ };677 \\ };
678 \\ a >>= @import("std").math.Log2Int(c_int)({678 \\ a >>= @import("std").math.Log2Int(c_int)(x: {
679 \\ const _ref = &a;679 \\ const _ref = &a;
680 \\ (*_ref) = ((*_ref) >> @import("std").math.Log2Int(c_int)(1));680 \\ (*_ref) = ((*_ref) >> @import("std").math.Log2Int(c_int)(1));
681 \\ *_ref681 \\ break :x *_ref;
682 \\ });682 \\ });
683 \\ a <<= @import("std").math.Log2Int(c_int)({683 \\ a <<= @import("std").math.Log2Int(c_int)(x: {
684 \\ const _ref = &a;684 \\ const _ref = &a;
685 \\ (*_ref) = ((*_ref) << @import("std").math.Log2Int(c_int)(1));685 \\ (*_ref) = ((*_ref) << @import("std").math.Log2Int(c_int)(1));
686 \\ *_ref686 \\ break :x *_ref;
687 \\ });687 \\ });
688 \\}688 \\}
689 );689 );
...@@ -703,45 +703,45 @@ pub fn addCases(cases: &tests.TranslateCContext) {...@@ -703,45 +703,45 @@ pub fn addCases(cases: &tests.TranslateCContext) {
703 ,703 ,
704 \\pub export fn foo() {704 \\pub export fn foo() {
705 \\ var a: c_uint = c_uint(0);705 \\ var a: c_uint = c_uint(0);
706 \\ a +%= {706 \\ a +%= x: {
707 \\ const _ref = &a;707 \\ const _ref = &a;
708 \\ (*_ref) = ((*_ref) +% c_uint(1));708 \\ (*_ref) = ((*_ref) +% c_uint(1));
709 \\ *_ref709 \\ break :x *_ref;
710 \\ };710 \\ };
711 \\ a -%= {711 \\ a -%= x: {
712 \\ const _ref = &a;712 \\ const _ref = &a;
713 \\ (*_ref) = ((*_ref) -% c_uint(1));713 \\ (*_ref) = ((*_ref) -% c_uint(1));
714 \\ *_ref714 \\ break :x *_ref;
715 \\ };715 \\ };
716 \\ a *%= {716 \\ a *%= x: {
717 \\ const _ref = &a;717 \\ const _ref = &a;
718 \\ (*_ref) = ((*_ref) *% c_uint(1));718 \\ (*_ref) = ((*_ref) *% c_uint(1));
719 \\ *_ref719 \\ break :x *_ref;
720 \\ };720 \\ };
721 \\ a &= {721 \\ a &= x: {
722 \\ const _ref = &a;722 \\ const _ref = &a;
723 \\ (*_ref) = ((*_ref) & c_uint(1));723 \\ (*_ref) = ((*_ref) & c_uint(1));
724 \\ *_ref724 \\ break :x *_ref;
725 \\ };725 \\ };
726 \\ a |= {726 \\ a |= x: {
727 \\ const _ref = &a;727 \\ const _ref = &a;
728 \\ (*_ref) = ((*_ref) | c_uint(1));728 \\ (*_ref) = ((*_ref) | c_uint(1));
729 \\ *_ref729 \\ break :x *_ref;
730 \\ };730 \\ };
731 \\ a ^= {731 \\ a ^= x: {
732 \\ const _ref = &a;732 \\ const _ref = &a;
733 \\ (*_ref) = ((*_ref) ^ c_uint(1));733 \\ (*_ref) = ((*_ref) ^ c_uint(1));
734 \\ *_ref734 \\ break :x *_ref;
735 \\ };735 \\ };
736 \\ a >>= @import("std").math.Log2Int(c_uint)({736 \\ a >>= @import("std").math.Log2Int(c_uint)(x: {
737 \\ const _ref = &a;737 \\ const _ref = &a;
738 \\ (*_ref) = ((*_ref) >> @import("std").math.Log2Int(c_uint)(1));738 \\ (*_ref) = ((*_ref) >> @import("std").math.Log2Int(c_uint)(1));
739 \\ *_ref739 \\ break :x *_ref;
740 \\ });740 \\ });
741 \\ a <<= @import("std").math.Log2Int(c_uint)({741 \\ a <<= @import("std").math.Log2Int(c_uint)(x: {
742 \\ const _ref = &a;742 \\ const _ref = &a;
743 \\ (*_ref) = ((*_ref) << @import("std").math.Log2Int(c_uint)(1));743 \\ (*_ref) = ((*_ref) << @import("std").math.Log2Int(c_uint)(1));
744 \\ *_ref744 \\ break :x *_ref;
745 \\ });745 \\ });
746 \\}746 \\}
747 );747 );
...@@ -778,29 +778,29 @@ pub fn addCases(cases: &tests.TranslateCContext) {...@@ -778,29 +778,29 @@ pub fn addCases(cases: &tests.TranslateCContext) {
778 \\ i -= 1;778 \\ i -= 1;
779 \\ u +%= 1;779 \\ u +%= 1;
780 \\ u -%= 1;780 \\ u -%= 1;
781 \\ i = {781 \\ i = x: {
782 \\ const _ref = &i;782 \\ const _ref = &i;
783 \\ const _tmp = *_ref;783 \\ const _tmp = *_ref;
784 \\ (*_ref) += 1;784 \\ (*_ref) += 1;
785 \\ _tmp785 \\ break :x _tmp;
786 \\ };786 \\ };
787 \\ i = {787 \\ i = x: {
788 \\ const _ref = &i;788 \\ const _ref = &i;
789 \\ const _tmp = *_ref;789 \\ const _tmp = *_ref;
790 \\ (*_ref) -= 1;790 \\ (*_ref) -= 1;
791 \\ _tmp791 \\ break :x _tmp;
792 \\ };792 \\ };
793 \\ u = {793 \\ u = x: {
794 \\ const _ref = &u;794 \\ const _ref = &u;
795 \\ const _tmp = *_ref;795 \\ const _tmp = *_ref;
796 \\ (*_ref) +%= 1;796 \\ (*_ref) +%= 1;
797 \\ _tmp797 \\ break :x _tmp;
798 \\ };798 \\ };
799 \\ u = {799 \\ u = x: {
800 \\ const _ref = &u;800 \\ const _ref = &u;
801 \\ const _tmp = *_ref;801 \\ const _tmp = *_ref;
802 \\ (*_ref) -%= 1;802 \\ (*_ref) -%= 1;
803 \\ _tmp803 \\ break :x _tmp;
804 \\ };804 \\ };
805 \\}805 \\}
806 );806 );
...@@ -826,25 +826,25 @@ pub fn addCases(cases: &tests.TranslateCContext) {...@@ -826,25 +826,25 @@ pub fn addCases(cases: &tests.TranslateCContext) {
826 \\ i -= 1;826 \\ i -= 1;
827 \\ u +%= 1;827 \\ u +%= 1;
828 \\ u -%= 1;828 \\ u -%= 1;
829 \\ i = {829 \\ i = x: {
830 \\ const _ref = &i;830 \\ const _ref = &i;
831 \\ (*_ref) += 1;831 \\ (*_ref) += 1;
832 \\ *_ref832 \\ break :x *_ref;
833 \\ };833 \\ };
834 \\ i = {834 \\ i = x: {
835 \\ const _ref = &i;835 \\ const _ref = &i;
836 \\ (*_ref) -= 1;836 \\ (*_ref) -= 1;
837 \\ *_ref837 \\ break :x *_ref;
838 \\ };838 \\ };
839 \\ u = {839 \\ u = x: {
840 \\ const _ref = &u;840 \\ const _ref = &u;
841 \\ (*_ref) +%= 1;841 \\ (*_ref) +%= 1;
842 \\ *_ref842 \\ break :x *_ref;
843 \\ };843 \\ };
844 \\ u = {844 \\ u = x: {
845 \\ const _ref = &u;845 \\ const _ref = &u;
846 \\ (*_ref) -%= 1;846 \\ (*_ref) -%= 1;
847 \\ *_ref847 \\ break :x *_ref;
848 \\ };848 \\ };
849 \\}849 \\}
850 );850 );
...@@ -1037,7 +1037,7 @@ pub fn addCases(cases: &tests.TranslateCContext) {...@@ -1037,7 +1037,7 @@ pub fn addCases(cases: &tests.TranslateCContext) {
1037 \\pub const glClearPFN = PFNGLCLEARPROC;1037 \\pub const glClearPFN = PFNGLCLEARPROC;
1038 ,1038 ,
1039 \\pub inline fn glClearUnion(arg0: GLbitfield) {1039 \\pub inline fn glClearUnion(arg0: GLbitfield) {
1040 \\ (??glProcs.gl.Clear)(arg0)1040 \\ return (??glProcs.gl.Clear)(arg0);
1041 \\}1041 \\}
1042 ,1042 ,
1043 \\pub const OpenGLProcs = union_OpenGLProcs;1043 \\pub const OpenGLProcs = union_OpenGLProcs;