authorgravatar for jacoblevgw@gmail.comJacob G-W <jacoblevgw@gmail.com> 2021-03-19 15:33:06-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-03-19 14:50:15-07:00
loga4f0ccdfe4ebbaed34b558943279797156832f4b
tree0bd6a6e2c7ee55e0971d41f4f67387506ac51191
parentc50397c2682846635d1ed116fcd5fe98e8f08c81

zir-memory-layout: astgen: literals and *, &

this was pretty low hanging fruit

1 files changed, 13 insertions(+), 38 deletions(-)

src/astgen.zig+13-38
...@@ -267,6 +267,8 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In...@@ -267,6 +267,8 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In
267 const node_tags = tree.nodes.items(.tag);267 const node_tags = tree.nodes.items(.tag);
268 const token_starts = tree.tokens.items(.start);268 const token_starts = tree.tokens.items(.start);
269269
270 const gz = scope.getGenZir();
271
270 switch (node_tags[node]) {272 switch (node_tags[node]) {
271 .root => unreachable, // Top-level declaration.273 .root => unreachable, // Top-level declaration.
272 .@"usingnamespace" => unreachable, // Top-level declaration.274 .@"usingnamespace" => unreachable, // Top-level declaration.
...@@ -443,56 +445,29 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In...@@ -443,56 +445,29 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In
443 .slice_sentinel => return sliceExpr(mod, scope, rl, tree.sliceSentinel(node)),445 .slice_sentinel => return sliceExpr(mod, scope, rl, tree.sliceSentinel(node)),
444446
445 .deref => {447 .deref => {
446 if (true) @panic("TODO update for zir-memory-layout");
447 const lhs = try expr(mod, scope, .none, node_datas[node].lhs);448 const lhs = try expr(mod, scope, .none, node_datas[node].lhs);
448 const src = token_starts[main_tokens[node]];449 const result = try gz.addUnNode(.deref_node, lhs, node);
449 const result = try addZIRUnOp(mod, scope, src, .deref, lhs);450 return rvalue(mod, scope, rl, result, node);
450 return rvalue(mod, scope, rl, result);
451 },451 },
452 .address_of => {452 .address_of => {
453 if (true) @panic("TODO update for zir-memory-layout");
454 const result = try expr(mod, scope, .ref, node_datas[node].lhs);453 const result = try expr(mod, scope, .ref, node_datas[node].lhs);
455 return rvalue(mod, scope, rl, result);454 return rvalue(mod, scope, rl, result, node);
456 },455 },
457 .undefined_literal => {456 .undefined_literal => {
458 if (true) @panic("TODO update for zir-memory-layout");457 const result = @enumToInt(zir.Const.undef);
459 const main_token = main_tokens[node];458 return rvalue(mod, scope, rl, result, node);
460 const src = token_starts[main_token];
461 const result = try addZIRInstConst(mod, scope, src, .{
462 .ty = Type.initTag(.@"undefined"),
463 .val = Value.initTag(.undef),
464 });
465 return rvalue(mod, scope, rl, result);
466 },459 },
467 .true_literal => {460 .true_literal => {
468 if (true) @panic("TODO update for zir-memory-layout");461 const result = @enumToInt(zir.Const.bool_true);
469 const main_token = main_tokens[node];462 return rvalue(mod, scope, rl, result, node);
470 const src = token_starts[main_token];
471 const result = try addZIRInstConst(mod, scope, src, .{
472 .ty = Type.initTag(.bool),
473 .val = Value.initTag(.bool_true),
474 });
475 return rvalue(mod, scope, rl, result);
476 },463 },
477 .false_literal => {464 .false_literal => {
478 if (true) @panic("TODO update for zir-memory-layout");465 const result = @enumToInt(zir.Const.bool_false);
479 const main_token = main_tokens[node];466 return rvalue(mod, scope, rl, result, node);
480 const src = token_starts[main_token];
481 const result = try addZIRInstConst(mod, scope, src, .{
482 .ty = Type.initTag(.bool),
483 .val = Value.initTag(.bool_false),
484 });
485 return rvalue(mod, scope, rl, result);
486 },467 },
487 .null_literal => {468 .null_literal => {
488 if (true) @panic("TODO update for zir-memory-layout");469 const result = @enumToInt(zir.Const.null_value);
489 const main_token = main_tokens[node];470 return rvalue(mod, scope, rl, result, node);
490 const src = token_starts[main_token];
491 const result = try addZIRInstConst(mod, scope, src, .{
492 .ty = Type.initTag(.@"null"),
493 .val = Value.initTag(.null_value),
494 });
495 return rvalue(mod, scope, rl, result);
496 },471 },
497 .optional_type => {472 .optional_type => {
498 if (true) @panic("TODO update for zir-memory-layout");473 if (true) @panic("TODO update for zir-memory-layout");