Euphoria
Ticket #503:
in translated program sometimes length of sequence result in erronous value
-
Reported by
coconut
Dec 05, 2010
here a procedure that fail only when the program is translated.
I added "? {segment, length(segment)}" for debuging help.
procedure DisplayLine(atom hdc, -- display context
integer ln_idx,-- index of line in Buffer
integer y, -- vertical position of line on screen
integer Color)-- Boolean indicator for colorization
sequence c_seg, segment
integer ok, cx, p,s, ls
sequence line=Buffer[ln_idx]
sequence co_state
puts(1,line&'\n')
if length(line) = 0 or length(line) < scol then
return
end if
if Color and EuFile then
if ln_idx>1 then
co_state=ColorStateBuffer[ln_idx-1]
else
co_state={}
end if
c_seg=GetColoredSegments(line,co_state)
ColorStateBuffer[ln_idx]=c_seg[2]
c_seg=c_seg[1]
ls = length(c_seg)
cx = 0
p = 1
while c_seg[p][2] < scol do
p = p + 1
if p > ls then
return
end if
end while
segment = line[max(scol,c_seg[p][1])..c_seg[p][2]] ? {segment,length(segment)}
TextOutColored(hdc,cx,y,segment,c_seg[p][3])
for i = p + 1 to ls do
cx = cx + length(segment)*cxChar
segment = line[c_seg[i][1]..c_seg[i][2]]
TextOutColored(hdc,cx,y,segment,c_seg[i][3])
if cx > cxEdit then
exit
end if
end for
else
TextOut(hdc,0,y,TrimLine(line))
end if
end procedure -- DisplayLine()
when the program is translated length(segment) report 1 whatever the length of segment.
The good length is reported when the program is execute with eui.
Details
1. Comment by coconut
Dec 05, 2010
platform windows 7 64 bits
2. Comment by jimcbrown
Dec 06, 2010
I can not reproduce your problem on Linux/GNU:
Euphoria to C Translator 4.0.0 development (r4525M) for Linux
Your example is incomplete and does not work. Here is the code I came up with to make your example run.
sequence Buffer=repeat(repeat('0', 100), 2)
integer scol = 1
constant Color = 1, EuFile = 1
sequence ColorStateBuffer={"2","2"}
integer cxEdit = 3, cxChar = 1
function max(object x, object y)
if compare(x, y) > 0 then
return x
else
return y
end if
end function
function GetColoredSegments(object x, object y)
return {{"222","222","222"},{"222","222","222"},{"222","222","222"}}
end function
procedure TextOutColored(object a, object b, object c, object d, object e)
end procedure
procedure TextOut(object a, object b, object c, object d)
end procedure
function TrimLine(object d)
return d
end function
procedure DisplayLine(atom hdc, -- display context
integer ln_idx,-- index of line in Buffer
integer y, -- vertical position of line on screen
integer Color)-- Boolean indicator for colorization
sequence c_seg, segment
integer ok, cx, p,s, ls
sequence line=Buffer[ln_idx]
sequence co_state
puts(1,line&'\n')
if length(line) = 0 or length(line) < scol then
return
end if
if Color and EuFile then
if ln_idx>1 then
co_state=ColorStateBuffer[ln_idx-1]
else
co_state={}
end if
c_seg=GetColoredSegments(line,co_state)
ColorStateBuffer[ln_idx]=c_seg[2]
c_seg=c_seg[1]
ls = length(c_seg)
cx = 0
p = 1
while c_seg[p][2] < scol do
p = p + 1
if p > ls then
return
end if
end while
segment = line[max(scol,c_seg[p][1])..c_seg[p][2]] ? {segment,length(segment)}
TextOutColored(hdc,cx,y,segment,c_seg[p][3])
for i = p + 1 to ls do
cx = cx + length(segment)*cxChar
segment = line[c_seg[i][1]..c_seg[i][2]]
TextOutColored(hdc,cx,y,segment,c_seg[i][3])
if cx > cxEdit then
exit
end if
end for
else
TextOut(hdc,0,y,TrimLine(line))
end if
end procedure -- DisplayLine()
DisplayLine(0, 2, 1, 1)
3. Comment by mattlewis
Dec 06, 2010
coconut: please run the eudist program (distrubuted with RC1) on your code, so we can get all of your infomation. Also, please paste in the translated code that you get for that line.
4. Comment by mattlewis
Dec 07, 2010
Temp values weren't being correctly tracked when they were objects, leading to incorrect translated code.
Waiting for coconut to confirm.
5. Comment by jimcbrown
Dec 08, 2010
Closing out as RC2 has been released. If this is not fixed, please reopen and we'll update the milestone to 4.0.0 (or RC3, whichever is relevant).