mirror of
https://github.com/irmen/prog8.git
synced 2024-09-10 09:54:32 +00:00
add sideEffects boolean to PtBuiltinFunctionCall
This commit is contained in:
parent
e2e951efdf
commit
a01aee3111
@ -38,7 +38,11 @@ class PtArray(type: DataType, position: Position): PtExpression(type, position)
|
||||
}
|
||||
|
||||
|
||||
class PtBuiltinFunctionCall(val name: String, val void: Boolean, type: DataType, position: Position) : PtExpression(type, position) {
|
||||
class PtBuiltinFunctionCall(val name: String,
|
||||
val void: Boolean,
|
||||
val hasNoSideEffects: Boolean,
|
||||
type: DataType,
|
||||
position: Position) : PtExpression(type, position) {
|
||||
init {
|
||||
if(!void)
|
||||
require(type!=DataType.UNDEFINED)
|
||||
@ -47,7 +51,7 @@ class PtBuiltinFunctionCall(val name: String, val void: Boolean, type: DataType,
|
||||
val args: List<PtExpression>
|
||||
get() = children.map { it as PtExpression }
|
||||
override fun printProperties() {
|
||||
print("$name void=$void")
|
||||
print("$name void=$void noSideFx=$hasNoSideEffects")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -77,7 +77,7 @@ internal class ExpressionGen(private val codeGen: CodeGen) {
|
||||
segWithArg
|
||||
}
|
||||
is PtBuiltinFunctionCall -> {
|
||||
val segWithArg = PtBuiltinFunctionCall(segment.name, segment.void, segment.type, segment.position)
|
||||
val segWithArg = PtBuiltinFunctionCall(segment.name, segment.void, segment.hasNoSideEffects, segment.type, segment.position)
|
||||
segWithArg.children.add(0, PtIdentifier(listOf(":vmreg-$sourceReg"), listOf(":vmreg-$sourceReg"), sourceDt, segment.position))
|
||||
segWithArg
|
||||
}
|
||||
|
@ -149,7 +149,8 @@ class IntermediateAstMaker(val program: Program) {
|
||||
|
||||
private fun transform(srcNode: BuiltinFunctionCallStatement): PtBuiltinFunctionCall {
|
||||
val type = builtinFunctionReturnType(srcNode.name, srcNode.args, program).getOr(DataType.UNDEFINED)
|
||||
val call = PtBuiltinFunctionCall(srcNode.name, true, type, srcNode.position)
|
||||
val noSideFx = BuiltinFunctions.getValue(srcNode.name).pure
|
||||
val call = PtBuiltinFunctionCall(srcNode.name, true, noSideFx, type, srcNode.position)
|
||||
for (arg in srcNode.args)
|
||||
call.add(transformExpression(arg))
|
||||
return call
|
||||
@ -436,7 +437,8 @@ class IntermediateAstMaker(val program: Program) {
|
||||
|
||||
private fun transform(srcCall: BuiltinFunctionCall): PtBuiltinFunctionCall {
|
||||
val type = srcCall.inferType(program).getOrElse { throw FatalAstException("unknown dt") }
|
||||
val call = PtBuiltinFunctionCall(srcCall.name, false, type, srcCall.position)
|
||||
val noSideFx = BuiltinFunctions.getValue(srcCall.name).pure
|
||||
val call = PtBuiltinFunctionCall(srcCall.name, false, noSideFx, type, srcCall.position)
|
||||
for (arg in srcCall.args)
|
||||
call.add(transformExpression(arg))
|
||||
return call
|
||||
|
Loading…
Reference in New Issue
Block a user