@@ -232,6 +232,34 @@ fn list_setitem(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
232
232
set_item ( vm, & mut elements, key. clone ( ) , value. clone ( ) )
233
233
}
234
234
235
+ fn list_mul ( vm : & mut VirtualMachine , args : PyFuncArgs ) -> PyResult {
236
+ arg_check ! (
237
+ vm,
238
+ args,
239
+ required = [
240
+ ( list, Some ( vm. ctx. list_type( ) ) ) ,
241
+ ( product, Some ( vm. ctx. int_type( ) ) )
242
+ ]
243
+ ) ;
244
+
245
+ let counter = objint:: get_value ( & product) . to_usize ( ) . unwrap ( ) ;
246
+
247
+ let elements = get_elements ( list) ;
248
+ let current_len = elements. len ( ) ;
249
+ let mut new_elements = Vec :: with_capacity ( counter * current_len) ;
250
+
251
+ for _ in 0 ..counter {
252
+ new_elements. extend ( elements. clone ( ) ) ;
253
+ }
254
+
255
+ Ok ( PyObject :: new (
256
+ PyObjectKind :: Sequence {
257
+ elements : new_elements,
258
+ } ,
259
+ vm. ctx . list_type ( ) ,
260
+ ) )
261
+ }
262
+
235
263
pub fn init ( context : & PyContext ) {
236
264
let ref list_type = context. list_type ;
237
265
context. set_attr ( & list_type, "__add__" , context. new_rustfunc ( list_add) ) ;
@@ -252,6 +280,7 @@ pub fn init(context: &PyContext) {
252
280
"__setitem__" ,
253
281
context. new_rustfunc ( list_setitem) ,
254
282
) ;
283
+ context. set_attr ( & list_type, "__mul__" , context. new_rustfunc ( list_mul) ) ;
255
284
context. set_attr ( & list_type, "__len__" , context. new_rustfunc ( list_len) ) ;
256
285
context. set_attr ( & list_type, "__new__" , context. new_rustfunc ( list_new) ) ;
257
286
context. set_attr ( & list_type, "__repr__" , context. new_rustfunc ( list_repr) ) ;
0 commit comments