static CRB_Value eval_function_call_expression(CRB_Interpreter *inter, LcoalEnvriroment *env, Expression *expr) { CRB_Value value; FunctionDefinition *func; char *identifier = expr->u.function_call_expression.identifier; func = crb_search_function(identifier); if(func == NULL){ crb_runtime_error(expr->line_number, FUNCTION_NOT_FOUND_ERR, STRING_MESSAGE_ARGUMENT, "name", identifier, MESSAGE_ARGUMENT_END); } switch(func->type){ case CROWBAR_FUNCTION_DEFINITION: value = call_crowbar_function(inter, env, expr, func); break; case NATIVE_FUNCTION_DEFINITION: value = call_native_function(inter, env, expr, func->u.native_f.proc); break; default: DBG_panic(("bad case..%d\n", func->type)); } return value; }
static void eval_function_call_expression(SIMCAR_Interpreter *inter, SIMCAR_LocalEnvironment *env, Expression *expr) { FunctionDefinition *func; SIMCAR_LocalEnvironment *local_env; char *identifier = expr->u.function_call_expression.identifier; func = crb_search_function(identifier); if (func == NULL) { crb_runtime_error(expr->line_number, FUNCTION_NOT_FOUND_ERR, STRING_MESSAGE_ARGUMENT, "name", identifier, MESSAGE_ARGUMENT_END); } local_env = alloc_local_environment(inter); switch (func->type) { case CROWBAR_FUNCTION_DEFINITION: call_crowbar_function(inter, local_env, env, expr, func); break; case NATIVE_FUNCTION_DEFINITION: call_native_function(inter, local_env, env, expr, func->u.native_f.proc); break; case FUNCTION_DEFINITION_TYPE_COUNT_PLUS_1: default: DBG_panic(("bad case..%d\n", func->type)); } dispose_local_environment(inter); }
void crb_function_define(char *identifier, ParameterList *parameter_list, Block *block) { FunctionDefinition *f; CRB_Interpreter *iter; if (crb_search_function(identifier)) { crb_compile_error(FUNCTION_MULTIPLE_DEFINE_ERR, STRING_MESSAGE_ARGUMENT, "name", identifier, MESSAGE_ARGUMENT_END); return; } inter = crb_get_current_interpreter(); f = crb_malloc(sizeof(FunctionDefinition)); f->name = identifier; f->type = CROWBAR_FUNCTION_DEFINITION; f->u.crowbar_f.parameter = parameter_list; f->u.crowbar_f.block = block; f->next = inter->function_list; inter->function_list = f; }