Mercurial > hg > Members > nobuyasu > CbC
changeset 13:f29ec9081099 draft
modify fibonacci2.cbc
author | Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 15 Jun 2012 04:18:53 +0900 |
parents | 774d70d1ea62 |
children | 43cfb6cbf809 |
files | fibonacci/Makefile fibonacci/fibonacci.cbc fibonacci/fibonacci2.cbc |
diffstat | 3 files changed, 20 insertions(+), 30 deletions(-) [+] |
line wrap: on
line diff
--- a/fibonacci/Makefile Mon Jun 04 02:45:53 2012 +0900 +++ b/fibonacci/Makefile Fri Jun 15 04:18:53 2012 +0900 @@ -1,15 +1,15 @@ -CC=gcc -CbCC=cbc-gcc-4.6 +CbCC=cbc-gcc-4.6.0 -CFLAGS=-O3 +#CFLAGS="-O3 -v" +CFLAGS=-O2 PROGRAM= cbc_fibonacci2 c_fibonacci2 all: $(PROGRAM) -cbc_fibonnacci2: fibonacci2.cbc +cbc_fibonacci2: fibonacci2.cbc $(CbCC) $(CFLAGS) -o $@ $^ c_fibonacci2: fibonacci2.c - $(CC) $(CFLAGS) -o $@ $^ + $(CbCC) $(CFLAGS) -o $@ $^ clean: - rm -rf *.{o,s} $(PROGRAM) \ No newline at end of file + rm e $(PROGRAM) \ No newline at end of file
--- a/fibonacci/fibonacci.cbc Mon Jun 04 02:45:53 2012 +0900 +++ b/fibonacci/fibonacci.cbc Fri Jun 15 04:18:53 2012 +0900 @@ -1,13 +1,10 @@ #include <stdio.h> #include <stdlib.h> - -__code print(__rectype *p, int num, int count, int result, int prev) { - printf("fibonacci(%d) = %d\n",num,result); +__code print(__rectype *p, long int num, long int count, long int result, long int prev) { + printf("fibonacci(%lld) = %lld\n",num,result); exit(0); } - -__code fibonacci(__rectype *p, int num, int count, int result, int prev) { - int tmp; +__code fibonacci(__rectype *p, long int num, long int count, long int result, long int prev) { if (count == 0) { result += 0; count++; @@ -15,7 +12,7 @@ result += 1; count++; } else if (count > 1){ - tmp = prev; + long int tmp = prev; prev = result; result = result + tmp; count++; @@ -26,18 +23,13 @@ if (num < count) goto p(fibonacci, num, count, result, prev); goto fibonacci(p, num, count, result, prev); - } - - - - int main(int argc, char* argv[]) { if (argc < 2) { printf("usage: ./fibonacci number \n"); exit(0); } - int num = atoi(argv[1]); + long int num = (long int)atoi(argv[1]); goto fibonacci(print, num, 0, 0, 0); return 0;
--- a/fibonacci/fibonacci2.cbc Mon Jun 04 02:45:53 2012 +0900 +++ b/fibonacci/fibonacci2.cbc Fri Jun 15 04:18:53 2012 +0900 @@ -1,15 +1,13 @@ #include <stdio.h> #include <stdlib.h> - -__code print(__rectype *p, int num, int count, int result, int prev) { - printf("fibonacci(%d) = %d\n",num,result); - +__code print(__rectype *p, long int num, long int count, long int result, long int prev) { + printf("fibonacci(%d) = %lld\n",num,result); goto cs_while(print, num, count, result, prev); - // exit(0); } -__code fibonacci(__rectype *p, int num, int count, int result, int prev) { +__code fibonacci(__rectype *p, long int num, long int count, long int result, long int prev) { +//__code fibonacci(__code (*p)(__code(*)(__rectype),int), long int num, long int count, long int result, long int prev) { if (count == 0) { result += 0; count++; @@ -17,7 +15,7 @@ result += 1; count++; } else if (count > 1){ - int tmp = prev; + long int tmp = prev; prev = result; result = result + tmp; count++; @@ -25,13 +23,13 @@ printf("please enter nutural number\n"); exit(0); } - if (num < count) + if (num < count) { goto p(fibonacci, num, count, result, prev); + } goto fibonacci(p, num, count, result, prev); - } -__code cs_while(__rectype *p, int num, int count, int result, int prev) { +__code cs_while(__rectype *p, long int num, long int count, long int result, long int prev) { if (num > 0) { num--; goto fibonacci(print, num, 0, 0, 0); @@ -45,7 +43,7 @@ printf("usage: ./fibonacci number \n"); exit(0); } - int num = atoi(argv[1]); + long int num = (long int)atoi(argv[1]); goto fibonacci(print, num, 0, 0, 0); return 0;