aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2012-04-09 17:54:25 -0700
committerAlon Zakai <alonzakai@gmail.com>2012-04-09 17:54:25 -0700
commitfa307241513ecc2e9a7711c79ed0b3a7e321f686 (patch)
tree3f0b4cb306187897f7a7b3cecb1764eff7a34c14
parentedf26eb8c4704fa07cc7e646b2b9ccd59a698467 (diff)
experimental support for inline js
-rw-r--r--src/intertyper.js14
-rwxr-xr-xtests/runner.py12
2 files changed, 20 insertions, 6 deletions
diff --git a/src/intertyper.js b/src/intertyper.js
index 7dafed6f..26f55392 100644
--- a/src/intertyper.js
+++ b/src/intertyper.js
@@ -660,17 +660,19 @@ function intertyper(data, sidePass, baseLineNums) {
item.type = item.tokens[1].text;
Types.needAnalysis[item.type] = 0;
while (['@', '%'].indexOf(item.tokens[2].text[0]) == -1 && !(item.tokens[2].text in PARSABLE_LLVM_FUNCTIONS) &&
- item.tokens[2].text != 'null') {
- // We cannot compile assembly. If you hit this, perhaps tell the compiler not
- // to generate arch-specific code? |-U__i386__ -U__x86_64__| might help, it undefines
- // the standard archs.
+ item.tokens[2].text != 'null' && item.tokens[2].text != 'asm') {
assert(item.tokens[2].text != 'asm', 'Inline assembly cannot be compiled to JavaScript!');
item.tokens.splice(2, 1);
}
var tokensLeft = item.tokens.slice(2);
item.ident = eatLLVMIdent(tokensLeft);
- // We cannot compile assembly, see above.
- assert(item.ident != 'asm', 'Inline assembly cannot be compiled to JavaScript!');
+ if (item.ident == 'asm') {
+ // Inline assembly is just JavaScript that we paste into the code
+ item.intertype = 'value';
+ if (tokensLeft[0].text == 'sideeffect') tokensLeft.splice(0, 1);
+ item.ident = tokensLeft[0].text.substr(1, tokensLeft[0].text.length-2);
+ return { forward: null, ret: [item], item: item };
+ }
if (item.ident.substr(-2) == '()') {
// See comment in isStructType()
item.ident = item.ident.substr(0, item.ident.length-2);
diff --git a/tests/runner.py b/tests/runner.py
index 99175b36..477cd29c 100755
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -2339,6 +2339,18 @@ def process(filename):
self.do_run(src, 'hello world!\n*100*', post_build=check)
+ def test_inlinejs(self):
+ src = r'''
+ #include <stdio.h>
+
+ int main() {
+ asm("Module.print('Inline JS is very cool')");
+ return 0;
+ }
+ '''
+
+ self.do_run(src, 'Inline JS is very cool')
+
def test_memorygrowth(self):
# With typed arrays in particular, it is dangerous to use more memory than TOTAL_MEMORY,
# since we then need to enlarge the heap(s).