diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-10-25 16:51:18 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-10-25 17:01:44 -0700 |
commit | 296cd5f54cb598fad7c9e58776bac906da1add02 (patch) | |
tree | 80bbc4c143b780f62f4814d19b58c803466d22e1 /src/modules.js | |
parent | 5041ed44a66938588e674b9f7c03b9281b99c4e1 (diff) |
support fround in function tables and asm module support functions
Diffstat (limited to 'src/modules.js')
-rw-r--r-- | src/modules.js | 41 |
1 files changed, 27 insertions, 14 deletions
diff --git a/src/modules.js b/src/modules.js index 814817a3..2e6edeba 100644 --- a/src/modules.js +++ b/src/modules.js @@ -253,13 +253,32 @@ var Functions = { aliases: {}, // in shared modules (MAIN_MODULE or SHARED_MODULE), a list of aliases for functions that have them + getSignatureLetter: function(type) { + switch(type) { + case 'float': return 'f'; + case 'double': return 'd'; + case 'void': return 'v'; + default: return 'i'; + } + }, + + getSignatureType: function(letter) { + switch(letter) { + case 'v': return 'void'; + case 'i': return 'i32'; + case 'f': return 'float'; + case 'd': return 'double'; + default: throw 'what is this sig? ' + sig; + } + }, + getSignature: function(returnType, argTypes, hasVarArgs) { - var sig = returnType == 'void' ? 'v' : (isIntImplemented(returnType) ? 'i' : 'f'); + var sig = Functions.getSignatureLetter(returnType); for (var i = 0; i < argTypes.length; i++) { var type = argTypes[i]; if (!type) break; // varargs if (type in Runtime.FLOAT_TYPES) { - sig += 'f'; + sig += Functions.getSignatureLetter(type); } else { var chunks = getNumIntChunks(type); for (var j = 0; j < chunks; j++) sig += 'i'; @@ -269,15 +288,6 @@ var Functions = { return sig; }, - getSignatureReturnType: function(sig) { - switch(sig[0]) { - case 'v': return 'void'; - case 'i': return 'i32'; - case 'f': return 'double'; - default: throw 'what is this sig? ' + sig; - } - }, - // Mark a function as needing indexing. Python will coordinate them all getIndex: function(ident, sig) { var ret; @@ -353,14 +363,17 @@ var Functions = { if (t[0] == 'i') { retPre = 'return '; retPost = '|0'; - } else { + } else if (t[0] === 'd') { retPre = 'return +'; + } else { + retPre = 'return Math_fround('; + retPost = ')'; } } for (var j = 1; j < t.length; j++) { args += (j > 1 ? ',' : '') + 'a' + j; - arg_coercions += 'a' + j + '=' + asmCoercion('a' + j, t[j] != 'i' ? 'float' : 'i32') + ';'; - call += (j > 1 ? ',' : '') + asmCoercion('a' + j, t[j] != 'i' ? 'float' : 'i32'); + arg_coercions += 'a' + j + '=' + asmCoercion('a' + j, Functions.getSignatureType(t[j])) + ';'; + call += (j > 1 ? ',' : '') + asmCoercion('a' + j, Functions.getSignatureType(t[j])); } call += ')'; if (short == '_setjmp') printErr('WARNING: setjmp used via a function pointer. If this is for libc setjmp (not something of your own with the same name), it will break things'); |