Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support variable declarations in c #1847

Merged
merged 163 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from 74 commits
Commits
Show all changes
163 commits
Select commit Hold shift + click to select a range
409f7df
add support for disard method and test functions
mustapha-belbiad Mar 1, 2024
02513d5
fix Codacy issue
mustapha-belbiad Mar 1, 2024
3cb376e
add docs for discard method
mustapha-belbiad Mar 1, 2024
c131d4d
Merge branch 'devel' into Set_Support-Discard_Method
mustapha-belbiad Apr 3, 2024
7274bb3
Check if the result of Pyccel is the same as Python.
mustapha-belbiad Apr 3, 2024
14d4fb5
Fix a typing mistake.
mustapha-belbiad Apr 4, 2024
168045a
Delete test files'
mustapha-belbiad Apr 4, 2024
1761006
add support for Update method.
mustapha-belbiad Apr 17, 2024
6145e41
add test for update method.
mustapha-belbiad Apr 17, 2024
27363ae
Merge branch 'devel' into Set_Support-Update_Method
mustapha-belbiad Apr 17, 2024
f14518d
remove a debug line.
mustapha-belbiad Apr 17, 2024
673cf16
Remove unnecessary change.
mustapha-belbiad Apr 17, 2024
fcf24cd
bad merge
mustapha-belbiad Apr 17, 2024
88b0ecc
Fix Codacy problem
mustapha-belbiad Apr 17, 2024
4f3391c
update changelog and fix bad merge problem
mustapha-belbiad Apr 17, 2024
f59716e
Merge branch 'devel' into Set_Support-Update_Method
mustapha-belbiad Apr 17, 2024
0d12488
Move the function position to the bottom of the file.
mustapha-belbiad Apr 17, 2024
58fb284
Merge branch 'Set_Support-Update_Method' of https://github.com/pyccel…
mustapha-belbiad Apr 17, 2024
1c3b75a
Add a newline in the end of file
mustapha-belbiad Apr 17, 2024
0a6a2c4
fix docs
mustapha-belbiad Apr 17, 2024
80ce7bb
Fix Python linting problem
mustapha-belbiad Apr 17, 2024
28eae73
Fix a small problem in code.
mustapha-belbiad Apr 17, 2024
1a76965
add support for type annotation
mustapha-belbiad Apr 22, 2024
dfbddd1
Merge branch 'devel' into Support_variable_declarations_in_C
mustapha-belbiad Apr 22, 2024
034cd26
only changes for type annotation
mustapha-belbiad Apr 22, 2024
188466f
only changes for type annotation
mustapha-belbiad Apr 22, 2024
d0bd13c
Modify the condition to be more general.
mustapha-belbiad Apr 23, 2024
918fa12
Merge branch 'devel' into Support_variable_declarations_in_C
mustapha-belbiad Apr 23, 2024
9fa2aa3
list declare in c: prototype
Farouk-Echaref Apr 23, 2024
de72d1d
Add support for sets in semantic and codegen stages.
mustapha-belbiad Apr 29, 2024
f11f946
Move all the imports to the header file and include STC, defining the…
mustapha-belbiad Apr 30, 2024
78d08ef
Remove unnecessary changes.
mustapha-belbiad Apr 30, 2024
3234426
Remove unnecessary changes.
mustapha-belbiad Apr 30, 2024
897046b
Merge branch 'devel' into list_declare_c
Farouk-Echaref Apr 30, 2024
b4d1ddd
Rewrite the solution.
mustapha-belbiad Apr 30, 2024
1537b39
assign generic empty list to typed list variable
Farouk-Echaref Apr 30, 2024
a0273cc
Make the conditions global.
mustapha-belbiad Apr 30, 2024
81411c4
New modification has been made.
mustapha-belbiad Apr 30, 2024
07456f5
Merge branch 'devel' into Support_variable_declarations_in_C
mustapha-belbiad May 2, 2024
62e7694
Make a dictionary to get the exact 'class_type_macro'.
mustapha-belbiad May 2, 2024
ecd70cc
Merge branch 'Support_variable_declarations_in_C' of https://github.c…
mustapha-belbiad May 2, 2024
cad722d
Rearrange a line.
mustapha-belbiad May 2, 2024
01150c5
New changes
mustapha-belbiad May 2, 2024
d242a4a
Fix: Codacy problem.
mustapha-belbiad May 2, 2024
59ba041
Fix: Codacy problem.
mustapha-belbiad May 2, 2024
a2f5856
Fix: Codacy problem.
mustapha-belbiad May 2, 2024
bf9f775
Merge branch 'devel' into Support_variable_declarations_in_C
mustapha-belbiad May 2, 2024
2d827df
Merge branch 'devel' into Support_variable_declarations_in_C
Farouk-Echaref May 6, 2024
0f58e7c
Merge branch 'list_declare_c' into Support_variable_declarations_in_C
Farouk-Echaref May 6, 2024
face851
revert to previous changes
Farouk-Echaref May 6, 2024
7adc801
set the appropriate datatype for the STC container & use STC Vector m…
Farouk-Echaref May 6, 2024
3270d83
use of maxsplit argument to optimize splitting
Farouk-Echaref May 7, 2024
3e2e7f2
fix: set the right import filename
Farouk-Echaref May 7, 2024
0a1f959
Merge branch 'devel' into Support_variable_declarations_in_C
Farouk-Echaref May 9, 2024
78fb75a
make pyccel.extension module
Farouk-Echaref May 10, 2024
1729f8a
prototype of treating external libraries
Farouk-Echaref May 10, 2024
042fbbf
prototype of treating external libraries: copying STC to the destinat…
Farouk-Echaref May 10, 2024
c89043d
print the init assignement of the vector
Farouk-Echaref May 10, 2024
52b5e7e
Use of c_init prototype
Farouk-Echaref May 15, 2024
b84f1f1
fix printing of c_init
Farouk-Echaref May 15, 2024
f4125ad
fix name conflict in importing external library
Farouk-Echaref May 15, 2024
c29f170
Fix Codacy Problem.
May 15, 2024
948be19
Rename list_to_vector to init_lists_or_sets to declare both of them w…
May 15, 2024
4e2bf03
Fix printing in case there are no arguments.
May 15, 2024
d08f8cd
Delete test file.
May 16, 2024
1245b3c
Merge branch 'devel' into Support_variable_declarations_in_C
May 16, 2024
51cdaf2
Bad Merge
May 16, 2024
ee8c9bb
Remove a empty lines.
May 16, 2024
ef38120
Remove a empty lines.
May 16, 2024
64aeff6
import hset STC header file
Farouk-Echaref May 17, 2024
9b528bf
Deprecate unused line.
May 17, 2024
f843b05
Add test
May 17, 2024
0bc5bff
unused external field
Farouk-Echaref May 17, 2024
12c2120
Merge branch 'Support_variable_declarations_in_C' of https://github.c…
Farouk-Echaref May 17, 2024
a4c1727
revert to old changes
Farouk-Echaref May 17, 2024
8127301
update the reason to skip test for fortran
Farouk-Echaref May 17, 2024
e87dbf1
disable unused var
Farouk-Echaref May 17, 2024
cab1cc9
chore: revert to old changes
Farouk-Echaref May 17, 2024
0576da7
feat: tests for different datatypes in list and set declarations, int…
Farouk-Echaref May 17, 2024
e557d45
set can't have duplicates
Farouk-Echaref May 17, 2024
a6b4704
ignore pylint warning for using duplicate in set test
Farouk-Echaref May 21, 2024
e910c60
feat: use of i_type macro => The i_type macro is used to construct th…
Farouk-Echaref May 21, 2024
e97c97e
Merge branch 'devel' into Support_variable_declarations_in_C
Farouk-Echaref May 23, 2024
4c7f8ec
fix: silent pylint warning to test duplicate value in set
Farouk-Echaref May 24, 2024
dd2af8b
fix comment: check in an "external lib" is needed
Farouk-Echaref May 24, 2024
283018f
fix: specify an encoding for open()
Farouk-Echaref May 24, 2024
b8b1b2a
fix: indentation and use of get() for dictionaries
Farouk-Echaref May 24, 2024
aa539e7
fix: use property decorator to access protected member _name
Farouk-Echaref May 24, 2024
9b53a28
fix: docstring for the init method
Farouk-Echaref May 24, 2024
b16a967
fix: unsubscriptable-object pylint error
Farouk-Echaref May 24, 2024
ab30ea0
fix doc
Farouk-Echaref May 24, 2024
64249ca
Fix Error in Print Module Header for classes
May 24, 2024
b05a669
The function is renamed in the _Print_Module instead of _Print_Module…
May 27, 2024
4a5aa9c
feat: print the deallocation of a STC container using container_X_dro…
Farouk-Echaref May 28, 2024
9dc7d46
feat: test list and set declarations without type annotations
Farouk-Echaref May 28, 2024
a3fe045
Make some tests as xfail because C does not support list indexing yet.
May 29, 2024
8174549
Make some tests as xfail because C does not support list indexing yet.
May 29, 2024
5af4955
Merge remote-tracking branch 'refs/remotes/origin/Support_variable_de…
May 29, 2024
f8132d4
Add related issue in xfail comments.
May 29, 2024
3dc4d5c
correct the path for STC.
May 29, 2024
1b0c043
Merge branch 'devel' into Support_variable_declarations_in_C
Farouk-Echaref May 29, 2024
863a1a1
Fix import STC folder.
May 29, 2024
1132b5d
Merge branch 'Support_variable_declarations_in_C' of https://github.c…
May 29, 2024
3ff3125
update changelog.
May 29, 2024
038bb39
update comment of copying external library
Farouk-Echaref May 29, 2024
ba24ebc
add or delete empty lines
Farouk-Echaref May 29, 2024
bf4fb34
Fix import of STC
May 30, 2024
93b52b8
Fix STC import.
May 30, 2024
b162d9d
fix: add decorator to skip fortran tests
Farouk-Echaref May 30, 2024
2e788a5
fix: construct the right macros
Farouk-Echaref May 30, 2024
8684133
fix: get the right container type to construct the drop() method
Farouk-Echaref May 30, 2024
27de41d
feat: test a list of embedded complex
Farouk-Echaref May 30, 2024
311150c
fix: list indexing tests marked as xfail for C language
Farouk-Echaref Jun 3, 2024
60afc9f
fix: get the right python name for the import
Farouk-Echaref Jun 3, 2024
c47d459
fix: rename the imported files
Farouk-Echaref Jun 4, 2024
8ddba14
chore: fix trailing whitespaces and empty lines
Farouk-Echaref Jun 4, 2024
700f254
fix: Lists wrapping issues
Farouk-Echaref Jun 4, 2024
c7d76e8
fix: comprehension list test in a different module
Farouk-Echaref Jun 4, 2024
55d03e6
chore: add docstring for rename_imported_methods function
Farouk-Echaref Jun 4, 2024
1c2a51a
trailing whitespace
Farouk-Echaref Jun 4, 2024
758de51
final newline
Farouk-Echaref Jun 4, 2024
9896729
enhance: map external libs to their path to avoid static lookup
Farouk-Echaref Jun 5, 2024
e4c4f3a
deprecated: import_stc map is no longer used
Farouk-Echaref Jun 5, 2024
296ca4e
update wrapper error message
Farouk-Echaref Jun 5, 2024
378ade6
test case for list comprehensions will start in alphabetic order
Farouk-Echaref Jun 5, 2024
749d5e5
rename function that initializes stc containers
Farouk-Echaref Jun 6, 2024
4196bcd
fix: raise an error from the codegen stage to handle the generic assi…
Farouk-Echaref Jun 6, 2024
9417035
fix: separate between ndarrays and the rest of the containers
Farouk-Echaref Jun 6, 2024
c7d984c
fix: update error message in wrapper
Farouk-Echaref Jun 6, 2024
32cbe96
fix: update error message in wrapper
Farouk-Echaref Jun 6, 2024
7962368
Merge branch 'Support_variable_declarations_in_C' of https://github.c…
Farouk-Echaref Jun 6, 2024
9872a5b
fix: update error message in wrapper
Farouk-Echaref Jun 6, 2024
674da24
update changelog
Farouk-Echaref Jun 7, 2024
c865d8e
avoid code duplication by grouping the renaming proccess of class met…
Farouk-Echaref Jun 7, 2024
d0c218b
getter property to retrieve the name of a pyccel type
Farouk-Echaref Jun 7, 2024
1e98867
fix bad indentation
Farouk-Echaref Jun 7, 2024
3765e6b
update issue description in changelog
Farouk-Echaref Jun 7, 2024
262e303
element_type instead of vec_dtype
Farouk-Echaref Jun 7, 2024
cc73b94
use of f-string
Farouk-Echaref Jun 7, 2024
8defc58
can't return dtype after fatal error
Farouk-Echaref Jun 7, 2024
edfb455
Merge branch 'devel' into Support_variable_declarations_in_C
Farouk-Echaref Jun 7, 2024
e620bc4
generalize the use of find_in_type_registry
Farouk-Echaref Jun 7, 2024
6d07beb
retrieve the correct stc container type for deallocation
Farouk-Echaref Jun 7, 2024
f9a7fb0
using a generator expression instead of a list comprehension inside t…
Farouk-Echaref Jun 7, 2024
16b721c
fix: PythonSet removed from builtin_functions_dict
Farouk-Echaref Jun 7, 2024
38d214c
fix: use of __eq__ method to compare list and set objects
Farouk-Echaref Jun 7, 2024
4bb4b5d
chore: trailing whitespace
Farouk-Echaref Jun 7, 2024
9f130af
chore: trailing whitespace
Farouk-Echaref Jun 7, 2024
b8bcfdc
chore: trailing whitespace
Farouk-Echaref Jun 7, 2024
48eddce
chore: trailing whitespace
Farouk-Echaref Jun 7, 2024
f3b368b
fix: lists and sets are not restricted to a rank of 15
Farouk-Echaref Jun 7, 2024
1134b8e
fix: check on supported containers only, to not conflict Dict and Cud…
Farouk-Echaref Jun 10, 2024
cd22d95
fix: add related issues to xfail, and update tests fixtures
Farouk-Echaref Jun 10, 2024
d0d055a
fix: typo in test
Farouk-Echaref Jun 10, 2024
211d99a
fix: pylint issues
Farouk-Echaref Jun 10, 2024
7d253d1
feat: test declaring an empty annotated list
Farouk-Echaref Jun 10, 2024
59e39e8
chore: duplicate import
Farouk-Echaref Jun 10, 2024
8b4fa11
update docs
Farouk-Echaref Jun 11, 2024
4992779
expr.target is unused
Farouk-Echaref Jun 11, 2024
5c72144
use of print to retrieve the container name
Farouk-Echaref Jun 11, 2024
c381e60
update error docstring
Farouk-Echaref Jun 11, 2024
fa58673
Merge branch 'devel' into Support_variable_declarations_in_C
Farouk-Echaref Jun 11, 2024
616deda
Merge branch 'devel' into Support_variable_declarations_in_C
EmilyBourne Jun 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions pyccel/ast/builtins.py
Original file line number Diff line number Diff line change
Expand Up @@ -1231,6 +1231,7 @@ def print_string(self):
'min' : PythonMin,
'not' : PyccelNot,
'map' : PythonMap,
'set' : PythonSet,
EmilyBourne marked this conversation as resolved.
Show resolved Hide resolved
'str' : LiteralString,
'type' : PythonType,
'tuple' : PythonTupleFunction,
Expand Down
4 changes: 2 additions & 2 deletions pyccel/ast/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
Concatenate, Module, PyccelFunctionDef)

from .builtins import (builtin_functions_dict,
PythonRange, PythonList, PythonTuple)
PythonRange, PythonList, PythonTuple, PythonSet)
from .cmathext import cmath_mod
from .datatypes import HomogeneousTupleType, PythonNativeInt
from .internals import PyccelFunction, Slice
Expand Down Expand Up @@ -409,7 +409,7 @@ def collect_loops(block, indices, new_index, language_has_vectors = False, resul
if result is None:
result = []
current_level = 0
array_creator_types = (Allocate, PythonList, PythonTuple, Concatenate, Duplicate)
array_creator_types = (Allocate, PythonList, PythonTuple, Concatenate, Duplicate, PythonSet)
is_function_call = lambda f: ((isinstance(f, FunctionCall) and not f.funcdef.is_elemental)
or (isinstance(f, PyccelFunction) and not f.is_elemental and not hasattr(f, '__getitem__')
and not isinstance(f, (NumpyTranspose))))
Expand Down
12 changes: 6 additions & 6 deletions pyccel/codegen/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,19 +216,19 @@ def export(self, filename):
header_filename = f'{filename}.{header_ext}'
filename = f'{filename}.{ext}'

# print module
code = self._printer.doprint(self.ast)
with open(filename, 'w') as f:
for line in code:
f.write(line)

# print module header
if header_ext is not None:
code = self._printer.doprint(ModuleHeader(self.ast))
with open(header_filename, 'w') as f:
for line in code:
f.write(line)

# print module
code = self._printer.doprint(self.ast)
with open(filename, 'w') as f:
for line in code:
f.write(line)

# print program
prog_filename = None
if self.is_program and self.language != 'python':
Expand Down
9 changes: 9 additions & 0 deletions pyccel/codegen/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from pyccel.codegen.utilities import recompile_object
from pyccel.codegen.utilities import copy_internal_library
from pyccel.codegen.utilities import internal_libs
from pyccel.codegen.utilities import external_libs
from pyccel.codegen.python_wrapper import create_shared_library
from pyccel.naming import name_clash_checkers
from pyccel.utilities.stage import PyccelStage
Expand Down Expand Up @@ -334,6 +335,14 @@ def handle_error(stage):

mod_obj.add_dependencies(stdlib)


# Iterate over the external_libs list and determine if the printer
# requires an internal lib to be included.
for ext_lib_name, ext_src_folder in external_libs.items():
if ext_lib_name in codegen.get_printer_imports():

lib_dest_path = copy_internal_library(ext_src_folder, pyccel_dirpath)

if convert_only:
# Change working directory back to starting point
os.chdir(base_dirpath)
Expand Down
63 changes: 52 additions & 11 deletions pyccel/codegen/printing/ccode.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

from pyccel.ast.basic import ScopedAstNode

from pyccel.ast.builtins import PythonRange, PythonComplex, DtypePrecisionToCastFunction
from pyccel.ast.builtins import PythonRange, PythonComplex
from pyccel.ast.builtins import PythonPrint, PythonType
from pyccel.ast.builtins import PythonList, PythonTuple
from pyccel.ast.builtins import PythonList, PythonTuple, PythonSet

from pyccel.ast.core import Declare, For, CodeBlock
from pyccel.ast.core import FuncAddressDeclare, FunctionCall, FunctionCallArgument
Expand All @@ -27,7 +27,7 @@

from pyccel.ast.datatypes import PythonNativeInt, PythonNativeBool, VoidType
from pyccel.ast.datatypes import TupleType, FixedSizeNumericType
from pyccel.ast.datatypes import CustomDataType, StringType, HomogeneousTupleType
from pyccel.ast.datatypes import CustomDataType, StringType, HomogeneousTupleType, HomogeneousListType, HomogeneousSetType
from pyccel.ast.datatypes import PrimitiveBooleanType, PrimitiveIntegerType, PrimitiveFloatingPointType, PrimitiveComplexType
from pyccel.ast.datatypes import HomogeneousContainerType

Expand Down Expand Up @@ -225,6 +225,10 @@

import_dict = {'omp_lib' : 'omp' }

import_stc = {'hset' : 'SET',
jalalium marked this conversation as resolved.
Show resolved Hide resolved
'vec' : 'VEC'
}

c_imports = {n : Import(n, Module(n, (), ())) for n in
['stdlib',
'math',
Expand Down Expand Up @@ -810,8 +814,8 @@ def _print_Module(self, expr):
global_variables = ''.join([self._print(d) for d in expr.declarations])

# Print imports last to be sure that all additional_imports have been collected
imports = [Import(self.scope.get_python_name(expr.name), Module(expr.name,(),())), *self._additional_imports.values()]
imports = ''.join(self._print(i) for i in imports)
imports = Import(expr.name, Module(expr.name,(),()))
imports = self._print(imports)

code = ('{imports}\n'
'{variables}\n'
Expand Down Expand Up @@ -947,6 +951,20 @@ def _print_Import(self, expr):
source = source.name[-1]
else:
source = self._print(source)
if expr.target:
dtype = expr.target.pop().name
if source.startswith('stc/'):
dtype_macro = dtype.upper()
_,container_type = source.split("/")
if container_type in import_stc:
class_type_macro = import_stc[container_type]
additional_defines = '#define i_use_cmp\n' if class_type_macro == 'VEC' else ''
return '\n'.join((f'#ifndef _{class_type_macro}_{dtype_macro}',
f'#define _{class_type_macro}_{dtype_macro}',
f'#define i_key {dtype}',
additional_defines,
f'#include "{source}.h"',
f'#endif\n'))

# Get with a default value is not used here as it is
# slower and on most occasions the import will not be in the
Expand Down Expand Up @@ -1163,6 +1181,13 @@ def find_in_dtype_registry(self, dtype):
return 'bool'

key = (primitive_type, dtype.precision)
elif isinstance(dtype, (HomogeneousSetType, HomogeneousListType)):
container_type = 'hset_' if dtype._name == 'set' else 'vec_'
vec_dtype = self.find_in_dtype_registry(dtype.element_type)
key = container_type + vec_dtype
source = 'stc/'+ container_type[:-1]
self.add_import(Import(source, Module(vec_dtype, (), ())))
return key
else:
key = dtype

Expand Down Expand Up @@ -1241,6 +1266,9 @@ def get_declare_type(self, expr):
if expr.is_ndarray or isinstance(expr.class_type, HomogeneousContainerType):
if expr.rank > 15:
jalalium marked this conversation as resolved.
Show resolved Hide resolved
errors.report(UNSUPPORTED_ARRAY_RANK, symbol=expr, severity='fatal')
if isinstance(expr.class_type, (HomogeneousSetType, HomogeneousListType)):
dtype = self.find_in_dtype_registry(expr.class_type)
return dtype
self.add_import(c_imports['ndarrays'])
dtype = 't_ndarray'
else:
Expand Down Expand Up @@ -1525,6 +1553,8 @@ def _print_PyccelArrayShapeElement(self, expr):
def _print_Allocate(self, expr):
free_code = ''
variable = expr.variable
if isinstance(variable.class_type, (HomogeneousListType, HomogeneousSetType)):
return ''
if variable.rank > 0:
#free the array if its already allocated and checking if its not null if the status is unknown
if (expr.status == 'unknown'):
Expand Down Expand Up @@ -1963,6 +1993,20 @@ def _print_FunctionCall(self, expr):
else:
return call_code

def init_lists_or_sets(self, expr, list_var):
"""
Print the initialization of a python assignment using STC init() method
"""
dtype = self.find_in_dtype_registry(expr.current_user_node.lhs.dtype)
container_type = "hset_"if isinstance(expr.class_type, HomogeneousSetType) else "vec_"
if (len(expr.args) == 0):
return f'{list_var} = c_init({container_type}{dtype},{"{}"});\n'

keyraw = '{' + ', '.join([self._print(a) for a in expr.args]) + '}'
EmilyBourne marked this conversation as resolved.
Show resolved Hide resolved
init = f'{list_var} = c_init({container_type}{dtype}, {keyraw});\n'

return init

def _print_Return(self, expr):
code = ''
args = [ObjectAddress(a) if isinstance(a, Variable) and self.is_c_pointer(a) else a for a in expr.expr]
Expand Down Expand Up @@ -2105,6 +2149,8 @@ def _print_Assign(self, expr):
if isinstance(rhs, (NumpyFull)):
return prefix_code+self.arrayFill(expr)
lhs = self._print(expr.lhs)
if isinstance(rhs, (PythonList, PythonSet)):
return prefix_code+self.init_lists_or_sets(rhs, lhs)
rhs = self._print(expr.rhs)
return prefix_code+'{} = {};\n'.format(lhs, rhs)

Expand Down Expand Up @@ -2307,19 +2353,14 @@ def _print_Constant(self, expr):
if expr == math_constants['inf']:
self.add_import(c_imports['math'])
return 'HUGE_VAL'
elif expr == math_constants['nan']:
self.add_import(c_imports['math'])
return 'NAN'
elif expr == math_constants['pi']:
self.add_import(c_imports['math'])
return 'M_PI'
elif expr == math_constants['e']:
self.add_import(c_imports['math'])
return 'M_E'
else:
cast_func = DtypePrecisionToCastFunction[expr.dtype]
return self._print(cast_func(expr.value))

raise NotImplementedError("Constant not implemented")

def _print_Variable(self, expr):
if self.is_c_pointer(expr):
Expand Down
17 changes: 15 additions & 2 deletions pyccel/codegen/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,26 @@
import shutil
from filelock import FileLock
import pyccel.stdlib as stdlib_folder
import pyccel.extensions as ext_folder

from .compiling.basic import CompileObj

# get path to pyccel/stdlib/lib_name
stdlib_path = os.path.dirname(stdlib_folder.__file__)

# get path to pyccel/extensions/lib_name
ext_path = os.path.dirname(ext_folder.__file__)

__all__ = ['copy_internal_library','recompile_object']

#==============================================================================
language_extension = {'fortran':'f90', 'c':'c', 'python':'py'}

#==============================================================================
# map external libraries to their folders inside pyccel/extensions
external_libs = {"stc/vec" : "stc",
"stc/hset" : "stc",}

#==============================================================================
# map internal libraries to their folders inside pyccel/stdlib and their compile objects
# The compile object folder will be in the pyccel dirpath
Expand Down Expand Up @@ -101,8 +110,12 @@ def copy_internal_library(lib_folder, pyccel_dirpath, extra_files = None):
str
The location that the files were copied to.
"""
# get lib path (stdlib_path/lib_name)
lib_path = os.path.join(stdlib_path, lib_folder)
# get lib path (stdlib_path/lib_name or ext_path/lib_name)
if lib_folder == "stc":
lib_path = os.path.join(ext_path, "STC", "include", lib_folder)
else:
lib_path = os.path.join(stdlib_path, lib_folder)

# remove library folder to avoid missing files and copy
# new one from pyccel stdlib
lib_dest_path = os.path.join(pyccel_dirpath, lib_folder)
Expand Down
Empty file added pyccel/extensions/__init__.py
Empty file.
9 changes: 5 additions & 4 deletions pyccel/parser/semantic.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
from pyccel.ast.class_defs import NumpyArrayClass, TupleClass, get_cls_base

from pyccel.ast.datatypes import CustomDataType, PyccelType, TupleType, VoidType, GenericType
from pyccel.ast.datatypes import PrimitiveIntegerType, HomogeneousListType, StringType, SymbolicType
from pyccel.ast.datatypes import PrimitiveIntegerType, HomogeneousListType, StringType, SymbolicType, HomogeneousSetType
from pyccel.ast.datatypes import PythonNativeBool, PythonNativeInt, PythonNativeFloat
from pyccel.ast.datatypes import DataTypeFactory, PrimitiveFloatingPointType
from pyccel.ast.datatypes import InhomogeneousTupleType, HomogeneousTupleType
Expand Down Expand Up @@ -1615,7 +1615,7 @@ def _ensure_inferred_type_matches_existing(self, class_type, d_var, var, is_auga
# to remove memory leaks
new_expressions.append(Deallocate(var))

elif class_type != var.class_type:
elif class_type != var.class_type and not isinstance(class_type.datatype, GenericType):
EmilyBourne marked this conversation as resolved.
Show resolved Hide resolved
if is_augassign:
tmp_result = PyccelAdd(var, rhs)
result_type = tmp_result.class_type
Expand Down Expand Up @@ -1917,8 +1917,7 @@ def _get_indexed_type(self, base, args, expr):
else:
raise errors.report(f"Unknown annotation base {base}\n"+PYCCEL_RESTRICTION_TODO,
severity='fatal', symbol=expr)
rank = 1
if len(args) == 2 and args[1] is LiteralEllipsis():
if len(args) > 0:
EmilyBourne marked this conversation as resolved.
Show resolved Hide resolved
syntactic_annotation = args[0]
if not isinstance(syntactic_annotation, SyntacticTypeAnnotation):
pyccel_stage.set_stage('syntactic')
Expand All @@ -1930,6 +1929,8 @@ def _get_indexed_type(self, base, args, expr):
class_type = HomogeneousTupleType
elif dtype_cls is PythonList:
class_type = HomogeneousListType
elif dtype_cls is PythonSet:
class_type = HomogeneousSetType
EmilyBourne marked this conversation as resolved.
Show resolved Hide resolved
else:
raise errors.report(f"Unknown annotation base {base}\n"+PYCCEL_RESTRICTION_TODO,
severity='fatal', symbol=expr)
Expand Down
17 changes: 17 additions & 0 deletions tests/epyccel/test_epyccel_variable_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,20 @@

assert epyc_homogeneous_tuple_annotation() == homogeneous_tuple_annotation()
assert isinstance(epyc_homogeneous_tuple_annotation(), type(homogeneous_tuple_annotation()))

@pytest.mark.parametrize( 'language', [
pytest.param("c", marks = pytest.mark.c),
pytest.param("fortran", marks = [
pytest.mark.skip(reason="append() not implemented in fortran"),
EmilyBourne marked this conversation as resolved.
Show resolved Hide resolved
pytest.mark.fortran]),
pytest.param("python", marks = pytest.mark.python)
]
)

def test_homogeneous_set_annotation_int(language):
def homogeneous_set_annotation ():
a : set[int]

Check warning on line 181 in tests/epyccel/test_epyccel_variable_annotations.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

tests/epyccel/test_epyccel_variable_annotations.py#L181

Unused variable 'a'
EmilyBourne marked this conversation as resolved.
Show resolved Hide resolved
a = {1, 2, 3, 4}
epyc_homogeneous_set_annotation = epyccel(homogeneous_set_annotation, language=language)
assert epyc_homogeneous_set_annotation() == homogeneous_set_annotation()
assert isinstance(epyc_homogeneous_set_annotation(), type(homogeneous_set_annotation()))

Check notice on line 185 in tests/epyccel/test_epyccel_variable_annotations.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

tests/epyccel/test_epyccel_variable_annotations.py#L185

Final newline missing