authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-12-31 17:10:29-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-12-31 17:10:29-05:00
log69132bdeda9f9ee672d883fd442b6158d8725422
tree29b1bfd8acbab82442f83bbad2d06d0eea0d7f35
parent5f89393acb0e3626d942302ca24de14349850040

IR: progress toward compiling standard library

* comptime fn call * is_comptime doesn't count as an instruction dependency * update more std code to latest zig

18 files changed, 101 insertions(+), 81 deletions(-)

doc/langref.md+1-1
......@@ -123,7 +123,7 @@ MultiplyOperator = "*" | "/" | "%" | "**" | "*%"
123123
124124PrefixOpExpression = PrefixOp PrefixOpExpression | SuffixOpExpression
125125
126SuffixOpExpression = PrimaryExpression option(FnCallExpression | ArrayAccessExpression | FieldAccessExpression | SliceExpression)
126SuffixOpExpression = option("inline") PrimaryExpression option(FnCallExpression | ArrayAccessExpression | FieldAccessExpression | SliceExpression)
127127
128128FieldAccessExpression = "." Symbol
129129
src/all_types.hpp+2-1
......@@ -445,6 +445,7 @@ struct AstNodeFnCallExpr {
445445 AstNode *fn_ref_expr;
446446 ZigList<AstNode *> params;
447447 bool is_builtin;
448 bool is_comptime;
448449};
449450
450451struct AstNodeArrayAccessExpr {
......@@ -1669,7 +1670,7 @@ struct IrInstructionCall {
16691670 FnTableEntry *fn_entry;
16701671 size_t arg_count;
16711672 IrInstruction **args;
1672 bool is_inline;
1673 bool is_comptime;
16731674 LLVMValueRef tmp_ptr;
16741675};
16751676
src/ir.cpp+26-17
......@@ -808,13 +808,15 @@ static IrInstruction *ir_build_enum_field_ptr_from(IrBuilder *irb, IrInstruction
808808}
809809
810810static IrInstruction *ir_build_call(IrBuilder *irb, Scope *scope, AstNode *source_node,
811 FnTableEntry *fn_entry, IrInstruction *fn_ref, size_t arg_count, IrInstruction **args)
811 FnTableEntry *fn_entry, IrInstruction *fn_ref, size_t arg_count, IrInstruction **args,
812 bool is_comptime)
812813{
813814 IrInstructionCall *call_instruction = ir_build_instruction<IrInstructionCall>(irb, scope, source_node);
814815 call_instruction->fn_entry = fn_entry;
815816 call_instruction->fn_ref = fn_ref;
816 call_instruction->arg_count = arg_count;
817 call_instruction->is_comptime = is_comptime;
817818 call_instruction->args = args;
819 call_instruction->arg_count = arg_count;
818820
819821 if (fn_ref)
820822 ir_ref_instruction(fn_ref);
......@@ -825,10 +827,11 @@ static IrInstruction *ir_build_call(IrBuilder *irb, Scope *scope, AstNode *sourc
825827}
826828
827829static IrInstruction *ir_build_call_from(IrBuilder *irb, IrInstruction *old_instruction,
828 FnTableEntry *fn_entry, IrInstruction *fn_ref, size_t arg_count, IrInstruction **args)
830 FnTableEntry *fn_entry, IrInstruction *fn_ref, size_t arg_count, IrInstruction **args,
831 bool is_comptime)
829832{
830833 IrInstruction *new_instruction = ir_build_call(irb, old_instruction->scope,
831 old_instruction->source_node, fn_entry, fn_ref, arg_count, args);
834 old_instruction->source_node, fn_entry, fn_ref, arg_count, args, is_comptime);
832835 ir_link_new_instruction(new_instruction, old_instruction);
833836 return new_instruction;
834837}
......@@ -1950,16 +1953,12 @@ static IrInstruction *ir_build_int_to_enum(IrBuilder *irb, Scope *scope, AstNode
19501953}
19511954
19521955static IrInstruction *ir_instruction_br_get_dep(IrInstructionBr *instruction, size_t index) {
1953 switch (index) {
1954 case 0: return instruction->is_comptime;
1955 default: return nullptr;
1956 }
1956 return nullptr;
19571957}
19581958
19591959static IrInstruction *ir_instruction_condbr_get_dep(IrInstructionCondBr *instruction, size_t index) {
19601960 switch (index) {
19611961 case 0: return instruction->condition;
1962 case 1: return instruction->is_comptime;
19631962 default: return nullptr;
19641963 }
19651964}
......@@ -1967,7 +1966,6 @@ static IrInstruction *ir_instruction_condbr_get_dep(IrInstructionCondBr *instruc
19671966static IrInstruction *ir_instruction_switchbr_get_dep(IrInstructionSwitchBr *instruction, size_t index) {
19681967 switch (index) {
19691968 case 0: return instruction->target_value;
1970 case 1: return instruction->is_comptime;
19711969 }
19721970 size_t case_index = index - 2;
19731971 if (case_index < instruction->case_count) return instruction->cases[case_index].value;
......@@ -3887,7 +3885,8 @@ static IrInstruction *ir_gen_fn_call(IrBuilder *irb, Scope *scope, AstNode *node
38873885 args[i] = ir_gen_node(irb, arg_node, scope);
38883886 }
38893887
3890 return ir_build_call(irb, scope, node, nullptr, fn_ref, arg_count, args);
3888 bool is_comptime = node->data.fn_call_expr.is_comptime;
3889 return ir_build_call(irb, scope, node, nullptr, fn_ref, arg_count, args, is_comptime);
38913890}
38923891
38933892static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, Scope *scope, AstNode *node) {
......@@ -5601,6 +5600,8 @@ static IrBasicBlock *ir_get_new_bb(IrAnalyze *ira, IrBasicBlock *old_bb) {
56015600 IrInstruction *dep_instruction = ir_instruction_get_dep(instruction, dep_i);
56025601 if (dep_instruction == nullptr)
56035602 break;
5603 if (dep_instruction->owner_bb == old_bb)
5604 continue;
56045605 ir_get_new_bb(ira, dep_instruction->owner_bb);
56055606 }
56065607 }
......@@ -6537,6 +6538,14 @@ static bool ir_resolve_bool(IrAnalyze *ira, IrInstruction *value, bool *out) {
65376538 return true;
65386539}
65396540
6541static bool ir_resolve_comptime(IrAnalyze *ira, IrInstruction *value, bool *out) {
6542 if (!value) {
6543 *out = false;
6544 return true;
6545 }
6546 return ir_resolve_bool(ira, value, out);
6547}
6548
65406549static bool ir_resolve_atomic_order(IrAnalyze *ira, IrInstruction *value, AtomicOrder *out) {
65416550 if (value->value.type->id == TypeTableEntryIdInvalid)
65426551 return false;
......@@ -7521,7 +7530,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
75217530
75227531 size_t impl_param_count = impl_fn->type_entry->data.fn.fn_type_id.param_count;
75237532 IrInstruction *new_call_instruction = ir_build_call_from(&ira->new_irb, &call_instruction->base,
7524 impl_fn, nullptr, impl_param_count, casted_args);
7533 impl_fn, nullptr, impl_param_count, casted_args, false);
75257534
75267535 TypeTableEntry *return_type = impl_fn->type_entry->data.fn.fn_type_id.return_type;
75277536 ir_add_alloca(ira, new_call_instruction, return_type);
......@@ -7574,7 +7583,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
75747583 return ira->codegen->builtin_types.entry_invalid;
75757584
75767585 IrInstruction *new_call_instruction = ir_build_call_from(&ira->new_irb, &call_instruction->base,
7577 fn_entry, fn_ref, call_param_count, casted_args);
7586 fn_entry, fn_ref, call_param_count, casted_args, false);
75787587
75797588 ir_add_alloca(ira, new_call_instruction, return_type);
75807589 return ir_finish_anal(ira, return_type);
......@@ -7585,7 +7594,7 @@ static TypeTableEntry *ir_analyze_instruction_call(IrAnalyze *ira, IrInstruction
75857594 if (fn_ref->value.type->id == TypeTableEntryIdInvalid)
75867595 return ira->codegen->builtin_types.entry_invalid;
75877596
7588 bool is_inline = call_instruction->is_inline || ir_should_inline(&ira->new_irb);
7597 bool is_inline = call_instruction->is_comptime || ir_should_inline(&ira->new_irb);
75897598
75907599 if (is_inline || fn_ref->value.special != ConstValSpecialRuntime) {
75917600 if (fn_ref->value.type->id == TypeTableEntryIdMetaType) {
......@@ -7862,7 +7871,7 @@ static TypeTableEntry *ir_analyze_instruction_br(IrAnalyze *ira, IrInstructionBr
78627871 IrBasicBlock *old_dest_block = br_instruction->dest_block;
78637872
78647873 bool is_comptime;
7865 if (!ir_resolve_bool(ira, br_instruction->is_comptime->other, &is_comptime))
7874 if (!ir_resolve_comptime(ira, br_instruction->is_comptime->other, &is_comptime))
78667875 return ir_unreach_error(ira);
78677876
78687877 if (is_comptime || old_dest_block->ref_count == 1)
......@@ -7879,7 +7888,7 @@ static TypeTableEntry *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstruct
78797888 return ir_unreach_error(ira);
78807889
78817890 bool is_comptime;
7882 if (!ir_resolve_bool(ira, cond_br_instruction->is_comptime->other, &is_comptime))
7891 if (!ir_resolve_comptime(ira, cond_br_instruction->is_comptime->other, &is_comptime))
78837892 return ir_unreach_error(ira);
78847893
78857894 if (is_comptime || instr_is_comptime(condition)) {
......@@ -9129,7 +9138,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_br(IrAnalyze *ira,
91299138 size_t case_count = switch_br_instruction->case_count;
91309139
91319140 bool is_comptime;
9132 if (!ir_resolve_bool(ira, switch_br_instruction->is_comptime->other, &is_comptime))
9141 if (!ir_resolve_comptime(ira, switch_br_instruction->is_comptime->other, &is_comptime))
91339142 return ira->codegen->builtin_types.entry_invalid;
91349143
91359144 if (is_comptime || instr_is_comptime(target_value)) {
src/parser.cpp+16-1
......@@ -837,7 +837,7 @@ static AstNode *ast_parse_curly_suffix_expr(ParseContext *pc, size_t *token_inde
837837}
838838
839839/*
840SuffixOpExpression : PrimaryExpression option(FnCallExpression | ArrayAccessExpression | FieldAccessExpression | SliceExpression)
840SuffixOpExpression = option("inline") PrimaryExpression option(FnCallExpression | ArrayAccessExpression | FieldAccessExpression | SliceExpression)
841841FnCallExpression : token(LParen) list(Expression, token(Comma)) token(RParen)
842842ArrayAccessExpression : token(LBracket) Expression token(RBracket)
843843SliceExpression : token(LBracket) Expression token(Ellipsis) option(Expression) token(RBracket) option(token(Const))
......@@ -845,8 +845,22 @@ FieldAccessExpression : token(Dot) token(Symbol)
845845StructLiteralField : token(Dot) token(Symbol) token(Eq) Expression
846846*/
847847static AstNode *ast_parse_suffix_op_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
848 Token *inline_token = &pc->tokens->at(*token_index);
849 bool is_comptime;
850 if (inline_token->id == TokenIdKeywordInline) {
851 // TODO make it an error if something other than function call has the comptime keyword
852 is_comptime = true;
853 *token_index += 1;
854 } else {
855 is_comptime = false;
856 }
857
858
848859 AstNode *primary_expr = ast_parse_primary_expr(pc, token_index, mandatory);
849860 if (!primary_expr) {
861 if (is_comptime) {
862 *token_index -= 1;
863 }
850864 return nullptr;
851865 }
852866
......@@ -857,6 +871,7 @@ static AstNode *ast_parse_suffix_op_expr(ParseContext *pc, size_t *token_index,
857871
858872 AstNode *node = ast_create_node(pc, NodeTypeFnCallExpr, first_token);
859873 node->data.fn_call_expr.fn_ref_expr = primary_expr;
874 node->data.fn_call_expr.is_comptime = is_comptime;
860875 ast_parse_fn_call_param_list(pc, token_index, &node->data.fn_call_expr.params);
861876
862877 primary_expr = node;
std/compiler_rt.zig+2-2
......@@ -214,7 +214,7 @@
214214//}
215215//
216216//fn test_umoddi3() {
217// @setFnTest(this, true);
217// @setFnTest(this);
218218//
219219// test_one_umoddi3(0, 1, 0);
220220// test_one_umoddi3(2, 1, 0);
......@@ -229,7 +229,7 @@
229229//}
230230//
231231//fn test_udivmoddi4() {
232// @setFnTest(this, true);
232// @setFnTest(this);
233233//
234234// const cases = [][4]du_int {
235235// []du_int{0x0000000000000000, 0x0000000000000001, 0x0000000000000000, 0x0000000000000000},
std/cstr.zig+9-9
......@@ -15,12 +15,12 @@ pub fn len(ptr: &const u8) -> usize {
1515pub fn cmp(a: &const u8, b: &const u8) -> i8 {
1616 var index: usize = 0;
1717 while (a[index] == b[index] && a[index] != 0; index += 1) {}
18 return if (a[index] > b[index]) {
19 1
18 if (a[index] > b[index]) {
19 return 1;
2020 } else if (a[index] < b[index]) {
21 -1
21 return -1;
2222 } else {
23 0
23 return 0;
2424 };
2525}
2626
......@@ -127,7 +127,7 @@ pub const CBuf = struct {
127127};
128128
129129fn testSimpleCBuf() {
130 @setFnTest(this, true);
130 @setFnTest(this);
131131
132132 var buf = %%CBuf.initEmpty(&debug.global_allocator);
133133 assert(buf.len() == 0);
......@@ -148,13 +148,13 @@ fn testSimpleCBuf() {
148148}
149149
150150fn testCompileTimeStrCmp() {
151 @setFnTest(this, true);
151 @setFnTest(this);
152152
153 assert(@constEval(cmp(c"aoeu", c"aoez") == -1));
153 assert(@staticEval(cmp(c"aoeu", c"aoez") == -1));
154154}
155155
156156fn testCompileTimeStrLen() {
157 @setFnTest(this, true);
157 @setFnTest(this);
158158
159 assert(@constEval(len(c"123456789") == 9));
159 assert(@staticEval(len(c"123456789") == 9));
160160}
std/debug.zig+7-7
......@@ -35,7 +35,7 @@ pub fn writeStackTrace(out_stream: &io.OutStream) -> %void {
3535 defer st.self_exe_stream.close() %% {};
3636
3737 %return st.elf.openStream(&global_allocator, &st.self_exe_stream);
38 defer %return st.elf.close();
38 defer st.elf.close();
3939
4040 st.debug_info = (%return st.elf.findSection(".debug_info")) ?? return error.MissingDebugInfo;
4141 st.debug_abbrev = (%return st.elf.findSection(".debug_abbrev")) ?? return error.MissingDebugInfo;
......@@ -154,7 +154,7 @@ const Die = struct {
154154 fn getAttrAddr(self: &const Die, id: u64) -> %u64 {
155155 const form_value = self.getAttr(id) ?? return error.InvalidDebugInfo;
156156 return switch (*form_value) {
157 Address => |value| value,
157 FormValue.Address => |value| value,
158158 else => error.InvalidDebugInfo,
159159 };
160160 }
......@@ -162,7 +162,7 @@ const Die = struct {
162162 fn getAttrUnsignedLe(self: &const Die, id: u64) -> %u64 {
163163 const form_value = self.getAttr(id) ?? return error.InvalidDebugInfo;
164164 return switch (*form_value) {
165 Const => |value| value.asUnsignedLe(),
165 FormValue.Const => |value| value.asUnsignedLe(),
166166 else => error.InvalidDebugInfo,
167167 };
168168 }
......@@ -170,8 +170,8 @@ const Die = struct {
170170 fn getAttrString(self: &const Die, st: &ElfStackTrace, id: u64) -> %[]u8 {
171171 const form_value = self.getAttr(id) ?? return error.InvalidDebugInfo;
172172 return switch (*form_value) {
173 String => |value| value,
174 StrPtr => |offset| getString(st, offset),
173 FormValue.String => |value| value,
174 FormValue.StrPtr => |offset| getString(st, offset),
175175 else => error.InvalidDebugInfo,
176176 }
177177 }
......@@ -406,8 +406,8 @@ fn scanAllCompileUnits(st: &ElfStackTrace) -> %void {
406406
407407 const high_pc_value = compile_unit_die.getAttr(DW.AT_high_pc) ?? return error.MissingDebugInfo;
408408 const pc_end = switch (*high_pc_value) {
409 Address => |value| value,
410 Const => |value| {
409 FormValue.Address => |value| value,
410 FormValue.Const => |value| {
411411 const offset = %return value.asUnsignedLe();
412412 low_pc + offset
413413 },
std/elf.zig+8-4
......@@ -230,9 +230,11 @@ pub const Elf = struct {
230230 }
231231 }
232232
233 pub fn close(elf: &Elf) -> %void {
233 pub fn close(elf: &Elf) {
234234 elf.allocator.free(SectionHeader, elf.section_headers);
235 if (elf.auto_close_stream) %return elf.in_stream.close();
235
236 if (elf.auto_close_stream)
237 elf.in_stream.close();
236238 }
237239
238240 pub fn findSection(elf: &Elf, name: []u8) -> %?&SectionHeader {
......@@ -247,8 +249,10 @@ pub const Elf = struct {
247249 if (target_c == 0 || expected_c != target_c) goto next_section;
248250 }
249251
250 const null_byte = %return elf.in_stream.readByte();
251 if (null_byte == 0) return (?&SectionHeader)(section);
252 {
253 const null_byte = %return elf.in_stream.readByte();
254 if (null_byte == 0) return (?&SectionHeader)(section);
255 }
252256
253257 next_section:
254258 }
std/hash_map.zig+1-1
......@@ -216,7 +216,7 @@ pub fn HashMap(inline K: type, inline V: type, inline hash: fn(key: K)->u32,
216216}
217217
218218fn basicHashMapTest() {
219 @setFnTest(this, true);
219 @setFnTest(this);
220220
221221 var map: HashMap(i32, i32, hash_i32, eql_i32) = undefined;
222222 map.init(&debug.global_allocator);
std/io.zig+12-19
......@@ -137,19 +137,12 @@ pub const OutStream = struct {
137137 }
138138 }
139139
140 pub fn close(self: &OutStream) -> %void {
140 pub fn close(self: &OutStream) {
141141 while (true) {
142142 const close_ret = system.close(self.fd);
143143 const close_err = system.getErrno(close_ret);
144 if (close_err > 0) {
145 return switch (close_err) {
146 errno.EINTR => continue,
147
148 errno.EIO => error.Io,
149 errno.EBADF => error.BadFd,
150 else => error.Unexpected,
151 }
152 }
144 if (close_err > 0 && close_err == errno.EINTR)
145 continue;
153146 return;
154147 }
155148 }
......@@ -163,7 +156,7 @@ pub const InStream = struct {
163156 /// Call close to clean up.
164157 pub fn open(is: &InStream, path: []const u8) -> %void {
165158 switch (@compileVar("os")) {
166 linux, darwin => {
159 Os.linux, Os.darwin => {
167160 while (true) {
168161 const result = system.open(path, system.O_LARGEFILE|system.O_RDONLY, 0);
169162 const err = system.getErrno(result);
......@@ -202,7 +195,7 @@ pub const InStream = struct {
202195 /// you must use the open() function.
203196 pub fn close(is: &InStream) -> %void {
204197 switch (@compileVar("os")) {
205 linux, darwin => {
198 Os.linux, Os.darwin => {
206199 while (true) {
207200 const close_ret = system.close(is.fd);
208201 const close_err = system.getErrno(close_ret);
......@@ -226,7 +219,7 @@ pub const InStream = struct {
226219 /// the stream reached End Of File.
227220 pub fn read(is: &InStream, buf: []u8) -> %usize {
228221 switch (@compileVar("os")) {
229 linux, darwin => {
222 Os.linux, Os.darwin => {
230223 var index: usize = 0;
231224 while (index < buf.len) {
232225 const amt_read = system.read(is.fd, &buf[index], buf.len - index);
......@@ -288,7 +281,7 @@ pub const InStream = struct {
288281
289282 pub fn seekForward(is: &InStream, amount: usize) -> %void {
290283 switch (@compileVar("os")) {
291 linux, darwin => {
284 Os.linux, Os.darwin => {
292285 const result = system.lseek(is.fd, amount, system.SEEK_CUR);
293286 const err = system.getErrno(result);
294287 if (err > 0) {
......@@ -308,7 +301,7 @@ pub const InStream = struct {
308301
309302 pub fn seekTo(is: &InStream, pos: usize) -> %void {
310303 switch (@compileVar("os")) {
311 linux, darwin => {
304 Os.linux, Os.darwin => {
312305 const result = system.lseek(is.fd, pos, system.SEEK_SET);
313306 const err = system.getErrno(result);
314307 if (err > 0) {
......@@ -328,7 +321,7 @@ pub const InStream = struct {
328321
329322 pub fn getPos(is: &InStream) -> %usize {
330323 switch (@compileVar("os")) {
331 linux, darwin => {
324 Os.linux, Os.darwin => {
332325 const result = system.lseek(is.fd, 0, system.SEEK_CUR);
333326 const err = system.getErrno(result);
334327 if (err > 0) {
......@@ -424,7 +417,7 @@ fn bufPrintUnsigned(inline T: type, out_buf: []u8, x: T) -> usize {
424417}
425418
426419fn parseU64DigitTooBig() {
427 @setFnTest(this, true);
420 @setFnTest(this);
428421
429422 parseUnsigned(u64, "123a", 10) %% |err| {
430423 if (err == error.InvalidChar) return;
......@@ -435,10 +428,10 @@ fn parseU64DigitTooBig() {
435428
436429pub fn openSelfExe(stream: &InStream) -> %void {
437430 switch (@compileVar("os")) {
438 linux => {
431 Os.linux => {
439432 %return stream.open("/proc/self/exe");
440433 },
441 darwin => {
434 Os.darwin => {
442435 %%stderr.printf("TODO: openSelfExe on Darwin\n");
443436 os.abort();
444437 },
std/linux.zig+3-3
......@@ -261,7 +261,7 @@ pub fn open_c(path: &const u8, flags: usize, perm: usize) -> usize {
261261}
262262
263263pub fn open(path: []const u8, flags: usize, perm: usize) -> usize {
264 var buf: [path.len + 1]u8 = undefined;
264 const buf = @alloca(u8, path.len + 1);
265265 @memcpy(&buf[0], &path[0], path.len);
266266 buf[path.len] = 0;
267267 return open_c(buf.ptr, flags, perm);
......@@ -272,7 +272,7 @@ pub fn create_c(path: &const u8, perm: usize) -> usize {
272272}
273273
274274pub fn create(path: []const u8, perm: usize) -> usize {
275 var buf: [path.len + 1]u8 = undefined;
275 const buf = @alloca(u8, path.len + 1);
276276 @memcpy(&buf[0], &path[0], path.len);
277277 buf[path.len] = 0;
278278 return create_c(buf.ptr, perm);
......@@ -283,7 +283,7 @@ pub fn openat_c(dirfd: i32, path: &const u8, flags: usize, mode: usize) -> usize
283283}
284284
285285pub fn openat(dirfd: i32, path: []const u8, flags: usize, mode: usize) -> usize {
286 var buf: [path.len + 1]u8 = undefined;
286 const buf = @alloca(u8, path.len + 1);
287287 @memcpy(&buf[0], &path[0], path.len);
288288 buf[path.len] = 0;
289289 return openat_c(dirfd, buf.ptr, flags, mode);
std/list.zig+1-1
......@@ -52,7 +52,7 @@ pub fn List(inline T: type) -> type{
5252}
5353
5454fn basicListTest() {
55 @setFnTest(this, true);
55 @setFnTest(this);
5656
5757 var list = List(i32).init(&debug.global_allocator);
5858 defer list.deinit();
std/mem.zig+1-1
......@@ -83,7 +83,7 @@ pub fn sliceAsInt(buf: []u8, is_be: bool, inline T: type) -> T {
8383}
8484
8585fn testSliceAsInt() {
86 @setFnTest(this, true);
86 @setFnTest(this);
8787 {
8888 const buf = []u8{0x00, 0x00, 0x12, 0x34};
8989 const answer = sliceAsInt(buf[0...], true, u64);
std/net.zig+3-5
......@@ -181,8 +181,6 @@ error JunkAtEnd;
181181error Incomplete;
182182
183183fn parseIp6(buf: []const u8) -> %Address {
184 @setFnStaticEval(this, false);
185
186184 var result: Address = undefined;
187185 result.family = linux.AF_INET6;
188186 result.scope_id = 0;
......@@ -320,7 +318,7 @@ fn parseIp4(buf: []const u8) -> %u32 {
320318
321319
322320fn testParseIp4() {
323 @setFnTest(this, true);
321 @setFnTest(this);
324322
325323 assert(%%parseIp4("127.0.0.1") == endian.swapIfLe(u32, 0x7f000001));
326324 switch (parseIp4("256.0.0.1")) { Overflow => {}, else => @unreachable(), }
......@@ -331,7 +329,7 @@ fn testParseIp4() {
331329}
332330
333331fn testParseIp6() {
334 @setFnTest(this, true);
332 @setFnTest(this);
335333
336334 {
337335 const addr = %%parseIp6("FF01:0:0:0:0:0:0:FB");
......@@ -342,7 +340,7 @@ fn testParseIp6() {
342340}
343341
344342fn testLookupSimpleIp() {
345 @setFnTest(this, true);
343 @setFnTest(this);
346344
347345 {
348346 var addrs_buf: [5]Address = undefined;
std/os.zig+3-3
......@@ -10,8 +10,8 @@ error Unexpected;
1010pub fn getRandomBytes(buf: []u8) -> %void {
1111 while (true) {
1212 const ret = switch (@compileVar("os")) {
13 linux => system.getrandom(buf.ptr, buf.len, 0),
14 darwin => system.getrandom(buf.ptr, buf.len),
13 Os.linux => system.getrandom(buf.ptr, buf.len, 0),
14 Os.darwin => system.getrandom(buf.ptr, buf.len),
1515 else => @compileError("unsupported os"),
1616 };
1717 const err = system.getErrno(ret);
......@@ -29,7 +29,7 @@ pub fn getRandomBytes(buf: []u8) -> %void {
2929
3030pub coldcc fn abort() -> unreachable {
3131 switch (@compileVar("os")) {
32 linux, darwin => {
32 Os.linux, Os.darwin => {
3333 system.raise(system.SIGABRT);
3434 system.raise(system.SIGKILL);
3535 while (true) {}
std/rand.zig+4-4
......@@ -87,7 +87,7 @@ pub const Rand = struct {
8787 } else if (T == f64) {
8888 9007199254740992
8989 } else {
90 @compileError("unknown floating point type" ++ @typeName(T))
90 @compileError("unknown floating point type")
9191 };
9292 return T(r.rangeUnsigned(int_type, 0, precision)) / T(precision);
9393 }
......@@ -156,7 +156,7 @@ fn MersenneTwister(
156156}
157157
158158fn testFloat32() {
159 @setFnTest(this, true);
159 @setFnTest(this);
160160
161161 var r: Rand = undefined;
162162 r.init(42);
......@@ -169,7 +169,7 @@ fn testFloat32() {
169169}
170170
171171fn testMT19937_64() {
172 @setFnTest(this, true);
172 @setFnTest(this);
173173
174174 var rng: MT19937_64 = undefined;
175175 rng.init(rand_test.mt64_seed);
......@@ -179,7 +179,7 @@ fn testMT19937_64() {
179179}
180180
181181fn testMT19937_32() {
182 @setFnTest(this, true);
182 @setFnTest(this);
183183
184184 var rng: MT19937_32 = undefined;
185185 rng.init(rand_test.mt32_seed);
std/str.zig+1-1
......@@ -13,7 +13,7 @@ pub fn sliceEql(inline T: type, a: []const T, b: []const T) -> bool {
1313}
1414
1515fn testStringEquality() {
16 @setFnTest(this, true);
16 @setFnTest(this);
1717
1818 assert(eql("abcd", "abcd"));
1919 assert(!eql("abcdef", "abZdef"));
test/cases/math.zig+1-1
......@@ -167,7 +167,7 @@ const DivResult = struct {
167167fn binaryNot() {
168168 @setFnTest(this);
169169
170 assert(~u16(0b1010101010101010) == 0b0101010101010101);
170 assert(@staticEval(~u16(0b1010101010101010) == 0b0101010101010101));
171171 testBinaryNot(0b1010101010101010);
172172}
173173