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


Groups > comp.lang.forth > #31211

Re: Compiler Tricks

From anton@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups comp.lang.forth
Subject Re: Compiler Tricks
Date 2014-06-05 18:21 +0000
Organization Institut fuer Computersprachen, Technische Universitaet Wien
Message-ID <2014Jun5.202121@mips.complang.tuwien.ac.at> (permalink)
References <e83ffde9-78ab-49f9-bd0b-2b83137d6a51@googlegroups.com>

Show all headers | View raw


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?

Hmm, if you want a word that works in interpretation mode, the
following is standard:

: string-xt ( c-addr u -- xt )
  2>r :noname 2r> postpone sliteral postpone ; ;
: test" ( "name" -- xt )
  [char] " parse string-xt ;

test" bla bla" .s execute type

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

- anton
-- 
M. Anton Ertl  http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
     New standard: http://www.forth200x.org/forth200x.html
   EuroForth 2014: http://www.euroforth.org/ef14/

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