diff options
author | alon@honor <none@none> | 2010-09-22 21:15:26 -0700 |
---|---|---|
committer | alon@honor <none@none> | 2010-09-22 21:15:26 -0700 |
commit | 17f4f4918767c3159f55c78f3c443067f0297b70 (patch) | |
tree | 7c2499ba30c0a1a37329e74675e3d39ddad6bccc | |
parent | 283667603bcd9641b7b4183d881c5f311243eb14 (diff) |
handle a few minor parsing issues (negative IEEE doubles, []s in constants, aliases - ignored)
-rw-r--r-- | src/intertyper.js | 9 | ||||
-rw-r--r-- | src/jsifier.js | 2 | ||||
-rw-r--r-- | src/parseTools.js | 21 | ||||
-rw-r--r-- | src/settings.js | 4 |
4 files changed, 31 insertions, 5 deletions
diff --git a/src/intertyper.js b/src/intertyper.js index aeae6c7b..eababb95 100644 --- a/src/intertyper.js +++ b/src/intertyper.js @@ -218,10 +218,15 @@ function intertyper(data) { // globals: type or variable substrate.addZyme('Global', { processItem: function(item) { + if (item.tokens[2].text == 'alias') { + return; // TODO: handle this. See raytrace.cpp + } if (item.tokens[2].text == 'type') { - //dprint('type/const linenum: ' + item.lineNum + ':' + dump(item)); var fields = []; - if (item.tokens[3].text != 'opaque') { + if (isNumberType(item.tokens[3].text)) { + // Clang sometimes has |= i32| instead of |= { i32 }| + fields = [item.tokens[3].text]; + } else if (item.tokens[3].text != 'opaque') { if (item.tokens[3].type == '<') { // type <{ i8 }> XXX - check spec item.tokens[3] = item.tokens[3].item[0]; } diff --git a/src/jsifier.js b/src/jsifier.js index 86c9270e..c9c2a63b 100644 --- a/src/jsifier.js +++ b/src/jsifier.js @@ -96,6 +96,8 @@ function JSify(data) { return '(' + handleSegment(subSegments[0]) + ' + ' + handleSegment(subSegments[1]) + ')'; } else if (segment[1].type == '{') { return '[' + handleSegments(segment[1].tokens) + ']'; + } else if (segment[1].type == '[') { + return '[' + handleSegments(segment[1].item[0].tokens) + ']'; } else if (segment.length == 2) { return parseNumerical(toNiceIdent(segment[1].text)); } else { diff --git a/src/parseTools.js b/src/parseTools.js index 2a689889..3221a829 100644 --- a/src/parseTools.js +++ b/src/parseTools.js @@ -324,11 +324,26 @@ function _HexToInt(stringy) { return ret; } +function _IntToHex(x) { + assert(x >= 0 && x <= 15); + if (x <= 9) { + return String.fromCharCode('0'.charCodeAt(0) + x); + } else { + return String.fromCharCode('A'.charCodeAt(0) + x - 10); + } +} + function IEEEUnHex(stringy) { - var a = _HexToInt(stringy.substr(2, 8)); - var b = _HexToInt(stringy.substr(10)); + stringy = stringy.substr(2); // '0x'; + var top = _HexToInt(stringy[0]); + var neg = !!(top & 8); + if (neg) { + stringy = _IntToHex(top & ~8) + stringy.substr(1); + } + var a = _HexToInt(stringy.substr(0, 8)); + var b = _HexToInt(stringy.substr(8)); var e = (a >> ((52 - 32) & 0x7ff)) - 1023; - return ((((a & 0xfffff | 0x100000) * 1.0) / Math.pow(2,52-32)) * Math.pow(2, e)) + (((b * 1.0) / Math.pow(2, 52)) * Math.pow(2, e)); + return (((((a & 0xfffff | 0x100000) * 1.0) / Math.pow(2,52-32)) * Math.pow(2, e)) + (((b * 1.0) / Math.pow(2, 52)) * Math.pow(2, e)) * (neg ? -1 : 1)).toString(); } function parseNumerical(value, type) { diff --git a/src/settings.js b/src/settings.js index 2133479c..f84391fd 100644 --- a/src/settings.js +++ b/src/settings.js @@ -9,4 +9,8 @@ EXECUTION_TIMEOUT = -1; // Throw an exception after X seconds - useful to debug // Compiler debugging options DEBUG_TAGS_SHOWING = ['enzymatic']; + // Some useful items: + // gconst + // types + // relooping |