runoperation.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  1. #include "__run.h"
  2. static bool getLeftRightValue(Result *left, Result *right, INTER_FUNCTIONSIG);
  3. static ResultType operationCore(INTER_FUNCTIONSIG, wchar_t *name);
  4. ResultType assOperation(INTER_FUNCTIONSIG);
  5. ResultType pointOperation(INTER_FUNCTIONSIG);
  6. ResultType blockOperation(INTER_FUNCTIONSIG);
  7. /**
  8. * operation的整体操作
  9. * @param st
  10. * @param inter
  11. * @param var_list
  12. * @return
  13. */
  14. ResultType operationStatement(INTER_FUNCTIONSIG) {
  15. setResultCore(result);
  16. switch (st->u.operation.OperationType) {
  17. case OPT_ADD:
  18. operationCore(CALL_INTER_FUNCTIONSIG(st, var_list, result, belong), inter->data.object_add);
  19. break;
  20. case OPT_SUB:
  21. operationCore(CALL_INTER_FUNCTIONSIG(st, var_list, result, belong), inter->data.object_sub);
  22. break;
  23. case OPT_MUL:
  24. operationCore(CALL_INTER_FUNCTIONSIG(st, var_list, result, belong), inter->data.object_mul);
  25. break;
  26. case OPT_DIV:
  27. operationCore(CALL_INTER_FUNCTIONSIG(st, var_list, result, belong), inter->data.object_div);
  28. break;
  29. case OPT_ASS:
  30. assOperation(CALL_INTER_FUNCTIONSIG(st, var_list, result, belong));
  31. break;
  32. case OPT_LINK:
  33. case OPT_POINT:
  34. pointOperation(CALL_INTER_FUNCTIONSIG(st, var_list, result, belong));
  35. break;
  36. case OPT_BLOCK:
  37. blockOperation(CALL_INTER_FUNCTIONSIG(st, var_list, result, belong));
  38. break;
  39. default:
  40. setResult(result, inter);
  41. break;
  42. }
  43. return result->type;
  44. }
  45. static void updateBlockYield(Statement *block_st, Statement *node){
  46. block_st->info.node = node->type == yield_code ? node->next : node;
  47. block_st->info.have_info = true;
  48. }
  49. static void newBlockYield(Statement *block_st, Statement *node, VarList *new_var, Inter *inter){
  50. new_var->next = NULL;
  51. gc_freeze(inter, new_var, NULL, true);
  52. block_st->info.var_list = new_var;
  53. block_st->info.node = node->type == yield_code ? node->next : node;
  54. block_st->info.have_info = true;
  55. }
  56. static void setBlockResult(Statement *st, bool yield_run, Result *result, INTER_FUNCTIONSIG_CORE) {
  57. if (yield_run) {
  58. if (result->type == R_yield){
  59. updateBlockYield(st, result->node);
  60. result->type = R_opt;
  61. result->is_yield = true;
  62. }
  63. else
  64. freeRunInfo(st);
  65. }
  66. else {
  67. if (result->type == R_yield){
  68. newBlockYield(st, result->node, var_list, inter);
  69. result->type = R_opt;
  70. result->is_yield = true;
  71. }
  72. else
  73. popVarList(var_list);
  74. }
  75. }
  76. ResultType blockOperation(INTER_FUNCTIONSIG) {
  77. Statement *info_st = st->u.operation.left;
  78. bool yield_run;
  79. if ((yield_run = popYieldVarList(st, &var_list, var_list, inter)))
  80. info_st = st->info.node;
  81. blockSafeInterStatement(CALL_INTER_FUNCTIONSIG(info_st, var_list, result, belong));
  82. if (result->type == R_error)
  83. return result->type;
  84. else
  85. setBlockResult(st, yield_run, result, CALL_INTER_FUNCTIONSIG_CORE(var_list));
  86. if (CHECK_RESULT(result) && st->aut != auto_aut)
  87. result->value->aut = st->aut;
  88. return result->type;
  89. }
  90. ResultType pointOperation(INTER_FUNCTIONSIG) {
  91. LinkValue *left;
  92. VarList *object = NULL;
  93. setResultCore(result);
  94. if (operationSafeInterStatement(CALL_INTER_FUNCTIONSIG(st->u.operation.left, var_list, result, belong)) || result->value->value->type == V_none)
  95. return result->type;
  96. left = result->value;
  97. result->value = NULL;
  98. freeResult(result);
  99. if (st->u.operation.OperationType == OPT_POINT)
  100. object = left->value->object.var;
  101. else if (st->u.operation.OperationType == OPT_LINK)
  102. object = left->value->object.out_var;
  103. if (object == NULL) {
  104. setResultError(E_TypeException, OBJ_NOTSUPPORT(->/.), st->line, st->code_file, true,
  105. CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  106. goto return_;
  107. }
  108. gc_freeze(inter, var_list, object, true);
  109. operationSafeInterStatement(CALL_INTER_FUNCTIONSIG(st->u.operation.right, object, result, left));
  110. if (!CHECK_RESULT(result) || !checkAut(left->aut, result->value->aut, st->line, st->code_file, NULL, false, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong)))
  111. PASS;
  112. else if (result->value->belong == NULL || result->value->belong->value != left->value && checkAttribution(left->value, result->value->belong->value))
  113. result->value->belong = left;
  114. gc_freeze(inter, var_list, object, false);
  115. return_:
  116. gc_freeTmpLink(&left->gc_status);
  117. return result->type;
  118. }
  119. ResultType delOperation(INTER_FUNCTIONSIG) {
  120. Statement *var;
  121. setResultCore(result);
  122. var = st->u.del_.var;
  123. delCore(var, false, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  124. return result->type;
  125. }
  126. ResultType delCore(Statement *name, bool check_aut, INTER_FUNCTIONSIG_NOT_ST) {
  127. setResultCore(result);
  128. if (name->type == base_list && name->u.base_list.type == L_tuple)
  129. listDel(name, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  130. else if (name->type == slice_)
  131. downDel(name, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  132. else if (name->type == operation && (name->u.operation.OperationType == OPT_POINT || name->u.operation.OperationType == OPT_LINK))
  133. pointDel(name, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  134. else
  135. varDel(name, check_aut, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  136. return result->type;
  137. }
  138. ResultType listDel(Statement *name, INTER_FUNCTIONSIG_NOT_ST) {
  139. setResultCore(result);
  140. for (Parameter *pt = name->u.base_list.list; pt != NULL; pt = pt->next){
  141. delCore(pt->data.value, false, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  142. freeResult(result);
  143. }
  144. setResultBase(result, inter);
  145. return result->type;
  146. }
  147. ResultType varDel(Statement *name, bool check_aut, INTER_FUNCTIONSIG_NOT_ST) {
  148. wchar_t *str_name = NULL;
  149. int int_times = 0;
  150. setResultCore(result);
  151. getVarInfo(&str_name, &int_times, CALL_INTER_FUNCTIONSIG(name, var_list, result, belong));
  152. if (!CHECK_RESULT(result)) {
  153. memFree(str_name);
  154. return result->type;
  155. }
  156. if (check_aut) {
  157. LinkValue *tmp = findFromVarList(str_name, int_times, read_var, CALL_INTER_FUNCTIONSIG_CORE(var_list));
  158. freeResult(result);
  159. if (tmp != NULL && !checkAut(name->aut, tmp->aut, name->line, name->code_file, NULL, false, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong))) {
  160. goto return_;
  161. }
  162. }
  163. findFromVarList(str_name, int_times, del_var, CALL_INTER_FUNCTIONSIG_CORE(var_list));
  164. setResult(result, inter);
  165. return_:
  166. memFree(str_name);
  167. return result->type;
  168. }
  169. ResultType pointDel(Statement *name, INTER_FUNCTIONSIG_NOT_ST) {
  170. Result left;
  171. VarList *object = NULL;
  172. Statement *right = name->u.operation.right;
  173. setResultCore(result);
  174. if (operationSafeInterStatement(CALL_INTER_FUNCTIONSIG(name->u.operation.left, var_list, result, belong)))
  175. return result->type;
  176. left = *result;
  177. setResultCore(result);
  178. object = name->u.operation.OperationType == OPT_POINT ? left.value->value->object.var : left.value->value->object.out_var;
  179. if (object == NULL) {
  180. setResultError(E_TypeException, OBJ_NOTSUPPORT(->/.), name->line, name->code_file, true,
  181. CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  182. goto return_;
  183. }
  184. gc_freeze(inter, var_list, object, true);
  185. if (right->type == OPERATION && (right->u.operation.OperationType == OPT_POINT || right->u.operation.OperationType == OPT_LINK))
  186. pointDel(name->u.operation.right, CALL_INTER_FUNCTIONSIG_NOT_ST(object, result, belong));
  187. else
  188. delCore(name->u.operation.right, true, CALL_INTER_FUNCTIONSIG_NOT_ST(object, result, belong));
  189. gc_freeze(inter, var_list, object, false);
  190. return_:
  191. freeResult(&left);
  192. return result->type;
  193. }
  194. ResultType downDel(Statement *name, INTER_FUNCTIONSIG_NOT_ST) {
  195. LinkValue *iter = NULL;
  196. LinkValue *_func_ = NULL;
  197. Parameter *pt = name->u.slice_.index;
  198. setResultCore(result);
  199. if (operationSafeInterStatement(CALL_INTER_FUNCTIONSIG(name->u.slice_.element, var_list, result, belong)))
  200. return result->type;
  201. iter = result->value;
  202. result->value = NULL;
  203. freeResult(result);
  204. if (name->u.slice_.type == SliceType_down_)
  205. _func_ = findAttributes(inter->data.object_down_del, false, 0, "sys", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, iter));
  206. else
  207. _func_ = findAttributes(inter->data.object_slice_del, false, 0, "sys", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, iter));
  208. if (!CHECK_RESULT(result))
  209. goto return_;
  210. freeResult(result);
  211. if (_func_ != NULL){
  212. Argument *arg = NULL;
  213. gc_addTmpLink(&_func_->gc_status);
  214. arg = getArgument(pt, false, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  215. if (!CHECK_RESULT(result))
  216. goto dderror_;
  217. freeResult(result);
  218. callBackCore(_func_, arg, name->line, name->code_file, 0,
  219. CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  220. dderror_:
  221. gc_freeTmpLink(&_func_->gc_status);
  222. freeArgument(arg, true);
  223. }
  224. else
  225. setResultErrorSt(E_TypeException, OBJ_NOTSUPPORT(del(__down_del__/__slice_del__)), true, name, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  226. return_:
  227. gc_freeTmpLink(&iter->gc_status);
  228. return result->type;
  229. }
  230. ResultType assOperation(INTER_FUNCTIONSIG) {
  231. LinkValue *value = NULL;
  232. setResultCore(result);
  233. if (st->u.operation.left->type == call_function){
  234. Statement *return_st = makeReturnStatement(st->u.operation.right, st->line, st->code_file);
  235. LinkValue *func = NULL;
  236. makeVMFunctionValue(return_st, st->u.operation.left->u.call_function.parameter, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  237. return_st->u.return_code.value = NULL;
  238. freeStatement(return_st);
  239. func = result->value;
  240. result->value = NULL;
  241. freeResult(result);
  242. assCore(st->u.operation.left->u.call_function.function, func, false, true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  243. gc_freeTmpLink(&func->gc_status);
  244. }
  245. else{
  246. if (operationSafeInterStatement(CALL_INTER_FUNCTIONSIG(st->u.operation.right, var_list, result, belong)))
  247. return result->type;
  248. value = result->value;
  249. freeResult(result);
  250. assCore(st->u.operation.left, value, false, false,
  251. CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  252. }
  253. return result->type;
  254. }
  255. ResultType assCore(Statement *name, LinkValue *value, bool check_aut, bool setting, INTER_FUNCTIONSIG_NOT_ST) {
  256. setResultCore(result);
  257. gc_addTmpLink(&value->gc_status);
  258. if (name->type == base_list && name->u.base_list.type == L_tuple)
  259. listAss(name, value, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  260. else if (name->type == slice_)
  261. downAss(name, value, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  262. else if (name->type == operation && (name->u.operation.OperationType == OPT_POINT || name->u.operation.OperationType == OPT_LINK))
  263. pointAss(name, value, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  264. else
  265. varAss(name, value, check_aut, setting, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  266. gc_freeTmpLink(&value->gc_status);
  267. return result->type;
  268. }
  269. ResultType varAss(Statement *name, LinkValue *value, bool check_aut, bool setting, INTER_FUNCTIONSIG_NOT_ST) {
  270. wchar_t *str_name = NULL;
  271. int int_times = 0;
  272. LinkValue *name_ = NULL;
  273. LinkValue *tmp;
  274. bool run = name->type == base_var ? name->u.base_var.run : name->type == base_svar ? name->u.base_svar.run : false;
  275. setResultCore(result);
  276. getVarInfo(&str_name, &int_times, CALL_INTER_FUNCTIONSIG(name, var_list, result, belong));
  277. if (!CHECK_RESULT(result)) {
  278. memFree(str_name);
  279. return result->type;
  280. }
  281. name_ = result->value;
  282. result->value = NULL;
  283. freeResult(result);
  284. if (name->aut != auto_aut)
  285. value->aut = name->aut;
  286. tmp = findFromVarList(str_name, int_times, read_var, CALL_INTER_FUNCTIONSIG_CORE(var_list));
  287. if (check_aut) {
  288. if (tmp != NULL && !checkAut(value->aut, tmp->aut, name->line, name->code_file, NULL, false, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong)))
  289. goto error_;
  290. } else if (name->aut != auto_aut && tmp != NULL)
  291. tmp->aut = value->aut;
  292. if (tmp == NULL || !run || !setVarFunc(tmp, value, name->line, name->code_file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong)))
  293. addFromVarList(str_name, name_, int_times, value, CALL_INTER_FUNCTIONSIG_CORE(var_list));
  294. if (CHECK_RESULT(result))
  295. goto error_;
  296. if (setting) {
  297. freeResult(result);
  298. newObjectSetting(value, name->line, name->code_file, value, result, inter, var_list);
  299. if (CHECK_RESULT(result))
  300. goto error_;
  301. }
  302. freeResult(result);
  303. result->type = R_opt;
  304. result->value = value;
  305. gc_addTmpLink(&result->value->gc_status);
  306. error_:
  307. gc_freeTmpLink(&name_->gc_status);
  308. memFree(str_name);
  309. return result->type;
  310. }
  311. ResultType listAss(Statement *name, LinkValue *value, INTER_FUNCTIONSIG_NOT_ST) {
  312. Parameter *pt = NULL;
  313. Argument *call = NULL;
  314. Statement *tmp_st = makeBaseLinkValueStatement(value, name->line, name->code_file);
  315. setResultCore(result);
  316. pt = makeArgsParameter(tmp_st);
  317. call = getArgument(pt, false, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  318. if (!CHECK_RESULT(result))
  319. goto return_;
  320. freeResult(result);
  321. setParameterCore(name->line, name->code_file, call, name->u.base_list.list, var_list, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  322. if (CHECK_RESULT(result)){
  323. freeResult(result);
  324. makeListValue(call, name->line, name->code_file, L_tuple, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  325. }
  326. return_:
  327. freeArgument(call, false);
  328. freeParameter(pt, true);
  329. return result->type;
  330. }
  331. ResultType downAss(Statement *name, LinkValue *value, INTER_FUNCTIONSIG_NOT_ST) {
  332. LinkValue *iter = NULL;
  333. LinkValue *_func_ = NULL;
  334. Parameter *pt = name->u.slice_.index;
  335. setResultCore(result);
  336. if (operationSafeInterStatement(CALL_INTER_FUNCTIONSIG(name->u.slice_.element, var_list, result, belong)))
  337. return result->type;
  338. iter = result->value;
  339. result->value = NULL;
  340. freeResult(result);
  341. if (name->u.slice_.type == SliceType_down_)
  342. _func_ = findAttributes(inter->data.object_down_assignment, false, 0, "sys", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, iter));
  343. else
  344. _func_ = findAttributes(inter->data.object_slice_assignment, false, 0, "sys", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, iter));
  345. if (!CHECK_RESULT(result))
  346. goto return_;
  347. freeResult(result);
  348. if (_func_ != NULL){
  349. Argument *arg = makeValueArgument(value);
  350. gc_addTmpLink(&_func_->gc_status);
  351. arg->next = getArgument(pt, false, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  352. if (!CHECK_RESULT(result))
  353. goto daerror_;
  354. freeResult(result);
  355. callBackCore(_func_, arg, name->line, name->code_file, 0, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  356. daerror_:
  357. freeArgument(arg, true);
  358. gc_freeTmpLink(&_func_->gc_status);
  359. }
  360. else
  361. setResultErrorSt(E_TypeException, OBJ_NOTSUPPORT(assignment(__down_assignment__/__slice_assignment__)), true, name, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  362. return_:
  363. gc_freeTmpLink(&iter->gc_status);
  364. return result->type;
  365. }
  366. ResultType pointAss(Statement *name, LinkValue *value, INTER_FUNCTIONSIG_NOT_ST) {
  367. Result left;
  368. Statement *right = name->u.operation.right;
  369. VarList *object = NULL;
  370. setResultCore(result);
  371. if (operationSafeInterStatement(CALL_INTER_FUNCTIONSIG(name->u.operation.left, var_list, result, belong)))
  372. return result->type;
  373. left = *result;
  374. setResultCore(result);
  375. object = name->u.operation.OperationType == OPT_POINT ? left.value->value->object.var : left.value->value->object.out_var;
  376. if (object == NULL) {
  377. setResultError(E_TypeException, OBJ_NOTSUPPORT(->/.), name->line, name->code_file, true,
  378. CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  379. goto return_;
  380. }
  381. gc_freeze(inter, var_list, object, true);
  382. if (right->type == OPERATION && (right->u.operation.OperationType == OPT_POINT || right->u.operation.OperationType == OPT_LINK))
  383. pointAss(name->u.operation.right, value, CALL_INTER_FUNCTIONSIG_NOT_ST(object, result, belong));
  384. else
  385. assCore(name->u.operation.right, value, true, false, CALL_INTER_FUNCTIONSIG_NOT_ST(object, result, belong));
  386. gc_freeze(inter, var_list, object, false);
  387. return_:
  388. freeResult(&left);
  389. return result->type;
  390. }
  391. ResultType getVar(INTER_FUNCTIONSIG, VarInfo var_info) {
  392. int int_times = 0;
  393. wchar_t *name = NULL;
  394. LinkValue *var;
  395. setResultCore(result);
  396. var_info(&name, &int_times, CALL_INTER_FUNCTIONSIG(st, var_list, result, belong));
  397. if (!CHECK_RESULT(result)) {
  398. memFree(name);
  399. return result->type;
  400. }
  401. freeResult(result);
  402. var = findFromVarList(name, int_times, get_var, CALL_INTER_FUNCTIONSIG_CORE(var_list));
  403. if (var == NULL) {
  404. wchar_t *message = memWidecat(L"Variable not found: ", name, false, false);
  405. setResultErrorSt(E_NameExceptiom, message, true, st, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  406. memFree(message);
  407. }
  408. else if (checkAut(st->aut, var->aut, st->line, st->code_file, NULL, true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong))) {
  409. bool run = st->type == base_var ? st->u.base_var.run : st->type == base_svar ? st->u.base_svar.run : false;
  410. if (!run || !runVarFunc(var, st->line, st->code_file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong)))
  411. setResultOperationBase(result, var);
  412. }
  413. memFree(name);
  414. return result->type;
  415. }
  416. ResultType getBaseValue(INTER_FUNCTIONSIG) {
  417. setResultCore(result);
  418. if (st->u.base_value.type == link_value) {
  419. result->value = st->u.base_value.value;
  420. result->type = R_opt;
  421. gc_addTmpLink(&result->value->gc_status);
  422. }
  423. else
  424. switch (st->u.base_value.type) {
  425. case number_str:
  426. makeNumberValue(wcstoll(st->u.base_value.str, NULL, 10), st->line, st->code_file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  427. break;
  428. case bool_true:
  429. makeBoolValue(true, st->line, st->code_file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  430. break;
  431. case bool_false:
  432. makeBoolValue(false, st->line, st->code_file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  433. break;
  434. case pass_value:
  435. makePassValue(st->line, st->code_file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  436. break;
  437. case null_value:
  438. useNoneValue(inter, result);
  439. break;
  440. default:
  441. makeStringValue(st->u.base_value.str, st->line, st->code_file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  442. break;
  443. }
  444. return result->type;
  445. }
  446. ResultType getList(INTER_FUNCTIONSIG) {
  447. Argument *at = NULL;
  448. Argument *at_tmp = NULL;
  449. setResultCore(result);
  450. at = getArgument(st->u.base_list.list, false, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  451. at_tmp = at;
  452. if (!CHECK_RESULT(result)){
  453. freeArgument(at_tmp, false);
  454. return result->type;
  455. }
  456. freeResult(result);
  457. makeListValue(at, st->line, st->code_file, st->u.base_list.type, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  458. freeArgument(at_tmp, false);
  459. return result->type;
  460. }
  461. ResultType getDict(INTER_FUNCTIONSIG) {
  462. Argument *at = NULL;
  463. setResultCore(result);
  464. at = getArgument(st->u.base_dict.dict, true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  465. if (!CHECK_RESULT(result)) {
  466. freeArgument(at, false);
  467. return result->type;
  468. }
  469. freeResult(result);
  470. Value *tmp_value = makeDictValue(at, true, st->line, st->code_file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  471. if (!CHECK_RESULT(result)) {
  472. freeArgument(at, false);
  473. return result->type;
  474. }
  475. freeResult(result);
  476. LinkValue *value = makeLinkValue(tmp_value, belong, inter);
  477. setResultOperation(result, value);
  478. freeArgument(at, false);
  479. return result->type;
  480. }
  481. ResultType setDefault(INTER_FUNCTIONSIG){
  482. enum DefaultType type = st->u.default_var.default_type;
  483. int base = 0; // 用于nonlocal和global
  484. setResultCore(result);
  485. if (type == global_)
  486. for (VarList *tmp = var_list; tmp->next != NULL; tmp = tmp->next)
  487. base++;
  488. else if (type == nonlocal_)
  489. base = 1;
  490. for (Parameter *pt = st->u.default_var.var; pt != NULL; pt = pt->next){
  491. wchar_t *name = NULL;
  492. int times = 0;
  493. freeResult(result);
  494. getVarInfo(&name, &times, CALL_INTER_FUNCTIONSIG(pt->data.value, var_list, result, belong));
  495. if (!CHECK_RESULT(result))
  496. break;
  497. if (type != default_)
  498. times = base;
  499. var_list->default_var = connectDefaultVar(var_list->default_var, name, times);
  500. memFree(name);
  501. }
  502. return result->type;
  503. }
  504. bool getLeftRightValue(Result *left, Result *right, INTER_FUNCTIONSIG){
  505. if (operationSafeInterStatement(CALL_INTER_FUNCTIONSIG(st->u.operation.left, var_list, result, belong)) || result->value->value->type == V_none)
  506. return true;
  507. *left = *result;
  508. setResultCore(result);
  509. if (operationSafeInterStatement(CALL_INTER_FUNCTIONSIG(st->u.operation.right, var_list, result, belong)) || result->value->value->type == V_none)
  510. return true;
  511. *right = *result;
  512. setResultCore(result);
  513. return false;
  514. }
  515. ResultType operationCore(INTER_FUNCTIONSIG, wchar_t *name) {
  516. Result left;
  517. Result right;
  518. LinkValue *_func_ = NULL;
  519. setResultCore(&left);
  520. setResultCore(&right);
  521. if (getLeftRightValue(&left, &right, CALL_INTER_FUNCTIONSIG(st, var_list, result, belong))) // 不需要释放result
  522. return result->type;
  523. _func_ = findAttributes(name, false, 0, "sys", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, left.value));
  524. if (!CHECK_RESULT(result))
  525. goto return_;
  526. freeResult(result);
  527. if (_func_ != NULL){
  528. Argument *arg = makeValueArgument(right.value);
  529. gc_addTmpLink(&_func_->gc_status);
  530. callBackCore(_func_, arg, st->line, st->code_file, 0, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  531. gc_freeTmpLink(&_func_->gc_status);
  532. freeArgument(arg, true);
  533. }
  534. else {
  535. wchar_t *message = memWidecat(L"Object not support ", name, false, false);
  536. setResultErrorSt(E_TypeException, message, true, st, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  537. memFree(message);
  538. }
  539. return_:
  540. freeResult(&left);
  541. freeResult(&right);
  542. return result->type;
  543. }