Ejemplo n.º 1
0
int main(void) {
  scheme *sc;
  
  // Init Scheme interpreter
  sc = scheme_init_new();
  scheme_set_output_port_file(sc, stdout);
  
  // Load init.scm
  FILE *finit = fopen("../tinyscheme/init.scm", "r");
  scheme_load_file(sc, finit);
  fclose(finit);

  SDECL("machine-create",sc_machine_create);
  SDECL("machine-peek",sc_machine_peek);
  SDECL("machine-poke",sc_machine_poke);
  SDECL("machine-run",sc_machine_run);
  SDECL("machine-say",sc_machine_say);
  SDECL("machine-start",sc_machine_start);
  SDECL("machine-say-addr",sc_machine_say_addr);
  SDECL("machine-say-size",sc_machine_say_size);

  FILE *fus = fopen("reactor.scm", "r");
  scheme_load_file(sc, fus);
  fclose(fus);
  
  // Bye!
  scheme_deinit(sc);
  return 0;
}
Ejemplo n.º 2
0
int main(int argc, char *argv[])
{
  void *sc;

  sc = malloc(1024 * 1024 * 4);

  void *h = dlopen("/usr/lib/libsandbox.dylib", RTLD_LAZY);
  printf("h = %p\n", h);
  void *loaded_base = dlsym(h, "sandbox_compile_file");
  printf("sandbox_compile_file = %p\n", loaded_base);

  unsigned int static_base = get_offset("_sandbox_compile_file");
  base = (unsigned int) loaded_base - static_base;

  int (*scheme_init)(void *) = 
      (int (*)(void *)) hidden_dlsym("_scheme_init");
  void (*scheme_set_input_port_file)(void *, FILE *) = 
      (void (*)(void *, FILE *)) hidden_dlsym("_scheme_set_input_port_file");
  void (*scheme_set_output_port_file)(void *, FILE *) =
      (void (*)(void *, FILE *)) hidden_dlsym("_scheme_set_output_port_file");
  void (*scheme_load_file)(void *, FILE *) = 
      (void (*)(void *, FILE *)) hidden_dlsym("_scheme_load_file");
  void (*scheme_deinit)(void *) = 
      (void (*)(void *)) hidden_dlsym("_scheme_deinit");

  if (!scheme_init(sc)) {
    fprintf(stderr, "Uh ohz!\n");
  } else {
    scheme_set_input_port_file(sc, stdin);
    scheme_set_output_port_file(sc, stdout);

    scheme_load_file(sc, stdin);

    scheme_deinit(sc);
  }

  dlclose(h);
  free(sc);
  return 0;
}
Ejemplo n.º 3
0
int main(int argc, char **argv) {
	FILE       *fin  = NULL;
	const char *expr = NULL;
	scheme      sc;

	if(argc > 1) { 
		if(argv[1][0] == '-') {
			if((strcmp(argv[1], "--help") == 0) || (strcmp(argv[1], "-h") == 0)) {
				help();
				return 0;
			} else if((strcmp(argv[1], "--expression") == 0) || (strcmp(argv[1], "-e") == 0)) {
				if(!argv[2]) {
					printf("This option requires a parameter\n");
					return 1;
				}
				expr = argv[2];
			} else {
				printf("Unrecognized option. Use 'ede-scriptbus --help' for options\n");
				return 1;
			}
		}

		if(!expr) {
			fin = fopen(argv[1], "r");
			if(!fin) {
				fprintf(stderr, "Unable to load '%s' file!\n", argv[1]);
				return 1;
			}
		}
	}

	if(!scheme_init(&sc)) {
		fprintf(stderr, "Fatal: Unable to initialize interpreter!\n");
		return 1;
	}

	scheme_set_input_port_file(&sc, stdin);
	scheme_set_output_port_file(&sc, stdout);

	/* load basic stuff */
	scheme_load_string(&sc, init_scm_content);

	/* register additional functions */
	register_sys_functions(&sc);
	register_communication_functions(&sc);
	register_string_functions(&sc);
	register_wm_functions(&sc);

	/* construct *args* */
	pointer args = sc.NIL;
	for(int i = 0; i < argc; i++) {
		pointer value = mk_string(&sc, argv[i]);
		args = cons(&sc, value, args);
	}

	args = scheme_reverse(&sc, args);
	scheme_define(&sc, sc.global_env, mk_symbol(&sc, "*args*"), args);

	if(!expr) {
		/* load file or go into console */
		if(!fin) {
			fin = stdin;
			printf("Type '(quit)' or press Ctrl-D to quit");
		}

		scheme_load_file(&sc, fin);
	} else {
		/* or execute expression */
		scheme_load_string(&sc, expr);
		if(sc.retcode != 0)
			printf("Bad expression: '%s'\n", expr);
	}

	scheme_deinit(&sc);
	return 0;
}