Digest #273 2024-08-05

Contributions

[354] 2024-08-04 19:34:46 kumaym wrote:

requestClarification - definion and use of colon-sys and nest-sys

This text is for clarification of the intended use of colon-sys and nest-sys and also its use taking into account the differents steps or phases involved.

I will expose my understandings and more probably my misuderstanding about this in order to get knowledge and clarify. Maybe my confussion is related to the way it is redacted or maybe to my lack of knowledge.

The questions I want to get clarified for colon-sys and nest-sys are basically:

  1. semantics and definition
  2. implementation
  3. need to be defined as a concept in the standard
  4. semantics in terms of compile time and excution time

You can follow the comments in word literal about this issue but it's not necessary for the following discussion

  1. semantics and definition

The only place in standard where I can find a kind of definition is in 3.1 Data types where it is said that both colon-sys and nest-sys datatypes are implementation dependent and define colon-sys as a "definition compilation". The same for nest-sys which is defined in the same place as "definition cells" which I find confuse since it doesn't even mention is a return address or a return from call

I couldn't find any rule or requisite relative to colon-sys or nest-sys wich has sense since it is implementation dependent but then why to mention?

What I supposed is colon-sys is an abstract concept refering to a word definition meaning more or less all the stuff needed to start a definition leaving its real meaning to implementation, similar for nest-sys

  1. implementation

Anyway colon-sys is a real thing which is pushed in data stack (or control-flow stack if any) so I think it should be precissely defined, in particular this page says colon word "Enter compilation state and start the current definition, producing colon-sys", producing colon-sys suggests to me there is something real. It could be said colon-sys may be zero length and thus it produces nothing, this is implementation dependant, but then if size, structure and meaning of colon-sys it totally implementation defined, why to even mention it in the standar? it's implementation dependant.

There are at least two questions interesting to know about the colon-sys and nest-sys implementation:

  • where is it stored? i.e. is it possible to access to the colon-sys object if needed or it only leaves temporaly on stack? is it a first class object?
  • since it is on stack on word definition time, may a word definition a stack is empty or has to assume there's always a colon-sys object even if being zero sized?
  1. need to be defined as a concept in the standard

the mission of colon word is to create a new entry in the dictionary filling all slots and start to compile each xt it encounters in definition to dictionary area pointed by HERE. My understandin is all those steps can be done without polluting the stack from the point of view of definition words. At the time colon word starts compiling the words in the definition, the stack shoud be untouched so words in definition list can assume stack is "clear" (empty or with data pushed for last word execute prior to excute colon word) Finally, word ; just have to compile EXIT and switch to interpretation state, again it doesn't need anything in the stack to do its action.

So I think it's not necessary to define colon-sys or nest-sys in the standard since it is completely implementation dependant and thus it should be a black box.

The only reason to define or use a colon-sys concept is as a flag to users to take into acount than you have to assume stack is "polluted" into a defined word and you shouldn't assume nothing about the stack and in particular you shouldn't assume it is empty or under you control. In fact you should assume there's stuff on the stack when inside a definition and everything needed on the stack whould be pushed inside the definition.

  1. semantics in terms of compile time and excution time

In this page about word colon it is said:

( C: "<spaces>name" -- colon-sys ) Skip leading space delimiters. Parse name delimited by a space. Create a definition for name, called a "colon definition". 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 name will be determined by the words compiled into the body of the definition. The current definition shall not be findable in the dictionary until it is ended (or until the execution of DOES> in some systems).

The use of C: confuses me, I understand it as taking about compilation semantics, the "C:" in the stack comment.

But reading carefully I think C: really means control-flow stack rather tha compilaton semantics, and there's no Compilation section because word colon has no compilation semantics.

I think it shoud be interpretation semantics because the behaviour describes is runtime behaviour, what word colon does when executed:

Skip leading space delimiters. Parse name delimited by a space. Create a definition for name, called a "colon definition". Enter compilation state and start the current definition, producing colon-sys.

Anyway, assuming interpretation semantics, my problem is with the sentence

Append the initiation semantics given below to the current definition.

what I understand for "append the initiation semantics to the current definition" is to compile the initiation semanctics to the current definition, but if doing so you should see the initiation semantics in the definition list when you perform a see on the defined word, since it is compiled there otherwise, if to append the initiation semantics really means to execute the initiation semantics I think it is redacted not quite clear.

but sure I misunderstood it and really it's all about interpretation semantics because being that initiation semantics is written as:

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 name.

I undestand initiation is a interpretation semantics, part of interpretion semantics of colon word, it is talking about the behaviour when you're going to execute a word in the definition list in order to save the return address (nest-sys strcuture)

Maybe everything will be more clear including a Compilation sections stating there¡s no compilation semantics and thus everything in the page refers to interpreation semantics

In a first reading I was assuming Initiation semantics is compiled into definied word because "append initiation semantics to current definition" sounds to me the same as "compile initiation semantics into current definition"

Under this assumption I was supposing nest-sys is about nested definitions, and since nested definition of colon words are not allowed in forth, I supposed it was related to quotations since you "compile" a quotation is some way inside a current definition.

Replies

[r1268] 2024-07-30 07:00:43 TammoFreese replies:

requestClarification - compile semantics or compile action of literal word

If colon-sys would be non-zero width and be placed on the data stack, then the following word could not be compiled, right?

: foo [ 42 ] ;


[r1269] 2024-07-30 07:51:06 AntonErtl replies:

requestClarification - compile semantics or compile action of literal word

: foo [ 42 ] ; 

is not a standard program, so it's up to the individual system what it does with this program. Some report an error, some don't.


[r1270] 2024-07-31 14:42:03 ruv replies:

proposal - Allow the text interpreter to use `WORD` and the pictured numeric output

Since the word WORD will be obsolete in any case

By the way, WORD should not be declared obsolescent without including PARSE-NAME (or some alternative) in the CORE word set.


[r1271] 2024-07-31 17:29:26 kumaym replies:

requestClarification - compile semantics or compile action of literal word

: ANS definition says

Skip leading space delimiters. Parse name delimited by a space. Create a definition for name, called a "colon definition". Enter compilation state and start the current definition, producing colon-sys. Append the initiation semantics given below to the current definition.

I do not fully understand what is a colon-sys in terms of implementation but I suppose it is an abstract concept in order to define a colon definition leaving its real meaning to implementation. I see gforth puts a quite long colon-sys on stack when defining a word, but anyway I feel uncomfortable with this behaviour, I feel that word : shouldn't push anything on stack, I can understand this is necessary in terms of standardization but I see this too complicated and contrary to forth spirit of full control.

A : word mission is to create a new entry in the dictionary filling all slots (including CFA) and start to copy (compile) each xt it encounters in definition to dictionary are pointed by here (into PFA). All those steps can be done without polluting the stack, at the time it starts compiling words in definition the stack shoud be untouched (empty from the point of view of : word). Finally, word ; just have to compile EXIT and switch to interpret state, again it doesn't need anything in the stack to do its action.

This is my point of view, is it erroneus somehow? what made the standard to define a colon-sys concept and implementations to push all that stuff on stack when defining a word?


[r1272] 2024-07-31 18:23:04 kumaym replies:

requestClarification - compile semantics or compile action of literal word

Also I doen't understand the reason for initiation semantics in word :

Standard says

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

So I assume its mission is to leave in return stack the return addres to continue the current definition in the case of a nesting definition, but as far as I know nesting definitions are not allowed in Forth, in fact the standard has something to say about it :

During the compilation of the current definition, a program shall not execute any defining word, :NONAME, or any definition that allocates dictionary data space.

and I think a nesting definition implies executing a defining word during the compilation of the current definition.

Maybe it is related to quotations anyhow?


[r1273] 2024-08-01 07:24:34 ruv replies:

requestClarification - compile semantics or compile action of literal word

Finally, word ; just have to compile EXIT and switch to interpret state, again it doesn't need anything in the stack to do its action.

How to check that all control flow structures are correctly finished? How to create a nested definition? (e.g., a quotation, but a system is allowed to implement and use other cases)

Some systems employ colon-sys on the data stack to save the previous state and to check pairing. An alternative is to use a separate control-flow stack, but this approach is more complex to implement.


to leave in return stack the return addres to continue the current definition in the case of a nesting definition.

It is not about compilation-time, but about run-time. It's the first part of the well-known "call/return" mechanism. Semantics of "call" are specified as initiation semantics, due to the way of specifying the behavior of compile,.


[r1274] 2024-08-01 15:26:41 AntonErtl replies:

requestClarification - compile semantics or compile action of literal word

If you prefer a system where the colon-sys is empty, use such a system (or as an implementor, implement such a system).

An example of why systems have non-empty colon-sys is Gforth: it puts a DEFSTART tag on the stack to detect (and report) unbalanced control structures. It also puts an xt on the stack that is used for remembering some of the things needed at the end of the definition (like resolving a DOES>). It also puts some data there that allows to perform some static stack depth checking (but that project is not finished yet).

The question about the initiation semantics (and also the one about colon-sys) would be more appropriate for the entry on :, but anyway: Yes, the initiation semantics is about saving the return address (the nest-sys in standards lingo) on the return stack; this happens at run-time when the new colon definition is called from some other colon definition in some way (directly or through EXECUTE); the initiation semantics is implemented by docol in the traditional threaded-code implementations. And having one colon definition call another colon definition is definitely allowed. The initiation semantics has no particular relation with quotations (which don't exist in Forth-2012).

By contrast, nesting colon definitions at compile time is not allowed in the Forth-2012, but initiation semantics are what happens at run-time and are not related to that. I.e., the following is non-standard:

: foo [ : bar ; ] ;

while the following is standard:

: bar ;
: foo bar 1 . ;

Here the initiation semantics of bar pushes the return address on the return stack so that at the end of bar the run-time semantics of ; knows how to return control to foo.


[r1275] 2024-08-01 19:03:57 kumaym replies:

requestClarification - compile semantics or compile action of literal word

You're right when saying this dicussion is better placed in word : , it was my fault not to do it .

But now I don't know how to move it there, so would you prefer to move the discussion to word : or continue here?

If you consider it's better to move it I will continue there and even rewrite what is already written here.


[r1276] 2024-08-02 08:55:36 AntonErtl replies:

requestClarification - compile semantics or compile action of literal word

The system currently has no way for ordinary users to move contributions or replies elsewhere (and it would probably be a lot of work for the admin, too). My suggestion is to formulate a followon for : that stands alone. You may also provide a pointer to the present discussion, but in order to make your followon easy to understand without having to first follow a link and read that discussion, make it standalone. However, I think that you should refrain from repeating more stuff from here than is necessary to make the new question standalone; your link should be enough for those people who want to read this discussion.


[r1277] 2024-08-03 14:14:25 AntonErtl replies:

requestClarification - Unspecified ambiguous condition in /STRING

What is existing practice? Let's try:

create foo 10 chars allot
foo 2 3 /string cr . foo - .

I tested this on Gforth, iForth 5.1-mini, SwiftForth 4.0.0-RC89 and VFX 5.43, and the output of this test was invariably "-1 3", i.e., the result of wraparound (as a fan of applying correct typing, you can use u. instead of ., but the output will not be any more enlightening). I don't see a reason for any of your options. If any clarification is needed, it should be along the lines of

c-addr2 is c-addr1+n; u2 is u1-n