int main(int argc, char **argv) { char *platformFile = NULL; unsigned int totalHosts, totalLinks; int timings=0; int version = 4; const char *link_ctn = "link_ctn"; unsigned int i; xbt_dict_t props = NULL; xbt_dict_cursor_t cursor = NULL; xbt_lib_cursor_t cursor_src = NULL; xbt_lib_cursor_t cursor_dst = NULL; char *src,*dst,*key,*data; sg_netcard_t value1; sg_netcard_t value2; const sg_host_t *hosts; const SD_link_t *links; xbt_os_timer_t parse_time = xbt_os_timer_new(); SD_init(&argc, argv); if (parse_cmdline(&timings, &platformFile, argc, argv) || !platformFile) { xbt_die("Invalid command line arguments: expected [--timings] platformFile"); } XBT_DEBUG("%d,%s", timings, platformFile); create_environment(parse_time, platformFile); if (timings) { XBT_INFO("Parsing time: %fs (%zu hosts, %d links)", xbt_os_timer_elapsed(parse_time), sg_host_count(), sg_link_count()); } else { printf("<?xml version='1.0'?>\n"); printf("<!DOCTYPE platform SYSTEM \"http://simgrid.gforge.inria.fr/simgrid/simgrid.dtd\">\n"); printf("<platform version=\"%d\">\n", version); printf("<AS id=\"AS0\" routing=\"Full\">\n"); // Hosts totalHosts = sg_host_count(); hosts = sg_host_list(); qsort((void *) hosts, totalHosts, sizeof(sg_host_t), name_compare_hosts); for (i = 0; i < totalHosts; i++) { printf(" <host id=\"%s\" speed=\"%.0f\"", sg_host_get_name(hosts[i]), sg_host_speed(hosts[i])); props = sg_host_get_properties(hosts[i]); if (sg_host_core_count(hosts[i])>1) { printf(" core=\"%d\"", sg_host_core_count(hosts[i])); } if (props && !xbt_dict_is_empty(props)) { printf(">\n"); xbt_dict_foreach(props, cursor, key, data) { printf(" <prop id=\"%s\" value=\"%s\"/>\n", key, data); } printf(" </host>\n"); } else {
void GarnetObject::do_init() { create_environment(); allocateBuiltInClasses(); }
/* Start the TAC generator process at the top of the AST */ tac_quad *start_tac_gen(NODE *tree) { /* Do a scan for function definitions first */ environment *initial_env; initial_env = create_environment(NULL); null_fn = build_null_function(); make_simple(initial_env, tree, INTERPRET_FN_SCAN, INT); /* Actually generate the TAC */ make_simple(initial_env, tree, 0, 0); return tac_output; }
int main (int argc, char *argv[]) { int write_character = -1; g_prog_mode = PRG_SENDER_MODE; /*check parameters */ if ((buffer_size = get_buffer_size(argc, argv)) == RETURN_ERROR) { return EXIT_FAILURE; } /*create semaphore and ringbuffer*/ if (create_environment() == RETURN_ERROR) { return EXIT_FAILURE; } /*write ringbuffer*/ do { /*read stdin input*/ write_character = fgetc(stdin); /*decrement semaphore*/ if (my_sem_wait() == RETURN_ERROR) { return EXIT_FAILURE; } /*write ringbuffer*/ write_char_to_buffer(write_character); /*increment semaphore*/ if (my_sem_post() == RETURN_ERROR) { return EXIT_FAILURE; } } while (write_character != EOF); /*check for errors in input of stdin*/ if (ferror(stdin)) { fprintf(stderr, "%s: %s%s\n", g_program_name, "Error while reading input from \"stdin\".", strerror(errno)); destroy_environment(PRG_ERROR); return EXIT_FAILURE; } /*destroy semaphore and ringbuffer*/ if (destroy_environment(PRG_SUCCESS) == RETURN_ERROR) { return EXIT_FAILURE; } else { return EXIT_SUCCESS; } }
int main() { char value[10] = "test\n"; int status = AXIS2_SUCCESS; axutil_env_t *env = NULL; env = create_environment(); status = test_stack(env,value); if(status != AXIS2_SUCCESS) { printf("The test failed"); } axutil_env_free(env); return 0; }
int main() { int status = AXIS2_SUCCESS; axutil_env_t *env = NULL; env = create_environment(); status = test_uri(env); if(status == AXIS2_FAILURE) { printf("The Test failed"); } axutil_env_free(env); return 0; }
int main() { axutil_env_t *env = NULL; int status = AXIS2_SUCCESS; env = create_environment(); status = test_date_time(env); if(status != AXIS2_SUCCESS) { printf("axutil_date_time_t test failed"); } else { printf("axutil_date_time_t test successful"); } axutil_env_free(env); return 0; }
void run_test_in_its_own_process(TestSuite *suite, CgreenTest *test, TestReporter *reporter) { #define COMMAND_LINE_LENGTH (2*MAX_PATH) BOOL success; char fname[MAX_PATH+1]; //make enough room for full path plus null terminator struct environment* p_environment = create_environment(); char handleString[256]; STARTUPINFOA siStartupInfo; PROCESS_INFORMATION piProcessInfo; //get executable path GetModuleFileNameA(NULL, fname,MAX_PATH); //launch process memset(&siStartupInfo, 0, sizeof(siStartupInfo)); memset(&piProcessInfo, 0, sizeof(piProcessInfo)); siStartupInfo.cb = sizeof(siStartupInfo); sprintf_s(handleString,sizeof(handleString), "%i", get_pipe_read_handle()); AddEnvironmentVariable(p_environment, CGREEN_READ_HANDLE, handleString); sprintf_s(handleString,sizeof(handleString), "%i", get_pipe_write_handle()); AddEnvironmentVariable(p_environment, CGREEN_WRITE_HANDLE, handleString); //put name of test to run in environment AddEnvironmentVariable(p_environment, CGREEN_TEST_TO_RUN, test->name); (*reporter->start_test)(reporter, test->name); //success = CreateProcessA(fname, NULL, NULL, NULL, true, NORMAL_PRIORITY_CLASS | CREATE_NO_WINDOW , p_environment, NULL, &siStartupInfo, &piProcessInfo); success = CreateProcessA(fname, NULL, NULL, NULL, true, NORMAL_PRIORITY_CLASS , p_environment, NULL, &siStartupInfo, &piProcessInfo); dispose_environment(p_environment); WaitForSingleObject(piProcessInfo.hProcess,INFINITE); (*reporter->finish_test)(reporter, test->filename, test->line, NULL); return; }
static int __cdecl common_initialize_environment_nolock() throw() { typedef __crt_char_traits<Character> traits; // We only initialize the environment once. Once the environment has been // initialized, all updates and modifications go through the other functions // that manipulate the environment. if (get_environment_nolock(Character())) return 0; pre_initialize(Character()); __crt_unique_heap_ptr<Character> const os_environment(traits::get_environment_from_os()); if (!os_environment) return -1; __crt_unique_heap_ptr<Character*> crt_environment(create_environment(os_environment.get())); if (!crt_environment) return -1; get_initial_environment(Character()) = crt_environment.get(); get_dual_state_environment_nolock(Character()).initialize(crt_environment.detach()); return 0; }
int main(int argc, const char * argv[]) { try { if(argc < 2) { printf("Please provide a .tora file to parse!\n"); exit(1); } if(!tora_init()) { TORA_RUNTIME_EXCEPTION("Failed to initialise parser!"); } // Create an input stream to begin parsing our document TORAInputStream *input_stream = input_stream_from_file_contents(argv[1]); if(!input_stream) { TORA_RUNTIME_EXCEPTION("Failed to parse input stream!"); } // Create a token stream from our TORAInputStream TORATokenStream *token_stream = token_stream_from_input(input_stream); if(!token_stream) { free_input_stream(input_stream); TORA_RUNTIME_EXCEPTION("Failed to malloc input stream!"); } // Parse the top level of our program and generate an AST TORAParserProgExpression *prog = parse_top_level(token_stream); if(!prog) { free_token_stream(token_stream); free_input_stream(input_stream); TORA_RUNTIME_EXCEPTION("Failed to generate expression tree!"); } // Create a base environment for use when evaluating the AST TORAEnvironment *environment = create_environment(NULL); if(!environment) { free_expression(prog); free_token_stream(token_stream); free_input_stream(input_stream); TORA_RUNTIME_EXCEPTION("Failed to malloc root environment!"); } // Evaluate the program! bool return_encountered = false; evaluate(prog, environment, &return_encountered); // Cleanup free_expression(prog); drain_queue(environment_queue); drain_queue(interpretter_queue); free_token_stream(token_stream); free_input_stream(input_stream); if(num_malloc != num_free) { printf("Num malloc'd blocks: %i, num freed: %i, lost: %i\n", num_malloc, num_free, num_malloc-num_free); printf("Num un-freed tokens: %i\n", num_tok); } // Teardown tora_shutdown(); } catch(ParserException) { printf("Parser Exception: \"%s\"\n\tfile: %s\n\tline: %d\n", e4c.err.message, e4c.err.file, e4c.err.line); } catch(InterpretterException) { printf("Interpretter Exception: \"%s\"\n\tfile: %s\n\tline: %d\n", e4c.err.message, e4c.err.file, e4c.err.line); } catch(RuntimeException) { printf("Runtime Exception: \"%s\"\n\tfile: %s\n\tline: %d\n", e4c.err.message, e4c.err.file, e4c.err.line); } return 0; }
/* * Make the given NODE simple - i.e. return a temporary for complex subtrees * The appropriate code is also generated and pushed onto the code stack */ value *make_simple(environment *env, NODE *node, int flag, int return_type) { int i_value = 0; char *s_tmp = NULL; value *val1 = NULL, *val2 = NULL, *temporary = NULL, *temp = NULL; static int if_count = 0; static int while_count = 0; tac_quad *temp_quad = NULL; environment *new_env = NULL; if (node==NULL) return NULL; switch(type_of(node)) { case LEAF: return make_simple(env, node->left, flag, return_type); case CONSTANT: i_value = cast_from_node(node)->value; s_tmp = malloc(sizeof(char) * 25); sprintf(s_tmp, "%d", i_value); return int_value(i_value); case IDENTIFIER: return string_value(cast_from_node(node)->lexeme); case IF: build_if_stmt(env, node, ++if_count, NULL, NULL, flag, return_type); return NULL; case BREAK: s_tmp = malloc(sizeof(char) * 25); sprintf(s_tmp, "__while%dend", while_count); append_code(make_goto(s_tmp)); return NULL; case CONTINUE: s_tmp = malloc(sizeof(char) * 25); sprintf(s_tmp, "__while%d", while_count); append_code(make_goto(s_tmp)); return NULL; case WHILE: build_while_stmt(env, node, ++while_count, ++if_count, flag, return_type); return NULL; case '=': if (flag == INTERPRET_FN_SCAN) return NULL; val1 = make_simple(env, node->left, flag, return_type); val2 = make_simple(env, node->right, flag, return_type); if (val2 && val2->value_type!=VT_INTEGR && val2->value_type!=VT_FUNCTN) { if (val2->value_type == VT_STRING) { val2 = get(env, val2->data.string_value); } else { val2 = get(env, val2->identifier); } if (!val2) fatal("Undeclared identifier"); } /* Check the LHS variable has already been defined */ temp = get(env, to_string(val1)); assert(temp!=NULL, "Variable not defined"); /* Type check the assignment */ type_check_assignment(val1, val2, vt_type_convert(temp->value_type)); temporary = assign(env, val1, val2, 0); if (flag != INTERPRET_FN_SCAN) append_code(make_quad_value("=", val2, NULL, temporary, TT_ASSIGN, 0)); return NULL; case '*': case '/': case '>': case '<': case '%': case '-': case '+': case NE_OP: case LE_OP: case GE_OP: case EQ_OP: temporary = generate_temporary(env, int_value(0)); val1 = make_simple(env, node->left, flag, return_type); val2 = make_simple(env, node->right, flag, return_type); if (val1->value_type==VT_STRING) val1 = get(env, correct_string_rep(val1)); if (val2->value_type==VT_STRING) val2 = get(env, correct_string_rep(val2)); assert(val1 != NULL, "Operand value 1 must not be null"); assert(val2 != NULL, "Operand value 2 must not be null"); if (flag != INTERPRET_FN_SCAN) append_code(make_quad_value(type_to_string(type_of(node)), val1, val2, temporary, TT_OP, type_of(node))); return temporary; case '~': if (flag != INTERPRET_PARAMS && flag!=INTERPRET_FN_SCAN) { /* Params should not be registered, because at this point we're not in the correct environment */ register_variable_subtree_tac(env, node, VT_ANY); } val1 = make_simple(env, node->left, flag, return_type); val2 = make_simple(env, node->right, flag, return_type); if (flag == INTERPRET_PARAMS) { return int_param(to_string(val2), to_int(env, val1)); } return NULL; case 'D': /* val1 is FN definition */ /* val1 is executed in current environment */ val1 = make_simple(env, node->left, flag, return_type); /* New FN body environment */ new_env = create_environment(env); if (val1!=NULL) { /* Point function to the correct fn body */ val1->data.func->node_value = node->right; /* Store function definition in environment */ val2 = store_function(env, val1, new_env); } if (flag != INTERPRET_FN_SCAN) { /* Write out FN Name label */ append_code(make_begin_fn(val2)); append_code(make_fn_def(val2)); /* Make init frame */ temp_quad = make_init_frame(); append_code(temp_quad); /* Define parameters with default empty values */ register_params(new_env, val2->data.func->params); append_code(make_fn_body(val2)); /* Look inside fn body */ val2 = make_simple(new_env, node->right, EMBEDDED_FNS, val1->data.func->return_type); /* Update prepare frame with environment size */ temp_quad->operand1 = int_value(env_size(new_env)); /* Write end of function marker */ append_code(make_end_fn(val2)); } return NULL; case 'd': /* val1 is the type */ val1 = make_simple(env, node->left, flag, return_type); /* val2 is fn name & params */ val2 = make_simple(env, node->right, flag, return_type); /* Store return type */ val2->data.func->return_type = to_int(env, val1); return val2; case 'F': /* FN name in val1 */ val1 = make_simple(env, node->left, flag, return_type); /* Pull our parameters */ val2 = make_simple(env, node->right, INTERPRET_PARAMS, return_type); return build_function(env, val1, val2); case RETURN: val1 = make_simple(env, node->left, flag, return_type); /* Provide lookup for non-constants */ if (val1 && val1->value_type!=VT_INTEGR) { if (val1->value_type == VT_STRING) { val1 = get(env, val1->data.string_value); } else { val1 = get(env, val1->identifier); } if (!val1) fatal("Undeclared identifier"); } type_check_return(val1, return_type); append_code(make_return(val1)); return NULL; case ',': val1 = make_simple(env, node->left, flag, return_type); val2 = make_simple(env, node->right, flag, return_type); if (val1 && val2) { return join(val1, val2); } return NULL; case APPLY: /* FN Name */ val1 = make_simple(env, node->left, flag, return_type); /* Params */ val2 = make_simple(env, node->right, flag, return_type); /* Lookup function */ temp = search(env, to_string(val1), VT_FUNCTN, VT_ANY, 1); if (temp) { int fn_return_type; append_code(prepare_fn(val2)); append_code(push_params(env, val2)); /* If we can't typecheck, set a special UNDEFINED flag to say we can't */ /* typecheck. This can happen with function variables, we do not EASILY know the */ /* return type of the functions they are bound to until runtime. */ fn_return_type = UNDEFINED; if (temp->data.func) { fn_return_type = temp->data.func->return_type; } /* Temporary for result (if any) */ switch(fn_return_type) { case INT: temporary = generate_temporary(env, int_value(0)); break; case VOID: temporary = generate_temporary(env, NULL); break; case FUNCTION: temporary = generate_temporary(env, null_fn); break; default: temporary = generate_untypechecked_temporary(env); break; } append_code(make_fn_call(temporary, temp)); return temporary; } else { fatal("Cannot find function '%s'", to_string(val1)); } return NULL; case FUNCTION: case INT: case VOID: return int_value(type_of(node)); case ';': make_simple(env, node->left, flag, return_type); make_simple(env, node->right, flag, return_type); return NULL; default: fatal("Unrecognised node type"); return NULL; } }
int main(int argc, char **argv) { char *platformFile = NULL; int totalHosts, totalLinks; int timings=0; int downgrade = 0; int version = 3; const char *link_ctn = link_ctn_v3; unsigned int i; xbt_dict_t props = NULL; xbt_dict_cursor_t cursor = NULL; xbt_lib_cursor_t cursor_src = NULL; xbt_lib_cursor_t cursor_dst = NULL; char *src,*dst,*key,*data; sg_routing_edge_t value1; sg_routing_edge_t value2; const SD_workstation_t *hosts; const SD_link_t *links; xbt_os_timer_t parse_time = xbt_os_timer_new(); setvbuf(stdout, NULL, _IOLBF, 0); SD_init(&argc, argv); if (parse_cmdline(&timings, &downgrade, &platformFile, argc, argv) || !platformFile) { xbt_die("Invalid command line arguments: expected [--timings|--downgrade] platformFile"); } XBT_DEBUG("%d,%d,%s", timings, downgrade, platformFile); if (downgrade) { version = 2; link_ctn = link_ctn_v2; } create_environment(parse_time, platformFile); if (timings) { XBT_INFO("Parsing time: %fs (%d hosts, %d links)", xbt_os_timer_elapsed(parse_time),SD_workstation_get_number(),SD_link_get_number()); } else { printf("<?xml version='1.0'?>\n"); printf("<!DOCTYPE platform SYSTEM \"http://simgrid.gforge.inria.fr/simgrid.dtd\">\n"); printf("<platform version=\"%d\">\n", version); if (!downgrade) printf("<AS id=\"AS0\" routing=\"Full\">\n"); // Hosts totalHosts = SD_workstation_get_number(); hosts = SD_workstation_get_list(); qsort((void *) hosts, totalHosts, sizeof(SD_workstation_t), name_compare_hosts); for (i = 0; i < totalHosts; i++) { printf(" <host id=\"%s\" power=\"%.0f\"", SD_workstation_get_name(hosts[i]), SD_workstation_get_power(hosts[i])); props = SD_workstation_get_properties(hosts[i]); if (props && !xbt_dict_is_empty(props)) { printf(">\n"); xbt_dict_foreach(props, cursor, key, data) { printf(" <prop id=\"%s\" value=\"%s\"/>\n", key, data); } printf(" </host>\n"); } else {