sys.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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=L"class_", .must=1, .long_arg=false},
  7. {.type=name_value, .name=L"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 = R_opt;
  20. gc_addTmpLink(&result->value->gc_status);
  21. } else
  22. setResultError(E_SuperException, L"Object has no next father", 0, "super", 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 = R_opt;
  35. gc_addTmpLink(&result->value->gc_status);
  36. }
  37. else
  38. setResultError(E_SuperException, L"Object has no next father", 0, "super", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  39. return result->type;
  40. }
  41. ResultType vm_setNowRunCore(OFFICAL_FUNCTIONSIG, bool type){
  42. LinkValue *function_value = NULL;
  43. ArgumentParser ap[] = {{.type=name_value, .name=L"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.run = type;
  53. result->value = function_value;
  54. gc_addTmpLink(&result->value->gc_status);
  55. result->type = R_opt;
  56. return R_opt;
  57. }
  58. ResultType vm_setMethodCore(OFFICAL_FUNCTIONSIG, enum FunctionPtType type){
  59. LinkValue *function_value = NULL;
  60. ArgumentParser ap[] = {{.type=name_value, .name=L"func", .must=1, .long_arg=false}, {.must=-1}};
  61. setResultCore(result);
  62. {
  63. parserArgumentUnion(ap, arg, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  64. if (!CHECK_RESULT(result))
  65. return result->type;
  66. freeResult(result);
  67. }
  68. function_value = ap[0].value;
  69. function_value->value->data.function.function_data.pt_type = type;
  70. result->value = function_value;
  71. gc_addTmpLink(&result->value->gc_status);
  72. result->type = R_opt;
  73. return R_opt;
  74. }
  75. ResultType vm_clsfreemethod(OFFICAL_FUNCTIONSIG){
  76. return vm_setMethodCore(CALL_OFFICAL_FUNCTION(arg, var_list, result, belong), cls_free_);
  77. }
  78. ResultType vm_clsmethod(OFFICAL_FUNCTIONSIG){
  79. return vm_setMethodCore(CALL_OFFICAL_FUNCTION(arg, var_list, result, belong), cls_static_);
  80. }
  81. ResultType vm_freemethod(OFFICAL_FUNCTIONSIG){
  82. return vm_setMethodCore(CALL_OFFICAL_FUNCTION(arg, var_list, result, belong), free_);
  83. }
  84. ResultType vm_staticmethod(OFFICAL_FUNCTIONSIG){
  85. return vm_setMethodCore(CALL_OFFICAL_FUNCTION(arg, var_list, result, belong), static_);
  86. }
  87. ResultType vm_classmethod(OFFICAL_FUNCTIONSIG){
  88. return vm_setMethodCore(CALL_OFFICAL_FUNCTION(arg, var_list, result, belong), class_static_);
  89. }
  90. ResultType vm_objectmethod(OFFICAL_FUNCTIONSIG){
  91. return vm_setMethodCore(CALL_OFFICAL_FUNCTION(arg, var_list, result, belong), object_static_);
  92. }
  93. ResultType vm_classfreemethod(OFFICAL_FUNCTIONSIG){
  94. return vm_setMethodCore(CALL_OFFICAL_FUNCTION(arg, var_list, result, belong), class_free_);
  95. }
  96. ResultType vm_objectfreemethod(OFFICAL_FUNCTIONSIG){
  97. return vm_setMethodCore(CALL_OFFICAL_FUNCTION(arg, var_list, result, belong), object_free_);
  98. }
  99. ResultType vm_allfreemethod(OFFICAL_FUNCTIONSIG){
  100. return vm_setMethodCore(CALL_OFFICAL_FUNCTION(arg, var_list, result, belong), all_free_);
  101. }
  102. ResultType vm_allstaticmethod(OFFICAL_FUNCTIONSIG){
  103. return vm_setMethodCore(CALL_OFFICAL_FUNCTION(arg, var_list, result, belong), all_static_);
  104. }
  105. ResultType vm_isnowrun(OFFICAL_FUNCTIONSIG){
  106. return vm_setNowRunCore(CALL_OFFICAL_FUNCTION(arg, var_list, result, belong), true);
  107. }
  108. ResultType vm_disnowrun(OFFICAL_FUNCTIONSIG){
  109. return vm_setNowRunCore(CALL_OFFICAL_FUNCTION(arg, var_list, result, belong), false);
  110. }
  111. ResultType vm_quit(OFFICAL_FUNCTIONSIG){
  112. if (arg != NULL)
  113. setResultError(E_ArgumentException, MANY_ARG, 0, "sys", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  114. else
  115. setResultError(E_QuitException, L"VirtualMath Quit", 0, "sys", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  116. return R_error;
  117. }
  118. void registeredSysFunction(REGISTERED_FUNCTIONSIG){
  119. NameFunc tmp[] = {{L"super", vm_super, free_},
  120. {L"freemethod", vm_freemethod, free_},
  121. {L"staticmethod", vm_staticmethod, free_},
  122. {L"staticclassmethod", vm_classmethod, free_},
  123. {L"staticobjectmethod", vm_objectmethod, free_},
  124. {L"classmethod", vm_classfreemethod, free_},
  125. {L"objectmethod", vm_objectfreemethod, free_},
  126. {L"simplemethod", vm_allfreemethod, free_},
  127. {L"simplestaticmethod", vm_allstaticmethod, free_},
  128. {L"clsmethod", vm_clsfreemethod, free_},
  129. {L"clsstaticmethod", vm_clsmethod, free_},
  130. {L"isnowrun", vm_isnowrun, free_},
  131. {L"disnowrun", vm_disnowrun, free_},
  132. {L"quit", vm_quit, free_},
  133. {NULL, NULL}};
  134. iterBaseNameFunc(tmp, belong, CALL_INTER_FUNCTIONSIG_CORE(var_list));
  135. }