summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/asm2wasm.h5
-rw-r--r--src/wasm-interpreter.h24
-rw-r--r--src/wasm-js.cpp8
3 files changed, 26 insertions, 11 deletions
diff --git a/src/asm2wasm.h b/src/asm2wasm.h
index 83f638310..4d12a66f1 100644
--- a/src/asm2wasm.h
+++ b/src/asm2wasm.h
@@ -1,4 +1,9 @@
+//
+// asm.js-to-WebAssembly translator. Uses the Emscripten optimizer
+// infrastructure.
+//
+
#include "wasm.h"
#include "optimizer.h"
#include "mixed_arena.h"
diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h
index 82e791389..95dce9e7a 100644
--- a/src/wasm-interpreter.h
+++ b/src/wasm-interpreter.h
@@ -1,6 +1,7 @@
-
+//
// Simple WebAssembly interpreter, designed to be embeddable in JavaScript, so it
// can function as a polyfill.
+//
#include "wasm.h"
@@ -16,6 +17,11 @@ class ModuleInstance {
public:
typedef std::vector<Literal> LiteralList;
+ //
+ // You need to implement one of these to create a concrete interpreter. The
+ // ExternalInterface provides embedding-specific functionality like calling
+ // an imported function or accessing memory.
+ //
struct ExternalInterface {
virtual Literal callImport(Import* import, LiteralList& arguments) = 0;
virtual Literal load(Load* load, Literal ptr) = 0;
@@ -28,15 +34,15 @@ public:
}
}
- Literal callFunction(IString name) {
- LiteralList empty;
- return callFunction(name, empty);
- }
-
#ifdef WASM_INTERPRETER_DEBUG
int indent = 0;
#endif
+ //
+ // Calls a function. This can be used both internally (calls from
+ // the interpreter to another method), or when you want to call into
+ // the module.
+ //
Literal callFunction(IString name, LiteralList& arguments) {
class FunctionScope {
@@ -365,6 +371,12 @@ public:
return ExpressionRunner(*this, scope).visit(function->body).value;
}
+ // Convenience method, for the case where you have no arguments.
+ Literal callFunction(IString name) {
+ LiteralList empty;
+ return callFunction(name, empty);
+ }
+
std::map<IString, Function*> functions;
private:
diff --git a/src/wasm-js.cpp b/src/wasm-js.cpp
index ab0923fb8..4d0914f32 100644
--- a/src/wasm-js.cpp
+++ b/src/wasm-js.cpp
@@ -1,10 +1,8 @@
-
//
-// wasm intepreter for asm2wasm output, in a js environment. receives asm.js,
-// generates a runnable module suitable as a polyfill.
+// WebAssembly intepreter for asm2wasm output, in a js environment.
//
-// this polyfills an emscripten --separate-asm *.asm.js file, as a drop-in
-// replacement. it writes the wasm module to Module.asm, and sets Module.buffer.
+// Receives asm.js, generates a runnable module that executes the code in a WebAssembly
+// interpreter. This is suitable as a polyfill for WebAssembly support in browsers.
//
#include <emscripten.h>