mescc: Support ?.
* module/language/c99/compiler.mes (ast->info): Support cond-expr. * scaffold/t.c (test): Test it.
This commit is contained in:
parent
b0e0ab014f
commit
c3eacb58df
|
@ -380,6 +380,41 @@
|
|||
body-text)
|
||||
#:globals (.globals body-info))))
|
||||
|
||||
((expr-stmt (cond-expr ,test ,then ,else))
|
||||
(let* ((text-length (length text))
|
||||
|
||||
(test-jump->info ((test->jump->info info) test))
|
||||
(test+jump-info (test-jump->info 0))
|
||||
(test-length (length (.text test+jump-info)))
|
||||
|
||||
(then-info ((ast->info test+jump-info) then))
|
||||
(text-then-info (.text then-info))
|
||||
(then-text (list-tail text-then-info test-length))
|
||||
(then-length (length (text->list then-text)))
|
||||
|
||||
(jump-text (list (lambda (f g t d) (i386:jump 0))))
|
||||
(jump-length (length (text->list jump-text)))
|
||||
(test+then+jump-info
|
||||
(clone then-info
|
||||
#:text (append (.text then-info) jump-text)))
|
||||
|
||||
(else-info ((ast->info test+then+jump-info) else))
|
||||
(text-else-info (.text else-info))
|
||||
(else-text (list-tail text-else-info (length (.text test+then+jump-info))))
|
||||
(else-length (length (text->list else-text)))
|
||||
|
||||
(text+test-text (.text (test-jump->info (+ then-length jump-length))))
|
||||
(test-text (list-tail text+test-text text-length))
|
||||
(jump-text (list (lambda (f g t d) (i386:jump else-length)))))
|
||||
|
||||
(clone info #:text
|
||||
(append text
|
||||
test-text
|
||||
then-text
|
||||
jump-text
|
||||
else-text)
|
||||
#:globals (.globals else-info))))
|
||||
|
||||
((for ,init ,test ,step ,body)
|
||||
(let* ((jump (pmatch test
|
||||
((lt ,a ,b) i386:jump-c)
|
||||
|
|
|
@ -156,6 +156,12 @@ test (char *p)
|
|||
puts ("t: if (--i)\n");
|
||||
if (--i) return 1;
|
||||
|
||||
puts ("t: (one == 1) ?");
|
||||
(one == 1) ? 1 : exit (1);
|
||||
|
||||
puts ("t: (f) ?");
|
||||
(f) ? exit (1) : 1;
|
||||
|
||||
puts ("t: if (1)\n");
|
||||
if (1) goto ok0;
|
||||
return 1;
|
||||
|
|
Loading…
Reference in a new issue