subroutines cannot use builtin function names for parameters

This commit is contained in:
Irmen de Jong 2018-09-27 23:58:14 +02:00
parent 91f9229b07
commit bf5c2e07a2
6 changed files with 18 additions and 8 deletions

View File

@ -1,5 +1,9 @@
%option enable_floats %option enable_floats
%import c64lib
%import mathlib
%import prog8lib
~ main { ~ main {
sub start() -> () { sub start() -> () {
@ -21,4 +25,8 @@ sub start() -> () {
yy = (22.0/v)/11.0 yy = (22.0/v)/11.0
} }
sub printIt(length: XY, control: A) -> (A) {
return 42 ; length / control
}
} }

View File

@ -65,6 +65,9 @@ class AstIdentifiersChecker : IAstProcessor {
// the builtin functions can't be redefined // the builtin functions can't be redefined
checkResult.add(NameError("builtin function cannot be redefined", subroutine.position)) checkResult.add(NameError("builtin function cannot be redefined", subroutine.position))
} else { } 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 scopedName = subroutine.scopedname
val existing = symbols[scopedName] val existing = symbols[scopedName]
if (existing != null) { if (existing != null) {

View File

@ -103,12 +103,11 @@ class Compiler(private val options: CompilationOptions) {
// create the pool of all variables used in all blocks and scopes // create the pool of all variables used in all blocks and scopes
val varGather = VarGatherer(intermediate) val varGather = VarGatherer(intermediate)
varGather.process(module) varGather.process(module)
println("Number of allocated variables and constants: ${intermediate.numVariables}") println(" ${intermediate.numVariables} allocated variables and constants")
val translator = StatementTranslator(intermediate, namespace) val translator = StatementTranslator(intermediate, namespace)
translator.process(module) translator.process(module)
println("Number of source statements: ${translator.stmtUniqueSequenceNr}") println(" ${translator.stmtUniqueSequenceNr} source statements, ${intermediate.numInstructions} resulting instructions")
println("Number of vm instructions: ${intermediate.numInstructions}")
return intermediate return intermediate
} }

View File

@ -22,7 +22,7 @@ fun Module.constantFold(globalNamespace: INameScope) {
} }
while(optimizer.errors.isEmpty() && optimizer.optimizationsDone>0) { 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 optimizer.optimizationsDone = 0
this.process(optimizer) this.process(optimizer)
} }
@ -41,7 +41,7 @@ fun Module.optimizeStatements(globalNamespace: INameScope, allScopedSymbolDefini
this.process(optimizer) this.process(optimizer)
optimizer.removeUnusedNodes(globalNamespace.usedNames(), allScopedSymbolDefinitions) optimizer.removeUnusedNodes(globalNamespace.usedNames(), allScopedSymbolDefinitions)
if(optimizer.optimizationsDone > 0) 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 this.linkParents() // re-link in final configuration
return optimizer.optimizationsDone return optimizer.optimizationsDone
} }
@ -50,6 +50,6 @@ fun Module.simplifyExpressions(namespace: INameScope) : Int {
val optimizer = SimplifyExpressions(namespace) val optimizer = SimplifyExpressions(namespace)
this.process(optimizer) this.process(optimizer)
if(optimizer.optimizationsDone > 0) if(optimizer.optimizationsDone > 0)
println("[${this.name}] ${optimizer.optimizationsDone} expression optimizations performed") println("[${this.name}] Debug: ${optimizer.optimizationsDone} expression optimizations performed")
return optimizer.optimizationsDone return optimizer.optimizationsDone
} }

View File

@ -436,7 +436,7 @@ and not specifying a code block::
.. data:: proc_parameters .. data:: proc_parameters
comma separated list of "<parametername>:<register>" pairs specifying the input parameters. comma separated list of "<parametername>:<register>" 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 .. data:: proc_results

View File

@ -142,7 +142,7 @@ sub GIVAYF (lo: Y, hi: A) -> (?) = $b391
sub FREADUY (ubyte: Y) -> (?) = $b3a2 ; 8 bit unsigned Y -> float in fac1 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 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 FPRINTLN () -> (?) = $aabc ; print string of fac1, on one line (= with newline)
sub FOUT () -> (AY, X?) = $bddd ; fac1 -> string, address returned in AY ($0100) sub FOUT () -> (AY, X?) = $bddd ; fac1 -> string, address returned in AY ($0100)