scirun.c

Go to the documentation of this file.
00001 /*-----------------------------------------------------------------------------------*/ 
00002 /* INRIA 2007 */
00003 /* Scilab */
00004 /*-----------------------------------------------------------------------------------*/ 
00005 #include "stack-c.h"
00006 #include "scirun.h"
00007 /*-----------------------------------------------------------------------------------*/ 
00008 extern int C2F(allowptr)(int *);
00009 extern int C2F(callinterf)(int *, int *);
00010 extern int C2F(iset)(int *, int *, int *, int *);
00011 extern int C2F(funs)(int *);
00012 extern int C2F(parse)(void);
00013 extern int C2F(error)(int *);
00014 extern int C2F(ref2val)(void);
00015 extern int C2F(isbyref)(int *);
00016 /*-----------------------------------------------------------------------------------*/ 
00017 static void str_copy_buf(register char *a, register char *b, long int la, long int lb);
00018 
00019 int C2F(scirun)(char *bu1, long int bu1_len)
00020 {
00021     static int iflagint = 0;
00022         static int k = 0;
00023         static int ir = 0;
00024 
00025         /* set instruction to execute at start-up */
00026 
00027         str_copy_buf(cha1_.buf, bu1, bsiz, bu1_len);
00028     C2F(iop).rio = -1;
00029     C2F(iop).lpt[0] = 1;
00030     C2F(iop).lpt[5] = 0;
00031     C2F(recu).pt = 0;
00032 
00033     C2F(recu).icall = 0;
00034     C2F(recu).krec = 99999;
00035 
00036         /* call instructions parser */
00037 
00038 L60:
00039     C2F(parse)();
00040     if (C2F(com).fun == 99) 
00041         {
00042                 C2F(com).fun = 0;
00043                 return 0;
00044     }
00045     if (Err > 0) 
00046         {
00047                 if (C2F(recu).niv > 0 && C2F(recu).paus > 0) C2F(com).fun = 0;
00048                 goto L60;
00049     }
00050 
00051     if (C2F(recu).rstk[C2F(recu).pt - 1] / 100 == 9) 
00052         {
00053                 ir = C2F(recu).rstk[C2F(recu).pt - 1] - 900;
00054 
00055                 if (ir == 1) 
00056                 {
00057                         /* back to gw_core */
00058                         k = 13;
00059                 } 
00060                 else if (ir >= 2 && ir <= 9) 
00061                 {
00062                         /* back to gw_io */
00063                         k = 5;
00064                 }
00065                 else if (ir == 10) 
00066                 {
00067                         /* end of overloaded function */
00068                         --C2F(recu).pt;
00069                         goto L90;
00070                 }
00071                 else if (ir > 40) 
00072                 {
00073                         /* back to gw_user2 */
00074                         k = 24;
00075                 }
00076                 else if (ir > 20) 
00077                 {
00078                         /* back to gw_user */
00079                         k = 14;
00080                 }
00081                 else
00082                 {
00083                         goto L89;
00084                 }
00085                 iflagint = 0;
00086                 goto L95;
00087     }
00088 
00089 L89:
00090     if (Top < Rhs) 
00091         {
00092                 int code_error=22;
00093                 C2F(error)(&code_error);
00094                 if (C2F(recu).niv > 0 && C2F(recu).paus > 0) C2F(com).fun = 0;
00095                 goto L60;
00096     }
00097     if (Top - Rhs + Lhs + 1 >= Bot) 
00098         {
00099                 int code_error=18;
00100                 C2F(error)(&code_error);
00101                 if (C2F(recu).niv > 0 && C2F(recu).paus > 0) C2F(com).fun = 0;
00102                 goto L60;
00103     }
00104     C2F(errgst).toperr = Top - Max(0,Rhs);
00105     goto L91;
00106 
00107 L90:
00108     if (Err > 0) 
00109         {
00110                 if (C2F(recu).niv > 0 && C2F(recu).paus > 0) C2F(com).fun = 0;
00111                 goto L60;
00112     }
00113 L91:
00114     k = C2F(com).fun;
00115     C2F(com).fun = 0;
00116     if (k == C2F(recu).krec) 
00117         {
00118                 int code_error=22;
00119                 C2F(recu).krec = -1;
00120                 C2F(error)(&code_error);
00121                 if (C2F(recu).niv > 0 && C2F(recu).paus > 0) C2F(com).fun = 0;
00122                 goto L60;
00123     }
00124     C2F(recu).krec = -1;
00125     if (k == 0) goto L60;
00126     
00127 L95:
00128     if (! C2F(allowptr)(&k)) 
00129         {
00130                 C2F(ref2val)();
00131     }
00132     C2F(recu).krec = k;
00133     C2F(callinterf)(&k, &iflagint);
00134     C2F(recu).krec = -1;
00135     if (C2F(com).fun >= 0) 
00136         {
00137                 if (Top - Lhs + 1 > 0) 
00138                 {
00139                         int cx0=0;
00140                         int cx1=0;
00141                         C2F(iset)(&Rhs, &cx0, &C2F(vstk).infstk[Top - Lhs], &cx1);
00142                 }
00143                 if (C2F(recu).paus > 0) 
00144                 {
00145                         goto L91;
00146                 }
00147                 if (C2F(errgst).err1 > 0) 
00148                 {
00149                         Top = C2F(errgst).toperr;
00150                 }
00151                 goto L90;
00152         }
00153 
00154         /*
00155         called interface ask for a scilab function to perform the function (fun=-1)
00156         the function name is given in ids(1,pt+1)
00157         call ref2val removed here because if forces overloading function to
00158         be called by value
00159         call ref2val
00160         */
00161     C2F(com).fun = 0;
00162     C2F(funs)(&C2F(recu).ids[(C2F(recu).pt + 1) * 6 - 6]);
00163     if (C2F(iop).err > 0) 
00164         {
00165                 if (C2F(recu).niv > 0 && C2F(recu).paus > 0) C2F(com).fun = 0;
00166                 goto L60;
00167     }
00168     if (C2F(com).fun > 0) 
00169         {
00170                 if (C2F(isbyref)(&C2F(com).fun) == 0) 
00171                 {
00172             C2F(ref2val)();
00173                 }
00174                 goto L91;
00175     }
00176 
00177     if (Fin == 0) 
00178         {
00179                 int code_error=246;
00180                 C2F(error)(&code_error);
00181                 if (Err > 0) 
00182                 {
00183                         if (C2F(recu).niv > 0 && C2F(recu).paus > 0) C2F(com).fun = 0;
00184                         goto L60;
00185                 }
00186                 goto L90;
00187     }
00188     ++C2F(recu).pt;
00189     Fin = C2F(vstk).lstk[Fin - 1];
00190     C2F(recu).rstk[C2F(recu).pt - 1] = 910;
00191     C2F(recu).icall = 5;
00192     C2F(com).fun = 0;
00193         /* *call*  macro */
00194     goto L60;
00195 
00196     return 0;
00197 }
00198 /*-----------------------------------------------------------------------------------*/ 
00199 static void str_copy_buf(register char *a, register char *b, long int la, long int lb)
00200 {
00201         if (lb>la) strncpy(a,b,la);
00202         else 
00203         {
00204                 int i=0;
00205                 strncpy(a,b,lb);
00206                 for (i=lb;i<la;i++) a[i]= ' ';
00207         }
00208 }
00209 /*-----------------------------------------------------------------------------------*/ 

Generated on Sun Mar 4 15:03:47 2007 for Scilab [trunk] by  doxygen 1.5.1