Back to index

plt-scheme  4.2.1
foreign-test.c
Go to the documentation of this file.
00001 #include <stdlib.h>
00002 
00003 typedef unsigned char byte;
00004 
00005 #ifdef _WIN32
00006 #define X __declspec(dllexport)
00007 #else
00008 #define X
00009 #endif
00010 
00011 X int  add1_int_int   (int  x) { return x + 1; }
00012 X int  add1_byte_int  (byte x) { return x + 1; }
00013 X byte add1_int_byte  (int  x) { return x + 1; }
00014 X byte add1_byte_byte (byte x) { return x + 1; }
00015 X int  decimal_int_int_int    (int  x, int  y) { return 10*x + y; }
00016 X int  decimal_byte_int_int   (byte x, int  y) { return 10*x + y; }
00017 X int  decimal_int_byte_int   (int  x, byte y) { return 10*x + y; }
00018 X int  decimal_byte_byte_int  (byte x, byte y) { return 10*x + y; }
00019 X byte decimal_int_int_byte   (int  x, int  y) { return 10*x + y; }
00020 X byte decimal_byte_int_byte  (byte x, int  y) { return 10*x + y; }
00021 X byte decimal_int_byte_byte  (int  x, byte y) { return 10*x + y; }
00022 X byte decimal_byte_byte_byte (byte x, byte y) { return 10*x + y; }
00023 
00024 X int  callback3_int_int_int    (int(*f)(int))   { if (f) return f(3); else return 79; }
00025 X int  callback3_byte_int_int   (int(*f)(byte))  { return f(3); }
00026 X int  callback3_int_byte_int   (byte(*f)(int))  { return f(3); }
00027 X int  callback3_byte_byte_int  (byte(*f)(byte)) { return f(3); }
00028 X byte callback3_int_int_byte   (int(*f)(int))   { return f(3); }
00029 X byte callback3_byte_int_byte  (int(*f)(byte))  { return f(3); }
00030 X byte callback3_int_byte_byte  (byte(*f)(int))  { return f(3); }
00031 X byte callback3_byte_byte_byte (byte(*f)(byte)) { return f(3); }
00032 
00033 X int g1;
00034 X int  curry_ret_int_int   (int  x) { return g1 + x; }
00035 X int  curry_ret_byte_int  (byte x) { return g1 + x; }
00036 X byte curry_ret_int_byte  (int  x) { return g1 + x; }
00037 X byte curry_ret_byte_byte (byte x) { return g1 + x; }
00038 X void* curry_int_int_int   (int  x)  { g1 = x; return &curry_ret_int_int;   }
00039 X void* curry_byte_int_int  (byte x)  { g1 = x; return &curry_ret_int_int;   }
00040 X void* curry_int_byte_int  (int  x)  { g1 = x; return &curry_ret_byte_int;  }
00041 X void* curry_byte_byte_int (byte x)  { g1 = x; return &curry_ret_byte_int;  }
00042 X void* curry_int_int_byte  (int  x)  { g1 = x; return &curry_ret_int_byte;  }
00043 X void* curry_byte_int_byte (byte x)  { g1 = x; return &curry_ret_int_byte;  }
00044 X void* curry_int_byte_byte (int  x)  { g1 = x; return &curry_ret_byte_byte; }
00045 X void* curry_byte_byte_byte(byte x)  { g1 = x; return &curry_ret_byte_byte; }
00046 
00047 X int g2;
00048 X int ho_return(int x) { return g2 + x; }
00049 X void* ho(int(*f)(int), int x) { g2 = f(x); return ho_return; }
00050 
00051 X void *g3 = NULL;
00052 X int use_g3(int x) { return ((int(*)(int))g3)(x); }
00053 
00054 /* typedef int(*int2int)(int); */
00055 /* typedef int2int(*int_to_int2int)(int); */
00056 /* int hoho(int x, int_to_int2int f) { */
00057 X int hoho(int x, int(*(*f)(int))(int)) { return (f(x+1))(x-1); }
00058 
00059 X int grab7th(void *p) { return ((char *)p)[7]; }
00060 
00061 X int vec4(int x[]) { return x[0]+x[1]+x[2]+x[3]; }
00062 
00063 typedef struct _char_int { unsigned char a; int b; } char_int;
00064 X int charint_to_int(char_int x) { return ((int)x.a) + x.b; }
00065 X char_int int_to_charint(int x) {
00066   char_int result;
00067   result.a = (unsigned char)x;
00068   result.b = x;
00069   return result;
00070 }
00071 X char_int charint_swap(char_int x) {
00072   char_int result;
00073   result.a = (unsigned char)x.b;
00074   result.b = (int)x.a;
00075   return result;
00076 }
00077 
00078 int(*grabbed_callback)(int) = NULL;
00079 X void grab_callback(int(*f)(int)) { grabbed_callback = f; }
00080 X int use_grabbed_callback(int n) { return grabbed_callback(n); }