예제 #1
0
int main(int argc, char** argv) {
  if(argc != 3) {
    printf("Usage: vitamin <bytecode-file> <procedure>\n");
    return -1;
  }

  vm_world* w = vm_make_world();

  vm_load_bytecode(w, argv[1]);
  vm_relink_world(w);
  vm_obj result = vm_interpret_procedure(w, argv[2], 0, 0);
  printf("result: ");
  vm_display_object(result);
  printf("\n");

  vm_unmake_world(w);

  return 0;
}
예제 #2
0
파일: ngs.c 프로젝트: Wingie/ngs
		fprintf(stderr, "NGS: Failed to parse at position %d (%s), rule %s. Exiting.\n", yyctx.fail_pos, sprintf_position(&yyctx, yyctx.fail_pos), yyctx.fail_rule);
		exit(2);
	}

	tree = yyctx.__;
	IF_DEBUG(COMPILER, print_ast(tree, 0);)

	yyrelease(&yyctx);

	// TODO: use native_... methods to load and run the code
	bytecode = compile(tree, source_file_name, &len);
	// BROKEN SINCE BYTECODE FORMAT CHANGE // IF_DEBUG(COMPILER, decompile(bytecode, 0, len);)
	vm_init(&vm, argc, argv);
	set_global(&vm, "BOOTSTRAP_FILE", make_string(bootstrap_file_name));
	ctx_init(&ctx);
	ip = vm_load_bytecode(&vm, bytecode);
	closure = make_closure_obj(ip, 0, 0, 0, 0, 0, NULL);
	mr = vm_call(&vm, &ctx, &result, closure, 0, NULL);
	if(mr == METHOD_OK) {
		return 0;
	}
	if(mr == METHOD_EXCEPTION) {
		if(obj_is_of_type(result, vm.Exception)) {
			printf("========= Uncaught exception of type '%s' =========\n", obj_to_cstring(NGS_TYPE_NAME(NORMAL_TYPE_INSTANCE_TYPE(result))));
			print_exception(&vm, result);
		} else {
			dump_titled("Uncaught exception", result);
		}
		return 1;
	}
	assert(0 == "Unexpected exit from bootstrap code");