diff options
-rw-r--r-- | src/parser.js | 10 | ||||
-rw-r--r-- | tests/runner.py | 4 |
2 files changed, 9 insertions, 5 deletions
diff --git a/src/parser.js b/src/parser.js index 802a049a..9908b0a5 100644 --- a/src/parser.js +++ b/src/parser.js @@ -1845,7 +1845,7 @@ function JSify(data) { item.JS += makePointer(JSON.stringify(makeEmptyStruct(item.type))); } else { // Generate a constant - item.JS += parseConst(value); + item.JS += parseConst(value, item.type); } item.JS += ';'; item.__result__ = true; @@ -1854,9 +1854,11 @@ function JSify(data) { }); // Gets an entire constant expression - function parseConst(value) { - //print('//yyyyy ' + JSON.stringify(value)); - if (value.text[0] == '"') { + function parseConst(value, type) { + //print('//yyyyy ' + JSON.stringify(value) + ',' + type); + if (isNumberType(type)) { + return makePointer(value.text); + } else if (value.text[0] == '"') { value.text = value.text.substr(1, value.text.length-2); return makePointer('intArrayFromString("' + value.text + '")'); } else { diff --git a/tests/runner.py b/tests/runner.py index 68904978..4aab0970 100644 --- a/tests/runner.py +++ b/tests/runner.py @@ -157,6 +157,7 @@ class T(unittest.TestCase): def test_intvars(self): src = ''' #include <stdio.h> + int global = 20; int main() { int x = 5; @@ -165,6 +166,7 @@ class T(unittest.TestCase): y += 1; int w = x*3+4; int k = w < 15 ? 99 : 101; + k += global; int i = k > 100; // Should be an int, not a bool! int j = i << 6; j >>= 1; @@ -177,7 +179,7 @@ class T(unittest.TestCase): return 0; } ''' - self.do_test(src, '*5,23,10,19,101,1,37,1,0*') + self.do_test(src, '*5,23,10,19,121,1,37,1,0*') def test_floatvars(self): src = ''' |