Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ruv opened this issue Aug 28, 2020 · 0 comments
Labels
api An API method semantics consideration

Comments

@ruv
Copy link
Collaborator

ruv commented Aug 28, 2020

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

@ruv ruv added the api An API method semantics consideration label Aug 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api An API method semantics consideration
Projects
None yet
Development

No branches or pull requests

1 participant