diff options
Diffstat (limited to 'src/library.js')
-rw-r--r-- | src/library.js | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/src/library.js b/src/library.js index 6feb37e4..cda318d7 100644 --- a/src/library.js +++ b/src/library.js @@ -3296,7 +3296,7 @@ LibraryManager.library = { }, atexit: function(func, arg) { - __ATEXIT__.push({ func: func, arg: arg }); + __ATEXIT__.unshift({ func: func, arg: arg }); }, __cxa_atexit: 'atexit', @@ -4384,7 +4384,7 @@ LibraryManager.library = { ptrTV -= {{{ Runtime.QUANTUM_SIZE }}}; var TI = {{{ makeGetValue('ptrTV', '0', '*') }}}; do { - if (TI == attemptedTI) return 1; + if (TI == attemptedTI) return ptr; // Go to parent class var type_infoAddr = {{{ makeGetValue('TI', '0', '*') }}} - {{{ Runtime.QUANTUM_SIZE*2 }}}; var type_info = {{{ makeGetValue('type_infoAddr', '0', '*') }}}; @@ -5349,19 +5349,26 @@ LibraryManager.library = { // ========================================================================== // setjmp.h + // + // Basic support for setjmp/longjmp: enough to run the wikipedia example and + // hopefully handle most normal behavior. We do not support cases where + // longjmp behavior is undefined (for example, if the setjmp function returns + // before longjmp is called). + // + // Note that we need to emulate functions that use setjmp, and also to create + // a new label we can return to. Emulation make such functions slower, this + // can be alleviated by making a new function containing just the setjmp + // related functionality so the slowdown is more limited. // ========================================================================== - setjmp: function(env) { - // XXX print('WARNING: setjmp() not really implemented, will fail if longjmp() is actually called'); - return 0; + setjmp__inline: function(env) { + // Save the label + return '(' + makeSetValue(env, '0', '__label__', 'i32') + ', 0)'; }, - _setjmp: 'setjmp', - longjmp: function(env, val) { - // not really working... - assert(0); + longjmp: function(env, value) { + throw { longjmp: true, label: {{{ makeGetValue('env', '0', 'i32') }}}, value: value || 1 }; }, - _longjmp: 'longjmp', // ========================================================================== // signal.h |