multiple entries 
Author Message
 multiple entries

Some flavors of fortran, as I recall, allowed multiple entries
to subroutines, each with its own name. This was an echo of the
underlying assembler that permitted overlapping code sequences.

This trick offers great advantages in code compactification.
HS/FORTH uses it a lot for CODE definitions in its kernel,
making the facility available to the programmer via a word
+CODE . I believe it is the main reason HS/FORTH's kernel
is 34K whereas those of other multiple-segment 16-bit Forths
tend to be nearer 100K. I don't believe the use of multiple
entries in this manner leads to bad structure.

With regard to multiple exits, indeed it is true that Forth
words exit at one point, popping the return stack and trans-
ferring control to the next word (or doing the equivalent
now that we all have ANS in our pants). However, it is
perfectly possible to do the Forth equivalent of the badly
structured, multiple exit subroutine: simply allow different
branches to leave different stack results. An example:

        : bad_word      A  IF  1 2     EXIT THEN
                        B  IF  3       EXIT THEN  ;

Need I say more? (BTW, this is why I don't like ?DUP .)

--
Julian V. Noble



Tue, 12 Jan 1999 03:00:00 GMT  
 multiple entries

     In using assembly language to write real time operating systems, I
found the ability to use multiple entries to a subroutine was often a life
saver.  I frequently used it when I wanted to accomplish one particular
thing but had to set up for it in different ways.
     This is where the Nova had it all over the PDP-8.  The eight stored
the return address in instruction memory at the point of subroutine entry.
 The nova saved it in a register.  With a Nova, you could do the set up
and then jump to a common point where you saved the return address and
then did the function of the subroutine.
     Not being able to do this in Pascal is one of the most frustrating
things about the language.  Even Basic allows it.
     I think that it is reasonable thing to do in Forth.
                                      Joel in Ogden



Tue, 12 Jan 1999 03:00:00 GMT  
 multiple entries

   Some flavors of FORTRAN, as I recall, allowed multiple entries
   to subroutines, each with its own name. This was an echo of the
   underlying assembler that permitted overlapping code sequences.

This is certainly part of FORTRAN 77 and subsequent standards.  I
believe it was also part of the FORTRAN 66 standard, which suggests
that it was first implemented in FORTRAN II, because FORTRAN I did not
have subroutines.  It does have maintenance problems partly because it
is so rarely used, and partly because changes in earlier parts of the
enclosing procedure can have unexpected effects on the code within the
ENTRY.
--

William B. Clodius              Phone: (505)-665-9370

Los Alamos, NM 87545



Tue, 12 Jan 1999 03:00:00 GMT  
 multiple entries

Quote:

>   Some flavors of FORTRAN, as I recall, allowed multiple entries
>   to subroutines, each with its own name. This was an echo of the
>   underlying assembler that permitted overlapping code sequences.
>This is certainly part of FORTRAN 77 and subsequent standards.  I
>believe it was also part of the FORTRAN 66 standard, which suggests
>that it was first implemented in FORTRAN II, because FORTRAN I did not
>have subroutines.  It does have maintenance problems partly because it
>is so rarely used, and partly because changes in earlier parts of the
>enclosing procedure can have unexpected effects on the code within the
>ENTRY.

Now, I would be curious to see what multiple entry points are useful
for.
[I definitly like multiple exits, but I can very hardly imagine
why someone needs multiple entries (well, maybe if someone wants to
save a few machine cycles, but then there is always Assembly).]

Andras



Wed, 13 Jan 1999 03:00:00 GMT  
 multiple entries

:    Some flavors of FORTRAN, as I recall, allowed multiple entries
:    to subroutines, each with its own name. This was an echo of the
:    underlying assembler that permitted overlapping code sequences.

: This is certainly part of FORTRAN 77 and subsequent standards.  I
: believe it was also part of the FORTRAN 66 standard, which suggests
: that it was first implemented in FORTRAN II, because FORTRAN I did not
: have subroutines.  It does have maintenance problems partly because it
: is so rarely used, and partly because changes in earlier parts of the
: enclosing procedure can have unexpected effects on the code within the
: ENTRY.

More than one ENTRY has gone out of fashion, but it was
considered essential in the past.  What better way is
there to implement SIN and COS than as two entries to
one routine?

In Classical Forth multiple entry was taken as a matter
of course.  EXPECT and TYPE are two entries to one
routine in Classical systems.

And who doesn't enjoy the Classical Forth definition of
MAX and MIN?

: MAX 2DUP < IF BEGIN SWAP DROP ;
: MIN 2DUP < UNTIL THEN DROP ;

This shows how easy it is to allow multiple entries in
Forth.  Just relaxthe checking of the control-flow
stack by `;'.

: RED   ." Red plays first. "
        BEGIN   Red-plays
        0 IF
;
: BLUE  ." Blue plays first. "
        THEN    Blue-plays
        AGAIN
;



Wed, 13 Jan 1999 03:00:00 GMT  
 multiple entries

Quote:


>:    Some flavors of FORTRAN, as I recall, allowed multiple entries
>:    to subroutines, each with its own name. This was an echo of the
>:    underlying assembler that permitted overlapping code sequences.

>: This is certainly part of FORTRAN 77 and subsequent standards.  I
>: believe it was also part of the FORTRAN 66 standard, which suggests
>: that it was first implemented in FORTRAN II, because FORTRAN I did not
>: have subroutines.  It does have maintenance problems partly because it
>: is so rarely used, and partly because changes in earlier parts of the
>: enclosing procedure can have unexpected effects on the code within the
>: ENTRY.

>More than one ENTRY has gone out of fashion, but it was
>considered essential in the past.  What better way is
>there to implement SIN and COS than as two entries to
>one routine?

  Well, either as two routines written like:

double sin(double angle)        { ... }
double cos(double angle)        { return (sin (angle + PIdiv2)); }

  Or make one a macro, such as:

double sin(double angle)        { ... }
#define cos(a)          sin((a)+PIdiv2

[NOTE: is there a way to do macro expansion in Forth?  Sure, you can define
the following like:

        : sin   ( f -- f )      ... ;
        : cos   ( f -- f )      PI/2 f+ sin ;

  but's that not quite the same, as cos is calling sin.  Would something
like:

        : cos   ( f -- f )      POSTPONE PI/2
                POSTPONE f+ POSTPONE sin ; immediate

  be close?  Seems kind of clunky to me.]

- Show quoted text -

Quote:
>And who doesn't enjoy the Classical Forth definition of
>MAX and MIN?

>: MAX 2DUP < IF BEGIN SWAP DROP ;
>: MIN 2DUP < UNTIL THEN DROP ;

>This shows how easy it is to allow multiple entries in
>Forth.  Just relaxthe checking of the control-flow
>stack by `;'.

>: RED   ." Red plays first. "
>    BEGIN   Red-plays
>    0 IF
>;
>: BLUE  ." Blue plays first. "
>    THEN    Blue-plays
>    AGAIN
>;

  Just hope that the next fellow to come along to maintain your code can
catch on to what you're doing and NOT insert a definition between RED and
BLUE.  Or what happens if GREEN needs to be added?  Before RED?  Between?
After BLUE?  It's maintenance problems that possibly made this style go out
of favor.

  Don't get me wrong, I enjoy doing this stuff in Assembly, but it can get
mighty tricky [1].

  -spc (And what if an optimizing Forth compiler gets to the 0 IF?)

[1]     Try, for example, the following 8088 code for example:

lamp_on:        mov     al,TURNON
                db      03dh
lamp_off:       mov     al,TURNOFF
lamp_switch:    mov     dx,LAMPPORT
                out     dx,al
                ret



Wed, 13 Jan 1999 03:00:00 GMT  
 multiple entries


Quote:

> >More than one ENTRY has gone out of fashion, but it was
> >considered essential in the past.  What better way is
> >there to implement SIN and COS than as two entries to
> >one routine?

>   Well, either as two routines written like:

> double sin(double angle)   { ... }
> double cos(double angle)   { return (sin (angle + PIdiv2)); }

You're right, of course.  But I knew that.

Quote:
> [NOTE: is there a way to do macro expansion in Forth?  Sure, you can
> define the following like:

>    : sin   ( f -- f )      ... ;
>    : cos   ( f -- f )      PI/2 f+ sin ;

>   but's that not quite the same, as cos is calling sin.  Would
> something like:

>    : cos   ( f -- f )      POSTPONE PI/2
>            POSTPONE f+ POSTPONE sin ; immediate

>   be close?  Seems kind of clunky to me.]

There is, in ThisForth.

: cos PLEASE " PI/2 F+ sin " ;  IMMEDIATE

And in Standard Forth you can write--

: cos S" PI/2 F+ sin " EVALUATE ; IMMEDIATE

Quote:
> Just hope that the next fellow to come along to
> maintain your code can catch on to what you're doing
> and NOT insert a definition between RED and BLUE.
> Or what happens if GREEN needs to be added?  Before
> RED?  Between? After BLUE?  It's maintenance
> problems that possibly made this style go out of
> favor.

You're right again.  But I knew that also.

Quote:
>  -spc (And what if an optimizing Forth compiler gets to the 0 IF?)

It does.  "0 IF" becomes an unconditional branch in ThisForth.
And nothing is generated for the semicolons because they're
preceded by unconditional branches.

ThisForth gives a non-fatal warning when it gets such bizarre code.

Quote:
> >And who doesn't enjoy the Classical Forth definition of MAX and MIN?

                   ^^^^^     ^^^^^^^^^
You missed a couple of keywords in what I wrote.

The m{*filter*}of what I have written is: Don't do as I say, do as I do.
--
Procedamus in pace.     Wil Baden Costa Mesa, California

P.S.  Thanks for responding.



Thu, 14 Jan 1999 03:00:00 GMT  
 multiple entries

: Now, I would be curious to see what multiple entry points are useful
: for.

An old, grey Fortran vet replies: in aircraft simulation code,
it was structurally sound to have a single routine to, say, model
the engine. One of the multiple entry points could be to initialize
the engine to some run point, another for "normal" iteration,
yet another, with different argument list altogether, to force
it to some arbitrary point, yet another to dump out local variables,
(in Fortran, these were all static).

In a math environment, you could have one routine maybe to invert
a matrix. One of the entry points could be for a matrix of special
form, (diagonal, upper triangular?). Or perhaps one entry would
be the normal routine entry, say for eigenvalue analysis. Another
entry to the same routine could also return additional information,
(matrix of eigenvectors). This would be used to (1) save memory,
which in Fortran days was very expensive, since the various entries
would be expected to share much common code. (2) ease maintenance,
since related code would all be in the same "deck." (3) Improve
runtime performance, by reducing subroutine calls or swapping.

D. Vanecek
---
 oh--my first post to this group.  Greetings, all.



Thu, 14 Jan 1999 03:00:00 GMT  
 multiple entries

Quote:

> Now, I would be curious to see what multiple entry
> points are useful for.

     I am sorry I can't give examples from Forth, but consider a routine
which initializes a data structure to a specified value.  An alternate
entry would pick up a zero and fall through to the set routine, thereby
becoming a clear routine.
     A write line routine concludes by emiting a <CR> <LF>.  An alternate
entry could provide only the <CR> <LF> characters.
                        Joel in Ogden


Fri, 15 Jan 1999 03:00:00 GMT  
 multiple entries

    Zsoter> Now, I would be curious to see what multiple entry points
    Zsoter> are useful for.  [I definitly like multiple exits, but I
    Zsoter> can very hardly imagine why someone needs multiple entries
    Zsoter> (well, maybe if someone wants to save a few machine
    Zsoter> cycles, but then there is always Assembly).]

The only thing I've used it for is to skip some tests when you know
for sure they aren't needed or some special cases allow for better
optimisation.  If used as described, it's really much more readable
than a bunch of computed GOTOs and it does save the test.  With the
current optimizer technology this is not much of an advantage anymore.
You might be able to use it in places where you'd need a switch with
fallthrough and to have some crude form of "overloaded function"
(sorry for the C++-ism).  You do even wierder stuff, but then you
might not be able to figure out what you wrote two weeks ago.
This is not limited to FORTRAN, though ;-)

--
Achim Gratz.

--+<[ It's the small pleasures that make life so miserable. ]>+--
WWW:    http://www.inf.tu-dresden.de/~ag7/{english/}

Phone:  +49 351 4575 - 325



Fri, 15 Jan 1999 03:00:00 GMT  
 multiple entries

Quote:

> Now, I would be curious to see what multiple entry points are useful
> for.

In the last few years, Chuck Moore published the code for his OK
programming environment.  There are places where he uses multiple entry
points.  I think one of them is in a formatting routine for numeric
output (entry based on number of digits to display for byte, word, and
doubleword numbers), and another was in memory moves for a BitBlit type
of function.  The multiple entry points allow repetitive processing to
be done quickly for different numbers of repetitions, and  minimize
return stack usage, which is important for the MuP21 chip he designed.

But this type of code is not for the faint-hearted! :)
--



Fri, 15 Jan 1999 03:00:00 GMT  
 multiple entries


 >
 >> [NOTE: is there a way to do macro expansion in Forth?  Sure, you can
 >> define the following like:
 >>
 >>       : sin   ( f -- f )      ... ;
 >>       : cos   ( f -- f )      PI/2 f+ sin ;
 >>
 >>   but's that not quite the same, as cos is calling sin.  Would
 >> something like:
 >>
 >>       : cos   ( f -- f )      POSTPONE PI/2
 >>               POSTPONE f+ POSTPONE sin ; immediate
 >>
 >>   be close?  Seems kind of clunky to me.]
 >
 >There is, in ThisForth.
 >
 >: cos PLEASE " PI/2 F+ sin " ;  IMMEDIATE
 >
 >And in Standard Forth you can write--
 >
 >: cos S" PI/2 F+ sin " EVALUATE ; IMMEDIATE
 >
  Ah.  Thanks.

Quote:
>>  -spc (And what if an optimizing Forth compiler gets to the 0 IF?)

>It does.  "0 IF" becomes an unconditional branch in ThisForth.
>And nothing is generated for the semicolons because they're
>preceded by unconditional branches.

  I would think that an optimizing compiler (reguardless of lanague) would
take a construct like:

        0 if do_this do_that then

  And not generate any code (since the 0 is immediate and this will always
evaluate to false, why include the code?).  Or in the case of:

        0 if do_this else do_that then

  generate code as if it appeared as:

                do_that

Quote:
>ThisForth gives a non-fatal warning when it gets such bizarre code.

  At least it gives a warning 8-)

Quote:
>> >And who doesn't enjoy the Classical Forth definition of MAX and MIN?
>                   ^^^^^     ^^^^^^^^^
>You missed a couple of keywords in what I wrote.

  I didn't even know it was possible.

Quote:
>The m{*filter*}of what I have written is: Don't do as I say, do as I do.

  I'll keep that in mind.

  -spc (As soon as I get my DWIM compiler ready 8-)



Fri, 15 Jan 1999 03:00:00 GMT  
 multiple entries

Quote:


>> Now, I would be curious to see what multiple entry
>> points are useful for.
>     I am sorry I can't give examples from Forth, but consider a routine
>which initializes a data structure to a specified value.  An alternate
>entry would pick up a zero and fall through to the set routine, thereby
>becoming a clear routine.
>     A write line routine concludes by emiting a <CR> <LF>.  An alternate
>entry could provide only the <CR> <LF> characters.

But these all look like bad factoring.
Why not factor out the common part of the two "entries" into a third
routine, and make two routines (which make use of the third one) which
provide the functionality of the two entry points of the original
monolite beast?

Well, you might loose a couple of CPU cycles for the additional call,
but how often does it matter?

Andras



Fri, 15 Jan 1999 03:00:00 GMT  
 multiple entries

Quote:

>: Now, I would be curious to see what multiple entry points are useful
>: for.

1: Presetting common or default parameters
   My Genesis game library *shrank* from 20K lines to 15 over 2 years by
ruthless application of this, yet gained more functionality.
Something like

DrawSprite16x16
        moveq   #16,d2
        moveq   #16,d3
DrawSprite
        {...}

2: Re-entering complex looping routines with simplified setup.
This has provided noticeable speedups in some of my graphics pipelines
AND reduced the size of the code.

Basically, its an size and speed optimising technique, although it has a
potential benefit in only having one copy of a routine to maintain
rather than several.

--
Paul Shirley



Fri, 15 Jan 1999 03:00:00 GMT  
 multiple entries

Quote:

> Well, you might loose a couple of CPU cycles for the
> additional call, but how often does it matter?

     When you consider that Forth is often used in embedded systems where
memory is very limited and clockspeed is ridiculously slow to save power,
it may be critical.  It takes one less level of stack (and I have seen
stacks limited by hardware to 16 bytes), saves a subroutine call for both
routines, and saves a return for both routines.  
     Joel in Ogden


Sat, 16 Jan 1999 03:00:00 GMT  
 
 [ 25 post ]  Go to page: [1] [2]

 Relevant Pages 

1. Using Shitf Pick to select multiple entries

2. Multiple entry points

3. Multiple entries "AND" without delay

4. Multiple entry tasks

5. H1 Multiple Entry Visa at Toronto, Canada : NEED INFORMATION

6. Sync'ing multiple Entry widgets

7. scrolling on canvas with multiple entries box

8. HELP: Can tcl's selection slect multiple entry widgets?

9. Entry Locator with Multiple Keys

10. Re Multiple screen entry (5.2)

11. PL/1 Multiple Main Entry Points

12. highlighting entries in multiple listboxes

 

 
Powered by phpBB® Forum Software