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,1478 @@
1
+ /*******************************************************/
2
+ /* "C" Language Integrated Production System */
3
+ /* */
4
+ /* CLIPS Version 6.40 02/03/21 */
5
+ /* */
6
+ /* */
7
+ /*******************************************************/
8
+
9
+ /**************************************************************/
10
+ /* Purpose: Procedural Code Support Routines for */
11
+ /* Deffunctions, Generic Function Methods, */
12
+ /* Message-Handlersand Rules */
13
+ /* */
14
+ /* Principal Programmer(s): */
15
+ /* Brian L. Dantes */
16
+ /* */
17
+ /* Contributing Programmer(s): */
18
+ /* */
19
+ /* Revision History: */
20
+ /* */
21
+ /* 6.23: Correction for FalseSymbol/TrueSymbol. DR0859 */
22
+ /* */
23
+ /* Changed name of variable log to logName */
24
+ /* because of Unix compiler warnings of shadowed */
25
+ /* definitions. */
26
+ /* */
27
+ /* 6.24: Renamed BOOLEAN macro type to intBool. */
28
+ /* */
29
+ /* Added pragmas to remove compilation warnings. */
30
+ /* */
31
+ /* 6.30: Updated ENTITY_RECORD definitions to include */
32
+ /* additional NULL initializers. */
33
+ /* */
34
+ /* Added ReleaseProcParameters call. */
35
+ /* */
36
+ /* Added tracked memory calls. */
37
+ /* */
38
+ /* Removed conditional code for unsupported */
39
+ /* compilers/operating systems (IBM_MCW, */
40
+ /* MAC_MCW, and IBM_TBC). */
41
+ /* */
42
+ /* Added const qualifiers to remove C++ */
43
+ /* deprecation warnings. */
44
+ /* */
45
+ /* 6.40: Added Env prefix to GetEvaluationError and */
46
+ /* SetEvaluationError functions. */
47
+ /* */
48
+ /* Pragma once and other inclusion changes. */
49
+ /* */
50
+ /* Added support for booleans with <stdbool.h>. */
51
+ /* */
52
+ /* Removed use of void pointers for specific */
53
+ /* data structures. */
54
+ /* */
55
+ /* UDF redesign. */
56
+ /* */
57
+ /* Generic error message no longer printed when */
58
+ /* an alternate variable handling function */
59
+ /* generates an error. */
60
+ /* */
61
+ /**************************************************************/
62
+
63
+ /* =========================================
64
+ *****************************************
65
+ EXTERNAL DEFINITIONS
66
+ =========================================
67
+ ***************************************** */
68
+ #include "setup.h"
69
+
70
+ #include <stdio.h>
71
+
72
+ #include <stdlib.h>
73
+ #include <ctype.h>
74
+
75
+ #include "memalloc.h"
76
+ #include "constant.h"
77
+ #include "envrnmnt.h"
78
+ #if DEFGLOBAL_CONSTRUCT
79
+ #include "globlpsr.h"
80
+ #endif
81
+ #include "exprnpsr.h"
82
+ #include "multifld.h"
83
+ #if OBJECT_SYSTEM
84
+ #include "object.h"
85
+ #endif
86
+ #include "pprint.h"
87
+ #include "prcdrpsr.h"
88
+ #include "prntutil.h"
89
+ #include "router.h"
90
+ #include "utility.h"
91
+
92
+ #include "prccode.h"
93
+
94
+ /* =========================================
95
+ *****************************************
96
+ MACROS AND TYPES
97
+ =========================================
98
+ ***************************************** */
99
+ typedef struct
100
+ {
101
+ unsigned firstFlag : 1;
102
+ unsigned first : 15;
103
+ unsigned secondFlag : 1;
104
+ unsigned second : 15;
105
+ } PACKED_PROC_VAR;
106
+
107
+ /***************************************/
108
+ /* LOCAL INTERNAL FUNCTION DEFINITIONS */
109
+ /***************************************/
110
+
111
+ static void EvaluateProcParameters(Environment *,Expression *,unsigned int,const char *,const char *);
112
+ static bool RtnProcParam(Environment *,void *,UDFValue *);
113
+ static bool GetProcBind(Environment *,void *,UDFValue *);
114
+ static bool PutProcBind(Environment *,void *,UDFValue *);
115
+ static bool RtnProcWild(Environment *,void *,UDFValue *);
116
+ static void DeallocateProceduralPrimitiveData(Environment *);
117
+ static void ReleaseProcParameters(Environment *);
118
+
119
+ #if (! BLOAD_ONLY) && (! RUN_TIME)
120
+ static unsigned int FindProcParameter(CLIPSLexeme *,Expression *,CLIPSLexeme *);
121
+ static bool ReplaceProcBinds(Environment *,Expression *,
122
+ int (*)(Environment *,Expression *,void *),void *);
123
+ static Expression *CompactActions(Environment *,Expression *);
124
+ #endif
125
+
126
+ #if (! DEFFUNCTION_CONSTRUCT) || (! DEFGENERIC_CONSTRUCT)
127
+ static bool EvaluateBadCall(Environment *,void *,UDFValue *);
128
+ #endif
129
+
130
+ /* =========================================
131
+ *****************************************
132
+ EXTERNALLY VISIBLE FUNCTIONS
133
+ =========================================
134
+ ***************************************** */
135
+
136
+ /****************************************************
137
+ NAME : InstallProcedurePrimitives
138
+ DESCRIPTION : Installs primitive function handlers
139
+ for accessing parameters and local
140
+ variables within the bodies of
141
+ message-handlers, methods, rules and
142
+ deffunctions.
143
+ INPUTS : None
144
+ RETURNS : Nothing useful
145
+ SIDE EFFECTS : Primitive entities installed
146
+ NOTES : None
147
+ ****************************************************/
148
+ void InstallProcedurePrimitives(
149
+ Environment *theEnv)
150
+ {
151
+ EntityRecord procParameterInfo = { "PROC_PARAM", PROC_PARAM,0,1,0,NULL,NULL,NULL,
152
+ (EntityEvaluationFunction *) RtnProcParam,
153
+ NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL },
154
+ procWildInfo = { "PROC_WILD_PARAM", PROC_WILD_PARAM,0,1,0,NULL,NULL,NULL,
155
+ (EntityEvaluationFunction *) RtnProcWild,
156
+ NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL },
157
+ procGetInfo = { "PROC_GET_BIND", PROC_GET_BIND,0,1,0,NULL,NULL,NULL,
158
+ (EntityEvaluationFunction *) GetProcBind,
159
+ NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL },
160
+ procBindInfo = { "PROC_BIND", PROC_BIND,0,1,0,NULL,NULL,NULL,
161
+ (EntityEvaluationFunction *) PutProcBind,
162
+ NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL };
163
+
164
+ #if ! DEFFUNCTION_CONSTRUCT
165
+ EntityRecord deffunctionEntityRecord =
166
+ { "PCALL", PCALL,0,0,1,
167
+ NULL,NULL,NULL,
168
+ EvaluateBadCall,
169
+ NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL };
170
+ #endif
171
+ #if ! DEFGENERIC_CONSTRUCT
172
+ EntityRecord genericEntityRecord =
173
+ { "GCALL", GCALL,0,0,1,
174
+ NULL,NULL,NULL,
175
+ EvaluateBadCall,
176
+ NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL };
177
+ #endif
178
+
179
+ AllocateEnvironmentData(theEnv,PROCEDURAL_PRIMITIVE_DATA,sizeof(struct proceduralPrimitiveData),DeallocateProceduralPrimitiveData);
180
+
181
+ memcpy(&ProceduralPrimitiveData(theEnv)->ProcParameterInfo,&procParameterInfo,sizeof(struct entityRecord));
182
+ memcpy(&ProceduralPrimitiveData(theEnv)->ProcWildInfo,&procWildInfo,sizeof(struct entityRecord));
183
+ memcpy(&ProceduralPrimitiveData(theEnv)->ProcGetInfo,&procGetInfo,sizeof(struct entityRecord));
184
+ memcpy(&ProceduralPrimitiveData(theEnv)->ProcBindInfo,&procBindInfo,sizeof(struct entityRecord));
185
+
186
+ InstallPrimitive(theEnv,&ProceduralPrimitiveData(theEnv)->ProcParameterInfo,PROC_PARAM);
187
+ InstallPrimitive(theEnv,&ProceduralPrimitiveData(theEnv)->ProcWildInfo,PROC_WILD_PARAM);
188
+ InstallPrimitive(theEnv,&ProceduralPrimitiveData(theEnv)->ProcGetInfo,PROC_GET_BIND);
189
+ InstallPrimitive(theEnv,&ProceduralPrimitiveData(theEnv)->ProcBindInfo,PROC_BIND);
190
+
191
+ ProceduralPrimitiveData(theEnv)->Oldindex = UINT_MAX;
192
+
193
+ /* ===============================================
194
+ Make sure a default evaluation function is
195
+ in place for deffunctions and generic functions
196
+ in the event that a binary image containing
197
+ these items is loaded into a configuration
198
+ that does not support them.
199
+ =============================================== */
200
+
201
+ #if ! DEFFUNCTION_CONSTRUCT
202
+ memcpy(&ProceduralPrimitiveData(theEnv)->DeffunctionEntityRecord,&deffunctionEntityRecord,sizeof(struct entityRecord));
203
+ InstallPrimitive(theEnv,&ProceduralPrimitiveData(theEnv)->DeffunctionEntityRecord,PCALL);
204
+ #endif
205
+
206
+ #if ! DEFGENERIC_CONSTRUCT
207
+ memcpy(&ProceduralPrimitiveData(theEnv)->GenericEntityRecord,&genericEntityRecord,sizeof(struct entityRecord));
208
+ InstallPrimitive(theEnv,&ProceduralPrimitiveData(theEnv)->GenericEntityRecord,GCALL);
209
+ #endif
210
+
211
+ /* =============================================
212
+ Install the special empty multifield to
213
+ let callers distinguish between no parameters
214
+ and zero-length multifield parameters
215
+ ============================================= */
216
+ ProceduralPrimitiveData(theEnv)->NoParamValue = CreateUnmanagedMultifield(theEnv,0L);
217
+ RetainMultifield(theEnv,ProceduralPrimitiveData(theEnv)->NoParamValue);
218
+ }
219
+
220
+ /**************************************************************/
221
+ /* DeallocateProceduralPrimitiveData: Deallocates environment */
222
+ /* data for the procedural primitives functionality. */
223
+ /**************************************************************/
224
+ static void DeallocateProceduralPrimitiveData(
225
+ Environment *theEnv)
226
+ {
227
+ ReturnMultifield(theEnv,ProceduralPrimitiveData(theEnv)->NoParamValue);
228
+ ReleaseProcParameters(theEnv);
229
+ }
230
+
231
+ #if (! BLOAD_ONLY) && (! RUN_TIME)
232
+
233
+ #if DEFFUNCTION_CONSTRUCT || OBJECT_SYSTEM
234
+
235
+ /************************************************************
236
+ NAME : ParseProcParameters
237
+ DESCRIPTION : Parses a parameter list for a
238
+ procedural routine, such as a
239
+ deffunction or message-handler
240
+ INPUTS : 1) The logical name of the input
241
+ 2) A buffer for scanned tokens
242
+ 3) The partial list of parameters so far
243
+ (can be NULL)
244
+ 3) A buffer for a wildcard symbol (if any)
245
+ 4) A buffer for a minimum of parameters
246
+ 5) A buffer for a maximum of parameters
247
+ (will be set to -1 if there is a wilcard)
248
+ 6) A buffer for an error flag
249
+ 7) The address of a function to do specialized
250
+ checking on a parameter (can be NULL)
251
+ The function should accept a string and
252
+ return false if the parameter is OK, true
253
+ otherwise.
254
+ RETURNS : A list of expressions containing the
255
+ parameter names
256
+ SIDE EFFECTS : Parameters parsed and expressions formed
257
+ NOTES : None
258
+ ************************************************************/
259
+ Expression *ParseProcParameters(
260
+ Environment *theEnv,
261
+ const char *readSource,
262
+ struct token *tkn,
263
+ Expression *parameterList,
264
+ CLIPSLexeme **wildcard,
265
+ unsigned short *min,
266
+ unsigned short *max,
267
+ bool *error,
268
+ bool (*checkfunc)(Environment *,const char *))
269
+ {
270
+ Expression *nextOne,*lastOne,*check;
271
+ int paramprintp = 0;
272
+
273
+ *wildcard = NULL;
274
+ *min = 0;
275
+ *error = true;
276
+ lastOne = nextOne = parameterList;
277
+ while (nextOne != NULL)
278
+ {
279
+ (*min)++;
280
+ lastOne = nextOne;
281
+ nextOne = nextOne->nextArg;
282
+ }
283
+ if (tkn->tknType != LEFT_PARENTHESIS_TOKEN)
284
+ {
285
+ SyntaxErrorMessage(theEnv,"parameter list");
286
+ ReturnExpression(theEnv,parameterList);
287
+ return NULL;
288
+ }
289
+ GetToken(theEnv,readSource,tkn);
290
+ while ((tkn->tknType == SF_VARIABLE_TOKEN) || (tkn->tknType == MF_VARIABLE_TOKEN))
291
+ {
292
+ for (check = parameterList ; check != NULL ; check = check->nextArg)
293
+ if (check->value == tkn->value)
294
+ {
295
+ PrintErrorID(theEnv,"PRCCODE",7,false);
296
+ WriteString(theEnv,STDERR,"Duplicate parameter names not allowed.\n");
297
+ ReturnExpression(theEnv,parameterList);
298
+ return NULL;
299
+ }
300
+ if (*wildcard != NULL)
301
+ {
302
+ PrintErrorID(theEnv,"PRCCODE",8,false);
303
+ WriteString(theEnv,STDERR,"No parameters allowed after wildcard parameter.\n");
304
+ ReturnExpression(theEnv,parameterList);
305
+ return NULL;
306
+ }
307
+ if ((checkfunc != NULL) ? (*checkfunc)(theEnv,tkn->lexemeValue->contents) : false)
308
+ {
309
+ ReturnExpression(theEnv,parameterList);
310
+ return NULL;
311
+ }
312
+ nextOne = GenConstant(theEnv,TokenTypeToType(tkn->tknType),tkn->value);
313
+ if (tkn->tknType == MF_VARIABLE_TOKEN)
314
+ *wildcard = tkn->lexemeValue;
315
+ else
316
+ (*min)++;
317
+ if (lastOne == NULL)
318
+ { parameterList = nextOne; }
319
+ else
320
+ { lastOne->nextArg = nextOne; }
321
+ lastOne = nextOne;
322
+ SavePPBuffer(theEnv," ");
323
+ paramprintp = 1;
324
+ GetToken(theEnv,readSource,tkn);
325
+ }
326
+ if (tkn->tknType != RIGHT_PARENTHESIS_TOKEN)
327
+ {
328
+ SyntaxErrorMessage(theEnv,"parameter list");
329
+ ReturnExpression(theEnv,parameterList);
330
+ return NULL;
331
+ }
332
+ if (paramprintp)
333
+ {
334
+ PPBackup(theEnv);
335
+ PPBackup(theEnv);
336
+ SavePPBuffer(theEnv,")");
337
+ }
338
+ *error = false;
339
+ *max = (*wildcard != NULL) ? PARAMETERS_UNBOUNDED : *min;
340
+ return(parameterList);
341
+ }
342
+
343
+ #endif
344
+
345
+ /*************************************************************************
346
+ NAME : ParseProcActions
347
+ DESCRIPTION : Parses the bodies of deffunctions, generic function
348
+ methods and message-handlers. Replaces parameter
349
+ and local variable references with appropriate
350
+ runtime access functions
351
+ INPUTS : 1) The environment
352
+ 2) The type of procedure body being parsed
353
+ 3) The logical name of the input
354
+ 4) A buffer for scanned tokens
355
+ 5) A list of expressions containing the names
356
+ of the parameters
357
+ 6) The wilcard parameter symbol (NULL if none)
358
+ 7) A pointer to a function to parse variables not
359
+ recognized by the standard parser
360
+ The function should accept the variable
361
+ expression and a generic pointer for special
362
+ data (can be NULL) as arguments. If the variable
363
+ is recognized, the function should modify the
364
+ expression to access this variable. Return 1
365
+ if recognized, 0 if not, -1 on errors
366
+ This argument can be NULL.
367
+ 8) A pointer to a function to handle binds in a
368
+ special way. The function should accept the
369
+ bind function call expression as an argument.
370
+ If the variable is recognized and treated specially,
371
+ the function should modify the expression
372
+ appropriately (including attaching/removing
373
+ any necessary argument expressions). Return 1
374
+ if recognized, 0 if not, -1 on errors.
375
+ This argument can be NULL.
376
+ 9) A buffer for holding the number of local vars
377
+ used by this procedure body.
378
+ 10) Special user data buffer to pass to variable
379
+ reference and bind replacement functions
380
+ RETURNS : A packed expression containing the body, NULL on
381
+ errors.
382
+ SIDE EFFECTS : Variable references replaced with runtime calls
383
+ to access the paramter and local variable array
384
+ NOTES : None
385
+ *************************************************************************/
386
+ Expression *ParseProcActions(
387
+ Environment *theEnv,
388
+ const char *bodytype,
389
+ const char *readSource,
390
+ struct token *tkn,
391
+ Expression *params,
392
+ CLIPSLexeme *wildcard,
393
+ int (*altvarfunc)(Environment *,Expression *,void *),
394
+ int (*altbindfunc)(Environment *,Expression *,void *),
395
+ unsigned short *lvarcnt,
396
+ void *userBuffer)
397
+ {
398
+ Expression *actions,*pactions;
399
+
400
+ /* ====================================================================
401
+ Clear parsed bind list - so that only local vars from this body will
402
+ be on it. The position of vars on thsi list are used to generate
403
+ indices into the LocalVarArray at runtime. The parsing of the
404
+ "bind" function adds vars to this list.
405
+ ==================================================================== */
406
+ ClearParsedBindNames(theEnv);
407
+ actions = GroupActions(theEnv,readSource,tkn,true,NULL,false);
408
+ if (actions == NULL)
409
+ return NULL;
410
+
411
+ /* ====================================================================
412
+ Replace any bind functions with special functions before replacing
413
+ any variable references. This allows those bind names to be removed
414
+ before they can be seen by variable replacement and thus generate
415
+ incorrect indices.
416
+ ==================================================================== */
417
+ if (altbindfunc != NULL)
418
+ {
419
+ if (ReplaceProcBinds(theEnv,actions,altbindfunc,userBuffer))
420
+ {
421
+ ClearParsedBindNames(theEnv);
422
+ ReturnExpression(theEnv,actions);
423
+ return NULL;
424
+ }
425
+ }
426
+
427
+ /* ======================================================================
428
+ The number of names left on the bind list is the number of local
429
+ vars for this procedure body. Replace all variable reference with
430
+ runtime access functions for ProcParamArray, LocalVarArray or
431
+ other special items, such as direct slot references, global variables,
432
+ or fact field references.
433
+ ====================================================================== */
434
+ *lvarcnt = CountParsedBindNames(theEnv);
435
+ if (ReplaceProcVars(theEnv,bodytype,actions,params,wildcard,altvarfunc,userBuffer))
436
+ {
437
+ ClearParsedBindNames(theEnv);
438
+ ReturnExpression(theEnv,actions);
439
+ return NULL;
440
+ }
441
+
442
+ /* =======================================================================
443
+ Normally, actions are grouped in a progn. If there is only one action,
444
+ the progn is unnecessary and can be removed. Also, the actions are
445
+ packed into a contiguous array to save on memory overhead. The
446
+ intermediate parsed bind names are freed to avoid tying up memory.
447
+ ======================================================================= */
448
+ actions = CompactActions(theEnv,actions);
449
+ pactions = PackExpression(theEnv,actions);
450
+ ReturnExpression(theEnv,actions);
451
+ ClearParsedBindNames(theEnv);
452
+ return(pactions);
453
+ }
454
+
455
+ /*************************************************************************
456
+ NAME : ReplaceProcVars
457
+ DESCRIPTION : Examines an expression for variables
458
+ and replaces any that correspond to
459
+ procedure parameters or globals
460
+ with function calls that get these
461
+ variables' values at run-time.
462
+ For example, procedure arguments
463
+ are stored an array at run-time, so at
464
+ parse-time, parameter-references are replaced
465
+ with function calls referencing this array at
466
+ the appropriate position.
467
+ INPUTS : 1) The type of procedure being parsed
468
+ 2) The expression-actions to be examined
469
+ 3) The parameter list
470
+ 4) The wildcard parameter symbol (NULL if none)
471
+ 5) A pointer to a function to parse variables not
472
+ recognized by the standard parser
473
+ The function should accept the variable
474
+ expression and a generic pointer for special
475
+ data (can be NULL) as arguments. If the variable
476
+ is recognized, the function should modify the
477
+ expression to access this variable. Return 1
478
+ if recognized, 0 if not, -1 on errors
479
+ This argument can be NULL.
480
+ 6) Data buffer to be passed to alternate parsing
481
+ function
482
+ RETURNS : False if OK, true on errors
483
+ SIDE EFFECTS : Variable references replaced with function calls
484
+ NOTES : This function works from the ParsedBindNames list in
485
+ SPCLFORM.C to access local binds. Make sure that
486
+ the list accurately reflects the binds by calling
487
+ ClearParsedBindNames(theEnv) before the parse of the body
488
+ in which variables are being replaced.
489
+ *************************************************************************/
490
+ int ReplaceProcVars(
491
+ Environment *theEnv,
492
+ const char *bodytype,
493
+ Expression *actions,
494
+ Expression *parameterList,
495
+ CLIPSLexeme *wildcard,
496
+ int (*altvarfunc)(Environment *,Expression *,void *),
497
+ void *specdata)
498
+ {
499
+ int altcode;
500
+ unsigned position, boundPosn;
501
+ Expression *arg_lvl,*altvarexp;
502
+ CLIPSLexeme *bindName;
503
+ PACKED_PROC_VAR pvar;
504
+ int errorCode;
505
+
506
+ while (actions != NULL)
507
+ {
508
+ if (actions->type == SF_VARIABLE)
509
+ {
510
+ /*===============================================*/
511
+ /* See if the variable is in the parameter list. */
512
+ /*===============================================*/
513
+
514
+ bindName = actions->lexemeValue;
515
+ position = FindProcParameter(bindName,parameterList,wildcard);
516
+
517
+ /*=============================================================*/
518
+ /* Check to see if the variable is bound within the procedure. */
519
+ /*=============================================================*/
520
+
521
+ boundPosn = SearchParsedBindNames(theEnv,bindName);
522
+
523
+ /*=============================================*/
524
+ /* If variable is not defined in the parameter */
525
+ /* list or as part of a bind action then... */
526
+ /*=============================================*/
527
+
528
+ if ((position == 0) && (boundPosn == 0))
529
+ {
530
+ /*================================================================*/
531
+ /* Check to see if the variable has a special access function, */
532
+ /* such as direct slot reference or a rule RHS pattern reference. */
533
+ /*================================================================*/
534
+
535
+ if (altvarfunc == NULL)
536
+ { errorCode = 0; }
537
+ else
538
+ { errorCode = (*altvarfunc)(theEnv,actions,specdata); }
539
+
540
+ if (errorCode != 1)
541
+ {
542
+ if (errorCode == 0)
543
+ {
544
+ PrintErrorID(theEnv,"PRCCODE",3,true);
545
+ WriteString(theEnv,STDERR,"Undefined variable ?");
546
+ WriteString(theEnv,STDERR,bindName->contents);
547
+ WriteString(theEnv,STDERR," referenced in ");
548
+ WriteString(theEnv,STDERR,bodytype);
549
+ WriteString(theEnv,STDERR,".\n");
550
+ }
551
+ return 1;
552
+ }
553
+ }
554
+
555
+ /*===================================================*/
556
+ /* Else if variable is defined in the parameter list */
557
+ /* and not rebound within the procedure then... */
558
+ /*===================================================*/
559
+
560
+ else if ((position > 0) && (boundPosn == 0))
561
+ {
562
+ actions->type = ((bindName != wildcard) ? PROC_PARAM : PROC_WILD_PARAM);
563
+ actions->value = AddBitMap(theEnv,&position,sizeof(int));
564
+ }
565
+
566
+ /*=========================================================*/
567
+ /* Else the variable is rebound within the procedure so... */
568
+ /*=========================================================*/
569
+
570
+ else
571
+ {
572
+ if (altvarfunc != NULL)
573
+ {
574
+ altvarexp = GenConstant(theEnv,actions->type,actions->value);
575
+ altcode = (*altvarfunc)(theEnv,altvarexp,specdata);
576
+ if (altcode == 0)
577
+ {
578
+ rtn_struct(theEnv,expr,altvarexp);
579
+ altvarexp = NULL;
580
+ }
581
+ else if (altcode == -1)
582
+ {
583
+ rtn_struct(theEnv,expr,altvarexp);
584
+ return true;
585
+ }
586
+ }
587
+ else
588
+ altvarexp = NULL;
589
+ actions->type = PROC_GET_BIND;
590
+ ClearBitString(&pvar,sizeof(PACKED_PROC_VAR));
591
+ pvar.first = boundPosn;
592
+ pvar.second = position;
593
+ pvar.secondFlag = (bindName != wildcard) ? 0 : 1;
594
+ actions->value = AddBitMap(theEnv,&pvar,sizeof(PACKED_PROC_VAR));
595
+ actions->argList = GenConstant(theEnv,SYMBOL_TYPE,bindName);
596
+ actions->argList->nextArg = altvarexp;
597
+ }
598
+ }
599
+ #if DEFGLOBAL_CONSTRUCT
600
+ else if (actions->type == GBL_VARIABLE)
601
+ {
602
+ if (ReplaceGlobalVariable(theEnv,actions) == false)
603
+ return(-1);
604
+ }
605
+ #endif
606
+ if ((altvarfunc != NULL) ? ((*altvarfunc)(theEnv,actions,specdata) == -1) : false)
607
+ return 1;
608
+ if (actions->argList != NULL)
609
+ {
610
+ if (ReplaceProcVars(theEnv,bodytype,actions->argList,parameterList,
611
+ wildcard,altvarfunc,specdata))
612
+ return 1;
613
+
614
+ /* ====================================================================
615
+ Check to see if this is a call to the bind function. If so (and the
616
+ second argument is a symbol) then it is a locally bound variable
617
+ (as opposed to a global).
618
+
619
+ Replace the call to "bind" with a call to PROC_BIND - the
620
+ special internal function for procedure local variables.
621
+ ==================================================================== */
622
+ if ((actions->value == (void *) FindFunction(theEnv,"bind")) &&
623
+ (actions->argList->type == SYMBOL_TYPE))
624
+ {
625
+ actions->type = PROC_BIND;
626
+ boundPosn = SearchParsedBindNames(theEnv,actions->argList->lexemeValue);
627
+ actions->value = AddBitMap(theEnv,&boundPosn,sizeof(int));
628
+ arg_lvl = actions->argList->nextArg;
629
+ rtn_struct(theEnv,expr,actions->argList);
630
+ actions->argList = arg_lvl;
631
+ }
632
+ }
633
+ actions = actions->nextArg;
634
+ }
635
+ return 0;
636
+ }
637
+
638
+ #if DEFGENERIC_CONSTRUCT
639
+
640
+ /*****************************************************
641
+ NAME : GenProcWildcardReference
642
+ DESCRIPTION : Returns an expression to access the
643
+ wildcard parameter for a method
644
+ INPUTS : The starting index of the wildcard
645
+ RETURNS : An expression containing the wildcard
646
+ reference
647
+ SIDE EFFECTS : Expression allocated
648
+ NOTES : None
649
+ *****************************************************/
650
+ Expression *GenProcWildcardReference(
651
+ Environment *theEnv,
652
+ int theIndex)
653
+ {
654
+ return(GenConstant(theEnv,PROC_WILD_PARAM,AddBitMap(theEnv,&theIndex,sizeof(int))));
655
+ }
656
+
657
+ #endif
658
+
659
+ #endif
660
+
661
+ /*******************************************************************
662
+ NAME : PushProcParameters
663
+ DESCRIPTION : Given a list of parameter expressions,
664
+ this function evaluates each expression
665
+ and stores the results in a contiguous
666
+ array of DATA_OBJECTS. Used in creating a new
667
+ ProcParamArray for the execution of a
668
+ procedure
669
+ The current arrays are saved on a stack.
670
+ INPUTS : 1) The paramter expression list
671
+ 2) The number of parameters in the list
672
+ 3) The name of the procedure for which
673
+ these parameters are being evaluated
674
+ 4) The type of procedure
675
+ 5) A pointer to a function to print out a trace
676
+ message about the currently executing
677
+ procedure when unbound variables are detected
678
+ at runtime (The function should take no
679
+ arguments and have no return value. The
680
+ function should print its synopsis to STDERR
681
+ and include the final carriage-return.)
682
+ RETURNS : Nothing useful
683
+ SIDE EFFECTS : Any side-effects of the evaluation of the
684
+ parameter expressions
685
+ UDFValue array allocated (deallocated on errors)
686
+ ProcParamArray set
687
+ NOTES : EvaluationError set on errors
688
+ *******************************************************************/
689
+ void PushProcParameters(
690
+ Environment *theEnv,
691
+ Expression *parameterList,
692
+ unsigned int numberOfParameters,
693
+ const char *pname,
694
+ const char *bodytype,
695
+ void (*UnboundErrFunc)(Environment *,const char *))
696
+ {
697
+ PROC_PARAM_STACK *ptmp;
698
+
699
+ ptmp = get_struct(theEnv,ProcParamStack);
700
+ ptmp->ParamArray = ProceduralPrimitiveData(theEnv)->ProcParamArray;
701
+ ptmp->ParamArraySize = ProceduralPrimitiveData(theEnv)->ProcParamArraySize;
702
+ ptmp->UnboundErrFunc = ProceduralPrimitiveData(theEnv)->ProcUnboundErrFunc;
703
+ ptmp->nxt = ProceduralPrimitiveData(theEnv)->pstack;
704
+ ProceduralPrimitiveData(theEnv)->pstack = ptmp;
705
+ EvaluateProcParameters(theEnv,parameterList,numberOfParameters,pname,bodytype);
706
+ if (EvaluationData(theEnv)->EvaluationError)
707
+ {
708
+ ptmp = ProceduralPrimitiveData(theEnv)->pstack;
709
+ ProceduralPrimitiveData(theEnv)->pstack = ProceduralPrimitiveData(theEnv)->pstack->nxt;
710
+ rtn_struct(theEnv,ProcParamStack,ptmp);
711
+ return;
712
+ }
713
+
714
+ /* ================================================================
715
+ Record ProcParamExpressions and WildcardValue for previous frame
716
+ AFTER evaluating arguments for the new frame, because they could
717
+ have gone from NULL to non-NULL (if they were already non-NULL,
718
+ they would remain unchanged.)
719
+ ================================================================ */
720
+ #if DEFGENERIC_CONSTRUCT
721
+ ptmp->ParamExpressions = ProceduralPrimitiveData(theEnv)->ProcParamExpressions;
722
+ ProceduralPrimitiveData(theEnv)->ProcParamExpressions = NULL;
723
+ #endif
724
+ ptmp->WildcardValue = ProceduralPrimitiveData(theEnv)->WildcardValue;
725
+ ProceduralPrimitiveData(theEnv)->WildcardValue = NULL;
726
+ ProceduralPrimitiveData(theEnv)->ProcUnboundErrFunc = UnboundErrFunc;
727
+ }
728
+
729
+ /******************************************************************
730
+ NAME : PopProcParameters
731
+ DESCRIPTION : Restores old procedure arrays
732
+ INPUTS : None
733
+ RETURNS : Nothing useful
734
+ SIDE EFFECTS : Stack popped and globals restored
735
+ NOTES : Assumes pstack != NULL
736
+ ******************************************************************/
737
+ void PopProcParameters(
738
+ Environment *theEnv)
739
+ {
740
+ PROC_PARAM_STACK *ptmp;
741
+
742
+ if (ProceduralPrimitiveData(theEnv)->ProcParamArray != NULL)
743
+ rm(theEnv,ProceduralPrimitiveData(theEnv)->ProcParamArray,(sizeof(UDFValue) * ProceduralPrimitiveData(theEnv)->ProcParamArraySize));
744
+
745
+ #if DEFGENERIC_CONSTRUCT
746
+ if (ProceduralPrimitiveData(theEnv)->ProcParamExpressions != NULL)
747
+ rm(theEnv,ProceduralPrimitiveData(theEnv)->ProcParamExpressions,(sizeof(Expression) * ProceduralPrimitiveData(theEnv)->ProcParamArraySize));
748
+ #endif
749
+
750
+ ptmp = ProceduralPrimitiveData(theEnv)->pstack;
751
+ ProceduralPrimitiveData(theEnv)->pstack = ProceduralPrimitiveData(theEnv)->pstack->nxt;
752
+ ProceduralPrimitiveData(theEnv)->ProcParamArray = ptmp->ParamArray;
753
+ ProceduralPrimitiveData(theEnv)->ProcParamArraySize = ptmp->ParamArraySize;
754
+
755
+ #if DEFGENERIC_CONSTRUCT
756
+ ProceduralPrimitiveData(theEnv)->ProcParamExpressions = ptmp->ParamExpressions;
757
+ #endif
758
+
759
+ if (ProceduralPrimitiveData(theEnv)->WildcardValue != NULL)
760
+ {
761
+ ReleaseMultifield(theEnv,ProceduralPrimitiveData(theEnv)->WildcardValue->multifieldValue);
762
+ if (ProceduralPrimitiveData(theEnv)->WildcardValue->value != ProceduralPrimitiveData(theEnv)->NoParamValue)
763
+ AddToMultifieldList(theEnv,ProceduralPrimitiveData(theEnv)->WildcardValue->multifieldValue);
764
+ rtn_struct(theEnv,udfValue,ProceduralPrimitiveData(theEnv)->WildcardValue);
765
+ }
766
+ ProceduralPrimitiveData(theEnv)->WildcardValue = ptmp->WildcardValue;
767
+ ProceduralPrimitiveData(theEnv)->ProcUnboundErrFunc = ptmp->UnboundErrFunc;
768
+ rtn_struct(theEnv,ProcParamStack,ptmp);
769
+ }
770
+
771
+ /******************************************************************
772
+ NAME : ReleaseProcParameters
773
+ DESCRIPTION : Restores old procedure arrays
774
+ INPUTS : None
775
+ RETURNS : Nothing useful
776
+ SIDE EFFECTS : Stack popped and globals restored
777
+ NOTES : Assumes pstack != NULL
778
+ ******************************************************************/
779
+ static void ReleaseProcParameters(
780
+ Environment *theEnv)
781
+ {
782
+ PROC_PARAM_STACK *ptmp, *next;
783
+
784
+ if (ProceduralPrimitiveData(theEnv)->ProcParamArray != NULL)
785
+ rm(theEnv,ProceduralPrimitiveData(theEnv)->ProcParamArray,(sizeof(UDFValue) * ProceduralPrimitiveData(theEnv)->ProcParamArraySize));
786
+
787
+
788
+ if (ProceduralPrimitiveData(theEnv)->WildcardValue != NULL)
789
+ {
790
+ if (ProceduralPrimitiveData(theEnv)->WildcardValue->value != ProceduralPrimitiveData(theEnv)->NoParamValue)
791
+ { ReturnMultifield(theEnv,ProceduralPrimitiveData(theEnv)->WildcardValue->multifieldValue); }
792
+
793
+ rtn_struct(theEnv,udfValue,ProceduralPrimitiveData(theEnv)->WildcardValue);
794
+ }
795
+
796
+ #if DEFGENERIC_CONSTRUCT
797
+ if (ProceduralPrimitiveData(theEnv)->ProcParamExpressions != NULL)
798
+ rm(theEnv,ProceduralPrimitiveData(theEnv)->ProcParamExpressions,(sizeof(Expression) * ProceduralPrimitiveData(theEnv)->ProcParamArraySize));
799
+ #endif
800
+
801
+ ptmp = ProceduralPrimitiveData(theEnv)->pstack;
802
+
803
+ while (ptmp != NULL)
804
+ {
805
+ next = ptmp->nxt;
806
+
807
+ if (ptmp->ParamArray != NULL)
808
+ { rm(theEnv,ptmp->ParamArray,(sizeof(UDFValue) * ptmp->ParamArraySize)); }
809
+
810
+ #if DEFGENERIC_CONSTRUCT
811
+ if (ptmp->ParamExpressions != NULL)
812
+ { rm(theEnv,ptmp->ParamExpressions,(sizeof(Expression) * ptmp->ParamArraySize)); }
813
+ #endif
814
+
815
+ if (ptmp->WildcardValue != NULL)
816
+ {
817
+ if (ptmp->WildcardValue->value != ProceduralPrimitiveData(theEnv)->NoParamValue)
818
+ { ReturnMultifield(theEnv,ptmp->WildcardValue->multifieldValue); }
819
+
820
+ rtn_struct(theEnv,udfValue,ptmp->WildcardValue);
821
+ }
822
+
823
+ rtn_struct(theEnv,ProcParamStack,ptmp);
824
+ ptmp = next;
825
+ }
826
+ }
827
+
828
+ #if DEFGENERIC_CONSTRUCT
829
+
830
+ /***********************************************************
831
+ NAME : GetProcParamExpressions
832
+ DESCRIPTION : Forms an array of expressions equivalent to
833
+ the current procedure paramter array. Used
834
+ to conveniently attach these parameters as
835
+ arguments to a H/L system function call
836
+ (used by the generic dispatch).
837
+ INPUTS : None
838
+ RETURNS : A pointer to an array of expressions
839
+ SIDE EFFECTS : Expression array created
840
+ NOTES : None
841
+ ***********************************************************/
842
+ Expression *GetProcParamExpressions(
843
+ Environment *theEnv)
844
+ {
845
+ unsigned int i;
846
+
847
+ if ((ProceduralPrimitiveData(theEnv)->ProcParamArray == NULL) || (ProceduralPrimitiveData(theEnv)->ProcParamExpressions != NULL))
848
+ return(ProceduralPrimitiveData(theEnv)->ProcParamExpressions);
849
+ ProceduralPrimitiveData(theEnv)->ProcParamExpressions = (Expression *)
850
+ gm2(theEnv,(sizeof(Expression) * ProceduralPrimitiveData(theEnv)->ProcParamArraySize));
851
+ for (i = 0 ; i < ProceduralPrimitiveData(theEnv)->ProcParamArraySize ; i++)
852
+ {
853
+ ProceduralPrimitiveData(theEnv)->ProcParamExpressions[i].type = ProceduralPrimitiveData(theEnv)->ProcParamArray[i].header->type; // TBD Remove
854
+ if (ProceduralPrimitiveData(theEnv)->ProcParamArray[i].header->type != MULTIFIELD_TYPE)
855
+ ProceduralPrimitiveData(theEnv)->ProcParamExpressions[i].value = ProceduralPrimitiveData(theEnv)->ProcParamArray[i].value;
856
+ else
857
+ ProceduralPrimitiveData(theEnv)->ProcParamExpressions[i].value = &ProceduralPrimitiveData(theEnv)->ProcParamArray[i];
858
+ ProceduralPrimitiveData(theEnv)->ProcParamExpressions[i].argList = NULL;
859
+ ProceduralPrimitiveData(theEnv)->ProcParamExpressions[i].nextArg =
860
+ ((i + 1) != ProceduralPrimitiveData(theEnv)->ProcParamArraySize) ? &ProceduralPrimitiveData(theEnv)->ProcParamExpressions[i+1] : NULL;
861
+ }
862
+ return(ProceduralPrimitiveData(theEnv)->ProcParamExpressions);
863
+ }
864
+
865
+ #endif
866
+
867
+ /***********************************************************
868
+ NAME : EvaluateProcActions
869
+ DESCRIPTION : Evaluates the actions of a deffunction,
870
+ generic function method or message-handler.
871
+ INPUTS : 1) The module where the actions should be
872
+ executed
873
+ 2) The actions (linked by nextArg fields)
874
+ 3) The number of local variables to reserve
875
+ space for.
876
+ 4) A buffer to hold the result of evaluating
877
+ the actions.
878
+ 5) A function which prints out the name of
879
+ the currently executing body for error
880
+ messages (can be NULL).
881
+ RETURNS : Nothing useful
882
+ SIDE EFFECTS : Allocates and deallocates space for
883
+ local variable array.
884
+ NOTES : None
885
+ ***********************************************************/
886
+ void EvaluateProcActions(
887
+ Environment *theEnv,
888
+ Defmodule *theModule,
889
+ Expression *actions,
890
+ unsigned short lvarcnt,
891
+ UDFValue *returnValue,
892
+ void (*crtproc)(Environment *,const char *))
893
+ {
894
+ UDFValue *oldLocalVarArray;
895
+ unsigned short i;
896
+ Defmodule *oldModule;
897
+ Expression *oldActions;
898
+ struct trackedMemory *theTM;
899
+
900
+ oldLocalVarArray = ProceduralPrimitiveData(theEnv)->LocalVarArray;
901
+ ProceduralPrimitiveData(theEnv)->LocalVarArray = (lvarcnt == 0) ? NULL :
902
+ (UDFValue *) gm2(theEnv,(sizeof(UDFValue) * lvarcnt));
903
+
904
+ if (lvarcnt != 0)
905
+ { theTM = AddTrackedMemory(theEnv,ProceduralPrimitiveData(theEnv)->LocalVarArray,sizeof(UDFValue) * lvarcnt); }
906
+ else
907
+ { theTM = NULL; }
908
+
909
+ for (i = 0 ; i < lvarcnt ; i++)
910
+ ProceduralPrimitiveData(theEnv)->LocalVarArray[i].supplementalInfo = FalseSymbol(theEnv);
911
+
912
+ oldModule = GetCurrentModule(theEnv);
913
+ if (oldModule != theModule)
914
+ SetCurrentModule(theEnv,theModule);
915
+ oldActions = ProceduralPrimitiveData(theEnv)->CurrentProcActions;
916
+ ProceduralPrimitiveData(theEnv)->CurrentProcActions = actions;
917
+
918
+ if (EvaluateExpression(theEnv,actions,returnValue))
919
+ {
920
+ returnValue->value = FalseSymbol(theEnv);
921
+ }
922
+
923
+ ProceduralPrimitiveData(theEnv)->CurrentProcActions = oldActions;
924
+ if (oldModule != GetCurrentModule(theEnv))
925
+ SetCurrentModule(theEnv,oldModule);
926
+ if ((crtproc != NULL) ? EvaluationData(theEnv)->HaltExecution : false)
927
+ {
928
+ const char *logName;
929
+
930
+ if (GetEvaluationError(theEnv))
931
+ {
932
+ PrintErrorID(theEnv,"PRCCODE",4,false);
933
+ logName = STDERR;
934
+ }
935
+ else
936
+ {
937
+ PrintWarningID(theEnv,"PRCCODE",4,false);
938
+ logName = STDWRN;
939
+ }
940
+ WriteString(theEnv,logName,"Execution halted during the actions of ");
941
+ (*crtproc)(theEnv,logName);
942
+ }
943
+
944
+ if ((ProceduralPrimitiveData(theEnv)->WildcardValue != NULL) ? (returnValue->value == ProceduralPrimitiveData(theEnv)->WildcardValue->value) : false)
945
+ {
946
+ ReleaseMultifield(theEnv,ProceduralPrimitiveData(theEnv)->WildcardValue->multifieldValue);
947
+ if (ProceduralPrimitiveData(theEnv)->WildcardValue->value != ProceduralPrimitiveData(theEnv)->NoParamValue)
948
+ AddToMultifieldList(theEnv,ProceduralPrimitiveData(theEnv)->WildcardValue->multifieldValue);
949
+ rtn_struct(theEnv,udfValue,ProceduralPrimitiveData(theEnv)->WildcardValue);
950
+ ProceduralPrimitiveData(theEnv)->WildcardValue = NULL;
951
+ }
952
+
953
+ if (lvarcnt != 0)
954
+ {
955
+ RemoveTrackedMemory(theEnv,theTM);
956
+ for (i = 0 ; i < lvarcnt ; i++)
957
+ if (ProceduralPrimitiveData(theEnv)->LocalVarArray[i].supplementalInfo == TrueSymbol(theEnv))
958
+ ReleaseUDFV(theEnv,&ProceduralPrimitiveData(theEnv)->LocalVarArray[i]);
959
+ rm(theEnv,ProceduralPrimitiveData(theEnv)->LocalVarArray,(sizeof(UDFValue) * lvarcnt));
960
+ }
961
+
962
+ ProceduralPrimitiveData(theEnv)->LocalVarArray = oldLocalVarArray;
963
+ }
964
+
965
+ /****************************************************
966
+ NAME : PrintProcParamArray
967
+ DESCRIPTION : Displays the contents of the
968
+ current procedure parameter array
969
+ INPUTS : The logical name of the output
970
+ RETURNS : Nothing useful
971
+ SIDE EFFECTS : None
972
+ NOTES : None
973
+ ****************************************************/
974
+ void PrintProcParamArray(
975
+ Environment *theEnv,
976
+ const char *logName)
977
+ {
978
+ unsigned int i;
979
+
980
+ WriteString(theEnv,logName," (");
981
+ for (i = 0 ; i < ProceduralPrimitiveData(theEnv)->ProcParamArraySize ; i++)
982
+ {
983
+ WriteUDFValue(theEnv,logName,&ProceduralPrimitiveData(theEnv)->ProcParamArray[i]);
984
+ if (i != ProceduralPrimitiveData(theEnv)->ProcParamArraySize-1)
985
+ WriteString(theEnv,logName," ");
986
+ }
987
+ WriteString(theEnv,logName,")\n");
988
+ }
989
+
990
+ /****************************************************************
991
+ NAME : GrabProcWildargs
992
+ DESCRIPTION : Groups a portion of the ProcParamArray
993
+ into a multi-field variable
994
+ INPUTS : 1) Starting index in ProcParamArray
995
+ for grouping of arguments into
996
+ multi-field variable
997
+ 2) Caller's result value buffer
998
+ RETURNS : Nothing useful
999
+ SIDE EFFECTS : Multi-field variable allocated and set
1000
+ with corresponding values of ProcParamArray
1001
+ NOTES : Multi-field is NOT on list of ephemeral segments
1002
+ ****************************************************************/
1003
+ void GrabProcWildargs(
1004
+ Environment *theEnv,
1005
+ UDFValue *returnValue,
1006
+ unsigned int theIndex)
1007
+ {
1008
+ unsigned int i, j;
1009
+ size_t k; /* 6.04 Bug Fix */
1010
+ size_t size;
1011
+ UDFValue *val;
1012
+
1013
+ returnValue->begin = 0;
1014
+ if (ProceduralPrimitiveData(theEnv)->WildcardValue == NULL)
1015
+ {
1016
+ ProceduralPrimitiveData(theEnv)->WildcardValue = get_struct(theEnv,udfValue);
1017
+ ProceduralPrimitiveData(theEnv)->WildcardValue->begin = 0;
1018
+ }
1019
+ else if (theIndex == ProceduralPrimitiveData(theEnv)->Oldindex)
1020
+ {
1021
+ returnValue->range = ProceduralPrimitiveData(theEnv)->WildcardValue->range;
1022
+ returnValue->value = ProceduralPrimitiveData(theEnv)->WildcardValue->value;
1023
+ return;
1024
+ }
1025
+ else
1026
+ {
1027
+ ReleaseMultifield(theEnv,ProceduralPrimitiveData(theEnv)->WildcardValue->multifieldValue);
1028
+ if (ProceduralPrimitiveData(theEnv)->WildcardValue->value != ProceduralPrimitiveData(theEnv)->NoParamValue)
1029
+ AddToMultifieldList(theEnv,ProceduralPrimitiveData(theEnv)->WildcardValue->multifieldValue);
1030
+ }
1031
+ ProceduralPrimitiveData(theEnv)->Oldindex = theIndex;
1032
+ size = ProceduralPrimitiveData(theEnv)->ProcParamArraySize + 1 - theIndex;
1033
+
1034
+ if (size == 0)
1035
+ {
1036
+ returnValue->range = 0;
1037
+ ProceduralPrimitiveData(theEnv)->WildcardValue->range = 0;
1038
+ returnValue->value = ProceduralPrimitiveData(theEnv)->WildcardValue->value = ProceduralPrimitiveData(theEnv)->NoParamValue;
1039
+ RetainMultifield(theEnv,ProceduralPrimitiveData(theEnv)->WildcardValue->multifieldValue);
1040
+ return;
1041
+ }
1042
+ for (i = theIndex-1 ; i < ProceduralPrimitiveData(theEnv)->ProcParamArraySize ; i++)
1043
+ {
1044
+ if (ProceduralPrimitiveData(theEnv)->ProcParamArray[i].header->type == MULTIFIELD_TYPE)
1045
+ size += ProceduralPrimitiveData(theEnv)->ProcParamArray[i].range - 1;
1046
+ }
1047
+ returnValue->range = size;
1048
+ ProceduralPrimitiveData(theEnv)->WildcardValue->range = size;
1049
+ returnValue->value = ProceduralPrimitiveData(theEnv)->WildcardValue->value = CreateUnmanagedMultifield(theEnv,size);
1050
+ for (i = theIndex-1 , j = 0 ; i < ProceduralPrimitiveData(theEnv)->ProcParamArraySize ; i++)
1051
+ {
1052
+ if (ProceduralPrimitiveData(theEnv)->ProcParamArray[i].header->type != MULTIFIELD_TYPE)
1053
+ {
1054
+ returnValue->multifieldValue->contents[j].value = ProceduralPrimitiveData(theEnv)->ProcParamArray[i].value;
1055
+ j++;
1056
+ }
1057
+ else
1058
+ {
1059
+ val = &ProceduralPrimitiveData(theEnv)->ProcParamArray[i];
1060
+ for (k = val->begin ; k < (val->begin + val->range) ; k++ , j++)
1061
+ {
1062
+ returnValue->multifieldValue->contents[j].value = val->multifieldValue->contents[k].value;
1063
+ }
1064
+ }
1065
+ }
1066
+ RetainMultifield(theEnv,ProceduralPrimitiveData(theEnv)->WildcardValue->multifieldValue);
1067
+ }
1068
+
1069
+ /* =========================================
1070
+ *****************************************
1071
+ INTERNALLY VISIBLE FUNCTIONS
1072
+ =========================================
1073
+ ***************************************** */
1074
+
1075
+ /*******************************************************************
1076
+ NAME : EvaluateProcParameters
1077
+ DESCRIPTION : Given a list of parameter expressions,
1078
+ this function evaluates each expression
1079
+ and stores the results in a contiguous
1080
+ array of DATA_OBJECTS. Used in creating a new
1081
+ ProcParamArray for the execution of a
1082
+ procedure
1083
+ INPUTS : 1) The paramter expression list
1084
+ 2) The number of parameters in the list
1085
+ 3) The name of the procedure for which
1086
+ these parameters are being evaluated
1087
+ 4) The type of procedure
1088
+ RETURNS : Nothing useful
1089
+ SIDE EFFECTS : Any side-effects of the evaluation of the
1090
+ parameter expressions
1091
+ UDFValue array allocated (deallocated on errors)
1092
+ ProcParamArray set
1093
+ NOTES : EvaluationError set on errors
1094
+ *******************************************************************/
1095
+ static void EvaluateProcParameters(
1096
+ Environment *theEnv,
1097
+ Expression *parameterList,
1098
+ unsigned int numberOfParameters,
1099
+ const char *pname,
1100
+ const char *bodytype)
1101
+ {
1102
+ UDFValue *rva,temp;
1103
+ int i = 0;
1104
+
1105
+ if (numberOfParameters == 0)
1106
+ {
1107
+ ProceduralPrimitiveData(theEnv)->ProcParamArray = NULL;
1108
+ ProceduralPrimitiveData(theEnv)->ProcParamArraySize = 0;
1109
+ return;
1110
+ }
1111
+
1112
+ rva = (UDFValue *) gm2(theEnv,(sizeof(UDFValue) * numberOfParameters));
1113
+ while (parameterList != NULL)
1114
+ {
1115
+ if ((EvaluateExpression(theEnv,parameterList,&temp) == true) ? true :
1116
+ (temp.header->type == VOID_TYPE))
1117
+ {
1118
+ if (temp.header->type == VOID_TYPE)
1119
+ {
1120
+ PrintErrorID(theEnv,"PRCCODE",2,false);
1121
+ WriteString(theEnv,STDERR,"Functions without a return value are illegal as ");
1122
+ WriteString(theEnv,STDERR,bodytype);
1123
+ WriteString(theEnv,STDERR," arguments.\n");
1124
+ SetEvaluationError(theEnv,true);
1125
+ }
1126
+ PrintErrorID(theEnv,"PRCCODE",6,false);
1127
+ WriteString(theEnv,STDERR,"This error occurred while evaluating arguments ");
1128
+ WriteString(theEnv,STDERR,"for the ");
1129
+ WriteString(theEnv,STDERR,bodytype);
1130
+ WriteString(theEnv,STDERR," '");
1131
+ WriteString(theEnv,STDERR,pname);
1132
+ WriteString(theEnv,STDERR,"'.\n");
1133
+ rm(theEnv,rva,(sizeof(UDFValue) * numberOfParameters));
1134
+ return;
1135
+ }
1136
+ rva[i].value = temp.value;
1137
+ rva[i].begin = temp.begin;
1138
+ rva[i].range = temp.range;
1139
+ parameterList = parameterList->nextArg;
1140
+ i++;
1141
+ }
1142
+ ProceduralPrimitiveData(theEnv)->ProcParamArraySize = numberOfParameters;
1143
+ ProceduralPrimitiveData(theEnv)->ProcParamArray = rva;
1144
+ }
1145
+
1146
+ /***************************************************
1147
+ NAME : RtnProcParam
1148
+ DESCRIPTION : Internal function for getting the
1149
+ value of an argument passed to
1150
+ a procedure
1151
+ INPUTS : 1) Expression to evaluate
1152
+ (PROC_PARAM index)
1153
+ 2) Caller's result value buffer
1154
+ RETURNS : Nothing useful
1155
+ SIDE EFFECTS : Caller's buffer set to specified
1156
+ node of ProcParamArray
1157
+ NOTES : None
1158
+ ***************************************************/
1159
+ static bool RtnProcParam(
1160
+ Environment *theEnv,
1161
+ void *value,
1162
+ UDFValue *returnValue)
1163
+ {
1164
+ UDFValue *src;
1165
+
1166
+ src = &ProceduralPrimitiveData(theEnv)->ProcParamArray[*((const int *) ((CLIPSBitMap *) value)->contents) - 1];
1167
+ returnValue->value = src->value;
1168
+ returnValue->begin = src->begin;
1169
+ returnValue->range = src->range;
1170
+ return true;
1171
+ }
1172
+
1173
+ /**************************************************************
1174
+ NAME : GetProcBind
1175
+ DESCRIPTION : Internal function for looking up the
1176
+ values of parameters or bound variables
1177
+ within procedures
1178
+ INPUTS : 1) Expression to evaluate
1179
+ (PROC_GET_BIND index)
1180
+ 2) Caller's result value buffer
1181
+ RETURNS : Nothing useful
1182
+ SIDE EFFECTS : Caller's buffer set to parameter value in
1183
+ ProcParamArray or the value in LocalVarArray
1184
+ NOTES : None
1185
+ **************************************************************/
1186
+ static bool GetProcBind(
1187
+ Environment *theEnv,
1188
+ void *value,
1189
+ UDFValue *returnValue)
1190
+ {
1191
+ UDFValue *src;
1192
+ const PACKED_PROC_VAR *pvar;
1193
+
1194
+ pvar = (const PACKED_PROC_VAR *) ((CLIPSBitMap *) value)->contents;
1195
+ src = &ProceduralPrimitiveData(theEnv)->LocalVarArray[pvar->first - 1];
1196
+ if (src->supplementalInfo == TrueSymbol(theEnv))
1197
+ {
1198
+ returnValue->value = src->value;
1199
+ returnValue->begin = src->begin;
1200
+ returnValue->range = src->range;
1201
+ return true;
1202
+ }
1203
+ if (GetFirstArgument()->nextArg != NULL)
1204
+ {
1205
+ EvaluateExpression(theEnv,GetFirstArgument()->nextArg,returnValue);
1206
+ return true;
1207
+ }
1208
+ if (pvar->second == 0)
1209
+ {
1210
+ PrintErrorID(theEnv,"PRCCODE",5,false);
1211
+ SetEvaluationError(theEnv,true);
1212
+ WriteString(theEnv,STDERR,"Variable ?");
1213
+ WriteString(theEnv,STDERR,GetFirstArgument()->lexemeValue->contents);
1214
+ if (ProceduralPrimitiveData(theEnv)->ProcUnboundErrFunc != NULL)
1215
+ {
1216
+ WriteString(theEnv,STDERR," unbound in ");
1217
+ (*ProceduralPrimitiveData(theEnv)->ProcUnboundErrFunc)(theEnv,STDERR);
1218
+ }
1219
+ else
1220
+ WriteString(theEnv,STDERR," unbound.\n");
1221
+ returnValue->value = FalseSymbol(theEnv);
1222
+ return true;
1223
+ }
1224
+ if (pvar->secondFlag == 0)
1225
+ {
1226
+ src = &ProceduralPrimitiveData(theEnv)->ProcParamArray[pvar->second - 1];
1227
+ returnValue->value = src->value;
1228
+ returnValue->begin = src->begin;
1229
+ returnValue->range = src->range;
1230
+ }
1231
+ else
1232
+ GrabProcWildargs(theEnv,returnValue,pvar->second);
1233
+ return true;
1234
+ }
1235
+
1236
+ /**************************************************************
1237
+ NAME : PutProcBind
1238
+ DESCRIPTION : Internal function for setting the values of
1239
+ of locally bound variables within procedures
1240
+ INPUTS : 1) Expression to evaluate
1241
+ (PROC_PARAM index)
1242
+ 2) Caller's result value buffer
1243
+ RETURNS : Nothing useful
1244
+ SIDE EFFECTS : Bound variable in LocalVarArray set to
1245
+ value in caller's buffer.
1246
+ NOTES : None
1247
+ **************************************************************/
1248
+ static bool PutProcBind(
1249
+ Environment *theEnv,
1250
+ void *value,
1251
+ UDFValue *returnValue)
1252
+ {
1253
+ UDFValue *dst;
1254
+
1255
+ dst = &ProceduralPrimitiveData(theEnv)->LocalVarArray[*((const int *) ((CLIPSBitMap *) value)->contents) - 1];
1256
+ if (GetFirstArgument() == NULL)
1257
+ {
1258
+ if (dst->supplementalInfo == TrueSymbol(theEnv))
1259
+ ReleaseUDFV(theEnv,dst);
1260
+ dst->supplementalInfo = FalseSymbol(theEnv);
1261
+ returnValue->value = FalseSymbol(theEnv);
1262
+ }
1263
+ else
1264
+ {
1265
+ if (GetFirstArgument()->nextArg != NULL)
1266
+ StoreInMultifield(theEnv,returnValue,GetFirstArgument(),true);
1267
+ else
1268
+ EvaluateExpression(theEnv,GetFirstArgument(),returnValue);
1269
+ if (dst->supplementalInfo == TrueSymbol(theEnv))
1270
+ ReleaseUDFV(theEnv,dst);
1271
+ dst->supplementalInfo = TrueSymbol(theEnv);
1272
+ dst->value = returnValue->value;
1273
+ dst->begin = returnValue->begin;
1274
+ dst->range = returnValue->range;
1275
+ RetainUDFV(theEnv,dst);
1276
+ }
1277
+ return true;
1278
+ }
1279
+
1280
+ /****************************************************************
1281
+ NAME : RtnProcWild
1282
+ DESCRIPTION : Groups a portion of the ProcParamArray
1283
+ into a multi-field variable
1284
+ INPUTS : 1) Starting index in ProcParamArray
1285
+ for grouping of arguments into
1286
+ multi-field variable (expression value)
1287
+ 2) Caller's result value buffer
1288
+ RETURNS : Nothing useful
1289
+ SIDE EFFECTS : Multi-field variable allocated and set
1290
+ with corresponding values of ProcParamArray
1291
+ NOTES : Multi-field is NOT on list of ephemeral segments
1292
+ ****************************************************************/
1293
+ static bool RtnProcWild(
1294
+ Environment *theEnv,
1295
+ void *value,
1296
+ UDFValue *returnValue)
1297
+ {
1298
+ GrabProcWildargs(theEnv,returnValue,*(const unsigned *) ((CLIPSBitMap *) value)->contents);
1299
+ return true;
1300
+ }
1301
+
1302
+ #if (! BLOAD_ONLY) && (! RUN_TIME)
1303
+
1304
+ /***************************************************
1305
+ NAME : FindProcParameter
1306
+ DESCRIPTION : Determines the relative position in
1307
+ an n-element list of a certain
1308
+ parameter. The index is 1..n.
1309
+ INPUTS : 1) Parameter name
1310
+ 2) Parameter list
1311
+ 3) Wildcard symbol (NULL if none)
1312
+ RETURNS : Index of parameter in list, 0 if
1313
+ not found
1314
+ SIDE EFFECTS : None
1315
+ NOTES : None
1316
+ ***************************************************/
1317
+ static unsigned int FindProcParameter(
1318
+ CLIPSLexeme *name,
1319
+ Expression *parameterList,
1320
+ CLIPSLexeme *wildcard)
1321
+ {
1322
+ unsigned int i = 1;
1323
+
1324
+ while (parameterList != NULL)
1325
+ {
1326
+ if (parameterList->value == (void *) name)
1327
+ { return i; }
1328
+ i++;
1329
+ parameterList = parameterList->nextArg;
1330
+ }
1331
+
1332
+ /* ===================================================================
1333
+ Wildcard may not be stored in actual list but know is always at end
1334
+ =================================================================== */
1335
+ if (name == wildcard)
1336
+ { return i; }
1337
+
1338
+ return 0;
1339
+ }
1340
+
1341
+ /*************************************************************************
1342
+ NAME : ReplaceProcBinds
1343
+ DESCRIPTION : Examines an expression and replaces calls to the
1344
+ "bind" function which are specially recognized
1345
+
1346
+ For example, in a message-handler,
1347
+
1348
+ (bind ?self <value>) would be illegal
1349
+
1350
+ and
1351
+
1352
+ (bind ?self:<slot-name> <value>) would be
1353
+ replaced with
1354
+ (put <slot-name> <value>)
1355
+
1356
+ INPUTS : 1) The actions in which to replace special binds
1357
+ 2) A pointer to a function to handle binds in a
1358
+ special way. The function should accept the
1359
+ bind function call expression and a specialized
1360
+ data buffer (can be NULL) as arguments.
1361
+ If the variable is recognized and treated specially,
1362
+ the function should modify the expression
1363
+ appropriately (including attaching/removing
1364
+ any necessary argument expressions). Return 1
1365
+ if recognized, 0 if not, -1 on errors.
1366
+ This argument CANNOT be NULL.
1367
+ 3) Specialized user data buffer
1368
+ RETURNS : False if OK, true on errors
1369
+ SIDE EFFECTS : Some binds replaced with specialized calls
1370
+ NOTES : Local variable binds are replaced in ReplaceProcVars
1371
+ (after this routine has had a chance to replace all
1372
+ special binds and remove the names from the parsed
1373
+ bind list)
1374
+ *************************************************************************/
1375
+ static bool ReplaceProcBinds(
1376
+ Environment *theEnv,
1377
+ Expression *actions,
1378
+ int (*altbindfunc)(Environment *,Expression *,void *),
1379
+ void *userBuffer)
1380
+ {
1381
+ int bcode;
1382
+ CLIPSLexeme *bname;
1383
+
1384
+ while (actions != NULL)
1385
+ {
1386
+ if (actions->argList != NULL)
1387
+ {
1388
+ if (ReplaceProcBinds(theEnv,actions->argList,altbindfunc,userBuffer))
1389
+ return true;
1390
+ if ((actions->value == (void *) FindFunction(theEnv,"bind")) &&
1391
+ (actions->argList->type == SYMBOL_TYPE))
1392
+ {
1393
+ bname = actions->argList->lexemeValue;
1394
+ bcode = (*altbindfunc)(theEnv,actions,userBuffer);
1395
+ if (bcode == -1)
1396
+ return true;
1397
+ if (bcode == 1)
1398
+ RemoveParsedBindName(theEnv,bname);
1399
+ }
1400
+ }
1401
+ actions = actions->nextArg;
1402
+ }
1403
+ return false;
1404
+ }
1405
+
1406
+ /*****************************************************
1407
+ NAME : CompactActions
1408
+ DESCRIPTION : Examines a progn expression chain,
1409
+ and if there is only one action,
1410
+ the progn header is deallocated and
1411
+ the action is returned. If there are
1412
+ no actions, the progn expression is
1413
+ modified to be the FALSE symbol
1414
+ and returned. Otherwise, the progn
1415
+ is simply returned.
1416
+ INPUTS : The action expression
1417
+ RETURNS : The compacted expression
1418
+ SIDE EFFECTS : Some expressions possibly deallocated
1419
+ NOTES : Assumes actions is a progn expression
1420
+ and actions->nextArg == NULL
1421
+ *****************************************************/
1422
+ static Expression *CompactActions(
1423
+ Environment *theEnv,
1424
+ Expression *actions)
1425
+ {
1426
+ struct expr *tmp;
1427
+
1428
+ if (actions->argList == NULL)
1429
+ {
1430
+ actions->type = SYMBOL_TYPE;
1431
+ actions->value = FalseSymbol(theEnv);
1432
+ }
1433
+ else if (actions->argList->nextArg == NULL)
1434
+ {
1435
+ tmp = actions;
1436
+ actions = actions->argList;
1437
+ rtn_struct(theEnv,expr,tmp);
1438
+ }
1439
+ return(actions);
1440
+ }
1441
+
1442
+ #endif
1443
+
1444
+ #if (! DEFFUNCTION_CONSTRUCT) || (! DEFGENERIC_CONSTRUCT)
1445
+
1446
+ /******************************************************
1447
+ NAME : EvaluateBadCall
1448
+ DESCRIPTION : Default evaluation function for
1449
+ deffunctions and gneric functions
1450
+ in configurations where either
1451
+ capability is not present.
1452
+ INPUTS : 1) The function (ignored)
1453
+ 2) A data object buffer for the result
1454
+ RETURNS : False
1455
+ SIDE EFFECTS : Data object buffer set to the
1456
+ symbol FALSE and evaluation error set
1457
+ NOTES : Used for binary images which
1458
+ contain deffunctions and generic
1459
+ functions which cannot be used
1460
+ ******************************************************/
1461
+ static bool EvaluateBadCall(
1462
+ Environment *theEnv,
1463
+ void *value,
1464
+ UDFValue *returnValue)
1465
+ {
1466
+ #if MAC_XCD
1467
+ #pragma unused(value)
1468
+ #endif
1469
+ PrintErrorID(theEnv,"PRCCODE",1,false);
1470
+ WriteString(theEnv,STDERR,"Attempted to call a deffunction/generic function ");
1471
+ WriteString(theEnv,STDERR,"which does not exist.\n");
1472
+ SetEvaluationError(theEnv,true);
1473
+ returnValue->value = FalseSymbol(theEnv);
1474
+ return false;
1475
+ }
1476
+
1477
+ #endif
1478
+