diff options
-rw-r--r-- | src/library.js | 7 | ||||
-rw-r--r-- | src/modules.js | 1 | ||||
-rw-r--r-- | src/parseTools.js | 5 |
3 files changed, 6 insertions, 7 deletions
diff --git a/src/library.js b/src/library.js index 74ebdc07..acbda42b 100644 --- a/src/library.js +++ b/src/library.js @@ -5983,14 +5983,13 @@ LibraryManager.library = { return 0; }, - // TODO: Implement remaining functions. // http://pubs.opengroup.org/onlinepubs/000095399/basedefs/sys/time.h.html gettimeofday: function(ptr) { // %struct.timeval = type { i32, i32 } - var indexes = Runtime.calculateStructAlignment({ fields: ['i32', 'i32'] }); + {{{ (LibraryManager.structs.gettimeofday = Runtime.calculateStructAlignment({ fields: ['i32', 'i32'] }), null) }}} var now = Date.now(); - {{{ makeSetValue('ptr', 'indexes[0]', 'Math.floor(now/1000)', 'i32') }}} // seconds - {{{ makeSetValue('ptr', 'indexes[1]', 'Math.floor((now-1000*Math.floor(now/1000))*1000)', 'i32') }}} // microseconds + {{{ makeSetValue('ptr', LibraryManager.structs.gettimeofday[0], 'Math.floor(now/1000)', 'i32') }}}; // seconds + {{{ makeSetValue('ptr', LibraryManager.structs.gettimeofday[1], 'Math.floor((now-1000*Math.floor(now/1000))*1000)', 'i32') }}}; // microseconds return 0; }, diff --git a/src/modules.js b/src/modules.js index f33f302b..695abbe7 100644 --- a/src/modules.js +++ b/src/modules.js @@ -347,6 +347,7 @@ var Functions = { var LibraryManager = { library: null, + structs: {}, loaded: false, load: function() { diff --git a/src/parseTools.js b/src/parseTools.js index 3410c4c9..f3ae7a22 100644 --- a/src/parseTools.js +++ b/src/parseTools.js @@ -6,11 +6,10 @@ // Does simple 'macro' substitution, using Django-like syntax, // {{{ code }}} will be replaced with |eval(code)|. function processMacros(text) { - return text.replace(/{{{[^}]+}}}/g, function(str) { + return text.replace(/{{{([^}]|}(?!}))+}}}/g, function(str) { str = str.substr(3, str.length-6); var ret = eval(str); - if (ret !== undefined) ret = ret.toString(); - return ret; + return ret ? ret.toString() : ''; }); } |