runcall.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. #include "__run.h"
  2. ResultType setClass(FUNC) {
  3. Argument *call = NULL;
  4. LinkValue *tmp = NULL;
  5. Inherit *class_inherit = NULL;
  6. setResultCore(result);
  7. call = getArgument(st->u.set_class.father, false, CNEXT_NT);
  8. if (!CHECK_RESULT(result))
  9. return result->type;
  10. class_inherit = setFather(call);
  11. freeArgument(call, false);
  12. tmp = makeLinkValue(makeClassValue(var_list, inter, class_inherit), belong, auto_aut, inter);
  13. gc_freeTmpLink(&tmp->value->gc_status);
  14. gc_addTmpLink(&tmp->gc_status);
  15. freeResult(result);
  16. {
  17. enum FunctionPtType pt_type_bak = inter->data.default_pt_type;
  18. VarList *var_backup = tmp->value->object.var->next;
  19. inter->data.default_pt_type = object_free_;
  20. tmp->value->object.var->next = var_list;
  21. // 运行类定义的时候需要调整belong
  22. functionSafeInterStatement(CFUNC(st->u.set_class.st, tmp->value->object.var, result, tmp));
  23. tmp->value->object.var->next = var_backup;
  24. inter->data.default_pt_type = pt_type_bak;
  25. if (result->type != R_yield && !CHECK_RESULT(result))
  26. goto error_;
  27. freeResult(result);
  28. }
  29. if (st->u.set_class.decoration != NULL){
  30. setDecoration(st->u.set_class.decoration, tmp, CNEXT_NT);
  31. if (!CHECK_RESULT(result))
  32. goto error_;
  33. gc_freeTmpLink(&tmp->gc_status);
  34. GET_RESULT(tmp, result);
  35. }
  36. assCore(st->u.set_class.name, tmp, false, true, CNEXT_NT);
  37. if (CHECK_RESULT(result))
  38. setResult(result, inter);
  39. gc_freeTmpLink(&tmp->gc_status);
  40. return result->type;
  41. error_:
  42. gc_freeTmpLink(&tmp->gc_status);
  43. setResultErrorSt(E_BaseException, NULL, false, st, CNEXT_NT);
  44. return result->type;
  45. }
  46. ResultType setFunction(FUNC) {
  47. LinkValue *func = NULL;
  48. setResultCore(result);
  49. makeVMFunctionValue(st->u.set_function.function, st->u.set_function.parameter, CNEXT_NT);
  50. if (!CHECK_RESULT(result))
  51. return result->type;
  52. GET_RESULT(func, result);
  53. {
  54. enum FunctionPtType pt_type_bak = inter->data.default_pt_type;
  55. VarList *var_backup = func->value->object.var->next;
  56. inter->data.default_pt_type = object_free_;
  57. func->value->object.var->next = var_list;
  58. // 运行函数初始化模块的时候需要调整belong
  59. functionSafeInterStatement(CFUNC(st->u.set_function.first_do, func->value->object.var, result, func));
  60. func->value->object.var->next = var_backup;
  61. inter->data.default_pt_type = pt_type_bak;
  62. if (result->type != R_yield && !CHECK_RESULT(result))
  63. goto error_;
  64. freeResult(result);
  65. }
  66. if (st->u.set_function.decoration != NULL){
  67. setDecoration(st->u.set_function.decoration, func, CNEXT_NT);
  68. if (!CHECK_RESULT(result))
  69. goto error_;
  70. gc_freeTmpLink(&func->gc_status);
  71. GET_RESULT(func, result);
  72. }
  73. assCore(st->u.set_function.name, func, false, true, CNEXT_NT);
  74. if (CHECK_RESULT(result)) // 若没有出现错误则设定none
  75. setResult(result, inter);
  76. error_:
  77. gc_freeTmpLink(&func->gc_status);
  78. return result->type;
  79. }
  80. ResultType setLambda(FUNC) {
  81. Statement *resunt_st = NULL;
  82. setResultCore(result);
  83. resunt_st = makeReturnStatement(st->u.base_lambda.function, st->line, st->code_file);
  84. makeVMFunctionValue(resunt_st, st->u.base_lambda.parameter, CNEXT_NT);
  85. resunt_st->u.return_code.value = NULL;
  86. freeStatement(resunt_st);
  87. return result->type;
  88. }
  89. ResultType elementSlice(FUNC) {
  90. LinkValue *element = NULL;
  91. LinkValue *_func_ = NULL;
  92. wchar_t *func_name = NULL;
  93. setResultCore(result);
  94. if (operationSafeInterStatement(CFUNC(st->u.slice_.element, var_list, result, belong)))
  95. return result->type;
  96. GET_RESULT(element, result);
  97. func_name = st->u.slice_.type == SliceType_down_ ? inter->data.mag_func[M_DOWN] : inter->data.mag_func[M_SLICE];
  98. _func_ = findAttributes(func_name, false, LINEFILE, true, CFUNC_NT(var_list, result, element));
  99. if (!CHECK_RESULT(result))
  100. goto return_;
  101. freeResult(result);
  102. if (_func_ != NULL){
  103. gc_addTmpLink(&_func_->gc_status);
  104. callBackCorePt(_func_, st->u.slice_.index, st->line, st->code_file, CNEXT_NT);
  105. gc_freeTmpLink(&_func_->gc_status);
  106. }
  107. else
  108. setResultErrorSt(E_TypeException, OBJ_NOTSUPPORT(__down__/__slice__), true, st, CNEXT_NT);
  109. return_:
  110. gc_freeTmpLink(&element->gc_status);
  111. return result->type;
  112. }
  113. ResultType callBack(FUNC) {
  114. LinkValue *func = NULL;
  115. setResultCore(result);
  116. if (operationSafeInterStatement(CFUNC(st->u.call_function.function, var_list, result, belong)))
  117. return result->type;
  118. GET_RESULT(func, result);
  119. callBackCorePt(func, st->u.call_function.parameter, st->line, st->code_file, CNEXT_NT);
  120. setResultErrorSt(E_BaseException, NULL, false, st, CNEXT_NT); // 显式执行函数才进行错误回溯
  121. gc_freeTmpLink(&func->gc_status);
  122. return result->type;
  123. }
  124. ResultType callBackCorePt(LinkValue *function_value, Parameter *pt, long line, char *file, FUNC_NT) {
  125. Argument *arg = NULL;
  126. int pt_sep =1;
  127. bool sep = false;
  128. setResultCore(result);
  129. gc_addTmpLink(&function_value->gc_status);
  130. arg = getArgument(pt, false, CNEXT_NT);
  131. if (!CHECK_RESULT(result))
  132. goto return_;
  133. for (Parameter *tmp = pt; tmp != NULL; tmp = tmp->next, pt_sep++) {
  134. if (tmp->data.is_sep) {
  135. sep = true;
  136. break;
  137. }
  138. }
  139. freeResult(result);
  140. callBackCore(function_value, arg, line, file, sep ? pt_sep : 0, CNEXT_NT);
  141. return_:
  142. gc_freeTmpLink(&function_value->gc_status);
  143. freeArgument(arg, false);
  144. return result->type;
  145. }
  146. static ResultType callClass(LinkValue *class_value, Argument *arg, fline line, char *file, int pt_sep, FUNC_NT) {
  147. LinkValue *_new_;
  148. setResultCore(result);
  149. gc_addTmpLink(&class_value->gc_status);
  150. _new_ = findAttributes(inter->data.mag_func[M_NEW], false, LINEFILE, true, CFUNC_NT(var_list, result, class_value));
  151. if (!CHECK_RESULT(result))
  152. goto return_;
  153. freeResult(result);
  154. if (_new_ != NULL){
  155. gc_addTmpLink(&_new_->gc_status);
  156. callBackCore(_new_, arg, line, file, pt_sep, CNEXT_NT);
  157. gc_freeTmpLink(&_new_->gc_status);
  158. }
  159. else
  160. setResultError(E_TypeException, OBJ_NOTSUPPORT(new(__new__)), line, file, true, CNEXT_NT);
  161. return_:
  162. gc_freeTmpLink(&class_value->gc_status);
  163. return result->type;
  164. }
  165. static ResultType callObject(LinkValue *object_value, Argument *arg, fline line, char *file, int pt_sep, FUNC_NT) {
  166. LinkValue *_call_;
  167. setResultCore(result);
  168. gc_addTmpLink(&object_value->gc_status);
  169. _call_ = findAttributes(inter->data.mag_func[M_CALL], false, LINEFILE, true, CFUNC_NT(var_list, result, object_value));
  170. if (!CHECK_RESULT(result))
  171. goto return_;
  172. freeResult(result);
  173. if (_call_ != NULL){
  174. gc_addTmpLink(&_call_->gc_status);
  175. callBackCore(_call_, arg, line, file, pt_sep, CNEXT_NT);
  176. gc_freeTmpLink(&_call_->gc_status);
  177. }
  178. else
  179. setResultError(E_TypeException, OBJ_NOTSUPPORT(call(__call__)), line, file, true, CNEXT_NT);
  180. return_:
  181. gc_freeTmpLink(&object_value->gc_status);
  182. return result->type;
  183. }
  184. static ResultType callCFunction(LinkValue *func_value, Argument *arg, long int line, char *file, int pt_sep, FUNC_NT){
  185. VarList *function_var = NULL;
  186. OfficialFunction of = NULL;
  187. Argument *bak;
  188. bool push = func_value->value->data.function.function_data.push;
  189. setResultCore(result);
  190. gc_addTmpLink(&func_value->gc_status);
  191. setFunctionArgument(&arg, &bak, func_value, line, file, pt_sep, CNEXT_NT);
  192. if (!CHECK_RESULT(result))
  193. goto return_;
  194. of = func_value->value->data.function.of;
  195. if (push)
  196. function_var = pushVarList(func_value->value->object.out_var != NULL ? func_value->value->object.out_var : var_list, inter);
  197. else
  198. function_var = func_value->value->object.out_var != NULL ? func_value->value->object.out_var : var_list;
  199. freeResult(result);
  200. of(CO_FUNC(arg, function_var, result, func_value->belong)); // belong设置为func的belong, 方便权限的认定
  201. if (result->type == R_func)
  202. result->type = R_opt;
  203. else if (result->type != R_opt && result->type != R_error)
  204. setResult(result, inter);
  205. if (push)
  206. popVarList(function_var);
  207. freeFunctionArgument(arg, bak);
  208. return_:
  209. #if START_GC
  210. if (SHOULD_RUNGC(inter))
  211. gc_run(inter, var_list);
  212. #endif
  213. gc_freeTmpLink(&func_value->gc_status);
  214. return result->type;
  215. }
  216. static bool makeFFIReturn(enum ArgumentFFIType af, void **re_v) {
  217. switch (af) {
  218. case af_uchar:
  219. case af_usint:
  220. case af_uint:
  221. case af_ulint:
  222. *re_v = memCalloc(1, sizeof(uint64_t)); // 无论是int32或者是int64,都申请int64_t的内存 (否则libffi会提升类型,导致内存溢出)
  223. break;
  224. case af_char:
  225. case af_sint:
  226. case af_int:
  227. case af_lint:
  228. *re_v = memCalloc(1, sizeof(int64_t)); // 无论是int32或者是int64,都申请int64_t的内存 (否则libffi会提升类型,导致内存溢出)
  229. break;
  230. case af_float:
  231. case af_double:
  232. *re_v = memCalloc(1, sizeof(double)); // 理由同上
  233. break;
  234. case af_ldouble:
  235. *re_v = memCalloc(1, sizeof(long double)); // 理由同上
  236. break;
  237. case af_pointer:
  238. case af_str:
  239. case af_wstr:
  240. *re_v = memCalloc(1, sizeof(void *)); // 所有指针数据大小都相同
  241. break;
  242. case af_void:
  243. *re_v = NULL;
  244. break;
  245. default:
  246. return false;
  247. }
  248. return true;
  249. }
  250. static bool FFIReturnValue(enum ArgumentFFIType aft, void *re_v, fline line, char *file, FUNC_NT) {
  251. switch (aft) { // 应用返回值函数
  252. case af_usint:
  253. case af_uint:
  254. case af_ulint:
  255. makeIntValue((vint)*(uint64_t *)re_v, line, file, CNEXT_NT); // 先以(int64_t)读取void *类型的数据, 再转换成(vint)类型 (避免大端和小端模式的行为不同)
  256. break;
  257. case af_sint:
  258. case af_int:
  259. case af_lint:
  260. makeIntValue((vint)*(int64_t *)re_v, line, file, CNEXT_NT); // 先以(int64_t)读取void *类型的数据, 再转换成(vint)类型 (避免大端和小端模式的行为不同)
  261. break;
  262. case af_float:
  263. case af_double:
  264. makeDouValue((vdou)*(double *)re_v, line, file, CNEXT_NT);
  265. break;
  266. case af_ldouble:
  267. makeDouValue((vdou)*(long double *)re_v, line, file, CNEXT_NT);
  268. break;
  269. case af_str: {
  270. wchar_t *tmp = memStrToWcs(*(char **)re_v, false);
  271. makeStringValue(tmp, line, file, CNEXT_NT);
  272. memFree(tmp);
  273. break;
  274. }
  275. case af_wstr: {
  276. wchar_t *tmp = memWidecpy(*(wchar_t **)re_v);
  277. makeStringValue(tmp, line, file, CNEXT_NT);
  278. memFree(tmp);
  279. break;
  280. }
  281. case af_pointer:
  282. makePointerValue(*(void **)re_v, line, file, CNEXT_NT);
  283. break;
  284. case af_uchar:
  285. case af_char: {
  286. wchar_t tmp[] = {(wchar_t)(*(int64_t *)re_v), WNUL};
  287. makeStringValue(tmp, line, file, CNEXT_NT);
  288. break;
  289. }
  290. case af_void:
  291. setResult(result, inter);
  292. break;
  293. default:
  294. setResultError(E_ArgumentException, (wchar_t *) L"no-support return type for C function", line, file, true, CNEXT_NT);
  295. return false;
  296. }
  297. return true;
  298. }
  299. static ffi_type *getRearg(LinkValue *function_value, enum ArgumentFFIType *aft, fline line, char *file, FUNC_NT) {
  300. ffi_type *re;
  301. LinkValue *re_var = findAttributes(L"rearg", false, line, file, true, CFUNC_NT(var_list, result, function_value));
  302. if (!CHECK_RESULT(result))
  303. return NULL;
  304. freeResult(result);
  305. if (re_var != NULL) {
  306. if (re_var->value->type != V_str) {
  307. setResultError(E_TypeException, ONLY_ACC(rearg, str), line, file, true, CNEXT_NT);
  308. return NULL;
  309. }
  310. re = getFFIType(re_var->value->data.str.str, aft);
  311. if (re == NULL) {
  312. setResultError(E_ArgumentException, (wchar_t *) L"no-support argument type for C function", line, file, true, CNEXT_NT);
  313. return NULL;
  314. }
  315. } else
  316. re = &ffi_type_sint32;
  317. return re;
  318. }
  319. static ResultType getFuncargs(LinkValue *function_value, ArgumentFFI *af, fline line, char *file, FUNC_NT) {
  320. LinkValue *arg_var = NULL;
  321. LinkValue *vaarg_var = NULL;
  322. setResultCore(result);
  323. arg_var = findAttributes(L"funcargs", false, line, file, true, CFUNC_NT(var_list, result, function_value));
  324. if (!CHECK_RESULT(result))
  325. return result->type;
  326. freeResult(result);
  327. vaarg_var = findAttributes(L"vaargs", false, line, file, true, CFUNC_NT(var_list, result, function_value));
  328. if (!CHECK_RESULT(result))
  329. return result->type;
  330. freeResult(result);
  331. if (arg_var != NULL) {
  332. LinkValue **valist = vaarg_var != NULL ? vaarg_var->value->data.list.list : NULL;
  333. vint vasize = vaarg_var != NULL ? vaarg_var->value->data.list.size : 0;
  334. af->b_va = arg_var->value->data.list.size;
  335. if (arg_var->value->type != V_list || vaarg_var != NULL && vaarg_var->value->type != V_list) {
  336. setResultError(E_TypeException, ONLY_ACC(funcargs / vaarg_var, list), line, file, true, CNEXT_NT);
  337. return R_error;
  338. }
  339. if (!listToArgumentFFI(af, arg_var->value->data.list.list, arg_var->value->data.list.size, valist, vasize)) {
  340. setResultError(E_ArgumentException, (wchar_t *) L"no-support argument type for C function", line, file, true, CNEXT_NT);
  341. return R_error;
  342. }
  343. }
  344. return result->type;
  345. }
  346. static ResultType callFFunction(LinkValue *function_value, Argument *arg, long int line, char *file, int pt_sep, FUNC_NT){
  347. ffi_cif cif;
  348. ffi_type *re;
  349. unsigned int size;
  350. ArgumentFFI af;
  351. enum ArgumentFFIType aft = af_int;
  352. void *re_v = NULL; // 存放返回值的函數
  353. setResultCore(result);
  354. if (function_value->value->data.function.function_data.cls->value->type != V_lib) {
  355. setResultError(E_ArgumentException, (wchar_t *) L"c function source is not clear", line, file, true, CNEXT_NT);
  356. return R_error;
  357. }
  358. if (function_value->value->data.function.function_data.cls->value->data.lib.handle == NULL) {
  359. setResultError(E_ArgumentException, (wchar_t *) L"dynamic library is closed", line, file, true, CNEXT_NT);
  360. return R_error;
  361. }
  362. setArgumentFFICore(&af);
  363. if (pt_sep != 0 || (size = checkArgument(arg, value_arg)) == -1) {
  364. setResultError(E_ArgumentException, (wchar_t *) L"does not support key-value arguments", line, file, true, CNEXT_NT);
  365. return R_error;
  366. }
  367. re = getRearg(function_value, &aft, line, file, CNEXT_NT);
  368. if (!CHECK_RESULT(result))
  369. return result->type;
  370. setArgumentFFI(&af, size);
  371. getFuncargs(function_value, &af, line, file, CNEXT_NT);
  372. if (!CHECK_RESULT(result))
  373. goto return_;
  374. if (!setArgumentToFFI(&af, arg)) {
  375. setResultError(E_ArgumentException, (wchar_t *) L"parameter exception when calling C function", line, file, true, CNEXT_NT);
  376. goto return_;
  377. }
  378. if (af.size == af.b_va)
  379. ffi_prep_cif(&cif, FFI_DEFAULT_ABI, af.size, re, af.arg);
  380. else
  381. ffi_prep_cif_var(&cif, FFI_DEFAULT_ABI, af.b_va, af.size, re, af.arg);
  382. if (makeFFIReturn(aft, &re_v)) {
  383. ffi_call(&cif, function_value->value->data.function.ffunc, re_v, af.arg_v);
  384. FFIReturnValue(aft, re_v, line, file, CNEXT_NT);
  385. memFree(re_v);
  386. } else
  387. setResultError(E_ArgumentException, (wchar_t *) L"no-support return type for C function", line, file, true, CNEXT_NT);
  388. return_:
  389. freeArgumentFFI(&af);
  390. return result->type;
  391. }
  392. static void updateFunctionYield(Statement *func_st, Statement *node){
  393. func_st->info.node = node->type == yield_code ? node->next : node;
  394. func_st->info.have_info = true;
  395. }
  396. static void newFunctionYield(Statement *func_st, Statement *node, bool push, VarList *new_var, Inter *inter){
  397. if (push)
  398. new_var->next = NULL;
  399. func_st->info.var_list = new_var;
  400. func_st->info.node = node->type == yield_code ? node->next : node;
  401. func_st->info.have_info = true;
  402. func_st->info.branch.func.push = push;
  403. }
  404. static void setFunctionResult(LinkValue *func_value, bool yield_run, bool push, Result *result, FUNC_CORE) {
  405. Statement *st_func = func_value->value->data.function.function;
  406. if (yield_run) {
  407. if (result->type == R_yield) {
  408. updateFunctionYield(st_func, result->node);
  409. result->type = R_opt;
  410. result->is_yield = true;
  411. } else {
  412. if (st_func->info.var_list != NULL && push)
  413. freeVarList(st_func->info.var_list);
  414. setRunInfo(st_func);
  415. }
  416. } else {
  417. if (result->type == R_yield) {
  418. newFunctionYield(st_func, result->node, push, var_list, inter);
  419. result->type = R_opt;
  420. result->is_yield = true;
  421. } else {
  422. if (push)
  423. popVarList(var_list);
  424. }
  425. }
  426. }
  427. static bool popFuncYieldVarList(Statement *st, VarList **return_, VarList *out_var, bool *push, Inter *inter) {
  428. bool yield_run;
  429. if ((yield_run = st->info.have_info)) {
  430. *push = st->info.branch.func.push;
  431. *return_ = st->info.var_list;
  432. if (*push)
  433. (*return_)->next = out_var; // 若是push进来的var_list, 则需要重新链接
  434. } else if (*push)
  435. *return_ = pushVarList(out_var, inter);
  436. else
  437. *return_ = out_var;
  438. return yield_run;
  439. }
  440. static ResultType callVMFunction(LinkValue *func_value, Argument *arg, long int line, char *file, int pt_sep, FUNC_NT) {
  441. Argument *bak;
  442. VarList *var_func = NULL;
  443. Statement *st_func = NULL;
  444. Parameter *pt_func = func_value->value->data.function.pt;
  445. bool yield_run = false;
  446. bool push = func_value->value->data.function.function_data.push;
  447. setResultCore(result);
  448. st_func = func_value->value->data.function.function;
  449. if (st_func == NULL) {
  450. setResult(result, inter);
  451. return result->type;
  452. }
  453. gc_addTmpLink(&func_value->gc_status);
  454. {
  455. VarList *out_var;
  456. if (func_value->value->object.out_var == NULL)
  457. out_var = var_list; // 当out_var等于空的时候为内联函数
  458. else
  459. out_var = func_value->value->object.out_var;
  460. yield_run = popFuncYieldVarList(st_func, &var_func, out_var, &push, inter);
  461. }
  462. if (yield_run)
  463. st_func = st_func->info.node;
  464. setFunctionArgument(&arg, &bak, func_value, line, file, pt_sep, CNEXT_NT);
  465. if (!CHECK_RESULT(result))
  466. goto return_;
  467. freeResult(result);
  468. setParameterCore(line, file, arg, pt_func, var_func, CFUNC_NT(var_list, result, func_value));
  469. freeFunctionArgument(arg, bak);
  470. if (!CHECK_RESULT(result))
  471. goto return_;
  472. freeResult(result);
  473. functionSafeInterStatement(CFUNC(st_func, var_func, result, func_value->belong)); // belong设置为函数的belong,方便权限校对
  474. return_:
  475. setFunctionResult(func_value, yield_run, push, result, CFUNC_CORE(var_func));
  476. gc_freeTmpLink(&func_value->gc_status);
  477. return result->type;
  478. }
  479. ResultType callBackCore(LinkValue *function_value, Argument *arg, fline line, char *file, int pt_sep, FUNC_NT) {
  480. setResultCore(result);
  481. gc_addTmpLink(&function_value->gc_status);
  482. switch (function_value->value->type) {
  483. case V_func:
  484. switch (function_value->value->data.function.type) {
  485. case vm_func:
  486. callVMFunction(function_value, arg, line, file, pt_sep, CNEXT_NT);
  487. break;
  488. case c_func:
  489. callCFunction(function_value, arg, line, file, pt_sep, CNEXT_NT);
  490. break;
  491. case f_func:
  492. callFFunction(function_value, arg, line, file, pt_sep, CNEXT_NT);
  493. break;
  494. default:
  495. setResultError(E_SystemException, L"function type error", line, file, true, CNEXT_NT);
  496. break;
  497. }
  498. break;
  499. case V_class:
  500. callClass(function_value, arg, line, file, pt_sep, CNEXT_NT);
  501. break;
  502. default :
  503. callObject(function_value, arg, line, file, pt_sep, CNEXT_NT);
  504. break;
  505. }
  506. // callBackCore不执行错误回溯
  507. gc_freeTmpLink(&function_value->gc_status);
  508. return result->type;
  509. }
  510. ResultType setDecoration(DecorationStatement *ds, LinkValue *value, FUNC_NT) {
  511. LinkValue *decall = NULL;
  512. Parameter *pt = NULL;
  513. setResultCore(result);
  514. gc_addTmpLink(&value->gc_status);
  515. for (PASS; ds != NULL; ds = ds->next){
  516. freeResult(result);
  517. if (operationSafeInterStatement(CFUNC(ds->decoration, var_list, result, belong)))
  518. break;
  519. pt = makeValueParameter(makeBaseLinkValueStatement(value, ds->decoration->line, ds->decoration->code_file));
  520. GET_RESULT(decall, result);
  521. callBackCorePt(decall, pt, ds->decoration->line, ds->decoration->code_file, CNEXT_NT);
  522. gc_freeTmpLink(&decall->gc_status);
  523. freeParameter(pt, true);
  524. if (!CHECK_RESULT(result))
  525. break;
  526. gc_freeTmpLink(&value->gc_status);
  527. value = result->value;
  528. gc_addTmpLink(&value->gc_status);
  529. }
  530. gc_freeTmpLink(&value->gc_status);
  531. return result->type;
  532. }