diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/library.js | 2 | ||||
-rw-r--r-- | src/modules.js | 2 | ||||
-rw-r--r-- | src/parseTools.js | 2 | ||||
-rw-r--r-- | src/preamble.js | 63 | ||||
-rw-r--r-- | src/shell.js | 8 |
5 files changed, 48 insertions, 29 deletions
diff --git a/src/library.js b/src/library.js index 031cf42d..e6fee62e 100644 --- a/src/library.js +++ b/src/library.js @@ -1783,7 +1783,7 @@ LibraryManager.library = { return -1; } }, - getlogin: ['getlogin_r'], + getlogin__deps: ['getlogin_r'], getlogin: function() { // char *getlogin(void); // http://pubs.opengroup.org/onlinepubs/000095399/functions/getlogin.html diff --git a/src/modules.js b/src/modules.js index 04b777fe..6b8d880a 100644 --- a/src/modules.js +++ b/src/modules.js @@ -235,7 +235,7 @@ var LibraryManager = { load: function() { assert(!this.library); - for (suffix in set('', '_sdl', '_gl', '_browser')) { + for (var suffix in set('', '_sdl', '_gl', '_browser')) { eval(processMacros(preprocess(read('library' + suffix + '.js'), CONSTANTS))); } }, diff --git a/src/parseTools.js b/src/parseTools.js index 4a3867ef..2985ccb6 100644 --- a/src/parseTools.js +++ b/src/parseTools.js @@ -13,7 +13,7 @@ function processMacros(text) { // Simple #if/else/endif preprocessing for a file. Checks if the // ident checked is true in our global. Also replaces some constants. function preprocess(text, constants) { - for (constant in constants) { + for (var constant in constants) { text = text.replace(eval('/' + constant + '/g'), constants[constant]); } var lines = text.split('\n'); diff --git a/src/preamble.js b/src/preamble.js index 21e9021e..99288244 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -301,6 +301,43 @@ function assert(condition, text) { } } +// Sets a value in memory in a dynamic way at run-time. Uses the +// type data. This is the same as makeSetValue, except that +// makeSetValue is done at compile-time and generates the needed +// code then, whereas this function picks the right code at +// run-time. + +function setValue(ptr, value, type) { + if (type[type.length-1] === '*') type = 'i32'; // pointers are 32-bit + switch(type) { + case 'i1': {{{ makeSetValue('ptr', '0', 'value', 'i1') }}}; break; + case 'i8': {{{ makeSetValue('ptr', '0', 'value', 'i8') }}}; break; + case 'i16': {{{ makeSetValue('ptr', '0', 'value', 'i16') }}}; break; + case 'i32': {{{ makeSetValue('ptr', '0', 'value', 'i32') }}}; break; + case 'i64': {{{ makeSetValue('ptr', '0', 'value', 'i64') }}}; break; + case 'float': {{{ makeSetValue('ptr', '0', 'value', 'float') }}}; break; + case 'double': {{{ makeSetValue('ptr', '0', 'value', 'double') }}}; break; + default: abort('invalid type for setValue: ' + type); + } +} + +// Parallel to setValue. + +function getValue(ptr, type) { + if (type[type.length-1] === '*') type = 'i32'; // pointers are 32-bit + switch(type) { + case 'i1': return {{{ makeGetValue('ptr', '0', 'i1') }}}; + case 'i8': return {{{ makeGetValue('ptr', '0', 'i8') }}}; + case 'i16': return {{{ makeGetValue('ptr', '0', 'i16') }}}; + case 'i32': return {{{ makeGetValue('ptr', '0', 'i32') }}}; + case 'i64': return {{{ makeGetValue('ptr', '0', 'i64') }}}; + case 'float': return {{{ makeGetValue('ptr', '0', 'float') }}}; + case 'double': return {{{ makeGetValue('ptr', '0', 'double') }}}; + default: abort('invalid type for setValue: ' + type); + } + return null; +} + // Allocates memory for some data and initializes it properly. var ALLOC_NORMAL = 0; // Tries to use _malloc() @@ -338,30 +375,8 @@ function allocate(slab, types, allocator) { assert(type, 'Must know what type to store in allocate!'); #endif - if (type === 'i1') { - {{{ makeSetValue(0, 'ret+i', 'curr', 'i1') }}} - i += {{{ getNativeFieldSize('i1', true) }}}; - } else if (type === 'i8') { - {{{ makeSetValue(0, 'ret+i', 'curr', 'i8') }}} - i += {{{ getNativeFieldSize('i8', true) }}}; - } else if (type === 'i16') { - {{{ makeSetValue(0, 'ret+i', 'curr', 'i16') }}} - i += {{{ getNativeFieldSize('i16', true) }}}; - } else if (type === 'i32' || type[type.length-1] === '*') { // hardcoded pointers as 32-bit - {{{ makeSetValue(0, 'ret+i', 'curr', 'i32') }}} - i += {{{ getNativeFieldSize('i32', true) }}}; - } else if (type === 'float') { - {{{ makeSetValue(0, 'ret+i', 'curr', 'float') }}} - i += {{{ getNativeFieldSize('float', true) }}}; - } else if (type === 'i64') { - {{{ makeSetValue(0, 'ret+i', 'curr', 'i64') }}} - i += {{{ getNativeFieldSize('i64', true) }}}; - } else if (type === 'double') { - {{{ makeSetValue(0, 'ret+i', 'curr', 'double') }}} - i += {{{ getNativeFieldSize('double', true) }}}; - } else { - abort('invalid type for allocate: ' + type); - } + setValue(ret+i, curr, type); + i += Runtime.getNativeFieldSize(type, true); } return ret; diff --git a/src/shell.js b/src/shell.js index c73cf6e4..06cf4175 100644 --- a/src/shell.js +++ b/src/shell.js @@ -13,9 +13,13 @@ if (!this['Module']) { this['Module'] = {}; } try { - Module.arguments = arguments; + Module.arguments = scriptArgs; } catch(e) { - Module.arguments = []; + try { + Module.arguments = arguments; + } catch(e) { + Module.arguments = []; + } } //*/ |