Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.lang.forth    |    Forth programmers eat a lot of Bratwurst    |    117,927 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 117,619 of 117,927    |
|    Hans Bezemer to Anton Ertl    |
|    Re: 3dup again (1/2)    |
|    05 Oct 25 11:29:41    |
   
   From: the.beez.speaks@gmail.com   
      
   On 02-10-2025 22:44, Anton Ertl wrote:   
    > Locals-haters, come to Gforth, where locals are implemented   
    > inefficiently:-). The code for 3DUP.2 is actually optimal for   
    > Gforth's calling convention.   
      
   I think I can beat you at that :)   
      
   1. This is the LOCAL definition   
      
    Addr| Opcode Operand Argument   
      
    35| branch 46 local   
    36| r> 0   
    37| swap 0   
    38| dup 0   
    39| >r 0   
    40| @ 0   
    41| >r 0   
    42| execute 0   
    43| r> 0   
    44| r> 0   
    45| ! 0   
    46| exit 0   
      
   2. This is the 3DUP with locals   
      
      
    Addr| Opcode Operand Argument   
      
    54| branch 82 3dup.1   
    55| literal 0   
    56| to 0 a   
    57| literal 0   
    58| environ 1   
    59| + 0   
    60| call 35 local   
    61| literal 0   
    62| to 1 b   
    63| literal 1   
    64| environ 1   
    65| + 0   
    66| call 35 local   
    67| literal 0   
    68| to 2 c   
    69| literal 2   
    70| environ 1   
    71| + 0   
    72| call 35 local   
    73| to 2 c   
    74| to 1 b   
    75| to 0 a   
    76| value 0 a   
    77| value 1 b   
    78| value 2 c   
    79| value 0 a   
    80| value 1 b   
    81| value 2 c   
    82| exit 0   
      
   3. This is 3DUP *without* locals   
      
    Addr| Opcode Operand Argument   
      
    83| branch 91 3dup.2   
    84| >r 0   
    85| over 0   
    86| over 0   
    87| r@ 0   
    88| rot 0   
    89| rot 0   
    90| r> 0   
    91| exit 0   
      
   And this is the sourcecode:   
      
   include lib/anstools.4th   
   include 4pp/lib/alocals.4pp   
      
   : clear depth 0 ?do drop loop ;   
   : 3dup.1 {: a b c -- a b c a b c :} a b c a b c ;   
   : 3dup.2 >r 2dup r@ -rot r> ;   
      
   1 2 3 3dup.1 .s clear   
   4 5 6 3dup.2 .s clear   
      
   Yeah, heavy use of the preprocessor. This is the expanded source:   
      
   : 3dup.1   
   [UNDEFINED] a [IF] 0 value a [THEN] ['] a >body local   
   [UNDEFINED] b [IF] 0 value b [THEN] ['] b >body local   
   [UNDEFINED] c [IF] 0 value c [THEN] ['] c >body local   
   to c to b to a a b c a b c ;   
      
   Maybe now the decompilation makes sense ;-)   
      
   Hans Bezemer   
      
   > dxf
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca