diff options
| author | bellard <bellard> | 2003-10-04 21:25:32 +0000 |
|---|---|---|
| committer | bellard <bellard> | 2003-10-04 21:25:32 +0000 |
| commit | 9890ea1233a1caf84782a0ab364622a8444e0519 (patch) | |
| tree | 48bf2d06c42ac7432207a1d0c579263b9a1144b6 | |
| parent | feed3262c91df6e491e3f529192acdcc6a72f157 (diff) | |
| download | tinycc-9890ea1233a1caf84782a0ab364622a8444e0519.tar.gz tinycc-9890ea1233a1caf84782a0ab364622a8444e0519.tar.bz2 | |
added examples
| -rw-r--r-- | .cvsignore | 5 | ||||
| -rwxr-xr-x | ex1.c | 8 | ||||
| -rw-r--r-- | ex2.c | 97 | ||||
| -rw-r--r-- | ex3.c | 23 | ||||
| -rwxr-xr-x | ex4.c | 25 | ||||
| -rw-r--r-- | ex5.c | 8 |
6 files changed, 161 insertions, 5 deletions
@@ -2,8 +2,6 @@ tcc_g tcc tc2.c ex3 -ex1.c -ex2.c otcc1.c doc tc3s.c @@ -11,14 +9,11 @@ p3.c tc1.c error.c i386-gen1.c -ex4.c test.out2 test.out3 web.sh -ex3.c memdebug.c bench -ex5.c tcc-newparse.c p1.c Makefile.uClibc @@ -0,0 +1,8 @@ +#! /usr/local/bin/tcc -run +#include <tcclib.h> + +int main() +{ + printf("Hello World\n"); + return 0; +} @@ -0,0 +1,97 @@ +#include "tcclib.h" + +#define N 20 + +int nb_num; +int tab[N]; +int stack_ptr; +int stack_op[N]; +int stack_res[60]; +int result; + +int find(int n, int i1, int a, int b, int op) +{ + int i, j; + int c; + + if (stack_ptr >= 0) { + stack_res[3*stack_ptr] = a; + stack_op[stack_ptr] = op; + stack_res[3*stack_ptr+1] = b; + stack_res[3*stack_ptr+2] = n; + if (n == result) + return 1; + tab[i1] = n; + } + + for(i=0;i<nb_num;i++) { + for(j=i+1;j<nb_num;j++) { + a = tab[i]; + b = tab[j]; + if (a != 0 && b != 0) { + + tab[j] = 0; + stack_ptr++; + + if (find(a + b, i, a, b, '+')) + return 1; + if (find(a - b, i, a, b, '-')) + return 1; + if (find(b - a, i, b, a, '-')) + return 1; + if (find(a * b, i, a, b, '*')) + return 1; + if (b != 0) { + c = a / b; + if (find(c, i, a, b, '/')) + return 1; + } + + if (a != 0) { + c = b / a; + if (find(c, i, b, a, '/')) + return 1; + } + + stack_ptr--; + tab[i] = a; + tab[j] = b; + } + } + } + + return 0; +} + +int main(int argc, char **argv) +{ + int i, res, p; + + if (argc < 3) { + printf("usage: %s: result numbers...\n" + "Try to find result from numbers with the 4 basic operations.\n", argv[0]); + exit(1); + } + + p = 1; + result = atoi(argv[p]); + printf("result=%d\n", result); + nb_num = 0; + for(i=p+1;i<argc;i++) { + tab[nb_num++] = atoi(argv[i]); + } + + stack_ptr = -1; + res = find(0, 0, 0, 0, ' '); + if (res) { + for(i=0;i<=stack_ptr;i++) { + printf("%d %c %d = %d\n", + stack_res[3*i], stack_op[i], + stack_res[3*i+1], stack_res[3*i+2]); + } + return 0; + } else { + printf("Impossible\n"); + return 1; + } +} @@ -0,0 +1,23 @@ +#include <tcclib.h> + +int fib(n) +{ + if (n <= 2) + return 1; + else + return fib(n-1) + fib(n-2); +} + +int main(int argc, char **argv) +{ + int n; + if (argc < 2) { + printf("usage: fib n\n" + "Compute nth Fibonacci number\n"); + return 1; + } + + n = atoi(argv[1]); + printf("fib(%d) = %d\n", n, fib(n, 2)); + return 0; +} @@ -0,0 +1,25 @@ +#!./tcc -run -L/usr/X11R6/lib -lX11 +#include <stdlib.h> +/* Yes, TCC can use X11 too ! */ +#include <stdio.h> +#include <X11/Xlib.h> + +int main(int argc, char **argv) +{ + Display *display; + Screen *screen; + + display = XOpenDisplay(""); + if (!display) { + fprintf(stderr, "Could not open X11 display\n"); + exit(1); + } + printf("X11 display opened.\n"); + screen = XScreenOfDisplay(display, 0); + printf("width = %d\nheight = %d\ndepth = %d\n", + screen->width, + screen->height, + screen->root_depth); + XCloseDisplay(display); + return 0; +} @@ -0,0 +1,8 @@ +#include <stdlib.h> +#include <stdio.h> + +int main() +{ + printf("Hello World\n"); + return 0; +} |
