bool.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #include "__ofunc.h"
  2. ResultType bool_new(O_FUNC){
  3. LinkValue *value = NULL;
  4. ArgumentParser ap[] = {{.type=only_value, .must=1, .long_arg=false},
  5. {.must=-1}};
  6. int status = 1;
  7. setResultCore(result);
  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. value->value->type = V_bool;
  15. value->value->data.bool_.bool_ = false;
  16. run_init(value, arg, LINEFILE, CNEXT_NT);
  17. return result->type;
  18. }
  19. ResultType bool_init(O_FUNC){
  20. ArgumentParser ap[] = {{.type=only_value, .must=1, .long_arg=false},
  21. {.type=only_value, .must=0, .long_arg=false},
  22. {.must=-1}};
  23. LinkValue *base;
  24. bool new = false;
  25. setResultCore(result);
  26. parserArgumentUnion(ap, arg, CNEXT_NT);
  27. if (!CHECK_RESULT(result))
  28. return result->type;
  29. freeResult(result);
  30. base = ap[0].value;
  31. if (ap[1].value != NULL) {
  32. new = checkBool(ap[1].value, LINEFILE, CNEXT_NT);
  33. if (!CHECK_RESULT(result))
  34. return result->type;
  35. freeResult(result);
  36. }
  37. base->value->data.bool_.bool_ = new;
  38. setResultBase(result, inter);
  39. return result->type;
  40. }
  41. void registeredBool(R_FUNC){
  42. LinkValue *object = inter->data.bool_;
  43. NameFunc tmp[] = {{inter->data.object_new, bool_new, class_free_},
  44. {inter->data.object_init, bool_init, object_free_},
  45. {NULL, NULL}};
  46. gc_addTmpLink(&object->gc_status);
  47. addBaseClassVar(L"bool", object, belong, inter);
  48. iterBaseClassFunc(tmp, object, CFUNC_CORE(inter->var_list));
  49. gc_freeTmpLink(&object->gc_status);
  50. }
  51. void makeBaseBool(Inter *inter){
  52. LinkValue *bool_ = makeBaseChildClass(inter->data.vobject, inter);
  53. gc_addStatementLink(&bool_->gc_status);
  54. inter->data.bool_ = bool_;
  55. }