aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralon@honor <none@none>2010-09-06 15:25:17 -0700
committeralon@honor <none@none>2010-09-06 15:25:17 -0700
commite5847048c36de42ca50284f956f5747b67de09c5 (patch)
tree88f885ee9ecd0cc652bddd301c10eea96dfbbafd
parent3c5c095e6542f6c9f56fbdce7a1bfa698a78fe34 (diff)
fixes for null vs 0, and support for assert +test
-rw-r--r--src/parser.js8
-rw-r--r--src/snippets.js4
-rw-r--r--tests/runner.py18
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 = '''