vm.c (40883) | vm.c (43078) |
---|---|
1/******************************************************************* 2** v m . c 3** Forth Inspired Command Language - virtual machine methods 4** Author: John Sadler (john_sadler@alum.mit.edu) 5** Created: 19 July 1997 6** 7*******************************************************************/ 8/* --- 142 unchanged lines hidden (view full) --- 151**************************************************************************/ 152STRINGINFO vmGetWord0(FICL_VM *pVM) 153{ 154 char *pSrc = vmGetInBuf(pVM); 155 STRINGINFO si; 156 UNS32 count = 0; 157 char ch; 158 | 1/******************************************************************* 2** v m . c 3** Forth Inspired Command Language - virtual machine methods 4** Author: John Sadler (john_sadler@alum.mit.edu) 5** Created: 19 July 1997 6** 7*******************************************************************/ 8/* --- 142 unchanged lines hidden (view full) --- 151**************************************************************************/ 152STRINGINFO vmGetWord0(FICL_VM *pVM) 153{ 154 char *pSrc = vmGetInBuf(pVM); 155 STRINGINFO si; 156 UNS32 count = 0; 157 char ch; 158 |
159 pSrc = skipSpace(pSrc); | 159 pSrc = skipSpace(pSrc,pVM->tib.end); |
160 SI_SETPTR(si, pSrc); 161 | 160 SI_SETPTR(si, pSrc); 161 |
162 for (ch = *pSrc; ch != '\0' && !isspace(ch); ch = *++pSrc) | 162 for (ch = *pSrc; (pVM->tib.end != pSrc) && (ch != '\0') && !isspace(ch); ch = *++pSrc) |
163 { 164 count++; 165 } 166 167 SI_SETLEN(si, count); 168 | 163 { 164 count++; 165 } 166 167 SI_SETLEN(si, count); 168 |
169 if (isspace(ch)) /* skip one trailing delimiter */ | 169 if ((pVM->tib.end != pSrc) && isspace(ch)) /* skip one trailing delimiter */ |
170 pSrc++; 171 172 vmUpdateTib(pVM, pSrc); 173 174 return si; 175} 176 177 --- 27 unchanged lines hidden (view full) --- 205** trailing delimiter. 206** Returns the address and length of the parsed string, not including the 207** trailing delimiter. 208**************************************************************************/ 209STRINGINFO vmParseString(FICL_VM *pVM, char delim) 210{ 211 STRINGINFO si; 212 char *pSrc = vmGetInBuf(pVM); | 170 pSrc++; 171 172 vmUpdateTib(pVM, pSrc); 173 174 return si; 175} 176 177 --- 27 unchanged lines hidden (view full) --- 205** trailing delimiter. 206** Returns the address and length of the parsed string, not including the 207** trailing delimiter. 208**************************************************************************/ 209STRINGINFO vmParseString(FICL_VM *pVM, char delim) 210{ 211 STRINGINFO si; 212 char *pSrc = vmGetInBuf(pVM); |
213 char ch; | 213 char ch; |
214 | 214 |
215 while (*pSrc == delim) /* skip lead delimiters */ | 215 while ((pVM->tib.end != pSrc) && (*pSrc == delim)) /* skip lead delimiters */ |
216 pSrc++; 217 218 SI_SETPTR(si, pSrc); /* mark start of text */ 219 | 216 pSrc++; 217 218 SI_SETPTR(si, pSrc); /* mark start of text */ 219 |
220 for (ch = *pSrc; (ch != delim) | 220 for (ch = *pSrc; (pVM->tib.end != pSrc) 221 && (ch != delim) |
221 && (ch != '\0') 222 && (ch != '\r') 223 && (ch != '\n'); ch = *++pSrc) 224 { 225 ; /* find next delimiter or end of line */ 226 } 227 228 /* set length of result */ 229 SI_SETLEN(si, pSrc - SI_PTR(si)); 230 | 222 && (ch != '\0') 223 && (ch != '\r') 224 && (ch != '\n'); ch = *++pSrc) 225 { 226 ; /* find next delimiter or end of line */ 227 } 228 229 /* set length of result */ 230 SI_SETLEN(si, pSrc - SI_PTR(si)); 231 |
231 if (*pSrc == delim) /* gobble trailing delimiter */ | 232 if ((pVM->tib.end != pSrc) && (*pSrc == delim)) /* gobble trailing delimiter */ |
232 pSrc++; 233 234 vmUpdateTib(pVM, pSrc); 235 return si; 236} 237 238 239/************************************************************************** --- 18 unchanged lines hidden (view full) --- 258 return; 259} 260 261 262/************************************************************************** 263 v m P u s h T i b 264** Binds the specified input string to the VM and clears >IN (the index) 265**************************************************************************/ | 233 pSrc++; 234 235 vmUpdateTib(pVM, pSrc); 236 return si; 237} 238 239 240/************************************************************************** --- 18 unchanged lines hidden (view full) --- 259 return; 260} 261 262 263/************************************************************************** 264 v m P u s h T i b 265** Binds the specified input string to the VM and clears >IN (the index) 266**************************************************************************/ |
266void vmPushTib(FICL_VM *pVM, char *text, TIB *pSaveTib) | 267void vmPushTib(FICL_VM *pVM, char *text, INT32 size, TIB *pSaveTib) |
267{ 268 if (pSaveTib) 269 { 270 *pSaveTib = pVM->tib; 271 } 272 273 pVM->tib.cp = text; | 268{ 269 if (pSaveTib) 270 { 271 *pSaveTib = pVM->tib; 272 } 273 274 pVM->tib.cp = text; |
275 pVM->tib.end = text + size; |
|
274 pVM->tib.index = 0; 275} 276 277 278void vmPopTib(FICL_VM *pVM, TIB *pTib) 279{ 280 if (pTib) 281 { --- 15 unchanged lines hidden (view full) --- 297 assert(pInterp); 298 299 stackReset(pVM->rStack); 300 pVM->fRestart = 0; 301 pVM->ip = &pInterp; 302 pVM->runningWord = pInterp; 303 pVM->state = INTERPRET; 304 pVM->tib.cp = NULL; | 276 pVM->tib.index = 0; 277} 278 279 280void vmPopTib(FICL_VM *pVM, TIB *pTib) 281{ 282 if (pTib) 283 { --- 15 unchanged lines hidden (view full) --- 299 assert(pInterp); 300 301 stackReset(pVM->rStack); 302 pVM->fRestart = 0; 303 pVM->ip = &pInterp; 304 pVM->runningWord = pInterp; 305 pVM->state = INTERPRET; 306 pVM->tib.cp = NULL; |
307 pVM->tib.end = NULL; |
|
305 pVM->tib.index = 0; 306 pVM->pad[0] = '\0'; 307 pVM->sourceID.i = 0; 308 return; 309} 310 311 312/************************************************************************** --- 233 unchanged lines hidden (view full) --- 546} 547 548 549 550/************************************************************************** 551 s k i p S p a c e 552** Given a string pointer, returns a pointer to the first non-space 553** char of the string, or to the NULL terminator if no such char found. | 308 pVM->tib.index = 0; 309 pVM->pad[0] = '\0'; 310 pVM->sourceID.i = 0; 311 return; 312} 313 314 315/************************************************************************** --- 233 unchanged lines hidden (view full) --- 549} 550 551 552 553/************************************************************************** 554 s k i p S p a c e 555** Given a string pointer, returns a pointer to the first non-space 556** char of the string, or to the NULL terminator if no such char found. |
557** If the pointer reaches "end" first, stop there. If you don't want 558** that, pass NULL. |
|
554**************************************************************************/ | 559**************************************************************************/ |
555char *skipSpace(char *cp) | 560char *skipSpace(char *cp, char *end) |
556{ 557 assert(cp); 558 | 561{ 562 assert(cp); 563 |
559 while (isspace(*cp)) | 564 while ((cp != end) && isspace(*cp)) |
560 cp++; 561 562 return cp; 563} 564 565 | 565 cp++; 566 567 return cp; 568} 569 570 |