mirror of
https://github.com/irmen/prog8.git
synced 2024-11-23 22:33:12 +00:00
tweaks for string handling as arguments
This commit is contained in:
parent
9735527062
commit
1c16bbb742
@ -304,9 +304,9 @@ internal class AstChecker(private val program: Program,
|
||||
} else {
|
||||
// Pass-by-reference datatypes can not occur as parameters to a subroutine directly
|
||||
// Instead, their reference (address) should be passed (as an UWORD).
|
||||
// The language has no typed pointers at this time.
|
||||
// TODO The language has no typed pointers at this time! This should be handled better.
|
||||
if(subroutine.parameters.any{it.type in PassByReferenceDatatypes }) {
|
||||
err("Pass-by-reference types (str, array) cannot occur as a parameter type directly. Instead, use an uword for their address, or access the variable from the outer scope directly.")
|
||||
err("Pass-by-reference types (str, array) cannot occur as a parameter type directly. Instead, use an uword to receive their address, or access the variable from the outer scope directly.")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1048,6 +1048,9 @@ $endLabel""")
|
||||
fun assignFromWordVariable(target: AssignTarget, variable: IdentifierReference) =
|
||||
assignmentAsmGen.assignFromWordVariable(target, variable)
|
||||
|
||||
fun assignFromAddressOf(target: AssignTarget, variable: IdentifierReference) =
|
||||
assignmentAsmGen.assignFromAddressOf(target, variable)
|
||||
|
||||
fun assignFromFloatVariable(target: AssignTarget, variable: IdentifierReference) =
|
||||
assignmentAsmGen.assignFromFloatVariable(target, variable)
|
||||
|
||||
|
@ -115,7 +115,6 @@ internal class FunctionCallAsmGen(private val program: Program, private val asmg
|
||||
in ByteDatatypes -> asmgen.assignFromByteConstant(target, value.number.toShort())
|
||||
in WordDatatypes -> asmgen.assignFromWordConstant(target, value.number.toInt())
|
||||
DataType.FLOAT -> asmgen.assignFromFloatConstant(target, value.number.toDouble())
|
||||
in PassByReferenceDatatypes -> throw AssemblyError("can't pass string/array as argument via a variable?") // TODO huh
|
||||
else -> throw AssemblyError("weird parameter datatype")
|
||||
}
|
||||
}
|
||||
@ -125,7 +124,7 @@ internal class FunctionCallAsmGen(private val program: Program, private val asmg
|
||||
in ByteDatatypes -> asmgen.assignFromByteVariable(target, value)
|
||||
in WordDatatypes -> asmgen.assignFromWordVariable(target, value)
|
||||
DataType.FLOAT -> asmgen.assignFromFloatVariable(target, value)
|
||||
in PassByReferenceDatatypes -> throw AssemblyError("can't pass string/array as argument via a variable?") // TODO huh
|
||||
in PassByReferenceDatatypes -> asmgen.assignFromAddressOf(target, value)
|
||||
else -> throw AssemblyError("weird parameter datatype")
|
||||
}
|
||||
}
|
||||
|
@ -105,9 +105,10 @@ internal class StatementOptimizer(private val program: Program,
|
||||
}
|
||||
if(stringVar!=null) {
|
||||
val vardecl = stringVar.targetVarDecl(program.namespace)!!
|
||||
val string = vardecl.value!! as StringLiteralValue
|
||||
val string = vardecl.value as? StringLiteralValue
|
||||
if(string!=null) {
|
||||
val pos = functionCallStatement.position
|
||||
if(string.value.length==1) {
|
||||
if (string.value.length == 1) {
|
||||
val firstCharEncoded = CompilationTarget.encodeString(string.value, string.altEncoding)[0]
|
||||
val chrout = FunctionCallStatement(
|
||||
IdentifierReference(listOf("c64", "CHROUT"), pos),
|
||||
@ -115,7 +116,7 @@ internal class StatementOptimizer(private val program: Program,
|
||||
functionCallStatement.void, pos
|
||||
)
|
||||
return listOf(IAstModification.ReplaceNode(functionCallStatement, chrout, parent))
|
||||
} else if(string.value.length==2) {
|
||||
} else if (string.value.length == 2) {
|
||||
val firstTwoCharsEncoded = CompilationTarget.encodeString(string.value.take(2), string.altEncoding)
|
||||
val chrout1 = FunctionCallStatement(
|
||||
IdentifierReference(listOf("c64", "CHROUT"), pos),
|
||||
@ -134,6 +135,7 @@ internal class StatementOptimizer(private val program: Program,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if the first instruction in the called subroutine is a return statement, remove the jump altogeter
|
||||
val subroutine = functionCallStatement.target.targetSubroutine(program.namespace)
|
||||
|
@ -10,27 +10,15 @@ main {
|
||||
float[] fa = [1,2,3,4]
|
||||
|
||||
sub start() {
|
||||
float x = 9.9
|
||||
|
||||
fa[2] = 8.8
|
||||
|
||||
p()
|
||||
|
||||
ubyte b = 2
|
||||
fa[b] = 9.8
|
||||
p()
|
||||
fa[b] = 9.9
|
||||
p()
|
||||
|
||||
wot("asdfasdf")
|
||||
wot("asdfasdf")
|
||||
wot("asdfasdf1")
|
||||
}
|
||||
|
||||
sub p() {
|
||||
byte i
|
||||
for i in 0 to len(fa)-1 {
|
||||
c64flt.print_f(fa[i])
|
||||
c64.CHROUT(',')
|
||||
c64.CHROUT(' ')
|
||||
}
|
||||
sub wot(uword text) {
|
||||
;c64scr.print(text) ; TODO better type error
|
||||
;c64.CHROUT('\n')
|
||||
c64scr.print_uwhex(text, 1)
|
||||
c64.CHROUT('\n')
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user