Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WASM: Support visit_StringLen() #2243

Merged
merged 2 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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