authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-03-25 19:25:26-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-03-25 19:25:26-07:00
logb9c5a1fdf59b16b86d33cb52693e84478295b6a3
treea1a16481e05979c250eea9e735356a894d5b29d8
parent399bb2e154395f1f2372eccb10ea41d6ba5ef68f

astgen: fix for loop expressions

also rename the ZIR instruction `deref_node` to `load`.

5 files changed, 119 insertions(+), 131 deletions(-)

BRANCH_TODO+3
......@@ -35,3 +35,6 @@ Performance optimizations to look into:
3535 * enum literals can use small strings
3636 * string literals can use small strings
3737 * don't need the Sema coercion on condbr condition, it's done with result locations
38 * astgen for loops using pointer arithmetic because it's faster and if the programmer
39 wants an index capture, that will just be a convenience variable that zig sets up
40 independently.
src/Sema.zig+15-15
......@@ -160,7 +160,7 @@ pub fn analyzeBody(
160160 .@"const" => try sema.zirConst(block, inst),
161161 .decl_ref => try sema.zirDeclRef(block, inst),
162162 .decl_val => try sema.zirDeclVal(block, inst),
163 .deref_node => try sema.zirDerefNode(block, inst),
163 .load => try sema.zirLoad(block, inst),
164164 .div => try sema.zirArithmetic(block, inst),
165165 .elem_ptr => try sema.zirElemPtr(block, inst),
166166 .elem_ptr_node => try sema.zirElemPtrNode(block, inst),
......@@ -576,7 +576,7 @@ fn zirIndexablePtrLen(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) In
576576 return sema.mod.failWithOwnedErrorMsg(&block.base, msg);
577577 }
578578 const result_ptr = try sema.namedFieldPtr(block, src, array_ptr, "len", src);
579 return sema.analyzeDeref(block, src, result_ptr, result_ptr.src);
579 return sema.analyzeLoad(block, src, result_ptr, result_ptr.src);
580580}
581581
582582fn zirAlloc(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {
......@@ -1911,7 +1911,7 @@ fn zirFieldVal(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerErro
19111911 const object = try sema.resolveInst(extra.lhs);
19121912 const object_ptr = try sema.analyzeRef(block, src, object);
19131913 const result_ptr = try sema.namedFieldPtr(block, src, object_ptr, field_name, field_name_src);
1914 return sema.analyzeDeref(block, src, result_ptr, result_ptr.src);
1914 return sema.analyzeLoad(block, src, result_ptr, result_ptr.src);
19151915}
19161916
19171917fn zirFieldPtr(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {
......@@ -1939,7 +1939,7 @@ fn zirFieldValNamed(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) Inne
19391939 const field_name = try sema.resolveConstString(block, field_name_src, extra.field_name);
19401940 const object_ptr = try sema.analyzeRef(block, src, object);
19411941 const result_ptr = try sema.namedFieldPtr(block, src, object_ptr, field_name, field_name_src);
1942 return sema.analyzeDeref(block, src, result_ptr, src);
1942 return sema.analyzeLoad(block, src, result_ptr, src);
19431943}
19441944
19451945fn zirFieldPtrNamed(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {
......@@ -2060,7 +2060,7 @@ fn zirElemVal(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError
20602060 const array_ptr = try sema.analyzeRef(block, sema.src, array);
20612061 const elem_index = try sema.resolveInst(bin_inst.rhs);
20622062 const result_ptr = try sema.elemPtr(block, sema.src, array_ptr, elem_index, sema.src);
2063 return sema.analyzeDeref(block, sema.src, result_ptr, sema.src);
2063 return sema.analyzeLoad(block, sema.src, result_ptr, sema.src);
20642064}
20652065
20662066fn zirElemValNode(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {
......@@ -2075,7 +2075,7 @@ fn zirElemValNode(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerE
20752075 const array_ptr = try sema.analyzeRef(block, src, array);
20762076 const elem_index = try sema.resolveInst(extra.rhs);
20772077 const result_ptr = try sema.elemPtr(block, src, array_ptr, elem_index, elem_index_src);
2078 return sema.analyzeDeref(block, src, result_ptr, src);
2078 return sema.analyzeLoad(block, src, result_ptr, src);
20792079}
20802080
20812081fn zirElemPtr(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {
......@@ -2183,7 +2183,7 @@ fn zirSwitchBr(
21832183
21842184 const target_ptr = try sema.resolveInst(inst.positionals.target);
21852185 const target = if (ref)
2186 try sema.analyzeDeref(parent_block, inst.base.src, target_ptr, inst.positionals.target.src)
2186 try sema.analyzeLoad(parent_block, inst.base.src, target_ptr, inst.positionals.target.src)
21872187 else
21882188 target_ptr;
21892189 try sema.validateSwitch(parent_block, target, inst);
......@@ -2639,7 +2639,7 @@ fn analyzeArithmetic(
26392639 return block.addBinOp(src, scalar_type, ir_tag, casted_lhs, casted_rhs);
26402640}
26412641
2642fn zirDerefNode(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {
2642fn zirLoad(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerError!*Inst {
26432643 const tracy = trace(@src());
26442644 defer tracy.end();
26452645
......@@ -2647,7 +2647,7 @@ fn zirDerefNode(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerErr
26472647 const src = inst_data.src();
26482648 const ptr_src: LazySrcLoc = .{ .node_offset_deref_ptr = inst_data.src_node };
26492649 const ptr = try sema.resolveInst(inst_data.operand);
2650 return sema.analyzeDeref(block, src, ptr, ptr_src);
2650 return sema.analyzeLoad(block, src, ptr, ptr_src);
26512651}
26522652
26532653fn zirAsm(
......@@ -2958,7 +2958,7 @@ fn zirIsNullPtr(
29582958 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
29592959 const src = inst_data.src();
29602960 const ptr = try sema.resolveInst(inst_data.operand);
2961 const loaded = try sema.analyzeDeref(block, src, ptr, src);
2961 const loaded = try sema.analyzeLoad(block, src, ptr, src);
29622962 return sema.analyzeIsNull(block, src, loaded, invert_logic);
29632963}
29642964
......@@ -2978,7 +2978,7 @@ fn zirIsErrPtr(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerErro
29782978 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
29792979 const src = inst_data.src();
29802980 const ptr = try sema.resolveInst(inst_data.operand);
2981 const loaded = try sema.analyzeDeref(block, src, ptr, src);
2981 const loaded = try sema.analyzeLoad(block, src, ptr, src);
29822982 return sema.analyzeIsErr(block, src, loaded);
29832983}
29842984
......@@ -3343,7 +3343,7 @@ fn namedFieldPtr(
33433343 },
33443344 .Type => {
33453345 _ = try sema.resolveConstValue(block, object_ptr.src, object_ptr);
3346 const result = try sema.analyzeDeref(block, src, object_ptr, object_ptr.src);
3346 const result = try sema.analyzeLoad(block, src, object_ptr, object_ptr.src);
33473347 const val = result.value().?;
33483348 const child_type = try val.toType(sema.arena);
33493349 switch (child_type.zigTypeTag()) {
......@@ -3409,7 +3409,7 @@ fn elemPtr(
34093409
34103410 if (elem_ty.isSinglePointer() and elem_ty.elemType().zigTypeTag() == .Array) {
34113411 // we have to deref the ptr operand to get the actual array pointer
3412 const array_ptr_deref = try sema.analyzeDeref(block, src, array_ptr, array_ptr.src);
3412 const array_ptr_deref = try sema.analyzeLoad(block, src, array_ptr, array_ptr.src);
34133413 if (array_ptr_deref.value()) |array_ptr_val| {
34143414 if (elem_index.value()) |index_val| {
34153415 // Both array pointer and index are compile-time known.
......@@ -3669,7 +3669,7 @@ fn coerceArrayPtrToMany(sema: *Sema, block: *Scope.Block, dest_type: Type, inst:
36693669
36703670fn analyzeDeclVal(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, decl: *Decl) InnerError!*Inst {
36713671 const decl_ref = try sema.analyzeDeclRef(block, src, decl);
3672 return sema.analyzeDeref(block, src, decl_ref, src);
3672 return sema.analyzeLoad(block, src, decl_ref, src);
36733673}
36743674
36753675fn analyzeDeclRef(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, decl: *Decl) InnerError!*Inst {
......@@ -3737,7 +3737,7 @@ fn analyzeRef(
37373737 return block.addUnOp(src, ptr_type, .ref, operand);
37383738}
37393739
3740fn analyzeDeref(
3740fn analyzeLoad(
37413741 sema: *Sema,
37423742 block: *Scope.Block,
37433743 src: LazySrcLoc,
src/astgen.zig+55-82
......@@ -443,7 +443,7 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In
443443
444444 .deref => {
445445 const lhs = try expr(mod, scope, .none, node_datas[node].lhs);
446 const result = try gz.addUnNode(.deref_node, lhs, node);
446 const result = try gz.addUnNode(.load, lhs, node);
447447 return rvalue(mod, scope, rl, result, node);
448448 },
449449 .address_of => {
......@@ -1042,7 +1042,7 @@ fn blockExprStmts(
10421042 .coerce_result_ptr,
10431043 .decl_ref,
10441044 .decl_val,
1045 .deref_node,
1045 .load,
10461046 .div,
10471047 .elem_ptr,
10481048 .elem_val,
......@@ -1396,7 +1396,7 @@ fn assignOp(
13961396 const gz = scope.getGenZir();
13971397
13981398 const lhs_ptr = try lvalExpr(mod, scope, node_datas[infix_node].lhs);
1399 const lhs = try gz.addUnNode(.deref_node, lhs_ptr, infix_node);
1399 const lhs = try gz.addUnNode(.load, lhs_ptr, infix_node);
14001400 const lhs_type = try gz.addUnTok(.typeof, lhs, infix_node);
14011401 const rhs = try expr(mod, scope, .{ .ty = lhs_type }, node_datas[infix_node].rhs);
14021402
......@@ -2105,7 +2105,7 @@ fn whileExpr(
21052105 try checkLabelRedefinition(mod, scope, label_token);
21062106 }
21072107 const parent_gz = scope.getGenZir();
2108 const is_inline = while_full.inline_token != null;
2108 const is_inline = parent_gz.force_comptime or while_full.inline_token != null;
21092109 const loop_tag: zir.Inst.Tag = if (is_inline) .block_inline else .loop;
21102110 const loop_block = try parent_gz.addBlock(loop_tag, node);
21112111 try parent_gz.instructions.append(mod.gpa, loop_block);
......@@ -2149,7 +2149,6 @@ fn whileExpr(
21492149 // TODO avoid emitting the continue expr when there
21502150 // are no jumps to it. This happens when the last statement of a while body is noreturn
21512151 // and there are no `continue` statements.
2152 // The "repeat" at the end of a loop body is implied.
21532152 if (while_full.ast.cont_expr != 0) {
21542153 _ = try expr(mod, &loop_scope.base, .{ .ty = .void_type }, while_full.ast.cont_expr);
21552154 }
......@@ -2236,44 +2235,32 @@ fn forExpr(
22362235 node: ast.Node.Index,
22372236 for_full: ast.full.While,
22382237) InnerError!zir.Inst.Ref {
2239 if (true) @panic("TODO update for zir-memory-layout");
22402238 if (for_full.label_token) |label_token| {
22412239 try checkLabelRedefinition(mod, scope, label_token);
22422240 }
2243
2244 if (for_full.inline_token) |inline_token| {
2245 return mod.failTok(scope, inline_token, "TODO inline for", .{});
2246 }
2247
22482241 // Set up variables and constants.
22492242 const parent_gz = scope.getGenZir();
2243 const is_inline = parent_gz.force_comptime or for_full.inline_token != null;
22502244 const tree = parent_gz.tree();
2251 const main_tokens = tree.nodes.items(.main_token);
22522245 const token_tags = tree.tokens.items(.tag);
22532246
2254 const for_src = token_starts[for_full.ast.while_token];
2247 const array_ptr = try expr(mod, scope, .ref, for_full.ast.cond_expr);
2248 const len = try parent_gz.addUnNode(.indexable_ptr_len, array_ptr, for_full.ast.cond_expr);
2249
22552250 const index_ptr = blk: {
2256 const usize_type = try addZIRInstConst(mod, scope, for_src, .{
2257 .ty = Type.initTag(.type),
2258 .val = Value.initTag(.usize_type),
2259 });
2260 const index_ptr = try addZIRUnOp(mod, scope, for_src, .alloc, usize_type);
2251 const index_ptr = try parent_gz.addUnNode(.alloc, .usize_type, node);
22612252 // initialize to zero
2262 const zero = try addZIRInstConst(mod, scope, for_src, .{
2263 .ty = Type.initTag(.usize),
2264 .val = Value.initTag(.zero),
2265 });
2266 _ = try addZIRBinOp(mod, scope, for_src, .store, index_ptr, zero);
2253 _ = try parent_gz.addBin(.store, index_ptr, .zero_usize);
22672254 break :blk index_ptr;
22682255 };
2269 const array_ptr = try expr(mod, scope, .ref, for_full.ast.cond_expr);
2270 const cond_src = token_starts[tree.firstToken(for_full.ast.cond_expr)];
2271 const len = try addZIRUnOp(mod, scope, cond_src, .indexable_ptr_len, array_ptr);
2256
2257 const loop_tag: zir.Inst.Tag = if (is_inline) .block_inline else .loop;
2258 const loop_block = try parent_gz.addBlock(loop_tag, node);
2259 try parent_gz.instructions.append(mod.gpa, loop_block);
22722260
22732261 var loop_scope: Scope.GenZir = .{
22742262 .parent = scope,
2275 .decl = scope.ownerDecl().?,
2276 .arena = scope.arena(),
2263 .zir_code = parent_gz.zir_code,
22772264 .force_comptime = parent_gz.force_comptime,
22782265 .instructions = .{},
22792266 };
......@@ -2282,66 +2269,49 @@ fn forExpr(
22822269
22832270 var cond_scope: Scope.GenZir = .{
22842271 .parent = &loop_scope.base,
2285 .decl = loop_scope.decl,
2286 .arena = loop_scope.arena,
2272 .zir_code = parent_gz.zir_code,
22872273 .force_comptime = loop_scope.force_comptime,
22882274 .instructions = .{},
22892275 };
22902276 defer cond_scope.instructions.deinit(mod.gpa);
22912277
22922278 // check condition i < array_expr.len
2293 const index = try addZIRUnOp(mod, &cond_scope.base, cond_src, .deref, index_ptr);
2294 const cond = try addZIRBinOp(mod, &cond_scope.base, cond_src, .cmp_lt, index, len);
2295
2296 const condbr = try addZIRInstSpecial(mod, &cond_scope.base, for_src, zir.Inst.CondBr, .{
2297 .condition = cond,
2298 .then_body = undefined, // populated below
2299 .else_body = undefined, // populated below
2300 }, .{});
2301 const cond_block = try addZIRInstBlock(mod, &loop_scope.base, for_src, .block, .{
2302 .instructions = try loop_scope.arena.dupe(zir.Inst.Ref, cond_scope.instructions.items),
2279 const index = try cond_scope.addUnNode(.load, index_ptr, for_full.ast.cond_expr);
2280 const cond = try cond_scope.addPlNode(.cmp_lt, for_full.ast.cond_expr, zir.Inst.Bin{
2281 .lhs = index,
2282 .rhs = len,
23032283 });
23042284
2305 // increment index variable
2306 const one = try addZIRInstConst(mod, &loop_scope.base, for_src, .{
2307 .ty = Type.initTag(.usize),
2308 .val = Value.initTag(.one),
2309 });
2310 const index_2 = try addZIRUnOp(mod, &loop_scope.base, cond_src, .deref, index_ptr);
2311 const index_plus_one = try addZIRBinOp(mod, &loop_scope.base, for_src, .add, index_2, one);
2312 _ = try addZIRBinOp(mod, &loop_scope.base, for_src, .store, index_ptr, index_plus_one);
2313
2314 const loop = try scope.arena().create(zir.Inst.Loop);
2315 loop.* = .{
2316 .base = .{
2317 .tag = .loop,
2318 .src = for_src,
2319 },
2320 .positionals = .{
2321 .body = .{
2322 .instructions = try scope.arena().dupe(zir.Inst.Ref, loop_scope.instructions.items),
2323 },
2324 },
2325 .kw_args = .{},
2326 };
2327 const for_block = try addZIRInstBlock(mod, scope, for_src, .block, .{
2328 .instructions = try scope.arena().dupe(zir.Inst.Ref, &[1]zir.Inst.Ref{&loop.base}),
2285 const condbr_tag: zir.Inst.Tag = if (is_inline) .condbr_inline else .condbr;
2286 const condbr = try cond_scope.addCondBr(condbr_tag, node);
2287 const block_tag: zir.Inst.Tag = if (is_inline) .block_inline else .block;
2288 const cond_block = try loop_scope.addBlock(block_tag, node);
2289 try loop_scope.instructions.append(mod.gpa, cond_block);
2290 try cond_scope.setBlockBody(cond_block);
2291
2292 // Increment the index variable.
2293 const index_2 = try loop_scope.addUnNode(.load, index_ptr, for_full.ast.cond_expr);
2294 const index_plus_one = try loop_scope.addPlNode(.add, node, zir.Inst.Bin{
2295 .lhs = index_2,
2296 .rhs = .one_usize,
23292297 });
2330 loop_scope.break_block = for_block;
2298 _ = try loop_scope.addBin(.store, index_ptr, index_plus_one);
2299 const repeat_tag: zir.Inst.Tag = if (is_inline) .repeat_inline else .repeat;
2300 _ = try loop_scope.addNode(repeat_tag, node);
2301
2302 try loop_scope.setBlockBody(loop_block);
2303 loop_scope.break_block = loop_block;
23312304 loop_scope.continue_block = cond_block;
23322305 if (for_full.label_token) |label_token| {
23332306 loop_scope.label = @as(?Scope.GenZir.Label, Scope.GenZir.Label{
23342307 .token = label_token,
2335 .block_inst = for_block,
2308 .block_inst = loop_block,
23362309 });
23372310 }
23382311
2339 // while body
2340 const then_src = token_starts[tree.lastToken(for_full.ast.then_expr)];
23412312 var then_scope: Scope.GenZir = .{
23422313 .parent = &cond_scope.base,
2343 .decl = cond_scope.decl,
2344 .arena = cond_scope.arena,
2314 .zir_code = parent_gz.zir_code,
23452315 .force_comptime = cond_scope.force_comptime,
23462316 .instructions = .{},
23472317 };
......@@ -2375,6 +2345,7 @@ fn forExpr(
23752345 .gen_zir = &then_scope,
23762346 .name = index_name,
23772347 .ptr = index_ptr,
2348 .src = parent_gz.tokSrcLoc(index_token),
23782349 };
23792350 break :blk &index_scope.base;
23802351 };
......@@ -2382,34 +2353,36 @@ fn forExpr(
23822353 loop_scope.break_count += 1;
23832354 const then_result = try expr(mod, then_sub_scope, loop_scope.break_result_loc, for_full.ast.then_expr);
23842355
2385 // else branch
23862356 var else_scope: Scope.GenZir = .{
23872357 .parent = &cond_scope.base,
2388 .decl = cond_scope.decl,
2389 .arena = cond_scope.arena,
2358 .zir_code = parent_gz.zir_code,
23902359 .force_comptime = cond_scope.force_comptime,
23912360 .instructions = .{},
23922361 };
23932362 defer else_scope.instructions.deinit(mod.gpa);
23942363
23952364 const else_node = for_full.ast.else_expr;
2396 const else_info: struct { src: usize, result: ?*zir.Inst } = if (else_node != 0) blk: {
2365 const else_info: struct {
2366 src: ast.Node.Index,
2367 result: zir.Inst.Ref,
2368 } = if (else_node != 0) blk: {
23972369 loop_scope.break_count += 1;
23982370 const sub_scope = &else_scope.base;
23992371 break :blk .{
2400 .src = token_starts[tree.lastToken(else_node)],
2372 .src = else_node,
24012373 .result = try expr(mod, sub_scope, loop_scope.break_result_loc, else_node),
24022374 };
24032375 } else .{
2404 .src = token_starts[tree.lastToken(for_full.ast.then_expr)],
2405 .result = null,
2376 .src = for_full.ast.then_expr,
2377 .result = .none,
24062378 };
24072379
24082380 if (loop_scope.label) |some| {
24092381 if (!some.used) {
2410 return mod.fail(scope, token_starts[some.token], "unused for loop label", .{});
2382 return mod.failTok(scope, some.token, "unused for loop label", .{});
24112383 }
24122384 }
2385 const break_tag: zir.Inst.Tag = if (is_inline) .break_inline else .@"break";
24132386 return finishThenElseBlock(
24142387 mod,
24152388 scope,
......@@ -2420,13 +2393,13 @@ fn forExpr(
24202393 &else_scope,
24212394 condbr,
24222395 cond,
2423 then_src,
2396 for_full.ast.then_expr,
24242397 else_info.src,
24252398 then_result,
24262399 else_info.result,
2427 for_block,
2400 loop_block,
24282401 cond_block,
2429 .@"break",
2402 break_tag,
24302403 );
24312404}
24322405
......@@ -2862,7 +2835,7 @@ fn identifier(
28622835 const local_ptr = s.cast(Scope.LocalPtr).?;
28632836 if (mem.eql(u8, local_ptr.name, ident_name)) {
28642837 if (rl == .ref) return local_ptr.ptr;
2865 const loaded = try gz.addUnNode(.deref_node, local_ptr.ptr, ident);
2838 const loaded = try gz.addUnNode(.load, local_ptr.ptr, ident);
28662839 return rvalue(mod, scope, rl, loaded, ident);
28672840 }
28682841 s = local_ptr.parent;
src/zir.zig+15-3
......@@ -281,7 +281,7 @@ pub const Inst = struct {
281281 decl_val,
282282 /// Load the value from a pointer. Assumes `x.*` syntax.
283283 /// Uses `un_node` field. AST node is the `x.*` syntax.
284 deref_node,
284 load,
285285 /// Arithmetic division. Asserts no integer overflow.
286286 /// Uses the `pl_node` union field. Payload is `Bin`.
287287 div,
......@@ -661,7 +661,7 @@ pub const Inst = struct {
661661 .dbg_stmt_node,
662662 .decl_ref,
663663 .decl_val,
664 .deref_node,
664 .load,
665665 .div,
666666 .elem_ptr,
667667 .elem_val,
......@@ -841,6 +841,10 @@ pub const Inst = struct {
841841 bool_true,
842842 /// `false`
843843 bool_false,
844 /// `0` (usize)
845 zero_usize,
846 /// `1` (usize)
847 one_usize,
844848
845849 _,
846850
......@@ -1016,10 +1020,18 @@ pub const Inst = struct {
10161020 .ty = Type.initTag(.comptime_int),
10171021 .val = Value.initTag(.zero),
10181022 },
1023 .zero_usize = .{
1024 .ty = Type.initTag(.usize),
1025 .val = Value.initTag(.zero),
1026 },
10191027 .one = .{
10201028 .ty = Type.initTag(.comptime_int),
10211029 .val = Value.initTag(.one),
10221030 },
1031 .one_usize = .{
1032 .ty = Type.initTag(.usize),
1033 .val = Value.initTag(.one),
1034 },
10231035 .void_value = .{
10241036 .ty = Type.initTag(.void),
10251037 .val = Value.initTag(.void_value),
......@@ -1377,7 +1389,7 @@ const Writer = struct {
13771389 .call_none,
13781390 .call_none_chkused,
13791391 .compile_error,
1380 .deref_node,
1392 .load,
13811393 .ensure_result_used,
13821394 .ensure_result_non_error,
13831395 .import,
test/stage2/test.zig+31-31
......@@ -968,37 +968,37 @@ pub fn addCases(ctx: *TestContext) !void {
968968 );
969969
970970 // Basic for loop
971 //case.addCompareOutput(
972 // \\export fn _start() noreturn {
973 // \\ for ("hello") |_| print();
974 // \\
975 // \\ exit();
976 // \\}
977 // \\
978 // \\fn print() void {
979 // \\ asm volatile ("syscall"
980 // \\ :
981 // \\ : [number] "{rax}" (1),
982 // \\ [arg1] "{rdi}" (1),
983 // \\ [arg2] "{rsi}" (@ptrToInt("hello\n")),
984 // \\ [arg3] "{rdx}" (6)
985 // \\ : "rcx", "r11", "memory"
986 // \\ );
987 // \\ return;
988 // \\}
989 // \\
990 // \\fn exit() noreturn {
991 // \\ asm volatile ("syscall"
992 // \\ :
993 // \\ : [number] "{rax}" (231),
994 // \\ [arg1] "{rdi}" (0)
995 // \\ : "rcx", "r11", "memory"
996 // \\ );
997 // \\ unreachable;
998 // \\}
999 //,
1000 // "hello\nhello\nhello\nhello\nhello\n",
1001 //);
971 case.addCompareOutput(
972 \\export fn _start() noreturn {
973 \\ for ("hello") |_| print();
974 \\
975 \\ exit();
976 \\}
977 \\
978 \\fn print() void {
979 \\ asm volatile ("syscall"
980 \\ :
981 \\ : [number] "{rax}" (1),
982 \\ [arg1] "{rdi}" (1),
983 \\ [arg2] "{rsi}" (@ptrToInt("hello\n")),
984 \\ [arg3] "{rdx}" (6)
985 \\ : "rcx", "r11", "memory"
986 \\ );
987 \\ return;
988 \\}
989 \\
990 \\fn exit() noreturn {
991 \\ asm volatile ("syscall"
992 \\ :
993 \\ : [number] "{rax}" (231),
994 \\ [arg1] "{rdi}" (0)
995 \\ : "rcx", "r11", "memory"
996 \\ );
997 \\ unreachable;
998 \\}
999 ,
1000 "hello\nhello\nhello\nhello\nhello\n",
1001 );
10021002 }
10031003
10041004 //{