Beispiel #1
0
int main(int argc, char** argv)
{
  try {
    if ( argc == 1 ) // by default, read standard input
      compile_and_run(stdin);
  
    for ( int n=1; n<argc; ++n )
      if ( argv[n][0]=='-' ) {
        if ( argv[n][1] == '\0' )
          compile_and_run(stdin);
        else
          help();
      } else
        compile_and_run(fileptr(fopen(argv[n], "rt")));

    return 0;
  }
  catch(const std::exception& e) {
    error(e.what());
  }
}
Beispiel #2
0
static void mload(const char *fname)
{
  FILE *f;

  context.display_error = TRUE;
  context._mudout = context._muderr = mstdout;
  context.call_count = MAX_CALLS;

  if (!(f = fopen(fname, "r")))
    {
      fprintf(stderr, "couldn't find %s\n", fname);
      exit(2);
    }
  push_frame(mload_action, sizeof(struct generic_frame));
  read_from_file(f);
  compile_and_run(NULL, globals, fname, NULL, FALSE);
}
Beispiel #3
0
void
run_gccode(void)
{
    FILE * ofd;
#if _POSIX_VERSION >= 200809L
    if( mkdtemp(tmpdir) == 0 ) {
	perror("mkdtemp()");
	exit(1);
    }
#else
#warning mkdtemp not used _POSIX_VERSION is too low, using mktemp instead
    if (mkdir(mktemp(tmpdir), 0700) < 0) {
	perror("mkdir(mktemp()");
	exit(1);
    }
#endif
    strcpy(ccode_name, tmpdir); strcat(ccode_name, "/"BFBASE".c");
    strcpy(dl_name, tmpdir); strcat(dl_name, "/"BFBASE".so");
    strcpy(obj_name, tmpdir); strcat(obj_name, "/"BFBASE".o");
    ofd = fopen(ccode_name, "w");
    print_ccode(ofd);
    fclose(ofd);
    compile_and_run();
}
int main(){
    printf("I am about to run a function. But first, you have to write it for me.\n"
        "Enter the function body. Conclude with a '}' alone on a line.\n\n");
    get_a_function();
    compile_and_run();
}
Beispiel #5
0
static void repl_action(frameact action, u8 **ffp, u8 **fsp)
{
  struct repl_frame *frame = (struct repl_frame *)*ffp;

  switch (action)
    {
    case fa_unwind:
      throw_handled();
      frame->state = read_line;
      return;
    case fa_execute:
      switch (frame->state)
	{
	case read_line:
#ifdef USE_READLINE
	  if (frame->line)
	    free(frame->line);

	  frame->line = readline((char *)"motlle> ");

	  if (!frame->line)
	    exit(0);

	  if (*frame->line)
	    add_history(frame->line);
#else
	  {
	    char _line[512];

	    frame->line = _line;
	    fputs("mudlle> ", stdout);
	    if (!fgets(_line, sizeof _line, stdin))
	      exit(0);
	  }
#endif
	  read_from_string(frame->line);
	  frame->state = print_result;
	  context.display_error = TRUE;
	  context._mudout = context._muderr = mstdout;
	  context.call_count = MAX_CALLS;
	  compile_and_run(NULL, globals, "<interactive>", NULL, FALSE);
	  break;
	case print_result:
	  {
	    value result = stack_pop();

	    printf("Result: ");
	    mprint(mstdout, prt_print, result);
	    printf("\n");
	    frame->state = read_line;
	    break;
	  }
	default:
	  abort();
	}
      break;
    case fa_print:
      mputs("<repl>" EOL, muderr);
      break;
    case fa_gcforward:
      /* fall through */
    case fa_pop:
      pop_frame(ffp, fsp, sizeof(struct repl_frame));
      break;
    default: abort();
    }
}