mescc: Support ==, != as expression value.

* module/mes/as-i386.scm: Export them.
* module/language/c99/compiler.mes (expr->accu): Set accu to 0/1 for eq, ne.
* module/mes/as-i386.mes (i386:nz->accu, i386:z->accu,
  i386:accu<->stack): New functions.
* scaffold/t.c (math_test): Test it.
This commit is contained in:
Jan Nieuwenhuizen 2017-05-06 17:30:14 +02:00
parent be6e30a8fa
commit 2eae07de72
4 changed files with 33 additions and 3 deletions

View File

@ -712,11 +712,20 @@
(wrap-as (i386:value->accu 0))
(wrap-as (i386:sub-base)))))
((eq ,a ,b) ((binop->accu info) a b (i386:sub-base)))
((eq ,a ,b) ((binop->accu info) a b (append (i386:sub-base) (i386:z->accu))))
((ge ,a ,b) ((binop->accu info) b a (i386:sub-base)))
((gt ,a ,b) ((binop->accu info) b a (i386:sub-base)))
((ne ,a ,b) ((binop->accu info) a b (append (i386:sub-base)
(i386:xor-zf))))
;; FIXME: set accu *and* flags
((ne ,a ,b) ((binop->accu info) a b (append (i386:push-accu)
(i386:sub-base)
(i386:nz->accu)
(i386:accu<->stack)
(i386:sub-base)
(i386:xor-zf)
(i386:pop-accu))))
((ne ,a ,b) ((binop->accu info) a b (append (i386:sub-base) (i386:xor-zf))))
((le ,a ,b) ((binop->accu info) b a (i386:base-sub)))
((lt ,a ,b) ((binop->accu info) b a (i386:base-sub)))

View File

@ -483,3 +483,14 @@
(define (i386:base-sub)
`(#x29 #xc2)) ; sub %eax,%edx
(define (i386:nz->accu)
'(#x0f #x95 #xc0 ; setne %al
#x0f #xb6 #xc0)) ; movzbl %al,%eax
(define (i386:z->accu)
'(#x0f #x94 #xc0 ; sete %al
#x0f #xb6 #xc0)) ; movzbl %al,%eax
(define (i386:accu<->stack)
'(#x87 #x04 #x24)) ; xchg %eax,(%esp)

View File

@ -148,6 +148,10 @@
i386:accu+n
i386:base+n
i386:base-address->accu-address
i386:nz->accu
i386:z->accu
i386:accu<->stack
))
(include-from-path "mes/as-i386.mes")

View File

@ -341,6 +341,12 @@ math_test ()
puts ("t: ^ 1 \n");
if ((1 ^ 3) != 2) return 1;
puts ("t: 3 == 3\n");
if ((3 == 3) != 1) return 1;
puts ("t: 3 != 3\n");
if ((3 != 3) != 0) return 1;
return array_test (env);
}