From bf5c2e07a236957ebdd071dba0d8b4f5d9b8db16 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Thu, 27 Sep 2018 23:58:14 +0200 Subject: [PATCH] subroutines cannot use builtin function names for parameters --- compiler/examples/test.p8 | 8 ++++++++ compiler/src/prog8/ast/AstIdentifiersChecker.kt | 3 +++ compiler/src/prog8/compiler/Compiler.kt | 5 ++--- compiler/src/prog8/optimizing/Extensions.kt | 6 +++--- docs/source/syntaxreference.rst | 2 +- prog8lib/c64lib.p8 | 2 +- 6 files changed, 18 insertions(+), 8 deletions(-) diff --git a/compiler/examples/test.p8 b/compiler/examples/test.p8 index 5e840063f..d3c61370f 100644 --- a/compiler/examples/test.p8 +++ b/compiler/examples/test.p8 @@ -1,5 +1,9 @@ %option enable_floats +%import c64lib +%import mathlib +%import prog8lib + ~ main { sub start() -> () { @@ -21,4 +25,8 @@ sub start() -> () { yy = (22.0/v)/11.0 } + +sub printIt(length: XY, control: A) -> (A) { + return 42 ; length / control +} } diff --git a/compiler/src/prog8/ast/AstIdentifiersChecker.kt b/compiler/src/prog8/ast/AstIdentifiersChecker.kt index 84177543e..e5ad0bfb8 100644 --- a/compiler/src/prog8/ast/AstIdentifiersChecker.kt +++ b/compiler/src/prog8/ast/AstIdentifiersChecker.kt @@ -65,6 +65,9 @@ class AstIdentifiersChecker : IAstProcessor { // the builtin functions can't be redefined checkResult.add(NameError("builtin function cannot be redefined", subroutine.position)) } else { + if(subroutine.parameters.any { BuiltinFunctionNames.contains(it.name) }) + checkResult.add(NameError("builtin function name cannot be used as parameter", subroutine.position)) + val scopedName = subroutine.scopedname val existing = symbols[scopedName] if (existing != null) { diff --git a/compiler/src/prog8/compiler/Compiler.kt b/compiler/src/prog8/compiler/Compiler.kt index 0bdca21de..6b295d578 100644 --- a/compiler/src/prog8/compiler/Compiler.kt +++ b/compiler/src/prog8/compiler/Compiler.kt @@ -103,12 +103,11 @@ class Compiler(private val options: CompilationOptions) { // create the pool of all variables used in all blocks and scopes val varGather = VarGatherer(intermediate) varGather.process(module) - println("Number of allocated variables and constants: ${intermediate.numVariables}") + println(" ${intermediate.numVariables} allocated variables and constants") val translator = StatementTranslator(intermediate, namespace) translator.process(module) - println("Number of source statements: ${translator.stmtUniqueSequenceNr}") - println("Number of vm instructions: ${intermediate.numInstructions}") + println(" ${translator.stmtUniqueSequenceNr} source statements, ${intermediate.numInstructions} resulting instructions") return intermediate } diff --git a/compiler/src/prog8/optimizing/Extensions.kt b/compiler/src/prog8/optimizing/Extensions.kt index 7705b768a..1d2461862 100644 --- a/compiler/src/prog8/optimizing/Extensions.kt +++ b/compiler/src/prog8/optimizing/Extensions.kt @@ -22,7 +22,7 @@ fun Module.constantFold(globalNamespace: INameScope) { } while(optimizer.errors.isEmpty() && optimizer.optimizationsDone>0) { - println("[${this.name}] ${optimizer.optimizationsDone} constant folds performed") + println("[${this.name}] Debug: ${optimizer.optimizationsDone} constant folds performed") optimizer.optimizationsDone = 0 this.process(optimizer) } @@ -41,7 +41,7 @@ fun Module.optimizeStatements(globalNamespace: INameScope, allScopedSymbolDefini this.process(optimizer) optimizer.removeUnusedNodes(globalNamespace.usedNames(), allScopedSymbolDefinitions) if(optimizer.optimizationsDone > 0) - println("[${this.name}] ${optimizer.optimizationsDone} statement optimizations performed") + println("[${this.name}] Debug: ${optimizer.optimizationsDone} statement optimizations performed") this.linkParents() // re-link in final configuration return optimizer.optimizationsDone } @@ -50,6 +50,6 @@ fun Module.simplifyExpressions(namespace: INameScope) : Int { val optimizer = SimplifyExpressions(namespace) this.process(optimizer) if(optimizer.optimizationsDone > 0) - println("[${this.name}] ${optimizer.optimizationsDone} expression optimizations performed") + println("[${this.name}] Debug: ${optimizer.optimizationsDone} expression optimizations performed") return optimizer.optimizationsDone } diff --git a/docs/source/syntaxreference.rst b/docs/source/syntaxreference.rst index 635cea7ed..8f623fe4a 100644 --- a/docs/source/syntaxreference.rst +++ b/docs/source/syntaxreference.rst @@ -436,7 +436,7 @@ and not specifying a code block:: .. data:: proc_parameters comma separated list of ":" pairs specifying the input parameters. - You can omit the parameter names as long as the arguments "line up". + You can omit these parameter names in subroutine calls, as long as the arguments "line up". .. data:: proc_results diff --git a/prog8lib/c64lib.p8 b/prog8lib/c64lib.p8 index 556719cef..822b74573 100644 --- a/prog8lib/c64lib.p8 +++ b/prog8lib/c64lib.p8 @@ -142,7 +142,7 @@ sub GIVAYF (lo: Y, hi: A) -> (?) = $b391 sub FREADUY (ubyte: Y) -> (?) = $b3a2 ; 8 bit unsigned Y -> float in fac1 sub FREADSA (sbyte: A) -> (?) = $bc3c ; 8 bit signed A -> float in fac1 -sub FREADSTR (len: A) -> (?) = $b7b5 ; str -> fac1, $22/23 must point to string, A=string length +sub FREADSTR (length: A) -> (?) = $b7b5 ; str -> fac1, $22/23 must point to string, A=string length sub FPRINTLN () -> (?) = $aabc ; print string of fac1, on one line (= with newline) sub FOUT () -> (AY, X?) = $bddd ; fac1 -> string, address returned in AY ($0100)