![]() |
||
| Home | SwiftForth Archive | SwiftX Archive | |

Bob,
> : test-word 5 5 + = ;
It appears you are attempting to compile a definition which opens up a
whole can of worms. I tackled this problem while developing a Forth
Script engine for our Forth Web Server. I modified it (below) for
EVALUATE (untested - sorry).
Good luck,
Mike
50000 VALUE /SCRIPT-DICT \ How much code space to ALLOCATE
: INIT-FORTH-SCRIPT ( -- )
DECIMAL /FORTH POSTPONE [
0 ( =keybrd ) 'SOURCE-ID !
CASE-INSENSITIVE BLK OFF WARNING OFF
['] (COMPILE,) IS COMPILE,
['] (SOURCE) IS SOURCE
['] DROP IS >XREF ;
: EVAL-SCRIPT ( addr len -- )
SAVE-INPUT N>R
INIT-FORTH-SCRIPT
'REMEMBER OFF 'PRUNE OFF ( Initialize Prune/Remember )
H @ >R HLIM @ >R
/SCRIPT-DICT ALLOCATE THROW
DUP >R DUP H ! /SCRIPT-DICT + HLIM ! ( create "new" dictionary
space )
S" MARKER FORGET-SCRIPT" ['] EVALUATE CATCH ?DUP
IF >R ( Stash ior )
ELSE INIT-FORTH-SCRIPT
( addr len ) ['] EVALUATE CATCH ( ior ) DUP >R
IF 2DROP ( addr & len ) THEN
INIT-FORTH-SCRIPT
S" FORGET-SCRIPT" ['] EVALUATE CATCH
IF 2DROP ( eval string+len ) THEN
THEN R> ( ior ) ( cleanup )
R> FREE THROW
R> HLIM ! R> H ! ( restore dictionary )
NR> RESTORE-INPUT DROP
( ior ) THROW ;
-----Original Message-----
From: sftalk-bounce_at_forth.com [mailto:sftalk-bounce_at_forth.com]On
Behalf
Of Bob Nash
Sent: Wednesday, June 18, 2003 2:13 PM
To: sftalk
Subject: [sftalk] EVALUATE in Callback Revisited
Some time ago (September 2001 and June 2002) there were discussions =
about using EVALUATE in a callback as part of a turnkeyed app.
According to Rick, the problem is that internal variables and system =
state are not initialized during callbacks, so the search order and =
CONTEXT had to be set before executing EVALUATE in the callback.
There were two solutions. One (from Rick) was to define the callback
=
word something like this:
: EVAL DECIMAL ONLY FORTH POSTPONE [ Buffer ZCOUNT ['] MY-EVALUATE =
CATCH IF 2DROP THEN ;
Buffer contained the string to be evaluated and MY-EVALUATE was a =
version of EVALUATE that did not try to write errors to the console.
Another solution (again from Rick) was to execute a special word, =
INHERIT-SEARCHORDER, just before executing the callback switch =
statements:
: INHERIT-SEARCHORDER OPERATOR #ORDER HIS #ORDER #VOCS 3 + CELLS
CMOVE =
; \ I'll trust Rick on this one!
I just tried various combos of the above with no success (mostly I got
a =
DOS console window that persisted for a while and then went away).
The =
evaluated words were simple stack manipulations like : test-word 5 5
+ =
; The word didn't seem to execute (nothing on the stack).
Finally, my questions:=20
1. Did anyone get this to work? =20
2. Do you have code snippets you are willing to share?
This is just for my own edification -- no immediate need. Thanks!
----------------------------------------------------------------------
sftalk_at_forth.com The SwiftForth programming discussion email list
To unsubscribe, send subject "unsubscribe" to sftalk-request_at_forth.com
For list command help, send subject "help" to sftalk-request_at_forth.com
Message archives are located at http://www.forth.com/archive/sftalk
----------------------------------------------------------------------
This list is a forum for SwiftForth users. For product support and bug
reports, please send email to support_at_forth.com
----------------------------------------------------------------------
Received on Wed Jun 18 2003 - 17:18:29 PDT
This archive was generated by hypermail 2.2.0 : Wed Jan 07 2009 - 03:04:09 PST