From 4c590780029e3923fd7d7b3b2f4ed63e43679114 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Sat, 18 Mar 2017 08:17:18 +0100 Subject: [PATCH] mescc: Support assignment test. * module/language/c99/compiler.mes (test->jump->info): Handle assignment. * doc/examples/t.c (test): Test it. --- module/language/c99/compiler.mes | 28 +++++++++++++++------------- scaffold/t.c | 17 ++++++----------- 2 files changed, 21 insertions(+), 24 deletions(-) diff --git a/module/language/c99/compiler.mes b/module/language/c99/compiler.mes index d66e1d41..59db6ac8 100644 --- a/module/language/c99/compiler.mes +++ b/module/language/c99/compiler.mes @@ -1014,7 +1014,7 @@ _))))) ))) (define (test->jump->info info) - (define (jump type) + (define (jump type . test) (lambda (o) (let* ((text (.text info)) (info (clone info #:text '())) @@ -1025,6 +1025,7 @@ _))))) (clone info #:text (append text (.text info) + (if (null? test) '() (car test)) (jump-text body-length))))))) (lambda (o) (pmatch o @@ -1074,18 +1075,19 @@ _))))) jump-text (.text (b-jump body-length))))))) - ((array-ref . _) ((jump (lambda (n) - (append - (i386:accu-zero?) - (i386:jump-byte-z n)))) o)) - ((de-ref _) ((jump (lambda (n) - (append - (i386:accu-zero?) - (i386:jump-byte-z n)))) o)) - (_ ((jump (lambda (n) - (append - (i386:accu-zero?) - (i386:Xjump-z n)))) o))))) + ((array-ref . _) ((jump i386:jump-byte-z + (list (lambda (f g ta t d) (i386:accu-zero?)))) o)) + + ((de-ref _) ((jump i386:jump-byte-z + (list (lambda (f g ta t d) (i386:accu-zero?)))) o)) + + ((assn-expr (p-expr (ident ,name)) ,op ,expr) + ((jump i386:Xjump-z + (append + ((ident->accu info) name) + (list (lambda (f g ta t d) (i386:accu-zero?))))) o)) + + (_ ((jump i386:Xjump-z (list (lambda (f g ta t d) (i386:accu-zero?)))) o))))) (define (cstring->number s) (cond ((string-prefix? "0x" s) (string->number (string-drop s 2) 16)) diff --git a/scaffold/t.c b/scaffold/t.c index 82165c41..b1193295 100644 --- a/scaffold/t.c +++ b/scaffold/t.c @@ -528,6 +528,12 @@ test (char *p) i -= 2; if (i != 0) return 1; + puts ("t: if (f = 0) ?\n"); + if (f = 0) return 1; + + puts ("t: if (!(t = 1)) ?\n"); + if (!(t = 1)) return 1; + puts ("t: (one == 1) ?\n"); (one == 1) ? 1 : exit (1); @@ -728,17 +734,6 @@ test (char *p) } #endif -int -init () -{ - // g_cells[0].cdr = 0; - // g_cells[1].cdr = 1; - g_functions[0] = g_foo; - g_functions[1] = g_bar; - - return 0; -} - int main (int argc, char *argv[]) {