mescc: Support do .. while.

* module/language/c99/compiler.mes (ast->info): Support do-while.
* doc/examples/t.c (test): Test it.
This commit is contained in:
Jan Nieuwenhuizen 2017-03-12 11:05:00 +01:00
parent 76f1a89cef
commit 3268027e46
2 changed files with 37 additions and 0 deletions

View file

@ -1303,6 +1303,30 @@
jump-text)
#:globals (.globals body-info))))
((do-while ,body ,test)
(let* ((text-length (length text))
(body-info ((ast->info info) body))
(body-text (list-tail (.text body-info) text-length))
(body-length (length (text->list body-text)))
(empty (clone info #:text '()))
(test-jump->info ((test->jump->info empty) test))
(test+jump-info (test-jump->info 0))
(test-length (length (text->list (.text test+jump-info))))
(jump-text (list (lambda (f g ta t d)
(i386:Xjump (- (+ body-length test-length))))))
(jump-length (length (text->list jump-text)))
(test-text (.text (test-jump->info jump-length))))
(clone info #:text
(append
(.text body-info)
test-text
jump-text)
#:globals (.globals body-info))))
((labeled-stmt (ident ,label) ,statement)
(let ((info (clone info #:text (append text (list label)))))
((ast->info info) statement)))

View file

@ -395,6 +395,19 @@ test (char *p)
char *x = arena;
char *y = g_chars;
puts ("t: for (i=1; i<5; ++i)\n");
for (i=1; i<5; ++i);
if (i != 5) return i;
puts ("t: while (i<3) i++\n");
i = 1;
while (i<3) i++;
if (i != 3) return i;
puts ("t: do i-- while (i>0)\n");
do i--; while (i>0);
if (i != 0) return 1;
puts ("t: if (0)\n");
if (0) return 1;