[WIP] Implement quit - #1
Conversation
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.
| cmp byte [esi], 0x0 ;end of string? | ||
| cmp byte [esi], 0x0 ;end of searchstring? | ||
| jnz .findcmploop | ||
| cmp byte [edi], 0x0 ;end of found string? |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| dd blank | ||
| dd cword | ||
| dd find | ||
| dd interpret_if |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Have you considered all-capsing the names of the forth operator words?
DROP: ;( a -- )
pop eax
jmp next
....
dd DROP
There was a problem hiding this comment.
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".
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
| ; 3. `INTERPRET` the input buffer until empty. | ||
| dd interpret | ||
| dd interpret_again | ||
| ; reset input buffer |
There was a problem hiding this comment.
the following is incomplete and in the wrong place anyway.
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.