diff --git a/module/language/c99/compiler.mes b/module/language/c99/compiler.mes index f160dcea..49c11099 100644 --- a/module/language/c99/compiler.mes +++ b/module/language/c99/compiler.mes @@ -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) diff --git a/scaffold/t.c b/scaffold/t.c index ce529e3e..ae1949a4 100644 --- a/scaffold/t.c +++ b/scaffold/t.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;