authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-08-13 23:14:57 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-08-13 23:14:57 -07:00
log3bc98c9e10d85bee081771558bcdf71fe9e3feed
tree275918fb5572b1be837e22662856b45067d6f563
parent4b343f8f237d08317246c709e97ccc2962d12e69

hoist x init in block block


1 files changed, 5 insertions(+), 7 deletions(-)

src/lib.zig+5-7
......@@ -84,16 +84,17 @@ fn do(writer: anytype, comptime value: astgen.Value, data: anytype, ctx: anytype
8484 .block => |v| {
8585 const body = astgen.Value{ .body = v.body };
8686 const bottom = astgen.Value{ .body = v.bttm };
87 const x = if (comptime std.mem.eql(u8, v.args[0][0], "this")) search(v.args[0][1..], data) else search(v.args[0], ctx);
88 const T = @TypeOf(x);
89 const TI = @typeInfo(T);
8790 switch (v.name) {
8891 .each => {
8992 comptime assertEqual(v.args.len, 1);
90 const x = if (comptime std.mem.eql(u8, v.args[0][0], "this")) search(v.args[0][1..], data) else search(v.args[0], ctx);
9193 for (x) |item| try do(writer, body, item, ctx, indent, flag1);
9294 },
9395 .@"if" => {
9496 comptime assertEqual(v.args.len, 1);
95 const x = if (comptime std.mem.eql(u8, v.args[0][0], "this")) search(v.args[0][1..], data) else search(v.args[0], ctx);
96 switch (@typeInfo(@TypeOf(x))) {
97 switch (TI) {
9798 .Bool => try doif(writer, body, bottom, data, ctx, indent, flag1, x, true),
9899 .Optional => try docap(writer, body, bottom, data, ctx, indent, flag1, x, true),
99100 else => unreachable,
......@@ -101,8 +102,7 @@ fn do(writer: anytype, comptime value: astgen.Value, data: anytype, ctx: anytype
101102 },
102103 .ifnot => {
103104 comptime assertEqual(v.args.len, 1);
104 const x = if (comptime std.mem.eql(u8, v.args[0][0], "this")) search(v.args[0][1..], data) else search(v.args[0], ctx);
105 switch (@typeInfo(@TypeOf(x))) {
105 switch (TI) {
106106 .Bool => try doif(writer, body, bottom, data, ctx, indent, flag1, x, false),
107107 .Optional => try docap(writer, body, bottom, data, ctx, indent, flag1, x, false),
108108 else => unreachable,
......@@ -110,13 +110,11 @@ fn do(writer: anytype, comptime value: astgen.Value, data: anytype, ctx: anytype
110110 },
111111 .ifequal => {
112112 comptime assertEqual(v.args.len, 2);
113 const x = if (comptime std.mem.eql(u8, v.args[0][0], "this")) search(v.args[0][1..], data) else search(v.args[0], ctx);
114113 const y = search(v.args[1], data);
115114 if (x == y) try do(writer, body, data, ctx, indent, flag1);
116115 },
117116 .ifnotequal => {
118117 comptime assertEqual(v.args.len, 2);
119 const x = if (comptime std.mem.eql(u8, v.args[0][0], "this")) search(v.args[0][1..], data) else search(v.args[0], ctx);
120118 const y = if (comptime std.mem.eql(u8, v.args[1][0], "this")) search(v.args[1][1..], data) else search(v.args[1], ctx);
121119 if (x != y) try do(writer, body, data, ctx, indent, flag1);
122120 },