summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/asm2wasm.cpp4
-rw-r--r--src/wasm-interpreter.cpp6
-rw-r--r--src/wasm.h8
3 files changed, 12 insertions, 6 deletions
diff --git a/src/asm2wasm.cpp b/src/asm2wasm.cpp
index 68717e67e..a327fb274 100644
--- a/src/asm2wasm.cpp
+++ b/src/asm2wasm.cpp
@@ -576,7 +576,7 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) {
IString name = ast[2][1]->getIString();
if (functionVariables.has(name)) {
auto ret = allocator.alloc<SetLocal>();
- ret->id = ast[2][1]->getIString();
+ ret->name = ast[2][1]->getIString();
ret->value = process(ast[3]);
ret->type = ret->value->type;
return ret;
@@ -655,7 +655,7 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) {
if (functionVariables.has(name)) {
// var in scope
auto ret = allocator.alloc<GetLocal>();
- ret->id = name;
+ ret->name = name;
ret->type = asmToWasmType(asmData.getType(name));
return ret;
}
diff --git a/src/wasm-interpreter.cpp b/src/wasm-interpreter.cpp
index 84f9b585a..0bb332bb7 100644
--- a/src/wasm-interpreter.cpp
+++ b/src/wasm-interpreter.cpp
@@ -64,6 +64,7 @@ public:
// Execute a statement
class ExpressionRunner : public WasmVisitor<Flow> {
FunctionScope& scope;
+
public:
ExpressionRunner(FunctionScope& scope) : scope(scope) {}
@@ -130,8 +131,13 @@ public:
Flow visitCallIndirect(CallIndirect *curr) override {
}
Flow visitGetLocal(GetLocal *curr) override {
+ return scope[curr->id];
}
Flow visitSetLocal(SetLocal *curr) override {
+ Flow flow = visit(curr->value);
+ if (flow.breaking()) return flow;
+ scope[curr->id] = flow.value;
+ return flow;
}
Flow visitLoad(Load *curr) override {
}
diff --git a/src/wasm.h b/src/wasm.h
index 097ce1900..c2816dc19 100644
--- a/src/wasm.h
+++ b/src/wasm.h
@@ -461,20 +461,20 @@ public:
class GetLocal : public Expression {
public:
- Name id;
+ Name name;
std::ostream& print(std::ostream &o, unsigned indent) override {
- return printOpening(o, "get_local ") << id << ')';
+ return printOpening(o, "get_local ") << name << ')';
}
};
class SetLocal : public Expression {
public:
- Name id;
+ Name name;
Expression *value;
std::ostream& print(std::ostream &o, unsigned indent) override {
- printOpening(o, "set_local ") << id;
+ printOpening(o, "set_local ") << name;
incIndent(o, indent);
printFullLine(o, indent, value);
return decIndent(o, indent);