diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index 513b825c29..fa8231bd20 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -454,8 +454,8 @@ RUN(NAME print_list_tuple_02 LABELS cpython llvm c NOFAST) RUN(NAME print_list_tuple_03 LABELS cpython llvm c NOFAST) # CPython and LLVM -RUN(NAME const_01 LABELS cpython llvm c) -RUN(NAME const_02 LABELS cpython llvm c) +RUN(NAME const_01 LABELS cpython llvm c wasm) +RUN(NAME const_02 LABELS cpython llvm c wasm) RUN(NAME const_03 LABELS cpython llvm c EXTRAFILES const_03b.c) RUN(NAME const_04 LABELS cpython llvm c) diff --git a/integration_tests/const_01.py b/integration_tests/const_01.py index 14c7213a2f..377f3ab676 100644 --- a/integration_tests/const_01.py +++ b/integration_tests/const_01.py @@ -13,6 +13,11 @@ def test_const_variables(): ycf: Const[f64] = 3.0 yf: f64 = 3.0 + print(xci, xi) + print(yci, yi) + print(xcf, xf) + print(ycf, yf) + assert xci == xi assert yci == yi assert xcf == xf diff --git a/src/libasr/codegen/asr_to_wasm.cpp b/src/libasr/codegen/asr_to_wasm.cpp index 9dc60dcbf7..023c5bcbe3 100644 --- a/src/libasr/codegen/asr_to_wasm.cpp +++ b/src/libasr/codegen/asr_to_wasm.cpp @@ -647,9 +647,10 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { } using namespace wasm; - int kind = ASRUtils::extract_kind_from_ttype_t(v->m_type); uint32_t global_var_idx = UINT_MAX; - ASR::ttype_t* v_m_type = ASRUtils::type_get_past_array(v->m_type); + ASR::ttype_t* ttype = ASRUtils::type_get_past_const(v->m_type); + ASR::ttype_t* v_m_type = ASRUtils::type_get_past_array(ttype); + int kind = ASRUtils::extract_kind_from_ttype_t(ttype); switch (v_m_type->type){ case ASR::ttypeType::Integer: { uint64_t init_val = 0; @@ -877,9 +878,11 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { throw CodeGenAbort(); } } else { - if (ASRUtils::is_integer(*v->m_type)) { + ASR::ttype_t* ttype = v->m_type; + ttype = ASRUtils::type_get_past_const(ttype); + if (ASRUtils::is_integer(*ttype)) { ASR::Integer_t *v_int = - ASR::down_cast(ASRUtils::type_get_past_array(v->m_type)); + ASR::down_cast(ASRUtils::type_get_past_array(ttype)); if (is_array) { type_vec.push_back(i32); } else { @@ -892,9 +895,9 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { "Integers of kind 4 and 8 only supported"); } } - } else if (ASRUtils::is_real(*v->m_type)) { + } else if (ASRUtils::is_real(*ttype)) { ASR::Real_t *v_float = ASR::down_cast( - ASRUtils::type_get_past_array(v->m_type)); + ASRUtils::type_get_past_array(ttype)); if (is_array) { type_vec.push_back(i32); @@ -908,10 +911,10 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { "Floating Points of kind 4 and 8 only supported"); } } - } else if (ASRUtils::is_logical(*v->m_type)) { + } else if (ASRUtils::is_logical(*ttype)) { ASR::Logical_t *v_logical = ASR::down_cast( - ASRUtils::type_get_past_array(v->m_type)); + ASRUtils::type_get_past_array(ttype)); if (is_array) { type_vec.push_back(i32); @@ -923,10 +926,10 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { throw CodeGenError("Logicals of kind 4 only supported"); } } - } else if (ASRUtils::is_character(*v->m_type)) { + } else if (ASRUtils::is_character(*ttype)) { ASR::Character_t *v_int = ASR::down_cast( - ASRUtils::type_get_past_array(v->m_type)); + ASRUtils::type_get_past_array(ttype)); if (is_array) { type_vec.push_back(i32); @@ -941,10 +944,10 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { "Characters of kind 1 only supported"); } } - } else if (ASRUtils::is_complex(*v->m_type)) { + } else if (ASRUtils::is_complex(*ttype)) { ASR::Complex_t *v_comp = ASR::down_cast( - ASRUtils::type_get_past_array(v->m_type)); + ASRUtils::type_get_past_array(ttype)); if (is_array) { type_vec.push_back(i32); @@ -2132,7 +2135,9 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { void visit_Var(const ASR::Var_t &x) { const ASR::symbol_t *s = ASRUtils::symbol_get_past_external(x.m_v); auto v = ASR::down_cast(s); - switch (ASRUtils::type_get_past_array(v->m_type)->type) { + ASR::ttype_t* ttype = ASRUtils::type_get_past_array(v->m_type); + ttype = ASRUtils::type_get_past_const(ttype); + switch (ttype->type) { case ASR::ttypeType::Integer: case ASR::ttypeType::Logical: case ASR::ttypeType::Real: @@ -2263,7 +2268,7 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { void visit_IntegerConstant(const ASR::IntegerConstant_t &x) { int64_t val = x.m_n; - int a_kind = ((ASR::Integer_t *)(&(x.m_type->base)))->m_kind; + int a_kind = ASRUtils::extract_kind_from_ttype_t(x.m_type); switch (a_kind) { case 4: { m_wa.emit_i32_const(val); @@ -2940,6 +2945,7 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { } ASR::expr_t *v = x.m_values[i]; ASR::ttype_t *t = ASRUtils::expr_type(v); + t = ASRUtils::type_get_past_const(t); int a_kind = ASRUtils::extract_kind_from_ttype_t(t); if (ASRUtils::is_integer(*t) || ASRUtils::is_logical(*t)) {