|
22 | 22 | LoadStatic, MethodCall, PrimitiveOp, OpDescription, RegisterOp, CallC, Truncate, |
23 | 23 | RaiseStandardError, Unreachable, LoadErrorValue, LoadGlobal, |
24 | 24 | NAMESPACE_TYPE, NAMESPACE_MODULE, NAMESPACE_STATIC, BinaryIntOp, GetElementPtr, |
25 | | - LoadMem, ComparisonOp, LoadAddress, TupleGet |
| 25 | + LoadMem, ComparisonOp, LoadAddress, TupleGet, SetMem |
26 | 26 | ) |
27 | 27 | from mypyc.ir.rtypes import ( |
28 | 28 | RType, RUnion, RInstance, optional_value_type, int_rprimitive, float_rprimitive, |
29 | 29 | bool_rprimitive, list_rprimitive, str_rprimitive, is_none_rprimitive, object_rprimitive, |
30 | 30 | c_pyssize_t_rprimitive, is_short_int_rprimitive, is_tagged, PyVarObject, short_int_rprimitive, |
31 | 31 | is_list_rprimitive, is_tuple_rprimitive, is_dict_rprimitive, is_set_rprimitive, PySetObject, |
32 | 32 | none_rprimitive, RTuple, is_bool_rprimitive, is_str_rprimitive, c_int_rprimitive, |
33 | | - pointer_rprimitive |
| 33 | + pointer_rprimitive, PyListObject |
34 | 34 | ) |
35 | 35 | from mypyc.ir.func_ir import FuncDecl, FuncSignature |
36 | 36 | from mypyc.ir.class_ir import ClassIR, all_concrete_classes |
37 | 37 | from mypyc.common import ( |
38 | 38 | FAST_ISINSTANCE_MAX_SUBCLASSES, MAX_LITERAL_SHORT_INT, |
39 | | - STATIC_PREFIX |
| 39 | + STATIC_PREFIX, PLATFORM_SIZE |
40 | 40 | ) |
41 | 41 | from mypyc.primitives.registry import ( |
42 | 42 | func_ops, c_method_call_ops, CFunctionDescription, c_function_ops, |
|
58 | 58 | from mypyc.primitives.int_ops import int_comparison_op_mapping |
59 | 59 | from mypyc.primitives.exc_ops import err_occurred_op, keep_propagating_op |
60 | 60 | from mypyc.primitives.str_ops import unicode_compare |
| 61 | +from mypyc.primitives.set_ops import new_set_op |
61 | 62 | from mypyc.rt_subtype import is_runtime_subtype |
62 | 63 | from mypyc.subtype import is_subtype |
63 | 64 | from mypyc.sametype import is_same_type |
@@ -273,7 +274,7 @@ def py_call(self, |
273 | 274 | else: |
274 | 275 | # Otherwise we construct a list and call extend it with the star args, since tuples |
275 | 276 | # don't have an extend method. |
276 | | - pos_args_list = self.primitive_op(new_list_op, pos_arg_values, line) |
| 277 | + pos_args_list = self.new_list_op(pos_arg_values, line) |
277 | 278 | for star_arg_value in star_arg_values: |
278 | 279 | self.call_c(list_extend_op, [pos_args_list, star_arg_value], line) |
279 | 280 | pos_args_tuple = self.call_c(list_tuple_op, [pos_args_list], line) |
@@ -755,6 +756,27 @@ def make_dict(self, key_value_pairs: Sequence[DictEntry], line: int) -> Value: |
755 | 756 |
|
756 | 757 | return result |
757 | 758 |
|
| 759 | + def new_list_op(self, values: List[Value], line: int) -> Value: |
| 760 | + length = self.add(LoadInt(len(values), line, rtype=c_pyssize_t_rprimitive)) |
| 761 | + result_list = self.call_c(new_list_op, [length], line) |
| 762 | + if len(values) == 0: |
| 763 | + return result_list |
| 764 | + args = [self.coerce(item, object_rprimitive, line) for item in values] |
| 765 | + ob_item_ptr = self.add(GetElementPtr(result_list, PyListObject, 'ob_item', line)) |
| 766 | + ob_item_base = self.add(LoadMem(pointer_rprimitive, ob_item_ptr, result_list, line)) |
| 767 | + for i in range(len(values)): |
| 768 | + if i == 0: |
| 769 | + item_address = ob_item_base |
| 770 | + else: |
| 771 | + offset = self.add(LoadInt(PLATFORM_SIZE * i, line, rtype=c_pyssize_t_rprimitive)) |
| 772 | + item_address = self.add(BinaryIntOp(pointer_rprimitive, ob_item_base, offset, |
| 773 | + BinaryIntOp.ADD, line)) |
| 774 | + self.add(SetMem(object_rprimitive, item_address, args[i], result_list, line)) |
| 775 | + return result_list |
| 776 | + |
| 777 | + def new_set_op(self, values: List[Value], line: int) -> Value: |
| 778 | + return self.call_c(new_set_op, values, line) |
| 779 | + |
758 | 780 | def builtin_call(self, |
759 | 781 | args: List[Value], |
760 | 782 | fn_op: str, |
|
0 commit comments