value.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  1. #include "__run.h"
  2. Value *makeObject(Inter *inter, VarList *object, VarList *out_var, Inherit *inherit) {
  3. Value *tmp, *list_tmp = inter->base;
  4. tmp = memCalloc(1, sizeof(Value));
  5. setGC(&tmp->gc_status);
  6. tmp->type = object_;
  7. tmp->gc_next = NULL;
  8. if (inter->data.object != NULL && inherit == NULL)
  9. inherit = makeInherit(inter->data.object);
  10. if (out_var == NULL && inherit != NULL)
  11. out_var = copyVarList(inherit->value->value->object.out_var, false, inter);
  12. tmp->object.var = makeObjectVarList(inherit, inter, object);
  13. tmp->object.out_var = out_var;
  14. tmp->object.inherit = inherit;
  15. if (list_tmp == NULL){
  16. inter->base = tmp;
  17. tmp->gc_last = NULL;
  18. goto return_;
  19. }
  20. for (PASS; list_tmp->gc_next != NULL; list_tmp = list_tmp->gc_next)
  21. PASS;
  22. list_tmp->gc_next = tmp;
  23. tmp->gc_last = list_tmp;
  24. return_:
  25. return tmp;
  26. }
  27. Value *useNoneValue(Inter *inter, Result *result) {
  28. LinkValue *tmp = inter->data.none;
  29. if (result != NULL) {
  30. setResultCore(result);
  31. result->type = R_opt;
  32. result->value = tmp;
  33. gc_addTmpLink(&result->value->gc_status);
  34. }
  35. return tmp->value;
  36. }
  37. Value *makeBoolValue(bool bool_num, fline line, char *file, INTER_FUNCTIONSIG_NOT_ST) {
  38. Value *tmp = NULL;
  39. setResultCore(result);
  40. callBackCore(inter->data.bool_, NULL, line, file, 0, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  41. if (!CHECK_RESULT(result))
  42. return NULL;
  43. tmp = result->value->value;
  44. tmp->data.bool_.bool_ = bool_num;
  45. return tmp;
  46. }
  47. Value *makePassValue(fline line, char *file, INTER_FUNCTIONSIG_NOT_ST){ // TODO-szh 让切片支持该语法 检查语法解析器支持 a[::]的语法
  48. Value *tmp = NULL;
  49. setResultCore(result);
  50. callBackCore(inter->data.pass_, NULL, line, file, 0, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  51. if (!CHECK_RESULT(result))
  52. return NULL;
  53. tmp = result->value->value;
  54. return tmp;
  55. }
  56. Value *makeNumberValue(vnum num, fline line, char *file, INTER_FUNCTIONSIG_NOT_ST) {
  57. Value *tmp = NULL;
  58. setResultCore(result);
  59. callBackCore(inter->data.num, NULL, line, file, 0, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  60. if (!CHECK_RESULT(result))
  61. return NULL;
  62. tmp = result->value->value;
  63. tmp->data.num.num = num;
  64. return tmp;
  65. }
  66. Value *makeStringValue(wchar_t *str, fline line, char *file, INTER_FUNCTIONSIG_NOT_ST) {
  67. Value *tmp = NULL;
  68. setResultCore(result);
  69. callBackCore(inter->data.str, NULL, line, file, 0, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  70. if (!CHECK_RESULT(result))
  71. return NULL;
  72. tmp = result->value->value;
  73. memFree(tmp->data.str.str);
  74. tmp->data.str.str = memWidecpy(str);
  75. return tmp;
  76. }
  77. Value *makeVMFunctionValue(Statement *st, Parameter *pt, INTER_FUNCTIONSIG_NOT_ST) {
  78. Value *tmp = NULL;
  79. callBackCore(inter->data.function, NULL, st->line, st->code_file, 0,
  80. CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  81. if (!CHECK_RESULT(result))
  82. return NULL;
  83. tmp = result->value->value;
  84. tmp->data.function.function = copyStatement(st);
  85. tmp->data.function.pt = copyParameter(pt);
  86. tmp->data.function.function_data.cls = belong;
  87. for (VarList *vl = tmp->object.out_var, *vl_next; vl != NULL; vl = vl_next) {
  88. vl_next = vl->next;
  89. freeVarList(vl);
  90. }
  91. tmp->object.out_var = copyVarList(var_list, false, inter);
  92. result->value->belong = belong;
  93. return tmp;
  94. }
  95. Value *makeCFunctionValue(OfficialFunction of, fline line, char *file, INTER_FUNCTIONSIG_NOT_ST) {
  96. Value *tmp = NULL;
  97. callBackCore(inter->data.function, NULL, line, file, 0,
  98. CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  99. if (!CHECK_RESULT(result))
  100. return NULL;
  101. tmp = result->value->value;
  102. tmp->data.function.type = c_function;
  103. tmp->data.function.of = of;
  104. tmp->data.function.function_data.pt_type = inter->data.default_pt_type;
  105. tmp->data.function.function_data.cls = belong;
  106. for (VarList *vl = tmp->object.out_var, *vl_next; vl != NULL; vl = vl_next) {
  107. vl_next = vl->next;
  108. freeVarList(vl);
  109. }
  110. tmp->object.out_var = copyVarList(var_list, false, inter);
  111. result->value->belong = belong;
  112. return tmp;
  113. }
  114. LinkValue *makeCFunctionFromOf(OfficialFunction of, LinkValue *func, OfficialFunction function_new, OfficialFunction function_init, LinkValue *belong, VarList *var_list, Inter *inter) {
  115. Argument *arg = makeValueArgument(func);
  116. Argument *init_arg = NULL;
  117. LinkValue *return_ = NULL;
  118. Result result;
  119. setResultCore(&result);
  120. function_new(CALL_OFFICAL_FUNCTION(arg, func->value->object.var, &result, func));
  121. return_ = result.value;
  122. result.value = NULL;
  123. freeResult(&result);
  124. init_arg = makeValueArgument(return_);
  125. function_init(CALL_OFFICAL_FUNCTION(init_arg, func->value->object.var, &result, func));
  126. freeResult(&result);
  127. freeArgument(init_arg, true);
  128. freeArgument(arg, true);
  129. return_->value->data.function.type = c_function;
  130. return_->value->data.function.of = of;
  131. return_->value->data.function.function_data.pt_type = inter->data.default_pt_type;
  132. return_->value->data.function.function_data.cls = belong;
  133. for (VarList *vl = return_->value->object.out_var; vl != NULL; vl = freeVarList(vl))
  134. PASS;
  135. return_->value->object.out_var = copyVarList(var_list, false, inter);
  136. return_->belong = belong;
  137. gc_freeTmpLink(&return_->gc_status);
  138. return return_;
  139. }
  140. Value *makeClassValue(VarList *var_list, Inter *inter, Inherit *father) {
  141. Value *tmp;
  142. VarList *new_var = copyVarList(var_list, false, inter);
  143. tmp = makeObject(inter, NULL, new_var, father);
  144. tmp->type = class;
  145. return tmp;
  146. }
  147. Value *makeListValue(Argument *arg, fline line, char *file, enum ListType type, INTER_FUNCTIONSIG_NOT_ST) {
  148. Value *tmp = NULL;
  149. setResultCore(result);
  150. if (type == value_list)
  151. callBackCore(inter->data.list, arg, line, file, 0,
  152. CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  153. else
  154. callBackCore(inter->data.tuple, arg, line, file, 0,
  155. CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  156. if (!CHECK_RESULT(result))
  157. return NULL;
  158. tmp = result->value->value;
  159. return tmp;
  160. }
  161. Value *makeDictValue(Argument *arg, bool new_hash, fline line, char *file, INTER_FUNCTIONSIG_NOT_ST) {
  162. Value *tmp = NULL;
  163. setResultCore(result);
  164. callBackCore(inter->data.dict, arg, line, file, 0, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  165. if (!CHECK_RESULT(result))
  166. return NULL;
  167. tmp = result->value->value;
  168. if (!new_hash) {
  169. tmp->data.dict.dict = NULL;
  170. tmp->data.dict.size = 0;
  171. }
  172. return tmp;
  173. }
  174. void freeValue(Value **value) {
  175. Value *free_value = *value;
  176. FREE_BASE(free_value, return_);
  177. for (VarList *tmp = free_value->object.var; tmp != NULL; tmp = freeVarList(tmp))
  178. PASS;
  179. for (VarList *tmp = free_value->object.out_var; tmp != NULL; tmp = freeVarList(tmp))
  180. PASS;
  181. for (struct Inherit *tmp = free_value->object.inherit; tmp != NULL; tmp = freeInherit(tmp))
  182. PASS;
  183. switch (free_value->type) {
  184. case string:
  185. memFree(free_value->data.str.str);
  186. break;
  187. case function: {
  188. freeParameter(free_value->data.function.pt, true);
  189. freeStatement(free_value->data.function.function);
  190. break;
  191. }
  192. case list:
  193. memFree(free_value->data.list.list);
  194. break;
  195. default:
  196. break;
  197. }
  198. if ((*value)->gc_next != NULL)
  199. (*value)->gc_next->gc_last = (*value)->gc_last;
  200. *value = (*value)->gc_next;
  201. memFree(free_value);
  202. return_: return;
  203. }
  204. LinkValue *makeLinkValue(Value *value, LinkValue *belong, Inter *inter){
  205. LinkValue *tmp;
  206. LinkValue *list_tmp = inter->link_base;
  207. tmp = memCalloc(1, sizeof(Value));
  208. tmp->belong = belong;
  209. tmp->value = value;
  210. setGC(&tmp->gc_status);
  211. if (list_tmp == NULL){
  212. inter->link_base = tmp;
  213. tmp->gc_last = NULL;
  214. goto return_;
  215. }
  216. for (PASS; list_tmp->gc_next != NULL; list_tmp = list_tmp->gc_next)
  217. PASS;
  218. list_tmp->gc_next = tmp;
  219. tmp->gc_last = list_tmp;
  220. tmp->aut = auto_aut;
  221. return_:
  222. return tmp;
  223. }
  224. void freeLinkValue(LinkValue **value) {
  225. LinkValue *free_value = *value;
  226. FREE_BASE(free_value, return_);
  227. if ((*value)->gc_next != NULL)
  228. (*value)->gc_next->gc_last = (*value)->gc_last;
  229. *value = (*value)->gc_next;
  230. memFree(free_value);
  231. return_: return;
  232. }
  233. LinkValue *copyLinkValue(LinkValue *value, Inter *inter) {
  234. LinkValue *tmp = NULL;
  235. if (value == NULL)
  236. return NULL;
  237. tmp = makeLinkValue(value->value, value->belong, inter);
  238. tmp->aut = value->aut;
  239. return tmp;
  240. }
  241. void setResultCore(Result *ru) {
  242. ru->type = R_not;
  243. ru->times = 0;
  244. ru->error = NULL;
  245. ru->value = NULL;
  246. ru->label = NULL;
  247. ru->node = NULL;
  248. }
  249. void setResult(Result *ru, Inter *inter) {
  250. freeResult(ru);
  251. setResultBase(ru, inter);
  252. }
  253. void setResultBase(Result *ru, Inter *inter) {
  254. setResultCore(ru);
  255. useNoneValue(inter, ru);
  256. }
  257. void setResultErrorSt(BaseErrorType type, wchar_t *error_message, bool new, Statement *st, INTER_FUNCTIONSIG_NOT_ST) {
  258. setResultError(type, error_message, st->line, st->code_file, new, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  259. }
  260. LinkValue *findBaseError(BaseErrorType type, Inter *inter){
  261. switch (type) {
  262. case E_BaseException:
  263. return inter->data.base_exc;
  264. case E_Exception:
  265. return inter->data.exc;
  266. case E_TypeException:
  267. return inter->data.type_exc;
  268. case E_ArgumentException:
  269. return inter->data.arg_exc;
  270. case E_PermissionsException:
  271. return inter->data.per_exc;
  272. case E_GotoException:
  273. return inter->data.goto_exc;
  274. case E_ResultException:
  275. return inter->data.result_exc;
  276. case E_NameExceptiom:
  277. return inter->data.name_exc;
  278. case E_AssertException:
  279. return inter->data.assert_exc;
  280. case E_IndexException:
  281. return inter->data.index_exc;
  282. case E_KeyException:
  283. return inter->data.key_exc;
  284. case E_StrideException:
  285. return inter->data.stride_exc;
  286. case E_StopIterException:
  287. return inter->data.iterstop_exc;
  288. case E_SuperException:
  289. return inter->data.super_exc;
  290. case E_ImportException:
  291. return inter->data.import_exc;
  292. case E_IncludeException:
  293. return inter->data.include_exp;
  294. case E_SystemException:
  295. return inter->data.sys_exc;
  296. case E_KeyInterrupt:
  297. return inter->data.keyInterrupt_exc;
  298. case E_QuitException:
  299. return inter->data.quit_exc;
  300. default:
  301. return NULL;
  302. }
  303. }
  304. wchar_t *getErrorInfo(LinkValue *exc, int type, Inter *inter){
  305. wchar_t *str_name = type == 1 ? inter->data.object_name : inter->data.object_message;
  306. LinkValue *_info_ = findAttributes(str_name, false, exc, inter);
  307. if (_info_ != NULL && _info_->value->type == string)
  308. return memWidecpy(_info_->value->data.str.str);
  309. else
  310. return type == 1 ? memWidecpy(L"Error Type: Unknown") : memWidecpy(L"Error Message: Unknown");
  311. }
  312. void callException(LinkValue *exc, wchar_t *message, fline line, char *file, INTER_FUNCTIONSIG_NOT_ST) {
  313. LinkValue *_new_ = findAttributes(inter->data.object_new, false, exc, inter);
  314. wchar_t *type = NULL;
  315. wchar_t *error_message = NULL;
  316. setResultCore(result);
  317. gc_addTmpLink(&exc->gc_status);
  318. if (_new_ != NULL){
  319. Argument *arg = NULL;
  320. makeStringValue(message, line, file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  321. if (!CHECK_RESULT(result))
  322. goto return_;
  323. arg = makeValueArgument(result->value);
  324. freeResult(result);
  325. gc_addTmpLink(&_new_->gc_status);
  326. callBackCore(_new_, arg, line, file, 0, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  327. gc_freeTmpLink(&_new_->gc_status);
  328. freeArgument(arg, true);
  329. type = getErrorInfo(result->value, 1, inter);
  330. error_message = getErrorInfo(result->value, 2, inter);
  331. }
  332. else {
  333. result->value = exc;
  334. gc_addTmpLink(&result->value->gc_status);
  335. }
  336. result->type = R_error;
  337. result->error = connectError(makeError(type, error_message, line, file), result->error);
  338. memFree(type);
  339. memFree(error_message);
  340. return_: gc_freeTmpLink(&exc->gc_status);
  341. }
  342. void setResultError(BaseErrorType type, wchar_t *error_message, fline line, char *file, bool new, INTER_FUNCTIONSIG_NOT_ST) {
  343. if (!new && result->type != R_error)
  344. return;
  345. if (new) {
  346. LinkValue *exc = findBaseError(type, inter);
  347. if (exc == NULL)
  348. exc = inter->data.base_exc;
  349. freeResult(result);
  350. callException(exc, error_message, line, file, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  351. }
  352. else
  353. result->error = connectError(makeError(NULL, NULL, line, file), result->error);
  354. }
  355. void setResultOperationNone(Result *ru, Inter *inter, LinkValue *belong) {
  356. setResult(ru, inter);
  357. ru->type = R_opt;
  358. }
  359. void setResultOperation(Result *ru, LinkValue *value) {
  360. freeResult(ru);
  361. setResultOperationBase(ru, value);
  362. }
  363. void setResultOperationBase(Result *ru, LinkValue *value) {
  364. setResultCore(ru);
  365. ru->value = value;
  366. if (value != NULL)
  367. gc_addTmpLink(&ru->value->gc_status);
  368. ru->type = R_opt;
  369. }
  370. void freeResult(Result *ru){
  371. memFree(ru->label);
  372. ru->label = NULL;
  373. freeResultSafe(ru);
  374. if (ru->value != NULL) {
  375. gc_freeTmpLink(&ru->value->gc_status);
  376. ru->value = NULL;
  377. }
  378. }
  379. void freeResultSafe(Result *ru){
  380. if (ru->error != NULL)
  381. freeError(ru);
  382. ru->error = NULL;
  383. }
  384. Error *makeError(wchar_t *type, wchar_t *message, fline line, char *file) {
  385. Error *tmp = memCalloc(1, sizeof(Error));
  386. tmp->line = line;
  387. tmp->type = memWidecpy(type);
  388. tmp->messgae = memWidecpy(message);
  389. tmp->file = memStrcpy(file);
  390. tmp->next = NULL;
  391. return tmp;
  392. }
  393. Error *connectError(Error *new, Error *base){
  394. new->next = base;
  395. return new;
  396. }
  397. void freeError(Result *base){
  398. Error *error = base->error;
  399. for (Error *next = NULL; error != NULL; error = next){
  400. next = error->next;
  401. memFree(error->messgae);
  402. memFree(error->type);
  403. memFree(error->file);
  404. memFree(error);
  405. }
  406. base->error = NULL;
  407. }
  408. void printError(Result *result, Inter *inter, bool free) {
  409. for (Error *base = result->error; base != NULL; base = base->next){
  410. if (base->next != NULL)
  411. fprintf(inter->data.inter_stderr, "Error Backtracking: On Line: %lld In file: %s Error ID: %p\n", base->line, base->file, base);
  412. else
  413. fprintf(inter->data.inter_stderr, "%ls\n%ls\nOn Line: %lld\nIn File: %s\nError ID: %p\n", base->type, base->messgae, base->line, base->file, base);
  414. }
  415. if (free)
  416. freeError(result);
  417. fflush(inter->data.inter_stderr);
  418. }
  419. inline bool isType(Value *value, enum ValueType type){
  420. return value->type == type;
  421. }
  422. Inherit *makeInherit(LinkValue *value){
  423. Inherit *tmp;
  424. tmp = memCalloc(1, sizeof(Inherit));
  425. tmp->value = value;
  426. tmp->next = NULL;
  427. return tmp;
  428. }
  429. Inherit *copyInheritCore(Inherit *value){
  430. Inherit *tmp;
  431. if (value == NULL)
  432. return NULL;
  433. tmp = makeInherit(value->value);
  434. return tmp;
  435. }
  436. Inherit *copyInherit(Inherit *value){
  437. Inherit *base = NULL;
  438. Inherit **tmp = &base;
  439. for (PASS; value != NULL; value = value->next, tmp = &(*tmp)->next)
  440. *tmp = copyInheritCore(value);
  441. return base;
  442. }
  443. Inherit *freeInherit(Inherit *value){
  444. FREE_BASE(value, error_);
  445. Inherit *next = value->next;
  446. memFree(value);
  447. return next;
  448. error_: return NULL;
  449. }
  450. Inherit *connectInherit(Inherit *base, Inherit *back){
  451. Inherit **tmp = &base;
  452. for (PASS; *tmp != NULL; tmp = &(*tmp)->next)
  453. PASS;
  454. *tmp = back;
  455. return base;
  456. }
  457. Inherit *connectSafeInherit(Inherit *base, Inherit *back){
  458. Inherit **last_node = &base;
  459. if (back == NULL)
  460. goto return_;
  461. for (PASS; *last_node != NULL;)
  462. if ((*last_node)->value->value == back->value->value)
  463. *last_node = freeInherit(*last_node);
  464. else
  465. last_node = &(*last_node)->next;
  466. *last_node = back;
  467. return_: return base;
  468. }
  469. Inherit *getInheritFromValueCore(LinkValue *num_father) {
  470. Inherit *object_father;
  471. Argument *father_arg = makeValueArgument(num_father);
  472. gc_addTmpLink(&num_father->gc_status);
  473. object_father = setFather(father_arg);
  474. freeArgument(father_arg, true);
  475. gc_freeTmpLink(&num_father->gc_status);
  476. return object_father;
  477. }
  478. Package *makePackage(Value *value, char *md5, char *name, Package *base) {
  479. Package *tmp = memCalloc(1, sizeof(Package));
  480. Package *tmp_base = base;
  481. tmp->name = memStrcpy(name);
  482. tmp->md5 = memStrcpy(md5);
  483. tmp->package = value;
  484. gc_addStatementLink(&value->gc_status);
  485. tmp->next = NULL;
  486. if (base == NULL)
  487. return tmp;
  488. for (PASS; tmp_base->next != NULL; tmp_base = tmp_base->next)
  489. PASS;
  490. tmp_base->next = tmp;
  491. return base;
  492. }
  493. void freePackage(Package *base) {
  494. for (Package *next; base != NULL; base = next) {
  495. next = base->next;
  496. gc_freeStatementLink(&base->package->gc_status);
  497. memFree(base->name);
  498. memFree(base->md5);
  499. memFree(base);
  500. }
  501. }
  502. Value *checkPackage(Package *base, char *md5, char *name) {
  503. for (PASS; base != NULL; base = base->next) {
  504. if (eqString(name, base->name) && eqString(md5, base->md5))
  505. return base->package;
  506. }
  507. return NULL;
  508. }
  509. bool needDel(Value *object_value, Inter *inter) {
  510. LinkValue *_del_ = checkStrVar(inter->data.object_del, false, CALL_INTER_FUNCTIONSIG_CORE(object_value->object.var));
  511. enum FunctionPtType type;
  512. if (_del_ == NULL)
  513. return false;
  514. type = _del_->value->data.function.function_data.pt_type;
  515. if ((type == object_free_ || type == object_static_) && object_value->type == class)
  516. return false;
  517. if (_del_->belong == NULL || _del_->belong->value == object_value || checkAttribution(object_value, _del_->belong->value))
  518. return true;
  519. return false;
  520. }
  521. bool callDel(Value *object_value, Result *result, Inter *inter, VarList *var_list) {
  522. LinkValue *_del_ = findStrVar(inter->data.object_del, false, CALL_INTER_FUNCTIONSIG_CORE(object_value->object.var));
  523. setResultCore(result);
  524. if (_del_ != NULL){
  525. gc_addTmpLink(&_del_->gc_status);
  526. if (_del_->belong == NULL || _del_->belong->value != object_value && checkAttribution(object_value, _del_->belong->value))
  527. _del_->belong = makeLinkValue(object_value, inter->base_belong, inter);
  528. callBackCore(_del_, NULL, 0, "sys", 0,
  529. CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, inter->base_belong));
  530. gc_freeTmpLink(&_del_->gc_status);
  531. return true;
  532. } else
  533. return false;
  534. }
  535. /**
  536. * 检查 father 是否为 self 的父亲
  537. * @param self
  538. * @param father
  539. * @return
  540. */
  541. bool checkAttribution(Value *self, Value *father){
  542. for (Inherit *self_father = self->object.inherit; self_father != NULL; self_father = self_father->next)
  543. if (self_father->value->value == father)
  544. return true;
  545. return false;
  546. }
  547. void printValue(Value *value, FILE *debug, bool print_father, bool print_in) {
  548. switch (value->type){
  549. case number:
  550. fprintf(debug, "%lld", value->data.num.num);
  551. break;
  552. case string:
  553. fprintf(debug, "%ls", value->data.str.str);
  554. break;
  555. case function:
  556. if (print_father)
  557. fprintf(debug, "function");
  558. else
  559. fprintf(debug, "(function on %p)", value);
  560. break;
  561. case list:
  562. if (print_in){
  563. fprintf(debug, "[");
  564. for (int i = 0; i < value->data.list.size; i++) {
  565. if (i > 0)
  566. fprintf(debug, ", ", NULL);
  567. printValue(value->data.list.list[i]->value, debug, false, false);
  568. }
  569. fprintf(debug, " ]", NULL);
  570. } else
  571. fprintf(debug, "[list]", NULL);
  572. break;
  573. case dict:
  574. if (print_in){
  575. Var *tmp = NULL;
  576. bool print_comma = false;
  577. fprintf(debug, "{");
  578. for (int i = 0; i < MAX_SIZE; i++) {
  579. for (tmp = value->data.dict.dict->hashtable[i]; tmp != NULL; tmp = tmp->next) {
  580. if (print_comma)
  581. fprintf(debug, ", ", NULL);
  582. else
  583. print_comma = true;
  584. printValue(tmp->name_->value, debug, false, false);
  585. fprintf(debug, " ['%ls'] : ", tmp->name);
  586. printValue(tmp->value->value, debug, false, false);
  587. }
  588. }
  589. fprintf(debug, " }", NULL);
  590. } else
  591. fprintf(debug, "[dict]", NULL);
  592. break;
  593. case none:
  594. fprintf(debug, "(null)", NULL);
  595. break;
  596. case class:
  597. if (print_father)
  598. fprintf(debug, "class");
  599. else
  600. fprintf(debug, "(class on %p)", value);
  601. break;
  602. case object_:
  603. if (print_father)
  604. fprintf(debug, "object");
  605. else
  606. fprintf(debug, "(object on %p)", value);
  607. break;
  608. case bool_:
  609. if (value->data.bool_.bool_)
  610. fprintf(debug, "true");
  611. else
  612. fprintf(debug, "false");
  613. break;
  614. case pass_:
  615. fprintf(debug, "...");
  616. break;
  617. default:
  618. fprintf(debug, "unknown");
  619. break;
  620. }
  621. if (print_father){
  622. fprintf(debug, "(");
  623. printf("<%p>", value);
  624. for (Inherit *fv = value->object.inherit; fv != NULL; fv = fv->next) {
  625. printf(" -> ");
  626. printValue(fv->value->value, debug, false, false);
  627. }
  628. fprintf(debug, ")");
  629. }
  630. }
  631. void printLinkValue(LinkValue *value, char *first, char *last, FILE *debug){
  632. if (value == NULL)
  633. return;
  634. fprintf(debug, "%s", first);
  635. if (value->belong != NULL) {
  636. printLinkValue(value->belong, "", "", debug);
  637. fprintf(debug, " . ", NULL);
  638. }
  639. if (value->value != NULL)
  640. printValue(value->value, debug, true, true);
  641. fprintf(debug, "%s", last);
  642. }