(
builder: IRBuilder, vec_type: RVec, arg: Expression, *, capacity: Value | None = None
)
| 584 | |
| 585 | |
| 586 | def translate_vec_create_from_iterable( |
| 587 | builder: IRBuilder, vec_type: RVec, arg: Expression, *, capacity: Value | None = None |
| 588 | ) -> Value: |
| 589 | line = arg.line |
| 590 | item_type = vec_type.item_type |
| 591 | if isinstance(arg, OpExpr) and arg.op == "*": |
| 592 | if isinstance(arg.left, ListExpr): |
| 593 | lst = arg.left |
| 594 | other = arg.right |
| 595 | elif isinstance(arg.right, ListExpr): |
| 596 | lst = arg.right |
| 597 | other = arg.left |
| 598 | else: |
| 599 | assert False |
| 600 | assert len(lst.items) == 1 |
| 601 | other_type = builder.node_type(other) |
| 602 | # TODO: is_any_int(...) |
| 603 | if is_int64_rprimitive(other_type) or is_int_rprimitive(other_type): |
| 604 | length = builder.accept(other) |
| 605 | init = builder.accept(lst.items[0]) |
| 606 | return vec_create_initialized( |
| 607 | builder.builder, vec_type, length, init, line, capacity=capacity |
| 608 | ) |
| 609 | assert False, other_type |
| 610 | if isinstance(arg, ListExpr): |
| 611 | items = [] |
| 612 | for item in arg.items: |
| 613 | value = builder.accept(item) |
| 614 | items.append(builder.coerce(value, item_type, line)) |
| 615 | return vec_create_from_values(builder.builder, vec_type, items, line, capacity=capacity) |
| 616 | if isinstance(arg, ListComprehension): |
| 617 | return translate_vec_comprehension(builder, vec_type, arg.generator, capacity=capacity) |
| 618 | return vec_from_iterable(builder, vec_type, arg, line, capacity=capacity) |
| 619 | |
| 620 | |
| 621 | def vec_from_iterable( |
no test coverage detected
searching dependent graphs…