function.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #include "__ofunc.h"
  2. static void setFunctionData(Value *value, LinkValue *cls, Inter *inter) {
  3. value->data.function.function_data.pt_type = inter->data.default_pt_type;
  4. value->data.function.function_data.cls = cls;
  5. }
  6. ResultType function_new(OFFICAL_FUNCTIONSIG){
  7. LinkValue *value = NULL;
  8. ArgumentParser ap[] = {{.type=only_value, .must=1, .long_arg=false},
  9. {.must=-1}};
  10. int status = 1;
  11. setResultCore(result);
  12. arg = parserValueArgument(ap, arg, &status, NULL);
  13. if (status != 1){
  14. setResultError(E_ArgumentException, FEW_ARG, 0, "V_func.new", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  15. return R_error;
  16. }
  17. {
  18. Inherit *object_father = getInheritFromValueCore(inter->data.function);
  19. VarList *new_var = copyVarList(var_list, false, inter);
  20. Value *new_object = makeObject(inter, NULL, new_var, object_father);
  21. value = makeLinkValue(new_object, belong, inter);
  22. }
  23. value->value->type = V_func;
  24. value->value->data.function.type = vm_func;
  25. value->value->data.function.function = NULL;
  26. value->value->data.function.pt = NULL;
  27. value->value->data.function.of = NULL;
  28. setFunctionData(value->value, ap->value, inter);
  29. switch (init_new(value, arg, "V_func.new", CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong))) {
  30. case 1:
  31. freeResult(result);
  32. setResultOperation(result, value);
  33. break;
  34. default:
  35. break;
  36. }
  37. return result->type;
  38. }
  39. ResultType function_init(OFFICAL_FUNCTIONSIG){
  40. ArgumentParser ap[] = {{.type=only_value, .must=1, .long_arg=false},
  41. {.type=only_value, .must=0, .long_arg=false},
  42. {.must=-1}};
  43. LinkValue *func;
  44. setResultCore(result);
  45. parserArgumentUnion(ap, arg, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  46. if (!CHECK_RESULT(result))
  47. return result->type;
  48. freeResult(result);
  49. if ((func = ap[0].value)->value->type != V_func) {
  50. setResultError(E_TypeException, INSTANCE_ERROR(V_func), 0, "V_func", true,
  51. CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  52. return R_error;
  53. }
  54. if (ap[1].value != NULL) {
  55. Statement *return_ = makeBaseLinkValueStatement(ap[1].value, 0, "sys");
  56. func->value->data.function.function = makeReturnStatement(return_, 0, "sys");
  57. func->value->data.function.function_data.pt_type = free_;
  58. func->value->data.function.type = vm_func;
  59. }
  60. setResult(result, inter);
  61. return result->type;
  62. }
  63. void registeredFunction(REGISTERED_FUNCTIONSIG){
  64. LinkValue *object = inter->data.function;
  65. NameFunc tmp[] = {{NULL, NULL}};
  66. gc_addTmpLink(&object->gc_status);
  67. addBaseClassVar(L"V_func", object, belong, inter);
  68. iterBaseClassFunc(tmp, object, CALL_INTER_FUNCTIONSIG_CORE(inter->var_list));
  69. gc_freeTmpLink(&object->gc_status);
  70. }
  71. void makeBaseFunction(Inter *inter){
  72. LinkValue *function = makeBaseChildClass(inter->data.vobject, inter);
  73. gc_addStatementLink(&function->gc_status);
  74. inter->data.function = function;
  75. }
  76. void functionPresetting(LinkValue *func, LinkValue **func_new, LinkValue **func_init, Inter *inter) {
  77. *func_new = makeCFunctionFromOf(function_new, func, function_new, function_init, func, inter->var_list, inter);
  78. *func_init = makeCFunctionFromOf(function_init, func, function_new, function_init, func, inter->var_list, inter);
  79. (*func_new)->value->data.function.function_data.pt_type = class_free_;
  80. (*func_init)->value->data.function.function_data.pt_type = object_free_;
  81. }
  82. void functionPresettingLast(LinkValue *func, LinkValue *func_new, LinkValue *func_init, Inter *inter) {
  83. Result result;
  84. VarList *object_var = func->value->object.var;
  85. setResultCore(&result);
  86. addStrVar(inter->data.object_new, false, true, func_new, 0, "sys", CALL_INTER_FUNCTIONSIG_NOT_ST(object_var, &result, func));
  87. freeResult(&result);
  88. addStrVar(inter->data.object_init, false, true, func_init, 0, "sys", CALL_INTER_FUNCTIONSIG_NOT_ST(object_var, &result, func));
  89. freeResult(&result);
  90. }