mirror of
https://github.com/irmen/prog8.git
synced 2024-11-29 17:50:35 +00:00
vm: added floats.str_f()
This commit is contained in:
parent
a01c0a283d
commit
d91ca8b197
@ -10,7 +10,7 @@ floats {
|
||||
|
||||
|
||||
sub print_f(float value) {
|
||||
; ---- prints the floating point value (without a newline).
|
||||
; ---- prints the floating point value (without a newline and no leading spaces).
|
||||
%ir {{
|
||||
loadm.f fr65535,floats.print_f.value
|
||||
syscall 25 (fr65535.f)
|
||||
@ -18,6 +18,18 @@ sub print_f(float value) {
|
||||
}}
|
||||
}
|
||||
|
||||
sub str_f(float value) -> str {
|
||||
; ---- converts the floating point value to a string (no leading spaces)
|
||||
str @shared buffer=" "*20
|
||||
%ir {{
|
||||
load.w r65535,floats.str_f.buffer
|
||||
loadm.f fr65535,floats.str_f.value
|
||||
syscall 47 (r65535.w, fr65535.f)
|
||||
load.w r0,floats.str_f.buffer
|
||||
returnr.w r0
|
||||
}}
|
||||
}
|
||||
|
||||
sub parse_f(str value) -> float {
|
||||
; -- parse a string value of a number to float
|
||||
%ir {{
|
||||
|
@ -52,8 +52,9 @@ SYSCALLS:
|
||||
42 = CLAMP_UWORD
|
||||
43 = CLAMP_FLOAT
|
||||
44 = ATAN
|
||||
45 = STR_TO_FLOAT
|
||||
45 = str to float
|
||||
46 = MUL16_LAST_UPPER
|
||||
47 = float to str
|
||||
*/
|
||||
|
||||
enum class Syscall {
|
||||
@ -103,7 +104,8 @@ enum class Syscall {
|
||||
CLAMP_FLOAT,
|
||||
ATAN,
|
||||
STR_TO_FLOAT,
|
||||
MUL16_LAST_UPPER
|
||||
MUL16_LAST_UPPER,
|
||||
FLOAT_TO_STR
|
||||
;
|
||||
|
||||
companion object {
|
||||
@ -509,6 +511,13 @@ object SysCalls {
|
||||
Syscall.MUL16_LAST_UPPER -> {
|
||||
returnValue(callspec.returns!!, vm.mul16_last_upper, vm)
|
||||
}
|
||||
Syscall.FLOAT_TO_STR -> {
|
||||
val (buffer, number) = getArgValues(callspec.arguments, vm)
|
||||
val bufferAddr = (buffer as UShort).toShort().toInt()
|
||||
val numf = number as Double
|
||||
val numStr = if(numf.toInt().toDouble()==numf) numf.toInt().toString() else numf.toString()
|
||||
vm.memory.setString(bufferAddr, numStr, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user