diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/jsifier.js | 10 | ||||
-rw-r--r-- | src/library.js | 4 | ||||
-rw-r--r-- | src/library_sdl.js | 17 | ||||
-rw-r--r-- | src/parseTools.js | 3 | ||||
-rw-r--r-- | src/settings.js | 3 |
5 files changed, 31 insertions, 6 deletions
diff --git a/src/jsifier.js b/src/jsifier.js index dcc853f2..8e688d8d 100644 --- a/src/jsifier.js +++ b/src/jsifier.js @@ -38,7 +38,6 @@ function JSify(data, functionsOnly, givenFunctions) { var preFile = BUILD_AS_SHARED_LIB ? 'preamble_sharedlib.js' : 'preamble.js'; var pre = processMacros(preprocess(read(preFile).replace('{{RUNTIME}}', getRuntime()))); print(pre); - if (PRECISE_I64_MATH) print(read('long.js')); Functions.implementedFunctions = set(data.unparsedFunctions.map(function(func) { return func.ident })); } @@ -405,7 +404,8 @@ function JSify(data, functionsOnly, givenFunctions) { // name the function; overwrite if it's already named snippet = snippet.replace(/function(?:\s+([^(]+))?\s*\(/, 'function _' + ident + '('); if (LIBRARY_DEBUG) { - snippet = snippet.replace('{', '{ Module.printErr("[library call:' + ident + ': " + Array.prototype.slice.call(arguments) + "]"); '); + snippet = snippet.replace('{', '{ var ret = (function() {Module.printErr("[library call:' + ident + ': " + Array.prototype.slice.call(arguments) + "]"); '); + snippet = snippet.substr(0, snippet.length-1) + '}).apply(this, arguments); Module.printErr(" [ return:" + ret); return ret; }'; } } @@ -1200,6 +1200,12 @@ function JSify(data, functionsOnly, givenFunctions) { // This is the main pass. Print out the generated code that we have here, together with the // rest of the output that we started to print out earlier (see comment on the // "Final shape that will be created"). + if (PRECISE_I64_MATH && preciseI64MathUsed) { + print(read('long.js')); + } else { + print('// Warning: printing of i64 values may be slightly rounded! No deep i64 math used, so precise i64 code not included'); + print('var i64Math = null;'); + } var generated = itemsDict.functionStub.concat(itemsDict.GlobalVariablePostSet); generated.forEach(function(item) { print(indentify(item.JS || '', 2)); }); if (RUNTIME_TYPE_INFO) { diff --git a/src/library.js b/src/library.js index f49a8a58..be5e48d7 100644 --- a/src/library.js +++ b/src/library.js @@ -2507,12 +2507,12 @@ LibraryManager.library = { var prefix = ''; if (next == 'd'.charCodeAt(0) || next == 'i'.charCodeAt(0)) { #if PRECISE_I64_MATH == 1 - if (argSize == 8) argText = i64Math.stringify(origArg[0], origArg[1]); else + if (argSize == 8 && i64Math) argText = i64Math.stringify(origArg[0], origArg[1]); else #endif argText = reSign(currArg, 8 * argSize, 1).toString(10); } else if (next == 'u'.charCodeAt(0)) { #if PRECISE_I64_MATH == 1 - if (argSize == 8) argText = i64Math.stringify(origArg[0], origArg[1], true); else + if (argSize == 8 && i64Math) argText = i64Math.stringify(origArg[0], origArg[1], true); else #endif argText = unSign(currArg, 8 * argSize, 1).toString(10); currArg = Math.abs(currArg); diff --git a/src/library_sdl.js b/src/library_sdl.js index 631de481..a6c5c559 100644 --- a/src/library_sdl.js +++ b/src/library_sdl.js @@ -84,6 +84,8 @@ mergeInto(LibraryManager.library, { copyOnLock: true }, + version: null, + surfaces: {}, events: [], audios: [null], @@ -162,6 +164,11 @@ mergeInto(LibraryManager.library, { ['i32', 'size'], ['void*', 'callback'], ['void*', 'userdata'] + ]), + version: Runtime.generateStructInfo([ + ['i8', 'major'], + ['i8', 'minor'], + ['i8', 'patch'] ]) }, @@ -369,6 +376,16 @@ mergeInto(LibraryManager.library, { } }, + SDL_Linked_Version: function() { + if (SDL.version === null) { + SDL.version = _malloc(SDL.structs.version.__size__); + {{{ makeSetValue('SDL.version + SDL.structs.version.major', '0', '1', 'i8') }}} + {{{ makeSetValue('SDL.version + SDL.structs.version.minor', '0', '3', 'i8') }}} + {{{ makeSetValue('SDL.version + SDL.structs.version.patch', '0', '0', 'i8') }}} + } + return SDL.version; + }, + SDL_Init__deps: ['$SDL'], SDL_Init: function(what) { SDL.startTime = Date.now(); diff --git a/src/parseTools.js b/src/parseTools.js index 5ec3b4ed..22f38207 100644 --- a/src/parseTools.js +++ b/src/parseTools.js @@ -1560,6 +1560,8 @@ function isSignedOp(op, variant) { } var legalizedI64s = USE_TYPED_ARRAYS == 2; // We do not legalize globals, but do legalize function lines. This will be true in the latter case +var preciseI64MathUsed = false; // Set to true if we actually use precise i64 math: If PRECISE_I64_MATH is set, and also such math is actually + // needed (+,-,*,/,% - we do not need it for bitops) function processMathop(item) { var op = item.op; @@ -1617,6 +1619,7 @@ function processMathop(item) { } } function i64PreciseOp(type, lastArg) { + preciseI64MathUsed = true; return finish(['(i64Math.' + type + '(' + low1 + ',' + high1 + ',' + low2 + ',' + high2 + (lastArg ? ',' + lastArg : '') + '),i64Math.result[0])', 'i64Math.result[1]']); } diff --git a/src/settings.js b/src/settings.js index ede00dd5..15c92176 100644 --- a/src/settings.js +++ b/src/settings.js @@ -67,9 +67,8 @@ var DOUBLE_MODE = 1; // How to load and store 64-bit doubles. Without typed arra // then load it aligned, and that load-store will make JS engines alter it if it is being // stored to a typed array for security reasons. That will 'fix' the number from being a // NaN or an infinite number. -var PRECISE_I64_MATH = 0; // If enabled, i64 addition etc. is emulated - which is slow but precise. If disabled, +var PRECISE_I64_MATH = 1; // If enabled, i64 addition etc. is emulated - which is slow but precise. If disabled, // we use the 'double trick' which is fast but incurs rounding at high values. - // Note that precise math currently only handles *signed* values, not unsigned var CLOSURE_ANNOTATIONS = 0; // If set, the generated code will be annotated for the closure // compiler. This potentially lets closure optimize the code better. |