runcall.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. #include "__run.h"
  2. ResultType setClass(INTER_FUNCTIONSIG) {
  3. Argument *call = NULL;
  4. LinkValue *tmp = NULL;
  5. FatherValue *class_father = NULL;
  6. VarList *father_var = NULL;
  7. setResultCore(result);
  8. call = getArgument(st->u.set_class.father, false, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, father));
  9. if (!run_continue(result))
  10. goto error_;
  11. class_father = setFather(call);
  12. freeArgument(call, true);
  13. tmp = makeLinkValue(makeClassValue(copyVarList(var_list, false, inter), inter, class_father), father, inter);
  14. gc_addTmpLink(&tmp->gc_status);
  15. father_var = tmp->value->object.var->next;
  16. tmp->value->object.var->next = var_list;
  17. freeResult(result);
  18. functionSafeInterStatement(CALL_INTER_FUNCTIONSIG(st->u.set_class.st, tmp->value->object.var, result, tmp));
  19. tmp->value->object.var->next = father_var;
  20. if (!run_continue(result))
  21. goto error_;
  22. freeResult(result);
  23. if (st->u.set_class.decoration != NULL){
  24. setDecoration(st->u.set_class.decoration, tmp, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, father));
  25. if (!run_continue(result))
  26. goto error_;
  27. gc_freeTmpLink(&tmp->gc_status);
  28. tmp = result->value;
  29. result->value = NULL;
  30. freeResult(result);
  31. }
  32. assCore(st->u.set_class.name, tmp, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, father));
  33. if (run_continue(result))
  34. setResult(result, inter, father);
  35. gc_freeTmpLink(&tmp->gc_status);
  36. return result->type;
  37. error_:
  38. gc_freeTmpLink(&tmp->gc_status);
  39. setResultErrorSt(result, inter, NULL, NULL, st, father, false);
  40. return result->type;
  41. }
  42. ResultType setFunction(INTER_FUNCTIONSIG) {
  43. LinkValue *tmp = NULL;
  44. Value *function_value = NULL;
  45. VarList *function_var = NULL;
  46. setResultCore(result);
  47. function_var = copyVarList(var_list, false, inter);
  48. function_value = makeVMFunctionValue(st->u.set_function.function, st->u.set_function.parameter, function_var, inter);
  49. tmp = makeLinkValue(function_value, father, inter);
  50. gc_addTmpLink(&tmp->gc_status);
  51. if (st->u.set_function.decoration != NULL){
  52. setDecoration(st->u.set_function.decoration, tmp, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, father));
  53. if (!run_continue(result))
  54. goto error_;
  55. gc_freeTmpLink(&tmp->gc_status);
  56. tmp = result->value;
  57. result->value = NULL;
  58. freeResult(result);
  59. }
  60. assCore(st->u.set_function.name, tmp, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, father));
  61. if (!run_continue(result))
  62. goto error_;
  63. setResult(result, inter, father);
  64. gc_freeTmpLink(&tmp->gc_status);
  65. return result->type;
  66. error_:
  67. gc_freeTmpLink(&tmp->gc_status);
  68. return result->type;
  69. }
  70. ResultType setLambda(INTER_FUNCTIONSIG) {
  71. Value *function_value = NULL;
  72. VarList *function_var = NULL;
  73. setResultCore(result);
  74. result->type = operation_return;
  75. function_var = copyVarList(var_list, false, inter);
  76. function_value = makeVMFunctionValue(st->u.base_lambda.function, st->u.base_lambda.parameter, function_var, inter);
  77. result->value = makeLinkValue(function_value, father, inter);
  78. gc_addTmpLink(&result->value->gc_status);
  79. return result->type;
  80. }
  81. ResultType callBack(INTER_FUNCTIONSIG) {
  82. LinkValue *function_value = NULL;
  83. setResultCore(result);
  84. if (operationSafeInterStatement(CALL_INTER_FUNCTIONSIG(st->u.call_function.function, var_list, result, father)))
  85. goto return_;
  86. function_value = result->value;
  87. result->value = NULL;
  88. freeResult(result);
  89. callBackCorePt(function_value, st->u.call_function.parameter, st->line, st->code_file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, father));
  90. gc_freeTmpLink(&function_value->gc_status);
  91. return_:
  92. return result->type;
  93. }
  94. ResultType callBackCorePt(LinkValue *function_value, Parameter *pt, long line, char *file, INTER_FUNCTIONSIG_NOT_ST) {
  95. Argument *arg = NULL;
  96. setResultCore(result);
  97. gc_addTmpLink(&function_value->gc_status);
  98. arg = getArgument(pt, false, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, father));
  99. if (!run_continue(result))
  100. goto return_;
  101. freeResult(result);
  102. callBackCore(function_value, arg, line, file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, father));
  103. return_:
  104. gc_freeTmpLink(&function_value->gc_status);
  105. freeArgument(arg, true);
  106. return result->type;
  107. }
  108. ResultType callBackCore(LinkValue *function_value, Argument *arg, long line, char *file, INTER_FUNCTIONSIG_NOT_ST){
  109. setResultCore(result);
  110. gc_addTmpLink(&function_value->gc_status);
  111. if (function_value->value->type == function && function_value->value->data.function.type == vm_function)
  112. callVMFunction(function_value, arg, line, file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, father));
  113. else if (function_value->value->type == function && function_value->value->data.function.type == c_function)
  114. callCFunction(function_value, arg, line, file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, father));
  115. else if (function_value->value->type == class)
  116. callClass(function_value, arg, line, file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, father));
  117. else{
  118. setResultError(result, inter, "TypeException", "Object is not callable", line, file, father, true);
  119. goto return_;
  120. }
  121. setResultError(result, inter, NULL, NULL, line, file, father, false);
  122. return_:
  123. gc_freeTmpLink(&function_value->gc_status);
  124. return result->type;
  125. }
  126. ResultType callClass(LinkValue *class_value, Argument *arg, long int line, char *file, INTER_FUNCTIONSIG_NOT_ST) {
  127. LinkValue *_new_ = NULL;
  128. setResultCore(result);
  129. char *init_name = setStrVarName(inter->data.object_new, false, CALL_INTER_FUNCTIONSIG_CORE(var_list));
  130. _new_ = findFromVarList(init_name, 0, false, CALL_INTER_FUNCTIONSIG_CORE(class_value->value->object.var));
  131. memFree(init_name);
  132. if (_new_ != NULL){
  133. _new_->father = class_value;
  134. gc_addTmpLink(&_new_->gc_status);
  135. callBackCore(_new_, arg, line, file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, father));
  136. gc_freeTmpLink(&_new_->gc_status);
  137. }
  138. else
  139. setResultError(result, inter, "ClassException", "Don't find __new__", line, file, father, true);
  140. return result->type;
  141. }
  142. ResultType callCFunction(LinkValue *function_value, Argument *arg, long int line, char *file, INTER_FUNCTIONSIG_NOT_ST){
  143. VarList *function_var = NULL;
  144. OfficialFunction of = NULL;
  145. setResultCore(result);
  146. gc_addTmpLink(&function_value->gc_status);
  147. setFunctionArgument(&arg, function_value, line, file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, father));
  148. if (!run_continue(result))
  149. goto return_;
  150. of = function_value->value->data.function.of;
  151. function_var = function_value->value->object.out_var;
  152. gc_freeze(inter, var_list, function_var, true);
  153. freeResult(result);
  154. of(CALL_OfficialFunction(arg, function_var, result, function_value->father));
  155. gc_freeze(inter, var_list, function_var, false);
  156. freeFunctionArgument(arg);
  157. return_:
  158. gc_freeTmpLink(&function_value->gc_status);
  159. return result->type;
  160. }
  161. ResultType callVMFunction(LinkValue *function_value, Argument *arg, long int line, char *file, INTER_FUNCTIONSIG_NOT_ST) {
  162. VarList *function_var = NULL;
  163. Statement *funtion_st = NULL;
  164. Parameter *func_pt = function_value->value->data.function.pt;
  165. bool yield_run = false;
  166. setResultCore(result);
  167. gc_addTmpLink(&function_value->gc_status);
  168. funtion_st = function_value->value->data.function.function;
  169. if ((yield_run = popStatementVarList(funtion_st, &function_var, function_value->value->object.out_var, inter)))
  170. funtion_st = getRunInfoStatement(funtion_st);
  171. gc_freeze(inter, var_list, function_var, true);
  172. setFunctionArgument(&arg, function_value, line, file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, father));
  173. if (!run_continue(result))
  174. goto return_;
  175. freeResult(result);
  176. gc_addTmpLink(&function_var->hashtable->gc_status);
  177. setParameterCore(line, file, arg, func_pt, function_var, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, function_value->father));
  178. freeFunctionArgument(arg);
  179. gc_freeTmpLink(&function_var->hashtable->gc_status);
  180. if (!run_continue(result)) {
  181. gc_freeze(inter, var_list, function_var, false);
  182. funtion_st = function_value->value->data.function.function;
  183. if (yield_run)
  184. freeFunctionYield(funtion_st, inter);
  185. else
  186. popVarList(function_var);
  187. goto return_;
  188. }
  189. freeResult(result);
  190. functionSafeInterStatement(CALL_INTER_FUNCTIONSIG(funtion_st, function_var, result, function_value->father));
  191. gc_freeze(inter, var_list, function_var, false);
  192. funtion_st = function_value->value->data.function.function;
  193. if (yield_run)
  194. if (result->type == yield_return){
  195. updateFunctionYield(funtion_st, result->node);
  196. result->type = operation_return;
  197. }
  198. else
  199. freeFunctionYield(funtion_st, inter);
  200. else
  201. if (result->type == yield_return){
  202. newFunctionYield(funtion_st, result->node, function_var, inter);
  203. result->type = operation_return;
  204. }
  205. else
  206. popVarList(function_var);
  207. return_:
  208. gc_freeTmpLink(&function_value->gc_status);
  209. return result->type;
  210. }
  211. ResultType setDecoration(DecorationStatement *ds, LinkValue *value, INTER_FUNCTIONSIG_NOT_ST) {
  212. LinkValue *decall = NULL;
  213. Parameter *pt = NULL;
  214. setResultCore(result);
  215. gc_addTmpLink(&value->gc_status);
  216. for (PASS; ds != NULL; ds = ds->next){
  217. freeResult(result);
  218. if (operationSafeInterStatement(CALL_INTER_FUNCTIONSIG(ds->decoration, var_list, result, father)))
  219. break;
  220. pt = makeValueParameter(makeBaseLinkValueStatement(value, ds->decoration->line, ds->decoration->code_file));
  221. decall = result->value;
  222. result->value = NULL;
  223. freeResult(result);
  224. callBackCorePt(decall, pt, ds->decoration->line, ds->decoration->code_file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, father));
  225. gc_freeTmpLink(&decall->gc_status);
  226. freeParameter(pt, true);
  227. if (!run_continue(result))
  228. break;
  229. gc_freeTmpLink(&value->gc_status);
  230. value = result->value;
  231. gc_addTmpLink(&value->gc_status);
  232. }
  233. gc_freeTmpLink(&value->gc_status);
  234. return result->type;
  235. }