authorgravatar for noam@pixelhero.devNoam Preil <noam@pixelhero.dev> 2020-08-16 20:36:33-04:00
committergravatar for noam@pixelhero.devNoam Preil <noam@pixelhero.dev> 2020-08-16 20:36:33-04:00
log3ca8c42e7ab04886f536a7bab34c9ea563c62711
treefb972fec508092f35842787bdfe41feae97b9348
parent93619a5e4e9ad0e29e521c2c30fc1e39f47a6ba8
signature Commit is signed but in an unrecognized format.

Astgen: further cleanup


1 files changed, 8 insertions(+), 11 deletions(-)

src-self-hosted/astgen.zig+8-11
......@@ -361,24 +361,21 @@ fn varDecl(
361361 return &sub_scope.base;
362362 },
363363 .Keyword_var => {
364 const alloc = if (node.getTrailer("type_node")) |type_node| a: {
364 const var_data: struct { result_loc: ResultLoc, alloc: *zir.Inst } = if (node.getTrailer("type_node")) |type_node| a: {
365365 const type_inst = try typeExpr(mod, scope, type_node);
366 break :a try addZIRUnOp(mod, scope, name_src, .alloc, type_inst);
367 } else try addZIRNoOp(mod, scope, name_src, .alloc_inferred);
368 const result_loc = r: {
369 if (node.getTrailer("type_node")) |type_node| {
370 break :r ResultLoc{ .ptr = alloc };
371 } else {
372 break :r ResultLoc{ .inferred_ptr = alloc.castTag(.alloc_inferred).? };
373 }
366 const alloc = try addZIRUnOp(mod, scope, name_src, .alloc, type_inst);
367 break :a .{ .alloc = try addZIRUnOp(mod, scope, name_src, .alloc, type_inst), .result_loc = .{ .ptr = alloc } };
368 } else a: {
369 const alloc = try addZIRNoOp(mod, scope, name_src, .alloc_inferred);
370 break :a .{ .alloc = alloc, .result_loc = .{ .inferred_ptr = alloc.castTag(.alloc_inferred).? } };
374371 };
375 const init_inst = try expr(mod, scope, result_loc, init_node);
372 const init_inst = try expr(mod, scope, var_data.result_loc, init_node);
376373 const sub_scope = try block_arena.create(Scope.LocalPtr);
377374 sub_scope.* = .{
378375 .parent = scope,
379376 .gen_zir = scope.getGenZIR(),
380377 .name = ident_name,
381 .ptr = alloc,
378 .ptr = var_data.alloc,
382379 };
383380 return &sub_scope.base;
384381 },