Deleted Added
full compact
vm.c (76116) vm.c (94290)
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
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** $Id: vm.c,v 1.8 2001-04-26 21:41:23-07 jsadler Exp jsadler $
6** $Id: vm.c,v 1.13 2001/12/05 07:21:34 jsadler Exp $
7*******************************************************************/
8/*
9** This file implements the virtual machine of FICL. Each virtual
10** machine retains the state of an interpreter. A virtual machine
11** owns a pair of stacks for parameters and return addresses, as
12** well as a pile of state variables and the two dedicated registers
13** of the interp.
14*/
15/*
16** Copyright (c) 1997-2001 John Sadler (john_sadler@alum.mit.edu)
17** All rights reserved.
18**
19** Get the latest Ficl release at http://ficl.sourceforge.net
20**
7*******************************************************************/
8/*
9** This file implements the virtual machine of FICL. Each virtual
10** machine retains the state of an interpreter. A virtual machine
11** owns a pair of stacks for parameters and return addresses, as
12** well as a pile of state variables and the two dedicated registers
13** of the interp.
14*/
15/*
16** Copyright (c) 1997-2001 John Sadler (john_sadler@alum.mit.edu)
17** All rights reserved.
18**
19** Get the latest Ficl release at http://ficl.sourceforge.net
20**
21** I am interested in hearing from anyone who uses ficl. If you have
22** a problem, a success story, a defect, an enhancement request, or
23** if you would like to contribute to the ficl release, please
24** contact me by email at the address above.
25**
21** L I C E N S E and D I S C L A I M E R
22**
23** Redistribution and use in source and binary forms, with or without
24** modification, are permitted provided that the following conditions
25** are met:
26** 1. Redistributions of source code must retain the above copyright
27** notice, this list of conditions and the following disclaimer.
28** 2. Redistributions in binary form must reproduce the above copyright

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

35** ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
36** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38** OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39** HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
40** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
41** OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42** SUCH DAMAGE.
26** L I C E N S E and D I S C L A I M E R
27**
28** Redistribution and use in source and binary forms, with or without
29** modification, are permitted provided that the following conditions
30** are met:
31** 1. Redistributions of source code must retain the above copyright
32** notice, this list of conditions and the following disclaimer.
33** 2. Redistributions in binary form must reproduce the above copyright

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

40** ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
41** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
42** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
43** OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44** HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
45** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
46** OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47** SUCH DAMAGE.
43**
44** I am interested in hearing from anyone who uses ficl. If you have
45** a problem, a success story, a defect, an enhancement request, or
46** if you would like to contribute to the ficl release, please send
47** contact me by email at the address above.
48**
49** $Id: vm.c,v 1.8 2001-04-26 21:41:23-07 jsadler Exp jsadler $
50*/
51
48*/
49
52/* $FreeBSD: head/sys/boot/ficl/vm.c 76116 2001-04-29 02:36:36Z dcs $ */
50/* $FreeBSD: head/sys/boot/ficl/vm.c 94290 2002-04-09 17:45:28Z dcs $ */
53
54#ifdef TESTMAIN
55#include <stdlib.h>
56#include <stdio.h>
57#include <ctype.h>
58#else
59#include <stand.h>
60#endif

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

160** Visual C++ 5 chokes on this loop in Release mode. Aargh.
161**************************************************************************/
162#if INLINE_INNER_LOOP == 0
163void vmInnerLoop(FICL_VM *pVM)
164{
165 M_INNER_LOOP(pVM);
166}
167#endif
51
52#ifdef TESTMAIN
53#include <stdlib.h>
54#include <stdio.h>
55#include <ctype.h>
56#else
57#include <stand.h>
58#endif

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

158** Visual C++ 5 chokes on this loop in Release mode. Aargh.
159**************************************************************************/
160#if INLINE_INNER_LOOP == 0
161void vmInnerLoop(FICL_VM *pVM)
162{
163 M_INNER_LOOP(pVM);
164}
165#endif
166#if 0
167/*
168** Recast inner loop that inlines tokens for control structures, arithmetic and stack operations,
169** as well as create does> : ; and various literals
170*/
171typedef enum
172{
173 PATCH = 0,
174 L0,
175 L1,
176 L2,
177 LMINUS1,
178 LMINUS2,
179 DROP,
180 SWAP,
181 DUP,
182 PICK,
183 ROLL,
184 FETCH,
185 STORE,
186 BRANCH,
187 CBRANCH,
188 LEAVE,
189 TO_R,
190 R_FROM,
191 EXIT;
192} OPCODE;
168
193
194typedef CELL *IPTYPE;
169
195
196void vmInnerLoop(FICL_VM *pVM)
197{
198 IPTYPE ip = pVM->ip;
199 FICL_STACK *pStack = pVM->pStack;
200
201 for (;;)
202 {
203 OPCODE o = (*ip++).i;
204 CELL c;
205 switch (o)
206 {
207 case L0:
208 stackPushINT(pStack, 0);
209 break;
210 case L1:
211 stackPushINT(pStack, 1);
212 break;
213 case L2:
214 stackPushINT(pStack, 2);
215 break;
216 case LMINUS1:
217 stackPushINT(pStack, -1);
218 break;
219 case LMINUS2:
220 stackPushINT(pStack, -2);
221 break;
222 case DROP:
223 stackDrop(pStack, 1);
224 break;
225 case SWAP:
226 stackRoll(pStack, 1);
227 break;
228 case DUP:
229 stackPick(pStack, 0);
230 break;
231 case PICK:
232 c = *ip++;
233 stackPick(pStack, c.i);
234 break;
235 case ROLL:
236 c = *ip++;
237 stackRoll(pStack, c.i);
238 break;
239 case EXIT:
240 return;
241 }
242 }
243
244 return;
245}
246#endif
247
248
249
170/**************************************************************************
250/**************************************************************************
251 v m G e t D i c t
252** Returns the address dictionary for this VM's system
253**************************************************************************/
254FICL_DICT *vmGetDict(FICL_VM *pVM)
255{
256 assert(pVM);
257 return pVM->pSys->dp;
258}
259
260
261/**************************************************************************
171 v m G e t S t r i n g
172** Parses a string out of the VM input buffer and copies up to the first
173** FICL_STRING_MAX characters to the supplied destination buffer, a
174** FICL_STRING. The destination string is NULL terminated.
175**
176** Returns the address of the first unused character in the dest buffer.
177**************************************************************************/
178char *vmGetString(FICL_VM *pVM, FICL_STRING *spDest, char delimiter)

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

435 else
436 pVM->textOut = ficlTextOut;
437
438 return;
439}
440
441
442/**************************************************************************
262 v m G e t S t r i n g
263** Parses a string out of the VM input buffer and copies up to the first
264** FICL_STRING_MAX characters to the supplied destination buffer, a
265** FICL_STRING. The destination string is NULL terminated.
266**
267** Returns the address of the first unused character in the dest buffer.
268**************************************************************************/
269char *vmGetString(FICL_VM *pVM, FICL_STRING *spDest, char delimiter)

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

526 else
527 pVM->textOut = ficlTextOut;
528
529 return;
530}
531
532
533/**************************************************************************
443 v m S t e p
444** Single step the vm - equivalent to "step into" - used for debugging
445**************************************************************************/
446#if FICL_WANT_DEBUGGER
447void vmStep(FICL_VM *pVM)
448{
449 M_VM_STEP(pVM);
450}
451#endif
452
453
454/**************************************************************************
455 v m T e x t O u t
456** Feeds text to the vm's output callback
457**************************************************************************/
458void vmTextOut(FICL_VM *pVM, char *text, int fNewline)
459{
460 assert(pVM);
461 assert(pVM->textOut);
462 (pVM->textOut)(pVM, text, fNewline);

--- 250 unchanged lines hidden ---
534 v m T e x t O u t
535** Feeds text to the vm's output callback
536**************************************************************************/
537void vmTextOut(FICL_VM *pVM, char *text, int fNewline)
538{
539 assert(pVM);
540 assert(pVM->textOut);
541 (pVM->textOut)(pVM, text, fNewline);

--- 250 unchanged lines hidden ---