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

Replace COMPILE and [COMPILE] with POSTPONE? #413

Closed
TG9541 opened this issue Apr 1, 2021 · 3 comments
Closed

Replace COMPILE and [COMPILE] with POSTPONE? #413

TG9541 opened this issue Apr 1, 2021 · 3 comments
Assignees
Labels

Comments

@TG9541
Copy link
Owner

TG9541 commented Apr 1, 2021

More modern Forth implementations than eForth have long replaced COMPILE and [COMPILE] with the more general word POSTPONE.

The difference between the old and the new approach is this:

  1. Compile a regular word:
    a: : test1a COMPILE DROP ; => <CALL XT-COMPILE><CALL XT-DROP>
    b: : test1b POSTPONE DROP ; => <LIT XT-DROP><CALL XT-CALL,>

  2. Compile an IMMEDIATE word:
    a: : test2a [COMPILE] IF ; => <CALL XT-IF>
    b: : test2b POSTPONE IF ; => <CALL XT-IF>

When used as "macros" or directly as IMMEDIATE the words test1a - test2a and test1b - test2b perform the same thing (COMPILE in test1b has to work around any STM8 eForth code optimization features which can be a big issue)

There is an edge case when [COMPILE] is used to compile a regular word:
a: : test3a [COMPILE] DROP ; => <CALL XT-DROP>
b: : test3b POSTPONE DROP ; => <LIT XT-DROP><CALL XT-CALL,>

Other edge cases exist if any of the words POSTPONE, COMPILE or [COMPILE] is used with words defined by CREATE, CONSTANT or VARIABLE. I'll have to check what the "the standard` has to say about that.

Before doing any such change I'd like to get some input from the community.

  • is ALIASing the legacy words to POSTPONE an acceptable solution?
  • would you expect the original words to be retained, and if yes, why so?
@TG9541 TG9541 added the question label Apr 1, 2021
@TG9541 TG9541 self-assigned this Apr 1, 2021
@TG9541
Copy link
Owner Author

TG9541 commented Apr 5, 2021

This is now getting more serious ;-)

@TG9541
Copy link
Owner Author

TG9541 commented Apr 5, 2021

I've found a problem in >REL, the relative addressing compiler overlay for IF ... ELSE ... THEN:

I hadn't realized that ] isn't flagged IMMEDIATE (it doesn't need to be since it starts the compiler) and had compiled it with [COMPILE]. This has no effect whatsoever unless that's an alias for POSTPONE. The problem is easy to fix ( -> #419 ) but [COMPILE] masks such errors and one has to be careful when replacing that word.

@TG9541
Copy link
Owner Author

TG9541 commented Apr 7, 2021

Using POSTPONE in the lib worked fine. I'll now turn off the legacy words in defconf.inc. If some code needs them they can be selected in a downstream build configuration (e.g. in globconf.inc).

By default the aliases COMPILE and [COMPILE] are in the target folder. Just take care not to use the [COMPILE] alias on a non-IMMEDIATE word (which is now from now on "officially" an error).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant