object.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #include "__ofunc.h"
  2. ResultType object_new(OFFICAL_FUNCTIONSIG){
  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, 0, "object.new", true, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  11. return error_return;
  12. }
  13. value = make_new(inter, belong, ap[0].value);
  14. switch (init_new(value, arg, "object.new", CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong))) {
  15. case 1:
  16. freeResult(result);
  17. setResultOperation(result, value);
  18. break;
  19. default:
  20. break;
  21. }
  22. return result->type;
  23. }
  24. ResultType objectRepoStrCore(OFFICAL_FUNCTIONSIG, bool is_repo){
  25. ArgumentParser ap[] = {{.type=only_value, .must=1, .long_arg=false},
  26. {.must=-1}};
  27. wchar_t *repo;
  28. wchar_t *name;
  29. wchar_t *type;
  30. LinkValue *name_value;
  31. setResultCore(result);
  32. parserArgumentUnion(ap, arg, CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  33. if (!CHECK_RESULT(result))
  34. return result->type;
  35. freeResult(result);
  36. name_value = findAttributes(inter->data.object_name, false, ap[0].value, inter);
  37. if (name_value != NULL){
  38. gc_addTmpLink(&name_value->gc_status);
  39. name = getRepoStr(name_value, is_repo, 0, "sys", CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  40. gc_freeTmpLink(&name_value->gc_status);
  41. if (!CHECK_RESULT(result))
  42. return result->type;
  43. freeResult(result);
  44. } else
  45. name = L"unknown";
  46. if (ap[0].value->value->type == none) {
  47. repo = memWidecpy(L"null");
  48. } else {
  49. size_t len;
  50. if (ap[0].value->value->type == class)
  51. type = L"class";
  52. else
  53. type = L"object";
  54. len = memWidelen(name) + 30;
  55. repo = memCalloc(len, sizeof(char ));
  56. swprintf(repo, len, (const wchar_t *) L"(%ls: %ls on %p)", type, name, ap[0].value->value);
  57. }
  58. makeStringValue(repo, 0, "object.repo", CALL_INTER_FUNCTIONSIG_NOT_ST(var_list, result, belong));
  59. memFree(repo);
  60. return result->type;
  61. }
  62. ResultType object_repo(OFFICAL_FUNCTIONSIG){
  63. return objectRepoStrCore(CALL_OFFICAL_FUNCTION(arg, var_list, result, belong), true);
  64. }
  65. ResultType object_str(OFFICAL_FUNCTIONSIG){
  66. return objectRepoStrCore(CALL_OFFICAL_FUNCTION(arg, var_list, result, belong), false);
  67. }
  68. void registeredObject(REGISTERED_FUNCTIONSIG){
  69. LinkValue *object = inter->data.object;
  70. NameFunc tmp[] = {{inter->data.object_new, object_new, class_free_},
  71. {inter->data.object_repo, object_repo, all_free_},
  72. {inter->data.object_str, object_str, all_free_},
  73. {NULL, NULL}};
  74. gc_addTmpLink(&object->gc_status);
  75. addBaseClassVar("object", object, belong, inter);
  76. iterBaseClassFunc(tmp, object, CALL_INTER_FUNCTIONSIG_CORE(inter->var_list));
  77. gc_freeTmpLink(&object->gc_status);
  78. }
  79. void makeBaseObject(Inter *inter, LinkValue *belong){
  80. LinkValue *g_belong;
  81. Value *object = makeClassValue(inter->var_list, inter, NULL);
  82. {
  83. Value *global_belong = makeObject(inter, copyVarList(inter->var_list, false, inter), NULL, NULL);
  84. g_belong = makeLinkValue(global_belong, belong, inter);
  85. inter->base_belong = g_belong;
  86. gc_addStatementLink(&inter->base_belong->gc_status);
  87. }
  88. inter->data.object = makeLinkValue(object, g_belong, inter);
  89. gc_addStatementLink(&inter->data.object->gc_status);
  90. for (Inherit *ih=g_belong->value->object.inherit; ih != NULL; ih = ih->next) {
  91. if (ih->value->value == object)
  92. ih->value->belong = g_belong;
  93. }
  94. {
  95. Result result;
  96. Argument *arg = makeValueArgument(makeLinkValue(object, g_belong, inter));
  97. setResultCore(&result);
  98. object_new(CALL_OFFICAL_FUNCTION(arg, inter->var_list, &result, g_belong));
  99. result.value->value->type = none;
  100. inter->data.none = result.value;
  101. gc_addStatementLink(&inter->data.none->gc_status);
  102. freeArgument(arg, true);
  103. freeResult(&result);
  104. }
  105. }