runoperation.c 22 KB

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