diff --git a/codeOptimizers/src/prog8/optimizer/StatementOptimizer.kt b/codeOptimizers/src/prog8/optimizer/StatementOptimizer.kt index c1db770d5..71bb3c0fa 100644 --- a/codeOptimizers/src/prog8/optimizer/StatementOptimizer.kt +++ b/codeOptimizers/src/prog8/optimizer/StatementOptimizer.kt @@ -61,7 +61,7 @@ class StatementOptimizer(private val program: Program, } override fun after(functionCallStatement: FunctionCallStatement, parent: Node): Iterable { - if(functionCallStatement.target.targetStatement(program) is BuiltinFunctionPlaceholder) { + if(functionCallStatement.target.nameInSource.size==1) { val functionName = functionCallStatement.target.nameInSource[0] if (functionName in functions.purefunctionNames) { errors.warn("statement has no effect (function return value is discarded)", functionCallStatement.position) diff --git a/compilerAst/src/prog8/ast/statements/AstStatements.kt b/compilerAst/src/prog8/ast/statements/AstStatements.kt index e6660a631..f31969f7c 100644 --- a/compilerAst/src/prog8/ast/statements/AstStatements.kt +++ b/compilerAst/src/prog8/ast/statements/AstStatements.kt @@ -49,6 +49,8 @@ sealed class Statement : Node { } +// this class is only created as temporary result from looking up the target for a builtin function call. +// this node is never actually part of the Ast. class BuiltinFunctionPlaceholder(val name: String, override val position: Position, override var parent: Node) : Statement() { override fun linkParents(parent: Node) {} override fun accept(visitor: IAstVisitor) = throw FatalAstException("should not iterate over this node") diff --git a/compilerAst/src/prog8/ast/walk/AstWalker.kt b/compilerAst/src/prog8/ast/walk/AstWalker.kt index ff31a7825..7c68a791d 100644 --- a/compilerAst/src/prog8/ast/walk/AstWalker.kt +++ b/compilerAst/src/prog8/ast/walk/AstWalker.kt @@ -131,7 +131,6 @@ abstract class AstWalker { open fun after(branch: ConditionalBranch, parent: Node): Iterable = noModifications open fun after(breakStmt: Break, parent: Node): Iterable = noModifications open fun after(containment: ContainmentCheck, parent: Node): Iterable = noModifications - open fun after(builtinFunctionPlaceholder: BuiltinFunctionPlaceholder, parent: Node): Iterable = noModifications open fun after(decl: VarDecl, parent: Node): Iterable = noModifications open fun after(directive: Directive, parent: Node): Iterable = noModifications open fun after(expr: BinaryExpression, parent: Node): Iterable = noModifications diff --git a/docs/source/todo.rst b/docs/source/todo.rst index 10d31a119..d08b1a993 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -5,6 +5,9 @@ For next release ^^^^^^^^^^^^^^^^ - attempt to rework registerArgsViaStackEvaluation() to use tempvars or push()/pop() instead of evalstack based evaluation actually, all function call asmgen code should use the same routine to pass arguments (replaceCallAsmSubStatementWithGosub ?) +- If all regular function calls (both expression + statement) are then replaced by a GoSub node, + the only reason the old FunctionCall[stmt/expression] nodes are still present is because they're for a builtin function call. + -> at this time make those a new Node type for the codegenerator Need help with