mescc: Fix d-sel comparisons.

* module/language/c99/compiler.mes (ast->info): Save base while
computing accu. Fix comparison using d-sel in second argument.
* doc/examples/t.c: Test it.
* doc/examples/mini-mes.c (assq): Use it.
This commit is contained in:
Jan Nieuwenhuizen 2017-03-14 00:15:13 +01:00
parent d039b00349
commit a2f180ba4a
3 changed files with 36 additions and 44 deletions

View file

@ -1522,7 +1522,10 @@ _)))))
(clone info #:text
(append text
(.text base)
(list (lambda (f g ta t d)
(i386:push-base)))
(.text accu)
(i386:pop-accu)
(list (lambda (f g ta t d)
(i386:sub-base)))))))
@ -1533,7 +1536,11 @@ _)))))
(clone info #:text
(append text
(.text base)
(list (lambda (f g ta t d)
(i386:push-base)))
(.text accu)
(list (lambda (f g ta t d)
(i386:pop-base)))
(list (lambda (f g ta t d)
(i386:sub-base)))))))
@ -1544,7 +1551,11 @@ _)))))
(clone info #:text
(append text
(.text base)
(list (lambda (f g ta t d)
(i386:push-base)))
(.text accu)
(list (lambda (f g ta t d)
(i386:pop-base)))
(list (lambda (f g ta t d)
(append
(i386:sub-base)
@ -1557,6 +1568,8 @@ _)))))
(clone info #:text
(append text
(.text base)
(list (lambda (f g ta t d)
(i386:push-base)))
(.text accu)
(list (lambda (f g ta t d)
(i386:base-sub)))))))
@ -1569,7 +1582,11 @@ _)))))
(clone info #:text
(append text
(.text base)
(list (lambda (f g ta t d)
(i386:push-base)))
(.text accu)
(list (lambda (f g ta t d)
(i386:pop-base)))
(list (lambda (f g ta t d)
(i386:base-sub)))))))

View file

@ -616,51 +616,9 @@ call (SCM fn, SCM x)
SCM
assq (SCM x, SCM a)
{
//FIXME: todo eq_p
//while (a != cell_nil && eq_p (x, CAAR (a)) == cell_f) a = CDR (a);
//while (a != cell_nil && x != CAAR (a)) a = CDR (a);
#if BDEBUG
puts ("assq: ");
display_ (x);
puts (" [");
puts (itoa (x));
puts ("]\n");
#endif
int i;
while (a != cell_nil) // && x != CAR (CAR (a)))
{
a = CDR (a);
// FIXME
i = CAR (CAR (a));
#if 1
//!__GNUC__
// puts (" ");
// puts (itoa (i));
// if (x == i) puts ("***FOUND*** ");
if (x == i) goto found;
// puts (" ");
// display_ (CAAR (a));
// puts ("[");
// puts (itoa (CAAR (a)));
// puts ("]\n");
#endif
}
found:
#if BDEBUG
//!__GNUC__
//puts ("assq: ");
puts (" ");
puts (" [");
puts (itoa (x));
puts ("]");
display_ (x);
puts (" => ");
if (a == cell_nil) display_ (cell_f);
else display_ (CAR (a));
puts ("[");
puts (itoa (CDR (CDR (CAR (a)))));
puts ("]\n");
#endif
while (a != cell_nil && x != CAAR (a)) a = CDR (a);
return a != cell_nil ? car (a) : cell_f;
}

View file

@ -129,6 +129,8 @@ int ARENA_SIZE = 200;
#define CDR(x) g_cells[x].cdr
#define VALUE(x) g_cells[x].cdr
#define CAAR(x) CAR (CAR (x))
struct scm scm_fun = {TFUNCTION,0,0};
SCM cell_fun;
@ -321,6 +323,15 @@ make_tmps_test (struct scm* cells)
int
struct_test ()
{
g_cells[0].car = 1;
g_cells[1].car = 2;
puts ("t: CAAR (0) != 2\n");
if (CAAR (0) != 2) return 1;
puts ("t: 2 != CAAR (0)\n");
if (2 != CAAR (0)) return 1;
g_cells[3].type = 0x64;
if (g_cells[3].type != 0x64)
return g_cells[3].type;
@ -460,6 +471,12 @@ test (char *p)
puts ("t: if (f)\n");
if (f) return 1;
puts ("t: if (one != 1)\n");
if (one != 1) return 1;
puts ("t: if (1 != one)\n");
if (1 != one) return 1;
puts ("t: if (one > 1)\n");
if (one > 1) return 1;