gforth
[Top][All Lists]
Advanced

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

Re: [gforth] Fwd: anonymous inline word definitions


From: Anton Ertl
Subject: Re: [gforth] Fwd: anonymous inline word definitions
Date: Wed, 5 Dec 2012 16:36:58 +0100
User-agent: Mutt/1.5.18 (2008-05-17)

On Tue, Dec 04, 2012 at 09:13:46PM -0500, John Earnest wrote:
> In a semi-related note, has anyone tried building callable words in
> dynamically allocated (non-dictionary space) memory?

For the threaded-code part, it's probably sufficient to just set dp
appropriately.  However, Gforth normally also generates some native
code, and that is managed in a stack-like way, and it's not easy to
change that.  I guess, though, that you don't need the native code for
your temporary code (execution is faster, but code generation is
slower with native code).

Unfortunately, it's not easy to get COMPILE, to produce just threaded
code in this case without turning off native code alltogether.  What
you can do is to work at a lower level.  E.g., if normally you would
code your thunk as follows:

: gen-thunk ( x coldef-xt -- xt2 )
  >r >r :noname r> postpone literal r> compile, postpone ; ;

you could instead do it as follows:

: postpone-prim ( "name" -- )
  ' @ postpone literal postpone , ; immediate
\   ^ leave that away for ITC

: gen-thunk ( x coldef-xt -- )
  docol: cfa, postpone-prim lit swap , postpone-prim branch >body , lastxt ;

and you get tail-call optimization thrown in.

> Any thoughts about how one would go about doing that portably? With a
> little sugar and a fairly significant amount of plumbing it would be
> possible to provide lexical capture of local variables surrounding
> quotations via such a mechanism.

Since you are prepared to go for garbage collection, that's possible,
but yes, it would require quite a bit of plumbing.

- anton



reply via email to

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