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


Groups > comp.lang.forth > #58992 > unrolled thread

accessing current xt

Started byAndreas Klimas <klimas@w3group.de>
First post2017-05-10 18:28 +0200
Last post2017-05-11 14:32 +0200
Articles 20 — 9 participants

Back to article view | Back to comp.lang.forth


Contents

  accessing current xt Andreas Klimas <klimas@w3group.de> - 2017-05-10 18:28 +0200
    Re: accessing current xt Mark Wills <markwills1970@gmail.com> - 2017-05-10 11:11 -0700
      Re: accessing current xt Mark Wills <markwills1970@gmail.com> - 2017-05-10 11:16 -0700
      Re: accessing current xt Lars Brinkhoff <lars.spam@nocrew.org> - 2017-05-10 20:20 +0200
      Re: accessing current xt Andreas Klimas <klimas@w3group.de> - 2017-05-10 21:48 +0200
        Re: accessing current xt pahihu <pahihu@gmail.com> - 2017-05-10 13:12 -0700
          Re: accessing current xt Andreas Klimas <klimas@w3group.de> - 2017-05-11 00:12 +0200
        Re: accessing current xt "Elizabeth D. Rather" <erather@forth.com> - 2017-05-10 15:14 -1000
          Re: accessing current xt Andreas Klimas <klimas@w3group.de> - 2017-05-11 09:57 +0200
            Re: accessing current xt "Elizabeth D. Rather" <erather@forth.com> - 2017-05-11 21:33 -1000
    accessing current xt gwj.nexus@gmail.com - 2017-05-10 12:56 -0700
      Re: accessing current xt Andreas Klimas <klimas@w3group.de> - 2017-05-11 00:12 +0200
        Re: accessing current xt gwj.nexus@gmail.com - 2017-05-10 22:57 -0700
    Re: accessing current xt anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2017-05-11 06:39 +0000
    Re: accessing current xt humptydumpty <ouatubi@gmail.com> - 2017-05-11 00:21 -0700
      Re: accessing current xt Lars Brinkhoff <lars.spam@nocrew.org> - 2017-05-11 09:38 +0200
        Re: accessing current xt humptydumpty <ouatubi@gmail.com> - 2017-05-11 00:49 -0700
          Re: accessing current xt Lars Brinkhoff <lars.spam@nocrew.org> - 2017-05-11 10:38 +0200
            Re: accessing current xt Julian Fondren <julian.fondren@gmail.com> - 2017-05-11 04:11 -0700
              Re: accessing current xt Lars Brinkhoff <lars.spam@nocrew.org> - 2017-05-11 14:32 +0200

#58992 — accessing current xt

FromAndreas Klimas <klimas@w3group.de>
Date2017-05-10 18:28 +0200
Subjectaccessing current xt
Message-ID<oevetu$ivi$1@dont-email.me>
is it possible to access the name of the word beeing compiled ?

fictive example

: log current-xt >name .log ; immediate

: foo log   ... ;


if I don't have access to the current xt, is it possible
to define my own : where I can catch the name and
may be the comment.

my: foo ( --) any words here ;

or maybe even simpler
: foo ... ;
comment" ..." where comment will take the name of the last
defined word. Or is this all illegal ?
the word immediate might do simmilar things ?

thank you
best wishes
Andreas Klimas

[toc] | [next] | [standalone]


#58999

FromMark Wills <markwills1970@gmail.com>
Date2017-05-10 11:11 -0700
Message-ID<88eb352b-b6b9-40a3-a560-14dd76a20a2b@googlegroups.com>
In reply to#58992
On Wednesday, 10 May 2017 17:28:54 UTC+1, Andreas Klimas  wrote:
> is it possible to access the name of the word beeing compiled ?
> 
> fictive example
> 
> : log current-xt >name .log ; immediate
> 
> : foo log   ... ;
> 
> 
> if I don't have access to the current xt, is it possible
> to define my own : where I can catch the name and
> may be the comment.
> 
> my: foo ( --) any words here ;
> 
> or maybe even simpler
> : foo ... ;
> comment" ..." where comment will take the name of the last
> defined word. Or is this all illegal ?
> the word immediate might do simmilar things ?
> 
> thank you
> best wishes
> Andreas Klimas

You might be able to access it via LATEST but it will be specific
to the system you are using. Not portable at all.

LATEST will point to the last thing to be built in the dictionary,
which should (hopefully) be your word that you are currently
compiling. It may be smudged. You'll generally want to convert
the address that LATEST @ returns into the XT using some magic
word. In my system, it's >CFA

LATEST @ >CFA

Would give you the XT (suitable for EXECUTE et al) of the last
word defined. Again, on *my system*, you can read LATEST while
you're actually compiling (for example in an immediate word)
and get the XT, or name field etc.

No guarantees though. Which system are you using?

[toc] | [prev] | [next] | [standalone]


#59000

FromMark Wills <markwills1970@gmail.com>
Date2017-05-10 11:16 -0700
Message-ID<08268674-e2ae-45ab-9347-ceda7cccdc20@googlegroups.com>
In reply to#58999
On Wednesday, 10 May 2017 19:11:32 UTC+1, Mark Wills  wrote:
> On Wednesday, 10 May 2017 17:28:54 UTC+1, Andreas Klimas  wrote:
> > is it possible to access the name of the word beeing compiled ?
> > 
> > fictive example
> > 
> > : log current-xt >name .log ; immediate
> > 
> > : foo log   ... ;
> > 
> > 
> > if I don't have access to the current xt, is it possible
> > to define my own : where I can catch the name and
> > may be the comment.
> > 
> > my: foo ( --) any words here ;
> > 
> > or maybe even simpler
> > : foo ... ;
> > comment" ..." where comment will take the name of the last
> > defined word. Or is this all illegal ?
> > the word immediate might do simmilar things ?
> > 
> > thank you
> > best wishes
> > Andreas Klimas
> 
> You might be able to access it via LATEST but it will be specific
> to the system you are using. Not portable at all.
> 
> LATEST will point to the last thing to be built in the dictionary,
> which should (hopefully) be your word that you are currently
> compiling. It may be smudged. You'll generally want to convert
> the address that LATEST @ returns into the XT using some magic
> word. In my system, it's >CFA
> 
> LATEST @ >CFA
> 
> Would give you the XT (suitable for EXECUTE et al) of the last
> word defined. Again, on *my system*, you can read LATEST while
> you're actually compiling (for example in an immediate word)
> and get the XT, or name field etc.
> 
> No guarantees though. Which system are you using?

Try something like this:

: get-XT ( -- ) ." XT of word being built is "
  LATEST @ >CFA . ; IMMEDIATE

: test ( -- ) get-XT 1 2 3 ;

Works on my system. You might need to find the equivalent of >CFA
for your system.

On my system, >CFA takes a dictionary link field address and converts
to the XT/CFA (code field address). LATEST always points to the link
field of the last word built.

[toc] | [prev] | [next] | [standalone]


#59001

FromLars Brinkhoff <lars.spam@nocrew.org>
Date2017-05-10 20:20 +0200
Message-ID<86inl88tfx.fsf@molnjunk.nocrew.org>
In reply to#58999
Mark Wills wrote:
> Andreas Klimas wrote:
>> is it possible to access the name of the word beeing compiled ?
>> : log current-xt >name .log ; immediate
>> : foo log   ... ;
>
> You might be able to access it via LATEST but it will be specific
> to the system you are using. Not portable at all.

Is it possible to check what RECURSE does?  It may have access to the xt
of the latest word.

[toc] | [prev] | [next] | [standalone]


#59006

FromAndreas Klimas <klimas@w3group.de>
Date2017-05-10 21:48 +0200
Message-ID<oevql0$3r5$1@dont-email.me>
In reply to#58999
On 2017-05-10 18:11:30 +0000, Mark Wills said:

> On Wednesday, 10 May 2017 17:28:54 UTC+1, Andreas Klimas  wrote:
>> is it possible to access the name of the word beeing compiled ?
>> 
>> fictive example
>> 
>> : log current-xt >name .log ; immediate
>> 
>> : foo log   ... ;
> 
> You might be able to access it via LATEST but it will be specific
> to the system you are using. Not portable at all.

currently I'm evaluating SwiftForth and gforth.

SwiftForth unfortunately doesn't have LATEST
gforth doesn't have >CFA

I'm using the evaluation version of SwiftForth, hence
kernel source is missing (in which recurese or immediat
is located).

I want to include some kind of introspection into
compiled code, for profiling, debugging, logging
etc. What is your (Forther) way ?
or don't you ?
you may be have another approach ?
If it is possible, I would go with Ansi Forth.

- Andreas

[toc] | [prev] | [next] | [standalone]


#59008

Frompahihu <pahihu@gmail.com>
Date2017-05-10 13:12 -0700
Message-ID<c6d61c1d-ead3-40a9-86a2-08d0e9bfcd5a@googlegroups.com>
In reply to#59006
2017. május 10., szerda 21:48:56 UTC+2 időpontban Andreas Klimas a következőt írta:
SwiftForth:

   : log cr ." -->" last @ count type ; immediate  ok
   : foo log 1 2 + ; 
-->foo ok

pahihu

[toc] | [prev] | [next] | [standalone]


#59012

FromAndreas Klimas <klimas@w3group.de>
Date2017-05-11 00:12 +0200
Message-ID<of031r$2kc$1@dont-email.me>
In reply to#59008
On 2017-05-10 20:12:03 +0000, pahihu said:

> 2017. május 10., szerda 21:48:56 UTC+2 időpontban Andreas Klimas a 
> következőt írta:
> SwiftForth:
> 
>    : log cr ." -->" last @ count type ; immediate  ok
>    : foo log 1 2 + ;-->foo ok
> 
> pahihu

works fine in SwiftForth, thank you

[toc] | [prev] | [next] | [standalone]


#59024

From"Elizabeth D. Rather" <erather@forth.com>
Date2017-05-10 15:14 -1000
Message-ID<xKqdndnmKPRoJ47EnZ2dnUU7-YPNnZ2d@supernews.com>
In reply to#59006
On 5/10/17 9:48 AM, Andreas Klimas wrote:
> On 2017-05-10 18:11:30 +0000, Mark Wills said:
>
>> On Wednesday, 10 May 2017 17:28:54 UTC+1, Andreas Klimas  wrote:
>>> is it possible to access the name of the word beeing compiled ?
>>>
>>> fictive example
>>>
>>> : log current-xt >name .log ; immediate
>>>
>>> : foo log   ... ;
>>
>> You might be able to access it via LATEST but it will be specific
>> to the system you are using. Not portable at all.
>
> currently I'm evaluating SwiftForth and gforth.
>
> SwiftForth unfortunately doesn't have LATEST
> gforth doesn't have >CFA
>
> I'm using the evaluation version of SwiftForth, hence
> kernel source is missing (in which recurese or immediat
> is located).
>
> I want to include some kind of introspection into
> compiled code, for profiling, debugging, logging
> etc. What is your (Forther) way ?
> or don't you ?
> you may be have another approach ?
> If it is possible, I would go with Ansi Forth.

"Introspection" pretty much necessitates carnal knowledge of the system. 
SwiftForth has a lot of facilities of this sort (check the manual), and 
I assume most systems do, but they're inevitably implementation-dependent.

Cheers,
Elizabeth

-- 
Elizabeth D. Rather
FORTH, Inc.
6080 Center Drive, Suite 600
Los Angeles, CA  90045
USA

[toc] | [prev] | [next] | [standalone]


#59057

FromAndreas Klimas <klimas@w3group.de>
Date2017-05-11 09:57 +0200
Message-ID<of15c0$27n$1@dont-email.me>
In reply to#59024
On 2017-05-11 01:14:28 +0000, Elizabeth D. Rather said:

> On 5/10/17 9:48 AM, Andreas Klimas wrote:
>> On 2017-05-10 18:11:30 +0000, Mark Wills said:
>> 
>>> On Wednesday, 10 May 2017 17:28:54 UTC+1, Andreas Klimas  wrote:
>>>> is it possible to access the name of the word beeing compiled ?
>>>> 
>>>> fictive example
>>>> 
>>>> : log current-xt >name .log ; immediate
>>>> 
>>>> : foo log   ... ;
>>> 
>>> You might be able to access it via LATEST but it will be specific
>>> to the system you are using. Not portable at all.
>> 
>> currently I'm evaluating SwiftForth and gforth.
>> 
>> SwiftForth unfortunately doesn't have LATEST
>> gforth doesn't have >CFA
>> 
>> I'm using the evaluation version of SwiftForth, hence
>> kernel source is missing (in which recurese or immediat
>> is located).
>> 
>> I want to include some kind of introspection into
>> compiled code, for profiling, debugging, logging
>> etc. What is your (Forther) way ?
>> or don't you ?
>> you may be have another approach ?
>> If it is possible, I would go with Ansi Forth.
> 
> "Introspection" pretty much necessitates carnal knowledge of the 
> system. SwiftForth has a lot of facilities of this sort (check the 
> manual), and I assume most systems do, but they're inevitably 
> implementation-dependent.

Elizabeth, I appreciate it very much from you to get an answer.

A Google search gave me

TRAVERSE-WORDLIST

which I found also in the standard documentation.
I think this could solve all my needs.


- Andreas Klimas

> 
> Cheers,
> Elizabeth

[toc] | [prev] | [next] | [standalone]


#59106

From"Elizabeth D. Rather" <erather@forth.com>
Date2017-05-11 21:33 -1000
Message-ID<WNWdneQ6g-Om-IjEnZ2dnUU7-UOdnZ2d@supernews.com>
In reply to#59057
On 5/10/17 9:57 PM, Andreas Klimas wrote:
> On 2017-05-11 01:14:28 +0000, Elizabeth D. Rather said:
>
>> On 5/10/17 9:48 AM, Andreas Klimas wrote:
>>> On 2017-05-10 18:11:30 +0000, Mark Wills said:
>>>
>>>> On Wednesday, 10 May 2017 17:28:54 UTC+1, Andreas Klimas  wrote:
>>>>> is it possible to access the name of the word beeing compiled ?
>>>>>
>>>>> fictive example
>>>>>
>>>>> : log current-xt >name .log ; immediate
>>>>>
>>>>> : foo log   ... ;
>>>>
>>>> You might be able to access it via LATEST but it will be specific
>>>> to the system you are using. Not portable at all.
>>>
>>> currently I'm evaluating SwiftForth and gforth.
>>>
>>> SwiftForth unfortunately doesn't have LATEST
>>> gforth doesn't have >CFA
>>>
>>> I'm using the evaluation version of SwiftForth, hence
>>> kernel source is missing (in which recurese or immediat
>>> is located).
>>>
>>> I want to include some kind of introspection into
>>> compiled code, for profiling, debugging, logging
>>> etc. What is your (Forther) way ?
>>> or don't you ?
>>> you may be have another approach ?
>>> If it is possible, I would go with Ansi Forth.
>>
>> "Introspection" pretty much necessitates carnal knowledge of the
>> system. SwiftForth has a lot of facilities of this sort (check the
>> manual), and I assume most systems do, but they're inevitably
>> implementation-dependent.
>
> Elizabeth, I appreciate it very much from you to get an answer.
>
> A Google search gave me
>
> TRAVERSE-WORDLIST
>
> which I found also in the standard documentation.
> I think this could solve all my needs.

Yes. This is the kind of solution that is needed as a standard facility, 
because it isn't feasible for users to add it.

Cheers,
Elizbeth

-- 
Elizabeth D. Rather
FORTH, Inc.
6080 Center Drive, Suite 600
Los Angeles, CA  900 45
USA

[toc] | [prev] | [next] | [standalone]


#59007

Fromgwj.nexus@gmail.com
Date2017-05-10 12:56 -0700
Message-ID<8ef4e831-3d7c-4e72-8ea2-f3fe86c5278e@googlegroups.com>
In reply to#58992
You can redefine : to get at the name of the new definition.

: : >in @ >r : r> >in ! parse-name type ;

Replay TYPE with whatever you wish to do with the name.

(I'm using Google groups here so can't include your post in this reply)

[toc] | [prev] | [next] | [standalone]


#59013

FromAndreas Klimas <klimas@w3group.de>
Date2017-05-11 00:12 +0200
Message-ID<of032t$2kc$2@dont-email.me>
In reply to#59007
On 2017-05-10 19:56:24 +0000, gwj.nexus@gmail.com said:

> You can redefine : to get at the name of the new definition.
> 
> : : >in @ >r : r> >in ! parse-name type ;
> 
> Replay TYPE with whatever you wish to do with the name.
> 
> (I'm using Google groups here so can't include your post in this reply)

works fine in gforth, thank you

- Andreas

[toc] | [prev] | [next] | [standalone]


#59035

Fromgwj.nexus@gmail.com
Date2017-05-10 22:57 -0700
Message-ID<937da544-2254-49a2-8256-6b3727d723fd@googlegroups.com>
In reply to#59013
It should work with any ANS Forth that has the Forth 2012 word PARSE-NAME. If not replace it with BL WORD COUNT.

Before giving up the struggle with my Android tablet last night, was going to add that you can use similar code to log the stack comment as well as the name by using PARSE to parse for '(' and then ')'.

[toc] | [prev] | [next] | [standalone]


#59043

Fromanton@mips.complang.tuwien.ac.at (Anton Ertl)
Date2017-05-11 06:39 +0000
Message-ID<2017May11.083951@mips.complang.tuwien.ac.at>
In reply to#58992
Andreas Klimas <klimas@w3group.de> writes:
>is it possible to access the name of the word beeing compiled ?

In both Gforth and SwiftForth, LAST @ gives you the nt of the most
recent definition (including the nt of the current definition while in
the definition.  So

last @ name>string type

prints the name.

>fictive example
>
>: log current-xt >name .log ; immediate
>
>: foo log   ... ;

One approach that has not been mentioned by others is that LOG could
access the current line and scan back from the >IN position to the
name before LOG.  That would be standard.

- 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 2017: http://www.euroforth.org/ef17/

[toc] | [prev] | [next] | [standalone]


#59049

Fromhumptydumpty <ouatubi@gmail.com>
Date2017-05-11 00:21 -0700
Message-ID<9688556b-283e-42cf-bef5-efa012b34e95@googlegroups.com>
In reply to#58992
On Wednesday, May 10, 2017 at 7:28:54 PM UTC+3, Andreas Klimas wrote:
> is it possible to access the name of the word beeing compiled ?
> 
> fictive example
> 
> : log current-xt >name .log ; immediate
> 
> : foo log   ... ;
> 
> 
> if I don't have access to the current xt, is it possible
> to define my own : where I can catch the name and
> may be the comment.
> 
> my: foo ( --) any words here ;
> 
> or maybe even simpler
> : foo ... ;
> comment" ..." where comment will take the name of the last
> defined word. Or is this all illegal ?
> the word immediate might do simmilar things ?
> 
> thank you
> best wishes
> Andreas Klimas

Here is a technique that I named "postfix literal" (command-line excerpt):

Gforth 0.7.3, Copyright (C) 1995-2008 Free Software Foundation, Inc.
Gforth comes with ABSOLUTELY NO WARRANTY; for details type `license'
Type `bye' to exit
variable post/fix  ok                                                
: pf/literal  ( n -- ) ['] lit compile, HERE post/fix ! , ; immediate  ok
: my-name-is  [ ' noop ] pf/literal >name name>string cr type ;  ok  
my-name-is                                                           
noop ok
' my-name-is post/fix @ !  ok                                        
my-name-is                                                     
my-name-is ok
bye 

You can try it on other Forth implementations. First thing to try
is to see how "literal" is defined.

Have a nice day,
hum9

[toc] | [prev] | [next] | [standalone]


#59053

FromLars Brinkhoff <lars.spam@nocrew.org>
Date2017-05-11 09:38 +0200
Message-ID<86y3u37sh8.fsf@molnjunk.nocrew.org>
In reply to#59049
humptydumpty wrote:
> Here is a technique that I named "postfix literal" (command-line excerpt):

I have sometimes felt this need for a LITERAL that is resolved later,
just like THEN resolves an IF.

[toc] | [prev] | [next] | [standalone]


#59055

Fromhumptydumpty <ouatubi@gmail.com>
Date2017-05-11 00:49 -0700
Message-ID<b947d14a-cb3f-4dff-963e-4db428e33c8e@googlegroups.com>
In reply to#59053
On Thursday, May 11, 2017 at 10:39:01 AM UTC+3, Lars Brinkhoff wrote:
> humptydumpty wrote:
> > Here is a technique that I named "postfix literal" (command-line excerpt):
> 
> I have sometimes felt this need for a LITERAL that is resolved later,
> just like THEN resolves an IF.


Can be evolved into a CREATE DOES> version with named fix-up addresses, for heavy use. :)

--
Have a nice day,
hum9

[toc] | [prev] | [next] | [standalone]


#59062

FromLars Brinkhoff <lars.spam@nocrew.org>
Date2017-05-11 10:38 +0200
Message-ID<86tw4r7pqq.fsf@molnjunk.nocrew.org>
In reply to#59055
humptydumpty write:
>> I have sometimes felt this need for a LITERAL that is resolved later,
>> just like THEN resolves an IF.
> Can be evolved into a CREATE DOES> version with named fix-up
> addresses, for heavy use. :)

That's the thing, I don't want it to be named.  Imagine if you had
to make up a name every time you used IF.

[toc] | [prev] | [next] | [standalone]


#59074

FromJulian Fondren <julian.fondren@gmail.com>
Date2017-05-11 04:11 -0700
Message-ID<2c886ade-1481-4aae-9903-ac7d8031d907@googlegroups.com>
In reply to#59062
On Thursday, May 11, 2017 at 3:38:06 AM UTC-5, Lars Brinkhoff wrote:
> humptydumpty write:
> >> I have sometimes felt this need for a LITERAL that is resolved later,
> >> just like THEN resolves an IF.
> > Can be evolved into a CREATE DOES> version with named fix-up
> > addresses, for heavy use. :)
> 
> That's the thing, I don't want it to be named.  Imagine if you had
> to make up a name every time you used IF.

Just reuse the name.

  0 value nonce
  : was ( n "name" -- )
    >in @ swap ' >body !
    >in ! 0 value ;
  
  : x1 cr ." x1: " nonce . ;  4 was nonce
  : x2 cr ." x2: " nonce . ; -4 was nonce
  
  0 value nonce'
  
  : x3 cr ." x3: " nonce . nonce' . ; 8 was nonce -8 was nonce'
  
  x1 x2 x3 x3 x2 x1

Output:

  x1: 4 
  x2: -4 
  x3: 8 -8 
  x3: 8 -8 
  x2: -4 
  x1: 4 

And also, you know, the warnings.

[toc] | [prev] | [next] | [standalone]


#59080

FromLars Brinkhoff <lars.spam@nocrew.org>
Date2017-05-11 14:32 +0200
Message-ID<86poff7evw.fsf@molnjunk.nocrew.org>
In reply to#59074
Julian Fondren wrote:
> Just reuse the name.
>
>   0 value nonce
>   : was ( n "name" -- )
>     >in @ swap ' >body !
>     >in ! 0 value ;

Thanks, that's clever!

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.forth


csiph-web