Skip to content

Commit e3e580f

Browse files
authored
Merge pull request #124 from namannimmo10/set
Completes initial type annotations
2 parents eff76b5 + 5ce4dd7 commit e3e580f

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/lpython/semantics/python_ast_to_asr.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,28 @@ class CommonVisitor : public AST::BaseVisitor<Derived> {
216216
ASR::ttype_t *type = ASRUtils::TYPE(ASR::make_Tuple_t(al, loc,
217217
types.p, types.size()));
218218
return type;
219+
} else if (var_annotation == "set") {
220+
if (AST::is_a<AST::Name_t>(*s->m_slice)) {
221+
ASR::ttype_t *type = ast_expr_to_asr_type(loc, *s->m_slice);
222+
return ASRUtils::TYPE(ASR::make_Set_t(al, loc, type));
223+
} else {
224+
throw SemanticError("Only Name in Subscript supported for now in `set`"
225+
" annotation", loc);
226+
}
227+
} else if (var_annotation == "dict") {
228+
if (AST::is_a<AST::Tuple_t>(*s->m_slice)) {
229+
AST::Tuple_t *t = AST::down_cast<AST::Tuple_t>(s->m_slice);
230+
if (t->n_elts != 2) {
231+
throw SemanticError("`dict` annotation must have 2 elements: types"
232+
" of both keys and values", loc);
233+
}
234+
ASR::ttype_t *key_type = ast_expr_to_asr_type(loc, *t->m_elts[0]);
235+
ASR::ttype_t *value_type = ast_expr_to_asr_type(loc, *t->m_elts[1]);
236+
return ASRUtils::TYPE(ASR::make_Dict_t(al, loc, key_type, value_type));
237+
} else {
238+
throw SemanticError("`dict` annotation must have 2 elements: types of"
239+
" both keys and values", loc);
240+
}
219241
} else {
220242
ASR::dimension_t dim;
221243
dim.loc = loc;

src/runtime/ltypes/ltypes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
i64 = []
33
f32 = []
44
f64 = []
5+
c128 = []

0 commit comments

Comments
 (0)