6.2.0455 :NONAME colon-no-name CORE EXT

( C: -- colon-sys ) ( S: -- xt )

Create an execution token xt, enter compilation state and start the current definition, producing colon-sys. Append the initiation semantics given below to the current definition.

The execution semantics of xt will be determined by the words compiled into the body of the definition. This definition can be executed later by using xt EXECUTE.

If the control-flow stack is implemented using the data stack, colon-sys shall be the topmost item on the data stack. See 3.2.3.2 Control-flow stack.

Initiation:

( i * x -- i * x ) ( R: -- nest-sys )

Save implementation-dependent information nest-sys about the calling definition. The stack effects i * x represent arguments to xt.

xt Execution:

( i * x -- j * x )

Execute the definition specified by xt. The stack effects i * x and j * x represent arguments to and results from xt, respectively.

See:

Rationale:

Typical use:

   DEFER print
   :NONAME ( n -- ) . ; IS print

Note:

RECURSE and DOES> are allowed within a :NONAME definition.

Testing:

VARIABLE nn1
VARIABLE nn2
T{ :NONAME 1234 ; nn1 ! -> }T
T{ :NONAME 9876 ; nn2 ! -> }T
T{ nn1 @ EXECUTE -> 1234 }T
T{ nn2 @ EXECUTE -> 9876 }T

ContributeContributions

flaagelavatar of flaagel [245] :NONAME PrimitivesRequest for clarification2022-07-05 16:22:37

Are these supposed to support RECURSE?

ruvavatar of ruv

Of course, recurse may be used in an unnamed definition.

The only place where recurse is not allowed is the part of a definition after does> (see the glossary entry for recurse).

A default rule is:

  • for a program: everything which is not explicitly forbidden is allowed;
  • for a system: everything which can be detected by a program and is not explicitly allowed is forbidden.

Where a program means a standard program, and a system means a standard system.

Reply New Version

pdaavatar of pda [373] where definition is compiled?Request for clarification2025-01-22 15:36:24

I couldn't find in any standard (fig-forth, ans...) a definition of the word saying how it is implemented, specially where the definition list of the word created using :NONAME is compiled.

In

:NONAME 2 * ;

where "2 *" is compiled? where in memory is literal 2 and * xt? and how long it will be using that memory? is there any way to free the memory?

AntonErtlavatar of AntonErtl

The standard generally leaves it to the system where it puts the compiled code. It might be in the dictionary, but it could also be elsewhere. Or it could be in the dictionary and elsewhere (e.g., Gforth puts threaded code in the dictionary, and native code elsewhere). The standard gives very few guarantees about this, so it also talks very little about it: There is "code space" in "2.1 Definition of Terms", and there is "3.3.2 Code Space" which does not give any guarantees.

Your best bet at reclaiming code space is to use FORGET or MARKER, but there is not guarantee that these words actually reclaim code space. And given the complexity of implementation arising from that, I am thinking about changing Gforth such that it does not reclaim the native code when MARKER is used.

I think this answers the question, so I am closing it. If there is anything unclear yet, write a reply and reopen it.

Closed

ruvavatar of ruv

how it is implemented, specially where the definition list of the word created using :NONAME is compiled.

The standard intentionally does not specify many options, which fall into implementation-defined options (which shall be documented) and implementation-dependent options (which might be undocumented).

Simple implementations typically reserve a big memory region for dictionary and use data space for code space too. Then, in direct and indirect threaded code, the words compile, and lit, is defined simply as:

: compile, ( xt -- ) , ;
: lit, ( x -- ) ['] lit compile, , ;

And

:noname 2 * ; 

is equivalent to

:noname [ 2 lit,  ' * compile, ] ;

is there any way to free the memory?

This is possible using marker:

marker restore-dict

: foo 123 . ;
foo \ prints "123"

restore-dict

foo \ error: not found
restore-dict \ error: not found

In some Forth system you can create many dictionaries and free them independently of each other.

Reply New Version