sys.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #include "__ofunc.h"
  2. ResultType vm_super(OFFICAL_FUNCTIONSIG){
  3. Value *arg_father = NULL;
  4. Value *arg_child = NULL;
  5. LinkValue *next_father = NULL;
  6. ArgumentParser ap[] = {{.type=name_value, .name="class_", .must=1, .long_arg=false},
  7. {.type=name_value, .name="obj_", .must=1, .long_arg=false},
  8. {.must=-1}};
  9. setResultCore(result);
  10. parserArgumentUnion(ap, arg, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  11. if (!CHECK_RESULT(result))
  12. return result->type;
  13. freeResult(result);
  14. arg_father = ap[0].value->value;
  15. arg_child = ap[1].value->value;
  16. if (arg_child == arg_father) {
  17. if (arg_child->object.inherit != NULL){
  18. result->value = copyLinkValue(arg_child->object.inherit->value, inter);
  19. result->type = operation_return;
  20. gc_addTmpLink(&result->value->gc_status);
  21. } else
  22. setResultError(E_SuperException, "Don't get next father", 0, "sys", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  23. return result->type;
  24. }
  25. for (Inherit *self_father = arg_child->object.inherit; self_father != NULL; self_father = self_father->next) {
  26. if (self_father->value->value == arg_father) {
  27. if (self_father->next != NULL)
  28. next_father = copyLinkValue(self_father->next->value, inter);
  29. break;
  30. }
  31. }
  32. if (next_father != NULL){
  33. result->value = next_father;
  34. result->type = operation_return;
  35. gc_addTmpLink(&result->value->gc_status);
  36. }
  37. else
  38. setResultError(E_SuperException, "Don't get next father", 0, "sys", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  39. return result->type;
  40. }
  41. ResultType vm_setMethodCore(OFFICAL_FUNCTIONSIG, enum FunctionPtType type){
  42. LinkValue *function_value = NULL;
  43. ArgumentParser ap[] = {{.type=name_value, .name="func", .must=1, .long_arg=false}, {.must=-1}};
  44. setResultCore(result);
  45. {
  46. parserArgumentUnion(ap, arg, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  47. if (!CHECK_RESULT(result))
  48. return result->type;
  49. freeResult(result);
  50. }
  51. function_value = ap[0].value;
  52. function_value->value->data.function.function_data.pt_type = type;
  53. result->value = function_value;
  54. gc_addTmpLink(&result->value->gc_status);
  55. result->type = operation_return;
  56. return operation_return;
  57. }
  58. ResultType vm_freemethod(OFFICAL_FUNCTIONSIG){
  59. return vm_setMethodCore(CALL_OFFICAL_FUNCTION(arg, var_list, result, belong), free_);
  60. }
  61. ResultType vm_staticmethod(OFFICAL_FUNCTIONSIG){
  62. return vm_setMethodCore(CALL_OFFICAL_FUNCTION(arg, var_list, result, belong), static_);
  63. }
  64. ResultType vm_classmethod(OFFICAL_FUNCTIONSIG){
  65. return vm_setMethodCore(CALL_OFFICAL_FUNCTION(arg, var_list, result, belong), class_static_);
  66. }
  67. ResultType vm_objectmethod(OFFICAL_FUNCTIONSIG){
  68. return vm_setMethodCore(CALL_OFFICAL_FUNCTION(arg, var_list, result, belong), object_static_);
  69. }
  70. ResultType vm_classfreemethod(OFFICAL_FUNCTIONSIG){
  71. return vm_setMethodCore(CALL_OFFICAL_FUNCTION(arg, var_list, result, belong), class_free_);
  72. }
  73. ResultType vm_objectfreemethod(OFFICAL_FUNCTIONSIG){
  74. return vm_setMethodCore(CALL_OFFICAL_FUNCTION(arg, var_list, result, belong), object_free_);
  75. }
  76. ResultType vm_allfreemethod(OFFICAL_FUNCTIONSIG){
  77. return vm_setMethodCore(CALL_OFFICAL_FUNCTION(arg, var_list, result, belong), all_free_);
  78. }
  79. ResultType vm_allstaticmethod(OFFICAL_FUNCTIONSIG){
  80. return vm_setMethodCore(CALL_OFFICAL_FUNCTION(arg, var_list, result, belong), all_static_);
  81. }
  82. ResultType vm_quit(OFFICAL_FUNCTIONSIG){
  83. if (arg != NULL)
  84. setResultError(E_ArgumentException, "Too Many Argument", 0, "sys", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  85. else
  86. setResultError(E_QuitException, "Quit By User", 0, "sys", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  87. return error_return;
  88. }
  89. void registeredSysFunction(REGISTERED_FUNCTIONSIG){
  90. NameFunc tmp[] = {{"super", vm_super, free_},
  91. {"freemethod", vm_freemethod, free_},
  92. {"staticmethod", vm_staticmethod, free_},
  93. {"staticclassmethod", vm_classmethod, free_},
  94. {"staticobjectmethod", vm_objectmethod, free_},
  95. {"classmethod", vm_classfreemethod, free_},
  96. {"objectmethod", vm_objectfreemethod, free_},
  97. {"simplemethod", vm_allfreemethod, free_},
  98. {"simplestaticmethod", vm_allstaticmethod, free_},
  99. {"quit", vm_quit, free_},
  100. {NULL, NULL}};
  101. iterNameFunc(tmp, belong, CALL_INTER_FUNCTIONSIG_CORE(var_list));
  102. }