mirror of
https://github.com/irmen/prog8.git
synced 2024-10-07 15:57:03 +00:00
swap syntax checks
This commit is contained in:
parent
39a5e341af
commit
fab5e4b17f
@ -5,6 +5,7 @@ import prog8.compiler.HeapValues
|
||||
import prog8.compiler.target.c64.FLOAT_MAX_NEGATIVE
|
||||
import prog8.compiler.target.c64.FLOAT_MAX_POSITIVE
|
||||
import prog8.functions.BuiltinFunctions
|
||||
import prog8.optimizing.same
|
||||
import prog8.parser.ParsingFailedError
|
||||
|
||||
/**
|
||||
@ -788,6 +789,19 @@ class AstChecker(private val namespace: INameScope,
|
||||
checkResult.add(ExpressionError("builtin function argument ${arg.first.index + 1} has invalid type $argDt, expected ${arg.second.possibleDatatypes}", position))
|
||||
}
|
||||
}
|
||||
if(target.name=="swap") {
|
||||
// swap() is a bit weird because this one is translated into a sequence of bytecodes, instead of being an actual function call
|
||||
val dt1 = args[0].resultingDatatype(namespace, heap)!!
|
||||
val dt2 = args[1].resultingDatatype(namespace, heap)!!
|
||||
if (dt1 != dt2)
|
||||
checkResult.add(ExpressionError("swap requires 2 args of identical type", position))
|
||||
else if (args[0].constValue(namespace, heap) != null || args[1].constValue(namespace, heap) != null)
|
||||
checkResult.add(ExpressionError("swap requires 2 variables, not constant value(s)", position))
|
||||
else if(same(args[0], args[1]))
|
||||
checkResult.add(ExpressionError("swap should have 2 different args", position))
|
||||
else if(dt1 !in NumericDatatypes)
|
||||
checkResult.add(ExpressionError("swap requires args of numerical type", position))
|
||||
}
|
||||
}
|
||||
} else if(target is Subroutine) {
|
||||
if(args.size!=target.parameters.size)
|
||||
|
@ -988,7 +988,6 @@ private class StatementTranslator(private val prog: IntermediateProgram,
|
||||
throw AstException("swap should have 2 different args")
|
||||
if(dt1 !in NumericDatatypes)
|
||||
throw AstException("swap requires args of numerical type")
|
||||
// @todo implement these errors as nice AstChecker expression errors.
|
||||
|
||||
translate(args[0])
|
||||
translate(args[1])
|
||||
|
118
examples/test.p8
118
examples/test.p8
@ -1,5 +1,5 @@
|
||||
%import c64lib
|
||||
|
||||
%option enable_floats
|
||||
|
||||
~ main {
|
||||
|
||||
@ -27,120 +27,8 @@
|
||||
byte[3] ba2
|
||||
uword[3] uwa2
|
||||
word[3] wa2
|
||||
|
||||
|
||||
A=$34
|
||||
Y=$34
|
||||
ub1=$33
|
||||
ub1=$34
|
||||
ub2=1
|
||||
ub2=2
|
||||
ub2=3
|
||||
ub2=4
|
||||
ub2=$34
|
||||
uw1=0
|
||||
uw1=1
|
||||
uw1=$0034
|
||||
w1=1
|
||||
w1=2
|
||||
w1=3
|
||||
w1=$0034
|
||||
|
||||
|
||||
if A>5 {
|
||||
A=$34
|
||||
Y=$34
|
||||
ub1=$33
|
||||
ub1=$34
|
||||
ub2=1
|
||||
ub2=2
|
||||
ub2=3
|
||||
ub2=4
|
||||
ub2=$34
|
||||
uw1=0
|
||||
uw1=1
|
||||
uw1=$0034
|
||||
w1=1
|
||||
w1=2
|
||||
w1=3
|
||||
w1=$0034
|
||||
|
||||
} else {
|
||||
A=$34
|
||||
Y=$34
|
||||
ub1=$33
|
||||
ub1=$34
|
||||
ub2=1
|
||||
ub2=2
|
||||
ub2=3
|
||||
ub2=4
|
||||
ub2=$34
|
||||
uw1=0
|
||||
uw1=1
|
||||
uw1=$0034
|
||||
w1=1
|
||||
w1=2
|
||||
w1=3
|
||||
w1=$0034
|
||||
|
||||
}
|
||||
|
||||
while(true) {
|
||||
A=$34
|
||||
Y=$34
|
||||
ub1=$33
|
||||
ub1=$34
|
||||
ub2=1
|
||||
ub2=2
|
||||
ub2=3
|
||||
ub2=4
|
||||
ub2=$34
|
||||
uw1=0
|
||||
uw1=1
|
||||
uw1=$0034
|
||||
w1=1
|
||||
w1=2
|
||||
w1=3
|
||||
w1=$0034
|
||||
|
||||
}
|
||||
|
||||
repeat {
|
||||
A=$34
|
||||
Y=$34
|
||||
ub1=$33
|
||||
ub1=$34
|
||||
ub2=1
|
||||
ub2=2
|
||||
ub2=3
|
||||
ub2=4
|
||||
ub2=$34
|
||||
uw1=0
|
||||
uw1=1
|
||||
uw1=$0034
|
||||
w1=1
|
||||
w1=2
|
||||
w1=3
|
||||
w1=$0034
|
||||
|
||||
} until(true)
|
||||
|
||||
A=$34
|
||||
Y=$34
|
||||
ub1=$33
|
||||
ub1=$34
|
||||
ub2=1
|
||||
ub2=2
|
||||
ub2=3
|
||||
ub2=4
|
||||
ub2=$34
|
||||
uw1=0
|
||||
uw1=1
|
||||
uw1=$0034
|
||||
w1=1
|
||||
w1=2
|
||||
w1=3
|
||||
w1=$0034
|
||||
str hoi = "hoi"
|
||||
str hoi2 = "hoi2"
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user