int skb_init(void) { int n; ec_set_option_int(EC_OPTION_IO, MEMORY_IO); ec_set_option_ptr(EC_OPTION_ECLIPSEDIR, ECLIPSE_DIR); ec_set_option_long(EC_OPTION_GLOBALSIZE, MEMORY_SIZE); ec_set_option_int(EC_OPTION_IO, MEMORY_IO); SKB_DEBUG("\ninitialize eclipse\n"); n = ec_init(); if (n != 0) { SKB_DEBUG("\nskb_main: ec_init() failed."); } return (n); }
main(int argc, char **argv) { char * eclipsedir = (char *) 0; int c, new_argc, err; int init_flags = INIT_SHARED|INIT_PRIVATE|INIT_ENGINE|INIT_PROCESS; char * session, * nsrv_hostname; unsigned nsrv_port_number; uword size; /* * If stdio is not a tty, get rid of the console window. This is not ideal * since the window flashes up briefly, but no better solution yet. * (The correct way would be not to build eclipse.exe as a "console * application" and have a WinMain() instead of main(). But then we have * to do all the setup of stdin/out/err, argc/argv, environment etc * ourselves) */ if (!isatty(_fileno(stdin)) && !isatty(_fileno(stdout)) && !isatty(_fileno(stderr))) { FreeConsole(); } /* * collect information from the command line * remove some internally used arguments from the command line */ for (c = new_argc = 1; c < argc; ) { if (argv[c][0] == '-' && argv[c][2] == 0) /* single char opt */ { switch (argv[c][1]) { case 'a': /* -a <worker> <session> <nsrv_hostname> <nsrv_port_no> */ if (++c + 4 > argc) usage(argv[c-1]); ec_set_option_int(EC_OPTION_PARALLEL_WORKER, atoi(argv[c++])); session = argv[c++]; nsrv_hostname = argv[c++]; nsrv_port_number = atoi(argv[c++]); break; case 'c': /* -c <shared_map_file> */ if (++c + 1 > argc) usage(argv[c-1]); ec_set_option_ptr(EC_OPTION_MAPFILE, argv[c++]); ec_set_option_int(EC_OPTION_ALLOCATION, ALLOC_FIXED); init_flags &= ~INIT_SHARED; break; case 'm': /* -m <shared_map_file> */ if (++c + 1 > argc) usage(argv[c-1]); ec_set_option_ptr(EC_OPTION_MAPFILE, argv[c++]); ec_set_option_int(EC_OPTION_ALLOCATION, ALLOC_FIXED); break; case 'b': /* -b <bootfile> */ argv[new_argc++] = argv[c]; /* shift */ if (++c + 1 > argc) usage(argv[c-1]); argv[new_argc++] = argv[c++]; /* shift */ break; case 'e': /* -e <goal> */ argv[new_argc++] = argv[c]; /* shift */ if (++c + 1 > argc) usage(argv[c-1]); argv[new_argc++] = argv[c++]; /* shift */ break; case 'g': /* -g <size> */ argv[new_argc++] = argv[c]; /* shift */ if (++c + 1 > argc) usage(argv[c-1]); argv[new_argc++] = argv[c]; /* shift */ size = sizearg(argv[c++]); ec_set_option_long(EC_OPTION_GLOBALSIZE, size); if (size < MIN_GLOBAL) { fprintf(stderr,"Global stack size out of range\n"); exit(-1); } break; case 'd': /* -d <n> */ /* delay worker startup by <n> seconds */ if (++c + 1 > argc) usage(argv[c-1]); Sleep(1000 * atoi(argv[c++])); break; case 'D': /* -D <eclipsedir> */ if (++c + 1 > argc) usage(argv[c-1]); eclipsedir = argv[c++]; break; case 'l': /* -l <size> */ argv[new_argc++] = argv[c]; /* shift */ if (++c + 1 > argc) usage(argv[c-1]); argv[new_argc++] = argv[c]; /* shift */ size = sizearg(argv[c++]); ec_set_option_long(EC_OPTION_LOCALSIZE, size); if (size < MIN_LOCAL) { fprintf(stderr,"Local stack size out of range\n"); exit(-1); } break; case 'h': /* -h <size> */ argv[new_argc++] = argv[c]; /* shift */ if (++c + 1 > argc) usage(argv[c-1]); argv[new_argc++] = argv[c]; /* shift */ size = sizearg(argv[c++]); ec_set_option_long(EC_OPTION_PRIVATESIZE, size); if (size < MIN_PRIVATE) { fprintf(stderr,"Private heap size out of range\n"); exit(-1); } break; case 's': /* -s <size> */ argv[new_argc++] = argv[c]; /* shift */ if (++c + 1 > argc) usage(argv[c-1]); argv[new_argc++] = argv[c]; /* shift */ size = sizearg(argv[c++]); ec_set_option_long(EC_OPTION_SHAREDSIZE, size); if (size < MIN_SHARED) { fprintf(stderr,"Shared heap size out of range\n"); exit(-1); } break; case 'o': /* enable oracles */ c += 1; /* vm_options = ORACLES_ENABLED; */ break; case '-': /* -- give the rest to Prolog */ for (; c < argc; ) argv[new_argc++] = argv[c++]; break; default: /* unknown: error */ usage(argv[c]); break; } } else if (!strcmp(argv[c], "-debug_level")) { if (++c + 1 > argc) usage(argv[c-1]); ec_set_option_int(EC_OPTION_DEBUG_LEVEL, atoi(argv[c++])); } else /* raise error unless preceeded by a -- option */ { usage(argv[c]); } } /*---------------------------------------------------------------- * Entry point after longjmp(reset) *----------------------------------------------------------------*/ switch (setjmp(reset)) { case 0: /* raw boot or -r from above */ break; case 3: /* restore program state */ case 2: init_flags = REINIT_SHARED|INIT_ENGINE|INIT_PRIVATE; break; case 4: /* restore execution state */ init_flags = REINIT_SHARED|INIT_PRIVATE; break; case 1: /* reset after fatal error */ default: init_flags = INIT_ENGINE; switch (memory_corrupted++) { case 0: break; case 1: /* try to print a message */ memory_corrupted = 2; fprintf(stderr,"\n*** SEPIA Fatal error: memory corrupted\n"); /* fall to */ case 2: /* we couldn't even print the message */ exit(-1); } break; } /* * set up our own panic function which longjumps back to reset */ ec_set_option_ptr(EC_OPTION_PANIC, main_panic); ec_set_option_int(EC_OPTION_INIT, init_flags); ec_set_option_int(EC_OPTION_ARGC, new_argc); ec_set_option_ptr(EC_OPTION_ARGV, argv); if (eclipsedir) ec_set_option_ptr(EC_OPTION_ECLIPSEDIR, eclipsedir); ec_init(); ec_post_goal(ec_term(ec_did(":",2), ec_atom(ec_did("sepia_kernel",0)), ec_atom(ec_did("standalone_toplevel",0)))); do { err = ec_resume(); } while (err == PYIELD); ec_cleanup(); return err; }