Nife version Beta
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

3 gün önce
10 yıl önce
9 yıl önce
10 yıl önce
10 yıl önce
10 yıl önce
9 yıl önce
10 yıl önce
10 yıl önce
10 yıl önce
9 yıl önce
10 yıl önce
9 yıl önce
10 yıl önce
9 yıl önce
10 yıl önce
9 yıl önce
10 yıl önce
9 yıl önce
10 yıl önce
10 yıl önce
10 yıl önce
10 yıl önce
10 yıl önce
10 yıl önce
10 yıl önce
9 yıl önce
10 yıl önce
9 yıl önce
10 yıl önce
10 yıl önce
10 yıl önce
10 yıl önce
10 yıl önce
10 yıl önce
10 yıl önce
10 yıl önce
10 yıl önce
10 yıl önce
10 yıl önce
10 yıl önce
10 yıl önce
10 yıl önce
10 yıl önce
10 yıl önce
10 yıl önce
10 yıl önce
10 yıl önce
10 yıl önce
10 yıl önce
10 yıl önce
10 yıl önce
10 yıl önce
10 yıl önce
10 yıl önce
10 yıl önce
10 yıl önce
10 yıl önce
10 yıl önce
10 yıl önce
10 yıl önce
10 yıl önce
10 yıl önce
10 yıl önce
10 yıl önce
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663
  1. /* Copyright (C) 2011-2024 Patrick H. E. Foubet - S.E.R.I.A.N.E.
  2. This program is free software: you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation, either version 3 of the License, or any
  5. later version.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License
  11. along with this program. If not, see <http://www.gnu.org/licenses/>
  12. *******************************************************************/
  13. /* stackF.c */
  14. #include "conf.h"
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <string.h>
  18. #include <strings.h>
  19. #include "nife.h"
  20. #include "mth.h"
  21. #include "err.h"
  22. #include "debug.h"
  23. #include "lib.h"
  24. #include "stackF.h"
  25. #include "stackN.h"
  26. #include "stackC.h"
  27. #include "stackL.h"
  28. #include "stackV.h"
  29. #include "tasks.h"
  30. #define MAXCODE 2048
  31. int FctInTask=0;
  32. static void * stackF = VIDE;
  33. struct Fct {
  34. char *l; /* libelle */
  35. void *n; /* next */
  36. void *c; /* code */
  37. short typ; /* type : 0 std, 1 sys in compilation, 2 sys terminated */
  38. };
  39. void initFct(char *Lib, int typ)
  40. {
  41. void * M, *L;
  42. struct Fct * N;
  43. if ((M = malloc(sizeof(struct Fct))) == NULL) stopErr("initFct","malloc");
  44. if ((L = malloc(strlen(Lib)+1)) == NULL) stopErr("initFct","malloc");
  45. strcpy((char*)L,Lib);
  46. N = (struct Fct*)M;
  47. N->l = (char*)L;
  48. N->n = stackF;
  49. N->c = VIDE;
  50. N->typ = typ;
  51. stackF = M;
  52. }
  53. static void eraseFct(struct Fct *F)
  54. {
  55. int i,n;
  56. char *C, *E;
  57. void *A, *W;
  58. struct Fct *FD;
  59. /* printf("eraseFct(%s) at 0x%lx\n", F->l, (long)F); */
  60. free((void*)F->l);
  61. /* free associates memories */
  62. if (F->c != VIDE) {
  63. A = F->c;
  64. n = sizeof(A);
  65. i = *(int*)A;
  66. C = (char*)A+(3*sizeof(int));
  67. E = C+i;
  68. while (C < E) {
  69. switch((Code)*C) {
  70. case T_CHA :
  71. case T_CHAS :
  72. case T_NUM :
  73. case T_BKC :
  74. case T_BKC1 :
  75. bcopy((void*)(C+1),(void*)&W,n);
  76. free(W);
  77. break;
  78. case T_FCTD :
  79. case T_FCTDS :
  80. case T_FCTDW :
  81. case T_FCTDWS :
  82. bcopy((void*)(C+1),(void*)&W,n);
  83. FD = (struct Fct*)W;
  84. eraseFct(FD);
  85. break;
  86. default:
  87. break;
  88. }
  89. C+= n+1;
  90. }
  91. free(A);
  92. }
  93. free((void*)F);
  94. }
  95. void updDynFct(void *AF, int M) /* M:0=init, 1=start, 2=stop */
  96. {
  97. int i,n;
  98. char *C, *E;
  99. void *A, *W;
  100. struct Fct *F, *FD;
  101. if (AF == VIDE) return;
  102. F = (struct Fct *)AF;
  103. /* printf("updDynFct(%s) at 0x%lx\n", F->l, (long)F); */
  104. if (F->c == VIDE) return;
  105. A = F->c;
  106. n = sizeof(A);
  107. i = *(int*)A;
  108. C = (char*)A+(3*sizeof(int));
  109. E = C+i;
  110. switch(M) {
  111. case 0 : /* init */
  112. while (C < E) {
  113. switch((Code)*C) {
  114. case T_CHAS :
  115. *C=T_CHA;
  116. break;
  117. case T_VARS :
  118. *C=T_VAR;
  119. break;
  120. case T_EXEKS :
  121. *C=T_EXEK;
  122. break;
  123. case T_FCTD :
  124. case T_FCTDS :
  125. case T_FCTDW :
  126. case T_FCTDWS :
  127. *C=T_EXEK;
  128. bcopy((void*)(C+1),(void*)&W,n);
  129. FD = (struct Fct*)W;
  130. eraseFct(FD);
  131. break;
  132. default:
  133. break;
  134. }
  135. C+= n+1;
  136. }
  137. break;
  138. case 1 : /* start */
  139. while (C < E) {
  140. switch((Code)*C) {
  141. case T_FCTDS :
  142. *C=T_FCTD;
  143. break;
  144. case T_FCTDWS :
  145. *C=T_FCTDW;
  146. break;
  147. default:
  148. break;
  149. }
  150. C+= n+1;
  151. }
  152. break;
  153. case 2 : /* stop */
  154. while (C < E) {
  155. switch((Code)*C) {
  156. case T_EXEK :
  157. *C=T_EXEKS;
  158. break;
  159. case T_FCTD :
  160. *C=T_FCTDS;
  161. break;
  162. case T_FCTDW :
  163. *C=T_FCTDWS;
  164. break;
  165. default:
  166. break;
  167. }
  168. C+= n+1;
  169. }
  170. break;
  171. default:
  172. break;
  173. }
  174. }
  175. void rmLastFct(void)
  176. {
  177. struct Fct *Elt;
  178. if (stackF != VIDE) {
  179. Elt = (struct Fct *)stackF;
  180. if (Elt->typ==2) return;
  181. stackF = Elt->n;
  182. eraseFct(Elt);
  183. } else messErr(7);
  184. }
  185. static void unlinkLastFct(void)
  186. {
  187. struct Fct *Elt;
  188. if (stackF != VIDE) {
  189. Elt = (struct Fct *)stackF;
  190. stackF = Elt->n;
  191. }
  192. }
  193. struct Fct *putCodeFct(void* C)
  194. {
  195. struct Fct *Elt;
  196. if (stackF != VIDE) {
  197. Elt = (struct Fct *)stackF;
  198. if (Elt->c == VIDE) Elt->c = C;
  199. else messErr(8);
  200. }
  201. else messErr(7);
  202. return Elt;
  203. }
  204. void replaceFctS(void)
  205. {
  206. void * Next, * Next2;
  207. struct Fct *Elt, *N, *N2;
  208. if (stackF != VIDE) {
  209. Elt = (struct Fct *)stackF;
  210. if (Elt->n == VIDE) return;
  211. Next = Elt->n;
  212. N = (struct Fct*) Next;
  213. if (N->typ) return;
  214. stackF = Elt->n;
  215. Elt->n = VIDE;
  216. while (Next != VIDE) {
  217. N = (struct Fct*) Next;
  218. Next2 = N->n;
  219. if (Next2==VIDE) {
  220. N->n = (void*)Elt;
  221. return;
  222. } else {
  223. N2 = (struct Fct*) Next2;
  224. if (N2->typ) {
  225. Elt->n = Next2;
  226. N->n = (void*)Elt;
  227. return;
  228. }
  229. }
  230. Next = N->n;
  231. }
  232. }
  233. else messErr(7);
  234. return;
  235. }
  236. void IF_show_stackF(void)
  237. {
  238. void * Next;
  239. struct Fct * N;
  240. char Ctyp;
  241. Next = stackF;
  242. while (Next != VIDE) {
  243. N = (struct Fct*) Next;
  244. if (N->typ) Ctyp='S'; else Ctyp=' ';
  245. printf(" %-25s%c %d octets\n",N->l,Ctyp,*((int*)N->c));
  246. Next = N->n;
  247. }
  248. printf("<end of functions stack>\n");
  249. }
  250. void IFD_show_stackF(void)
  251. {
  252. _IFD_BEGIN_
  253. IF_show_stackF();
  254. _IFD_END_
  255. }
  256. static char cod[MAXCODE];
  257. static int i_cod;
  258. /* pile pour IF ELSE THEN */
  259. static int i_adr;
  260. static void * adr[MAXCODE/4];
  261. static char tad[MAXCODE/4];
  262. /* pile pour BEGIN ... WHILE ... REPEAT / BEGIN ... AGAIN / BEGIN ... UNTIL */
  263. static int i_adB;
  264. static int adB[MAXCODE/4];
  265. static char tcB[MAXCODE/4];
  266. /* pile pour DO ... LOOP / +LOOP */
  267. static int i_adD;
  268. static int adD[MAXCODE/4];
  269. static char tcD[MAXCODE/4];
  270. /* pour l'execution */
  271. static int I_DO=-1;
  272. static char S_DO[MAXCODE/4];
  273. static long D_DO[MAXCODE/4], L_DO[MAXCODE/4];
  274. void IF_nDO (void)
  275. {
  276. putLong((long long)(I_DO+1));
  277. }
  278. static void IF_getIndDo(int v)
  279. {
  280. int i = I_DO - v;
  281. if (i<0) putLong((long long)0);
  282. else putLong((long long)D_DO[i]);
  283. }
  284. int tadExist(Code c)
  285. {
  286. int i=0;
  287. while (i<i_adr) {
  288. if (tad[i] == c) return 1;
  289. i++;
  290. }
  291. return 0;
  292. }
  293. void IF_finFct(void)
  294. {
  295. void * M;
  296. struct Fct * F;
  297. int i,l, *ea, *Ea;
  298. if ((M = malloc((3*sizeof(int))+i_cod)) == NULL)
  299. stopErr("IF_finFct","malloc");
  300. ea = (int*)M;
  301. *ea++ = i_cod;
  302. *ea=0;
  303. Ea=ea+1;
  304. *Ea=0;
  305. /* on remplace tous les MYSELF */
  306. l = sizeof(M);
  307. for (i=0; i<i_cod; i+=(l+1)) {
  308. if (cod[i]==T_MYSF) {
  309. cod[i] = T_FCT;
  310. bcopy((void*)&M,(void*)&cod[i+1],l);
  311. } else {
  312. if (cod[i]==T_ONER) {
  313. if (*ea==0) *ea = i;
  314. else {
  315. messErr(46);
  316. return;
  317. }
  318. } else {
  319. if (cod[i]==T_END) {
  320. if (*Ea==0) *Ea = i;
  321. else {
  322. messErr(47);
  323. return;
  324. }
  325. }
  326. }
  327. }
  328. }
  329. bcopy((void*)cod,(void*)((char*)M+(3*sizeof(int))),i_cod);
  330. F=putCodeFct(M);
  331. if (F->typ) {
  332. F->typ=2;
  333. addFonU(F->l,M);
  334. replaceFctS();
  335. }
  336. /* printf("Total Fct : %d + %d !\n",i_cod,(3*sizeof(int))); */
  337. _MODIF_fctEnCours_(0);
  338. }
  339. void makeFct(Code c,void *A)
  340. {
  341. int d,i;
  342. long L, L2, LE;
  343. d = sizeof(A);
  344. /* printf("makeFct Entree : code %d + %d\n",(int)c,i_cod); */
  345. switch(c) {
  346. case T_RET :
  347. case T_NUM :
  348. case T_CHA :
  349. case T_LIB :
  350. case T_FCT :
  351. case T_MYSF :
  352. case T_DO_I :
  353. case T_DO_J :
  354. case T_DO_K :
  355. case T_VAR :
  356. case T_BKC :
  357. case T_BKC1 :
  358. case T_ONER :
  359. case T_END :
  360. case T_JEND :
  361. case T_EXEK :
  362. cod[i_cod++] = c;
  363. bcopy((void*)&A,(void*)&cod[i_cod],d);
  364. i_cod+=d;
  365. break;
  366. case T_IF :
  367. cod[i_cod++] = c;
  368. adr[i_adr]=(void*)&cod[i_cod];
  369. i_cod+=d;
  370. tad[i_adr++]=c;
  371. break;
  372. case T_ELSE :
  373. if (tad[i_adr-1] == T_IF) {
  374. cod[i_cod++] = T_JMP;
  375. adr[i_adr]=(void*)&cod[i_cod];
  376. L = (void*)&(cod[i_cod]) - adr[i_adr-1];
  377. i_cod+=d;
  378. bcopy((void*)&L,adr[i_adr-1],d);
  379. tad[i_adr++]=c;
  380. } else messErr(14);
  381. break;
  382. case T_THEN :
  383. if ((tad[i_adr-1] == T_IF) || (tad[i_adr-1] == T_ELSE)) {
  384. L = (void*)&cod[i_cod+1] - adr[i_adr-1] - (sizeof(void*)+1);/*AV5*/
  385. bcopy((void*)&L,adr[i_adr-1],d);
  386. tad[i_adr]='\0';
  387. while (tad[i_adr] != T_IF) i_adr--; /* depile adr */
  388. } else messErr(14);
  389. break;
  390. case T_BEGI :
  391. adB[i_adB]=i_cod;
  392. tcB[i_adB++]=c;
  393. break;
  394. case T_DO :
  395. cod[i_cod++] = c;
  396. i_cod+=d;
  397. adD[i_adD]=i_cod;
  398. tcD[i_adD++]=c;
  399. cod[i_cod++] = T_IFD;
  400. L = d+1;
  401. bcopy((void*)&L,(void*)&cod[i_cod],d);
  402. i_cod+=d;
  403. cod[i_cod++] = T_GOTO;
  404. L = -1;
  405. bcopy((void*)&L,(void*)&cod[i_cod],d);
  406. i_cod+=d;
  407. break;
  408. case T_PLOO :
  409. case T_LOOP :
  410. if (tcD[i_adD-1] == T_DO) {
  411. i_adD--; /* on depile */
  412. cod[i_cod++] = c;
  413. i_cod+=d;
  414. cod[i_cod++] = T_GOTO;
  415. L = adD[i_adD];
  416. bcopy((void*)&L,(void*)&cod[i_cod],d);
  417. i_cod+=d;
  418. /* maj des breaks GOTO -1 */
  419. LE = i_cod;
  420. for(i=L;i<i_cod-(d+1);i+=(d+1)) {
  421. if (cod[i] == T_GOTO) {
  422. bcopy((void*)&cod[i+1],(void*)&L2,d);
  423. if (L2==-1) bcopy((void*)&LE,(void*)&cod[i+1],d);
  424. }
  425. }
  426. } else messErr(39);
  427. break;
  428. case T_AGAI :
  429. case T_REPE :
  430. if (tcB[i_adB-1] == T_BEGI) {
  431. i_adB--; /* on depile */
  432. cod[i_cod++] = T_GOTO;
  433. L = adB[i_adB];
  434. bcopy((void*)&L,(void*)&cod[i_cod],d);
  435. i_cod+=d;
  436. /* maj des breaks GOTO -1 */
  437. LE = i_cod;
  438. for(i=L;i<i_cod-(d+1);i+=(d+1)) {
  439. if (cod[i] == T_GOTO) {
  440. bcopy((void*)&cod[i+1],(void*)&L2,d);
  441. if (L2==-1) bcopy((void*)&LE,(void*)&cod[i+1],d);
  442. }
  443. }
  444. } else messErr(22);
  445. break;
  446. case T_UNTI :
  447. case T_WHIL :
  448. if (tcB[i_adB-1] == T_BEGI) {
  449. cod[i_cod++] = T_IFN;
  450. /* if (c==T_UNTI) cod[i_cod++] = T_IFN;
  451. else cod[i_cod++] = T_IF;
  452. */
  453. L = d+1;
  454. bcopy((void*)&L,(void*)&cod[i_cod],d);
  455. i_cod+=d;
  456. cod[i_cod++] = T_GOTO;
  457. if (c==T_UNTI) L = adB[i_adB-1];
  458. else L = -1;
  459. bcopy((void*)&L,(void*)&cod[i_cod],d);
  460. i_cod+=d;
  461. if (c==T_UNTI) {
  462. i_adB--; /* depile adB */
  463. /* maj des breaks GOTO -1 */
  464. LE = i_cod;
  465. for(i=L;i<i_cod-(d+1);i+=(d+1)) {
  466. if (cod[i] == T_GOTO) {
  467. bcopy((void*)&cod[i+1],(void*)&L2,d);
  468. if (L2==-1) bcopy((void*)&LE,(void*)&cod[i+1],d);
  469. }
  470. }
  471. }
  472. } else messErr(22);
  473. break;
  474. case T_BREA :
  475. cod[i_cod++] = T_GOTO;
  476. L = -1; /* special value for BREAK */
  477. bcopy((void*)&L,(void*)&cod[i_cod],d);
  478. i_cod+=d;
  479. break;
  480. default :
  481. messErr(11);
  482. }
  483. }
  484. static void newFct2(char * S, int U)
  485. {
  486. char Lib[LDFLT+1];
  487. strncpy(Lib,S,LDFLT);
  488. Lib[LDFLT]='\0';
  489. initFct(Lib, U);
  490. _MODIF_fctEnCours_(1);
  491. dropTrSuite();
  492. i_cod = 0;
  493. i_adr = 0;
  494. i_adB = 0;
  495. i_adD = 0;
  496. }
  497. static void newFct0(char * S)
  498. {
  499. newFct2(S,0);
  500. }
  501. static void newFct1(char * S)
  502. {
  503. newFct2(S,1);
  504. }
  505. void IF_debFct(void)
  506. {
  507. putTrSuite(newFct0);
  508. }
  509. void IF_debFctS(void)
  510. {
  511. putTrSuite(newFct1);
  512. }
  513. int D_Cod=0; /* deep of execution functions */
  514. static int D_LooP=0; /* deep of execution loops */
  515. static int Do_Evts=0; /* Global events indicator for do...loop */
  516. void IF_DO_MLeave (void)
  517. {
  518. long P, i;
  519. getParLong(&P);
  520. i=I_DO+1;
  521. if (i) {
  522. if (P > i) P=i;
  523. Do_Evts=P;
  524. }
  525. }
  526. void IF_DO_Leave (void)
  527. {
  528. if (I_DO>=0) Do_Evts=1;
  529. }
  530. void IF_DO_Next (void)
  531. {
  532. if (I_DO>=0) Do_Evts=-1;
  533. }
  534. void IF_DO_Show (void)
  535. {
  536. printf("do vars : I_DO=%d Evts=%d\n",I_DO, Do_Evts);
  537. }
  538. void execCod(void *A)
  539. {
  540. int i,n, ea, Ea, *ai, InDo=0, OnErr=0, mFCTP;
  541. long L, P;
  542. char * C, *D, *F, *W, *S, *ADo_Next, *ADo_Leave;
  543. void * T, *T2;
  544. void (*f)(void);
  545. struct Fct * FR;
  546. /* printf("pid = %d ITASK=%d FctInTask=%d\n",getpid(),ITASK,FctInTask);*/
  547. if (FctInTask) {
  548. if (ITASK==0) {
  549. if (FctInTask==-1) {
  550. FctInTask=0; return;
  551. }
  552. if (MakeTask(A)) return;
  553. }
  554. if (ITASK!=FctInTask) return;
  555. }
  556. D_Cod++;
  557. ai = (int*)A;
  558. i = *ai++;
  559. ea = *ai++;
  560. Ea = *ai;
  561. if (ea) tellOnErr(A);
  562. C = (char*)A+(3*sizeof(int));
  563. D = C;
  564. F = C+i;
  565. n = sizeof(T);
  566. while (C <= F) {
  567. /* printf("execCod : %s %d - %x : %ld\n",
  568. codByAddr(A),(int)(C-D),*C,(long)*(C+1));
  569. */
  570. if (noErr() && ((C==F) || ((Code)*C != T_ONER)) ) { /* to find onerr: */
  571. if (ea && (OnErr==0)) {
  572. C = D+ea;
  573. } else {
  574. printf("Called in %s err=%d i=%d/%d cod=<%x>\n",
  575. codByAddr(A),noErr(),(int)(C-D),i,*C);
  576. if (InDebugFct==0) fprintf(stderr,
  577. "Called in %s err=%d i=%d/%d cod=<%x>\n",
  578. codByAddr(A),noErr(),(int)(C-D),i,*C);
  579. break; /* end of while */
  580. }
  581. }
  582. if (C==F) break; /* end of code */
  583. switch((Code)*C) {
  584. case T_ONER :
  585. if (noErr()==0) { /* jmp end: */
  586. if (Ea>ea) C = D+Ea;
  587. else C = F; /* to break */
  588. } else {
  589. if (OnErr==0) {
  590. OnErr=1;
  591. majLastErr(A);
  592. razErr();
  593. } else C = F;
  594. }
  595. break;
  596. case T_RET :
  597. C = F; /* to break */
  598. break;
  599. case T_END :
  600. break; /* nothing */
  601. case T_JEND :
  602. if (Ea) C = D+Ea;
  603. else C = F; /* to break */
  604. break;
  605. case T_NUM :
  606. bcopy((void*)(C+1),(void*)&T,n);
  607. insertVal(T);
  608. break;
  609. case T_CHA :
  610. bcopy((void*)(C+1),(void*)&W,n);
  611. putString(W);
  612. break;
  613. case T_LIB :
  614. if (InstallOn) {
  615. if (InstallOn < 3) {
  616. bcopy((void*)(C+1),(void*)&T,n);
  617. _MODIF_FCT_INST_(T);
  618. _MODIF_FCT_TYP_(1);
  619. } else {
  620. _MODIF_FCT_INST_(VIDE);
  621. _MODIF_FCT_TYP_(0);
  622. }
  623. InstallOn=0;
  624. } else {
  625. bcopy((void*)(C+1),(void*)&f,n);
  626. f();
  627. /* free context loops */
  628. if (Do_Evts) { /* quit or cut */
  629. /*printf("execCod T_LIB : Evts %d\n",Do_Evts);*/
  630. if (InDo) {
  631. if (Do_Evts>0) {
  632. C=ADo_Leave;
  633. I_DO--;
  634. InDo = 0;
  635. Do_Evts--;
  636. } else {
  637. C=ADo_Next;
  638. Do_Evts=0;
  639. }
  640. } else { /* quit */
  641. C = F;
  642. }
  643. }
  644. }
  645. break;
  646. case T_FCT :
  647. if (InstallOn) {
  648. if (InstallOn < 3) {
  649. bcopy((void*)(C+1),(void*)&T,n);
  650. T2=fctByCode(T);
  651. _MODIF_FCT_INST_(T2);
  652. _MODIF_FCT_TYP_(2);
  653. } else {
  654. _MODIF_FCT_INST_(VIDE);
  655. _MODIF_FCT_TYP_(0);
  656. }
  657. InstallOn=0;
  658. } else {
  659. bcopy((void*)(C+1),(void*)&T,n);
  660. execCod(T);
  661. /* free context loops */
  662. if (Do_Evts) { /* quit or cut */
  663. /*printf("execCod T_FCT : Evts %d\n",Do_Evts);*/
  664. if (InDo) {
  665. if (Do_Evts>0) {
  666. C=ADo_Leave;
  667. I_DO--;
  668. InDo = 0;
  669. Do_Evts--;
  670. } else {
  671. C=ADo_Next;
  672. Do_Evts=0;
  673. }
  674. } else { /* quit */
  675. C = F;
  676. }
  677. }
  678. }
  679. break;
  680. case T_FCTDS :
  681. case T_EXEKS :
  682. if ((S = getString()) != NULL)
  683. free((void*)S); /* remove the string */
  684. break;
  685. case T_FCTD :
  686. if ((S = getString()) != NULL)
  687. free((void*)S); /* remove the string */
  688. if (noErr()) break;
  689. case T_FCTDW :
  690. case T_FCTP :
  691. bcopy((void*)(C+1),(void*)&T,n);
  692. FR = (struct Fct *)T;
  693. execCod(FR->c);
  694. /* free context loops */
  695. if (Do_Evts) { /* quit or cut */
  696. /*printf("execCod T_FCTD : Evts %d\n",Do_Evts);*/
  697. if (InDo) {
  698. if (Do_Evts>0) {
  699. C=ADo_Leave;
  700. I_DO--;
  701. InDo = 0;
  702. Do_Evts--;
  703. } else {
  704. C=ADo_Next;
  705. Do_Evts=0;
  706. }
  707. } else { /* quit */
  708. C = F;
  709. }
  710. }
  711. if (*C == T_FCTP) {
  712. if (mFCTP) *C = T_FCTDW;
  713. else *C = T_FCTD;
  714. }
  715. break;
  716. case T_EXEK :
  717. if ((S = getString()) != NULL) {
  718. if (strlen(S)>0) { /* to do with T_FCTD */
  719. mFCTP=0;
  720. T = makeFunction(S);
  721. if (T != VIDE) {
  722. bcopy((void*)&T, (void*)(C+1),n);
  723. *C = T_FCTP;
  724. C -= (n+1);
  725. unlinkLastFct();
  726. /* upgrading precedent code ? not always ! */
  727. if (C >= D) {
  728. if (*C == T_CHA) { /* case of a string */
  729. *C = T_CHAS;
  730. mFCTP=1;
  731. }
  732. if (*C == T_VAR) { /* case of a variable string */
  733. bcopy((void*)(C+1),(void*)&W,n);
  734. if (isVarChar(W)) {
  735. *C = T_VARS;
  736. mFCTP=1;
  737. }
  738. }
  739. }
  740. } else /* error in compilation */
  741. *C = T_EXEKS;
  742. }
  743. free((void*)S);
  744. }
  745. break;
  746. case T_IF :
  747. if (!getBool()) {
  748. bcopy((void*)(C+1),(void*)&L,n);
  749. C += L;
  750. }
  751. break;
  752. case T_IFN :
  753. if (getBool()) {
  754. bcopy((void*)(C+1),(void*)&L,n);
  755. C += L;
  756. }
  757. break;
  758. case T_DO :
  759. I_DO++;
  760. InDo=1;
  761. /* maj do_adresses */
  762. W = C + (2*(n+1));
  763. bcopy((void*)(W+1),(void*)&L,n);
  764. ADo_Leave=D+L-n-1;
  765. ADo_Next=ADo_Leave-(2*(n+1));
  766. /* printf("execCod T_DO : AL= %d AN=%d\n",
  767. (int)(ADo_Leave-D), (int)(ADo_Next-D));*/
  768. getParLong(&P);
  769. D_DO[I_DO] = P;
  770. getParLong(&P);
  771. L_DO[I_DO] = P;
  772. if (P > D_DO[I_DO]) S_DO[I_DO]=0;
  773. else S_DO[I_DO]=1;
  774. break;
  775. case T_DO_I :
  776. IF_getIndDo(0);
  777. break;
  778. case T_DO_J :
  779. IF_getIndDo(1);
  780. break;
  781. case T_DO_K :
  782. IF_getIndDo(2);
  783. break;
  784. case T_IFD :
  785. if (S_DO[I_DO]) {
  786. if (D_DO[I_DO] > L_DO[I_DO]) {
  787. bcopy((void*)(C+1),(void*)&L,n);
  788. C += L;
  789. } else {
  790. I_DO--;
  791. InDo=0;
  792. }
  793. } else {
  794. if (D_DO[I_DO] < L_DO[I_DO]) {
  795. bcopy((void*)(C+1),(void*)&L,n);
  796. C += L;
  797. } else {
  798. I_DO--;
  799. InDo=0;
  800. }
  801. }
  802. break;
  803. case T_LOOP :
  804. if (S_DO[I_DO]) D_DO[I_DO]--;
  805. else D_DO[I_DO]++;
  806. break;
  807. case T_PLOO :
  808. getParLong(&P);
  809. D_DO[I_DO]+=P;
  810. break;
  811. case T_JMP :
  812. bcopy((void*)(C+1),(void*)&L,n);
  813. C += L;
  814. break;
  815. case T_GOTO :
  816. bcopy((void*)(C+1),(void*)&L,n);
  817. C = D + L - n-1;
  818. break;
  819. case T_VAR :
  820. if (InstallOn) {
  821. if (InstallOn == 3) {
  822. bcopy((void*)(C+1),(void*)&T,n);
  823. _MODIF_FCT_INST_(T);
  824. _MODIF_FCT_TYP_(3);
  825. } else {
  826. _MODIF_FCT_INST_(VIDE);
  827. _MODIF_FCT_TYP_(0);
  828. }
  829. InstallOn=0;
  830. } else {
  831. bcopy((void*)(C+1),(void*)&W,n);
  832. executeVar(W);
  833. /* free context loops */
  834. if (Do_Evts) { /* quit or cut */
  835. /*printf("execCod T_VAR : Evts %d\n",Do_Evts);*/
  836. if (InDo) {
  837. if (Do_Evts>0) {
  838. C=ADo_Leave;
  839. I_DO--;
  840. InDo = 0;
  841. Do_Evts--;
  842. } else {
  843. C=ADo_Next;
  844. Do_Evts=0;
  845. }
  846. } else { /* quit */
  847. C = F;
  848. }
  849. }
  850. }
  851. break;
  852. case T_BKC :
  853. bcopy((void*)(C+1),(void*)&W,n);
  854. execLib(W);
  855. break;
  856. case T_BKC1 : /* like makeFct */
  857. bcopy((void*)(C+1),(void*)&W,n);
  858. /* try to modify the code */
  859. if (VARS==2) { /* VARS UP */
  860. if ((T = varByName(W)) != VIDE) {
  861. *C = T_VAR;
  862. } else {
  863. if ((T = fctByName(W)) != VIDE) {
  864. *C = T_FCT;
  865. FR = (struct Fct *)T;
  866. T = FR->c;
  867. }
  868. }
  869. } else {
  870. if ((T = fctByName(W)) != VIDE) {
  871. *C = T_FCT;
  872. FR = (struct Fct *)T;
  873. T = FR->c;
  874. } else {
  875. if ((VARS==1) && ((T = varByName(W)) != VIDE)) {
  876. *C = T_VAR;
  877. }
  878. }
  879. }
  880. if ((Code)*C != T_BKC1) { /* code is updated */
  881. bcopy((void*)&T, (void*)(C+1),n);
  882. C-=(n+1); /* it must be executed */
  883. }
  884. break;
  885. case T_NOP :
  886. case T_CHAS :
  887. case T_VARS :
  888. case T_FCTDWS :
  889. break;
  890. default :
  891. messErr(11);
  892. }
  893. C+= n+1;
  894. }
  895. D_Cod--;
  896. if (ea) tellOnErr(VIDE);
  897. }
  898. void execFctV(void * A)
  899. {
  900. struct Fct * N;
  901. N = (struct Fct*) A;
  902. execCod(N->c);
  903. }
  904. int IF_execFct(char * L)
  905. {
  906. void * Next;
  907. struct Fct * N;
  908. Next = stackF;
  909. while (Next != VIDE) {
  910. N = (struct Fct*) Next;
  911. if (strcmp(N->l,L)==0) {
  912. if (fctEnCours) makeFct(T_FCT,N->c);
  913. else execCod(N->c);
  914. return 1;
  915. }
  916. Next = N->n;
  917. }
  918. return 0;
  919. }
  920. void * fctByName(char * L)
  921. {
  922. void * Next;
  923. struct Fct * N;
  924. Next = stackF;
  925. while (Next != VIDE) {
  926. N = (struct Fct*) Next;
  927. if (strcmp(N->l,L)==0) return Next;
  928. Next = N->n;
  929. }
  930. return VIDE;
  931. }
  932. void * codFctByInd(long i)
  933. {
  934. void * Next;
  935. struct Fct * N;
  936. long j=0;
  937. Next = stackF;
  938. while (Next != VIDE) {
  939. N = (struct Fct*) Next;
  940. j++;
  941. if (i==j) return (N->c);
  942. Next = N->n;
  943. }
  944. return VIDE;
  945. }
  946. void * fctByInd(long i)
  947. {
  948. void * Next;
  949. struct Fct * N;
  950. long j=0;
  951. Next = stackF;
  952. while (Next != VIDE) {
  953. N = (struct Fct*) Next;
  954. j++;
  955. if (i==j) return Next;
  956. Next = N->n;
  957. }
  958. return VIDE;
  959. }
  960. void * fctByCode(void * C)
  961. {
  962. void * Next;
  963. struct Fct * N;
  964. Next = stackF;
  965. while (Next != VIDE) {
  966. N = (struct Fct*) Next;
  967. if (N->c==C) return Next;
  968. Next = N->n;
  969. }
  970. return VIDE;
  971. }
  972. static void rmFct(char * L)
  973. {
  974. void ** PNext;
  975. struct Fct * N;
  976. dropTrSuite();
  977. PNext = &stackF;
  978. while (*PNext != VIDE) {
  979. N = (struct Fct*) *PNext;
  980. if (N->typ==0)
  981. if (strcmp(N->l,L)==0) {
  982. *PNext = N->n;
  983. eraseFct(N);
  984. return;
  985. }
  986. PNext = &N->n;
  987. }
  988. messErr(21);
  989. }
  990. static void rmAFct(char * L)
  991. {
  992. void ** PNext;
  993. struct Fct * N;
  994. dropTrSuite();
  995. PNext = &stackF;
  996. while (*PNext != VIDE) {
  997. N = (struct Fct*) *PNext;
  998. if ((N->typ==0) && (strncmp(N->l,L,strlen(L))==0)) {
  999. *PNext = N->n;
  1000. eraseFct(N);
  1001. }
  1002. else PNext = &N->n;
  1003. }
  1004. }
  1005. static void rmOFct(char * L)
  1006. {
  1007. void ** PNext, ** FP;
  1008. struct Fct * N, * F;
  1009. dropTrSuite();
  1010. F = VIDE;
  1011. PNext = &stackF;
  1012. while (*PNext != VIDE) {
  1013. N = (struct Fct*) *PNext;
  1014. if (N->typ==0)
  1015. if (strcmp(N->l,L)==0) {
  1016. FP = PNext;
  1017. F = N;
  1018. }
  1019. PNext = &N->n;
  1020. }
  1021. if (F != VIDE) {
  1022. *FP = F->n;
  1023. eraseFct(F);
  1024. }
  1025. else messErr(21);
  1026. }
  1027. char * fctByAddr(void * A)
  1028. {
  1029. void * Next;
  1030. struct Fct * N;
  1031. Next = stackF;
  1032. while (Next != VIDE) {
  1033. N = (struct Fct*) Next;
  1034. if (Next==A) return N->l;
  1035. Next = N->n;
  1036. }
  1037. return NULL;
  1038. }
  1039. long iFctByCode(void * A)
  1040. {
  1041. void * Next;
  1042. struct Fct * N;
  1043. long i=0;
  1044. Next = stackF;
  1045. while (Next != VIDE) {
  1046. i++;
  1047. N = (struct Fct*) Next;
  1048. if (N->c==A) return i;
  1049. Next = N->n;
  1050. }
  1051. return 0L;
  1052. }
  1053. long iFctByAddr(void * A)
  1054. {
  1055. void * Next;
  1056. struct Fct * N;
  1057. long i=0;
  1058. Next = stackF;
  1059. while (Next != VIDE) {
  1060. i++;
  1061. N = (struct Fct*) Next;
  1062. if (Next==A) return i;
  1063. Next = N->n;
  1064. }
  1065. return 0L;
  1066. }
  1067. char * codByAddr(void * A)
  1068. {
  1069. void * Next;
  1070. struct Fct * N;
  1071. Next = stackF;
  1072. while (Next != VIDE) {
  1073. N = (struct Fct*) Next;
  1074. if (N->c==A) return N->l;
  1075. Next = N->n;
  1076. }
  1077. return NULL;
  1078. }
  1079. void prMarge(int n)
  1080. {
  1081. int N, i;
  1082. N = n*3;
  1083. for(i=0;i<N;i++) printf(" ");
  1084. }
  1085. static void scanFoncI(void * AdF, int marge)
  1086. {
  1087. void *A, *W;
  1088. struct Fct * N;
  1089. int i,n, ea, Ea, *ai;
  1090. long L;
  1091. char * C, *F, *D, lm[6];
  1092. N = (struct Fct *)AdF;
  1093. *lm = '\0';
  1094. A = N->c;
  1095. ai = (int*)A;
  1096. i = *ai++;
  1097. ea = *ai++;
  1098. Ea = *ai;
  1099. C = (char*)A+(3*sizeof(int));
  1100. D = C;
  1101. F = C+i;
  1102. n = sizeof(A);
  1103. if (marge) prMarge(marge);
  1104. if (N->typ) printf ("System ");
  1105. printf("Fonction : %s (%d) : 0x%lx\n", N->l, i, (unsigned long)A );
  1106. if (ea+Ea) {
  1107. if (ea) printf("Catching error at %d",ea);
  1108. if (Ea) {
  1109. if (ea) printf(" - ");
  1110. printf("End label at %d",Ea);
  1111. }
  1112. printf("\n");
  1113. }
  1114. while (C < F) {
  1115. if (marge) prMarge(marge);
  1116. printf(" %.4d : ",(int)(C-D));
  1117. switch((Code)*C) {
  1118. case T_NOP :
  1119. case T_CHAS :
  1120. case T_VARS :
  1121. case T_FCTDWS :
  1122. printf("NOP\n");
  1123. break;
  1124. case T_FCTDS :
  1125. case T_EXEKS :
  1126. printf("\"drop\n");
  1127. break;
  1128. case T_RET :
  1129. printf("RETURN\n");
  1130. break;
  1131. case T_ONER :
  1132. printf("onerr: label\n");
  1133. break;
  1134. case T_END :
  1135. printf("end: label\n");
  1136. break;
  1137. case T_JEND :
  1138. printf("goto end:\n");
  1139. break;
  1140. case T_NUM :
  1141. bcopy((void*)(C+1),(void*)&W,n);
  1142. printf("Number value : ");
  1143. printNumber(W);
  1144. printf("\n");
  1145. break;
  1146. case T_CHA :
  1147. bcopy((void*)(C+1),(void*)&W,n);
  1148. printf("Character String \"%s\"\n",(char*)W);
  1149. break;
  1150. case T_LIB :
  1151. bcopy((void*)(C+1),(void*)&W,n);
  1152. printf("Call to library : %s\n", libByAddr(W));
  1153. break;
  1154. case T_FCT :
  1155. bcopy((void*)(C+1),(void*)&W,n);
  1156. printf("Function : %s\n", codByAddr(W));
  1157. break;
  1158. case T_FCTD :
  1159. printf("\"drop + ");
  1160. case T_FCTDW :
  1161. bcopy((void*)(C+1),(void*)&W,n);
  1162. N = (struct Fct *)W;
  1163. printf("Dynamic Function at 0x%lx\n", (long)W);
  1164. scanFoncI(W,marge+1);
  1165. break;
  1166. case T_IF :
  1167. bcopy((void*)(C+1),(void*)&L,n);
  1168. printf("IF false goto %ld\n",(C-D)+L+n+1);
  1169. break;
  1170. case T_DO :
  1171. printf("DO [ LIMIT I -- ]\n");
  1172. break;
  1173. case T_DO_I :
  1174. printf("GET I [ -- I ]\n");
  1175. break;
  1176. case T_DO_J :
  1177. printf("GET J [ -- J ]\n");
  1178. break;
  1179. case T_DO_K :
  1180. printf("GET K [ -- K ]\n");
  1181. break;
  1182. case T_LOOP :
  1183. printf("I=+/-1\n");
  1184. break;
  1185. case T_PLOO :
  1186. printf("I += V [ V -- ]\n");
  1187. break;
  1188. case T_IFN :
  1189. bcopy((void*)(C+1),(void*)&L,n);
  1190. printf("IF true goto %ld\n",(C-D)+L+n+1);
  1191. break;
  1192. case T_IFD :
  1193. bcopy((void*)(C+1),(void*)&L,n);
  1194. printf("IF (LIMIT NOT REACHED) goto %ld\n",(C-D)+L+n+1);
  1195. break;
  1196. case T_JMP :
  1197. bcopy((void*)(C+1),(void*)&L,n);
  1198. printf("JMP $+%ld\n",L);
  1199. break;
  1200. case T_GOTO :
  1201. bcopy((void*)(C+1),(void*)&L,n);
  1202. printf("GOTO %ld\n",L);
  1203. break;
  1204. case T_EXEK :
  1205. printf("Dynamic Compile (\"execk) !\n");
  1206. break;
  1207. case T_VAR :
  1208. bcopy((void*)(C+1),(void*)&W,n);
  1209. printf("Call variable : %s\n", varByAddr(W));
  1210. break;
  1211. case T_BKC1 :
  1212. strcpy(lm,"1st ");
  1213. case T_BKC :
  1214. bcopy((void*)(C+1),(void*)&W,n);
  1215. printf("Back Compile %s: \"%s\"\n",lm, (char*)W);
  1216. break;
  1217. default :
  1218. printf("0x%x : code inconnu !!\n",(int)*C);
  1219. }
  1220. C+= n+1;
  1221. }
  1222. }
  1223. static void scanFonc(char * Lib)
  1224. {
  1225. void ** PNext;
  1226. struct Fct * N;
  1227. dropTrSuite();
  1228. PNext = &stackF;
  1229. while (*PNext != VIDE) {
  1230. N = (struct Fct*) *PNext;
  1231. if (strcmp(N->l,Lib)==0) break;
  1232. PNext = &N->n;
  1233. }
  1234. if (strcmp(N->l,Lib)!=0) {
  1235. messErr(21);
  1236. return;
  1237. }
  1238. scanFoncI((void*)N ,0);
  1239. }
  1240. void IF_execCS(void)
  1241. {
  1242. char * f;
  1243. f = getString();
  1244. if (f != NULL) {
  1245. if (!IF_execFct(f)) {
  1246. printf("%s - ",f); messErr(21);
  1247. }
  1248. free((void*)f);
  1249. }
  1250. }
  1251. void IF_execCSl(void)
  1252. {
  1253. char * f;
  1254. f = getString();
  1255. if (f != NULL) {
  1256. if (IF_execFct(f)) putBool(TRUE);
  1257. else putBool(FALSE);
  1258. free((void*)f);
  1259. }
  1260. else putBool(FALSE);
  1261. }
  1262. void IF_execCSv(void)
  1263. {
  1264. char * f;
  1265. f = getString();
  1266. if (f != NULL) {
  1267. if (!IF_execVar(f)) {
  1268. printf("%s - ",f); messErr(24);
  1269. }
  1270. free((void*)f);
  1271. }
  1272. }
  1273. void IF_execCSvl(void)
  1274. {
  1275. char * f;
  1276. f = getString();
  1277. if (f != NULL) {
  1278. if (IF_execVar(f)) putBool(TRUE);
  1279. else putBool(FALSE);
  1280. free((void*)f);
  1281. }
  1282. else putBool(FALSE);
  1283. }
  1284. void IF_delFct(void)
  1285. {
  1286. putTrSuite(rmFct);
  1287. }
  1288. void IF_delAFct(void)
  1289. {
  1290. putTrSuite(rmAFct);
  1291. }
  1292. void IF_delOFct(void)
  1293. {
  1294. putTrSuite(rmOFct);
  1295. }
  1296. void IF_scanFct(void)
  1297. {
  1298. putTrSuite(scanFonc);
  1299. }
  1300. static void IF_instruct(Code C)
  1301. {
  1302. if (fctEnCours) makeFct(C,NULL);
  1303. else messErr(13);
  1304. }
  1305. void IF_RET(void) { IF_instruct(T_RET); }
  1306. void IF_IF(void) { IF_instruct(T_IF); }
  1307. void IF_THEN(void) { IF_instruct(T_THEN); }
  1308. void IF_ELSE(void) { IF_instruct(T_ELSE); }
  1309. void IF_BEGIN(void) { IF_instruct(T_BEGI); }
  1310. void IF_AGAIN(void) { IF_instruct(T_AGAI); }
  1311. void IF_UNTIL(void) { IF_instruct(T_UNTI); }
  1312. void IF_WHILE(void) { IF_instruct(T_WHIL); }
  1313. void IF_REPEAT(void) { IF_instruct(T_REPE); }
  1314. void IF_BREAK(void) { IF_instruct(T_BREA); }
  1315. void IF_MYSELF(void) { IF_instruct(T_MYSF); }
  1316. void IF_DO(void) { IF_instruct(T_DO); }
  1317. void IF_LOOP(void) { IF_instruct(T_LOOP); }
  1318. void IF_PLOOP(void) { IF_instruct(T_PLOO); }
  1319. void IF_I_DO(void) { IF_instruct(T_DO_I); }
  1320. void IF_J_DO(void) { IF_instruct(T_DO_J); }
  1321. void IF_K_DO(void) { IF_instruct(T_DO_K); }
  1322. void IF_ONERR(void) { IF_instruct(T_ONER); }
  1323. void IF_END(void) { IF_instruct(T_END); }
  1324. void IF_JEND(void) { IF_instruct(T_JEND); }
  1325. void IF_EXEK(void) { IF_instruct(T_EXEK); }
  1326. /* code for back compilation of calling functions and variables */
  1327. void suiteBackC(char *S)
  1328. {
  1329. void * M;
  1330. dropTrSuite();
  1331. if (strlen(S) > LDFLT) {
  1332. messErr(9);
  1333. return;
  1334. }
  1335. if (S[strlen(S)-1] != '\'') {
  1336. messErr(44);
  1337. return;
  1338. }
  1339. S[strlen(S)-1] = '\0';
  1340. if ((M = malloc(strlen(S)+1)) == NULL) stopErr("suiteBackC","malloc");
  1341. #ifdef DEBUG_M
  1342. printf("New String address : %lu \n",(unsigned long)M);
  1343. #endif
  1344. strcpy((char*)M,S);
  1345. if (fctEnCours) makeFct(T_BKC,M);
  1346. else messErr(13);
  1347. }
  1348. void IF_debBackC(void)
  1349. {
  1350. putTrSuite(suiteBackC);
  1351. }
  1352. void suiteBackC1(char *S)
  1353. {
  1354. void * M;
  1355. dropTrSuite();
  1356. if (strlen(S) > LDFLT) {
  1357. messErr(9);
  1358. return;
  1359. }
  1360. if (S[strlen(S)-1] != '`') {
  1361. messErr(44);
  1362. return;
  1363. }
  1364. S[strlen(S)-1] = '\0';
  1365. if ((M = malloc(strlen(S)+1)) == NULL) stopErr("suiteBackC1","malloc");
  1366. #ifdef DEBUG_M
  1367. printf("New String address : %lu \n",(unsigned long)M);
  1368. #endif
  1369. strcpy((char*)M,S);
  1370. if (fctEnCours) makeFct(T_BKC1,M);
  1371. else messErr(13);
  1372. }
  1373. void IF_debBackC1(void)
  1374. {
  1375. putTrSuite(suiteBackC1);
  1376. }
  1377. void dump_code(int fd, char * C)
  1378. {
  1379. void * A;
  1380. uint32_t i;
  1381. write(fd, C, 1);
  1382. bcopy((void*)(C+1),(void*)&A,sizeof(A));
  1383. switch((Code)*C) {
  1384. case T_ONER :
  1385. case T_RET :
  1386. case T_END :
  1387. case T_JEND :
  1388. case T_NOP :
  1389. case T_DO_I :
  1390. case T_DO_J :
  1391. case T_DO_K :
  1392. case T_LOOP :
  1393. case T_PLOO :
  1394. case T_EXEK :
  1395. break; /* nothing */
  1396. case T_NUM :
  1397. dump_eltN(fd, A, 0);
  1398. break;
  1399. case T_CHA :
  1400. case T_BKC :
  1401. case T_BKC1 :
  1402. dump_eltC(fd, (char*)A);
  1403. break;
  1404. case T_LIB :
  1405. i = iLibByAddr(A);
  1406. write(fd, (void*)&i, sizeof(i));
  1407. break;
  1408. case T_FCT :
  1409. i = iFctByCode(A);
  1410. write(fd, (void*)&i, sizeof(i));
  1411. break;
  1412. case T_VAR :
  1413. i = iVarByAddr(A);
  1414. write(fd, (void*)&i, sizeof(i));
  1415. break;
  1416. case T_IF :
  1417. case T_IFN :
  1418. case T_DO :
  1419. case T_IFD :
  1420. case T_JMP :
  1421. case T_GOTO :
  1422. bcopy((void*)(C+1),(void*)&i,sizeof(i));
  1423. write(fd, (void*)&i, sizeof(i));
  1424. break;
  1425. /* en principe pas possible !!!
  1426. case T_FCTP :
  1427. i = iFctByAddr(A);
  1428. write(fd, (void*)&i, sizeof(i));
  1429. break;
  1430. *********************/
  1431. default :
  1432. printf("dump_code : Code %d inconnu !\n",(int)(*C));
  1433. messErr(58);
  1434. }
  1435. }
  1436. void dump_stackF(int fd)
  1437. {
  1438. uint32_t n=0, vv;
  1439. long v, vi, i, j, pas, t;
  1440. int *av;
  1441. void *Next, *A;
  1442. struct Fct * N;
  1443. char * C, *F;
  1444. Next = stackF;
  1445. while (Next != VIDE) {
  1446. N = (struct Fct*) Next;
  1447. n++;
  1448. Next = N->n;
  1449. }
  1450. write(fd, (void*)&n, sizeof(n));
  1451. t = sizeof(A) + 1;
  1452. for (i=n; i>0; i--) {
  1453. Next = stackF;
  1454. j=0;
  1455. while (Next != VIDE) {
  1456. N = (struct Fct*) Next;
  1457. j++;
  1458. if (i==j) break;
  1459. Next = N->n;
  1460. }
  1461. updDynFct(Next,0);
  1462. write(fd, (void*)&(N->typ), sizeof(N->typ));
  1463. dump_eltC(fd, N->l);
  1464. A = N->c;
  1465. av = (int*)A;
  1466. vi = (long)*av++; /* i */
  1467. vv = vi / t;
  1468. write(fd, (void*)&vv, sizeof(vv));
  1469. v = (long)*av++; /* ea */
  1470. vv = v / t;
  1471. write(fd, (void*)&vv, sizeof(vv));
  1472. v = (long)*av++; /* Ea */
  1473. vv = v / t;
  1474. write(fd, (void*)&vv, sizeof(vv));
  1475. C = (char*)A+(3*sizeof(int));
  1476. F = C+vi;
  1477. pas = sizeof(A) + 1;
  1478. while (C < F) {
  1479. dump_code(fd, C);
  1480. C += pas;
  1481. }
  1482. }
  1483. dump_rest_pr(0,n,"user functions");
  1484. }
  1485. void restore_links_stackF(void)
  1486. {
  1487. void **ANext, *A;
  1488. return;
  1489. }
  1490. static int NbARIV, NbARIL, NbARIF;
  1491. void restore_code(int fd, char * b, long delta)
  1492. {
  1493. void * A;
  1494. uint32_t i;
  1495. int nc;
  1496. if ((read(fd, (void*)b, 1)) != 1) return;
  1497. switch((Code)*b) {
  1498. case T_NUM :
  1499. A = restore_eltN(fd);
  1500. bcopy((void*)(&A),(void*)(b+1),sizeof(A));
  1501. break;
  1502. case T_CHA :
  1503. case T_BKC :
  1504. case T_BKC1 :
  1505. A = (void*)restore_eltC(fd);
  1506. bcopy((void*)(&A),(void*)(b+1),sizeof(A));
  1507. break;
  1508. case T_LIB :
  1509. nc = read(fd, (void*)&i, sizeof(i));
  1510. A = libByInd(i);
  1511. bcopy((void*)(&A),(void*)(b+1),sizeof(A));
  1512. NbARIL++;
  1513. break;
  1514. case T_FCT :
  1515. nc = read(fd, (void*)&i, sizeof(i));
  1516. A = codFctByInd(i-delta);
  1517. /* printf("i=%d delta=%d A=%lx\n",i,delta,(long)A); */
  1518. bcopy((void*)(&A),(void*)(b+1),sizeof(A));
  1519. NbARIF++;
  1520. break;
  1521. case T_VAR :
  1522. nc = read(fd, (void*)&i, sizeof(i));
  1523. A = varAddrByInd(i);
  1524. bcopy((void*)(&A),(void*)(b+1),sizeof(A));
  1525. NbARIV++;
  1526. break;
  1527. case T_IF :
  1528. case T_IFN :
  1529. case T_DO :
  1530. case T_IFD :
  1531. case T_JMP :
  1532. case T_GOTO :
  1533. nc = read(fd, (void*)&i, sizeof(i));
  1534. bcopy((void*)(&i),(void*)(b+1),sizeof(i));
  1535. break;
  1536. default :
  1537. break;
  1538. }
  1539. /* printf("\tCODE=%d i=%d\n", (int)*b, (int)i); */
  1540. }
  1541. void restore_stackF(int fd)
  1542. {
  1543. uint32_t n=0, vv;
  1544. long i, vi, v, pas, t;
  1545. short typ;
  1546. char *Lib, *C, *F;
  1547. void * M;
  1548. struct Fct *Elt;
  1549. int *bi, nc;
  1550. if (read(fd, (void*)&n, sizeof(n)) != sizeof(n)) return;
  1551. /* suppress all fcts */
  1552. rmAllFonU();
  1553. while (stackF != VIDE) {
  1554. Elt = (struct Fct *)stackF;
  1555. stackF = Elt->n;
  1556. eraseFct(Elt);
  1557. }
  1558. /* printf("Nb fct : %d\n", n); */
  1559. NbARIV=NbARIF=NbARIL=0;
  1560. t = sizeof(M) + 1;
  1561. for (i=0; i<n; i++) {
  1562. nc = read(fd, (void*)&typ, sizeof(typ));
  1563. Lib = restore_eltC(fd);
  1564. initFct(Lib,typ);
  1565. nc=read(fd, (void*)&vv, sizeof(vv));
  1566. vi = vv * t;
  1567. if ((M = malloc((3*sizeof(int))+vi)) == NULL)
  1568. stopErr("restore_stackF","malloc");
  1569. bi = (int*)M;
  1570. *bi++ = (int)vi;
  1571. nc=read(fd, (void*)&vv, sizeof(vv));
  1572. v = vv * t;
  1573. *bi++ = (int)v;
  1574. /* printf("Nom=<%s> type=%d vi=%d v1=%d", Lib, typ, (int)vi, (int)v); */
  1575. nc=read(fd, (void*)&vv, sizeof(vv));
  1576. v = vv * t;
  1577. *bi = (int)v;
  1578. /* printf(" v2=%d\n", (int)v); */
  1579. C = (char*)M+(3*sizeof(int));
  1580. F = C+vi;
  1581. pas = sizeof(M) + 1;
  1582. putCodeFct(M);
  1583. while (C < F) {
  1584. restore_code(fd, C, n-(i+1));
  1585. C += pas;
  1586. }
  1587. }
  1588. dump_rest_pr(1,n,"user functions");
  1589. rest_links_pr(NbARIV, "variable", "user functions");
  1590. rest_links_pr(NbARIL, "library function", "user functions");
  1591. rest_links_pr(NbARIF, "user function", "user functions");
  1592. }