Skip to content

Commit 413dd2d

Browse files
committed
Remove abs implementation from visit_Call
1 parent 6d70d82 commit 413dd2d

File tree

1 file changed

+0
-91
lines changed

1 file changed

+0
-91
lines changed

src/lpython/semantics/python_ast_to_asr.cpp

Lines changed: 0 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -2327,97 +2327,6 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
23272327
throw SemanticError(call_name + "() must have one integer argument",
23282328
x.base.base.loc);
23292329
}
2330-
} else if (call_name == "abs") {
2331-
if (args.size() != 1) {
2332-
throw SemanticError(call_name + "() takes exactly one argument (" +
2333-
std::to_string(args.size()) + " given)", x.base.base.loc);
2334-
}
2335-
std::string rl_path = get_runtime_library_dir();
2336-
SymbolTable *st = current_scope;
2337-
while (st->parent != nullptr) {
2338-
st = st->parent;
2339-
}
2340-
bool ltypes;
2341-
std::string msym = "lpython_builtin";
2342-
ASR::symbol_t *t = (ASR::symbol_t*)(load_module(al, st,
2343-
msym, x.base.base.loc, true, rl_path, ltypes,
2344-
[&](const std::string &msg, const Location &loc) { throw SemanticError(msg, loc); }
2345-
));
2346-
LFORTRAN_ASSERT(!ltypes)
2347-
if (!t) {
2348-
throw SemanticError("The module '" + msym + "' cannot be loaded",
2349-
x.base.base.loc);
2350-
}
2351-
2352-
ASR::Module_t *m = ASR::down_cast<ASR::Module_t>(t);
2353-
2354-
std::string local_sym = "abs";
2355-
t = m->m_symtab->resolve_symbol(local_sym);
2356-
if (!t) {
2357-
throw SemanticError("ICE: The symbol '" + local_sym + "' not found in the module '" + msym + "'",
2358-
x.base.base.loc);
2359-
}
2360-
if (ASR::is_a<ASR::Function_t>(*t)) {
2361-
if (current_scope->scope.find(local_sym) != current_scope->scope.end()) {
2362-
throw SemanticError("Function already defined",
2363-
x.base.base.loc);
2364-
}
2365-
ASR::Function_t *mfn = ASR::down_cast<ASR::Function_t>(t);
2366-
// `mfn` is the Function in a module. Now we construct
2367-
// an ExternalSymbol that points to it.
2368-
Str name;
2369-
name.from_str(al, local_sym);
2370-
char *cname = name.c_str(al);
2371-
ASR::asr_t *fn = ASR::make_ExternalSymbol_t(
2372-
al, mfn->base.base.loc,
2373-
/* a_symtab */ current_scope,
2374-
/* a_name */ cname,
2375-
(ASR::symbol_t*)mfn,
2376-
m->m_name, nullptr, 0, mfn->m_name,
2377-
ASR::accessType::Public
2378-
);
2379-
current_scope->scope[local_sym] = ASR::down_cast<ASR::symbol_t>(fn);
2380-
2381-
ASR::ttype_t *a_type = ASRUtils::TYPE(ASR::make_Real_t(al,
2382-
x.base.base.loc, 8, nullptr, 0));
2383-
tmp = ASR::make_FunctionCall_t(al, x.base.base.loc, ASR::down_cast<ASR::symbol_t>(fn),
2384-
nullptr, args.p, args.size(), nullptr, 0, a_type, nullptr, nullptr);
2385-
return;
2386-
} else {
2387-
throw SemanticError("ICE: Abs expected to be a function", x.base.base.loc);
2388-
}
2389-
// Compile time value implementation:
2390-
/*
2391-
ASR::expr_t* arg = ASRUtils::expr_value(args[0]);
2392-
ASR::ttype_t* t = ASRUtils::expr_type(arg);
2393-
ASR::ttype_t* real_type = ASRUtils::TYPE(ASR::make_Real_t(al,
2394-
x.base.base.loc, 8, nullptr, 0));
2395-
ASR::ttype_t *int_type = ASRUtils::TYPE(ASR::make_Integer_t(al,
2396-
x.base.base.loc, 4, nullptr, 0));
2397-
if (ASRUtils::is_real(*t)) {
2398-
double rv = ASR::down_cast<ASR::ConstantReal_t>(arg)->m_r;
2399-
double val = std::abs(rv);
2400-
tmp = ASR::make_ConstantReal_t(al, x.base.base.loc, val, t);
2401-
} else if (ASRUtils::is_integer(*t)) {
2402-
int64_t rv = ASR::down_cast<ASR::ConstantInteger_t>(arg)->m_n;
2403-
int64_t val = std::abs(rv);
2404-
tmp = ASR::make_ConstantInteger_t(al, x.base.base.loc, val, t);
2405-
} else if (ASRUtils::is_complex(*t)) {
2406-
double re = ASR::down_cast<ASR::ConstantComplex_t>(arg)->m_re;
2407-
double im = ASR::down_cast<ASR::ConstantComplex_t>(arg)->m_im;
2408-
std::complex<double> c(re, im);
2409-
double result = std::abs(c);
2410-
tmp = ASR::make_ConstantReal_t(al, x.base.base.loc, result, real_type);
2411-
} else if (ASRUtils::is_logical(*t)) {
2412-
bool rv = ASR::down_cast<ASR::ConstantLogical_t>(arg)->m_value;
2413-
int8_t val = rv ? 1 : 0;
2414-
tmp = ASR::make_ConstantInteger_t(al, x.base.base.loc, val, int_type);
2415-
} else {
2416-
throw SemanticError(call_name + "() must have one real, integer, complex, or logical argument",
2417-
x.base.base.loc);
2418-
}
2419-
return;
2420-
*/
24212330
} else if (call_name == "bool") {
24222331
if (args.size() != 1) {
24232332
throw SemanticError(call_name + "() takes exactly one argument (" +

0 commit comments

Comments
 (0)