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.
- checksums.yaml +7 -0
- data/ext/clipsruby/agenda.c +1373 -0
- data/ext/clipsruby/agenda.h +169 -0
- data/ext/clipsruby/analysis.c +1142 -0
- data/ext/clipsruby/analysis.h +61 -0
- data/ext/clipsruby/argacces.c +526 -0
- data/ext/clipsruby/argacces.h +77 -0
- data/ext/clipsruby/bload.c +884 -0
- data/ext/clipsruby/bload.h +94 -0
- data/ext/clipsruby/bmathfun.c +557 -0
- data/ext/clipsruby/bmathfun.h +66 -0
- data/ext/clipsruby/bsave.c +634 -0
- data/ext/clipsruby/bsave.h +130 -0
- data/ext/clipsruby/classcom.c +976 -0
- data/ext/clipsruby/classcom.h +115 -0
- data/ext/clipsruby/classexm.c +1376 -0
- data/ext/clipsruby/classexm.h +97 -0
- data/ext/clipsruby/classfun.c +1392 -0
- data/ext/clipsruby/classfun.h +164 -0
- data/ext/clipsruby/classinf.c +1245 -0
- data/ext/clipsruby/classinf.h +94 -0
- data/ext/clipsruby/classini.c +843 -0
- data/ext/clipsruby/classini.h +75 -0
- data/ext/clipsruby/classpsr.c +957 -0
- data/ext/clipsruby/classpsr.h +73 -0
- data/ext/clipsruby/clips.h +133 -0
- data/ext/clipsruby/clipsruby.c +619 -0
- data/ext/clipsruby/clsltpsr.c +931 -0
- data/ext/clipsruby/clsltpsr.h +72 -0
- data/ext/clipsruby/commline.c +1217 -0
- data/ext/clipsruby/commline.h +131 -0
- data/ext/clipsruby/conscomp.c +1593 -0
- data/ext/clipsruby/conscomp.h +150 -0
- data/ext/clipsruby/constant.h +264 -0
- data/ext/clipsruby/constrct.c +1090 -0
- data/ext/clipsruby/constrct.h +216 -0
- data/ext/clipsruby/constrnt.c +554 -0
- data/ext/clipsruby/constrnt.h +132 -0
- data/ext/clipsruby/crstrtgy.c +1088 -0
- data/ext/clipsruby/crstrtgy.h +85 -0
- data/ext/clipsruby/cstrcbin.c +185 -0
- data/ext/clipsruby/cstrcbin.h +61 -0
- data/ext/clipsruby/cstrccmp.h +43 -0
- data/ext/clipsruby/cstrccom.c +1791 -0
- data/ext/clipsruby/cstrccom.h +115 -0
- data/ext/clipsruby/cstrcpsr.c +835 -0
- data/ext/clipsruby/cstrcpsr.h +97 -0
- data/ext/clipsruby/cstrnbin.c +282 -0
- data/ext/clipsruby/cstrnbin.h +55 -0
- data/ext/clipsruby/cstrnchk.c +826 -0
- data/ext/clipsruby/cstrnchk.h +91 -0
- data/ext/clipsruby/cstrncmp.c +238 -0
- data/ext/clipsruby/cstrncmp.h +57 -0
- data/ext/clipsruby/cstrnops.c +1176 -0
- data/ext/clipsruby/cstrnops.h +47 -0
- data/ext/clipsruby/cstrnpsr.c +1394 -0
- data/ext/clipsruby/cstrnpsr.h +88 -0
- data/ext/clipsruby/cstrnutl.c +564 -0
- data/ext/clipsruby/cstrnutl.h +54 -0
- data/ext/clipsruby/default.c +454 -0
- data/ext/clipsruby/default.h +57 -0
- data/ext/clipsruby/defins.c +971 -0
- data/ext/clipsruby/defins.h +127 -0
- data/ext/clipsruby/developr.c +677 -0
- data/ext/clipsruby/developr.h +69 -0
- data/ext/clipsruby/dffctbin.c +477 -0
- data/ext/clipsruby/dffctbin.h +76 -0
- data/ext/clipsruby/dffctbsc.c +308 -0
- data/ext/clipsruby/dffctbsc.h +72 -0
- data/ext/clipsruby/dffctcmp.c +297 -0
- data/ext/clipsruby/dffctcmp.h +44 -0
- data/ext/clipsruby/dffctdef.c +364 -0
- data/ext/clipsruby/dffctdef.h +104 -0
- data/ext/clipsruby/dffctpsr.c +179 -0
- data/ext/clipsruby/dffctpsr.h +49 -0
- data/ext/clipsruby/dffnxbin.c +520 -0
- data/ext/clipsruby/dffnxbin.h +67 -0
- data/ext/clipsruby/dffnxcmp.c +378 -0
- data/ext/clipsruby/dffnxcmp.h +54 -0
- data/ext/clipsruby/dffnxexe.c +241 -0
- data/ext/clipsruby/dffnxexe.h +58 -0
- data/ext/clipsruby/dffnxfun.c +1192 -0
- data/ext/clipsruby/dffnxfun.h +155 -0
- data/ext/clipsruby/dffnxpsr.c +514 -0
- data/ext/clipsruby/dffnxpsr.h +57 -0
- data/ext/clipsruby/dfinsbin.c +509 -0
- data/ext/clipsruby/dfinsbin.h +66 -0
- data/ext/clipsruby/dfinscmp.c +345 -0
- data/ext/clipsruby/dfinscmp.h +48 -0
- data/ext/clipsruby/drive.c +1191 -0
- data/ext/clipsruby/drive.h +65 -0
- data/ext/clipsruby/emathfun.c +1213 -0
- data/ext/clipsruby/emathfun.h +99 -0
- data/ext/clipsruby/engine.c +1568 -0
- data/ext/clipsruby/engine.h +203 -0
- data/ext/clipsruby/entities.h +276 -0
- data/ext/clipsruby/envrnbld.c +514 -0
- data/ext/clipsruby/envrnbld.h +40 -0
- data/ext/clipsruby/envrnmnt.c +257 -0
- data/ext/clipsruby/envrnmnt.h +112 -0
- data/ext/clipsruby/evaluatn.c +1736 -0
- data/ext/clipsruby/evaluatn.h +211 -0
- data/ext/clipsruby/expressn.c +494 -0
- data/ext/clipsruby/expressn.h +154 -0
- data/ext/clipsruby/exprnbin.c +538 -0
- data/ext/clipsruby/exprnbin.h +60 -0
- data/ext/clipsruby/exprnops.c +564 -0
- data/ext/clipsruby/exprnops.h +67 -0
- data/ext/clipsruby/exprnpsr.c +1112 -0
- data/ext/clipsruby/exprnpsr.h +98 -0
- data/ext/clipsruby/extconf.rb +2 -0
- data/ext/clipsruby/extnfunc.c +1015 -0
- data/ext/clipsruby/extnfunc.h +157 -0
- data/ext/clipsruby/factbin.c +447 -0
- data/ext/clipsruby/factbin.h +56 -0
- data/ext/clipsruby/factbld.c +1035 -0
- data/ext/clipsruby/factbld.h +63 -0
- data/ext/clipsruby/factcmp.c +386 -0
- data/ext/clipsruby/factcmp.h +46 -0
- data/ext/clipsruby/factcom.c +759 -0
- data/ext/clipsruby/factcom.h +80 -0
- data/ext/clipsruby/factfile.c +1761 -0
- data/ext/clipsruby/factfile.h +54 -0
- data/ext/clipsruby/factfun.c +682 -0
- data/ext/clipsruby/factfun.h +77 -0
- data/ext/clipsruby/factgen.c +1305 -0
- data/ext/clipsruby/factgen.h +229 -0
- data/ext/clipsruby/facthsh.c +438 -0
- data/ext/clipsruby/facthsh.h +81 -0
- data/ext/clipsruby/factlhs.c +250 -0
- data/ext/clipsruby/factlhs.h +54 -0
- data/ext/clipsruby/factmch.c +905 -0
- data/ext/clipsruby/factmch.h +68 -0
- data/ext/clipsruby/factmngr.c +3373 -0
- data/ext/clipsruby/factmngr.h +325 -0
- data/ext/clipsruby/factprt.c +498 -0
- data/ext/clipsruby/factprt.h +60 -0
- data/ext/clipsruby/factqpsr.c +796 -0
- data/ext/clipsruby/factqpsr.h +61 -0
- data/ext/clipsruby/factqury.c +1267 -0
- data/ext/clipsruby/factqury.h +112 -0
- data/ext/clipsruby/factrete.c +978 -0
- data/ext/clipsruby/factrete.h +70 -0
- data/ext/clipsruby/factrhs.c +667 -0
- data/ext/clipsruby/factrhs.h +55 -0
- data/ext/clipsruby/filecom.c +353 -0
- data/ext/clipsruby/filecom.h +137 -0
- data/ext/clipsruby/filertr.c +481 -0
- data/ext/clipsruby/filertr.h +94 -0
- data/ext/clipsruby/fileutil.c +1020 -0
- data/ext/clipsruby/fileutil.h +50 -0
- data/ext/clipsruby/generate.c +1079 -0
- data/ext/clipsruby/generate.h +57 -0
- data/ext/clipsruby/genrcbin.c +902 -0
- data/ext/clipsruby/genrcbin.h +69 -0
- data/ext/clipsruby/genrccmp.c +640 -0
- data/ext/clipsruby/genrccmp.h +59 -0
- data/ext/clipsruby/genrccom.c +2017 -0
- data/ext/clipsruby/genrccom.h +119 -0
- data/ext/clipsruby/genrcexe.c +737 -0
- data/ext/clipsruby/genrcexe.h +73 -0
- data/ext/clipsruby/genrcfun.c +890 -0
- data/ext/clipsruby/genrcfun.h +185 -0
- data/ext/clipsruby/genrcpsr.c +1618 -0
- data/ext/clipsruby/genrcpsr.h +80 -0
- data/ext/clipsruby/globlbin.c +458 -0
- data/ext/clipsruby/globlbin.h +71 -0
- data/ext/clipsruby/globlbsc.c +361 -0
- data/ext/clipsruby/globlbsc.h +83 -0
- data/ext/clipsruby/globlcmp.c +330 -0
- data/ext/clipsruby/globlcmp.h +52 -0
- data/ext/clipsruby/globlcom.c +289 -0
- data/ext/clipsruby/globlcom.h +63 -0
- data/ext/clipsruby/globldef.c +1087 -0
- data/ext/clipsruby/globldef.h +151 -0
- data/ext/clipsruby/globlpsr.c +530 -0
- data/ext/clipsruby/globlpsr.h +59 -0
- data/ext/clipsruby/immthpsr.c +431 -0
- data/ext/clipsruby/immthpsr.h +55 -0
- data/ext/clipsruby/incrrset.c +530 -0
- data/ext/clipsruby/incrrset.h +73 -0
- data/ext/clipsruby/inherpsr.c +850 -0
- data/ext/clipsruby/inherpsr.h +52 -0
- data/ext/clipsruby/inscom.c +2076 -0
- data/ext/clipsruby/inscom.h +182 -0
- data/ext/clipsruby/insfile.c +1764 -0
- data/ext/clipsruby/insfile.h +96 -0
- data/ext/clipsruby/insfun.c +1451 -0
- data/ext/clipsruby/insfun.h +134 -0
- data/ext/clipsruby/insmngr.c +2550 -0
- data/ext/clipsruby/insmngr.h +125 -0
- data/ext/clipsruby/insmoddp.c +1041 -0
- data/ext/clipsruby/insmoddp.h +91 -0
- data/ext/clipsruby/insmult.c +804 -0
- data/ext/clipsruby/insmult.h +62 -0
- data/ext/clipsruby/inspsr.c +602 -0
- data/ext/clipsruby/inspsr.h +60 -0
- data/ext/clipsruby/insquery.c +1278 -0
- data/ext/clipsruby/insquery.h +115 -0
- data/ext/clipsruby/insqypsr.c +729 -0
- data/ext/clipsruby/insqypsr.h +63 -0
- data/ext/clipsruby/iofun.c +2045 -0
- data/ext/clipsruby/iofun.h +116 -0
- data/ext/clipsruby/lgcldpnd.c +644 -0
- data/ext/clipsruby/lgcldpnd.h +75 -0
- data/ext/clipsruby/main.c +112 -0
- data/ext/clipsruby/match.h +142 -0
- data/ext/clipsruby/memalloc.c +481 -0
- data/ext/clipsruby/memalloc.h +197 -0
- data/ext/clipsruby/miscfun.c +1801 -0
- data/ext/clipsruby/miscfun.h +132 -0
- data/ext/clipsruby/modulbin.c +607 -0
- data/ext/clipsruby/modulbin.h +84 -0
- data/ext/clipsruby/modulbsc.c +347 -0
- data/ext/clipsruby/modulbsc.h +67 -0
- data/ext/clipsruby/modulcmp.c +499 -0
- data/ext/clipsruby/modulcmp.h +54 -0
- data/ext/clipsruby/moduldef.c +817 -0
- data/ext/clipsruby/moduldef.h +271 -0
- data/ext/clipsruby/modulpsr.c +1150 -0
- data/ext/clipsruby/modulpsr.h +69 -0
- data/ext/clipsruby/modulutl.c +1036 -0
- data/ext/clipsruby/modulutl.h +84 -0
- data/ext/clipsruby/msgcom.c +1221 -0
- data/ext/clipsruby/msgcom.h +125 -0
- data/ext/clipsruby/msgfun.c +1076 -0
- data/ext/clipsruby/msgfun.h +118 -0
- data/ext/clipsruby/msgpass.c +1441 -0
- data/ext/clipsruby/msgpass.h +103 -0
- data/ext/clipsruby/msgpsr.c +698 -0
- data/ext/clipsruby/msgpsr.h +73 -0
- data/ext/clipsruby/multifld.c +1404 -0
- data/ext/clipsruby/multifld.h +130 -0
- data/ext/clipsruby/multifun.c +2182 -0
- data/ext/clipsruby/multifun.h +102 -0
- data/ext/clipsruby/network.h +142 -0
- data/ext/clipsruby/objbin.c +1522 -0
- data/ext/clipsruby/objbin.h +79 -0
- data/ext/clipsruby/objcmp.c +1507 -0
- data/ext/clipsruby/objcmp.h +71 -0
- data/ext/clipsruby/object.h +260 -0
- data/ext/clipsruby/objrtbin.c +701 -0
- data/ext/clipsruby/objrtbin.h +79 -0
- data/ext/clipsruby/objrtbld.c +2393 -0
- data/ext/clipsruby/objrtbld.h +66 -0
- data/ext/clipsruby/objrtcmp.c +734 -0
- data/ext/clipsruby/objrtcmp.h +66 -0
- data/ext/clipsruby/objrtfnx.c +1330 -0
- data/ext/clipsruby/objrtfnx.h +222 -0
- data/ext/clipsruby/objrtgen.c +736 -0
- data/ext/clipsruby/objrtgen.h +63 -0
- data/ext/clipsruby/objrtmch.c +1524 -0
- data/ext/clipsruby/objrtmch.h +160 -0
- data/ext/clipsruby/parsefun.c +415 -0
- data/ext/clipsruby/parsefun.h +67 -0
- data/ext/clipsruby/pattern.c +1265 -0
- data/ext/clipsruby/pattern.h +163 -0
- data/ext/clipsruby/pprint.c +328 -0
- data/ext/clipsruby/pprint.h +79 -0
- data/ext/clipsruby/prccode.c +1478 -0
- data/ext/clipsruby/prccode.h +145 -0
- data/ext/clipsruby/prcdrfun.c +640 -0
- data/ext/clipsruby/prcdrfun.h +95 -0
- data/ext/clipsruby/prcdrpsr.c +1068 -0
- data/ext/clipsruby/prcdrpsr.h +79 -0
- data/ext/clipsruby/prdctfun.c +869 -0
- data/ext/clipsruby/prdctfun.h +77 -0
- data/ext/clipsruby/prntutil.c +878 -0
- data/ext/clipsruby/prntutil.h +125 -0
- data/ext/clipsruby/proflfun.c +827 -0
- data/ext/clipsruby/proflfun.h +118 -0
- data/ext/clipsruby/reorder.c +2082 -0
- data/ext/clipsruby/reorder.h +172 -0
- data/ext/clipsruby/reteutil.c +1732 -0
- data/ext/clipsruby/reteutil.h +111 -0
- data/ext/clipsruby/retract.c +710 -0
- data/ext/clipsruby/retract.h +74 -0
- data/ext/clipsruby/router.c +737 -0
- data/ext/clipsruby/router.h +147 -0
- data/ext/clipsruby/rulebin.c +1136 -0
- data/ext/clipsruby/rulebin.h +153 -0
- data/ext/clipsruby/rulebld.c +1328 -0
- data/ext/clipsruby/rulebld.h +62 -0
- data/ext/clipsruby/rulebsc.c +517 -0
- data/ext/clipsruby/rulebsc.h +91 -0
- data/ext/clipsruby/rulecmp.c +733 -0
- data/ext/clipsruby/rulecmp.h +63 -0
- data/ext/clipsruby/rulecom.c +1583 -0
- data/ext/clipsruby/rulecom.h +116 -0
- data/ext/clipsruby/rulecstr.c +892 -0
- data/ext/clipsruby/rulecstr.h +53 -0
- data/ext/clipsruby/ruledef.c +559 -0
- data/ext/clipsruby/ruledef.h +179 -0
- data/ext/clipsruby/ruledlt.c +599 -0
- data/ext/clipsruby/ruledlt.h +58 -0
- data/ext/clipsruby/rulelhs.c +1216 -0
- data/ext/clipsruby/rulelhs.h +52 -0
- data/ext/clipsruby/rulepsr.c +1073 -0
- data/ext/clipsruby/rulepsr.h +61 -0
- data/ext/clipsruby/scanner.c +856 -0
- data/ext/clipsruby/scanner.h +112 -0
- data/ext/clipsruby/setup.h +488 -0
- data/ext/clipsruby/sortfun.c +433 -0
- data/ext/clipsruby/sortfun.h +55 -0
- data/ext/clipsruby/strngfun.c +1173 -0
- data/ext/clipsruby/strngfun.h +96 -0
- data/ext/clipsruby/strngrtr.c +523 -0
- data/ext/clipsruby/strngrtr.h +97 -0
- data/ext/clipsruby/symblbin.c +648 -0
- data/ext/clipsruby/symblbin.h +64 -0
- data/ext/clipsruby/symblcmp.c +893 -0
- data/ext/clipsruby/symblcmp.h +61 -0
- data/ext/clipsruby/symbol.c +1961 -0
- data/ext/clipsruby/symbol.h +243 -0
- data/ext/clipsruby/sysdep.c +894 -0
- data/ext/clipsruby/sysdep.h +164 -0
- data/ext/clipsruby/textpro.c +1388 -0
- data/ext/clipsruby/textpro.h +77 -0
- data/ext/clipsruby/tmpltbin.c +609 -0
- data/ext/clipsruby/tmpltbin.h +108 -0
- data/ext/clipsruby/tmpltbsc.c +327 -0
- data/ext/clipsruby/tmpltbsc.h +87 -0
- data/ext/clipsruby/tmpltcmp.c +450 -0
- data/ext/clipsruby/tmpltcmp.h +57 -0
- data/ext/clipsruby/tmpltdef.c +584 -0
- data/ext/clipsruby/tmpltdef.h +155 -0
- data/ext/clipsruby/tmpltfun.c +2477 -0
- data/ext/clipsruby/tmpltfun.h +122 -0
- data/ext/clipsruby/tmpltlhs.c +379 -0
- data/ext/clipsruby/tmpltlhs.h +50 -0
- data/ext/clipsruby/tmpltpsr.c +819 -0
- data/ext/clipsruby/tmpltpsr.h +59 -0
- data/ext/clipsruby/tmpltrhs.c +595 -0
- data/ext/clipsruby/tmpltrhs.h +55 -0
- data/ext/clipsruby/tmpltutl.c +637 -0
- data/ext/clipsruby/tmpltutl.h +82 -0
- data/ext/clipsruby/userdata.c +156 -0
- data/ext/clipsruby/userdata.h +72 -0
- data/ext/clipsruby/userfunctions.c +70 -0
- data/ext/clipsruby/usrsetup.h +7 -0
- data/ext/clipsruby/utility.c +1594 -0
- data/ext/clipsruby/utility.h +250 -0
- data/ext/clipsruby/watch.c +865 -0
- data/ext/clipsruby/watch.h +124 -0
- data/lib/clipsruby.rb +1 -0
- metadata +388 -0
@@ -0,0 +1,640 @@
|
|
1
|
+
/*******************************************************/
|
2
|
+
/* "C" Language Integrated Production System */
|
3
|
+
/* */
|
4
|
+
/* CLIPS Version 6.40 10/18/16 */
|
5
|
+
/* */
|
6
|
+
/* PROCEDURAL FUNCTIONS MODULE */
|
7
|
+
/*******************************************************/
|
8
|
+
|
9
|
+
/*************************************************************/
|
10
|
+
/* Purpose: Contains the code for several procedural */
|
11
|
+
/* functions including if, while, loop-for-count, bind, */
|
12
|
+
/* progn, return, break, and switch */
|
13
|
+
/* */
|
14
|
+
/* Principal Programmer(s): */
|
15
|
+
/* Gary D. Riley */
|
16
|
+
/* Brian L. Dantes */
|
17
|
+
/* */
|
18
|
+
/* Contributing Programmer(s): */
|
19
|
+
/* */
|
20
|
+
/* Revision History: */
|
21
|
+
/* */
|
22
|
+
/* 6.23: Correction for FalseSymbol/TrueSymbol. DR0859 */
|
23
|
+
/* */
|
24
|
+
/* Changed name of variable exp to theExp */
|
25
|
+
/* because of Unix compiler warnings of shadowed */
|
26
|
+
/* definitions. */
|
27
|
+
/* */
|
28
|
+
/* 6.24: Renamed BOOLEAN macro type to intBool. */
|
29
|
+
/* */
|
30
|
+
/* 6.30: Local variables set with the bind function */
|
31
|
+
/* persist until a reset/clear command is issued. */
|
32
|
+
/* */
|
33
|
+
/* Changed garbage collection algorithm. */
|
34
|
+
/* */
|
35
|
+
/* Support for long long integers. */
|
36
|
+
/* */
|
37
|
+
/* 6.40: Added Env prefix to GetHaltExecution and */
|
38
|
+
/* SetHaltExecution functions. */
|
39
|
+
/* */
|
40
|
+
/* Pragma once and other inclusion changes. */
|
41
|
+
/* */
|
42
|
+
/* Added support for booleans with <stdbool.h>. */
|
43
|
+
/* */
|
44
|
+
/* Removed use of void pointers for specific */
|
45
|
+
/* data structures. */
|
46
|
+
/* */
|
47
|
+
/* UDF redesign. */
|
48
|
+
/* */
|
49
|
+
/* Added GCBlockStart and GCBlockEnd functions */
|
50
|
+
/* for garbage collection blocks. */
|
51
|
+
/* */
|
52
|
+
/* Eval support for run time and bload only. */
|
53
|
+
/* */
|
54
|
+
/*************************************************************/
|
55
|
+
|
56
|
+
#include <stdio.h>
|
57
|
+
|
58
|
+
#include "setup.h"
|
59
|
+
|
60
|
+
#include "argacces.h"
|
61
|
+
#include "constrnt.h"
|
62
|
+
#include "cstrnchk.h"
|
63
|
+
#include "cstrnops.h"
|
64
|
+
#include "envrnmnt.h"
|
65
|
+
#include "exprnpsr.h"
|
66
|
+
#include "memalloc.h"
|
67
|
+
#include "multifld.h"
|
68
|
+
#include "prcdrpsr.h"
|
69
|
+
#include "router.h"
|
70
|
+
#include "scanner.h"
|
71
|
+
#include "utility.h"
|
72
|
+
|
73
|
+
#include "prcdrfun.h"
|
74
|
+
|
75
|
+
#if DEFGLOBAL_CONSTRUCT
|
76
|
+
#include "globldef.h"
|
77
|
+
#endif
|
78
|
+
|
79
|
+
/***************************************/
|
80
|
+
/* LOCAL INTERNAL FUNCTION DEFINITIONS */
|
81
|
+
/***************************************/
|
82
|
+
|
83
|
+
static void DeallocateProceduralFunctionData(Environment *);
|
84
|
+
|
85
|
+
/**********************************************/
|
86
|
+
/* ProceduralFunctionDefinitions: Initializes */
|
87
|
+
/* the procedural functions. */
|
88
|
+
/**********************************************/
|
89
|
+
void ProceduralFunctionDefinitions(
|
90
|
+
Environment *theEnv)
|
91
|
+
{
|
92
|
+
AllocateEnvironmentData(theEnv,PRCDRFUN_DATA,sizeof(struct procedureFunctionData),DeallocateProceduralFunctionData);
|
93
|
+
|
94
|
+
#if ! RUN_TIME
|
95
|
+
AddUDF(theEnv,"if","*",0,UNBOUNDED,NULL,IfFunction,"IfFunction",NULL);
|
96
|
+
AddUDF(theEnv,"while","*",0,UNBOUNDED,NULL,WhileFunction,"WhileFunction",NULL);
|
97
|
+
AddUDF(theEnv,"loop-for-count","*",0,UNBOUNDED,NULL,LoopForCountFunction,"LoopForCountFunction",NULL);
|
98
|
+
AddUDF(theEnv,"(get-loop-count)","l",1,1,NULL,GetLoopCount,"GetLoopCount",NULL);
|
99
|
+
AddUDF(theEnv,"bind","*",0,UNBOUNDED,NULL,BindFunction,"BindFunction",NULL);
|
100
|
+
AddUDF(theEnv,"progn","*",0,UNBOUNDED,NULL,PrognFunction,"PrognFunction",NULL);
|
101
|
+
AddUDF(theEnv,"return","*",0,UNBOUNDED,NULL,ReturnFunction,"ReturnFunction",NULL);
|
102
|
+
AddUDF(theEnv,"break","v",0,0,NULL,BreakFunction,"BreakFunction",NULL);
|
103
|
+
AddUDF(theEnv,"switch","*",0,UNBOUNDED,NULL,SwitchFunction,"SwitchFunction",NULL);
|
104
|
+
#endif
|
105
|
+
|
106
|
+
ProceduralFunctionParsers(theEnv);
|
107
|
+
|
108
|
+
#if ! RUN_TIME
|
109
|
+
FuncSeqOvlFlags(theEnv,"progn",false,false);
|
110
|
+
FuncSeqOvlFlags(theEnv,"if",false,false);
|
111
|
+
FuncSeqOvlFlags(theEnv,"while",false,false);
|
112
|
+
FuncSeqOvlFlags(theEnv,"loop-for-count",false,false);
|
113
|
+
FuncSeqOvlFlags(theEnv,"return",false,false);
|
114
|
+
FuncSeqOvlFlags(theEnv,"switch",false,false);
|
115
|
+
#endif
|
116
|
+
|
117
|
+
AddResetFunction(theEnv,"bind",FlushBindList,0,NULL);
|
118
|
+
AddClearFunction(theEnv,"bind",FlushBindList,0,NULL);
|
119
|
+
}
|
120
|
+
|
121
|
+
/*************************************************************/
|
122
|
+
/* DeallocateProceduralFunctionData: Deallocates environment */
|
123
|
+
/* data for procedural functions. */
|
124
|
+
/*************************************************************/
|
125
|
+
static void DeallocateProceduralFunctionData(
|
126
|
+
Environment *theEnv)
|
127
|
+
{
|
128
|
+
UDFValue *nextPtr, *garbagePtr;
|
129
|
+
|
130
|
+
garbagePtr = ProcedureFunctionData(theEnv)->BindList;
|
131
|
+
|
132
|
+
while (garbagePtr != NULL)
|
133
|
+
{
|
134
|
+
nextPtr = garbagePtr->next;
|
135
|
+
rtn_struct(theEnv,udfValue,garbagePtr);
|
136
|
+
garbagePtr = nextPtr;
|
137
|
+
}
|
138
|
+
}
|
139
|
+
|
140
|
+
/***************************************/
|
141
|
+
/* WhileFunction: H/L access routine */
|
142
|
+
/* for the while function. */
|
143
|
+
/***************************************/
|
144
|
+
void WhileFunction(
|
145
|
+
Environment *theEnv,
|
146
|
+
UDFContext *context,
|
147
|
+
UDFValue *returnValue)
|
148
|
+
{
|
149
|
+
UDFValue theResult;
|
150
|
+
GCBlock gcb;
|
151
|
+
|
152
|
+
/*====================================================*/
|
153
|
+
/* Evaluate the body of the while loop as long as the */
|
154
|
+
/* while condition evaluates to a non-FALSE value. */
|
155
|
+
/*====================================================*/
|
156
|
+
|
157
|
+
GCBlockStart(theEnv,&gcb);
|
158
|
+
|
159
|
+
UDFNthArgument(context,1,ANY_TYPE_BITS,&theResult);
|
160
|
+
while ((theResult.value != FalseSymbol(theEnv)) &&
|
161
|
+
(EvaluationData(theEnv)->HaltExecution != true))
|
162
|
+
{
|
163
|
+
if ((ProcedureFunctionData(theEnv)->BreakFlag == true) || (ProcedureFunctionData(theEnv)->ReturnFlag == true))
|
164
|
+
break;
|
165
|
+
|
166
|
+
UDFNthArgument(context,2,ANY_TYPE_BITS,&theResult);
|
167
|
+
|
168
|
+
if ((ProcedureFunctionData(theEnv)->BreakFlag == true) || (ProcedureFunctionData(theEnv)->ReturnFlag == true))
|
169
|
+
break;
|
170
|
+
|
171
|
+
CleanCurrentGarbageFrame(theEnv,NULL);
|
172
|
+
CallPeriodicTasks(theEnv);
|
173
|
+
|
174
|
+
UDFNthArgument(context,1,ANY_TYPE_BITS,&theResult);
|
175
|
+
}
|
176
|
+
|
177
|
+
/*=====================================================*/
|
178
|
+
/* Reset the break flag. The return flag is not reset */
|
179
|
+
/* because the while loop is probably contained within */
|
180
|
+
/* a deffunction or RHS of a rule which needs to be */
|
181
|
+
/* returned from as well. */
|
182
|
+
/*=====================================================*/
|
183
|
+
|
184
|
+
ProcedureFunctionData(theEnv)->BreakFlag = false;
|
185
|
+
|
186
|
+
/*====================================================*/
|
187
|
+
/* If the return command was issued, then return that */
|
188
|
+
/* value, otherwise return the symbol FALSE. */
|
189
|
+
/*====================================================*/
|
190
|
+
|
191
|
+
if (ProcedureFunctionData(theEnv)->ReturnFlag == true)
|
192
|
+
{
|
193
|
+
returnValue->value = theResult.value;
|
194
|
+
returnValue->begin = theResult.begin;
|
195
|
+
returnValue->range = theResult.range;
|
196
|
+
}
|
197
|
+
else
|
198
|
+
{
|
199
|
+
returnValue->value = FalseSymbol(theEnv);
|
200
|
+
}
|
201
|
+
|
202
|
+
GCBlockEndUDF(theEnv,&gcb,returnValue);
|
203
|
+
CallPeriodicTasks(theEnv);
|
204
|
+
}
|
205
|
+
|
206
|
+
/********************************************/
|
207
|
+
/* LoopForCountFunction: H/L access routine */
|
208
|
+
/* for the loop-for-count function. */
|
209
|
+
/********************************************/
|
210
|
+
void LoopForCountFunction(
|
211
|
+
Environment *theEnv,
|
212
|
+
UDFContext *context,
|
213
|
+
UDFValue *loopResult)
|
214
|
+
{
|
215
|
+
UDFValue theArg;
|
216
|
+
long long iterationEnd;
|
217
|
+
LOOP_COUNTER_STACK *tmpCounter;
|
218
|
+
GCBlock gcb;
|
219
|
+
|
220
|
+
tmpCounter = get_struct(theEnv,loopCounterStack);
|
221
|
+
tmpCounter->loopCounter = 0L;
|
222
|
+
tmpCounter->nxt = ProcedureFunctionData(theEnv)->LoopCounterStack;
|
223
|
+
ProcedureFunctionData(theEnv)->LoopCounterStack = tmpCounter;
|
224
|
+
|
225
|
+
if (! UDFNthArgument(context,1,INTEGER_BIT,&theArg))
|
226
|
+
{
|
227
|
+
loopResult->value = FalseSymbol(theEnv);
|
228
|
+
ProcedureFunctionData(theEnv)->LoopCounterStack = tmpCounter->nxt;
|
229
|
+
rtn_struct(theEnv,loopCounterStack,tmpCounter);
|
230
|
+
return;
|
231
|
+
}
|
232
|
+
tmpCounter->loopCounter = theArg.integerValue->contents;
|
233
|
+
if (! UDFNthArgument(context,2,INTEGER_BIT,&theArg))
|
234
|
+
{
|
235
|
+
loopResult->value = FalseSymbol(theEnv);
|
236
|
+
ProcedureFunctionData(theEnv)->LoopCounterStack = tmpCounter->nxt;
|
237
|
+
rtn_struct(theEnv,loopCounterStack,tmpCounter);
|
238
|
+
return;
|
239
|
+
}
|
240
|
+
|
241
|
+
GCBlockStart(theEnv,&gcb);
|
242
|
+
|
243
|
+
iterationEnd = theArg.integerValue->contents;
|
244
|
+
while ((tmpCounter->loopCounter <= iterationEnd) &&
|
245
|
+
(EvaluationData(theEnv)->HaltExecution != true))
|
246
|
+
{
|
247
|
+
if ((ProcedureFunctionData(theEnv)->BreakFlag == true) || (ProcedureFunctionData(theEnv)->ReturnFlag == true))
|
248
|
+
break;
|
249
|
+
|
250
|
+
UDFNthArgument(context,3,ANY_TYPE_BITS,&theArg);
|
251
|
+
|
252
|
+
if ((ProcedureFunctionData(theEnv)->BreakFlag == true) || (ProcedureFunctionData(theEnv)->ReturnFlag == true))
|
253
|
+
break;
|
254
|
+
|
255
|
+
CleanCurrentGarbageFrame(theEnv,NULL);
|
256
|
+
CallPeriodicTasks(theEnv);
|
257
|
+
|
258
|
+
tmpCounter->loopCounter++;
|
259
|
+
}
|
260
|
+
|
261
|
+
ProcedureFunctionData(theEnv)->BreakFlag = false;
|
262
|
+
if (ProcedureFunctionData(theEnv)->ReturnFlag == true)
|
263
|
+
{
|
264
|
+
loopResult->value = theArg.value;
|
265
|
+
loopResult->begin = theArg.begin;
|
266
|
+
loopResult->range = theArg.range;
|
267
|
+
}
|
268
|
+
else
|
269
|
+
{
|
270
|
+
loopResult->value = FalseSymbol(theEnv);
|
271
|
+
}
|
272
|
+
ProcedureFunctionData(theEnv)->LoopCounterStack = tmpCounter->nxt;
|
273
|
+
rtn_struct(theEnv,loopCounterStack,tmpCounter);
|
274
|
+
|
275
|
+
GCBlockEndUDF(theEnv,&gcb,loopResult);
|
276
|
+
CallPeriodicTasks(theEnv);
|
277
|
+
}
|
278
|
+
|
279
|
+
/*****************/
|
280
|
+
/* GetLoopCount: */
|
281
|
+
/*****************/
|
282
|
+
void GetLoopCount(
|
283
|
+
Environment *theEnv,
|
284
|
+
UDFContext *context,
|
285
|
+
UDFValue *returnValue)
|
286
|
+
{
|
287
|
+
long long depth;
|
288
|
+
UDFValue theArg;
|
289
|
+
LOOP_COUNTER_STACK *tmpCounter;
|
290
|
+
|
291
|
+
if (! UDFFirstArgument(context,INTEGER_BIT,&theArg))
|
292
|
+
{ return; }
|
293
|
+
depth = theArg.integerValue->contents;
|
294
|
+
tmpCounter = ProcedureFunctionData(theEnv)->LoopCounterStack;
|
295
|
+
while (depth > 0)
|
296
|
+
{
|
297
|
+
tmpCounter = tmpCounter->nxt;
|
298
|
+
depth--;
|
299
|
+
}
|
300
|
+
|
301
|
+
returnValue->integerValue = CreateInteger(theEnv,tmpCounter->loopCounter);
|
302
|
+
}
|
303
|
+
|
304
|
+
/************************************/
|
305
|
+
/* IfFunction: H/L access routine */
|
306
|
+
/* for the if function. */
|
307
|
+
/************************************/
|
308
|
+
void IfFunction(
|
309
|
+
Environment *theEnv,
|
310
|
+
UDFContext *context,
|
311
|
+
UDFValue *returnValue)
|
312
|
+
{
|
313
|
+
unsigned int numArgs;
|
314
|
+
|
315
|
+
/*=========================*/
|
316
|
+
/* Evaluate the condition. */
|
317
|
+
/*=========================*/
|
318
|
+
|
319
|
+
if (! UDFNthArgument(context,1,ANY_TYPE_BITS,returnValue))
|
320
|
+
{
|
321
|
+
returnValue->value = FalseSymbol(theEnv);
|
322
|
+
return;
|
323
|
+
}
|
324
|
+
|
325
|
+
if ((ProcedureFunctionData(theEnv)->BreakFlag == true) ||
|
326
|
+
(ProcedureFunctionData(theEnv)->ReturnFlag == true))
|
327
|
+
{
|
328
|
+
returnValue->value = FalseSymbol(theEnv);
|
329
|
+
return;
|
330
|
+
}
|
331
|
+
|
332
|
+
/*=========================================*/
|
333
|
+
/* If the condition evaluated to FALSE and */
|
334
|
+
/* an "else" portion exists, evaluate it */
|
335
|
+
/* and return the value. */
|
336
|
+
/*=========================================*/
|
337
|
+
|
338
|
+
numArgs = UDFArgumentCount(context);
|
339
|
+
if ((returnValue->value == FalseSymbol(theEnv)) &&
|
340
|
+
(numArgs == 3))
|
341
|
+
{
|
342
|
+
UDFNthArgument(context,3,ANY_TYPE_BITS,returnValue);
|
343
|
+
return;
|
344
|
+
}
|
345
|
+
|
346
|
+
/*===================================================*/
|
347
|
+
/* Otherwise if the symbol evaluated to a non-FALSE */
|
348
|
+
/* value, evaluate the "then" portion and return it. */
|
349
|
+
/*===================================================*/
|
350
|
+
|
351
|
+
else if (returnValue->value != FalseSymbol(theEnv))
|
352
|
+
{
|
353
|
+
UDFNthArgument(context,2,ANY_TYPE_BITS,returnValue);
|
354
|
+
return;
|
355
|
+
}
|
356
|
+
|
357
|
+
/*=========================================*/
|
358
|
+
/* Return FALSE if the condition evaluated */
|
359
|
+
/* to FALSE and there is no "else" portion */
|
360
|
+
/* of the if statement. */
|
361
|
+
/*=========================================*/
|
362
|
+
|
363
|
+
returnValue->value = FalseSymbol(theEnv);
|
364
|
+
}
|
365
|
+
|
366
|
+
/**************************************/
|
367
|
+
/* BindFunction: H/L access routine */
|
368
|
+
/* for the bind function. */
|
369
|
+
/**************************************/
|
370
|
+
void BindFunction(
|
371
|
+
Environment *theEnv,
|
372
|
+
UDFContext *context,
|
373
|
+
UDFValue *returnValue)
|
374
|
+
{
|
375
|
+
UDFValue *theBind, *lastBind;
|
376
|
+
bool found = false,
|
377
|
+
unbindVar = false;
|
378
|
+
CLIPSLexeme *variableName = NULL;
|
379
|
+
#if DEFGLOBAL_CONSTRUCT
|
380
|
+
Defglobal *theGlobal = NULL;
|
381
|
+
#endif
|
382
|
+
|
383
|
+
/*===============================================*/
|
384
|
+
/* Determine the name of the variable to be set. */
|
385
|
+
/*===============================================*/
|
386
|
+
|
387
|
+
#if DEFGLOBAL_CONSTRUCT
|
388
|
+
if (GetFirstArgument()->type == DEFGLOBAL_PTR)
|
389
|
+
{ theGlobal = (Defglobal *) GetFirstArgument()->value; }
|
390
|
+
else
|
391
|
+
#endif
|
392
|
+
{
|
393
|
+
EvaluateExpression(theEnv,GetFirstArgument(),returnValue);
|
394
|
+
variableName = returnValue->lexemeValue;
|
395
|
+
}
|
396
|
+
|
397
|
+
/*===========================================*/
|
398
|
+
/* Determine the new value for the variable. */
|
399
|
+
/*===========================================*/
|
400
|
+
|
401
|
+
if (GetFirstArgument()->nextArg == NULL)
|
402
|
+
{ unbindVar = true; }
|
403
|
+
else if (GetFirstArgument()->nextArg->nextArg == NULL)
|
404
|
+
{ EvaluateExpression(theEnv,GetFirstArgument()->nextArg,returnValue); }
|
405
|
+
else
|
406
|
+
{ StoreInMultifield(theEnv,returnValue,GetFirstArgument()->nextArg,true); }
|
407
|
+
|
408
|
+
/*==================================*/
|
409
|
+
/* Bind a defglobal if appropriate. */
|
410
|
+
/*==================================*/
|
411
|
+
|
412
|
+
#if DEFGLOBAL_CONSTRUCT
|
413
|
+
if (theGlobal != NULL)
|
414
|
+
{
|
415
|
+
QSetDefglobalValue(theEnv,theGlobal,returnValue,unbindVar);
|
416
|
+
return;
|
417
|
+
}
|
418
|
+
#endif
|
419
|
+
|
420
|
+
/*===============================================*/
|
421
|
+
/* Search for the variable in the list of binds. */
|
422
|
+
/*===============================================*/
|
423
|
+
|
424
|
+
theBind = ProcedureFunctionData(theEnv)->BindList;
|
425
|
+
lastBind = NULL;
|
426
|
+
|
427
|
+
while ((theBind != NULL) && (found == false))
|
428
|
+
{
|
429
|
+
if (theBind->supplementalInfo == (void *) variableName)
|
430
|
+
{ found = true; }
|
431
|
+
else
|
432
|
+
{
|
433
|
+
lastBind = theBind;
|
434
|
+
theBind = theBind->next;
|
435
|
+
}
|
436
|
+
}
|
437
|
+
|
438
|
+
/*========================================================*/
|
439
|
+
/* If variable was not in the list of binds, then add it. */
|
440
|
+
/* Make sure that this operation preserves the bind list */
|
441
|
+
/* as a stack. */
|
442
|
+
/*========================================================*/
|
443
|
+
|
444
|
+
if (found == false)
|
445
|
+
{
|
446
|
+
if (unbindVar == false)
|
447
|
+
{
|
448
|
+
theBind = get_struct(theEnv,udfValue);
|
449
|
+
theBind->supplementalInfo = (void *) variableName;
|
450
|
+
IncrementLexemeCount(variableName);
|
451
|
+
theBind->next = NULL;
|
452
|
+
if (lastBind == NULL)
|
453
|
+
{ ProcedureFunctionData(theEnv)->BindList = theBind; }
|
454
|
+
else
|
455
|
+
{ lastBind->next = theBind; }
|
456
|
+
}
|
457
|
+
else
|
458
|
+
{
|
459
|
+
returnValue->value = FalseSymbol(theEnv);
|
460
|
+
return;
|
461
|
+
}
|
462
|
+
}
|
463
|
+
else
|
464
|
+
{ ReleaseUDFV(theEnv,theBind); }
|
465
|
+
|
466
|
+
/*================================*/
|
467
|
+
/* Set the value of the variable. */
|
468
|
+
/*================================*/
|
469
|
+
|
470
|
+
if (unbindVar == false)
|
471
|
+
{
|
472
|
+
theBind->value = returnValue->value;
|
473
|
+
theBind->begin = returnValue->begin;
|
474
|
+
theBind->range = returnValue->range;
|
475
|
+
RetainUDFV(theEnv,returnValue);
|
476
|
+
}
|
477
|
+
else
|
478
|
+
{
|
479
|
+
if (lastBind == NULL) ProcedureFunctionData(theEnv)->BindList = theBind->next;
|
480
|
+
else lastBind->next = theBind->next;
|
481
|
+
ReleaseLexeme(theEnv,(CLIPSLexeme *) theBind->supplementalInfo);
|
482
|
+
rtn_struct(theEnv,udfValue,theBind);
|
483
|
+
returnValue->value = FalseSymbol(theEnv);
|
484
|
+
}
|
485
|
+
}
|
486
|
+
|
487
|
+
/*******************************************/
|
488
|
+
/* GetBoundVariable: Searches the BindList */
|
489
|
+
/* for a specified variable. */
|
490
|
+
/*******************************************/
|
491
|
+
bool GetBoundVariable(
|
492
|
+
Environment *theEnv,
|
493
|
+
UDFValue *vPtr,
|
494
|
+
CLIPSLexeme *varName)
|
495
|
+
{
|
496
|
+
UDFValue *bindPtr;
|
497
|
+
|
498
|
+
for (bindPtr = ProcedureFunctionData(theEnv)->BindList; bindPtr != NULL; bindPtr = bindPtr->next)
|
499
|
+
{
|
500
|
+
if (bindPtr->supplementalInfo == (void *) varName)
|
501
|
+
{
|
502
|
+
vPtr->value = bindPtr->value;
|
503
|
+
vPtr->begin = bindPtr->begin;
|
504
|
+
vPtr->range = bindPtr->range;
|
505
|
+
return true;
|
506
|
+
}
|
507
|
+
}
|
508
|
+
|
509
|
+
return false;
|
510
|
+
}
|
511
|
+
|
512
|
+
/*************************************************/
|
513
|
+
/* FlushBindList: Removes all variables from the */
|
514
|
+
/* list of currently bound local variables. */
|
515
|
+
/*************************************************/
|
516
|
+
void FlushBindList(
|
517
|
+
Environment *theEnv,
|
518
|
+
void *context)
|
519
|
+
{
|
520
|
+
ReturnValues(theEnv,ProcedureFunctionData(theEnv)->BindList,true);
|
521
|
+
ProcedureFunctionData(theEnv)->BindList = NULL;
|
522
|
+
}
|
523
|
+
|
524
|
+
/***************************************/
|
525
|
+
/* PrognFunction: H/L access routine */
|
526
|
+
/* for the progn function. */
|
527
|
+
/***************************************/
|
528
|
+
void PrognFunction(
|
529
|
+
Environment *theEnv,
|
530
|
+
UDFContext *context,
|
531
|
+
UDFValue *returnValue)
|
532
|
+
{
|
533
|
+
struct expr *argPtr;
|
534
|
+
|
535
|
+
argPtr = EvaluationData(theEnv)->CurrentExpression->argList;
|
536
|
+
|
537
|
+
if (argPtr == NULL)
|
538
|
+
{
|
539
|
+
returnValue->value = FalseSymbol(theEnv);
|
540
|
+
return;
|
541
|
+
}
|
542
|
+
|
543
|
+
while ((argPtr != NULL) && (GetHaltExecution(theEnv) != true))
|
544
|
+
{
|
545
|
+
EvaluateExpression(theEnv,argPtr,returnValue);
|
546
|
+
|
547
|
+
if ((ProcedureFunctionData(theEnv)->BreakFlag == true) || (ProcedureFunctionData(theEnv)->ReturnFlag == true))
|
548
|
+
break;
|
549
|
+
argPtr = argPtr->nextArg;
|
550
|
+
}
|
551
|
+
|
552
|
+
if (GetHaltExecution(theEnv) == true)
|
553
|
+
{
|
554
|
+
returnValue->value = FalseSymbol(theEnv);
|
555
|
+
return;
|
556
|
+
}
|
557
|
+
|
558
|
+
return;
|
559
|
+
}
|
560
|
+
|
561
|
+
/***************************************************************/
|
562
|
+
/* ReturnFunction: H/L access routine for the return function. */
|
563
|
+
/***************************************************************/
|
564
|
+
void ReturnFunction(
|
565
|
+
Environment *theEnv,
|
566
|
+
UDFContext *context,
|
567
|
+
UDFValue *returnValue)
|
568
|
+
{
|
569
|
+
if (! UDFHasNextArgument(context))
|
570
|
+
{
|
571
|
+
returnValue->voidValue = VoidConstant(theEnv);
|
572
|
+
}
|
573
|
+
else
|
574
|
+
{ UDFNextArgument(context,ANY_TYPE_BITS,returnValue); }
|
575
|
+
ProcedureFunctionData(theEnv)->ReturnFlag = true;
|
576
|
+
}
|
577
|
+
|
578
|
+
/***************************************************************/
|
579
|
+
/* BreakFunction: H/L access routine for the break function. */
|
580
|
+
/***************************************************************/
|
581
|
+
void BreakFunction(
|
582
|
+
Environment *theEnv,
|
583
|
+
UDFContext *context,
|
584
|
+
UDFValue *returnValue)
|
585
|
+
{
|
586
|
+
ProcedureFunctionData(theEnv)->BreakFlag = true;
|
587
|
+
}
|
588
|
+
|
589
|
+
/*****************************************************************/
|
590
|
+
/* SwitchFunction: H/L access routine for the switch function. */
|
591
|
+
/*****************************************************************/
|
592
|
+
void SwitchFunction(
|
593
|
+
Environment *theEnv,
|
594
|
+
UDFContext *context,
|
595
|
+
UDFValue *returnValue)
|
596
|
+
{
|
597
|
+
UDFValue switch_val,case_val;
|
598
|
+
Expression *theExp;
|
599
|
+
|
600
|
+
returnValue->lexemeValue = FalseSymbol(theEnv);
|
601
|
+
|
602
|
+
/* ==========================
|
603
|
+
Get the value to switch on
|
604
|
+
========================== */
|
605
|
+
EvaluateExpression(theEnv,GetFirstArgument(),&switch_val);
|
606
|
+
if (EvaluationData(theEnv)->EvaluationError)
|
607
|
+
return;
|
608
|
+
for (theExp = GetFirstArgument()->nextArg ; theExp != NULL ; theExp = theExp->nextArg->nextArg)
|
609
|
+
{
|
610
|
+
/* =================================================
|
611
|
+
VOID_TYPE is the default case (if any) for the switch
|
612
|
+
================================================= */
|
613
|
+
if (theExp->type == VOID_TYPE)
|
614
|
+
{
|
615
|
+
EvaluateExpression(theEnv,theExp->nextArg,returnValue);
|
616
|
+
return;
|
617
|
+
}
|
618
|
+
|
619
|
+
/* ====================================================
|
620
|
+
If the case matches, evaluate the actions and return
|
621
|
+
==================================================== */
|
622
|
+
EvaluateExpression(theEnv,theExp,&case_val);
|
623
|
+
if (EvaluationData(theEnv)->EvaluationError)
|
624
|
+
return;
|
625
|
+
if (switch_val.header->type == case_val.header->type)
|
626
|
+
{
|
627
|
+
if ((case_val.header->type == MULTIFIELD_TYPE) ? MultifieldDOsEqual(&switch_val,&case_val) :
|
628
|
+
(switch_val.value == case_val.value))
|
629
|
+
{
|
630
|
+
EvaluateExpression(theEnv,theExp->nextArg,returnValue);
|
631
|
+
return;
|
632
|
+
}
|
633
|
+
}
|
634
|
+
}
|
635
|
+
}
|
636
|
+
|
637
|
+
|
638
|
+
|
639
|
+
|
640
|
+
|