clipsruby 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (346) hide show
  1. checksums.yaml +7 -0
  2. data/ext/clipsruby/agenda.c +1373 -0
  3. data/ext/clipsruby/agenda.h +169 -0
  4. data/ext/clipsruby/analysis.c +1142 -0
  5. data/ext/clipsruby/analysis.h +61 -0
  6. data/ext/clipsruby/argacces.c +526 -0
  7. data/ext/clipsruby/argacces.h +77 -0
  8. data/ext/clipsruby/bload.c +884 -0
  9. data/ext/clipsruby/bload.h +94 -0
  10. data/ext/clipsruby/bmathfun.c +557 -0
  11. data/ext/clipsruby/bmathfun.h +66 -0
  12. data/ext/clipsruby/bsave.c +634 -0
  13. data/ext/clipsruby/bsave.h +130 -0
  14. data/ext/clipsruby/classcom.c +976 -0
  15. data/ext/clipsruby/classcom.h +115 -0
  16. data/ext/clipsruby/classexm.c +1376 -0
  17. data/ext/clipsruby/classexm.h +97 -0
  18. data/ext/clipsruby/classfun.c +1392 -0
  19. data/ext/clipsruby/classfun.h +164 -0
  20. data/ext/clipsruby/classinf.c +1245 -0
  21. data/ext/clipsruby/classinf.h +94 -0
  22. data/ext/clipsruby/classini.c +843 -0
  23. data/ext/clipsruby/classini.h +75 -0
  24. data/ext/clipsruby/classpsr.c +957 -0
  25. data/ext/clipsruby/classpsr.h +73 -0
  26. data/ext/clipsruby/clips.h +133 -0
  27. data/ext/clipsruby/clipsruby.c +619 -0
  28. data/ext/clipsruby/clsltpsr.c +931 -0
  29. data/ext/clipsruby/clsltpsr.h +72 -0
  30. data/ext/clipsruby/commline.c +1217 -0
  31. data/ext/clipsruby/commline.h +131 -0
  32. data/ext/clipsruby/conscomp.c +1593 -0
  33. data/ext/clipsruby/conscomp.h +150 -0
  34. data/ext/clipsruby/constant.h +264 -0
  35. data/ext/clipsruby/constrct.c +1090 -0
  36. data/ext/clipsruby/constrct.h +216 -0
  37. data/ext/clipsruby/constrnt.c +554 -0
  38. data/ext/clipsruby/constrnt.h +132 -0
  39. data/ext/clipsruby/crstrtgy.c +1088 -0
  40. data/ext/clipsruby/crstrtgy.h +85 -0
  41. data/ext/clipsruby/cstrcbin.c +185 -0
  42. data/ext/clipsruby/cstrcbin.h +61 -0
  43. data/ext/clipsruby/cstrccmp.h +43 -0
  44. data/ext/clipsruby/cstrccom.c +1791 -0
  45. data/ext/clipsruby/cstrccom.h +115 -0
  46. data/ext/clipsruby/cstrcpsr.c +835 -0
  47. data/ext/clipsruby/cstrcpsr.h +97 -0
  48. data/ext/clipsruby/cstrnbin.c +282 -0
  49. data/ext/clipsruby/cstrnbin.h +55 -0
  50. data/ext/clipsruby/cstrnchk.c +826 -0
  51. data/ext/clipsruby/cstrnchk.h +91 -0
  52. data/ext/clipsruby/cstrncmp.c +238 -0
  53. data/ext/clipsruby/cstrncmp.h +57 -0
  54. data/ext/clipsruby/cstrnops.c +1176 -0
  55. data/ext/clipsruby/cstrnops.h +47 -0
  56. data/ext/clipsruby/cstrnpsr.c +1394 -0
  57. data/ext/clipsruby/cstrnpsr.h +88 -0
  58. data/ext/clipsruby/cstrnutl.c +564 -0
  59. data/ext/clipsruby/cstrnutl.h +54 -0
  60. data/ext/clipsruby/default.c +454 -0
  61. data/ext/clipsruby/default.h +57 -0
  62. data/ext/clipsruby/defins.c +971 -0
  63. data/ext/clipsruby/defins.h +127 -0
  64. data/ext/clipsruby/developr.c +677 -0
  65. data/ext/clipsruby/developr.h +69 -0
  66. data/ext/clipsruby/dffctbin.c +477 -0
  67. data/ext/clipsruby/dffctbin.h +76 -0
  68. data/ext/clipsruby/dffctbsc.c +308 -0
  69. data/ext/clipsruby/dffctbsc.h +72 -0
  70. data/ext/clipsruby/dffctcmp.c +297 -0
  71. data/ext/clipsruby/dffctcmp.h +44 -0
  72. data/ext/clipsruby/dffctdef.c +364 -0
  73. data/ext/clipsruby/dffctdef.h +104 -0
  74. data/ext/clipsruby/dffctpsr.c +179 -0
  75. data/ext/clipsruby/dffctpsr.h +49 -0
  76. data/ext/clipsruby/dffnxbin.c +520 -0
  77. data/ext/clipsruby/dffnxbin.h +67 -0
  78. data/ext/clipsruby/dffnxcmp.c +378 -0
  79. data/ext/clipsruby/dffnxcmp.h +54 -0
  80. data/ext/clipsruby/dffnxexe.c +241 -0
  81. data/ext/clipsruby/dffnxexe.h +58 -0
  82. data/ext/clipsruby/dffnxfun.c +1192 -0
  83. data/ext/clipsruby/dffnxfun.h +155 -0
  84. data/ext/clipsruby/dffnxpsr.c +514 -0
  85. data/ext/clipsruby/dffnxpsr.h +57 -0
  86. data/ext/clipsruby/dfinsbin.c +509 -0
  87. data/ext/clipsruby/dfinsbin.h +66 -0
  88. data/ext/clipsruby/dfinscmp.c +345 -0
  89. data/ext/clipsruby/dfinscmp.h +48 -0
  90. data/ext/clipsruby/drive.c +1191 -0
  91. data/ext/clipsruby/drive.h +65 -0
  92. data/ext/clipsruby/emathfun.c +1213 -0
  93. data/ext/clipsruby/emathfun.h +99 -0
  94. data/ext/clipsruby/engine.c +1568 -0
  95. data/ext/clipsruby/engine.h +203 -0
  96. data/ext/clipsruby/entities.h +276 -0
  97. data/ext/clipsruby/envrnbld.c +514 -0
  98. data/ext/clipsruby/envrnbld.h +40 -0
  99. data/ext/clipsruby/envrnmnt.c +257 -0
  100. data/ext/clipsruby/envrnmnt.h +112 -0
  101. data/ext/clipsruby/evaluatn.c +1736 -0
  102. data/ext/clipsruby/evaluatn.h +211 -0
  103. data/ext/clipsruby/expressn.c +494 -0
  104. data/ext/clipsruby/expressn.h +154 -0
  105. data/ext/clipsruby/exprnbin.c +538 -0
  106. data/ext/clipsruby/exprnbin.h +60 -0
  107. data/ext/clipsruby/exprnops.c +564 -0
  108. data/ext/clipsruby/exprnops.h +67 -0
  109. data/ext/clipsruby/exprnpsr.c +1112 -0
  110. data/ext/clipsruby/exprnpsr.h +98 -0
  111. data/ext/clipsruby/extconf.rb +2 -0
  112. data/ext/clipsruby/extnfunc.c +1015 -0
  113. data/ext/clipsruby/extnfunc.h +157 -0
  114. data/ext/clipsruby/factbin.c +447 -0
  115. data/ext/clipsruby/factbin.h +56 -0
  116. data/ext/clipsruby/factbld.c +1035 -0
  117. data/ext/clipsruby/factbld.h +63 -0
  118. data/ext/clipsruby/factcmp.c +386 -0
  119. data/ext/clipsruby/factcmp.h +46 -0
  120. data/ext/clipsruby/factcom.c +759 -0
  121. data/ext/clipsruby/factcom.h +80 -0
  122. data/ext/clipsruby/factfile.c +1761 -0
  123. data/ext/clipsruby/factfile.h +54 -0
  124. data/ext/clipsruby/factfun.c +682 -0
  125. data/ext/clipsruby/factfun.h +77 -0
  126. data/ext/clipsruby/factgen.c +1305 -0
  127. data/ext/clipsruby/factgen.h +229 -0
  128. data/ext/clipsruby/facthsh.c +438 -0
  129. data/ext/clipsruby/facthsh.h +81 -0
  130. data/ext/clipsruby/factlhs.c +250 -0
  131. data/ext/clipsruby/factlhs.h +54 -0
  132. data/ext/clipsruby/factmch.c +905 -0
  133. data/ext/clipsruby/factmch.h +68 -0
  134. data/ext/clipsruby/factmngr.c +3373 -0
  135. data/ext/clipsruby/factmngr.h +325 -0
  136. data/ext/clipsruby/factprt.c +498 -0
  137. data/ext/clipsruby/factprt.h +60 -0
  138. data/ext/clipsruby/factqpsr.c +796 -0
  139. data/ext/clipsruby/factqpsr.h +61 -0
  140. data/ext/clipsruby/factqury.c +1267 -0
  141. data/ext/clipsruby/factqury.h +112 -0
  142. data/ext/clipsruby/factrete.c +978 -0
  143. data/ext/clipsruby/factrete.h +70 -0
  144. data/ext/clipsruby/factrhs.c +667 -0
  145. data/ext/clipsruby/factrhs.h +55 -0
  146. data/ext/clipsruby/filecom.c +353 -0
  147. data/ext/clipsruby/filecom.h +137 -0
  148. data/ext/clipsruby/filertr.c +481 -0
  149. data/ext/clipsruby/filertr.h +94 -0
  150. data/ext/clipsruby/fileutil.c +1020 -0
  151. data/ext/clipsruby/fileutil.h +50 -0
  152. data/ext/clipsruby/generate.c +1079 -0
  153. data/ext/clipsruby/generate.h +57 -0
  154. data/ext/clipsruby/genrcbin.c +902 -0
  155. data/ext/clipsruby/genrcbin.h +69 -0
  156. data/ext/clipsruby/genrccmp.c +640 -0
  157. data/ext/clipsruby/genrccmp.h +59 -0
  158. data/ext/clipsruby/genrccom.c +2017 -0
  159. data/ext/clipsruby/genrccom.h +119 -0
  160. data/ext/clipsruby/genrcexe.c +737 -0
  161. data/ext/clipsruby/genrcexe.h +73 -0
  162. data/ext/clipsruby/genrcfun.c +890 -0
  163. data/ext/clipsruby/genrcfun.h +185 -0
  164. data/ext/clipsruby/genrcpsr.c +1618 -0
  165. data/ext/clipsruby/genrcpsr.h +80 -0
  166. data/ext/clipsruby/globlbin.c +458 -0
  167. data/ext/clipsruby/globlbin.h +71 -0
  168. data/ext/clipsruby/globlbsc.c +361 -0
  169. data/ext/clipsruby/globlbsc.h +83 -0
  170. data/ext/clipsruby/globlcmp.c +330 -0
  171. data/ext/clipsruby/globlcmp.h +52 -0
  172. data/ext/clipsruby/globlcom.c +289 -0
  173. data/ext/clipsruby/globlcom.h +63 -0
  174. data/ext/clipsruby/globldef.c +1087 -0
  175. data/ext/clipsruby/globldef.h +151 -0
  176. data/ext/clipsruby/globlpsr.c +530 -0
  177. data/ext/clipsruby/globlpsr.h +59 -0
  178. data/ext/clipsruby/immthpsr.c +431 -0
  179. data/ext/clipsruby/immthpsr.h +55 -0
  180. data/ext/clipsruby/incrrset.c +530 -0
  181. data/ext/clipsruby/incrrset.h +73 -0
  182. data/ext/clipsruby/inherpsr.c +850 -0
  183. data/ext/clipsruby/inherpsr.h +52 -0
  184. data/ext/clipsruby/inscom.c +2076 -0
  185. data/ext/clipsruby/inscom.h +182 -0
  186. data/ext/clipsruby/insfile.c +1764 -0
  187. data/ext/clipsruby/insfile.h +96 -0
  188. data/ext/clipsruby/insfun.c +1451 -0
  189. data/ext/clipsruby/insfun.h +134 -0
  190. data/ext/clipsruby/insmngr.c +2550 -0
  191. data/ext/clipsruby/insmngr.h +125 -0
  192. data/ext/clipsruby/insmoddp.c +1041 -0
  193. data/ext/clipsruby/insmoddp.h +91 -0
  194. data/ext/clipsruby/insmult.c +804 -0
  195. data/ext/clipsruby/insmult.h +62 -0
  196. data/ext/clipsruby/inspsr.c +602 -0
  197. data/ext/clipsruby/inspsr.h +60 -0
  198. data/ext/clipsruby/insquery.c +1278 -0
  199. data/ext/clipsruby/insquery.h +115 -0
  200. data/ext/clipsruby/insqypsr.c +729 -0
  201. data/ext/clipsruby/insqypsr.h +63 -0
  202. data/ext/clipsruby/iofun.c +2045 -0
  203. data/ext/clipsruby/iofun.h +116 -0
  204. data/ext/clipsruby/lgcldpnd.c +644 -0
  205. data/ext/clipsruby/lgcldpnd.h +75 -0
  206. data/ext/clipsruby/main.c +112 -0
  207. data/ext/clipsruby/match.h +142 -0
  208. data/ext/clipsruby/memalloc.c +481 -0
  209. data/ext/clipsruby/memalloc.h +197 -0
  210. data/ext/clipsruby/miscfun.c +1801 -0
  211. data/ext/clipsruby/miscfun.h +132 -0
  212. data/ext/clipsruby/modulbin.c +607 -0
  213. data/ext/clipsruby/modulbin.h +84 -0
  214. data/ext/clipsruby/modulbsc.c +347 -0
  215. data/ext/clipsruby/modulbsc.h +67 -0
  216. data/ext/clipsruby/modulcmp.c +499 -0
  217. data/ext/clipsruby/modulcmp.h +54 -0
  218. data/ext/clipsruby/moduldef.c +817 -0
  219. data/ext/clipsruby/moduldef.h +271 -0
  220. data/ext/clipsruby/modulpsr.c +1150 -0
  221. data/ext/clipsruby/modulpsr.h +69 -0
  222. data/ext/clipsruby/modulutl.c +1036 -0
  223. data/ext/clipsruby/modulutl.h +84 -0
  224. data/ext/clipsruby/msgcom.c +1221 -0
  225. data/ext/clipsruby/msgcom.h +125 -0
  226. data/ext/clipsruby/msgfun.c +1076 -0
  227. data/ext/clipsruby/msgfun.h +118 -0
  228. data/ext/clipsruby/msgpass.c +1441 -0
  229. data/ext/clipsruby/msgpass.h +103 -0
  230. data/ext/clipsruby/msgpsr.c +698 -0
  231. data/ext/clipsruby/msgpsr.h +73 -0
  232. data/ext/clipsruby/multifld.c +1404 -0
  233. data/ext/clipsruby/multifld.h +130 -0
  234. data/ext/clipsruby/multifun.c +2182 -0
  235. data/ext/clipsruby/multifun.h +102 -0
  236. data/ext/clipsruby/network.h +142 -0
  237. data/ext/clipsruby/objbin.c +1522 -0
  238. data/ext/clipsruby/objbin.h +79 -0
  239. data/ext/clipsruby/objcmp.c +1507 -0
  240. data/ext/clipsruby/objcmp.h +71 -0
  241. data/ext/clipsruby/object.h +260 -0
  242. data/ext/clipsruby/objrtbin.c +701 -0
  243. data/ext/clipsruby/objrtbin.h +79 -0
  244. data/ext/clipsruby/objrtbld.c +2393 -0
  245. data/ext/clipsruby/objrtbld.h +66 -0
  246. data/ext/clipsruby/objrtcmp.c +734 -0
  247. data/ext/clipsruby/objrtcmp.h +66 -0
  248. data/ext/clipsruby/objrtfnx.c +1330 -0
  249. data/ext/clipsruby/objrtfnx.h +222 -0
  250. data/ext/clipsruby/objrtgen.c +736 -0
  251. data/ext/clipsruby/objrtgen.h +63 -0
  252. data/ext/clipsruby/objrtmch.c +1524 -0
  253. data/ext/clipsruby/objrtmch.h +160 -0
  254. data/ext/clipsruby/parsefun.c +415 -0
  255. data/ext/clipsruby/parsefun.h +67 -0
  256. data/ext/clipsruby/pattern.c +1265 -0
  257. data/ext/clipsruby/pattern.h +163 -0
  258. data/ext/clipsruby/pprint.c +328 -0
  259. data/ext/clipsruby/pprint.h +79 -0
  260. data/ext/clipsruby/prccode.c +1478 -0
  261. data/ext/clipsruby/prccode.h +145 -0
  262. data/ext/clipsruby/prcdrfun.c +640 -0
  263. data/ext/clipsruby/prcdrfun.h +95 -0
  264. data/ext/clipsruby/prcdrpsr.c +1068 -0
  265. data/ext/clipsruby/prcdrpsr.h +79 -0
  266. data/ext/clipsruby/prdctfun.c +869 -0
  267. data/ext/clipsruby/prdctfun.h +77 -0
  268. data/ext/clipsruby/prntutil.c +878 -0
  269. data/ext/clipsruby/prntutil.h +125 -0
  270. data/ext/clipsruby/proflfun.c +827 -0
  271. data/ext/clipsruby/proflfun.h +118 -0
  272. data/ext/clipsruby/reorder.c +2082 -0
  273. data/ext/clipsruby/reorder.h +172 -0
  274. data/ext/clipsruby/reteutil.c +1732 -0
  275. data/ext/clipsruby/reteutil.h +111 -0
  276. data/ext/clipsruby/retract.c +710 -0
  277. data/ext/clipsruby/retract.h +74 -0
  278. data/ext/clipsruby/router.c +737 -0
  279. data/ext/clipsruby/router.h +147 -0
  280. data/ext/clipsruby/rulebin.c +1136 -0
  281. data/ext/clipsruby/rulebin.h +153 -0
  282. data/ext/clipsruby/rulebld.c +1328 -0
  283. data/ext/clipsruby/rulebld.h +62 -0
  284. data/ext/clipsruby/rulebsc.c +517 -0
  285. data/ext/clipsruby/rulebsc.h +91 -0
  286. data/ext/clipsruby/rulecmp.c +733 -0
  287. data/ext/clipsruby/rulecmp.h +63 -0
  288. data/ext/clipsruby/rulecom.c +1583 -0
  289. data/ext/clipsruby/rulecom.h +116 -0
  290. data/ext/clipsruby/rulecstr.c +892 -0
  291. data/ext/clipsruby/rulecstr.h +53 -0
  292. data/ext/clipsruby/ruledef.c +559 -0
  293. data/ext/clipsruby/ruledef.h +179 -0
  294. data/ext/clipsruby/ruledlt.c +599 -0
  295. data/ext/clipsruby/ruledlt.h +58 -0
  296. data/ext/clipsruby/rulelhs.c +1216 -0
  297. data/ext/clipsruby/rulelhs.h +52 -0
  298. data/ext/clipsruby/rulepsr.c +1073 -0
  299. data/ext/clipsruby/rulepsr.h +61 -0
  300. data/ext/clipsruby/scanner.c +856 -0
  301. data/ext/clipsruby/scanner.h +112 -0
  302. data/ext/clipsruby/setup.h +488 -0
  303. data/ext/clipsruby/sortfun.c +433 -0
  304. data/ext/clipsruby/sortfun.h +55 -0
  305. data/ext/clipsruby/strngfun.c +1173 -0
  306. data/ext/clipsruby/strngfun.h +96 -0
  307. data/ext/clipsruby/strngrtr.c +523 -0
  308. data/ext/clipsruby/strngrtr.h +97 -0
  309. data/ext/clipsruby/symblbin.c +648 -0
  310. data/ext/clipsruby/symblbin.h +64 -0
  311. data/ext/clipsruby/symblcmp.c +893 -0
  312. data/ext/clipsruby/symblcmp.h +61 -0
  313. data/ext/clipsruby/symbol.c +1961 -0
  314. data/ext/clipsruby/symbol.h +243 -0
  315. data/ext/clipsruby/sysdep.c +894 -0
  316. data/ext/clipsruby/sysdep.h +164 -0
  317. data/ext/clipsruby/textpro.c +1388 -0
  318. data/ext/clipsruby/textpro.h +77 -0
  319. data/ext/clipsruby/tmpltbin.c +609 -0
  320. data/ext/clipsruby/tmpltbin.h +108 -0
  321. data/ext/clipsruby/tmpltbsc.c +327 -0
  322. data/ext/clipsruby/tmpltbsc.h +87 -0
  323. data/ext/clipsruby/tmpltcmp.c +450 -0
  324. data/ext/clipsruby/tmpltcmp.h +57 -0
  325. data/ext/clipsruby/tmpltdef.c +584 -0
  326. data/ext/clipsruby/tmpltdef.h +155 -0
  327. data/ext/clipsruby/tmpltfun.c +2477 -0
  328. data/ext/clipsruby/tmpltfun.h +122 -0
  329. data/ext/clipsruby/tmpltlhs.c +379 -0
  330. data/ext/clipsruby/tmpltlhs.h +50 -0
  331. data/ext/clipsruby/tmpltpsr.c +819 -0
  332. data/ext/clipsruby/tmpltpsr.h +59 -0
  333. data/ext/clipsruby/tmpltrhs.c +595 -0
  334. data/ext/clipsruby/tmpltrhs.h +55 -0
  335. data/ext/clipsruby/tmpltutl.c +637 -0
  336. data/ext/clipsruby/tmpltutl.h +82 -0
  337. data/ext/clipsruby/userdata.c +156 -0
  338. data/ext/clipsruby/userdata.h +72 -0
  339. data/ext/clipsruby/userfunctions.c +70 -0
  340. data/ext/clipsruby/usrsetup.h +7 -0
  341. data/ext/clipsruby/utility.c +1594 -0
  342. data/ext/clipsruby/utility.h +250 -0
  343. data/ext/clipsruby/watch.c +865 -0
  344. data/ext/clipsruby/watch.h +124 -0
  345. data/lib/clipsruby.rb +1 -0
  346. metadata +388 -0
@@ -0,0 +1,1192 @@
1
+ /*******************************************************/
2
+ /* "C" Language Integrated Production System */
3
+ /* */
4
+ /* CLIPS Version 6.40 07/02/18 */
5
+ /* */
6
+ /* DEFFUNCTION MODULE */
7
+ /*******************************************************/
8
+
9
+ /*************************************************************/
10
+ /* Purpose: */
11
+ /* */
12
+ /* Principal Programmer(s): */
13
+ /* Brian L. Dantes */
14
+ /* */
15
+ /* Contributing Programmer(s): */
16
+ /* Gary D. Riley */
17
+ /* */
18
+ /* Revision History: */
19
+ /* */
20
+ /* 6.23: Correction for FalseSymbol/TrueSymbol. DR0859 */
21
+ /* */
22
+ /* Corrected compilation errors for files */
23
+ /* generated by constructs-to-c. DR0861 */
24
+ /* */
25
+ /* Changed name of variable log to logName */
26
+ /* because of Unix compiler warnings of shadowed */
27
+ /* definitions. */
28
+ /* */
29
+ /* 6.24: Renamed BOOLEAN macro type to intBool. */
30
+ /* */
31
+ /* Corrected code to remove run-time program */
32
+ /* compiler warning. */
33
+ /* */
34
+ /* 6.30: Removed conditional code for unsupported */
35
+ /* compilers/operating systems (IBM_MCW, */
36
+ /* MAC_MCW, and IBM_TBC). */
37
+ /* */
38
+ /* Changed integer type/precision. */
39
+ /* */
40
+ /* Added missing initializer for ENTITY_RECORD. */
41
+ /* */
42
+ /* Added const qualifiers to remove C++ */
43
+ /* deprecation warnings. */
44
+ /* */
45
+ /* Converted API macros to function calls. */
46
+ /* */
47
+ /* Changed find construct functionality so that */
48
+ /* imported modules are search when locating a */
49
+ /* named construct. */
50
+ /* */
51
+ /* Added code to keep track of pointers to */
52
+ /* constructs that are contained externally to */
53
+ /* to constructs, DanglingConstructs. */
54
+ /* */
55
+ /* 6.40: Pragma once and other inclusion changes. */
56
+ /* */
57
+ /* Added support for booleans with <stdbool.h>. */
58
+ /* */
59
+ /* Removed use of void pointers for specific */
60
+ /* data structures. */
61
+ /* */
62
+ /* ALLOW_ENVIRONMENT_GLOBALS no longer supported. */
63
+ /* */
64
+ /* UDF redesign. */
65
+ /* */
66
+ /* Pretty print functions accept optional logical */
67
+ /* name argument. */
68
+ /* */
69
+ /*************************************************************/
70
+
71
+ /* =========================================
72
+ *****************************************
73
+ EXTERNAL DEFINITIONS
74
+ =========================================
75
+ ***************************************** */
76
+ #include "setup.h"
77
+
78
+ #if DEFFUNCTION_CONSTRUCT
79
+
80
+ #if (BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE)
81
+ #include "bload.h"
82
+ #include "dffnxbin.h"
83
+ #endif
84
+
85
+ #if CONSTRUCT_COMPILER && (! RUN_TIME)
86
+ #include "dffnxcmp.h"
87
+ #endif
88
+
89
+ #if (! BLOAD_ONLY) && (! RUN_TIME)
90
+ #include "constrct.h"
91
+ #include "cstrcpsr.h"
92
+ #include "dffnxpsr.h"
93
+ #include "modulpsr.h"
94
+ #endif
95
+
96
+ #include "envrnmnt.h"
97
+
98
+ #if (! RUN_TIME)
99
+ #include "extnfunc.h"
100
+ #endif
101
+
102
+ #include "dffnxexe.h"
103
+
104
+ #if DEBUGGING_FUNCTIONS
105
+ #include "watch.h"
106
+ #endif
107
+
108
+ #include "argacces.h"
109
+ #include "cstrccom.h"
110
+ #include "memalloc.h"
111
+ #include "modulutl.h"
112
+ #include "multifld.h"
113
+ #include "prntutil.h"
114
+ #include "router.h"
115
+
116
+ #include "dffnxfun.h"
117
+
118
+ /* =========================================
119
+ *****************************************
120
+ INTERNALLY VISIBLE FUNCTION HEADERS
121
+ =========================================
122
+ ***************************************** */
123
+
124
+ static void PrintDeffunctionCall(Environment *,const char *,Deffunction *);
125
+ static bool EvaluateDeffunctionCall(Environment *,Deffunction *,UDFValue *);
126
+ static void DecrementDeffunctionBusyCount(Environment *,Deffunction *);
127
+ static void IncrementDeffunctionBusyCount(Environment *,Deffunction *);
128
+ static void DeallocateDeffunctionData(Environment *);
129
+
130
+ #if ! RUN_TIME
131
+ static void DestroyDeffunctionAction(Environment *,ConstructHeader *,void *);
132
+ static void *AllocateModule(Environment *);
133
+ static void ReturnModule(Environment *,void *);
134
+ static bool ClearDeffunctionsReady(Environment *,void *);
135
+ #else
136
+ static void RuntimeDeffunctionAction(Environment *,ConstructHeader *,void *);
137
+ #endif
138
+
139
+ #if (! BLOAD_ONLY) && (! RUN_TIME)
140
+ static bool RemoveAllDeffunctions(Environment *);
141
+ static void DeffunctionDeleteError(Environment *,const char *);
142
+ static void SaveDeffunctionHeaders(Environment *,Defmodule *,const char *,void *);
143
+ static void SaveDeffunctionHeader(Environment *,ConstructHeader *,void *);
144
+ static void SaveDeffunctions(Environment *,Defmodule *,const char *,void *);
145
+ #endif
146
+
147
+ #if DEBUGGING_FUNCTIONS
148
+ static bool DeffunctionWatchAccess(Environment *,int,bool,Expression *);
149
+ static bool DeffunctionWatchPrint(Environment *,const char *,int,Expression *);
150
+ #endif
151
+
152
+ /* =========================================
153
+ *****************************************
154
+ EXTERNALLY VISIBLE FUNCTIONS
155
+ =========================================
156
+ ***************************************** */
157
+
158
+ /***************************************************
159
+ NAME : SetupDeffunctions
160
+ DESCRIPTION : Initializes parsers and access
161
+ functions for deffunctions
162
+ INPUTS : None
163
+ RETURNS : Nothing useful
164
+ SIDE EFFECTS : Deffunction environment initialized
165
+ NOTES : None
166
+ ***************************************************/
167
+ void SetupDeffunctions(
168
+ Environment *theEnv)
169
+ {
170
+ EntityRecord deffunctionEntityRecord =
171
+ { "PCALL", PCALL,0,0,1,
172
+ (EntityPrintFunction *) PrintDeffunctionCall,
173
+ (EntityPrintFunction *) PrintDeffunctionCall,
174
+ NULL,
175
+ (EntityEvaluationFunction *) EvaluateDeffunctionCall,
176
+ NULL,
177
+ (EntityBusyCountFunction *) DecrementDeffunctionBusyCount,
178
+ (EntityBusyCountFunction *) IncrementDeffunctionBusyCount,
179
+ NULL,NULL,NULL,NULL,NULL };
180
+
181
+ AllocateEnvironmentData(theEnv,DEFFUNCTION_DATA,sizeof(struct deffunctionData),DeallocateDeffunctionData);
182
+ memcpy(&DeffunctionData(theEnv)->DeffunctionEntityRecord,&deffunctionEntityRecord,sizeof(struct entityRecord));
183
+
184
+ InstallPrimitive(theEnv,&DeffunctionData(theEnv)->DeffunctionEntityRecord,PCALL);
185
+
186
+ DeffunctionData(theEnv)->DeffunctionModuleIndex =
187
+ RegisterModuleItem(theEnv,"deffunction",
188
+ #if (! RUN_TIME)
189
+ AllocateModule,
190
+ ReturnModule,
191
+ #else
192
+ NULL,NULL,
193
+ #endif
194
+ #if BLOAD_AND_BSAVE || BLOAD || BLOAD_ONLY
195
+ BloadDeffunctionModuleReference,
196
+ #else
197
+ NULL,
198
+ #endif
199
+ #if CONSTRUCT_COMPILER && (! RUN_TIME)
200
+ DeffunctionCModuleReference,
201
+ #else
202
+ NULL,
203
+ #endif
204
+ (FindConstructFunction *) FindDeffunctionInModule);
205
+ DeffunctionData(theEnv)->DeffunctionConstruct = AddConstruct(theEnv,"deffunction","deffunctions",
206
+ #if (! BLOAD_ONLY) && (! RUN_TIME)
207
+ ParseDeffunction,
208
+ #else
209
+ NULL,
210
+ #endif
211
+ (FindConstructFunction *) FindDeffunction,
212
+ GetConstructNamePointer,GetConstructPPForm,
213
+ GetConstructModuleItem,
214
+ (GetNextConstructFunction *) GetNextDeffunction,
215
+ SetNextConstruct,
216
+ (IsConstructDeletableFunction *) DeffunctionIsDeletable,
217
+ (DeleteConstructFunction *) Undeffunction,
218
+ #if (! BLOAD_ONLY) && (! RUN_TIME)
219
+ (FreeConstructFunction *) RemoveDeffunction
220
+ #else
221
+ NULL
222
+ #endif
223
+ );
224
+
225
+ #if ! RUN_TIME
226
+ AddClearReadyFunction(theEnv,"deffunction",ClearDeffunctionsReady,0,NULL);
227
+
228
+ #if ! BLOAD_ONLY
229
+ #if DEFMODULE_CONSTRUCT
230
+ AddPortConstructItem(theEnv,"deffunction",SYMBOL_TOKEN);
231
+ #endif
232
+ AddSaveFunction(theEnv,"deffunction-headers",SaveDeffunctionHeaders,1000,NULL);
233
+ AddSaveFunction(theEnv,"deffunctions",SaveDeffunctions,0,NULL);
234
+ AddUDF(theEnv,"undeffunction","v",1,1,"y",UndeffunctionCommand,"UndeffunctionCommand",NULL);
235
+ #endif
236
+
237
+ #if DEBUGGING_FUNCTIONS
238
+ AddUDF(theEnv,"list-deffunctions","v",0,1,"y",ListDeffunctionsCommand,"ListDeffunctionsCommand",NULL);
239
+ AddUDF(theEnv,"ppdeffunction","vs",1,2,";y;ldsyn",PPDeffunctionCommand,"PPDeffunctionCommand",NULL);
240
+ #endif
241
+
242
+ AddUDF(theEnv,"get-deffunction-list","m",0,1,"y",GetDeffunctionListFunction,"GetDeffunctionListFunction",NULL);
243
+ AddUDF(theEnv,"deffunction-module","y",1,1,"y",GetDeffunctionModuleCommand,"GetDeffunctionModuleCommand",NULL);
244
+
245
+ #if BLOAD_AND_BSAVE || BLOAD || BLOAD_ONLY
246
+ SetupDeffunctionsBload(theEnv);
247
+ #endif
248
+
249
+ #if CONSTRUCT_COMPILER
250
+ SetupDeffunctionCompiler(theEnv);
251
+ #endif
252
+
253
+ #endif
254
+
255
+ #if DEBUGGING_FUNCTIONS
256
+ AddWatchItem(theEnv,"deffunctions",0,&DeffunctionData(theEnv)->WatchDeffunctions,32,
257
+ DeffunctionWatchAccess,DeffunctionWatchPrint);
258
+ #endif
259
+
260
+ }
261
+
262
+ /******************************************************/
263
+ /* DeallocateDeffunctionData: Deallocates environment */
264
+ /* data for the deffunction construct. */
265
+ /******************************************************/
266
+ static void DeallocateDeffunctionData(
267
+ Environment *theEnv)
268
+ {
269
+ #if ! RUN_TIME
270
+ DeffunctionModuleData *theModuleItem;
271
+ Defmodule *theModule;
272
+
273
+ #if BLOAD || BLOAD_AND_BSAVE
274
+ if (Bloaded(theEnv)) return;
275
+ #endif
276
+
277
+ DoForAllConstructs(theEnv,
278
+ DestroyDeffunctionAction,
279
+ DeffunctionData(theEnv)->DeffunctionModuleIndex,false,NULL);
280
+
281
+ for (theModule = GetNextDefmodule(theEnv,NULL);
282
+ theModule != NULL;
283
+ theModule = GetNextDefmodule(theEnv,theModule))
284
+ {
285
+ theModuleItem = (struct deffunctionModuleData *)
286
+ GetModuleItem(theEnv,theModule,
287
+ DeffunctionData(theEnv)->DeffunctionModuleIndex);
288
+ rtn_struct(theEnv,deffunctionModuleData,theModuleItem);
289
+ }
290
+ #else
291
+ #if MAC_XCD
292
+ #pragma unused(theEnv)
293
+ #endif
294
+ #endif
295
+ }
296
+
297
+ #if ! RUN_TIME
298
+ /*****************************************************/
299
+ /* DestroyDeffunctionAction: Action used to remove */
300
+ /* deffunctions as a result of DestroyEnvironment. */
301
+ /*****************************************************/
302
+ static void DestroyDeffunctionAction(
303
+ Environment *theEnv,
304
+ ConstructHeader *theConstruct,
305
+ void *buffer)
306
+ {
307
+ #if MAC_XCD
308
+ #pragma unused(buffer)
309
+ #endif
310
+ #if (! BLOAD_ONLY) && (! RUN_TIME)
311
+ Deffunction *theDeffunction = (Deffunction *) theConstruct;
312
+
313
+ if (theDeffunction == NULL) return;
314
+
315
+ ReturnPackedExpression(theEnv,theDeffunction->code);
316
+
317
+ DestroyConstructHeader(theEnv,&theDeffunction->header);
318
+
319
+ rtn_struct(theEnv,deffunction,theDeffunction);
320
+ #else
321
+ #if MAC_XCD
322
+ #pragma unused(theConstruct,theEnv)
323
+ #endif
324
+ #endif
325
+ }
326
+ #endif
327
+
328
+ /***************************************************
329
+ NAME : FindDeffunction
330
+ DESCRIPTION : Searches for a deffunction
331
+ INPUTS : The name of the deffunction
332
+ (possibly including a module name)
333
+ RETURNS : Pointer to the deffunction if
334
+ found, otherwise NULL
335
+ SIDE EFFECTS : None
336
+ NOTES : None
337
+ ***************************************************/
338
+ Deffunction *FindDeffunction(
339
+ Environment *theEnv,
340
+ const char *dfnxModuleAndName)
341
+ {
342
+ return (Deffunction *) FindNamedConstructInModuleOrImports(theEnv,dfnxModuleAndName,DeffunctionData(theEnv)->DeffunctionConstruct);
343
+ }
344
+
345
+ /***************************************************
346
+ NAME : FindDeffunctionInModule
347
+ DESCRIPTION : Searches for a deffunction
348
+ INPUTS : The name of the deffunction
349
+ (possibly including a module name)
350
+ RETURNS : Pointer to the deffunction if
351
+ found, otherwise NULL
352
+ SIDE EFFECTS : None
353
+ NOTES : None
354
+ ***************************************************/
355
+ Deffunction *FindDeffunctionInModule(
356
+ Environment *theEnv,
357
+ const char *dfnxModuleAndName)
358
+ {
359
+ return (Deffunction *) FindNamedConstructInModule(theEnv,dfnxModuleAndName,DeffunctionData(theEnv)->DeffunctionConstruct);
360
+ }
361
+
362
+ /***************************************************
363
+ NAME : LookupDeffunctionByMdlOrScope
364
+ DESCRIPTION : Finds a deffunction anywhere (if
365
+ module is specified) or in current
366
+ or imported modules
367
+ INPUTS : The deffunction name
368
+ RETURNS : The deffunction (NULL if not found)
369
+ SIDE EFFECTS : Error message printed on
370
+ ambiguous references
371
+ NOTES : None
372
+ ***************************************************/
373
+ Deffunction *LookupDeffunctionByMdlOrScope(
374
+ Environment *theEnv,
375
+ const char *deffunctionName)
376
+ {
377
+ return((Deffunction *) LookupConstruct(theEnv,DeffunctionData(theEnv)->DeffunctionConstruct,deffunctionName,true));
378
+ }
379
+
380
+ /***************************************************
381
+ NAME : LookupDeffunctionInScope
382
+ DESCRIPTION : Finds a deffunction in current or
383
+ imported modules (module
384
+ specifier is not allowed)
385
+ INPUTS : The deffunction name
386
+ RETURNS : The deffunction (NULL if not found)
387
+ SIDE EFFECTS : Error message printed on
388
+ ambiguous references
389
+ NOTES : None
390
+ ***************************************************/
391
+ Deffunction *LookupDeffunctionInScope(
392
+ Environment *theEnv,
393
+ const char *deffunctionName)
394
+ {
395
+ return (Deffunction *) LookupConstruct(theEnv,DeffunctionData(theEnv)->DeffunctionConstruct,deffunctionName,false);
396
+ }
397
+
398
+ /***************************************************
399
+ NAME : Undeffunction
400
+ DESCRIPTION : External interface routine for
401
+ removing a deffunction
402
+ INPUTS : Deffunction pointer
403
+ RETURNS : False if unsuccessful,
404
+ true otherwise
405
+ SIDE EFFECTS : Deffunction deleted, if possible
406
+ NOTES : None
407
+ ***************************************************/
408
+ bool Undeffunction(
409
+ Deffunction *theDeffunction,
410
+ Environment *allEnv)
411
+ {
412
+ #if BLOAD_ONLY || RUN_TIME
413
+ return false;
414
+ #else
415
+ Environment *theEnv;
416
+ bool success;
417
+ GCBlock gcb;
418
+
419
+ if (theDeffunction == NULL)
420
+ { theEnv = allEnv; }
421
+ else
422
+ { theEnv = theDeffunction->header.env; }
423
+
424
+ #if BLOAD || BLOAD_AND_BSAVE
425
+ if (Bloaded(theEnv) == true)
426
+ return false;
427
+ #endif
428
+
429
+ GCBlockStart(theEnv,&gcb);
430
+ if (theDeffunction == NULL)
431
+ {
432
+ success = RemoveAllDeffunctions(theEnv);
433
+ GCBlockEnd(theEnv,&gcb);
434
+ return success;
435
+ }
436
+
437
+ if (DeffunctionIsDeletable(theDeffunction) == false)
438
+ {
439
+ GCBlockEnd(theEnv,&gcb);
440
+ return false;
441
+ }
442
+
443
+ RemoveConstructFromModule(theEnv,&theDeffunction->header);
444
+ RemoveDeffunction(theEnv,theDeffunction);
445
+ GCBlockEnd(theEnv,&gcb);
446
+
447
+ return true;
448
+ #endif
449
+ }
450
+
451
+ /****************************************************
452
+ NAME : GetNextDeffunction
453
+ DESCRIPTION : Accesses list of deffunctions
454
+ INPUTS : Deffunction pointer
455
+ RETURNS : The next deffunction, or the
456
+ first deffunction (if input is NULL)
457
+ SIDE EFFECTS : None
458
+ NOTES : None
459
+ ****************************************************/
460
+ Deffunction *GetNextDeffunction(
461
+ Environment *theEnv,
462
+ Deffunction *theDeffunction)
463
+ {
464
+ return (Deffunction *)
465
+ GetNextConstructItem(theEnv,&theDeffunction->header,
466
+ DeffunctionData(theEnv)->DeffunctionModuleIndex);
467
+ }
468
+
469
+ /***************************************************
470
+ NAME : DeffunctionIsDeletable
471
+ DESCRIPTION : Determines if a deffunction is
472
+ executing or referenced by another
473
+ expression
474
+ INPUTS : Deffunction pointer
475
+ RETURNS : True if the deffunction can
476
+ be deleted, false otherwise
477
+ SIDE EFFECTS : None
478
+ NOTES : None
479
+ ***************************************************/
480
+ bool DeffunctionIsDeletable(
481
+ Deffunction *theDeffunction)
482
+ {
483
+ Environment *theEnv = theDeffunction->header.env;
484
+
485
+ if (! ConstructsDeletable(theEnv))
486
+ { return false; }
487
+
488
+ return(((theDeffunction->busy == 0) && (theDeffunction->executing == 0)) ? true : false);
489
+ }
490
+
491
+ #if (! BLOAD_ONLY) && (! RUN_TIME)
492
+
493
+ /***************************************************
494
+ NAME : RemoveDeffunction
495
+ DESCRIPTION : Removes a deffunction
496
+ INPUTS : Deffunction pointer
497
+ RETURNS : Nothing useful
498
+ SIDE EFFECTS : Deffunction deallocated
499
+ NOTES : Assumes deffunction is not in use!!
500
+ ***************************************************/
501
+ void RemoveDeffunction(
502
+ Environment *theEnv,
503
+ Deffunction *theDeffunction)
504
+ {
505
+ if (theDeffunction == NULL)
506
+ return;
507
+ ReleaseLexeme(theEnv,GetDeffunctionNamePointer(theEnv,theDeffunction));
508
+ ExpressionDeinstall(theEnv,theDeffunction->code);
509
+ ReturnPackedExpression(theEnv,theDeffunction->code);
510
+ SetDeffunctionPPForm(theEnv,theDeffunction,NULL);
511
+ ClearUserDataList(theEnv,theDeffunction->header.usrData);
512
+ rtn_struct(theEnv,deffunction,theDeffunction);
513
+ }
514
+
515
+ #endif
516
+
517
+ /********************************************************
518
+ NAME : UndeffunctionCommand
519
+ DESCRIPTION : Deletes the named deffunction(s)
520
+ INPUTS : None
521
+ RETURNS : Nothing useful
522
+ SIDE EFFECTS : Deffunction(s) removed
523
+ NOTES : H/L Syntax: (undeffunction <name> | *)
524
+ ********************************************************/
525
+ void UndeffunctionCommand(
526
+ Environment *theEnv,
527
+ UDFContext *context,
528
+ UDFValue *returnValue)
529
+ {
530
+ UndefconstructCommand(context,"undeffunction",DeffunctionData(theEnv)->DeffunctionConstruct);
531
+ }
532
+
533
+ /****************************************************************
534
+ NAME : GetDeffunctionModuleCommand
535
+ DESCRIPTION : Determines to which module a deffunction belongs
536
+ INPUTS : None
537
+ RETURNS : The symbolic name of the module
538
+ SIDE EFFECTS : None
539
+ NOTES : H/L Syntax: (deffunction-module <dfnx-name>)
540
+ ****************************************************************/
541
+ void GetDeffunctionModuleCommand(
542
+ Environment *theEnv,
543
+ UDFContext *context,
544
+ UDFValue *returnValue)
545
+ {
546
+ returnValue->value = GetConstructModuleCommand(context,"deffunction-module",DeffunctionData(theEnv)->DeffunctionConstruct);
547
+ }
548
+
549
+ #if DEBUGGING_FUNCTIONS
550
+
551
+ /****************************************************
552
+ NAME : PPDeffunctionCommand
553
+ DESCRIPTION : Displays the pretty-print form of a
554
+ deffunction
555
+ INPUTS : None
556
+ RETURNS : Nothing useful
557
+ SIDE EFFECTS : Pretty-print form displayed to
558
+ STDOUT logical name
559
+ NOTES : H/L Syntax: (ppdeffunction <name>)
560
+ ****************************************************/
561
+ void PPDeffunctionCommand(
562
+ Environment *theEnv,
563
+ UDFContext *context,
564
+ UDFValue *returnValue)
565
+ {
566
+ PPConstructCommand(context,"ppdeffunction",DeffunctionData(theEnv)->DeffunctionConstruct,returnValue);
567
+ }
568
+
569
+ /***************************************************
570
+ NAME : ListDeffunctionsCommand
571
+ DESCRIPTION : Displays all deffunction names
572
+ INPUTS : None
573
+ RETURNS : Nothing useful
574
+ SIDE EFFECTS : Deffunction name sprinted
575
+ NOTES : H/L Interface
576
+ ***************************************************/
577
+ void ListDeffunctionsCommand(
578
+ Environment *theEnv,
579
+ UDFContext *context,
580
+ UDFValue *returnValue)
581
+ {
582
+ ListConstructCommand(context,DeffunctionData(theEnv)->DeffunctionConstruct);
583
+ }
584
+
585
+ /***************************************************
586
+ NAME : ListDeffunctions
587
+ DESCRIPTION : Displays all deffunction names
588
+ INPUTS : 1) The logical name of the output
589
+ 2) The module
590
+ RETURNS : Nothing useful
591
+ SIDE EFFECTS : Deffunction name sprinted
592
+ NOTES : C Interface
593
+ ***************************************************/
594
+ void ListDeffunctions(
595
+ Environment *theEnv,
596
+ const char *logicalName,
597
+ Defmodule *theModule)
598
+ {
599
+ ListConstruct(theEnv,DeffunctionData(theEnv)->DeffunctionConstruct,logicalName,theModule);
600
+ }
601
+
602
+ #endif
603
+
604
+ /***************************************************************
605
+ NAME : GetDeffunctionListFunction
606
+ DESCRIPTION : Groups all deffunction names into
607
+ a multifield list
608
+ INPUTS : A data object buffer to hold
609
+ the multifield result
610
+ RETURNS : Nothing useful
611
+ SIDE EFFECTS : Multifield allocated and filled
612
+ NOTES : H/L Syntax: (get-deffunction-list [<module>])
613
+ ***************************************************************/
614
+ void GetDeffunctionListFunction(
615
+ Environment *theEnv,
616
+ UDFContext *context,
617
+ UDFValue *returnValue)
618
+ {
619
+ GetConstructListFunction(context,returnValue,DeffunctionData(theEnv)->DeffunctionConstruct);
620
+ }
621
+
622
+ /***************************************************************
623
+ NAME : GetDeffunctionList
624
+ DESCRIPTION : Groups all deffunction names into
625
+ a multifield list
626
+ INPUTS : 1) A data object buffer to hold
627
+ the multifield result
628
+ 2) The module from which to obtain deffunctions
629
+ RETURNS : Nothing useful
630
+ SIDE EFFECTS : Multifield allocated and filled
631
+ NOTES : External C access
632
+ ***************************************************************/
633
+ void GetDeffunctionList(
634
+ Environment *theEnv,
635
+ CLIPSValue *returnValue,
636
+ Defmodule *theModule)
637
+ {
638
+ UDFValue result;
639
+
640
+ GetConstructList(theEnv,&result,DeffunctionData(theEnv)->DeffunctionConstruct,theModule);
641
+ NormalizeMultifield(theEnv,&result);
642
+ returnValue->value = result.value;
643
+ }
644
+
645
+ /*******************************************************
646
+ NAME : CheckDeffunctionCall
647
+ DESCRIPTION : Checks the number of arguments
648
+ passed to a deffunction
649
+ INPUTS : 1) Deffunction pointer
650
+ 2) The number of arguments
651
+ RETURNS : True if OK, false otherwise
652
+ SIDE EFFECTS : Message printed on errors
653
+ NOTES : None
654
+ *******************************************************/
655
+ bool CheckDeffunctionCall(
656
+ Environment *theEnv,
657
+ Deffunction *theDeffunction,
658
+ int args)
659
+ {
660
+ if (theDeffunction == NULL)
661
+ return false;
662
+
663
+ if (args < theDeffunction->minNumberOfParameters)
664
+ {
665
+ if (theDeffunction->maxNumberOfParameters == PARAMETERS_UNBOUNDED)
666
+ ExpectedCountError(theEnv,DeffunctionName(theDeffunction),
667
+ AT_LEAST,theDeffunction->minNumberOfParameters);
668
+ else
669
+ ExpectedCountError(theEnv,DeffunctionName(theDeffunction),
670
+ EXACTLY,theDeffunction->minNumberOfParameters);
671
+ return false;
672
+ }
673
+ else if ((args > theDeffunction->minNumberOfParameters) &&
674
+ (theDeffunction->maxNumberOfParameters != PARAMETERS_UNBOUNDED))
675
+ {
676
+ ExpectedCountError(theEnv,DeffunctionName(theDeffunction),
677
+ EXACTLY,theDeffunction->minNumberOfParameters);
678
+ return false;
679
+ }
680
+ return true;
681
+ }
682
+
683
+ /* =========================================
684
+ *****************************************
685
+ INTERNALLY VISIBLE FUNCTIONS
686
+ =========================================
687
+ ***************************************** */
688
+
689
+ /***************************************************
690
+ NAME : PrintDeffunctionCall
691
+ DESCRIPTION : PrintExpression() support function
692
+ for deffunction calls
693
+ INPUTS : 1) The output logical name
694
+ 2) The deffunction
695
+ RETURNS : Nothing useful
696
+ SIDE EFFECTS : Call expression printed
697
+ NOTES : None
698
+ ***************************************************/
699
+ static void PrintDeffunctionCall(
700
+ Environment *theEnv,
701
+ const char *logName,
702
+ Deffunction *theDeffunction)
703
+ {
704
+ #if DEVELOPER
705
+
706
+ WriteString(theEnv,logName,"(");
707
+ WriteString(theEnv,logName,DeffunctionName(theDeffunction));
708
+ if (GetFirstArgument() != NULL)
709
+ {
710
+ WriteString(theEnv,logName," ");
711
+ PrintExpression(theEnv,logName,GetFirstArgument());
712
+ }
713
+ WriteString(theEnv,logName,")");
714
+ #else
715
+ #if MAC_XCD
716
+ #pragma unused(theEnv)
717
+ #pragma unused(logName)
718
+ #pragma unused(theDeffunction)
719
+ #endif
720
+ #endif
721
+ }
722
+
723
+ /*******************************************************
724
+ NAME : EvaluateDeffunctionCall
725
+ DESCRIPTION : Primitive support function for
726
+ calling a deffunction
727
+ INPUTS : 1) The deffunction
728
+ 2) A data object buffer to hold
729
+ the evaluation result
730
+ RETURNS : False if the deffunction
731
+ returns the symbol false,
732
+ true otherwise
733
+ SIDE EFFECTS : Data obejct buffer set and any
734
+ side-effects of calling the deffunction
735
+ NOTES : None
736
+ *******************************************************/
737
+ static bool EvaluateDeffunctionCall(
738
+ Environment *theEnv,
739
+ Deffunction *theDeffunction,
740
+ UDFValue *returnValue)
741
+ {
742
+ CallDeffunction(theEnv,theDeffunction,GetFirstArgument(),returnValue);
743
+ if (returnValue->value == FalseSymbol(theEnv))
744
+ { return false; }
745
+ return true;
746
+ }
747
+
748
+ /***************************************************
749
+ NAME : DecrementDeffunctionBusyCount
750
+ DESCRIPTION : Lowers the busy count of a
751
+ deffunction construct
752
+ INPUTS : The deffunction
753
+ RETURNS : Nothing useful
754
+ SIDE EFFECTS : Busy count decremented if a clear
755
+ is not in progress (see comment)
756
+ NOTES : None
757
+ ***************************************************/
758
+ static void DecrementDeffunctionBusyCount(
759
+ Environment *theEnv,
760
+ Deffunction *theDeffunction)
761
+ {
762
+ /* ==============================================
763
+ The deffunctions to which expressions in other
764
+ constructs may refer may already have been
765
+ deleted - thus, it is important not to modify
766
+ the busy flag during a clear.
767
+ ============================================== */
768
+ if (! ConstructData(theEnv)->ClearInProgress)
769
+ theDeffunction->busy--;
770
+ }
771
+
772
+ /***************************************************
773
+ NAME : IncrementDeffunctionBusyCount
774
+ DESCRIPTION : Raises the busy count of a
775
+ deffunction construct
776
+ INPUTS : The deffunction
777
+ RETURNS : Nothing useful
778
+ SIDE EFFECTS : Busy count incremented
779
+ NOTES : None
780
+ ***************************************************/
781
+ static void IncrementDeffunctionBusyCount(
782
+ Environment *theEnv,
783
+ Deffunction *theDeffunction)
784
+ {
785
+ #if MAC_XCD
786
+ #pragma unused(theEnv)
787
+ #endif
788
+ #if (! RUN_TIME) && (! BLOAD_ONLY)
789
+ if (! ConstructData(theEnv)->ParsingConstruct)
790
+ { ConstructData(theEnv)->DanglingConstructs++; }
791
+ #endif
792
+
793
+ theDeffunction->busy++;
794
+ }
795
+
796
+ #if ! RUN_TIME
797
+
798
+ /*****************************************************
799
+ NAME : AllocateModule
800
+ DESCRIPTION : Creates and initializes a
801
+ list of deffunctions for a new module
802
+ INPUTS : None
803
+ RETURNS : The new deffunction module
804
+ SIDE EFFECTS : Deffunction module created
805
+ NOTES : None
806
+ *****************************************************/
807
+ static void *AllocateModule(
808
+ Environment *theEnv)
809
+ {
810
+ return (void *) get_struct(theEnv,deffunctionModuleData);
811
+ }
812
+
813
+ /***************************************************
814
+ NAME : ReturnModule
815
+ DESCRIPTION : Removes a deffunction module and
816
+ all associated deffunctions
817
+ INPUTS : The deffunction module
818
+ RETURNS : Nothing useful
819
+ SIDE EFFECTS : Module and deffunctions deleted
820
+ NOTES : None
821
+ ***************************************************/
822
+ static void ReturnModule(
823
+ Environment *theEnv,
824
+ void *theItem)
825
+ {
826
+ #if (! BLOAD_ONLY)
827
+ FreeConstructHeaderModule(theEnv,(struct defmoduleItemHeader *) theItem,DeffunctionData(theEnv)->DeffunctionConstruct);
828
+ #endif
829
+ rtn_struct(theEnv,deffunctionModuleData,theItem);
830
+ }
831
+
832
+ /***************************************************
833
+ NAME : ClearDeffunctionsReady
834
+ DESCRIPTION : Determines if it is safe to
835
+ remove all deffunctions
836
+ Assumes *all* constructs will be
837
+ deleted - only checks to see if
838
+ any deffunctions are currently
839
+ executing
840
+ INPUTS : None
841
+ RETURNS : True if no deffunctions are
842
+ executing, false otherwise
843
+ SIDE EFFECTS : None
844
+ NOTES : Used by (clear) and (bload)
845
+ ***************************************************/
846
+ static bool ClearDeffunctionsReady(
847
+ Environment *theEnv,
848
+ void *context)
849
+ {
850
+ return((DeffunctionData(theEnv)->ExecutingDeffunction != NULL) ? false : true);
851
+ }
852
+
853
+ #endif
854
+
855
+ #if RUN_TIME
856
+
857
+ /**************************************************/
858
+ /* RuntimeDeffunctionAction: Action to be applied */
859
+ /* to each deffunction construct when a runtime */
860
+ /* initialization occurs. */
861
+ /**************************************************/
862
+ static void RuntimeDeffunctionAction(
863
+ Environment *theEnv,
864
+ ConstructHeader *theConstruct,
865
+ void *buffer)
866
+ {
867
+ #if MAC_XCD
868
+ #pragma unused(buffer)
869
+ #endif
870
+ Deffunction *theDeffunction = (Deffunction *) theConstruct;
871
+
872
+ theDeffunction->header.env = theEnv;
873
+ }
874
+
875
+ /*********************************/
876
+ /* DeffunctionRunTimeInitialize: */
877
+ /*********************************/
878
+ void DeffunctionRunTimeInitialize(
879
+ Environment *theEnv)
880
+ {
881
+ DoForAllConstructs(theEnv,RuntimeDeffunctionAction,DeffunctionData(theEnv)->DeffunctionModuleIndex,true,NULL);
882
+ }
883
+
884
+ #endif
885
+
886
+ #if (! BLOAD_ONLY) && (! RUN_TIME)
887
+
888
+ /***************************************************
889
+ NAME : RemoveAllDeffunctions
890
+ DESCRIPTION : Removes all deffunctions
891
+ INPUTS : None
892
+ RETURNS : True if all deffunctions
893
+ removed, false otherwise
894
+ SIDE EFFECTS : Deffunctions removed
895
+ NOTES : None
896
+ ***************************************************/
897
+ static bool RemoveAllDeffunctions(
898
+ Environment *theEnv)
899
+ {
900
+ Deffunction *dptr, *dtmp;
901
+ unsigned oldbusy;
902
+ bool success = true;
903
+
904
+ #if BLOAD || BLOAD_AND_BSAVE
905
+
906
+ if (Bloaded(theEnv) == true)
907
+ return false;
908
+ #endif
909
+
910
+ dptr = GetNextDeffunction(theEnv,NULL);
911
+ while (dptr != NULL)
912
+ {
913
+ if (dptr->executing > 0)
914
+ {
915
+ DeffunctionDeleteError(theEnv,DeffunctionName(dptr));
916
+ success = false;
917
+ }
918
+ else
919
+ {
920
+ oldbusy = dptr->busy;
921
+ ExpressionDeinstall(theEnv,dptr->code);
922
+ dptr->busy = oldbusy;
923
+ ReturnPackedExpression(theEnv,dptr->code);
924
+ dptr->code = NULL;
925
+ }
926
+ dptr = GetNextDeffunction(theEnv,dptr);
927
+ }
928
+
929
+ dptr = GetNextDeffunction(theEnv,NULL);
930
+ while (dptr != NULL)
931
+ {
932
+ dtmp = dptr;
933
+ dptr = GetNextDeffunction(theEnv,dptr);
934
+ if (dtmp->executing == 0)
935
+ {
936
+ if (dtmp->busy > 0)
937
+ {
938
+ PrintWarningID(theEnv,"DFFNXFUN",1,false);
939
+ WriteString(theEnv,STDWRN,"Deffunction '");
940
+ WriteString(theEnv,STDWRN,DeffunctionName(dtmp));
941
+ WriteString(theEnv,STDWRN,"' only partially deleted due to usage by other constructs.\n");
942
+ SetDeffunctionPPForm(theEnv,dtmp,NULL);
943
+ success = false;
944
+ }
945
+ else
946
+ {
947
+ RemoveConstructFromModule(theEnv,&dtmp->header);
948
+ RemoveDeffunction(theEnv,dtmp);
949
+ }
950
+ }
951
+ }
952
+ return(success);
953
+ }
954
+
955
+ /****************************************************
956
+ NAME : DeffunctionDeleteError
957
+ DESCRIPTION : Prints out an error message when
958
+ a deffunction deletion attempt fails
959
+ INPUTS : The deffunction name
960
+ RETURNS : Nothing useful
961
+ SIDE EFFECTS : Error message printed
962
+ NOTES : None
963
+ ****************************************************/
964
+ static void DeffunctionDeleteError(
965
+ Environment *theEnv,
966
+ const char *dfnxName)
967
+ {
968
+ CantDeleteItemErrorMessage(theEnv,"deffunction",dfnxName);
969
+ }
970
+
971
+ /***************************************************
972
+ NAME : SaveDeffunctionHeaders
973
+ DESCRIPTION : Writes out deffunction forward
974
+ declarations for (save) command
975
+ INPUTS : The logical output name
976
+ RETURNS : Nothing useful
977
+ SIDE EFFECTS : Writes out deffunctions with no
978
+ body of actions
979
+ NOTES : Used for deffunctions which are
980
+ mutually recursive with other
981
+ constructs
982
+ ***************************************************/
983
+ static void SaveDeffunctionHeaders(
984
+ Environment *theEnv,
985
+ Defmodule *theModule,
986
+ const char *logicalName,
987
+ void *context)
988
+ {
989
+ DoForAllConstructsInModule(theEnv,theModule,
990
+ SaveDeffunctionHeader,
991
+ DeffunctionData(theEnv)->DeffunctionModuleIndex,
992
+ false,(void *) logicalName);
993
+ }
994
+
995
+ /***************************************************
996
+ NAME : SaveDeffunctionHeader
997
+ DESCRIPTION : Writes a deffunction forward
998
+ declaration to the save file
999
+ INPUTS : 1) The deffunction
1000
+ 2) The logical name of the output
1001
+ RETURNS : Nothing useful
1002
+ SIDE EFFECTS : Defffunction header written
1003
+ NOTES : None
1004
+ ***************************************************/
1005
+ static void SaveDeffunctionHeader(
1006
+ Environment *theEnv,
1007
+ ConstructHeader *theDeffunction,
1008
+ void *userBuffer)
1009
+ {
1010
+ Deffunction *dfnxPtr = (Deffunction *) theDeffunction;
1011
+ const char *logicalName = (const char *) userBuffer;
1012
+ unsigned short i;
1013
+
1014
+ if (DeffunctionPPForm(dfnxPtr) != NULL)
1015
+ {
1016
+ WriteString(theEnv,logicalName,"(deffunction ");
1017
+ WriteString(theEnv,logicalName,DeffunctionModule(dfnxPtr));
1018
+ WriteString(theEnv,logicalName,"::");
1019
+ WriteString(theEnv,logicalName,DeffunctionName(dfnxPtr));
1020
+ WriteString(theEnv,logicalName," (");
1021
+ for (i = 0 ; i < dfnxPtr->minNumberOfParameters ; i++)
1022
+ {
1023
+ WriteString(theEnv,logicalName,"?p");
1024
+ PrintUnsignedInteger(theEnv,logicalName,i);
1025
+ if ((i + 1) != dfnxPtr->minNumberOfParameters)
1026
+ WriteString(theEnv,logicalName," ");
1027
+ }
1028
+ if (dfnxPtr->maxNumberOfParameters == PARAMETERS_UNBOUNDED)
1029
+ {
1030
+ if (dfnxPtr->minNumberOfParameters != 0)
1031
+ WriteString(theEnv,logicalName," ");
1032
+ WriteString(theEnv,logicalName,"$?wildargs))\n\n");
1033
+ }
1034
+ else
1035
+ WriteString(theEnv,logicalName,"))\n\n");
1036
+ }
1037
+ }
1038
+
1039
+ /***************************************************
1040
+ NAME : SaveDeffunctions
1041
+ DESCRIPTION : Writes out deffunctions
1042
+ for (save) command
1043
+ INPUTS : The logical output name
1044
+ RETURNS : Nothing useful
1045
+ SIDE EFFECTS : Writes out deffunctions
1046
+ NOTES : None
1047
+ ***************************************************/
1048
+ static void SaveDeffunctions(
1049
+ Environment *theEnv,
1050
+ Defmodule *theModule,
1051
+ const char *logicalName,
1052
+ void *context)
1053
+ {
1054
+ SaveConstruct(theEnv,theModule,logicalName,DeffunctionData(theEnv)->DeffunctionConstruct);
1055
+ }
1056
+
1057
+ #endif
1058
+
1059
+ #if DEBUGGING_FUNCTIONS
1060
+
1061
+ /******************************************************************
1062
+ NAME : DeffunctionWatchAccess
1063
+ DESCRIPTION : Parses a list of deffunction names passed by
1064
+ AddWatchItem() and sets the traces accordingly
1065
+ INPUTS : 1) A code indicating which trace flag is to be set
1066
+ Ignored
1067
+ 2) The value to which to set the trace flags
1068
+ 3) A list of expressions containing the names
1069
+ of the deffunctions for which to set traces
1070
+ RETURNS : True if all OK, false otherwise
1071
+ SIDE EFFECTS : Watch flags set in specified deffunctions
1072
+ NOTES : Accessory function for AddWatchItem()
1073
+ ******************************************************************/
1074
+ static bool DeffunctionWatchAccess(
1075
+ Environment *theEnv,
1076
+ int code,
1077
+ bool newState,
1078
+ Expression *argExprs)
1079
+ {
1080
+ #if MAC_XCD
1081
+ #pragma unused(code)
1082
+ #endif
1083
+
1084
+ return(ConstructSetWatchAccess(theEnv,DeffunctionData(theEnv)->DeffunctionConstruct,newState,argExprs,
1085
+ (ConstructGetWatchFunction *) DeffunctionGetWatch,
1086
+ (ConstructSetWatchFunction *) DeffunctionSetWatch));
1087
+ }
1088
+
1089
+ /***********************************************************************
1090
+ NAME : DeffunctionWatchPrint
1091
+ DESCRIPTION : Parses a list of deffunction names passed by
1092
+ AddWatchItem() and displays the traces accordingly
1093
+ INPUTS : 1) The logical name of the output
1094
+ 2) A code indicating which trace flag is to be examined
1095
+ Ignored
1096
+ 3) A list of expressions containing the names
1097
+ of the deffunctions for which to examine traces
1098
+ RETURNS : True if all OK, false otherwise
1099
+ SIDE EFFECTS : Watch flags displayed for specified deffunctions
1100
+ NOTES : Accessory function for AddWatchItem()
1101
+ ***********************************************************************/
1102
+ static bool DeffunctionWatchPrint(
1103
+ Environment *theEnv,
1104
+ const char *logName,
1105
+ int code,
1106
+ Expression *argExprs)
1107
+ {
1108
+ #if MAC_XCD
1109
+ #pragma unused(code)
1110
+ #endif
1111
+
1112
+ return(ConstructPrintWatchAccess(theEnv,DeffunctionData(theEnv)->DeffunctionConstruct,logName,argExprs,
1113
+ (ConstructGetWatchFunction *) DeffunctionGetWatch,
1114
+ (ConstructSetWatchFunction *) DeffunctionSetWatch));
1115
+ }
1116
+
1117
+ /*********************************************************
1118
+ NAME : DeffunctionSetWatch
1119
+ DESCRIPTION : Sets the trace to ON/OFF for the
1120
+ deffunction
1121
+ INPUTS : 1) True to set the trace on,
1122
+ false to set it off
1123
+ 2) A pointer to the deffunction
1124
+ RETURNS : Nothing useful
1125
+ SIDE EFFECTS : Watch flag for the deffunction set
1126
+ NOTES : None
1127
+ *********************************************************/
1128
+ void DeffunctionSetWatch(
1129
+ Deffunction *theDeffunction,
1130
+ bool newState)
1131
+ {
1132
+ theDeffunction->trace = newState;
1133
+ }
1134
+
1135
+ /*********************************************************
1136
+ NAME : DeffunctionGetWatch
1137
+ DESCRIPTION : Determines if trace messages are
1138
+ gnerated when executing deffunction
1139
+ INPUTS : A pointer to the deffunction
1140
+ RETURNS : True if a trace is active,
1141
+ false otherwise
1142
+ SIDE EFFECTS : None
1143
+ NOTES : None
1144
+ *********************************************************/
1145
+ bool DeffunctionGetWatch(
1146
+ Deffunction *theDeffunction)
1147
+ {
1148
+ return theDeffunction->trace;
1149
+ }
1150
+
1151
+ #endif
1152
+
1153
+ /*##################################*/
1154
+ /* Additional Environment Functions */
1155
+ /*##################################*/
1156
+
1157
+ const char *DeffunctionModule(
1158
+ Deffunction *theDeffunction)
1159
+ {
1160
+ return GetConstructModuleName(&theDeffunction->header);
1161
+ }
1162
+
1163
+ const char *DeffunctionName(
1164
+ Deffunction *theDeffunction)
1165
+ {
1166
+ return GetConstructNameString(&theDeffunction->header);
1167
+ }
1168
+
1169
+ const char *DeffunctionPPForm(
1170
+ Deffunction *theDeffunction)
1171
+ {
1172
+ return GetConstructPPForm(&theDeffunction->header);
1173
+ }
1174
+
1175
+ CLIPSLexeme *GetDeffunctionNamePointer(
1176
+ Environment *theEnv,
1177
+ Deffunction *theDeffunction)
1178
+ {
1179
+ return GetConstructNamePointer(&theDeffunction->header);
1180
+ }
1181
+
1182
+ void SetDeffunctionPPForm(
1183
+ Environment *theEnv,
1184
+ Deffunction *theDeffunction,
1185
+ const char *thePPForm)
1186
+ {
1187
+ SetConstructPPForm(theEnv,&theDeffunction->header,thePPForm);
1188
+ }
1189
+
1190
+ #endif
1191
+
1192
+