mirror of
https://github.com/irmen/prog8.git
synced 2025-01-11 13:29:45 +00:00
added warning about sgn() of unsigned type
This commit is contained in:
parent
d28dd92b47
commit
a326ffa00a
@ -814,6 +814,14 @@ internal class AstChecker(private val program: Program,
|
||||
val targetStatement = checkFunctionOrLabelExists(functionCall.target, stmtOfExpression)
|
||||
if(targetStatement!=null)
|
||||
checkFunctionCall(targetStatement, functionCall.args, functionCall.position)
|
||||
|
||||
// warn about sgn(unsigned) this is likely a mistake
|
||||
if(functionCall.target.nameInSource.last()=="sgn") {
|
||||
val sgnArgType = functionCall.args.first().inferType(program)
|
||||
if(sgnArgType.istype(DataType.UBYTE) || sgnArgType.istype(DataType.UWORD))
|
||||
printWarning("sgn() of unsigned type is always 0 or 1, this is perhaps not what was intended", functionCall.args.first().position)
|
||||
}
|
||||
|
||||
super.visit(functionCall)
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,9 @@
|
||||
TODO
|
||||
====
|
||||
|
||||
- remove statements after an exit() or return
|
||||
- fix warnings about that unreachable code?
|
||||
|
||||
- option to load library files from a directory instead of the embedded ones
|
||||
|
||||
|
||||
|
130
examples/arithmetic/sgn.p8
Normal file
130
examples/arithmetic/sgn.p8
Normal file
@ -0,0 +1,130 @@
|
||||
%import c64flt
|
||||
%zeropage basicsafe
|
||||
|
||||
main {
|
||||
|
||||
sub start() {
|
||||
byte b1
|
||||
byte b2
|
||||
ubyte ub1
|
||||
ubyte ub2
|
||||
word w1
|
||||
word w2
|
||||
uword uw1
|
||||
uword uw2
|
||||
float f1
|
||||
float f2
|
||||
|
||||
b1 = 10
|
||||
b2 = 10
|
||||
if sgn(b2-b1) != 0
|
||||
c64scr.print("sgn1 error1\n")
|
||||
|
||||
b1 = -100
|
||||
b2 = -100
|
||||
if sgn(b2-b1) != 0
|
||||
c64scr.print("sgn1 error2\n")
|
||||
|
||||
ub1 = 200
|
||||
ub2 = 200
|
||||
if sgn(ub2-ub1) != 0
|
||||
c64scr.print("sgn1 error3\n")
|
||||
|
||||
w1 = 100
|
||||
w2 = 100
|
||||
if sgn(w2-w1) != 0
|
||||
c64scr.print("sgn1 error4\n")
|
||||
|
||||
w1 = -2000
|
||||
w2 = -2000
|
||||
if sgn(w2-w1) != 0
|
||||
c64scr.print("sgn1 error5\n")
|
||||
|
||||
uw1 = 999
|
||||
uw2 = 999
|
||||
if sgn(uw2-uw1) != 0
|
||||
c64scr.print("sgn1 error6\n")
|
||||
|
||||
f1 = 3.45
|
||||
f2 = 3.45
|
||||
if sgn(f2-f1) != 0
|
||||
c64scr.print("sgn1 error7\n")
|
||||
|
||||
|
||||
; -1
|
||||
b1 = 11
|
||||
b2 = 10
|
||||
if sgn(b2-b1) != -1
|
||||
c64scr.print("sgn2 error1\n")
|
||||
|
||||
b1 = -10
|
||||
b2 = -100
|
||||
if sgn(b2-b1) != -1
|
||||
c64scr.print("sgn2 error2\n")
|
||||
|
||||
ub1 = 202
|
||||
ub2 = 200
|
||||
if sgn(ub2 as byte - ub1 as byte) != -1
|
||||
c64scr.print("sgn2 error3\n")
|
||||
|
||||
w1 = 101
|
||||
w2 = 100
|
||||
if sgn(w2-w1) != -1
|
||||
c64scr.print("sgn2 error4\n")
|
||||
|
||||
w1 = -200
|
||||
w2 = -2000
|
||||
if sgn(w2-w1) != -1
|
||||
c64scr.print("sgn2 error5\n")
|
||||
|
||||
uw1 = 2222
|
||||
uw2 = 999
|
||||
if sgn(uw2 as word - uw1 as word) != -1
|
||||
c64scr.print("sgn2 error6\n")
|
||||
if sgn(uw2 - uw1) != -1
|
||||
c64scr.print("sgn2 error6\n")
|
||||
|
||||
f1 = 3.45
|
||||
f2 = 1.11
|
||||
if sgn(f2-f1) != -1
|
||||
c64scr.print("sgn2 error7\n")
|
||||
|
||||
; +1
|
||||
b1 = 11
|
||||
b2 = 20
|
||||
if sgn(b2-b1) != 1
|
||||
c64scr.print("sgn3 error1\n")
|
||||
|
||||
b1 = -10
|
||||
b2 = -1
|
||||
if sgn(b2-b1) != 1
|
||||
c64scr.print("sgn3 error2\n")
|
||||
|
||||
ub1 = 202
|
||||
ub2 = 205
|
||||
if sgn(ub2-ub1) != 1
|
||||
c64scr.print("sgn3 error3\n")
|
||||
|
||||
w1 = 101
|
||||
w2 = 200
|
||||
if sgn(w2-w1) != 1
|
||||
c64scr.print("sgn3 error4\n")
|
||||
|
||||
w1 = -200
|
||||
w2 = -20
|
||||
if sgn(w2-w1) != 1
|
||||
c64scr.print("sgn3 error5\n")
|
||||
|
||||
uw1 = 2222
|
||||
uw2 = 9999
|
||||
if sgn(uw2-uw1) != 1
|
||||
c64scr.print("sgn3 error6\n")
|
||||
|
||||
f1 = 3.45
|
||||
f2 = 5.11
|
||||
if sgn(f2-f1) != 1
|
||||
c64scr.print("sgn3 error7\n")
|
||||
|
||||
c64scr.print("should see no sgn errors\n")
|
||||
}
|
||||
}
|
@ -14,6 +14,11 @@ main {
|
||||
for r in 3 to 12 step 3 {
|
||||
circle(r)
|
||||
}
|
||||
line(5,3, 30,3)
|
||||
line(5,3, 5, 24)
|
||||
line(30,3,30,24)
|
||||
line(5,24,30,24)
|
||||
|
||||
line(1, 10, 38, 24)
|
||||
line(1, 20, 38, 2)
|
||||
line(20, 4, 10, 24)
|
||||
@ -27,23 +32,11 @@ main {
|
||||
ubyte dy = abs(y2 - y1)
|
||||
ubyte dx2 = 2 * dx
|
||||
ubyte dy2 = 2 * dy
|
||||
byte ix = sgn(x2-x1)
|
||||
byte iy = sgn(y2-y1)
|
||||
byte ix = sgn(x2 as byte - x1 as byte)
|
||||
byte iy = sgn(y2 as byte - y1 as byte)
|
||||
ubyte x = x1
|
||||
ubyte y = y1
|
||||
|
||||
; TODO fix sgn
|
||||
if x1<x2
|
||||
ix=1
|
||||
else
|
||||
ix=-1
|
||||
|
||||
; TODO fix sgn
|
||||
if y1<y2
|
||||
iy=1
|
||||
else
|
||||
iy=-1
|
||||
|
||||
if dx >= dy {
|
||||
; TODO fix assembler problem when defining label here
|
||||
forever {
|
@ -1,4 +1,3 @@
|
||||
%import c64flt
|
||||
%zeropage basicsafe
|
||||
|
||||
main {
|
||||
|
Loading…
x
Reference in New Issue
Block a user