Skip to content

Suspicious code in cross.fs #80

@ElectronicRU

Description

@ElectronicRU

https://github.com/jamesbowman/swapforth/blob/master/j1a/cross.fs#L167
AFAICT, this piece of code means "If any of the previous instructions branches to end-of-word, do a return trick on it."
However,

            i tbranches @ tdp @ = if
                i tbranches @ shortcut and
            then

is by construction (i tbranches @ == tdp @) equivalent to

            i tbranches @ tdp @ = if
                tdp @ shortcut and
            then

which doesn't make sense, as it attempts to shortcut an instruction yet unwritten.

If I understand the code correctly, this is supposed to mean "if an instruction at address i branches to here (as would happen if the last word in a word definition is then), then apply the return-hack to that instruction". The correct if-statement in this case would be something like

            i tbranches @ tdp @ = if
                i shortcut and
            then

if I am not mistaken.

P.S. "shortcut" for this case should probably also replace unconditional-jump to exit location with "exit".
P.P.S. Could the enclosing do-loop be changed from tdp @ 0 to tdp @ wordstart @?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions