Skip to content

Commit 7850aa4

Browse files
committed
Initial sync commit
1 parent 8f62ac4 commit 7850aa4

36 files changed

+1964
-494
lines changed

src/libasr/ASR.asdl

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ stmt
163163
| Associate(expr target, expr value)
164164
| Cycle()
165165
-- deallocates if allocated otherwise throws a runtime error
166-
| ExplicitDeallocate(symbol* vars)
166+
| ExplicitDeallocate(expr* vars)
167167
-- deallocates if allocated otherwise does nothing
168168
| ImplicitDeallocate(symbol* vars)
169169
| DoConcurrentLoop(do_loop_head head, stmt* body)
@@ -286,6 +286,7 @@ expr
286286
| ArrayPack(expr array, expr mask, expr? vector, ttype type, expr? value)
287287
| ArrayReshape(expr array, expr shape, ttype type, expr? value)
288288
| ArrayMaxloc(expr array, expr? dim, expr? mask, expr? kind, expr? back, ttype type, expr? value)
289+
| ArrayAll(expr mask, expr? dim, ttype type, expr? value)
289290

290291
| BitCast(expr source, expr mold, expr? size, ttype type, expr? value)
291292
| StructInstanceMember(expr v, symbol m, ttype type, expr? value)
@@ -318,6 +319,8 @@ expr
318319
| PointerNullConstant(ttype type)
319320
| PointerAssociated(expr ptr, expr? tgt, ttype type, expr? value)
320321

322+
| IntrinsicFunctionSqrt(expr arg, ttype type, expr? value)
323+
321324

322325
-- `len` in Character:
323326
-- >=0 ... the length of the string, known at compile time
@@ -357,9 +360,9 @@ ttype
357360
| CPtr()
358361
| TypeParameter(identifier param, dimension* dims)
359362
| FunctionType(ttype* arg_types, ttype? return_var_type,
360-
abi abi, deftype deftype, string? bindc_name, bool elemental,
361-
bool pure, bool module, bool inline, bool static, ttype* type_params,
362-
symbol* restrictions, bool is_restriction)
363+
abi abi, deftype deftype, string? bindc_name, bool elemental,
364+
bool pure, bool module, bool inline, bool static, ttype* type_params,
365+
symbol* restrictions, bool is_restriction)
363366

364367
restriction_arg = RestrictionArg(identifier restriction_name, symbol restriction_func)
365368

@@ -399,7 +402,7 @@ cast_kind
399402

400403
dimension = (expr? start, expr? length)
401404

402-
alloc_arg = (symbol a, dimension* dims)
405+
alloc_arg = (expr a, dimension* dims)
403406

404407
attribute = Attribute(identifier name, attribute_arg *args)
405408

@@ -415,7 +418,7 @@ do_loop_head = (expr? v, expr? start, expr? end, expr? increment)
415418

416419
case_stmt = CaseStmt(expr* test, stmt* body) | CaseStmt_Range(expr? start, expr? end, stmt* body)
417420

418-
type_stmt = TypeStmt(symbol sym, stmt* body)
421+
type_stmt = TypeStmtName(symbol sym, stmt* body) | TypeStmtType(ttype type, stmt* body)
419422

420423
enumtype = IntegerConsecutiveFromZero | IntegerUnique | IntegerNotUnique | NonInteger
421424

src/libasr/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ set(SRC
3636
pass/implied_do_loops.cpp
3737
pass/array_op.cpp
3838
pass/subroutine_from_function.cpp
39+
pass/transform_optional_argument_functions.cpp
3940
pass/class_constructor.cpp
4041
pass/arr_slice.cpp
4142
pass/print_arr.cpp

src/libasr/asdl_cpp.py

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -797,9 +797,11 @@ class ExprStmtDuplicatorVisitor(ASDLVisitor):
797797
def __init__(self, stream, data):
798798
self.duplicate_stmt = []
799799
self.duplicate_expr = []
800+
self.duplicate_ttype = []
800801
self.duplicate_case_stmt = []
801802
self.is_stmt = False
802803
self.is_expr = False
804+
self.is_ttype = False
803805
self.is_case_stmt = False
804806
self.is_product = False
805807
super(ExprStmtDuplicatorVisitor, self).__init__(stream, data)
@@ -834,6 +836,13 @@ def visitModule(self, mod):
834836
self.duplicate_expr.append(("", 0))
835837
self.duplicate_expr.append((" switch(x->type) {", 1))
836838

839+
self.duplicate_ttype.append((" ASR::ttype_t* duplicate_ttype(ASR::ttype_t* x) {", 0))
840+
self.duplicate_ttype.append((" if( !x ) {", 1))
841+
self.duplicate_ttype.append((" return nullptr;", 2))
842+
self.duplicate_ttype.append((" }", 1))
843+
self.duplicate_ttype.append(("", 0))
844+
self.duplicate_ttype.append((" switch(x->type) {", 1))
845+
837846
self.duplicate_case_stmt.append((" ASR::case_stmt_t* duplicate_case_stmt(ASR::case_stmt_t* x) {", 0))
838847
self.duplicate_case_stmt.append((" if( !x ) {", 1))
839848
self.duplicate_case_stmt.append((" return nullptr;", 2))
@@ -858,6 +867,14 @@ def visitModule(self, mod):
858867
self.duplicate_expr.append((" return nullptr;", 1))
859868
self.duplicate_expr.append((" }", 0))
860869

870+
self.duplicate_ttype.append((" default: {", 2))
871+
self.duplicate_ttype.append((' LCOMPILERS_ASSERT_MSG(false, "Duplication of " + std::to_string(x->type) + " type is not supported yet.");', 3))
872+
self.duplicate_ttype.append((" }", 2))
873+
self.duplicate_ttype.append((" }", 1))
874+
self.duplicate_ttype.append(("", 0))
875+
self.duplicate_ttype.append((" return nullptr;", 1))
876+
self.duplicate_ttype.append((" }", 0))
877+
861878
self.duplicate_case_stmt.append((" default: {", 2))
862879
self.duplicate_case_stmt.append((' LCOMPILERS_ASSERT_MSG(false, "Duplication of " + std::to_string(x->type) + " case statement is not supported yet.");', 3))
863880
self.duplicate_case_stmt.append((" }", 2))
@@ -872,6 +889,9 @@ def visitModule(self, mod):
872889
for line, level in self.duplicate_expr:
873890
self.emit(line, level=level)
874891
self.emit("")
892+
for line, level in self.duplicate_ttype:
893+
self.emit(line, level=level)
894+
self.emit("")
875895
for line, level in self.duplicate_case_stmt:
876896
self.emit(line, level=level)
877897
self.emit("")
@@ -885,8 +905,9 @@ def visitType(self, tp):
885905
def visitSum(self, sum, *args):
886906
self.is_stmt = args[0] == 'stmt'
887907
self.is_expr = args[0] == 'expr'
908+
self.is_ttype = args[0] == "ttype"
888909
self.is_case_stmt = args[0] == 'case_stmt'
889-
if self.is_stmt or self.is_expr or self.is_case_stmt:
910+
if self.is_stmt or self.is_expr or self.is_case_stmt or self.is_ttype:
890911
for tp in sum.types:
891912
self.visit(tp, *args)
892913

@@ -933,6 +954,10 @@ def make_visitor(self, name, fields):
933954
self.duplicate_expr.append((" }", 3))
934955
self.duplicate_expr.append((" return down_cast<ASR::expr_t>(self().duplicate_%s(down_cast<ASR::%s_t>(x)));" % (name, name), 3))
935956
self.duplicate_expr.append((" }", 2))
957+
elif self.is_ttype:
958+
self.duplicate_ttype.append((" case ASR::ttypeType::%s: {" % name, 2))
959+
self.duplicate_ttype.append((" return down_cast<ASR::ttype_t>(self().duplicate_%s(down_cast<ASR::%s_t>(x)));" % (name, name), 3))
960+
self.duplicate_ttype.append((" }", 2))
936961
elif self.is_case_stmt:
937962
self.duplicate_case_stmt.append((" case ASR::case_stmtType::%s: {" % name, 2))
938963
self.duplicate_case_stmt.append((" return down_cast<ASR::case_stmt_t>(self().duplicate_%s(down_cast<ASR::%s_t>(x)));" % (name, name), 3))
@@ -949,7 +974,8 @@ def visitField(self, field):
949974
field.type == "do_loop_head" or
950975
field.type == "array_index" or
951976
field.type == "alloc_arg" or
952-
field.type == "case_stmt"):
977+
field.type == "case_stmt" or
978+
field.type == "ttype"):
953979
level = 2
954980
if field.seq:
955981
self.used = True
@@ -1107,10 +1133,12 @@ def visitField(self, field):
11071133
self.used = True
11081134
self.emit("for (size_t i = 0; i < x->n_%s; i++) {" % field.name, level)
11091135
if field.type == "call_arg":
1110-
self.emit(" ASR::expr_t** current_expr_copy_%d = current_expr;" % (self.current_expr_copy_variable_count), level)
1111-
self.emit(" current_expr = &(x->m_%s[i].m_value);" % (field.name), level)
1112-
self.emit(" self().replace_expr(x->m_%s[i].m_value);"%(field.name), level)
1113-
self.emit(" current_expr = current_expr_copy_%d;" % (self.current_expr_copy_variable_count), level)
1136+
self.emit(" if (x->m_%s[i].m_value != nullptr) {" % (field.name), level)
1137+
self.emit(" ASR::expr_t** current_expr_copy_%d = current_expr;" % (self.current_expr_copy_variable_count), level + 1)
1138+
self.emit(" current_expr = &(x->m_%s[i].m_value);" % (field.name), level + 1)
1139+
self.emit(" self().replace_expr(x->m_%s[i].m_value);"%(field.name), level + 1)
1140+
self.emit(" current_expr = current_expr_copy_%d;" % (self.current_expr_copy_variable_count), level + 1)
1141+
self.emit(" }", level)
11141142
self.current_expr_copy_variable_count += 1
11151143
self.emit("}", level)
11161144
else:
@@ -2310,6 +2338,8 @@ def make_visitor(self, name, fields):
23102338
LCOMPILERS_ASSERT(e->m_external);
23112339
LCOMPILERS_ASSERT(!ASR::is_a<ASR::ExternalSymbol_t>(*e->m_external));
23122340
s = e->m_external;
2341+
} else if (s->type == ASR::symbolType::Function) {
2342+
return ASR::down_cast<ASR::Function_t>(s)->m_function_signature;
23132343
}
23142344
return ASR::down_cast<ASR::Variable_t>(s)->m_type;
23152345
}""" \
@@ -2529,6 +2559,9 @@ def main(argv):
25292559
subs["MOD"] = "LPython::AST"
25302560
subs["mod"] = "ast"
25312561
subs["lcompiler"] = "lpython"
2562+
elif subs["MOD"] == "AST":
2563+
subs["MOD"] = "LFortran::AST"
2564+
subs["lcompiler"] = "lfortran"
25322565
else:
25332566
subs["lcompiler"] = "lfortran"
25342567
is_asr = (mod.name.upper() == "ASR")

0 commit comments

Comments
 (0)