rls.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /* This file is part of rls.
  2. *
  3. * Rls 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. * Rls 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 rls. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #ifndef RLS_H
  17. #define RLS_H
  18. /*
  19. Include:
  20. something with size_t
  21. #include <rid.h>
  22. #include <stdint.h>
  23. #include <unfy/unfy.h>
  24. #include <rls/rls.h>
  25. */
  26. #ifndef STYLE_9
  27. #include <rid.h>
  28. #include <stdint.h>
  29. #include <unfy/unfy.h>
  30. #endif
  31. typedef struct Rls_rule Rls_rule;
  32. typedef struct Rls_srch Rls_srch;
  33. typedef struct {
  34. Rls_rule *rules;
  35. Rls_srch *srchs;
  36. Unfy_recycle unfy;
  37. } Rls_recycle;
  38. typedef enum { RLS_SRCH, RLS_RUN } Rls_mode;
  39. typedef Unfy_stat (*Rls_act)(Rls_mode mode, Rls_srch *srch, void *extra);
  40. struct Rls_rule {
  41. Rls_rule *next;
  42. Unfy_term *head;
  43. void *dat;
  44. Rid id;
  45. union {
  46. Unfy_list *body;
  47. Rls_act act;
  48. } u;
  49. uint16_t size;
  50. uint16_t max_binds;
  51. uint8_t actable;
  52. };
  53. struct Rls_srch {
  54. Rls_srch *up;
  55. Unfy_term *term;
  56. Rls_rule *rule;
  57. Unfy_bind *lbind;
  58. Unfy_bind *rbind;
  59. Unfy_bind *nbind; /* name binds */
  60. Unfy_bind *fbind; /* final lbinds */
  61. Rls_srch **body;
  62. uint16_t num;
  63. };
  64. typedef enum {
  65. RLS_RSN_OKAY,
  66. RLS_RSN_END,
  67. RLS_RSN_LIMIT,
  68. RLS_RSN_UNFY,
  69. } Rls_rsn;
  70. typedef enum {
  71. RLS_DIF_SAME,
  72. RLS_DIF_ERR,
  73. RLS_DIF_NULL,
  74. /* check info for info */
  75. RLS_DIF_HEAD,
  76. RLS_DIF_BODY,
  77. RLS_DIF_ACTABLE,
  78. RLS_DIF_ACT,
  79. } Rls_dif;
  80. typedef struct {
  81. Unfy_info unfy;
  82. Unfy_bind *nbind;
  83. Unfy_term *term;
  84. Unfy_term *nterm;
  85. Rls_rule *rule;
  86. Rls_rsn rsn;
  87. unsigned lull : 1; /* Stop if head fails to unify */
  88. unsigned miss : 1; /* Ignore successful unification of head */
  89. } Rls_info;
  90. typedef struct Rls_bndr Rls_bndr;
  91. /* if stat is NULL then initialize rules on inability to find them */
  92. typedef Rls_rule **(*Rls_bend)(const Unfy_term *term, Unfy_stat *stat,
  93. void *extra);
  94. typedef void (*Rls_dat_free)(void *dat, void *extra);
  95. /* info */
  96. int
  97. rls_info_init(Rls_info *info, Unfy_term *term,
  98. Rls_rule *rules, Rls_recycle *rec);
  99. void
  100. rls_info_dispose(Rls_info *info, Rls_recycle *rec);
  101. /* void */
  102. /* rls_info_change(Rls_info *info, Unfy_term *term, */
  103. /* Rls_rule *rules, Rls_recycle *rec); */
  104. /* void */
  105. /* rls_info_next(Rls_info *info, Rls_recycle *rec); */
  106. /* recycle */
  107. void
  108. rls_recycle_init(Rls_recycle *rec);
  109. void
  110. rls_recycle_empty(Rls_recycle *rec);
  111. void
  112. rls_recycle_rule(Rls_recycle *rec, Rls_rule *rule,
  113. Rls_dat_free dat_free, void *extra);
  114. void
  115. rls_recycle_srch(Rls_recycle *rec, Rls_srch *srch);
  116. /* rule */
  117. int
  118. rls_rule_add(Rls_rule **rule, const Rid id, Unfy_term *head,
  119. Unfy_list *body, void *dat, Rls_recycle *rec);
  120. int
  121. rls_rule_add_actable(Rls_rule **rule, const Rid id, Unfy_term *head,
  122. Rls_act act, void *dat, Rls_recycle *rec);
  123. Rls_dif
  124. rls_rule_same(Unfy_info *info, Rls_rule *left, Rls_rule *right,
  125. Rls_recycle *rec);
  126. Unfy_stat
  127. rls_rule_query(Rls_info *info, Rls_recycle *rec);
  128. /* srch */
  129. Unfy_stat
  130. rls_srch_limit(Rls_srch **srch_ref, Unfy_term *term, Rls_rule *rules,
  131. int *limit, Rls_bend bend, Rls_info *info, void *extra,
  132. Rls_recycle *rec);
  133. Unfy_stat
  134. rls_srch(Rls_srch **srch_ref, Unfy_term *term, Rls_rule *rules,
  135. Rls_bend bend, Rls_info *info, void *extra, Rls_recycle *rec);
  136. void
  137. rls_srch_next(Rls_srch **srch);
  138. int
  139. rls_srch_same_next(Rls_srch **left, Rls_srch **right);
  140. Rls_dif
  141. rls_srch_same(Unfy_info *info, Rls_srch **left, Rls_srch **right,
  142. Rls_recycle *rec);
  143. Unfy_stat
  144. rls_srch_run(Rls_srch *srch, void *extra);
  145. #endif