Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #31235

Re: Compiler Tricks

From Gerry Jackson <gerry@jackson9000.fsnet.co.uk>
Newsgroups comp.lang.forth
Subject Re: Compiler Tricks
Date 2014-06-06 09:16 +0100
Organization A noiseless patient Spider
Message-ID <lmrtcn$epv$1@dont-email.me> (permalink)
References <e83ffde9-78ab-49f9-bd0b-2b83137d6a51@googlegroups.com> <2014Jun5.202121@mips.complang.tuwien.ac.at>

Show all headers | View raw


On 05/06/2014 19:21, Anton Ertl wrote:
> Jason Damisch <jasondamisch@yahoo.com> writes:
>> Hi Guys ( and Gals ),
>>
>> I want to ask a question.  I want to have a word which compiles a string but instead of returning the address to the string, instead returns an XT which when executed returns the address of the string.
> ....
>> My question, is there a more portable way of doing this?
>
[...]

>
> If you want a word that works inside a colon definition, I don't think
> that's possible in standard Forth.  It may be possible with quotations
> (but the following does not work currently with Gforth):
>
> : string-xt1 ( c-addr u -- xt )
>    2>r postpone [: 2r> postpone sliteral  postpone ;] ;
>
> : [test]" '"' parse string-xt1 postpone literal ; immediate
>
> : foo [test]" bla bla" ;
> foo execute type
>

It doesn't work on my system either but removing POSTPONE LITERAL from 
[test]" does work because ;] already compiles the xt as a literal in its 
enclosing definition which is FOO in this case i.e.

: [test]" '"' parse string-xt1 ; immediate

So you might as well define

: string-xt1" ( -- )
    [char] " parse 2>r postpone [: 2r> postpone sliteral  postpone ;]
; immediate

: foo string-xt1" bla bla" ;
foo execute type

-- 
Gerry

Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Compiler Tricks Jason Damisch <jasondamisch@yahoo.com> - 2014-06-05 11:00 -0700
  Re: Compiler Tricks anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2014-06-05 18:21 +0000
    Re: Compiler Tricks Jason Damisch <jasondamisch@yahoo.com> - 2014-06-05 13:43 -0700
    Re: Compiler Tricks Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2014-06-06 09:16 +0100
  Re: Compiler Tricks "Rod Pemberton" <dont_use_email@xnothavet.cqm> - 2014-06-05 15:36 -0400
    Re: Compiler Tricks Jason Damisch <jasondamisch@yahoo.com> - 2014-06-05 13:48 -0700
      Re: Compiler Tricks "Rod Pemberton" <dont_use_email@xnothavet.cqm> - 2014-06-05 17:30 -0400
        Re: Compiler Tricks Jason Damisch <jasondamisch@yahoo.com> - 2014-06-05 14:50 -0700
  Compiler Tricks Julian Fondren <ayrnieu@gmail.com> - 2014-06-05 13:50 -0700
    Re: Compiler Tricks Jason Damisch <jasondamisch@yahoo.com> - 2014-06-05 14:03 -0700
  Re: Compiler Tricks "Clyde W. Phillips Jr." <cwpjr02@gmail.com> - 2014-06-05 19:32 -0700

csiph-web