function.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #include "__ofunc.h"
  2. ResultType function_init(OFFICAL_FUNCTIONSIG){
  3. ArgumentParser ap[] = {{.type=only_value, .must=1, .long_arg=false},
  4. {.type=only_value, .must=0, .long_arg=false},
  5. {.must=-1}};
  6. LinkValue *base;
  7. LinkValue *func_return;
  8. setResultCore(result);
  9. parserArgumentUnion(ap, arg, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  10. if (!CHECK_RESULT(result))
  11. return result->type;
  12. freeResult(result);
  13. base = ap[0].value;
  14. func_return = ap[1].value;
  15. if (func_return == NULL)
  16. func_return = makeLinkValue(makeNoneValue(inter), belong, inter);
  17. makeVMFunctionFromValue(base->value, func_return, 0, "sys", inter);
  18. setResult(result, inter, belong);
  19. return result->type;
  20. }
  21. void registeredFunction(REGISTERED_FUNCTIONSIG){
  22. LinkValue *object = makeLinkValue(inter->data.function, inter->base_father, inter);
  23. NameFunc tmp[] = {{inter->data.object_init, function_init, object_free_},
  24. {NULL, NULL}};
  25. gc_addTmpLink(&object->gc_status);
  26. addStrVar("function", false, true, object, belong, CALL_INTER_FUNCTIONSIG_CORE(inter->var_list));
  27. iterClassFunc(tmp, object, CALL_INTER_FUNCTIONSIG_CORE(inter->var_list));
  28. gc_freeTmpLink(&object->gc_status);
  29. }
  30. void makeBaseFunction(Inter *inter){
  31. Value *function = makeBaseChildClass(inter->data.vobject, inter);
  32. gc_addStatementLink(&function->gc_status);
  33. inter->data.function = function;
  34. }