From ca633abdda729ca99e8b3ef9cc94b2e5ac6ca367 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Fri, 24 Mar 2017 22:32:02 +0100 Subject: [PATCH] mescc: Lshift support non-fixed shift value. * module/mes/as-i386.mes (i386:accu<accu): Use it. * scaffold/t.c (math_test): Test it. --- module/language/c99/compiler.mes | 18 +++++++++++++++--- module/mes/as-i386.mes | 5 +++++ module/mes/as-i386.scm | 1 + scaffold/t.c | 7 +++++++ 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/module/language/c99/compiler.mes b/module/language/c99/compiler.mes index 51d24870..719ec5e7 100644 --- a/module/language/c99/compiler.mes +++ b/module/language/c99/compiler.mes @@ -761,15 +761,27 @@ (list (lambda (f g ta t d) (i386:accu-base))))))) - ((lshift ,a (p-expr (fixed ,value))) + ((bitwise-or ,a ,b) (let* ((empty (clone info #:text '())) (accu ((expr->accu empty) a)) - (value (cstring->number value))) + (base ((expr->base empty) b))) (clone info #:text (append text (.text accu) + (.text base) (list (lambda (f g ta t d) - (i386:accu-shl value))))))) + (i386:accu-or-base))))))) + + ((lshift ,a ,b) + (let* ((empty (clone info #:text '())) + (accu ((expr->accu empty) a)) + (base ((expr->base empty) b))) + (clone info #:text + (append text + (.text accu) + (.text base) + (list (lambda (f g ta t d) + (i386:accu<accu i386:base->accu-address diff --git a/scaffold/t.c b/scaffold/t.c index cffa2ce7..419e7533 100644 --- a/scaffold/t.c +++ b/scaffold/t.c @@ -212,6 +212,13 @@ math_test () puts ("t: 3*4="); i = 3 * 4; if (i!=12) return 1; + + puts ("t: 1 << 3\n"); + if (1 << 3 != 8) return 1 << 3; + + puts ("t: 3 << 4\n"); + if (3 << 4 != 48) return 3 << 4; + return read_test (); }