Skip to content

Commit c3314f7

Browse files
authored
Merge pull request #2243 from Shaikh-Ubaid/wasm_string_len
WASM: Support visit_StringLen()
2 parents 1180f99 + fe4f98e commit c3314f7

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

integration_tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,7 @@ RUN(NAME test_types_02 LABELS cpython llvm c wasm)
494494
RUN(NAME test_str_01 LABELS cpython llvm c)
495495
RUN(NAME test_str_02 LABELS cpython llvm c)
496496
RUN(NAME test_str_03 LABELS cpython llvm c)
497+
RUN(NAME test_str_04 LABELS cpython llvm c wasm)
497498
RUN(NAME test_list_01 LABELS cpython llvm c)
498499
RUN(NAME test_list_02 LABELS cpython llvm c)
499500
RUN(NAME test_list_03 LABELS cpython llvm c NOFAST)

integration_tests/test_str_04.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
def main0():
2+
x: str
3+
x = "abcdefghijkl"
4+
print(len(x))
5+
assert len(x) == 12
6+
7+
y: str = "123"
8+
print(len(y))
9+
assert len(y) == 3
10+
11+
main0()

src/libasr/codegen/asr_to_wasm.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1935,6 +1935,15 @@ class ASRToWASMVisitor : public ASR::BaseVisitor<ASRToWASMVisitor> {
19351935
throw CodeGenError("String Types not yet supported");
19361936
}
19371937

1938+
void visit_StringLen(const ASR::StringLen_t & x) {
1939+
if (x.m_value) {
1940+
visit_expr(*x.m_value);
1941+
return;
1942+
}
1943+
this->visit_expr(*x.m_arg);
1944+
m_wa.emit_i32_load(wasm::mem_align::b8, 4);
1945+
}
1946+
19381947
void visit_LogicalBinOp(const ASR::LogicalBinOp_t &x) {
19391948
if (x.m_value) {
19401949
visit_expr(*x.m_value);

0 commit comments

Comments
 (0)