runoperation.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  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, iter, inter);
  206. else
  207. _func_ = findAttributes(inter->data.object_slice_del, false, iter, inter);
  208. if (_func_ != NULL){
  209. Argument *arg = NULL;
  210. gc_addTmpLink(&_func_->gc_status);
  211. arg = getArgument(pt, false, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  212. if (!CHECK_RESULT(result))
  213. goto dderror_;
  214. freeResult(result);
  215. callBackCore(_func_, arg, name->line, name->code_file, 0,
  216. CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  217. dderror_:
  218. gc_freeTmpLink(&_func_->gc_status);
  219. freeArgument(arg, true);
  220. }
  221. else
  222. setResultErrorSt(E_TypeException, OBJ_NOTSUPPORT(del(__down_del__/__slice_del__)), true, name, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  223. gc_freeTmpLink(&iter->gc_status);
  224. return result->type;
  225. }
  226. ResultType assOperation(INTER_FUNCTIONSIG) {
  227. LinkValue *value = NULL;
  228. setResultCore(result);
  229. if (st->u.operation.left->type == call_function){
  230. Statement *return_st = makeReturnStatement(st->u.operation.right, st->line, st->code_file);
  231. LinkValue *func = NULL;
  232. makeVMFunctionValue(return_st, st->u.operation.left->u.call_function.parameter, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  233. return_st->u.return_code.value = NULL;
  234. freeStatement(return_st);
  235. func = result->value;
  236. result->value = NULL;
  237. freeResult(result);
  238. assCore(st->u.operation.left->u.call_function.function, func, false, true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  239. gc_freeTmpLink(&func->gc_status);
  240. }
  241. else{
  242. if (operationSafeInterStatement(CALL_INTER_FUNCTIONSIG(st->u.operation.right, var_list, result, belong)))
  243. return result->type;
  244. value = result->value;
  245. freeResult(result);
  246. assCore(st->u.operation.left, value, false, false,
  247. CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  248. }
  249. return result->type;
  250. }
  251. ResultType assCore(Statement *name, LinkValue *value, bool check_aut, bool setting, INTER_FUNCTIONSIG_NOT_ST) {
  252. setResultCore(result);
  253. gc_addTmpLink(&value->gc_status);
  254. if (name->type == base_list && name->u.base_list.type == L_tuple)
  255. listAss(name, value, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  256. else if (name->type == slice_)
  257. downAss(name, value, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  258. else if (name->type == operation && (name->u.operation.OperationType == OPT_POINT || name->u.operation.OperationType == OPT_LINK))
  259. pointAss(name, value, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  260. else
  261. varAss(name, value, check_aut, setting, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  262. gc_freeTmpLink(&value->gc_status);
  263. return result->type;
  264. }
  265. ResultType varAss(Statement *name, LinkValue *value, bool check_aut, bool setting, INTER_FUNCTIONSIG_NOT_ST) {
  266. wchar_t *str_name = NULL;
  267. int int_times = 0;
  268. LinkValue *var_value = NULL;
  269. setResultCore(result);
  270. getVarInfo(&str_name, &int_times, CALL_INTER_FUNCTIONSIG(name, var_list, result, belong));
  271. if (!CHECK_RESULT(result)) {
  272. memFree(str_name);
  273. return result->type;
  274. }
  275. var_value = copyLinkValue(value, inter);
  276. if (name->aut != auto_aut)
  277. var_value->aut = name->aut;
  278. if (check_aut) {
  279. LinkValue *tmp = findFromVarList(str_name, int_times, read_var, CALL_INTER_FUNCTIONSIG_CORE(var_list));
  280. if (tmp != NULL && !checkAut(value->aut, tmp->aut, name->line, name->code_file, NULL, false, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong)))
  281. goto error_;
  282. } else if (name->aut != auto_aut){
  283. LinkValue *tmp = findFromVarList(str_name, int_times, read_var, CALL_INTER_FUNCTIONSIG_CORE(var_list));
  284. if (tmp != NULL)
  285. tmp->aut = name->aut;
  286. }
  287. addFromVarList(str_name, result->value, int_times, value, CALL_INTER_FUNCTIONSIG_CORE(var_list));
  288. if (setting) {
  289. freeResult(result);
  290. newObjectSetting(value, name->line, name->code_file, value, result, inter, var_list);
  291. if (CHECK_RESULT(result))
  292. goto error_;
  293. }
  294. freeResult(result);
  295. result->type = R_opt;
  296. result->value = value;
  297. gc_addTmpLink(&result->value->gc_status);
  298. error_:
  299. memFree(str_name);
  300. return result->type;
  301. }
  302. ResultType listAss(Statement *name, LinkValue *value, INTER_FUNCTIONSIG_NOT_ST) {
  303. Parameter *pt = NULL;
  304. Argument *call = NULL;
  305. Statement *tmp_st = makeBaseLinkValueStatement(value, name->line, name->code_file);
  306. setResultCore(result);
  307. pt = makeArgsParameter(tmp_st);
  308. call = getArgument(pt, false, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  309. if (!CHECK_RESULT(result))
  310. goto return_;
  311. freeResult(result);
  312. setParameterCore(name->line, name->code_file, call, name->u.base_list.list, var_list, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  313. if (CHECK_RESULT(result)){
  314. freeResult(result);
  315. makeListValue(call, name->line, name->code_file, L_tuple, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  316. }
  317. return_:
  318. freeArgument(call, false);
  319. freeParameter(pt, true);
  320. return result->type;
  321. }
  322. ResultType downAss(Statement *name, LinkValue *value, INTER_FUNCTIONSIG_NOT_ST) {
  323. LinkValue *iter = NULL;
  324. LinkValue *_func_ = NULL;
  325. Parameter *pt = name->u.slice_.index;
  326. setResultCore(result);
  327. if (operationSafeInterStatement(CALL_INTER_FUNCTIONSIG(name->u.slice_.element, var_list, result, belong)))
  328. return result->type;
  329. iter = result->value;
  330. result->value = NULL;
  331. freeResult(result);
  332. if (name->u.slice_.type == SliceType_down_)
  333. _func_ = findAttributes(inter->data.object_down_assignment, false, iter, inter);
  334. else
  335. _func_ = findAttributes(inter->data.object_slice_assignment, false, iter, inter);
  336. if (_func_ != NULL){
  337. Argument *arg = makeValueArgument(value);
  338. gc_addTmpLink(&_func_->gc_status);
  339. arg->next = getArgument(pt, false, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  340. if (!CHECK_RESULT(result))
  341. goto daerror_;
  342. freeResult(result);
  343. callBackCore(_func_, arg, name->line, name->code_file, 0,
  344. CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  345. daerror_:
  346. freeArgument(arg, true);
  347. gc_freeTmpLink(&_func_->gc_status);
  348. }
  349. else
  350. setResultErrorSt(E_TypeException, OBJ_NOTSUPPORT(assignment(__down_assignment__/__slice_assignment__)), true, name, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  351. gc_freeTmpLink(&iter->gc_status);
  352. return result->type;
  353. }
  354. ResultType pointAss(Statement *name, LinkValue *value, INTER_FUNCTIONSIG_NOT_ST) {
  355. Result left;
  356. Statement *right = name->u.operation.right;
  357. VarList *object = NULL;
  358. setResultCore(result);
  359. if (operationSafeInterStatement(CALL_INTER_FUNCTIONSIG(name->u.operation.left, var_list, result, belong)))
  360. return result->type;
  361. left = *result;
  362. setResultCore(result);
  363. object = name->u.operation.OperationType == OPT_POINT ? left.value->value->object.var : left.value->value->object.out_var;
  364. if (object == NULL) {
  365. setResultError(E_TypeException, OBJ_NOTSUPPORT(->/.), name->line, name->code_file, true,
  366. CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  367. goto return_;
  368. }
  369. gc_freeze(inter, var_list, object, true);
  370. if (right->type == OPERATION && (right->u.operation.OperationType == OPT_POINT || right->u.operation.OperationType == OPT_LINK))
  371. pointAss(name->u.operation.right, value, CALL_INTER_FUNCTIONSIG_NOT_ST(object, result, belong));
  372. else
  373. assCore(name->u.operation.right, value, true, false, CALL_INTER_FUNCTIONSIG_NOT_ST(object, result, belong));
  374. gc_freeze(inter, var_list, object, false);
  375. return_:
  376. freeResult(&left);
  377. return result->type;
  378. }
  379. ResultType getVar(INTER_FUNCTIONSIG, VarInfo var_info) {
  380. int int_times = 0;
  381. wchar_t *name = NULL;
  382. LinkValue *var;
  383. setResultCore(result);
  384. var_info(&name, &int_times, CALL_INTER_FUNCTIONSIG(st, var_list, result, belong));
  385. if (!CHECK_RESULT(result)) {
  386. memFree(name);
  387. return result->type;
  388. }
  389. freeResult(result);
  390. var = findFromVarList(name, int_times, get_var, CALL_INTER_FUNCTIONSIG_CORE(var_list));
  391. if (var == NULL) {
  392. wchar_t *message = memWidecat(L"Variable not found: ", name, false, false);
  393. setResultErrorSt(E_NameExceptiom, message, true, st, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  394. memFree(message);
  395. }
  396. else if (checkAut(st->aut, var->aut, st->line, st->code_file, NULL, true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong)))
  397. setResultOperationBase(result, var);
  398. memFree(name);
  399. return result->type;
  400. }
  401. ResultType getBaseValue(INTER_FUNCTIONSIG) {
  402. setResultCore(result);
  403. if (st->u.base_value.type == link_value) {
  404. result->value = st->u.base_value.value;
  405. result->type = R_opt;
  406. gc_addTmpLink(&result->value->gc_status);
  407. }
  408. else
  409. switch (st->u.base_value.type) {
  410. case number_str:
  411. makeNumberValue(wcstoll(st->u.base_value.str, NULL, 10), st->line, st->code_file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  412. break;
  413. case bool_true:
  414. makeBoolValue(true, st->line, st->code_file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  415. break;
  416. case bool_false:
  417. makeBoolValue(false, st->line, st->code_file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  418. break;
  419. case pass_value:
  420. makePassValue(st->line, st->code_file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  421. break;
  422. case null_value:
  423. useNoneValue(inter, result);
  424. break;
  425. default:
  426. makeStringValue(st->u.base_value.str, st->line, st->code_file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  427. break;
  428. }
  429. return result->type;
  430. }
  431. ResultType getList(INTER_FUNCTIONSIG) {
  432. Argument *at = NULL;
  433. Argument *at_tmp = NULL;
  434. setResultCore(result);
  435. at = getArgument(st->u.base_list.list, false, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  436. at_tmp = at;
  437. if (!CHECK_RESULT(result)){
  438. freeArgument(at_tmp, false);
  439. return result->type;
  440. }
  441. freeResult(result);
  442. makeListValue(at, st->line, st->code_file, st->u.base_list.type, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  443. freeArgument(at_tmp, false);
  444. return result->type;
  445. }
  446. ResultType getDict(INTER_FUNCTIONSIG) {
  447. Argument *at = NULL;
  448. setResultCore(result);
  449. at = getArgument(st->u.base_dict.dict, true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  450. if (!CHECK_RESULT(result)) {
  451. freeArgument(at, false);
  452. return result->type;
  453. }
  454. freeResult(result);
  455. Value *tmp_value = makeDictValue(at, true, st->line, st->code_file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  456. if (!CHECK_RESULT(result)) {
  457. freeArgument(at, false);
  458. return result->type;
  459. }
  460. freeResult(result);
  461. LinkValue *value = makeLinkValue(tmp_value, belong, inter);
  462. setResultOperation(result, value);
  463. freeArgument(at, false);
  464. return result->type;
  465. }
  466. ResultType setDefault(INTER_FUNCTIONSIG){
  467. enum DefaultType type = st->u.default_var.default_type;
  468. int base = 0; // 用于nonlocal和global
  469. setResultCore(result);
  470. if (type == global_)
  471. for (VarList *tmp = var_list; tmp->next != NULL; tmp = tmp->next)
  472. base++;
  473. else if (type == nonlocal_)
  474. base = 1;
  475. for (Parameter *pt = st->u.default_var.var; pt != NULL; pt = pt->next){
  476. wchar_t *name = NULL;
  477. int times = 0;
  478. freeResult(result);
  479. getVarInfo(&name, &times, CALL_INTER_FUNCTIONSIG(pt->data.value, var_list, result, belong));
  480. if (!CHECK_RESULT(result))
  481. break;
  482. if (type != default_)
  483. times = base;
  484. var_list->default_var = connectDefaultVar(var_list->default_var, name, times);
  485. memFree(name);
  486. }
  487. return result->type;
  488. }
  489. bool getLeftRightValue(Result *left, Result *right, INTER_FUNCTIONSIG){
  490. if (operationSafeInterStatement(CALL_INTER_FUNCTIONSIG(st->u.operation.left, var_list, result, belong)) || result->value->value->type == V_none)
  491. return true;
  492. *left = *result;
  493. setResultCore(result);
  494. if (operationSafeInterStatement(CALL_INTER_FUNCTIONSIG(st->u.operation.right, var_list, result, belong)) || result->value->value->type == V_none)
  495. return true;
  496. *right = *result;
  497. setResultCore(result);
  498. return false;
  499. }
  500. ResultType operationCore(INTER_FUNCTIONSIG, wchar_t *name) {
  501. Result left;
  502. Result right;
  503. LinkValue *_func_ = NULL;
  504. setResultCore(&left);
  505. setResultCore(&right);
  506. if (getLeftRightValue(&left, &right, CALL_INTER_FUNCTIONSIG(st, var_list, result, belong)))
  507. return result->type;
  508. _func_ = findAttributes(name, false, left.value, inter);
  509. if (_func_ != NULL){
  510. Argument *arg = makeValueArgument(right.value);
  511. gc_addTmpLink(&_func_->gc_status);
  512. callBackCore(_func_, arg, st->line, st->code_file, 0,
  513. CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  514. gc_freeTmpLink(&_func_->gc_status);
  515. freeArgument(arg, true);
  516. }
  517. else {
  518. wchar_t *message = memWidecat(L"Object not support ", name, false, false);
  519. setResultErrorSt(E_TypeException, message, true, st, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  520. memFree(message);
  521. }
  522. freeResult(&left);
  523. freeResult(&right);
  524. return result->type;
  525. }