unfy.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /* This file is part of unfy.
  2. *
  3. * Unfy is free software: you can redistribute it and/or modify
  4. * it under the terms of the GNU Lesser General Public License as published by
  5. * the Free Software Foundation, either version 3 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * Unfy is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU Lesser General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU Lesser General Public License
  14. * along with unfy. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #ifndef UNFY_H
  17. #define UNFY_H
  18. /*
  19. Include:
  20. something with size_t
  21. #include <rid.h>
  22. #include <unfy/unfy.h>
  23. */
  24. #ifndef STYLE_9
  25. #include <rid.h>
  26. #endif
  27. typedef enum {
  28. UNFY_RSN_OKAY,
  29. UNFY_RSN_VAL,
  30. UNFY_RSN_TYPE,
  31. UNFY_RSN_LEN,
  32. UNFY_RSN_SELF,
  33. UNFY_RSN_FORM,
  34. } Unfy_rsn;
  35. typedef enum {
  36. UNFY_CONST = 0,
  37. UNFY_ORDER,
  38. UNFY_IGN,
  39. UNFY_LIST,
  40. UNFY_VAR,
  41. } Unfy_type;
  42. typedef enum {
  43. UNFY_YES,
  44. UNFY_NO,
  45. UNFY_ERR,
  46. } Unfy_stat;
  47. typedef struct Unfy_list Unfy_list;
  48. typedef struct {
  49. Unfy_type type;
  50. union {
  51. Rid id;
  52. Unfy_list *list;
  53. void *dat;
  54. size_t order;
  55. } u;
  56. } Unfy_term;
  57. struct Unfy_list {
  58. Unfy_list *next;
  59. Unfy_term *term;
  60. };
  61. typedef struct Unfy_bind Unfy_bind;
  62. struct Unfy_bind {
  63. Unfy_bind *next;
  64. Rid var_id;
  65. Unfy_term *term;
  66. };
  67. typedef struct {
  68. Unfy_term *terms;
  69. Unfy_list *lists;
  70. Unfy_bind *binds;
  71. } Unfy_recycle;
  72. typedef struct {
  73. Unfy_bind *lbind;
  74. Unfy_bind *rbind;
  75. Unfy_rsn rsn;
  76. Unfy_term *left;
  77. Unfy_term *right;
  78. Unfy_term *lvar;
  79. Unfy_term *rvar;
  80. } Unfy_info;
  81. /* recycle */
  82. void
  83. unfy_recycle_init(Unfy_recycle *rec);
  84. void
  85. unfy_recycle_empty(Unfy_recycle *rec);
  86. void
  87. unfy_recycle_term(Unfy_recycle *rec, Unfy_term *term);
  88. void
  89. unfy_recycle_list(Unfy_recycle *rec, Unfy_list *list);
  90. void
  91. unfy_recycle_bind(Unfy_recycle *rec, Unfy_bind *bind);
  92. /* term */
  93. Unfy_term *
  94. unfy_term(Unfy_type type, void *dat, Unfy_recycle *rec);
  95. Unfy_term *
  96. unfy_term_id(Unfy_type type, const Rid id, Unfy_recycle *rec);
  97. Unfy_term *
  98. unfy_term_copy(const Unfy_term *term, Unfy_recycle *rec);
  99. void
  100. unfy_term_init(Unfy_term *term, Unfy_type type, void *dat);
  101. int
  102. unfy_term_init_copy(Unfy_term *des, const Unfy_term *src, Unfy_recycle *rec);
  103. Unfy_stat
  104. unfy_term_same(Unfy_info *info, Unfy_recycle *rec);
  105. int
  106. unfy_term_revar(const Unfy_term *term, Unfy_bind **bind, Unfy_recycle *rec);
  107. /* list */
  108. Unfy_list *
  109. unfy_list(Unfy_term *term, Unfy_list *next, Unfy_recycle *rec);
  110. int
  111. unfy_list_copy(Unfy_list **copy, const Unfy_list *list, Unfy_recycle *rec);
  112. void
  113. unfy_list_init(Unfy_list *list, Unfy_term *term, Unfy_list *next);
  114. int
  115. unfy_list_init_copy(Unfy_list *copy, const Unfy_list *list, Unfy_recycle *rec);
  116. Unfy_stat
  117. unfy_list_same(Unfy_info *info, Unfy_list *llist, Unfy_list *rlist,
  118. Unfy_recycle *rec);
  119. Unfy_list **
  120. unfy_list_append(Unfy_list **tail, Unfy_term *term, Unfy_recycle *rec);
  121. /* binding */
  122. int
  123. unfy_bind(Unfy_bind **bind, const Rid var_id, Unfy_term *term,
  124. Unfy_recycle *rec);
  125. Unfy_bind *
  126. unfy_bind_copy(const Unfy_bind *bind, Unfy_recycle *rec);
  127. Unfy_term *
  128. unfy_bind_get(const Unfy_bind *bind, const Rid var_id);
  129. Unfy_stat
  130. unfy_bind_replace(Unfy_bind *bind, const Rid var_id, const Unfy_term *val,
  131. Unfy_recycle *rec);
  132. Unfy_term *
  133. unfy_term_bind(const Unfy_term *term, const Unfy_bind *bind, Unfy_recycle *rec);
  134. int
  135. unfy_term_bind_set(Unfy_term *term, const Unfy_bind *bind, Unfy_recycle *rec);
  136. /* unification */
  137. void
  138. unfy_info_init(Unfy_info *info, Unfy_term *left, Unfy_term *right);
  139. void
  140. unfy_info_dispose(Unfy_info *info, Unfy_recycle *rec);
  141. Unfy_stat
  142. unfy_unify(Unfy_info *info, Unfy_recycle *rec);
  143. #endif