runcall.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include "__run.h"
  2. Result setFunction(INTER_FUNCTIONSIG) {
  3. Result result;
  4. LinkValue *tmp = makeLinkValue(NULL, NULL, inter);
  5. setResultCore(&result);
  6. tmp->value = makeFunctionValue(st->u.set_function.function, st->u.set_function.parameter, var_list, inter);
  7. result = assCore(st->u.set_function.name, tmp, CALL_INTER_FUNCTIONSIG_CORE(var_list));
  8. if (!run_continue(result))
  9. return result;
  10. setResult(&result, inter);
  11. return result;
  12. }
  13. Result callFunction(INTER_FUNCTIONSIG) {
  14. Result result;
  15. Result function_value;
  16. Result set_tmp;
  17. setResultCore(&result);
  18. setResultCore(&function_value);
  19. setResultCore(&set_tmp);
  20. if (operationSafeInterStatement(&function_value, CALL_INTER_FUNCTIONSIG(st->u.call_function.function, var_list)))
  21. return function_value;
  22. if (function_value.value->value->type != function){
  23. freeResult(&function_value);
  24. setResultError(&result, inter, "TypeException", "Object is not callable", st, true);
  25. result.type = error_return;
  26. goto return_;
  27. }
  28. VarList *function_var = pushVarList(function_value.value->value->data.function.var, inter);
  29. gcAddTmp(&function_var->hashtable->gc_status);
  30. set_tmp = setParameter(st->u.call_function.parameter, function_value.value->value->data.function.pt, function_var,
  31. st, CALL_INTER_FUNCTIONSIG_CORE(var_list));
  32. if (set_tmp.type == error_return) {
  33. gcAddTmp(&function_var->hashtable->gc_status);
  34. popVarList(function_var);
  35. return set_tmp;
  36. }
  37. else
  38. freeResult(&set_tmp);
  39. functionSafeInterStatement(&result, CALL_INTER_FUNCTIONSIG(function_value.value->value->data.function.function, function_var));
  40. gcFreeTmpLink(&function_var->hashtable->gc_status);
  41. popVarList(function_var);
  42. freeResult(&function_value);
  43. setResultError(&result, inter, NULL, NULL, st, false); // 自带检查
  44. return_:
  45. return result;
  46. }