Skip to content

Instantly share code, notes, and snippets.

@ruv
Last active April 19, 2021 07:13
Show Gist options
  • Save ruv/3c75b48f405ecd8842d8024f1dcd0692 to your computer and use it in GitHub Desktop.
Save ruv/3c75b48f405ecd8842d8024f1dcd0692 to your computer and use it in GitHub Desktop.
Proposal, specification for FIND

(version A)


FIND

( c-addr -- c-addr 0 | xt n )

Find the definition name whose name matches the counted string at c-addr. If the definition is not found, return c-addr and zero. Otherwise the definition is found, return xt and n, where xt is the execution token for name, and n is 1 or -1. If name has other than default interpretation semantics, all the returned values may differ between interpretation and compilation state; otherwise they are the same.

When the definition is found in interpretation state: if the definition is immediate then n is 1, otherwise n is -1; performing xt in interpretation state performs the interpretation semantics for name.

When the definition is found in compilation state: if n is -1, appending the execution semantics identified by xt to the current definition performs the compilation semantics for name, otherwise performing xt in compilation state performs the compilation semantics for name.

An ambiguous condition exists if xt returned by FIND is performed in the conditions that are not met the conditions specified above.


"Performing xt" means performing the execution semantics identified by the execution token xt.

A definition has default interpretation semantics if and only if the "Interpretation:" section is absent in the corresponding glossary entry, and the "Execution:" section is present. Default interpretation semantics for a definition is to perform its executin semantics in interpretation state (see also 3.4.3.2).

(version B)


FIND

( c-addr -- c-addr 0 | xt n )

Find the definition name whose name matches the counted string at c-addr. If the definition is not found, return c-addr and zero. Otherwise the definition is found, return xt and n.

If name has default interpretation semantics, xt is the execution token for name, and n is 1 if name is immediate word, -1 otherwise. The returned values are the same regardless whether the definition is found in interpretation state or in compilation state.

If name has other than default interpretation semantics, xt is the execution token for an unspecified implementation-dependent definition, and n is 1 or -1, and the following conditions are met.

  1. When the definition is found in compilation state: if n is 1, performing xt in compilation state performs the compilation semantics for name, otherwise n is -1, and appending the execution semantics identified by xt to the current definition performs the compilation semantics for name.

  2. When the definition is found in interpretation state: if n is 1, xt and n are the same when the definition is found in compilation state, otherwise n is -1, and both xt and n may be different when the definition is found in compilation state; performing xt in interpretation state performs the interpretation semantics for name.

  3. The definition may be not found in interpretation state but found in compilation state, and vise versa. Also a definition may be not found at all.

An ambiguous condition exists if xt is performed in the conditions that are not met the conditions specified above.


"Performing xt" means performing the execution semantics identified by the execution token xt.

A definition has default interpretation semantics if and only if the "Interpretation:" section is absent in the corresponding glossary entry, and the "Execution:" section is present (see also 3.4.3.1). Default interpretation semantics for a definition is to perform its executin semantics in interpretation state (see also 3.4.3.2).

If interpretation semantics are undefined for a definition, a Forth system is allowed to provide implementation-defined interpretation semantics for this definition (see A.3.4.3.2). In such case, when the definition is found in interpretation state, performing the returned xt in interpretation state performs the implementation-defined interpretation semantics for name.

A program is allowed to apply FIND to any string. A definition may be not found even if a Forth system provides interpretation or compilation semantics for the corresponding name (for example, in the case of locals).

(version C)


Rationale

Features

  • Cover single-xt, dual-nt, and dual-xt systems.
  • Avoid ambiguous clause "xt is the execution token for name" in the case of a word with non default interpretation semantics.
  • Allow to return the different xt for any definition.
  • Tight meaning of n in interpretation state.
  • Gurantee that if name has default interpretation semantics, then ' name in interpretation state returns the same xt that FIND returns for name in interpretation state.

FIND

( c-addr -- c-addr 0 | xt n )

Find the definition name whose name matches the counted string at c-addr. If the definition is not found, return c-addr and zero.

Otherwise, return xt and n, where xt is an execution token and n is -1 or 1. The returned values may differ between interpretation and compilation state, and the following conditions shall be met:

  • if the definition is found in interpretation state, then
    • if and only if name is immediate, n is 1, otherwise n is -1;
    • if name has default interpretation semantics, xt indetifies the execution semantics for name;
    • performing xt in interpretation state performs the interpretation semantics for name;
  • if the definition is found in compilation state, then
    • if n is 1, performing xt in compilation state performs the compilation semantics for name;
    • if n is -1, appending the execution semantics identified by xt to the current definition performs the compilation semantics for name.

A definition may be found in compilation state but not found in interpretation state (or vise versa).

If the execution semantics identified by xt are specified either for interpretatin or for compilation state only (i.e., in the cases when the interpretation semantics for name are not default), it's ambiguous to perform these semantics in a state they are not specified for.


"Performing xt" means performing the execution semantics identified by the execution token xt.

A definition has default interpretation semantics if and only if the "Interpretation:" section is absent in the corresponding glossary entry (see 3.4.3.2).

If interpretation semantics are undefined for a definition, a Forth system is allowed to provide implementation-defined interpretation semantics for this definition (see A.3.4.3.2). In such case, when the definition is found in interpretation state, performing the returned xt in interpretation state performs the implementation-defined interpretation semantics for name.

If immediacy is not specified for a definition with non default interpretation semantics, a Forth system is still allowed to implement this definition as an immediate word by providing implementation-dependent execution semantics for this definition (see A.6.1.2033, A.6.1.1550).

@ruv
Copy link
Author

ruv commented Oct 23, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment