aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--system/include/emscripten/emscripten.h10
-rw-r--r--tests/test_core.py23
2 files changed, 32 insertions, 1 deletions
diff --git a/system/include/emscripten/emscripten.h b/system/include/emscripten/emscripten.h
index f0df8dca..1ed4c721 100644
--- a/system/include/emscripten/emscripten.h
+++ b/system/include/emscripten/emscripten.h
@@ -19,6 +19,16 @@ extern "C" {
#endif
/*
+ * Convenient syntax for inline assembly/js. Allows stuff like
+ *
+ * EM_ASM(window.alert('hai'));
+ *
+ * Note: double-quotes (") are not supported, but you can use
+ * single-quotes (') in js anyhow.
+ */
+#define EM_ASM(...) asm(#__VA_ARGS__)
+
+/*
* Forces LLVM to not dead-code-eliminate a function. Note that
* you still need to use EXPORTED_FUNCTIONS so it stays alive
* in JS, e.g.
diff --git a/tests/test_core.py b/tests/test_core.py
index a477c05e..543f2407 100644
--- a/tests/test_core.py
+++ b/tests/test_core.py
@@ -3752,7 +3752,7 @@ def process(filename):
}
'''
- self.do_run(src, 'Inline JS is very cool\n3.64')
+ self.do_run(src, 'Inline JS is very cool\n3.64\n')
def test_inlinejs2(self):
if Settings.ASM_JS: return self.skip('asm does not support random code, TODO: something that works in asm')
@@ -3779,6 +3779,27 @@ def process(filename):
self.do_run(src, '4\n200\n')
+ def test_inlinejs3(self):
+ if Settings.ASM_JS: return self.skip('asm does not support random code, TODO: something that works in asm')
+ src = r'''
+ #include <stdio.h>
+ #include <emscripten.h>
+
+ int main() {
+ EM_ASM(Module.print('hello dere1'));
+ EM_ASM(
+ Module.print('hello dere2');
+ );
+ EM_ASM(
+ Module.print('hello dere3');
+ Module.print('hello dere' + 4);
+ );
+ return 0;
+ }
+ '''
+
+ self.do_run(src, 'hello dere1\nhello dere2\nhello dere3\nhello dere4\n')
+
def test_memorygrowth(self):
if Settings.USE_TYPED_ARRAYS == 0: return self.skip('memory growth is only supported with typed arrays')
if Settings.ASM_JS: return self.skip('asm does not support memory growth yet')