mirror of
https://github.com/irmen/prog8.git
synced 2024-11-29 17:50:35 +00:00
subroutines cannot use builtin function names for parameters
This commit is contained in:
parent
91f9229b07
commit
bf5c2e07a2
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -436,7 +436,7 @@ and not specifying a code block::
|
||||
.. data:: proc_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
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user