object.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #include "__ofunc.h"
  2. ResultType object_new(O_FUNC){
  3. LinkValue *value = NULL;
  4. setResultCore(result);
  5. ArgumentParser ap[] = {{.type=only_value, .must=1, .long_arg=false},
  6. {.must=-1}};
  7. int status = 1;
  8. arg = parserValueArgument(ap, arg, &status, NULL);
  9. if (status != 1){
  10. setResultError(E_ArgumentException, FEW_ARG, LINEFILE, true, CNEXT_NT);
  11. return R_error;
  12. }
  13. value = make_new(inter, belong, ap[0].value);
  14. run_init(value, arg, LINEFILE, CNEXT_NT);
  15. return result->type;
  16. }
  17. ResultType objectRepoStrCore(O_FUNC, bool is_repo){
  18. ArgumentParser ap[] = {{.type=only_value, .must=1, .long_arg=false},
  19. {.must=-1}};
  20. wchar_t *repo;
  21. wchar_t *name;
  22. wchar_t *type;
  23. LinkValue *name_value;
  24. setResultCore(result);
  25. parserArgumentUnion(ap, arg, CNEXT_NT);
  26. if (!CHECK_RESULT(result))
  27. return result->type;
  28. freeResult(result);
  29. name_value = findAttributes(inter->data.mag_func[M_NAME], false, LINEFILE, true, CFUNC_NT(var_list, result, ap[0].value));
  30. if (!CHECK_RESULT(result))
  31. return result->type;
  32. freeResult(result);
  33. if (name_value != NULL){
  34. gc_addTmpLink(&name_value->gc_status);
  35. name = getRepoStr(name_value, is_repo, LINEFILE, CNEXT_NT);
  36. gc_freeTmpLink(&name_value->gc_status);
  37. if (!CHECK_RESULT(result))
  38. return result->type;
  39. freeResult(result);
  40. } else
  41. name = L"unknown";
  42. if (ap[0].value->value->type == V_none) {
  43. repo = memWidecpy(L"null");
  44. } else {
  45. size_t len;
  46. if (ap[0].value->value->type == V_class)
  47. type = L"V_class";
  48. else
  49. type = L"object";
  50. len = memWidelen(name) + 30;
  51. repo = memCalloc(len, sizeof(char ));
  52. swprintf(repo, len, L"(%ls: %ls on %p)", type, name, ap[0].value->value);
  53. }
  54. makeStringValue(repo, LINEFILE, CNEXT_NT);
  55. memFree(repo);
  56. return result->type;
  57. }
  58. ResultType object_repo(O_FUNC){
  59. return objectRepoStrCore(CO_FUNC(arg, var_list, result, belong), true);
  60. }
  61. ResultType object_str(O_FUNC){
  62. return objectRepoStrCore(CO_FUNC(arg, var_list, result, belong), false);
  63. }
  64. void registeredObject(R_FUNC){
  65. LinkValue *object = inter->data.base_obj[B_OBJECT];
  66. NameFunc tmp[] = {{inter->data.mag_func[M_NEW], object_new, class_free_},
  67. {inter->data.mag_func[M_REPO], object_repo, all_free_},
  68. {inter->data.mag_func[M_STR], object_str, all_free_},
  69. {NULL, NULL}};
  70. gc_addTmpLink(&object->gc_status);
  71. addBaseClassVar(L"object", object, belong, inter);
  72. iterBaseClassFunc(tmp, object, CFUNC_CORE(inter->var_list));
  73. gc_freeTmpLink(&object->gc_status);
  74. }
  75. void makeBaseObject(Inter *inter, LinkValue *belong){
  76. LinkValue *g_belong;
  77. Value *object = makeClassValue(inter->var_list, inter, NULL);
  78. {
  79. Value *global_belong = makeObject(inter, copyVarList(inter->var_list, false, inter), NULL, NULL);
  80. g_belong = makeLinkValue(global_belong, belong, inter);
  81. inter->base_belong = g_belong;
  82. gc_addStatementLink(&inter->base_belong->gc_status);
  83. }
  84. inter->data.base_obj[B_OBJECT] = makeLinkValue(object, g_belong, inter);
  85. gc_addStatementLink(&inter->data.base_obj[B_OBJECT]->gc_status);
  86. for (Inherit *ih=g_belong->value->object.inherit; ih != NULL; ih = ih->next) {
  87. if (ih->value->value == object)
  88. ih->value->belong = g_belong;
  89. }
  90. {
  91. Result result;
  92. Argument *arg = makeValueArgument(makeLinkValue(object, g_belong, inter));
  93. setResultCore(&result);
  94. object_new(CO_FUNC(arg, inter->var_list, &result, g_belong));
  95. result.value->value->type = V_none;
  96. inter->data.base_obj[B_NONE] = result.value;
  97. gc_addStatementLink(&inter->data.base_obj[B_NONE]->gc_status);
  98. freeArgument(arg, true);
  99. freeResult(&result);
  100. }
  101. }