1 \ *****************************************************************************
2 \ * Copyright (c) 2004, 2008 IBM Corporation
3 \ * All rights reserved.
4 \ * This program and the accompanying materials
5 \ * are made available under the terms of the BSD License
6 \ * which accompanies this distribution, and is available at
7 \ * http://www.opensource.org/licenses/bsd-license.php
10 \ * IBM Corporation - initial implementation
11 \ ****************************************************************************/
13 : ?offset16 ( -- true|false )
17 : ?arch64 ( -- true|false )
21 : ?bigendian ( -- true|false )
23 fcode-num ?arch64 IF 4 + THEN
27 : reset-fcode-end ( -- )
51 : ?compile-mode ( -- on|off )
55 : save-evaluator-state
56 get-ip eva-debug? IF ." saved ip " dup . cr THEN
57 fcode-end @ eva-debug? IF ." saved fcode-end " dup . cr THEN
58 fcode-offset eva-debug? IF ." saved fcode-offset " dup . cr THEN
59 \ local fcodes are currently NOT saved!
60 fcode-spread eva-debug? IF ." saved fcode-spread " dup . cr THEN
61 ['] fcode@ behavior eva-debug? IF ." saved fcode@ " dup . cr THEN
64 : restore-evaluator-state
65 eva-debug? IF ." restored fcode@ " dup . cr THEN to fcode@
66 eva-debug? IF ." restored fcode-spread " dup . cr THEN to fcode-spread
67 \ local fcodes are currently NOT restored!
68 eva-debug? IF ." restored fcode-offset " dup . cr THEN to fcode-offset
69 eva-debug? IF ." restored fcode-end " dup . cr THEN fcode-end !
70 eva-debug? IF ." restored ip " dup . cr THEN set-ip
73 : token-table-index ( fcode# -- addr )
77 : join-immediate ( xt immediate? addr -- xt+immediate? addr )
81 : split-immediate ( xt+immediate? -- xt immediate? )
82 dup 1 and 2dup - rot drop swap
91 dup c, bounds ?do i c@ c, loop
94 : set-token ( xt immediate? fcode# -- )
95 token-table-index join-immediate !
98 : get-token ( fcode# -- xt immediate? )
99 token-table-index @ split-immediate
102 ( ---------------------------------------------------- )
104 #include "little-big.fs"
106 ( ---------------------------------------------------- )
108 : read-fcode# ( -- FCode# )
110 dup 01 0F between IF drop read-fcode-num16 THEN
113 : read-header ( adr -- )
114 next-ip read-byte drop
115 next-ip read-fcode-num16 drop
116 next-ip read-fcode-num32 drop
119 : read-fcode-string ( -- str len )
120 read-byte \ get string length ( -- len )
121 next-ip get-ip \ get string addr ( -- len str )
122 swap \ type needs the parameters swapped ( -- str len )
123 dup 1- jump-n-ip \ jump to the end of the string in FCode
127 -1 VALUE break-fcode-addr
128 0 VALUE break-fcode-steps
130 : evaluate-fcode ( -- )
132 get-ip break-fcode-addr = IF
143 \ When it is not immediate and in compile-mode, then compile
144 get-token 0= ?compile-mode AND IF ( xt )
146 ELSE \ immediate or "interpretation" mode
147 eva-debug? IF dup xt>name type space THEN
150 eva-debug? IF .s cr THEN
152 break-fcode-steps 1- TO break-fcode-steps
153 break-fcode-steps 0= IF
161 \ Run FCODE for n steps
162 : steps-fcode ( n -- )
164 break-fcode-addr >r -1 to break-fcode-addr
167 r> to break-fcode-addr
170 \ Step through one FCODE instruction