Local variables, call-back functions under Windows 
Author Message
 Local variables, call-back functions under Windows

There was some discussion about local variables, or even stack frames
in FORTH . Thinking for a while about that I realized, that I've been
using this technique without being aware of it.

There are two local places in FORTH -- the data and the return stack.
And while the data stack has been the target of the discussions about
local variables/stack frames, I think, that the return stack offers
better means of dealing with with them.

When one does a DO ... LOOP, there are two "local variables" defined.
Threse are I and I' . /I know, that this is implementation dependent
in dp-ANS./ And while the usage in the DO ... LOOP construct is
obious, I have found myself using them outside it. for exapmple, I
execute a >R or a 2>R in the beginning of the word, getting rid of
some of the arguments on the stack, and use them with I and I' as
needed inside the word. Of course, cleanup is needed at the end. For
usage with more arguments or with loop constucts, the words J , J' and K
can be defined.

While the former may not exactly be what the stack frame purists
insist on, this helps a lot in cleaning up code, that requires a lot
of arguments to be passed. Sure, the problem may be in the other
direction -- bad factorization, too much generality of the words, bad
design, poor uderstanding of the problem. But this is another issue.

With regards to the "call-back" functions in Windows, the problems are
quite different.  In general there are very few functions, that need
to be defined as "call-back" and even fewer need to be reentrant. I
would suggest to use something like an interrupt handler for the
call-back function. When Windows calls FORTH back, save the C
arguments in a structure and WAKE the task that will perform the
function. When the action is accomplished, return controll to Windows.
Of course different implementations of this idea may exist, depending
on the nature of the multitasking of the FORTH at hand and the actions
of the cal-back function.

--

Disclaimer: All oppinions are mine.



Sun, 16 Jun 1996 11:24:09 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. calling function recursively, local variables?

2. local variable and local variable in block behave differently

3. indirect function calls and variable variables

4. indirect function calls and variable variables

5. local variables in functions

6. nasm , functions and local variables

7. NASM - how do I define local variables in a function

8. global variables and local functions.

9. local variable not destructed if the function raised a exception

10. VC++ calling fortran function and fortran function calling a c++ function

11. call-back functions in a fortran dll

12. DVF 6 and VB6 problem ( call back function)

 

 
Powered by phpBB® Forum Software