aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-01-19 12:59:01 -0800
committerAlon Zakai <alonzakai@gmail.com>2013-01-19 12:59:01 -0800
commitcaf16eda45a7abc0397fa3bf4044bda16b36a606 (patch)
tree24d76fd6059d50c1b7f22365613823ee0888a134
parent8a816f70aa3b07098761557b5b57cfaee498c204 (diff)
fix asm function table wrappers
-rw-r--r--src/modules.js22
1 files changed, 15 insertions, 7 deletions
diff --git a/src/modules.js b/src/modules.js
index 9d516707..f6587773 100644
--- a/src/modules.js
+++ b/src/modules.js
@@ -299,17 +299,25 @@ var Functions = {
}
if (ASM_JS) {
var curr = table[i];
- if (curr && Functions.unimplementedFunctions[table[i]]) {
+ if (curr && Functions.unimplementedFunctions[curr]) {
// This is a library function, we can't just put it in the function table, need a wrapper
if (!wrapped[curr]) {
- var args = '', arg_coercions = '', call = curr + '(', ret = t[0] == 'v' ? '' : ('return ' + (t[0] == 'f' ? '+0' : '0'));
- for (var i = 1; i < t.length; i++) {
- args += (i > 1 ? ',' : '') + 'a' + i;
- arg_coercions += 'a' + i + '=' + asmCoercion('a' + i, t[i] == 'f' ? 'float' : 'i32') + ';';
- call += (i > 1 ? ',' : '') + asmCoercion('a' + i, t[i] == 'f' ? 'float' : 'i32');
+ var args = '', arg_coercions = '', call = curr + '(', retPre = '', retPost = '';
+ if (t[0] != 'v') {
+ if (t[0] == 'i') {
+ retPre = 'return ';
+ retPost = '|0';
+ } else {
+ retPre = 'return +';
+ }
+ }
+ for (var j = 1; j < t.length; j++) {
+ args += (j > 1 ? ',' : '') + 'a' + j;
+ arg_coercions += 'a' + j + '=' + asmCoercion('a' + j, t[j] == 'f' ? 'float' : 'i32') + ';';
+ call += (j > 1 ? ',' : '') + asmCoercion('a' + j, t[j] == 'f' ? 'float' : 'i32');
}
call += ')';
- tables.pre += 'function ' + curr + '__wrapper(' + args + ') { ' + arg_coercions + ' ; ' + call + ' ; ' + ret + ' }\n';
+ tables.pre += 'function ' + curr + '__wrapper(' + args + ') { ' + arg_coercions + ' ; ' + retPre + call + retPost + ' }\n';
wrapped[curr] = 1;
}
table[i] = curr + '__wrapper';