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