Skip to content

Commit

Permalink
Merge pull request lcompilers#2243 from Shaikh-Ubaid/wasm_string_len
Browse files Browse the repository at this point in the history
WASM: Support visit_StringLen()
  • Loading branch information
certik committed Aug 1, 2023
2 parents 1180f99 + fe4f98e commit c3314f7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions integration_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions integration_tests/test_str_04.py
Original file line number Diff line number Diff line change
@@ -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()
9 changes: 9 additions & 0 deletions src/libasr/codegen/asr_to_wasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1935,6 +1935,15 @@ class ASRToWASMVisitor : public ASR::BaseVisitor<ASRToWASMVisitor> {
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);
Expand Down

0 comments on commit c3314f7

Please sign in to comment.