prog8 icon indicating copy to clipboard operation
prog8 copied to clipboard

string.find is not working

Open AtomiJD opened this issue 1 year ago • 4 comments

Target cx16, Version:Prog8 compiler v10.3 string.find not working correct, here the compiled asm source for: flag, pos = string.find(consts.DELIMETERCHAR, @(prgptr)) is compiled to:

ldy  #>p8b_consts.p8v_DELIMETERCHAR
lda  #<p8b_consts.p8v_DELIMETERCHAR
lda  (p8b_main.p8v_prgptr)
tax
jsr  string.find

But it should be

lda  (p8b_main.p8v_prgptr)
tax
ldy  #>p8b_consts.p8v_DELIMETERCHAR
lda  #<p8b_consts.p8v_DELIMETERCHAR
jsr  string.find

AtomiJD avatar May 12 '24 09:05 AtomiJD

interesting, a register order problem. I'll have a look when I get back from my coding pause. You may be able to work around it by assigning one or both of the arguments of the function call to an intermedate variable or maybe cx16.Rx register.

However, in the meantime, I also have a question: is the code you posted supposed to be actual code? If so, what should it do? It suggests a problem in the meaning of the arguments.

irmen avatar May 12 '24 13:05 irmen

Thanks for the response. The code is parsing a command /program line and is looking for delimiter char; str DELIMITERCHAR = " =,;#()]*/-+%&><" where: @(prgptr) is the actual value of the position of the prg/line pointer As workaround I'm using: flag = string.contains(consts.DELIMITERCHAR, @(prgptr))

AtomiJD avatar May 13 '24 05:05 AtomiJD

You could also just write if character in stringvar .

irmen avatar May 13 '24 12:05 irmen

For my own reference: problem is inside argumentsViaRegisters() routine

irmen avatar May 18 '24 14:05 irmen

Note that a fix for this will probably take me a while as I need a summer break ^_^

irmen avatar May 31 '24 19:05 irmen

A workaround that avoids the problem was quite easy to make and is now implemented, but it could be improved a lot especially on 6502 CPU targets (it can cause a lot of stack juggling now). This is an optimization that has to wait till later.

irmen avatar Jul 02 '24 21:07 irmen