diff options
author | Alon Zakai <azakai@mozilla.com> | 2010-12-12 15:05:22 -0800 |
---|---|---|
committer | Alon Zakai <azakai@mozilla.com> | 2010-12-12 15:05:22 -0800 |
commit | 6d83c785fb2f9befb0af92f57b5c5f8e5242ba49 (patch) | |
tree | da83e3cb3126df53ddb0aed7f45430330a0f5b07 | |
parent | 240ff2ff8e8d797740a6ee1dd534240afed6d6e5 (diff) |
support for library dependencies +misc python float fixes
-rw-r--r-- | src/jsifier.js | 18 | ||||
-rw-r--r-- | src/library.js | 59 | ||||
-rw-r--r-- | src/preamble.js | 4 | ||||
-rw-r--r-- | src/runtime.js | 2 | ||||
-rw-r--r-- | tests/python/readme.txt | 2 | ||||
-rw-r--r-- | tests/runner.py | 4 |
6 files changed, 81 insertions, 8 deletions
diff --git a/src/jsifier.js b/src/jsifier.js index ed42dae7..90b155e7 100644 --- a/src/jsifier.js +++ b/src/jsifier.js @@ -270,13 +270,21 @@ function JSify(data, functionsOnly, givenTypes, givenFunctions) { processItem: function(item) { var shortident = item.ident.substr(1); if (shortident in Library) { - var snippet = Library[shortident]; - if (typeof snippet === 'string') { - if (Library[snippet]) { - snippet = Library[snippet]; // redirection for aliases + function addFromLibrary(ident) { + var me = arguments.callee; + if (!me.added) me.added = {}; + if (ident in me.added) return ''; + me.added[ident] = true; + var snippet = Library[ident]; + if (typeof snippet === 'string') { + if (Library[snippet]) { + snippet = Library[snippet]; // redirection for aliases + } } + var deps = Library[ident + '__deps']; + return '_' + ident + ' = ' + snippet.toString() + (deps ? '\n' + deps.map(addFromLibrary).join('\n') : ''); } - item.JS = item.ident + ' = ' + snippet.toString(); + item.JS = addFromLibrary(shortident); } else { item.JS = '// stub for ' + item.ident; } diff --git a/src/library.js b/src/library.js index 9a979ade..a4280a85 100644 --- a/src/library.js +++ b/src/library.js @@ -125,6 +125,7 @@ var Library = { return 0; // TODO }, + strtod__deps: ['isspace', 'isdigit'], strtod: function(str, endptr) { // XXX handles only whitespace + |[0-9]+(.[0.9]+)?|, no e+ while (_isspace(str)) str++; @@ -329,6 +330,15 @@ var Library = { return Pointer_make(String_copy(ptr, true), 0, ALLOC_NORMAL); }, + strpbrk: function(ptr1, ptr2) { + var searchSet = set.apply(null, String_copy(ptr2)); + while (IHEAP[ptr1]) { + if (IHEAP[ptr1] in searchSet) return ptr1; + ptr1++; + } + return 0; + }, + // ctype.h isdigit: function(chr) { @@ -542,6 +552,41 @@ var Library = { llvm_sqrt_f64: 'Math.sqrt', llvm_pow_f32: 'Math.pow', + modf: function(x, intpart) { + FHEAP[intpart] = Math.floor(x); +#if SAFE_HEAP + SAFE_HEAP_ACCESS(intpart, 'f32', true); // XXX f64? +#endif + return x - FHEAP[intpart]; + }, + + frexp: function(x, exp_addr) { + var sig = 0, exp_ = 0; + if (x !== 0) { + var raw_exp = Math.log(x)/Math.log(2); + exp_ = Math.ceil(raw_exp); + if (exp_ === raw_exp) exp_ += 1; + sig = x/Math.pow(2, exp_); + } + IHEAP[exp_addr] = exp_; +#if SAFE_HEAP + SAFE_HEAP_ACCESS(exp_addr, 'i32', true); +#endif + return sig; + }, + + __finite: function(x) { + return x !== Infinity && x !== -Infinity; + }, + + __isinf: function(x) { + return x === Infinity || x === -Infinity; + }, + + __isnan: function(x) { + return isNaN(x); + }, + // unistd.h sysconf: function(name_) { @@ -640,6 +685,20 @@ var Library = { return 0; }, + localeconv: function() { + // %struct.timeval = type { char* decimal point, other stuff... } + // var indexes = Runtime.calculateStructAlignment({ fields: ['i32', 'i32'] }); + var me = arguments.callee; + if (!me.ret) { + me.ret = Pointer_make([Pointer_make(intArrayFromString('.'), null)], null); // just decimal point, for now +#if SAFE_HEAP + SAFE_HEAP_ACCESS(me.ret, 'i32', true); + SAFE_HEAP_ACCESS(IHEAP[me.ret], 'i32', true); +#endif + } + return me.ret; + }, + // langinfo.h nl_langinfo: function(item) { diff --git a/src/preamble.js b/src/preamble.js index 3494053a..e577ba3c 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -203,7 +203,7 @@ function __initializeRuntime__() { FHEAP = HEAP; // fallback } #else - IHEAP = HEAP; // We use that name in our runtime code that processes strings etc., see library.js + IHEAP = FHEAP = HEAP; #endif Module['HEAP'] = HEAP; @@ -281,7 +281,7 @@ function __formatString() { if (next == 'e'.charCodeAt(0) || next == 'g'.charCodeAt(0)) { next = 'f'.charCodeAt(0); // no support for 'e' } - if (['d', 'u', 'p', 'f'].indexOf(String.fromCharCode(next)) != -1) { + if (['d', 'i', 'u', 'p', 'f'].indexOf(String.fromCharCode(next)) != -1) { var currArg; var argText; currArg = getNextArg(next); diff --git a/src/runtime.js b/src/runtime.js index 455d8c0e..d6ce9c3d 100644 --- a/src/runtime.js +++ b/src/runtime.js @@ -107,6 +107,8 @@ Runtime = { getNativeFieldSize: getNativeFieldSize, dedup: dedup, + set: set, + // Calculate aligned size, just like C structs should be. TODO: Consider // requesting that compilation be done with #pragma pack(push) /n #pragma pack(1), // which would remove much of the complexity here. diff --git a/tests/python/readme.txt b/tests/python/readme.txt index 5481414a..e8875955 100644 --- a/tests/python/readme.txt +++ b/tests/python/readme.txt @@ -7,6 +7,8 @@ This is Python 2.7.1, compiled to .ll as follows: EDIT pyconfig.h (in ./bin), remove HAVE_GCC_ASM_FOR_X87 HAVE_SIG* except SIGNAL_H + and *add* + #define PY_NO_SHORT_FLOAT_REPR make ...it will fail, but can continue manually cd pylibs diff --git a/tests/runner.py b/tests/runner.py index 2e96651b..0560cc5d 100644 --- a/tests/runner.py +++ b/tests/runner.py @@ -1042,10 +1042,12 @@ if 'benchmark' not in sys.argv: printf("*%%*\\n"); printf("*%.1ld*\\n", 5); + printf("*%.1f*\\n", strtod("66", NULL)); // checks dependency system, as our strtod needs _isspace etc. + return 0; } ''' - self.do_test(src, '*1,2,3,5,5,6*\n*stdin==0:0*\n*%*\n*5*\n*cleaned*') + self.do_test(src, '*1,2,3,5,5,6*\n*stdin==0:0*\n*%*\n*5*\n*66.0*\n*cleaned*') def test_statics(self): src = ''' |