Exemple #1
0
BOOL cl_eval_file(char* file_name)
{
    sByteCode code;
    sConst constant;
    sVarTable gv_table;
    int max_stack;
    int gv_var_num;
    char compiled_file_name[PATH_MAX];

    /// make compiled file name ///
    xstrncpy(compiled_file_name, file_name, PATH_MAX-3);
    xstrncat(compiled_file_name, ".o", PATH_MAX);

    sByteCode_init(&code);
    sConst_init(&constant);

    if(!load_code(&code, &constant, &gv_var_num, &max_stack, compiled_file_name)) {
        fprintf(stderr, "load script file (%s) failure.\n", compiled_file_name);
        sByteCode_free(&code);
        sConst_free(&constant);
        return FALSE;
    }

    if(!cl_main(&code, &constant, gv_var_num, max_stack, CL_STACK_SIZE)) {
        sByteCode_free(&code);
        sConst_free(&constant);
        return FALSE;
    }

    sByteCode_free(&code);
    sConst_free(&constant);

    return TRUE;
}
Exemple #2
0
void load(char *input) {
	char *p = strtok(input, " ");
	p = strtok(NULL, " ");
	strcat(p, ".obj");
	printf("Loading %s into memory...", p);
	load_code(p);
}
Exemple #3
0
// -- 
int main(void) {
	/* 
	bool b = any_of('c', "abc");
	printf("%d\n", b);
	*/ 
	/*
	char *s1 = "adaeda ; a;k;j;";
	char *s2 = "abcde ;";
	int len = strspn(s1, s2);
	printf("%d\n", len);
	*/ 
	// printf("%d\n", isalpha('3'));
    code_t *code = load_code("./code.scm");
    // printf("%s", code->code);

    identifier_t *id = alloc_identifier();
    int iter = 0;
    extract_identifier(code, iter, id);
    dealloc_identifier(id);

    free_code(code);
    return 0;

	return 0;
}
Exemple #4
0
int main(void) {
    code_t *code = load_code("./code.scm");
    printf("%s", code->code);

    string_t *str = alloc_string();
    extract_string(code, 0, str);
    printf("%s", str->contents);
    dealloc_string(str);

    free_code(code);
    return 0;
}
Exemple #5
0
void
generate (const char *str)
{
  did_gen = TRUE;
  if (compile_only)
    {
      printf ("%s",str);
      out_count += strlen(str);
      if (out_count > 60)
	{
	  printf ("\n");
	  out_count = 0;
	}
    }
  else
    load_code (str);
}
Exemple #6
0
static int load_function(struct load_state *S, ktap_proto *f)
{
	f->linedefined = READ_INT(S);
 	f->lastlinedefined = READ_INT(S);
	f->numparams = READ_BYTE(S);
	f->is_vararg = READ_BYTE(S);
	f->maxstacksize = READ_BYTE(S);
	if (load_code(S, f))
		return -1;
	if (load_constants(S, f))
		return -1;
	if (load_upvalues(S, f))
		return -1;
	if (load_debuginfo(S, f))
		return -1;

	return 0;
}
 // Method code and related information.
 address code()                                 { if (_code == NULL) load_code(); return _code; }
Exemple #8
0
int main(int argc, char **argv)
{
	int datasize = 10;
	int debug = 0;
	int usestdin = 0;
	int o;
	extern int optind;

	while ((o = getopt(argc, argv, "ds")) != -1) {
		switch (o) {
		case 'd':
			debug = 1;
			break;
		case 's':
			usestdin = 1;
			break;
		default:
			usage(argv[0]);
			exit(EXIT_SUCCESS);
		}
	}

	if (optind >= argc) {
		usage(argv[0]);
		exit(EXIT_SUCCESS);
	}
	char *input = argv[optind];

	FILE *f;
	struct stat st;
	if ((f = fopen(input, "rb")) == NULL) {
		perror(argv[0]);
		exit(EXIT_FAILURE);
	}
	if (fstat(fileno(f), &st) < 0) {
		perror(argv[0]);
		exit(EXIT_FAILURE);
	}

	uint8_t *code;
	if ((code = malloc(st.st_size)) == NULL) {
		perror(argv[0]);
		exit(EXIT_FAILURE);
	}
	if ((fread(code, 1, st.st_size, f)) != st.st_size) {
		fprintf(stderr, "%s: error reading input file\n", argv[0]);
		exit(EXIT_FAILURE);
	}
	fclose(f);

	struct cpu *cpu = new_cpu(datasize);
	if (cpu == NULL) {
		fprintf(stderr, "error: can't create CPU\n");
		exit(EXIT_FAILURE);
	}

	cpu->debug = debug;
	cpu->exception = exception;
	if (usestdin) {
		cpu->inbox = stdinbox;
	} else {
		cpu->inbox = inbox;
	}
	cpu->outbox = outbox;

	if (load_code(cpu, code, st.st_size) < 0) {
		fprintf(stderr, "error: can't load code\n");
		exit(EXIT_FAILURE);
	}
	free(code);

	cpu->data[9] = 0;

	run_cpu(cpu);

	printf("Executed %d instructions\n", cpu->clock);
	
	exit(EXIT_SUCCESS);
}
int main(int argc, char* argv[])
{
    printf("\n\n\n\n----- Phantom exec test v. 0.5\n\n");


    run_init_functions( INIT_LEVEL_PREPARE );
    run_init_functions( INIT_LEVEL_INIT ); // before video

    //drv_video_win32.mouse = mouse_callback;
    //video_drv = &drv_video_win32;
    //video_drv = &drv_video_x11;

    args(argc,argv);

    pvm_bulk_init( bulk_seek_f, bulk_read_f );

    pvm_video_init();
    video_drv->mouse = mouse_callback;

    drv_video_init_windows();
    init_main_event_q();
    init_new_windows();

    scr_mouse_set_cursor(drv_video_get_default_mouse_bmp());


    mem = malloc(size+1024*10);
    setDiffMem( mem, malloc(size+1024*10), size );

    hal_init( mem, size );
    //pvm_alloc_threaded_init(); // no threads yet - no lock

    run_init_functions( INIT_LEVEL_LATE );

#if 0
    videotest();
    //getchar();
    exit(0);
#endif

#if 0
    new_videotest();
    getchar();
    exit(0);
#endif


    char *dir = getenv("PHANTOM_HOME");
    char *rest = "plib/bin/classes";

    if( dir == NULL )
    {
        dir = "pcode";
        rest = "classes";
    }

    char fn[1024];
    snprintf( fn, 1024, "%s/%s", dir, rest );

    if( load_code( &bulk_code, &bulk_size, fn ) ) //"pcode/classes") )
    {
        printf("No bulk classes file '%s'\n", fn );
        exit(22);
    }
    bulk_read_pos = bulk_code;


    pvm_root_init();


    // TODO use stray catcher in pvm_test too
    //stray();

#if 0
//ui_loop( argc, argv, "test");
    printf("\nPhantom code finished\n" );
    //getchar();
    //{ char c; read( 0, &c, 1 ); }
	sleep(100);
#else
    dbg_init();
    kernel_debugger();
#endif

#if 0
    pvm_memcheck();

    printf("will run GC\n" );
    run_gc();

    printf("press enter\n" );
//    getchar();

    pvm_memcheck();

    save_mem(mem, size);
#endif
    return 0;
}