Updating built in Io code to use += instead of x = x + y
[io/quag.git] / tools / source / main.c
blobb4bea612c66ff17792aca60fb2be76c878e1cc47
1 #include "IoState.h"
3 void IoAddonsInit(IoObject *context);
5 //#define IOBINDINGS
7 #ifdef IO_CHECK_ALLOC
8 #define IO_SHOW_STATS 1
9 #endif
11 #ifdef IO_SHOW_STATS
12 #include <time.h>
13 #include <sys/time.h>
14 #include <sys/resource.h>
16 double System_UserTime(void)
18 struct rusage u;
19 int r = getrusage(0, &u);
20 return r == -1 ? -1 : u.ru_utime.tv_sec + (((double)u.ru_utime.tv_usec)/1000000);
23 #endif
25 int main(int argc, const char *argv[])
27 int exitResult;
28 IoState *self;
29 #ifdef IO_SHOW_STATS
30 size_t t1 = clock();
31 size_t maxAllocatedBytes;
32 double collectorTime;
33 size_t sweepCount;
34 #endif
37 self = IoState_new();
38 #ifdef IOBINDINGS
39 IoState_setBindingsInitCallback(self, (IoStateBindingsInitCallback *)IoAddonsInit);
40 #endif
41 IoState_init(self);
42 IoState_argc_argv_(self, argc, argv);
43 IoState_runCLI(self);
44 exitResult = IoState_exitResult(self);
46 #ifdef IO_SHOW_STATS
47 maxAllocatedBytes = io_maxAllocatedBytes();
48 collectorTime = Collector_timeUsed(self->collector);
49 sweepCount = self->collector->sweepCount;
50 #endif
52 IoState_free(self);
54 #ifdef IO_SHOW_STATS
56 float totalTime = (clock()-t1)/(float)CLOCKS_PER_SEC;
57 printf("[ %.3fs user %.3fs total %.1f%% gc %i sweeps %i frees %.3fmb max ]\n",
58 System_UserTime(),
59 totalTime,
60 100.0*collectorTime/totalTime,
61 (int)sweepCount,
62 (int)io_frees(),
63 maxAllocatedBytes/1048576.0);
65 if(io_allocatedBytes() != 0)
67 printf("warning: %i bytes in %i blocks not freed:\n\n",
68 (int)io_allocatedBytes(), (int)(io_allocs() - io_frees()));
69 io_showUnfreed();
71 else
73 printf("[ no memory leaks found ]\n");
76 #endif
78 return exitResult;