Skip to content

[WIP] Implement quit - #1

Open
zormit wants to merge 4 commits into
masterfrom
implement-quit
Open

[WIP] Implement quit#1
zormit wants to merge 4 commits into
masterfrom
implement-quit

Conversation

@zormit

@zormit zormit commented May 19, 2017

Copy link
Copy Markdown
Owner

There has to be an easier way to do this, instead of defining fake-forth words like "interpret-if" which hacks the control flow by modifying the forth instruction pointer.

zormit added 4 commits May 18, 2017 21:36
Parse name and execute it, if it's in the dictionary.
Convert to number and push to stack otherwise.
scanf only reads until next space? weird.
Comment thread forth.asm
cmp byte [esi], 0x0 ;end of string?
cmp byte [esi], 0x0 ;end of searchstring?
jnz .findcmploop
cmp byte [edi], 0x0 ;end of found string?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a more concise way to make sure both strings are ending on 0?
I tried something like

mov cl, byte [esi]
and cl, byte [edi]

which failed, I forgot in which way.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That will fail if the bits in the two bytes are disjoint. e.g 01010101 and 10101010. The and cl, cl trick only works if it is the exact same value. In this case, without seeing the surrounding code, I think this might be your best option.

Comment thread forth.asm
dd blank
dd cword
dd find
dd interpret_if

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think now it snaps back to me, that I was to "lazy" to distinguish between words used in assembly and words executed by the interpreter. Or is there something else I can do?

@anjakefala anjakefala May 19, 2017

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you considered all-capsing the names of the forth operator words?

DROP:       ;( a -- )
    pop     eax
    jmp     next

....

dd DROP

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion. I think that would be confusing though, because the labels are not the actual forth words. For example blank will be BL in forth, or star is *.

Maybe I phrased it confusing, because I'm not even sure what I am looking for.
Basically I would like to have something like this, i.e. inline the interpret_if:

    dd      blank
    dd      cword
    dd      find
    pop     eax
    test    eax, eax
    jnz     .execute
    dd     tonumber
    dd     exit
.execute:
    dd     execute
    dd     exit

which is of course not possible. I might have to look at other implementations how they did it. I think there must be something like an "internal next".

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider making that inline assembly code into a proper word. Perhaps it would consume a stack element, and if the stack element is non-zero, it adds some number to the Forth PC.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is what I did already, see above. Seems to be the right way then... Modifying the Forth PC felt too hacky to me. But that's what I am always saying... Forth is so hacky... How does it even work properly? :P

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the number added to PC was not hard-coded, perhaps it might be the next cell in the instruction stream? Maybe you could call this word something like ?BRANCH or BRANCHNZ.

Comment thread forth.asm
; 3. `INTERPRET` the input buffer until empty.
dd interpret
dd interpret_again
; reset input buffer

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the following is incomplete and in the wrong place anyway.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants