-
Notifications
You must be signed in to change notification settings - Fork 171
Enable C test for test_math.py
#1357
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
base: main
Are you sure you want to change the base?
Changes from all commits
c9ef293
a8ab745
90a8fe1
45b1b3b
f1b31d8
d5517c2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4864,13 +4864,30 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> { | |
} | ||
} else if (ASR::is_a<ASR::Module_t>(*t)) { | ||
ASR::Module_t *m = ASR::down_cast<ASR::Module_t>(t); | ||
std::string sym_name = value + "@" + x.m_attr; | ||
std::string sym_name = value + "_" + x.m_attr + "_external__"; | ||
ASR::symbol_t *sym = current_scope->resolve_symbol(sym_name); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we insert this in the global scope itself? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not needed IMO. Otherwise it would get declared in global scope in the C code as well and will mix things up with other scopes. |
||
if (!sym) { | ||
sym = import_from_module(al, m, current_scope, value, | ||
x.m_attr, sym_name, x.base.base.loc, false); | ||
LFORTRAN_ASSERT(ASR::is_a<ASR::ExternalSymbol_t>(*sym)); | ||
current_scope->add_symbol(sym_name, sym); | ||
} else { | ||
if( ASR::is_a<ASR::ExternalSymbol_t>(*sym) ) { | ||
ASR::ExternalSymbol_t* ext_sym = ASR::down_cast<ASR::ExternalSymbol_t>(sym); | ||
if( ext_sym->m_external != m->m_symtab->resolve_symbol(std::string(x.m_attr)) ) { | ||
sym_name = current_scope->get_unique_name(sym_name); | ||
sym = import_from_module(al, m, current_scope, value, | ||
x.m_attr, sym_name, x.base.base.loc, false); | ||
LFORTRAN_ASSERT(ASR::is_a<ASR::ExternalSymbol_t>(*sym)); | ||
current_scope->add_symbol(sym_name, sym); | ||
} | ||
} else { | ||
sym_name = current_scope->get_unique_name(sym_name); | ||
sym = import_from_module(al, m, current_scope, value, | ||
x.m_attr, sym_name, x.base.base.loc, false); | ||
LFORTRAN_ASSERT(ASR::is_a<ASR::ExternalSymbol_t>(*sym)); | ||
current_scope->add_symbol(sym_name, sym); | ||
} | ||
} | ||
tmp = ASR::make_Var_t(al, x.base.base.loc, sym); | ||
} else { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -563,10 +563,19 @@ def _lfortran_dtan(x: f64) -> f64: | |
def tan(x: f64) -> f64: | ||
return _lfortran_dtan(x) | ||
|
||
@ccall | ||
def _lfortran_slog(x: f32) -> f32: | ||
pass | ||
|
||
@overload | ||
def log(x: f32) -> f32: | ||
return _lfortran_slog(x) | ||
|
||
@ccall | ||
def _lfortran_dlog(x: f64) -> f64: | ||
pass | ||
|
||
@overload | ||
def log(x: f64) -> f64: | ||
return _lfortran_dlog(x) | ||
|
||
|
@@ -682,21 +691,43 @@ def atanh(x: f64) -> f64: | |
def expm1(x: f64) -> f64: | ||
return exp(x) - 1.0 | ||
|
||
@ccall | ||
def _lfortran_slog1p(x: f32) -> f32: | ||
pass | ||
|
||
@overload | ||
def log1p(x: f32) -> f32: | ||
return _lfortran_slog1p(x) | ||
|
||
@ccall | ||
def _lfortran_dlog1p(x: f64) -> f64: | ||
pass | ||
|
||
@overload | ||
def log1p(x: f64) -> f64: | ||
return log(1.0 + x) | ||
return _lfortran_dlog1p(x) | ||
|
||
|
||
@ccall | ||
def _lfortran_dfmod(x: f64, y: f64) -> f64: | ||
pass | ||
|
||
@overload | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is kind of hacky and shouldn't we use some name tweaks at the ASR level? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess overload just does that. We can do it by hand but that will be needed only for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The other way is to do it for every imported symbol. For example, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This sounds better to me. The reason is that the users might not be aware of this and may end up writing a function without an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did a more sensible change (by implementing log for f32, fmod for (f32, f32) and log1p for f32). So the overloads make sense now.
This is not possible actually because call names won't resolve correctly. This is a problem on our compiler's end and I fixed it by implementing, log and fmod correctly. |
||
def fmod(x: f64, y: f64) -> f64: | ||
if y == 0.0: | ||
raise ValueError('math domain error') | ||
return _lfortran_dfmod(x, y) | ||
|
||
|
||
@ccall | ||
def _lfortran_dfmod(x: f64, y: f64) -> f64: | ||
def _lfortran_sfmod(x: f32, y: f32) -> f32: | ||
pass | ||
|
||
@overload | ||
def fmod(x: f32, y: f32) -> f32: | ||
if y == f32(0.0): | ||
raise ValueError('math domain error') | ||
return _lfortran_sfmod(x, y) | ||
|
||
|
||
def remainder(x: f64, y: f64) -> f64: | ||
q: i64 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we have to be careful here.
What happens if
v_ext->m_name
is equal to "x" and then we have another variable like "expr, will the
x` in it be substituted? I think it will be, so we do not want to do that. Also we do not want to have any such macro defines in header files. We currently do not generate them, but eventually we will.I would not use C macros.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So constant C variables should work for this case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either that, or we can initialize the global variables when the program starts. I think both seems better than macros.