mirror of
https://github.com/irmen/prog8.git
synced 2024-07-26 20:29:55 +00:00
fixed strlen() to work on arguments other than just a variable
This commit is contained in:
parent
add5bfa2ec
commit
43c0afdea0
@ -540,6 +540,8 @@ internal class BuiltinFunctionsAsmGen(private val program: Program, private val
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun funcStrlen(fcall: IFunctionCall, resultToStack: Boolean) {
|
private fun funcStrlen(fcall: IFunctionCall, resultToStack: Boolean) {
|
||||||
|
if (fcall.args[0] is IdentifierReference) {
|
||||||
|
// use the address of the variable
|
||||||
val name = asmgen.asmVariableName(fcall.args[0] as IdentifierReference)
|
val name = asmgen.asmVariableName(fcall.args[0] as IdentifierReference)
|
||||||
val type = fcall.args[0].inferType(program)
|
val type = fcall.args[0].inferType(program)
|
||||||
when {
|
when {
|
||||||
@ -547,6 +549,11 @@ internal class BuiltinFunctionsAsmGen(private val program: Program, private val
|
|||||||
type.istype(DataType.UWORD) -> asmgen.out(" lda $name | ldy $name+1")
|
type.istype(DataType.UWORD) -> asmgen.out(" lda $name | ldy $name+1")
|
||||||
else -> throw AssemblyError("strlen requires str or uword arg")
|
else -> throw AssemblyError("strlen requires str or uword arg")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// use the expression value as address of the string
|
||||||
|
asmgen.assignExpressionToRegister(fcall.args[0], RegisterOrPair.AY)
|
||||||
|
}
|
||||||
if (resultToStack)
|
if (resultToStack)
|
||||||
asmgen.out(" jsr prog8_lib.func_strlen_stack")
|
asmgen.out(" jsr prog8_lib.func_strlen_stack")
|
||||||
else
|
else
|
||||||
|
@ -354,7 +354,7 @@ private fun builtinStrlen(args: List<Expression>, position: Position, program: P
|
|||||||
val argument=args[0]
|
val argument=args[0]
|
||||||
if(argument is StringLiteralValue)
|
if(argument is StringLiteralValue)
|
||||||
return NumericLiteralValue.optimalInteger(argument.value.length, argument.position)
|
return NumericLiteralValue.optimalInteger(argument.value.length, argument.position)
|
||||||
val vardecl = (argument as IdentifierReference).targetVarDecl(program.namespace)
|
val vardecl = (argument as? IdentifierReference)?.targetVarDecl(program.namespace)
|
||||||
if(vardecl!=null) {
|
if(vardecl!=null) {
|
||||||
if(vardecl.datatype!=DataType.STR && vardecl.datatype!=DataType.UWORD)
|
if(vardecl.datatype!=DataType.STR && vardecl.datatype!=DataType.UWORD)
|
||||||
throw SyntaxError("strlen must have string argument", position)
|
throw SyntaxError("strlen must have string argument", position)
|
||||||
|
Loading…
Reference in New Issue
Block a user