gforth
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [gforth] anonymous inline word definitions


From: David Kuehling
Subject: Re: [gforth] anonymous inline word definitions
Date: Wed, 05 Dec 2012 01:10:43 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux)

>>>>> "John" == John Earnest <address@hidden> writes:

> Howdy folks, Factor, PostScript and a few other stack-oriented
> languages have literal syntax for blocks of code- Factor calls these
> "quotations". I've been puzzling over how I might go about building a
> similar facility in GForth. I'd like to define { and } to delimit an
> inline word and leave an XT on the stack. So, for example, if I
> executed a word like:

>     : test   54 { 27 . } execute . ;

> It would simply print "27 54". Here's my first try at { and } :

>     : {   postpone ahead noname create latestxt ; immediate     : }  
> postpone exit >r postpone then r> postpone literal ; immediate

After some changes, this seems to actually work:

: { postpone ahead :noname ; immediate
: } postpone ; >R ] postpone then R> postpone literal  ; immediate

: test  54 { 27 . } execute . ;

The main problem with your approach is that 'create latestxt' does not
start a callable section of forth code.  Also note that gforth is not a
simple indirect threaded forth, so many naive assumptions about how code
can be generated/patched won't hold (you may use gforth-itc if you need
that anyways).

cheers,

David
-- 
GnuPG public key: http://dvdkhlng.users.sourceforge.net/dk.gpg
Fingerprint: B17A DC95 D293 657B 4205  D016 7DEF 5323 C174 7D40

Attachment: pgpgoZmPGACVI.pgp
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]