changeset 4:175041088754

fix examples.
author Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
date Wed, 22 Oct 2014 18:54:12 +0900
parents 18eda8cb71e9
children 90e6146d24cd
files Makefile test1.c tmp1.c tmp2.c tmp4.c too-long-argument.c
diffstat 6 files changed, 76 insertions(+), 69 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Wed Oct 22 02:12:59 2014 +0900
+++ b/Makefile	Wed Oct 22 18:54:12 2014 +0900
@@ -1,6 +1,6 @@
 CC=/Users/e105711/prog/seminar/CbC/llvmInst/Debug+Asserts/bin/clang
-TARGET=bug conv fact-a loto6 normal normal2 test01 test02 test04 test05 test2 test_array test_call test_cs test_para test_para2 test_para4 test_return test_struct test_tailcall1 test_tree tmp1 tmp2 tmp4 test_csp1 test_func2code tmpa too-long-argument
-CFLAGS=-O2 -D"CLANG"
+TARGET=bug conv fact-a loto6 normal normal2 test01 test02 test04 test05 test_array test_call test_cs test_para test_para2 test_para4 test_return test_struct test_tailcall1 test_tree tmp1 tmp2 tmp4 test_csp1 test_func2code tmpa too-long-argument test1 
+CFLAGS= -D"CLANG"
 
 .SUFFIXES: .c .o
 
@@ -12,3 +12,4 @@
 clean:
 	rm -f $(TARGET)
 	rm -f *.o
+	rm -f a.out
--- a/test1.c	Wed Oct 22 02:12:59 2014 +0900
+++ b/test1.c	Wed Oct 22 18:54:12 2014 +0900
@@ -4,124 +4,124 @@
 #endif
 
 /*
-    test for CbC converted __code from C
- */
+  test for CbC converted __code from C
+*/
 
 #include <stdio.h>
+#include <stdlib.h>
 
-extern void *malloc(int);
 
 typedef void *stack;
 
 void *stack0;      /* size of void* == 1 */
 
 struct cont_save { /* General Return Continuation */
-    __code (*ret)();
+  __code (*ret)(int,void*);
 };
 
 /*
-    __code g(int,void *);
-    __code f_g0(int ,int ,void *);
-    __code f_g1(int,void *);
+  __code g(int,void *);
+  __code f_g0(int ,int ,void *);
+  __code f_g1(int,void *);
 */
 
 struct f_g0_save {  /* Specialized Return Continuation */
-    __code (*ret)();
-    int ii,kk,jj;
+  __code (*ret)(int,void*);
+  int ii,kk,jj;
 };
 
 __code g(int i,void *sp) {
-    goto (* ((struct cont_save *)sp)->ret)(i+4,sp);
+  goto (* ((struct cont_save *)sp)->ret)(i+4,sp);
 }
 
 __code f_g1(int j,void *sp) {  /* Continuation  */
-    int k;
-    struct f_g0_save *c;
+  int k;
+  struct f_g0_save *c;
 
-    c = sp;
-    k = c->kk;
-    sp += sizeof(struct f_g0_save);
-    goto (* ((struct cont_save *)sp)->ret)(k+4+j,sp);
+  c = sp;
+  k = c->kk;
+  sp += sizeof(struct f_g0_save);
+  goto (* ((struct cont_save *)sp)->ret)(k+4+j,sp);
 }
 
 __code f(int i,void *sp) {
-    int k,j;
-    struct f_g0_save *c;
-printf("#0047:f 0 sp: %x\n",sp-stack0);
+  int k,j;
+  struct f_g0_save *c;
+  printf("#0047:f 0 sp: %lx\n",sp-stack0);
 
-    k = 3+i;
+  k = 3+i;
 
-printf("#0051:f 1 sp: %x\n",sp-stack0);
-    sp -= sizeof(struct f_g0_save);
-printf("#0053:f 2 sp: %x\n",sp-stack0);
-    c = sp;
-    c->kk = k;
-    c->ii = i;
-    c->jj = j;
-    c->ret = f_g1;
-    goto g(i,sp);
+  printf("#0051:f 1 sp: %lx\n",sp-stack0);
+  sp -= sizeof(struct f_g0_save);
+  printf("#0053:f 2 sp: %lx\n",sp-stack0);
+  c = sp;
+  c->kk = k;
+  c->ii = i;
+  c->jj = j;
+  c->ret = f_g1;
+  goto g(i,sp);
 }
 
 
 
 struct f0_save {  /* Specialized Return Continuation */
-	__code (*ret)();
-	__code (*exit1)();
-	void *exit1env;
-	int jj;
+  __code (*ret)();
+  __code (*exit1)();
+  void *exit1env;
+  int jj;
 };
 
 __code f1(int i,void *sp) ;
 __code f0(int i,int j,__code(*exit2)(), void *exit2env,void *sp)
 {
-	struct f0_save *c;
-    printf("#0075:f0 1 sp: %x\n",sp-stack0);
-	sp -= sizeof(struct f0_save);
-    printf("#0077:f0 2 sp: %x\n",sp-stack0);
-	c = sp;
-	c->jj = j;
-        c->exit1 = exit2;
-        c->exit1env = exit2env;
-	c->ret = f1;
-    printf("#0083:f0 3 sp: %x\n",sp-stack0);
-	goto f(i,sp);
+  struct f0_save *c;
+  printf("#0075:f0 1 sp: %lx\n",sp-stack0);
+  sp -= sizeof(struct f0_save);
+  printf("#0077:f0 2 sp: %lx\n",sp-stack0);
+  c = sp;
+  c->jj = j;
+  c->exit1 = exit2;
+  c->exit1env = exit2env;
+  c->ret = f1;
+  printf("#0083:f0 3 sp: %lx\n",sp-stack0);
+  goto f(i,sp);
 }
 
 __code print(int i,int j,__code (*exit1)(),void*exit1env);
 
 __code f1(int i,void *sp) {
-	int j;
-	int *exit2env;
-	__code (*exit2)();
-	struct f0_save *c;
+  int j;
+  int *exit2env;
+  __code (*exit2)();
+  struct f0_save *c;
 
-        c = sp;
-        j = c->jj;
-        exit2 = c->exit1;
-        exit2env = c->exit1env;
+  c = sp;
+  j = c->jj;
+  exit2 = c->exit1;
+  exit2env = c->exit1env;
 
-	sp += sizeof(struct f0_save);
-	goto print(i,j,exit2,exit2env);
+  sp += sizeof(struct f0_save);
+  goto print(i,j,exit2,exit2env);
 }
 
 int main( int ac, char *av[])
 {
-    int i,j;
-    int *sp;
+  int i,j;
+  int *sp;
 
-    // i = atoi(av[1]);
-    i = 1;
-    stack0 = ((char *)malloc(1024)+1024);
-    sp = stack0;
-    j = i;
+  // i = atoi(av[1]);
+  i = 1;
+  stack0 = ((char *)malloc(1024)+1024);
+  sp = stack0;
+  j = i;
     
-    printf("#0115:sp: %x %x\n",sp-(int*)stack0,sizeof(*stack0));
-    goto f0(i,j,__return,__environment,sp);
+  printf("#0115:sp: %lx %lx\n",sp-(int*)stack0,sizeof(*stack0));
+  goto f0(i,j,__return,__environment,sp);
 }
 
-__code print(int i,int j,__code (*exit1)(),void*exit1env)
+__code print(int i,int j,__code (*exit1)(int,void*),void*exit1env)
 {
-    printf("#0121:%d %d\n",i,j);
-    goto (*exit1)(0,exit1env);
+  printf("#0121:%d %d\n",i,j);
+  goto (*exit1)(0,exit1env);
 }
 
--- a/tmp1.c	Wed Oct 22 02:12:59 2014 +0900
+++ b/tmp1.c	Wed Oct 22 18:54:12 2014 +0900
@@ -3,7 +3,6 @@
 #define __environment _CbC_environment
 #define __return _CbC_return
 #endif
-
 extern int printf(const char *,...);
 
 __code (*ret)(int, void*);
@@ -24,6 +23,7 @@
   goto code1(ac,av,exit1);
   // not reached. (warning?)
   printf("#0022:main0 %d end.\n",ac);
+  return 0;
 }
 
 __code exit1(int ac,void *vp)
--- a/tmp2.c	Wed Oct 22 02:12:59 2014 +0900
+++ b/tmp2.c	Wed Oct 22 18:54:12 2014 +0900
@@ -23,6 +23,7 @@
 {
     fprintf(stdout,"#0021:2: %s\n",av[0]);
     goto code0(av,__return,__environment);
+    return 0;
 }
 
 __code code0(char *av[],__code (*ret)(int,void*),void *retenv)
--- a/tmp4.c	Wed Oct 22 02:12:59 2014 +0900
+++ b/tmp4.c	Wed Oct 22 18:54:12 2014 +0900
@@ -28,6 +28,7 @@
     k=789;
     fprintf(stdout,"#0025:2: %s\n",av[0]+2);
     goto code0(i,j,k,av,__return,__environment);
+    return 0;
 }
 
 __code code0(int i,int j,int k,char *av[],__code (*ret)(int,void*),void*retenv)
--- a/too-long-argument.c	Wed Oct 22 02:12:59 2014 +0900
+++ b/too-long-argument.c	Wed Oct 22 18:54:12 2014 +0900
@@ -63,6 +63,7 @@
   goto tcode2(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,
               __return,__environment);
 #endif
+  return 0;
 }
 
 int
@@ -75,18 +76,21 @@
   goto tcode1(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,
               __return,__environment);
 #endif
+  return 0;
 }
 
 int
 main2()
 {
   goto tcode0(0,1,tcode1,__return,__environment);
+  return 0;
 }
 
 int
 main4()
 {
   goto tcode4(0,1,tcode2,__return,__environment);
+  return 0;
 }
 
 int