Skip to content

Commit 4561537

Browse files
committed
Support i1 as bool alias
1 parent c050351 commit 4561537

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

src/lpython/semantics/python_ast_to_asr.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,7 +1076,7 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
10761076
} else if (var_annotation == "str") {
10771077
type = ASRUtils::TYPE(ASR::make_Character_t(al, loc, 1, -2, nullptr));
10781078
type = ASRUtils::make_Array_t_util(al, loc, type, dims.p, dims.size());
1079-
} else if (var_annotation == "bool") {
1079+
} else if (var_annotation == "bool" || var_annotation == "i1") {
10801080
type = ASRUtils::TYPE(ASR::make_Logical_t(al, loc, 4));
10811081
type = ASRUtils::make_Array_t_util(al, loc, type, dims.p, dims.size());
10821082
} else if (var_annotation == "CPtr") {
@@ -4446,11 +4446,11 @@ class SymbolTableVisitor : public CommonVisitor<SymbolTableVisitor> {
44464446
if (AST::is_a<AST::Name_t>(*x.m_targets[0])) {
44474447
std::string tvar_name = AST::down_cast<AST::Name_t>(x.m_targets[0])->m_id;
44484448
// Check if the type variable name is a reserved type keyword
4449-
const char* type_list[14]
4449+
const char* type_list[15]
44504450
= { "list", "set", "dict", "tuple",
44514451
"i8", "i16", "i32", "i64", "f32",
4452-
"f64", "c32", "c64", "str", "bool"};
4453-
for (int i = 0; i < 14; i++) {
4452+
"f64", "c32", "c64", "str", "bool", "i1"};
4453+
for (int i = 0; i < 15; i++) {
44544454
if (strcmp(s2c(al, tvar_name), type_list[i]) == 0) {
44554455
throw SemanticError(tvar_name + " is a reserved type, consider a different type variable name",
44564456
x.base.base.loc);

src/runtime/lpython/lpython.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# data-types
1616

1717
type_to_convert_func = {
18+
"i1": bool,
1819
"i8": int,
1920
"i16": int,
2021
"i32": int,
@@ -75,6 +76,7 @@ def __init__(self, type, dims):
7576
self._type = type
7677
self._dims = dims
7778

79+
i1 = Type("i1")
7880
i8 = Type("i8")
7981
i16 = Type("i16")
8082
i32 = Type("i32")

0 commit comments

Comments
 (0)