Skip to content

Commit f3b4bde

Browse files
Add support for list.append method (pyccel#1982)
Add support for list.append method --------- Co-authored-by: Emily Bourne <[email protected]>
1 parent 82aa57c commit f3b4bde

File tree

5 files changed

+128
-111
lines changed

5 files changed

+128
-111
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ All notable changes to this project will be documented in this file.
3131
- #1874 : Add C and Fortran support for the `len()` function for the `list` container.
3232
- #1875 : Add C and Fortran support for the `len()` function for the `set` container.
3333
- #1908 : Add C and Fortran support for the `len()` function for the `dict` container.
34+
- #1689 : Add C and Fortran support for list method `append()`.
3435
- #1876 : Add C support for indexing lists.
3536
- #1690 : Add C support for list method `pop()`.
3637
- #1877 : Add C Support for set method `pop()`.

docs/builtin-functions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ Python contains a limited number of builtin functions defined [here](https://doc
7878

7979
| Method | Supported |
8080
|----------|-----------|
81-
| `append` | Python-only |
81+
| **`append`** | **Yes** |
8282
| `clear` | Python-only |
8383
| `copy` | Python-only |
8484
| `count` | No |

pyccel/codegen/printing/ccode.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2580,6 +2580,14 @@ def _print_ClassDef(self, expr):
25802580
return methods + interfaces
25812581

25822582
#================== List methods ==================
2583+
def _print_ListAppend(self, expr):
2584+
target = expr.list_obj
2585+
class_type = target.class_type
2586+
c_type = self.get_c_type(class_type)
2587+
arg = self._print(expr.args[0])
2588+
list_obj = self._print(ObjectAddress(expr.list_obj))
2589+
return f'{c_type}_push({list_obj}, {arg});\n'
2590+
25832591
def _print_ListPop(self, expr):
25842592
class_type = expr.list_obj.class_type
25852593
c_type = self.get_c_type(class_type)

pyccel/codegen/printing/fcode.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,6 +1147,14 @@ def _print_PythonImag(self, expr):
11471147
value = self._print(expr.internal_var)
11481148
return f'aimag({value})'
11491149

1150+
#========================== List Methods ===============================#
1151+
1152+
def _print_ListAppend(self, expr):
1153+
target = expr.list_obj
1154+
arg = self._print(expr.args[0])
1155+
return f'call {target} % push_back({arg})\n'
1156+
1157+
11501158

11511159

11521160
#========================== Numpy Elements ===============================#

0 commit comments

Comments
 (0)