Beispiel #1
0
value start_interp(value may_free, value prog, value offset, value vlen) /* ML */
{
  bytecode_t bprog = (bytecode_t)&Byte(prog, Long_val(offset)); // In ML heap
  int len = Long_val(vlen);
  value res;

#if defined(MOSML_BIG_ENDIAN) && !defined(ALIGNMENT)
  fixup_endianness(&Byte(prog, 0), (asize_t) len);
#endif

#if defined(DIRECT_JUMP) && defined(THREADED)
  {
    realcode_t generated_code;    
    res = interprete(/* mode=byte exec */ 1, bprog, len, &generated_code);
    if (Bool_val(may_free)) {
      //      printf("start_interp freeing: generated_code=%d, len=%d\n", 
      //     (int)*generated_code, len); 
      free(generated_code);	// Allocated by the call to interprete()
    }
  }
#else
  {
    // Copy bytecode to memory outside the ML heap
    bytecode_t actualprog = (bytecode_t)malloc(len);
    bcopy(bprog, actualprog, len);
    res = interprete(/* mode=byte exec */ 1, actualprog, len, NULL);
    if (Bool_val(may_free)) 
      free(actualprog);		// Allocated above
  }
#endif

  return res;
}
Beispiel #2
0
int main(int argc, char* argv[]) {
    struct Stack stack;
    struct Program program;
    int exit_code = 1, file_nr, size;
    FILE * code_file;
    
    stack_new(&stack, 100);
    debug(" * created stack of 100");
    
    if (argc > 1) {
        for (file_nr = 1; file_nr < argc; file_nr++) {
#ifdef DEBUG
            printf(" * open file '%s'\n", argv[file_nr]);
#endif
            code_file = fopen(argv[file_nr], "r");
            debug(" * start programm");
            size = program_size(code_file);
            fseek(code_file, 0, SEEK_SET);
            program_new(&program, size);
            debug(" * created programm, start reading...");
            read_program(code_file, &program);
            exit_code = interprete(&stack, &program);
            fclose(code_file);
        }
    } else {
        debug(" ! no programm specified, vm will end");
        printf("usage: %s {simple-language.slc}\n", argv[0]);
    }
    
    return exit_code;
}
Beispiel #3
0
void MainWindow::onEqual()
{
    interprete(NONE);
    if (ui->lineEdit_2->displayText().contains("."))
        disableComa();
    else
        allowComa();
}
Beispiel #4
0
char *comando(char *cmd, char **argv, char* output,int rs[2], FD *ph,FD *hp){
    int argc=0;
    interprete(cmd, &argc, argv);
    strcpy(output, "");
    
    if (argc > 0) {
        if(!strcmp(argv[0], "ls")) {
            ls(argc, argv,output);
        }
        else if(!strcmp(argv[0], "cat")) {
            char *c = cat(argc, argv);
            if(c == NULL) {
                sprintf(output,"-fssh: %s/%s: No existe el archivo\n",
                        argv[1],argv[2]);
            }
            else {
                strcpy(output,c);
                return c;
            }
        }
        else if(!strcmp(argv[0], "cp")) {
            cp(argc, argv,output);
        }
        else if(!strcmp(argv[0], "mv")) {
            mv(argc, argv, output);
        }
        else if(!strcmp(argv[0], "find")) {
            find(argc,argv,output,rs,ph,hp);
        }
        else if(!strcmp(argv[0], "rm")) {
            rm(argc, argv,output);
        }
        else if(!strcmp(argv[0], "mkdir")) {
           output = mkdir_(argc, argv,output);
        }
        else if(!strcmp(argv[0], "rmdir")) {
            rmdir_(argc, argv,output);
        }
        else if(!strcmp(argv[0], "quit")) {
            exit(0);
        }
        else {
            sprintf(output,"-fssh: %s: No existe el comando\n",argv[0]);
        }
    }
    else {
        sprintf(output, "-fssh: %s: Es un directorio\n",argv[1]);
    }

    
    return output;
}
Beispiel #5
0
/*!
 * THE MAIN FUNCTION
 */
int main ( int const argc , char const * const argv [] ) {
  char* buff1 = "-h";
  bool trace = false;
  char* buff2 = "-t";
  FILE * input;
  for(int x = 1; x < argc; x++){
    if(strcmp(argv[x], buff1) == 0){
      help_message ( argv [ 0 ] ) ;
    }else{
      if(strcmp(argv[x], buff2) == 0){
	trace = true;
      }else{
	input = fopen(argv[x], "r");
      }
    }
  }
 interprete(input, trace);
 fclose(input);
 return 0;
}
Beispiel #6
0
int main(int argc, char * argv[])
{
  int fd;
  struct exec_trailer trail;
  int i, r;
  struct longjmp_buffer raise_buf;
  struct channel * chan;
  int verbose_init = 0, percent_free_init = Percent_free_def;
  long minor_heap_init = Minor_heap_def, heap_chunk_init = Heap_chunk_def;
#ifdef DEBUG
  char * debugger_address = NULL;


  verbose_init = 1;
#endif

  i = 0;
  fd = attempt_open(&argv[0], &trail, 0);

  if (fd < 0) {

    for(i = 1; i < argc && argv[i][0] == '-'; i++) {
      switch(argv[i][1]) {
#ifdef DEBUG
      case 't': {
        extern int trace_flag;
        trace_flag = 1;
        break;
      }
#endif
      case 'v':
        verbose_init = 1;
        break;
      case 'V':
        fprintf(stderr, "The Caml Light runtime system for Ex-SML, version %s\n",
                VERSION);
	fprintf(stderr, "  git commit %s\n", GIT_HEAD);
	sys_exit(INT_TO_VAL(0));
      default:
        fatal_error_arg("Unknown option %s.\n", argv[i]);
      }
    }

    if (argv[i] == 0)
      fatal_error("No bytecode file specified.\n");

    fd = attempt_open(&argv[i], &trail, 1);

    switch(fd) {
    case FILE_NOT_FOUND:
	    fatal_error_arg("Fatal error: cannot find file %s\n", argv[i]);
	    break;
    case TRUNCATED_FILE:
    case BAD_MAGIC_NUM:
	    fatal_error_arg(
		    "Fatal error: the file %s is not a bytecode executable file\n",
		    argv[i]);
	    break;
    default: /* By default, accept */
	    break;
    }
  }

  /* Runtime options.  The option letter is the first letter of the
     last word of the ML name of the option (see [lib/gc.mli]). */

  { char *opt = getenv ("CAMLRUNPARAM");
    if (opt != NULL){
      while (*opt != '\0'){
	switch (*opt++){
	case 's': sscanf (opt, "=%ld", &minor_heap_init); break;
	case 'i': sscanf (opt, "=%ld", &heap_chunk_init); break;
	case 'o': sscanf (opt, "=%d", &percent_free_init); break;
	case 'v': sscanf (opt, "=%d", &verbose_init); break;
	default:
		perror("Unknown CAMLRUNPARAM Option");
		break;
	}
      }
    }
  }

#ifdef DEBUG
  if (debugger_address == NULL)
    debugger_address = getenv("CAML_DEBUG_SOCKET");
#endif

  if (setjmp(raise_buf.buf) == 0) {

    external_raise = &raise_buf;

    init_gc (minor_heap_init, heap_chunk_init, percent_free_init,
	     verbose_init);
    init_stack();
    init_atoms();

    lseek(fd, - (long) (TRAILER_SIZE + trail.code_size + trail.data_size
                        + trail.symbol_size + trail.debug_size), 2);

    code_size = trail.code_size;

    start_code = (bytecode_t) stat_alloc(code_size);
    r = read(fd, (char *) start_code, code_size);
    if (r == -1) {
	    fatal(NULL);
    } else if ((unsigned) r != code_size) {
	    fatal_error("Fatal error: truncated bytecode file.\n");
    }

#if defined(WORDS_BIGENDIAN) && !defined(HAVE_ALIGNED_ACCESS_REQUIRED)
    fixup_endianness(start_code, code_size);
#endif

    chan = open_descr(fd);
    global_data = intern_val(chan);
    modify(&Field(global_data, GLOBAL_DATA), global_data);
    close_in(chan);

    sys_init(argv + i);
    interprete(/* mode=init */ 0, NULL, NULL);
    interprete(/* mode=byte exec */ 1, start_code, NULL);
    sys_exit(INT_TO_VAL(0));

  } else {
    if (Field(exn_bucket, 0) == Field(global_data, SYS__EXN_MEMORY))
      fatal_error ("Fatal error: out of memory.\n");
    else {
      char* buf = (char*)malloc(201);
      char* exnmsg = exnmessage_aux(exn_bucket);
      snprintf(buf, 200, "Uncaught exception:\n%s\n", exnmsg);
      free(exnmsg);
      fatal_error(buf);
    }
  }
  return 0;			/* Can't get here */
}
Beispiel #7
0
int main(int argc, char * argv[])
#endif
{
  int fd;
  struct exec_trailer trail;
  int i;
  struct longjmp_buffer raise_buf;
  struct channel * chan;
  int verbose_init = 0, percent_free_init = Percent_free_def;
  long minor_heap_init = Minor_heap_def, heap_chunk_init = Heap_chunk_def;
  char * debugger_address = NULL;
#ifdef MSDOS
  extern char ** check_args();
  argv = check_args(argv);
#endif

#ifdef DEBUG
  verbose_init = 1;
#endif

#ifdef WIN32
  BOOL fOk;
  fOk = SetConsoleCtrlHandler(NULL, FALSE);
#endif

  i = 0;
  fd = attempt_open(&argv[0], &trail, 0);

  if (fd < 0) {

    for(i = 1; i < argc && argv[i][0] == '-'; i++) {
      switch(argv[i][1]) {
#ifdef DEBUG
      case 't': {
        extern int trace_flag;
        trace_flag = 1;
        break;
      }
#endif
      case 'v':
        verbose_init = 1;
        break;
      case 'V':
        fprintf(stderr, "The Caml Light runtime system, version %s\n",
                VERSION);
	sys_exit(Val_int(0));
      default:
        fatal_error_arg("Unknown option %s.\n", argv[i]);
      }
    }

    if (argv[i] == 0)
      fatal_error("No bytecode file specified.\n");

    fd = attempt_open(&argv[i], &trail, 1);

    switch(fd) {
    case FILE_NOT_FOUND:
      fatal_error_arg("Fatal error: cannot find file %s\n", argv[i]);
      break;
    case TRUNCATED_FILE:
    case BAD_MAGIC_NUM:
      fatal_error_arg(
        "Fatal error: the file %s is not a bytecode executable file\n",
        argv[i]);
      break;
    }
  }

  /* Runtime options.  The option letter is the first letter of the
     last word of the ML name of the option (see [lib/gc.mli]). */

  { char *opt = getenv ("CAMLRUNPARAM");
    if (opt != NULL){
      while (*opt != '\0'){
	switch (*opt++){
	case 's': sscanf (opt, "=%ld", &minor_heap_init); break;
	case 'i': sscanf (opt, "=%ld", &heap_chunk_init); break;
	case 'o': sscanf (opt, "=%d", &percent_free_init); break;
	case 'v': sscanf (opt, "=%d", &verbose_init); break;
	}
      }
    }
  }

#ifdef HAS_SOCKETS
  if (debugger_address == NULL)
    debugger_address = getenv("CAML_DEBUG_SOCKET");
#endif

  if (setjmp(raise_buf.buf) == 0) {

    external_raise = &raise_buf;

    init_gc (minor_heap_init, heap_chunk_init, percent_free_init,
	     verbose_init);
    init_stack();
    init_atoms();

    lseek(fd, - (long) (TRAILER_SIZE + trail.code_size + trail.data_size
                        + trail.symbol_size + trail.debug_size), 2);

    code_size = trail.code_size;

#if defined(DIRECT_JUMP) && defined(THREADED)
    start_code = (bytecode_t) alloc_string(code_size);
#else
    start_code = (bytecode_t) stat_alloc(code_size);
#endif
    if (read(fd, (char *) start_code, code_size) != code_size)
      fatal_error("Fatal error: truncated bytecode file.\n");

#if defined(MOSML_BIG_ENDIAN) && !defined(ALIGNMENT)
    fixup_endianness(start_code, code_size);
#endif

    chan = open_descr(fd);
    global_data = intern_val(chan);
    modify(&Field(global_data, GLOBAL_DATA), global_data);
    close_in(chan);

    sys_init(argv + i);
    interprete(/* mode=init */ 0, NULL, 0, NULL); 
    interprete(/* mode=byte exec */ 1, start_code, code_size, NULL);
    sys_exit(Val_int(0));

  } else {
    if (Field(exn_bucket, 0) == Field(global_data, SYS__EXN_MEMORY))
      fatal_error ("Fatal error: out of memory.\n");
    else {
      char* buf = (char*)malloc(201);
      char* exnmsg = exnmessage_aux(exn_bucket);
#if defined(__CYGWIN__) || defined(hpux)
      sprintf(buf, "Uncaught exception:\n%s\n", exnmsg);
#elif defined(WIN32)
      _snprintf(buf, 200, "Uncaught exception:\n%s\n", exnmsg);
#else
      snprintf(buf, 200, "Uncaught exception:\n%s\n", exnmsg);
#endif
      free(exnmsg);
      fatal_error(buf);
    }
  }
  return 0;			/* Can't get here */
}
Beispiel #8
0
void MainWindow::onMultiplicate()
{
    interprete(TIME);
    allowComa();
}
Beispiel #9
0
void MainWindow::onMinus()
{
    interprete(MINUS);
    allowComa();
}
Beispiel #10
0
void MainWindow::onPlus()
{
    interprete(PLUS);
    allowComa();
}
Beispiel #11
0
void MainWindow::onDivided()
{
    interprete(DIVIDED);
    allowComa();
}