diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-10-29 14:36:15 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-10-29 14:36:15 -0700 |
commit | 2f2f3ca9fbbe5906bb68aa56edf7eca192ac9dc1 (patch) | |
tree | 2377ae19fbc463308c5ca4b460a27458b33c7e7d /src | |
parent | 76014aec3125274b975196103259018f37785451 (diff) |
use asm ffi coercing for floats in load abort calls
Diffstat (limited to 'src')
-rw-r--r-- | src/jsifier.js | 5 | ||||
-rw-r--r-- | src/parseTools.js | 7 |
2 files changed, 9 insertions, 3 deletions
diff --git a/src/jsifier.js b/src/jsifier.js index 329b06c6..669cec73 100644 --- a/src/jsifier.js +++ b/src/jsifier.js @@ -1324,7 +1324,7 @@ function JSify(data, functionsOnly, givenFunctions) { if (isNumber(item.ident)) { // Direct read from a memory address; this may be an intentional segfault, if not, it is a bug in the source if (ASM_JS) { - return asmCoercion('abort(' + item.ident + ')', item.type); + return asmFFICoercion('abort(' + item.ident + ')', item.type); } else { item.assignTo = null; return 'throw "fault on read from ' + item.ident + '";'; @@ -1617,8 +1617,7 @@ function JSify(data, functionsOnly, givenFunctions) { var ret = callIdent + '(' + args.join(',') + ')'; if (ASM_JS) { // TODO: do only when needed (library functions and Math.*?) XXX && simpleIdent in Functions.libraryFunctions) { if (ffiCall) { - ret = asmCoercion(ret, ensureValidFFIType(returnType)); - if (FROUND && returnType === 'float') ret = asmCoercion(ret, 'float'); // receive double, then float it + ret = asmFFICoercion(ret, returnType); } else { ret = asmCoercion(ret, returnType); } diff --git a/src/parseTools.js b/src/parseTools.js index 80320826..9089a9e6 100644 --- a/src/parseTools.js +++ b/src/parseTools.js @@ -2695,3 +2695,10 @@ function ensureValidFFIType(type) { return type === 'float' ? 'double' : type; // ffi does not tolerate float XXX } +// FFI return values must arrive as doubles, and we can force them to floats afterwards +function asmFFICoercion(value, type) { + value = asmCoercion(value, ensureValidFFIType(type)); + if (FROUND && type === 'float') value = asmCoercion(value, 'float'); + return value; +} + |