diff options
-rw-r--r-- | src/parser.js | 8 | ||||
-rw-r--r-- | src/snippets.js | 4 | ||||
-rw-r--r-- | tests/runner.py | 18 |
3 files changed, 26 insertions, 4 deletions
diff --git a/src/parser.js b/src/parser.js index 6da567db..40bffff0 100644 --- a/src/parser.js +++ b/src/parser.js @@ -68,6 +68,7 @@ function pointingLevels(type) { function toNiceIdent(ident) { if (parseFloat(ident) == ident) return ident; + if (ident == 'null') return '0'; // see parseNumerical return ident.replace(/[" \.@%:<>,\*]/g, '_'); } @@ -325,6 +326,10 @@ function parseNumerical(value, type) { // "The one non-intuitive notation for constants is the hexadecimal form of floating point constants." return IEEEUnHex(value); } + if (value == 'null') { + // NULL *is* 0, in C/C++. No JS null! (null == 0 is false, etc.) + return '0'; + } return value; } @@ -2139,12 +2144,11 @@ function JSify(data) { item.JS = (item.overrideSSA ? '' : 'var ') + toNiceIdent(item.ident); var type = item.value.type.text; - var value = item.value.JS; + var value = parseNumerical(item.value.JS); //print("zz var: " + item.JS); var impl = getVarData(item.funcData, item.ident); switch (impl) { case VAR_NATIVE: { - value = parseNumerical(value, type); break; } case VAR_NATIVIZED: { diff --git a/src/snippets.js b/src/snippets.js index 83cc26e6..5d84f1a0 100644 --- a/src/snippets.js +++ b/src/snippets.js @@ -56,6 +56,10 @@ var Snippets = { } } }, + + __assert_fail: function(condition, file, line) { + throw 'Assertion failed: ' + Pointer_stringify(condition);//JSON.stringify(arguments)//condition; + }, }; // Aliases diff --git a/tests/runner.py b/tests/runner.py index eae225b4..205fe2b2 100644 --- a/tests/runner.py +++ b/tests/runner.py @@ -357,11 +357,25 @@ class T(unittest.TestCase): c = c->next; } while (c != chunk); - printf("*%d*\\n", total); + printf("*%d,%d*\\n", total, b.next); + // NULL *is* 0, in C/C++. No JS null! (null == 0 is false, etc.) + return 0; } ''' - self.do_test(src, '*1410*') + self.do_test(src, '*1410,0*') + + def test_assert(self): + src = ''' + #include <stdio.h> + #include <assert.h> + int main() { + assert(1 == true); // pass + assert(1 == false); // fail + return 1; + } + ''' + self.do_test(src, 'Assertion failed: 1 == false') def test_class(self): src = ''' |