diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index f7c33230ac..56a07b2c62 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -494,6 +494,7 @@ RUN(NAME test_types_02 LABELS cpython llvm c wasm) RUN(NAME test_str_01 LABELS cpython llvm c) RUN(NAME test_str_02 LABELS cpython llvm c) RUN(NAME test_str_03 LABELS cpython llvm c) +RUN(NAME test_str_04 LABELS cpython llvm c wasm) RUN(NAME test_list_01 LABELS cpython llvm c) RUN(NAME test_list_02 LABELS cpython llvm c) RUN(NAME test_list_03 LABELS cpython llvm c NOFAST) diff --git a/integration_tests/test_str_04.py b/integration_tests/test_str_04.py new file mode 100644 index 0000000000..c0ede7991f --- /dev/null +++ b/integration_tests/test_str_04.py @@ -0,0 +1,11 @@ +def main0(): + x: str + x = "abcdefghijkl" + print(len(x)) + assert len(x) == 12 + + y: str = "123" + print(len(y)) + assert len(y) == 3 + +main0() diff --git a/src/libasr/codegen/asr_to_wasm.cpp b/src/libasr/codegen/asr_to_wasm.cpp index 084131366e..93650918dc 100644 --- a/src/libasr/codegen/asr_to_wasm.cpp +++ b/src/libasr/codegen/asr_to_wasm.cpp @@ -1935,6 +1935,15 @@ class ASRToWASMVisitor : public ASR::BaseVisitor { throw CodeGenError("String Types not yet supported"); } + void visit_StringLen(const ASR::StringLen_t & x) { + if (x.m_value) { + visit_expr(*x.m_value); + return; + } + this->visit_expr(*x.m_arg); + m_wa.emit_i32_load(wasm::mem_align::b8, 4); + } + void visit_LogicalBinOp(const ASR::LogicalBinOp_t &x) { if (x.m_value) { visit_expr(*x.m_value);