changeset 800:c3957d127e17

minor fix
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Wed, 24 Nov 2010 10:50:18 +0900
parents 56ba015b37ca
children 6b93d95a1564
files mc-parse.c test/regargs.c test/tstdarg.c
diffstat 3 files changed, 83 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/mc-parse.c	Tue Nov 23 23:05:08 2010 +0900
+++ b/mc-parse.c	Wed Nov 24 10:50:18 2010 +0900
@@ -21,6 +21,11 @@
 
 #include <stdio.h>
 // #include <stdlib.h>  // for malloc
+// this in ./stdio.h
+//extern     void * malloc(size_t size);
+//extern     void * realloc(void *ptr, size_t size);
+
+
 
 #include "mc.h"
 #include "mc-parse.h"
@@ -303,7 +308,7 @@
 	heapsize *= 2;
 	if (HEAP_REPORT)
 	    fprintf(stderr,"** heap extended to %d\n",heapsize);
-	heap = (int*)realloc(heap,heapsize*sizeof(int));
+	heap = (int*)realloc((void*)heap,heapsize*sizeof(int));
 	if(!heap) { error(MMERR); exit(1); }
     }
     set_lfree(heapsize);
@@ -3854,7 +3859,7 @@
 	type = FLOAT;
 	if (is_const(e)) {
 #if FLOAT_CODE
-	    return (dcadr(e)>0.0) ? dcadr(e) : dlist2(FCONST,-dcadr(e));
+	    return (dcadr(e)>0.0) ? e : dlist2(FCONST,-dcadr(e));
 #endif
 	}
 	return e;
@@ -3869,7 +3874,7 @@
 	type = DOUBLE;
 	if (is_const(e)) {
 #if FLOAT_CODE
-	    return (dcadr(e)>0.0) ? dcadr(e) : dlist2(DCONST,-dcadr(e));
+	    return (dcadr(e)>0.0) ? e : dlist2(DCONST,-dcadr(e));
 #endif
 	}
 	return e;
--- a/test/regargs.c	Tue Nov 23 23:05:08 2010 +0900
+++ b/test/regargs.c	Wed Nov 24 10:50:18 2010 +0900
@@ -1,21 +1,93 @@
 int printf(const char *format, ...);
 
+extern  unsigned long strlen(const char *s);
+
 
 void
 arg1(int a1,int a2,int a3,int a4)
 {
-    printf("#0006:%d %d %d %d\n",a1,a2,a3,a4);
+    printf("#0008:%d %d %d %d\n",a1,a2,a3,a4);
 }
 
 void
 arg0(int a1,int a2,int a3,int a4)
 {
     arg1(0,1,2,3);
-    printf("#0013:%d %d %d %d\n",a1,a2,a3,a4);
+    printf("#0015:%d %d %d %d\n",a1,a2,a3,a4);
+}
+
+
+static int gcd(int i0,int j0)
+{
+    register int k,i=i0,j=j0;
+    if (i<j) { k=i; i=j; j=k;}
+    for(;;) {
+        if ((k=i%j)==0) return j;
+        i = j; j = k;
+    }
+}
+
+static int test_register()
+{
+    register int a=122,b=22,c=34,d=44,e=5,f;
+    printf("#0032: %d %d %d %d %d\n",a,b,c,d,e,f);
+
+    f = gcd(a,b);
+    e = gcd(c,d);
+    f = gcd(a,f);
+    e = gcd(a,e);
+    printf("#0038: %d %d %d %d %d\n",a,b,c,d,e,f);
+    
 }
+
+static char *float_one_lib[] = {
+  "        .literal8",
+"        .align 3",
+"__float_one:",
+"        .long   0",
+"        .long   1072693248",
+        0
+};
+
+static int float_one_lib_used = 1;
+
+static void
+emit_lib(char *p[])
+{
+  while(*p) {
+    printf("#0057:%s\n",*p++);
+  }
+}
+
+void
+code_closing()
+{
+  if (float_one_lib_used) emit_lib(float_one_lib);
+}
+
+void
+return_value()
+{
+    printf("#0070:%ld\n",strlen("test"));
+    int ia =3, ib = 4;
+    printf("#0072:%d\n", ia*ib >ib? ia*3 : ia/4);
+    float fa =3, fb = 4;
+    printf("#0074:%f\n", fa*fb >fb? fa*3 : fa/4);
+    double ga =3, gb = 4;
+    printf("#0076:%g\n", ga*gb >gb? ga*3 : ga/4);
+    long long la =3, lb = 4;
+    printf("#0078:%lld\n", la*lb >lb? la*3 : la/4);
+}
+
+
 int
 main()
 {
     arg0(0,1,2,3);
+    test_register();
+    code_closing();
+    return_value();
     return 0;
 }
+
+
--- a/test/tstdarg.c	Tue Nov 23 23:05:08 2010 +0900
+++ b/test/tstdarg.c	Wed Nov 24 10:50:18 2010 +0900
@@ -18,7 +18,7 @@
     while((t= *numtypes++)) {
 	if (t=='i') {
 	    i = va_arg(ap,int);
-	    printf("#0021:int arg: %d\n",i);
+	    printf("#0020:int arg: %d\n",i);
 
 #if 0        /*  ‘float’ is promoted to ‘double’ when passed through ‘...’ */
 	} else if (t=='f') {