| ... | ... | @@ -152,17 +152,23 @@ fn do(alloc: std.mem.Allocator, writer: anytype, comptime value: astgen.Value, d |
| 152 | 152 | } |
| 153 | 153 | }, |
| 154 | 154 | .function => |v| { |
| 155 | var arena = std.heap.ArenaAllocator.init(alloc); |
| 156 | defer arena.deinit(); |
| 157 | |
| 155 | 158 | if (@hasDecl(root, "pek_" ++ v.name)) { |
| 156 | 159 | const func = @field(root, "pek_" ++ v.name); |
| 160 | var list = std.ArrayList(u8).init(arena.allocator()); |
| 161 | errdefer list.deinit(); |
| 157 | 162 | var args: FnArgsTuple(func) = undefined; |
| 158 | 163 | args.@"0" = alloc; |
| 164 | args.@"1" = list.writer(); |
| 159 | 165 | inline for (v.args) |arg, i| { |
| 160 | | const field_name = comptime std.fmt.comptimePrint("{d}", .{i + 1}); |
| 166 | const field_name = comptime std.fmt.comptimePrint("{d}", .{i + 2}); |
| 161 | 167 | @field(args, field_name) = if (comptime std.mem.eql(u8, arg[0], "this")) search(arg[1..], data) else search(arg, ctx); |
| 162 | 168 | } |
| 163 | 169 | const repvalue = astgen.Value{ .replacement = &.{"this"} }; |
| 164 | | const newdata = try @call(.{}, func, args); |
| 165 | | try do(alloc, writer, repvalue, newdata, ctx, indent, flag1); |
| 170 | try @call(.{}, func, args); |
| 171 | try do(alloc, writer, repvalue, list.toOwnedSlice(), ctx, indent, flag1); |
| 166 | 172 | return; |
| 167 | 173 | } |
| 168 | 174 | @compileError("pek: unknown custom function: " ++ v.name); |