Skip to content

API: interpretation and compilation semantics are enough for user-defined descriptors #16

Open
@ruv

Description

@ruv

Idea

It is enough to provide interpretation and compilation semantics for new descriptors, no need for postponing action or reproducing action.

Rationale

There are only two places when postponing action can be used: POSTPONE and ]] ... [[ construct.

And this action is applicable to the system's descriptors only. So this action isn't required for the user defined descriptors.

Conceptual solution

Proof of concept

  : token>xt? ( k*x td -- xt td-xt | k*x td 0 )
    td-xt   over = if ( xt td-xt ) exit then
    td-nt   over = if over name> dup if nip nip td-xt then exit then
    0
  ;

  : xt, compile, ;

  : postpone-token?  ( k*x td -- true | k*x td false )
    td-nt over = if drop name>compile swap lit, xt, true exit then
    td-xt-imm over = if drop lit, 'execute-compiling xt, true exit then
    token>xt? if lit, 'xt, xt, true exit then
    false
  ;
  : compile-compile-token? ( k*x td -- true | k*x td false )
    postpone-token? ?et
    postpone [: compile-token postpone ;] 'xt, xt, true
    \ There is a possibility to return false
    \ for some implementation defined cases
  ;
  : next-lexeme ( -- c-addr u|0 )
    begin parse-lexeme ?et ( addr ) refill ?e0 drop again
  ;
  : ]]
    begin next-lexeme 2dup "[[" equals 0= while
      recognize-any dup ?nf compile-compile-token?
      0= -32 and throw
    repeat 2drop
  ;
  : postpone ( "ccc" -- )
    parse-lexeme perceive-lexeme dup ?nf
    postpone-token? ?e -32 throw
  ; immediate

Where

  compile-token ( i*x k*x td -- j*x )
  \ perform the compilation semantics that are determined
  \ by the given fully qualified token ( k*x td )

  recognize-any ( c-addr u -- k*x td | 0 )
  \ recognize a lexeme using the recognizer
  \ that the Forth text interpreter currently uses

In this approach, neither POSTPONE nor ]] refers to "postponing action" of user-defined descriptors. And, the former isn't applicable to them at all, the latter is applicable, and they parses the input (if any).


See also: "Recognizers and postponing" news:rdcn35$sd2$1@dont-email.me

See also: An approach to create any token descriptor

Short URL to this issue: https://git.io/JTHlm

Metadata

Metadata

Assignees

No one assigned

    Labels

    apiAn API method semantics consideration

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions