Deleted Added
full compact
ficl.h (42679) ficl.h (43078)
1/*******************************************************************
2** f i c l . h
3** Forth Inspired Command Language
4** Author: John Sadler (john_sadler@alum.mit.edu)
5** Created: 19 July 1997
6**
7*******************************************************************/
8/*

--- 100 unchanged lines hidden (view full) ---

109**
110** 1. Unimplemented system dependent CORE word: key
111** 2. Kludged CORE word: ACCEPT
112** 3. Dictionary locking is full of holes - only one vm at a time
113** can alter the dict.
114** 4. Ficl uses the pad in CORE words - this violates the standard,
115** but it's cleaner for a multithreaded system. I'll have to make a
116** second pad for reference by the word PAD to fix this.
1/*******************************************************************
2** f i c l . h
3** Forth Inspired Command Language
4** Author: John Sadler (john_sadler@alum.mit.edu)
5** Created: 19 July 1997
6**
7*******************************************************************/
8/*

--- 100 unchanged lines hidden (view full) ---

109**
110** 1. Unimplemented system dependent CORE word: key
111** 2. Kludged CORE word: ACCEPT
112** 3. Dictionary locking is full of holes - only one vm at a time
113** can alter the dict.
114** 4. Ficl uses the pad in CORE words - this violates the standard,
115** but it's cleaner for a multithreaded system. I'll have to make a
116** second pad for reference by the word PAD to fix this.
117** 5. The whole inner interpreter is screwed up. It ought to be detached
118** from ficlExec. Also, it should fall in line with exception
119** handling by saving state. (sobral)
120** 6. EXCEPTION should be cleaned. Right now, it doubles ficlExec's
121** inner interpreter. (sobral)
122** 7. colonParen must get the inner interpreter working on it's "case"
123** *before* returning, so that it becomes possible to execute them
124** inside other definitions without recreating the inner interpreter
125** or other such hacks. (sobral)
126** 8. We now have EXCEPTION word set. Let's:
127** 8.1. Use the appropriate exceptions throughout the code.
128** 8.2. Print the error messages at ficlExec, so someone can catch
129** them first. (sobral)
117**
118** F o r M o r e I n f o r m a t i o n
119**
120** Web home of ficl
121** http://www.taygeta.com/forth/compilers
122** Check this website for Forth literature (including the ANSI standard)
123** http://www.taygeta.com/forthlit.html
124** and here for software and more links

--- 23 unchanged lines hidden (view full) ---

148** haven't considered doing them. Another possibility is to
149** declare the pVm parameter to be "register", and hope the compiler
150** pays attention.
151**
152*/
153
154/*
155** Revision History:
130**
131** F o r M o r e I n f o r m a t i o n
132**
133** Web home of ficl
134** http://www.taygeta.com/forth/compilers
135** Check this website for Forth literature (including the ANSI standard)
136** http://www.taygeta.com/forthlit.html
137** and here for software and more links

--- 23 unchanged lines hidden (view full) ---

161** haven't considered doing them. Another possibility is to
162** declare the pVm parameter to be "register", and hope the compiler
163** pays attention.
164**
165*/
166
167/*
168** Revision History:
169**
170** 12 Jan 1999 (sobral) Corrected EVALUATE behavior. Now TIB has an
171** "end" field, and all words respect this. ficlExec is passed a "size"
172** of TIB, as well as vmPushTib. This size is used to calculate the "end"
173** of the string, ie, base+size. If the size is not known, pass -1.
174**
175** 10 Jan 1999 (sobral) EXCEPTION word set has been added, and existing
176** words has been modified to conform to EXCEPTION EXT word set.
177**
156** 27 Aug 1998 (sadler) testing and corrections for LOCALS, LOCALS EXT,
157** SEARCH / SEARCH EXT, TOOLS / TOOLS EXT.
158** Added .X to display in hex, PARSE and PARSE-WORD to supplement WORD,
159** EMPTY to clear stack.
160**
161** 29 jun 1998 (sadler) added variable sized hash table support
162** and ANS Forth optional SEARCH & SEARCH EXT word set.
163** 26 May 1998 (sadler)

--- 123 unchanged lines hidden (view full) ---

287#define SI_PFS(si, pfs) \
288 {si.cp = pfs->text; si.count = pfs->count;}
289
290/*
291** Ficl uses a this little structure to hold the address of
292** the block of text it's working on and an index to the next
293** unconsumed character in the string. Traditionally, this is
294** done by a Text Input Buffer, so I've called this struct TIB.
178** 27 Aug 1998 (sadler) testing and corrections for LOCALS, LOCALS EXT,
179** SEARCH / SEARCH EXT, TOOLS / TOOLS EXT.
180** Added .X to display in hex, PARSE and PARSE-WORD to supplement WORD,
181** EMPTY to clear stack.
182**
183** 29 jun 1998 (sadler) added variable sized hash table support
184** and ANS Forth optional SEARCH & SEARCH EXT word set.
185** 26 May 1998 (sadler)

--- 123 unchanged lines hidden (view full) ---

309#define SI_PFS(si, pfs) \
310 {si.cp = pfs->text; si.count = pfs->count;}
311
312/*
313** Ficl uses a this little structure to hold the address of
314** the block of text it's working on and an index to the next
315** unconsumed character in the string. Traditionally, this is
316** done by a Text Input Buffer, so I've called this struct TIB.
317**
318** Since this structure also holds the size of the input buffer,
319** and since evaluate requires that, let's put the size here.
320** The size is stored as an end-pointer because that is what the
321** null-terminated string aware functions find most easy to deal
322** with.
323** Notice, though, that nobody really uses this except evaluate,
324** so it might just be moved to FICL_VM instead. (sobral)
295*/
296typedef struct
297{
298 INT32 index;
325*/
326typedef struct
327{
328 INT32 index;
329 char *end;
299 char *cp;
300} TIB;
301
302
303/*
304** Stacks get heavy use in Ficl and Forth...
305** Each virtual machine implements two of them:
306** one holds parameters (data), and the other holds return

--- 158 unchanged lines hidden (view full) ---

465
466#define FW_COMPIMMED (FW_IMMEDIATE | FW_COMPILE)
467#define FW_DEFAULT 0
468
469
470/*
471** Exit codes for vmThrow
472*/
330 char *cp;
331} TIB;
332
333
334/*
335** Stacks get heavy use in Ficl and Forth...
336** Each virtual machine implements two of them:
337** one holds parameters (data), and the other holds return

--- 158 unchanged lines hidden (view full) ---

496
497#define FW_COMPIMMED (FW_IMMEDIATE | FW_COMPILE)
498#define FW_DEFAULT 0
499
500
501/*
502** Exit codes for vmThrow
503*/
473#define VM_OUTOFTEXT 1 /* hungry - normal exit */
474#define VM_RESTART 2 /* word needs more text to suxcceed - re-run it */
475#define VM_USEREXIT 3 /* user wants to quit */
476#define VM_ERREXIT 4 /* interp found an error */
477#define VM_QUIT 5 /* like errexit, but leave pStack & base alone */
504#define VM_OUTOFTEXT -256 /* hungry - normal exit */
505#define VM_RESTART -257 /* word needs more text to suxcceed - re-run it */
506#define VM_USEREXIT -258 /* user wants to quit */
507#define VM_ERREXIT -259 /* interp found an error */
508#define VM_ABORT -1 /* like errexit -- abort */
509#define VM_ABORTQ -2 /* like errexit -- abort" */
510#define VM_QUIT -56 /* like errexit, but leave pStack & base alone */
478
479
480void vmBranchRelative(FICL_VM *pVM, int offset);
481FICL_VM * vmCreate (FICL_VM *pVM, unsigned nPStack, unsigned nRStack);
482void vmDelete (FICL_VM *pVM);
483void vmExecute(FICL_VM *pVM, FICL_WORD *pWord);
484char * vmGetString(FICL_VM *pVM, FICL_STRING *spDest, char delimiter);
485STRINGINFO vmGetWord(FICL_VM *pVM);

--- 22 unchanged lines hidden (view full) ---

508** ANS forth seems to require the input buffer to be represented
509** as a pointer to the start of the buffer, and an index to the
510** next character to read.
511** PushTib points the VM to a new input string and optionally
512** returns a copy of the current state
513** PopTib restores the TIB state given a saved TIB from PushTib
514** GetInBuf returns a pointer to the next unused char of the TIB
515*/
511
512
513void vmBranchRelative(FICL_VM *pVM, int offset);
514FICL_VM * vmCreate (FICL_VM *pVM, unsigned nPStack, unsigned nRStack);
515void vmDelete (FICL_VM *pVM);
516void vmExecute(FICL_VM *pVM, FICL_WORD *pWord);
517char * vmGetString(FICL_VM *pVM, FICL_STRING *spDest, char delimiter);
518STRINGINFO vmGetWord(FICL_VM *pVM);

--- 22 unchanged lines hidden (view full) ---

541** ANS forth seems to require the input buffer to be represented
542** as a pointer to the start of the buffer, and an index to the
543** next character to read.
544** PushTib points the VM to a new input string and optionally
545** returns a copy of the current state
546** PopTib restores the TIB state given a saved TIB from PushTib
547** GetInBuf returns a pointer to the next unused char of the TIB
548*/
516void vmPushTib(FICL_VM *pVM, char *text, TIB *pSaveTib);
549void vmPushTib(FICL_VM *pVM, char *text, INT32 size, TIB *pSaveTib);
517void vmPopTib(FICL_VM *pVM, TIB *pTib);
518#define vmGetInBuf(pVM) ((pVM)->tib.cp + (pVM)->tib.index)
519#define vmSetTibIndex(pVM, i) (pVM)->tib.index = i
520#define vmUpdateTib(pVM, str) (pVM)->tib.index = (str) - (pVM)->tib.cp
521
522/*
523** Generally useful string manipulators omitted by ANSI C...
524** ltoa complements strtol

--- 5 unchanged lines hidden (view full) ---

530*/
531#pragma warning(disable: 4273)
532#endif
533
534char *ltoa( INT32 value, char *string, int radix );
535char *ultoa(UNS32 value, char *string, int radix );
536char digit_to_char(int value);
537char *strrev( char *string );
550void vmPopTib(FICL_VM *pVM, TIB *pTib);
551#define vmGetInBuf(pVM) ((pVM)->tib.cp + (pVM)->tib.index)
552#define vmSetTibIndex(pVM, i) (pVM)->tib.index = i
553#define vmUpdateTib(pVM, str) (pVM)->tib.index = (str) - (pVM)->tib.cp
554
555/*
556** Generally useful string manipulators omitted by ANSI C...
557** ltoa complements strtol

--- 5 unchanged lines hidden (view full) ---

563*/
564#pragma warning(disable: 4273)
565#endif
566
567char *ltoa( INT32 value, char *string, int radix );
568char *ultoa(UNS32 value, char *string, int radix );
569char digit_to_char(int value);
570char *strrev( char *string );
538char *skipSpace(char *cp);
571char *skipSpace(char *cp,char *end);
539char *caseFold(char *cp);
540int strincmp(char *cp1, char *cp2, FICL_COUNT count);
541
542#if defined(_WIN32) && !FICL_MAIN
543#pragma warning(default: 4273)
544#endif
545
546/*

--- 125 unchanged lines hidden (view full) ---

672** reclaim all memory used by the dictionary and VMs.
673*/
674void ficlTermSystem(void);
675
676/*
677** f i c l E x e c
678** Evaluates a block of input text in the context of the
679** specified interpreter. Emits any requested output to the
572char *caseFold(char *cp);
573int strincmp(char *cp1, char *cp2, FICL_COUNT count);
574
575#if defined(_WIN32) && !FICL_MAIN
576#pragma warning(default: 4273)
577#endif
578
579/*

--- 125 unchanged lines hidden (view full) ---

705** reclaim all memory used by the dictionary and VMs.
706*/
707void ficlTermSystem(void);
708
709/*
710** f i c l E x e c
711** Evaluates a block of input text in the context of the
712** specified interpreter. Emits any requested output to the
680** interpreter's output function
713** interpreter's output function. If the size of the input
714** is not known, pass -1.
681** Execution returns when the text block has been executed,
682** or an error occurs.
683** Returns one of the VM_XXXX codes defined in ficl.h:
684** VM_OUTOFTEXT is the normal exit condition
685** VM_ERREXIT means that the interp encountered a syntax error
686** and the vm has been reset to recover (some or all
687** of the text block got ignored
688** VM_USEREXIT means that the user executed the "bye" command
689** to shut down the interpreter. This would be a good
690** time to delete the vm, etc -- or you can ignore this
691** signal.
715** Execution returns when the text block has been executed,
716** or an error occurs.
717** Returns one of the VM_XXXX codes defined in ficl.h:
718** VM_OUTOFTEXT is the normal exit condition
719** VM_ERREXIT means that the interp encountered a syntax error
720** and the vm has been reset to recover (some or all
721** of the text block got ignored
722** VM_USEREXIT means that the user executed the "bye" command
723** to shut down the interpreter. This would be a good
724** time to delete the vm, etc -- or you can ignore this
725** signal.
726** VM_ABORT and VM_ABORTQ are generated by 'abort' and 'abort"'
727** commands.
692** Preconditions: successful execution of ficlInitSystem,
693** Successful creation and init of the VM by ficlNewVM (or equiv)
694*/
728** Preconditions: successful execution of ficlInitSystem,
729** Successful creation and init of the VM by ficlNewVM (or equiv)
730*/
695int ficlExec(FICL_VM *pVM, char *pText);
731int ficlExec(FICL_VM *pVM, char *pText, INT32 size);
696
697/*
698** ficlExecFD(FICL_VM *pVM, int fd);
699 * Evaluates text from file passed in via fd.
700 * Execution returns when all of file has been executed or an
701 * error occurs.
702 */
703int ficlExecFD(FICL_VM *pVM, int fd);

--- 70 unchanged lines hidden ---
732
733/*
734** ficlExecFD(FICL_VM *pVM, int fd);
735 * Evaluates text from file passed in via fd.
736 * Execution returns when all of file has been executed or an
737 * error occurs.
738 */
739int ficlExecFD(FICL_VM *pVM, int fd);

--- 70 unchanged lines hidden ---