From 390059a42d0ee6784f79e22de18c87adb1cbfda6 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Sat, 6 May 2017 18:16:24 +0200 Subject: [PATCH] mescc: Support binary constants. * module/language/c99/compiler.mes (cstring->number): Support binary 0bxxx values. * scaffold/t.c (math_test): Test it. --- module/language/c99/compiler.mes | 1 + scaffold/t.c | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/module/language/c99/compiler.mes b/module/language/c99/compiler.mes index 2b554781..a734c284 100644 --- a/module/language/c99/compiler.mes +++ b/module/language/c99/compiler.mes @@ -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)))) diff --git a/scaffold/t.c b/scaffold/t.c index 8ad92369..015c934d 100644 --- a/scaffold/t.c +++ b/scaffold/t.c @@ -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); }