corda/src/main.cpp

73 lines
1.3 KiB
C++
Raw Normal View History

#include "common.h"
2007-06-20 19:20:25 +00:00
#include "system.h"
#include "heap.h"
#include "finder.h"
#include "processor.h"
#include "machine.h"
2007-06-20 19:20:25 +00:00
using namespace vm;
extern "C" void __cxa_pure_virtual(void) { abort(); }
2007-06-20 19:20:25 +00:00
namespace {
int
2007-06-20 19:20:25 +00:00
run(unsigned heapSize, const char* path, const char* class_, int argc,
const char** argv)
{
System* s = makeSystem(heapSize);
Finder* f = makeFinder(s, path);
Heap* heap = makeHeap(s);
Processor* p = makeProcessor(s);
2007-06-20 19:20:25 +00:00
int exitCode = run(s, heap, f, p, class_, argc, argv);
2007-06-20 19:20:25 +00:00
p->dispose();
2007-06-20 19:20:25 +00:00
heap->dispose();
f->dispose();
s->dispose();
return exitCode;
2007-06-20 19:20:25 +00:00
}
void
usageAndExit(const char* name)
{
fprintf(stderr, "usage: %s [-cp <classpath>] [-hs <maximum heap size>] "
2007-06-20 21:27:22 +00:00
"<class name> [<argument> ...]\n", name);
2007-06-20 19:20:25 +00:00
exit(-1);
}
} // namespace
int
main(int ac, const char** av)
{
unsigned heapSize = 128 * 1024 * 1024;
2007-06-20 19:20:25 +00:00
const char* path = ".";
const char* class_ = 0;
int argc = 0;
const char** argv = 0;
for (int i = 1; i < ac; ++i) {
if (strcmp(av[i], "-cp") == 0) {
path = av[++i];
} else if (strcmp(av[i], "-hs") == 0) {
heapSize = atoi(av[++i]);
} else {
class_ = av[i++];
if (i < ac) {
argc = ac - i;
argv = av + i;
i = ac;
}
}
}
if (class_ == 0) {
usageAndExit(av[0]);
}
return run(heapSize, path, class_, argc, argv);
2007-06-20 19:20:25 +00:00
}