mirror of
https://github.com/irmen/prog8.git
synced 2026-04-20 11:17:01 +00:00
doc
This commit is contained in:
@@ -12,11 +12,13 @@ internal class BuiltinFuncGen(private val codeGen: CodeGen, private val exprGen:
|
||||
|
||||
fun translate(call: PtBuiltinFunctionCall, resultRegister: Int): VmCodeChunk {
|
||||
return when(call.name) {
|
||||
"cmp" -> TODO("cmp() can't be used on vm because no processor status bits implemented")
|
||||
"max" -> TODO()
|
||||
"max" -> funcMax(call, resultRegister)
|
||||
"min" -> TODO()
|
||||
"sum" -> TODO()
|
||||
"abs" -> TODO()
|
||||
"any" -> TODO()
|
||||
"all" -> TODO()
|
||||
"abs" -> TODO("abs once we can compare plus minus")
|
||||
"cmp" -> TODO("cmp() can't be used on vm because no processor status bits implemented")
|
||||
"sgn" -> funcSgn(call, resultRegister)
|
||||
"sin" -> TODO("floats not yet implemented")
|
||||
"cos" -> TODO("floats not yet implemented")
|
||||
@@ -31,8 +33,6 @@ internal class BuiltinFuncGen(private val codeGen: CodeGen, private val exprGen:
|
||||
"round" -> TODO("floats not yet implemented")
|
||||
"floor" -> TODO("floats not yet implemented")
|
||||
"ceil" -> TODO("floats not yet implemented")
|
||||
"any" -> TODO()
|
||||
"all" -> TODO()
|
||||
"pop" -> funcPop(call)
|
||||
"popw" -> funcPopw(call)
|
||||
"push" -> funcPush(call)
|
||||
@@ -59,8 +59,6 @@ internal class BuiltinFuncGen(private val codeGen: CodeGen, private val exprGen:
|
||||
"pokew" -> funcPokeW(call)
|
||||
"pokemon" -> VmCodeChunk()
|
||||
"mkword" -> funcMkword(call, resultRegister)
|
||||
"sin8u" -> funcSin8u(call, resultRegister)
|
||||
"cos8u" -> funcCos8u(call, resultRegister)
|
||||
"sort" -> funcSort(call)
|
||||
"reverse" -> funcReverse(call)
|
||||
"swap" -> funcSwap(call)
|
||||
@@ -72,6 +70,25 @@ internal class BuiltinFuncGen(private val codeGen: CodeGen, private val exprGen:
|
||||
}
|
||||
}
|
||||
|
||||
private fun funcMax(call: PtBuiltinFunctionCall, resultRegister: Int): VmCodeChunk {
|
||||
val code = VmCodeChunk()
|
||||
val arrayName = (call.args.single() as PtIdentifier).targetName
|
||||
val array = codeGen.symbolTable.flat.getValue(arrayName) as StStaticVariable
|
||||
when (array.dt) {
|
||||
DataType.ARRAY_UW, DataType.ARRAY_W -> {
|
||||
TODO("max word array")
|
||||
}
|
||||
DataType.STR -> {
|
||||
TODO("max string")
|
||||
}
|
||||
else -> {
|
||||
TODO("max byte array")
|
||||
}
|
||||
}
|
||||
|
||||
return code
|
||||
}
|
||||
|
||||
private fun funcSgn(call: PtBuiltinFunctionCall, resultRegister: Int): VmCodeChunk {
|
||||
val code = VmCodeChunk()
|
||||
code += exprGen.translateExpression(call.args.single(), 0)
|
||||
@@ -164,24 +181,6 @@ internal class BuiltinFuncGen(private val codeGen: CodeGen, private val exprGen:
|
||||
return code
|
||||
}
|
||||
|
||||
private fun funcCos8u(call: PtBuiltinFunctionCall, resultRegister: Int): VmCodeChunk {
|
||||
val code = VmCodeChunk()
|
||||
code += exprGen.translateExpression(call.args[0], 0)
|
||||
code += VmCodeInstruction(Opcode.SYSCALL, value=Syscall.COS8U.ordinal)
|
||||
if(resultRegister!=0)
|
||||
code += VmCodeInstruction(Opcode.LOADR, VmDataType.BYTE, reg1=resultRegister, reg2=0)
|
||||
return code
|
||||
}
|
||||
|
||||
private fun funcSin8u(call: PtBuiltinFunctionCall, resultRegister: Int): VmCodeChunk {
|
||||
val code = VmCodeChunk()
|
||||
code += exprGen.translateExpression(call.args[0], 0)
|
||||
code += VmCodeInstruction(Opcode.SYSCALL, value=Syscall.SIN8U.ordinal)
|
||||
if(resultRegister!=0)
|
||||
code += VmCodeInstruction(Opcode.LOADR, VmDataType.BYTE, reg1=resultRegister, reg2=0)
|
||||
return code
|
||||
}
|
||||
|
||||
private fun funcMkword(call: PtBuiltinFunctionCall, resultRegister: Int): VmCodeChunk {
|
||||
val msbReg = codeGen.vmRegisters.nextFree()
|
||||
val lsbReg = codeGen.vmRegisters.nextFree()
|
||||
|
||||
Reference in New Issue
Block a user