Skip to content

Commit 0db644d

Browse files
committed
Compose List builtins in typecheck fuzzer
1 parent ed4ad1f commit 0db644d

1 file changed

Lines changed: 32 additions & 1 deletion

File tree

test/fuzzing/TypedCodeGenerator.zig

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,13 +440,16 @@ fn writeRecordExpr(self: *Self, context: ExprContext, depth: u8, visible_methods
440440
}
441441

442442
fn writeListU64Expr(self: *Self, context: ExprContext, depth: u8, visible_methods: usize) std.mem.Allocator.Error!void {
443-
switch (self.reader.intRangeAtMost(u8, 0, 5)) {
443+
switch (self.reader.intRangeAtMost(u8, 0, 8)) {
444444
0 => try self.writeContextSymbolOrElse(.list_u64, context, writeListLiteral, depth - 1, visible_methods),
445445
1 => if (!try self.writeMethodCall(.list_u64, context, depth - 1, visible_methods)) try self.writeListLiteral(context, depth - 1, visible_methods),
446446
2 => try self.writeIfExpr(.list_u64, context, depth - 1, visible_methods),
447447
3 => try self.writeListLiteral(context, depth - 1, visible_methods),
448448
4 => try self.writeListMapExpr(context, depth - 1, visible_methods),
449449
5 => try self.writeListMatchExpr(context, depth - 1, visible_methods),
450+
6 => try self.writeListConcatExpr(context, depth - 1, visible_methods),
451+
7 => try self.writeListAppendExpr(context, depth - 1, visible_methods),
452+
8 => try self.writeListFilterExpr(context, depth - 1, visible_methods),
450453
else => unreachable,
451454
}
452455
}
@@ -633,6 +636,34 @@ fn writeListMapExpr(self: *Self, context: ExprContext, depth: u8, visible_method
633636
try self.write(")");
634637
}
635638

639+
fn writeListConcatExpr(self: *Self, context: ExprContext, depth: u8, visible_methods: usize) std.mem.Allocator.Error!void {
640+
try self.write("List.concat(");
641+
try self.writeExpr(.list_u64, context, depth, visible_methods);
642+
try self.write(", ");
643+
try self.writeExpr(.list_u64, context, depth, visible_methods);
644+
try self.write(")");
645+
}
646+
647+
fn writeListAppendExpr(self: *Self, context: ExprContext, depth: u8, visible_methods: usize) std.mem.Allocator.Error!void {
648+
try self.write("List.append(");
649+
try self.writeExpr(.list_u64, context, depth, visible_methods);
650+
try self.write(", ");
651+
try self.writeExpr(.u64, context, depth, visible_methods);
652+
try self.write(")");
653+
}
654+
655+
fn writeListFilterExpr(self: *Self, context: ExprContext, depth: u8, visible_methods: usize) std.mem.Allocator.Error!void {
656+
const item = self.fresh(.value);
657+
658+
try self.write(if (self.reader.boolean()) "List.keep_if(" else "List.drop_if(");
659+
try self.writeExpr(.list_u64, context, depth, visible_methods);
660+
try self.write(", |");
661+
try self.writeSymbol(item);
662+
try self.write("| ");
663+
try self.writeExpr(.bool, extendContext(context, item, .u64), depth, visible_methods);
664+
try self.write(")");
665+
}
666+
636667
fn writeListMatchExpr(self: *Self, context: ExprContext, depth: u8, visible_methods: usize) std.mem.Allocator.Error!void {
637668
const head = self.fresh(.value);
638669
const tail = self.fresh(.value);

0 commit comments

Comments
 (0)