Re: defered word options



On Fri, 23 Nov 2007 11:48:14 -0800 (PST), foxchip
<fox@xxxxxxxxxxxxxxxxxxx> wrote:

Nested decsions trees may introduce the greatest overhead.
Traditional Forth code might look like outside the loop:

VARIABLE 'FUNCTION
' MYFUCTION 'FUNCTION !

and inside the loop

'FUNCTION @ PUSH ;

Portable ANSI Forth cannot rely on the existence of an
actual return stack and has added a layer of abstraction:

'FUNCTION @ EXECUTE

(some systems provide an @EXECUTE function similar to
the operation of the machineforth sequence

IF PUSH ; THEN DROP ;

DEFERed words are not part of the standard but are
common practice. Similar to the traditional style

'FUNCTION @EXECUTE

in their implementation they are often used with syntax

' MYFUCTION IS THEFUNCTION

I have argued for many years that the most efficient
implementation of defered words is simply a jump opcode.
It is of course an example of using self-modifying code
to implement DEFER.

DEFER FOO

: t ... FOO ... ;

Are you are talking about the implementation of FOO or the
code laid by referencing FOO ? If the latter, it's really
architecture dependent. On the i32, 68k and MSP430
architectures and other CISC machines it often just reduces
to an indirect call.

defer foo ok
: t ... foo ... ; ok
dis t
T
....
( FF1510AA4A00 ) CALL [004AAA10] FOO
....
( C3 ) NEXT,
ok

variable poo ok
: t2 ... poo @ execute ... ; ok
dis t2
T2
....
( 004AAA80 FF1560AA4A00 ) CALL [004AAA60] POO
....
( 004AAA86 C3 ) NEXT,
ok

The code density vs speed tradeoff is also dependent on CPU and
memory architecture, as well as on application demands.

Stephen


--
Stephen Pelc, stephenXXX@xxxxxxxxxxxx
MicroProcessor Engineering Ltd - More Real, Less Time
133 Hill Lane, Southampton SO15 5AF, England
tel: +44 (0)23 8063 1441, fax: +44 (0)23 8033 9691
web: http://www.mpeforth.com - free VFX Forth downloads
.



Relevant Pages

  • Re: Compilers, Aho/Sethi/Ullman, Exercise 2.15
    ... For example if j = 5 before the loop, ... push v onto the stack ... lvalue l... ... throw away value on top of stack ...
    (comp.compilers)
  • Re: Repairmans knot
    ... I like the "push the loop through" at the end rather than "push the plug through". ... Lately, for certain cables that get wrapped and unwrapped frequently, I've taken to doubling the cord back on itself, as many times as is convenient, and tying a simple overhand knot in the entire loop. ...
    (sci.electronics.repair)
  • Re: looping through a file
    ... information out of that and push it into an array. ... I have a second file that contain another log. ... If this is not an error then try changing the loop to ...
    (perl.beginners)
  • Re: Virtual machine: assembly instructions
    ... push; Push the address of the first variable onto the stack ... jmpzero loopStart; ... This seems like pretty good code, assuming that the code inside the loop ...
    (comp.programming)