static Variable * search_global_variable_from_env(CRB_Interpreter *inter, LocalEnvironment *env, char *name) { GlobalVariableRef *pos; if(env == NULL){ return crb_search_global_variable(inter, name); } for(pos = env->global_variable; pos; pos = pos->next){ if(!strcmp(pos->variable->name, name)){ return pos->variable; } } return NULL; }
static StatementResult execute_global_statement(CRB_Interpreter *inter, CRB_LocalEnvironment *env, Statement *statement) { IdentifierList *pos; StatementResult result; result.type = NORMAL_STATEMENT_RESULT; if (env == NULL) { crb_runtime_error(statement->line_number, GLOBAL_STATEMENT_IN_TOPLEVEL_ERR, MESSAGE_ARGUMENT_END); } for (pos = statement->u.global_s.identifier_list; pos; pos = pos->next) { GlobalVariableRef *ref_pos; GlobalVariableRef *new_ref; Variable *variable; for (ref_pos = env->global_variable; ref_pos; ref_pos = ref_pos->next) { if (!strcmp(ref_pos->variable->name, pos->name)) goto NEXT_IDENTIFIER; } variable = crb_search_global_variable(inter, pos->name); if (variable == NULL) { crb_runtime_error(statement->line_number, GLOBAL_VARIABLE_NOT_FOUND_ERR, STRING_MESSAGE_ARGUMENT, "name", pos->name, MESSAGE_ARGUMENT_END); } new_ref = MEM_malloc(sizeof(GlobalVariableRef)); new_ref->variable = variable; new_ref->next = env->global_variable; env->global_variable = new_ref; NEXT_IDENTIFIER: ; } return result; }