mescc: Support binary constants.

* module/language/c99/compiler.mes (cstring->number): Support binary 0bxxx values.
* scaffold/t.c (math_test): Test it.
This commit is contained in:
Jan Nieuwenhuizen 2017-05-06 18:16:24 +02:00
parent 2eae07de72
commit 390059a42d
2 changed files with 10 additions and 0 deletions

View file

@ -1073,6 +1073,7 @@
(define (cstring->number s)
(cond ((string-prefix? "0x" s) (string->number (string-drop s 2) 16))
((string-prefix? "0b" s) (string->number (string-drop s 2) 2))
((string-prefix? "0" s) (string->number s 8))
(else (string->number s))))

View file

@ -347,6 +347,15 @@ math_test ()
puts ("t: 3 != 3\n");
if ((3 != 3) != 0) return 1;
puts ("t: 011 == 15\n");
if (011 != 9) return 1;
puts ("t: 0b11 == 3\n");
if (0b11 != 3) return 1;
puts ("t: 0x11 == 3\n");
if (0x11 != 17) return 1;
return array_test (env);
}