Boriel Basic Forum
type problem (*solved*) - Printable Version

+- Boriel Basic Forum (https://forum.boriel.com)
+-- Forum: Compilers and Computer Languages (https://forum.boriel.com/forumdisplay.php?fid=12)
+--- Forum: ZX Basic Compiler (https://forum.boriel.com/forumdisplay.php?fid=11)
+---- Forum: Bug Reports (https://forum.boriel.com/forumdisplay.php?fid=15)
+---- Thread: type problem (*solved*) (/showthread.php?tid=423)



type problem (*solved*) - slenkar - 2012-02-14

Code:
Function distance (x1 as Integer, y1 as Integer, x2 as Integer, y2 as Integer) as Integer Dim x as Integer x=Abs(x1-x2) Dim y as Integer y=Abs(y1-y2) Return x+y End Function Dim bresx(0 to 300) as UByte Dim bresy(0 to 300) as UByte Function line(X1 as Integer,Y1 as Integer,X2 as Integer,Y2 as Integer) as Integer 'Draws a line of individual pixels from X1,Y1 to X2,Y2 at any angle Dim dist as Integer dist=distance(X1,Y1,X2,Y2) dim bresiter as Integer For bresiter=0 To dist bresx(bresiter)=0 bresy(bresiter)=0 Next Dim steep as Byte steep=Abs(Y2-Y1) > Abs(X2-X1) PRINT AT 1,1 ; PAPER 1 ; INK 0 ; "steep "+STR(steep) If steep =1 Then Dim Temp as Integer steep=X1 X1=Y1 Y1=Temp Temp=X2 X2=Y2 Y2=Temp End If Dim DeltaX as Integer DeltaX=Abs(X2-X1) Dim DeltaY as Integer DeltaY=Abs(Y2-Y1) Dim IError as Integer IError=0 Dim DeltaError as Integer DeltaError=DeltaY Dim x as Integer x=X1 'Start at X1,Y1 Dim y as Integer y=Y1 Dim XStep as Integer Dim YStep as Integer If X1<X2 Then XStep=1 Else XStep=-1 end if If Y1<Y2 Then YStep=1 Else YStep=-1 'Direction end if 'If Steep Then Plot(Y,X) Else Plot(X,Y) 'Draw Dim iter as Integer=1 While x<>X2 'Print x+" <x "+X2+"<x2" 'Print "xstep "+XStep 'x=truncate(x,1) x=x+XStep 'Move in X 'Print x+" <x after adding xstep "+X2+"<x2" IError=IError+DeltaError 'Add to counter If (IError Shl 1)>DeltaX then 'Would it overflow? y=y+YStep 'Move in Y IError=IError-DeltaX 'Overflow/wrap the counter End if ' x=truncate(x,1) ' y=truncate(y,1) ' Print x+" <x after truncating xstep "+X2+"<x2" If steep then bresx(iter)=y ' Print bresx[iter]+"<bresx iter>"+iter bresy(iter)=x ' Print bresy[iter]+"<bresy iter>"+iter Else bresx(iter)=x ' Print bresx[iter]+"<bresx iter>"+iter bresy(iter)=y ' Print bresy[iter]+"<bresy iter>"+iter End If iter=iter+1 If iter>dist then Print "bresenham over distance "+dist Return dist End If ' If Steep Then Plot(Y,X) Else Plot(X,Y) 'Draw Wend Return dist End Function line(0,0,10,5) for x=0 to 6 Plot bresx(x),bresy(x) next

When I try to compile it says cant convert to string on line 16 but there are no strings being referred to on that line

EDIT- the problem was on line 107 so the compiler was confused


Re: type problem - boriel - 2012-02-14

Will try to debug ASAP.
NOTE: I'm alive. Just considering rewriting al ZX BASIC *from scratch* Confusedhock:


Re: type problem - slenkar - 2012-02-14

Confusedhock: Confusedhock:


Re: type problem - britlion - 2012-02-15

Confusedhock: Confusedhock: Confusedhock:


Re: type problem - boriel - 2012-02-15

Okay, not from scratch (the lexers modules and preprocessor, and assembler are ok), but almost.
It's a huge rewriting... :oops:


Re: type problem - slenkar - 2012-02-15

in python?


Re: type problem - boriel - 2012-02-15

Yes: If it weren't in python it would be completely from scratch (even the lexer, asm and preprocessors). I guess I would choose C++ otherwise.


Re: type problem - boriel - 2012-02-18

Yes, the bug was in line:
Code:
Print "bresenham over distance "+dist
Variable dist is integer (use STR(dist) for that). It's incorrectly reporting line #15 (where Dist was declared!) instead of that line.
Will try to improve this...


Re: type problem - boriel - 2012-02-18

britlion Wrote:Confusedhock: Confusedhock: Confusedhock:
I also asked about revamping the site into something more specific to ZX Basic, instead of my blog. :?:
(See Poll in the main forum)


Re: type problem - LCD - 2012-02-18

boriel Wrote:Yes, the bug was in line:
Code:
Print "bresenham over distance "+dist
Variable dist is integer (use STR(dist) for that). It's incorrectly reporting line #15 (where Dist was declared!) instead of that line.
Will try to improve this...
Sounds logical because dist could be DIMed as String, so the compiler is confused.


Re: type problem - boriel - 2012-02-21

The error reporting line is now correct.
Can you check it? (download 1.2.8 s785 or newer)