From 5a776dd69018764a6074004e246fe1fe05cdd196 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Wed, 6 Dec 2023 22:17:08 +0100 Subject: [PATCH] improve KotlinJavaRuntime library ref --- .idea/libraries/KotlinJavaRuntime.xml | 41 +++--- .../intermediate/IRPeepholeOptimizer.kt | 4 + docs/source/todo.rst | 2 +- examples/cx16/floatparse.p8 | 139 ++++++++++++++++++ examples/test.p8 | 131 ----------------- 5 files changed, 168 insertions(+), 149 deletions(-) create mode 100644 examples/cx16/floatparse.p8 diff --git a/.idea/libraries/KotlinJavaRuntime.xml b/.idea/libraries/KotlinJavaRuntime.xml index 1a7265de2..4a4136c90 100644 --- a/.idea/libraries/KotlinJavaRuntime.xml +++ b/.idea/libraries/KotlinJavaRuntime.xml @@ -1,19 +1,26 @@ - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/codeGenIntermediate/src/prog8/codegen/intermediate/IRPeepholeOptimizer.kt b/codeGenIntermediate/src/prog8/codegen/intermediate/IRPeepholeOptimizer.kt index 5c9c6418a..70e004fb2 100644 --- a/codeGenIntermediate/src/prog8/codegen/intermediate/IRPeepholeOptimizer.kt +++ b/codeGenIntermediate/src/prog8/codegen/intermediate/IRPeepholeOptimizer.kt @@ -408,6 +408,9 @@ class IRPeepholeOptimizer(private val irprog: IRProgram) { } private fun removeDoubleLoadsAndStores(chunk: IRCodeChunk, indexedInstructions: List>): Boolean { + return false + +/* var changed = false indexedInstructions.forEach { (idx, ins) -> @@ -421,5 +424,6 @@ class IRPeepholeOptimizer(private val irprog: IRProgram) { // ... } return changed +*/ } } \ No newline at end of file diff --git a/docs/source/todo.rst b/docs/source/todo.rst index f17f81e26..3e4cab3e3 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -46,7 +46,7 @@ Compiler: Libraries: -- once a VAL_1 implementation is merged into the X16 kernal properly, remove all the workarounds in cx16 floats.parse_f() +- once a VAL_1 implementation is merged into the X16 kernal properly, remove all the workarounds in cx16 floats.parse_f() . Prototype parse routine in examples/cx16/floatparse.p8 - fix the problems in atari target, and flesh out its libraries. - c128 target: make syslib more complete (missing kernal routines)? - pet32 target: make syslib more complete (missing kernal routines)? diff --git a/examples/cx16/floatparse.p8 b/examples/cx16/floatparse.p8 new file mode 100644 index 000000000..e756f1d6a --- /dev/null +++ b/examples/cx16/floatparse.p8 @@ -0,0 +1,139 @@ +%import floats +%import textio +%import string +%zeropage basicsafe + +main { + + ; float parsing prototype (remember, there's no official kernal VAL_1 routine to do this yet...) + + sub start() { + f("") + f("0") + f("-0") + f(".0") + f("-.0") + f("0.0") + f("0.1") + f("+1.1") + f("-1.1") + f("-.1") + f("-.9") + f("-99.9") + f("99.9") + f("123456789.888888") + f("123.456789123456") + f("-123.") + f("-123.456789123456") + f("123.45e20") + f("+123.45e+20") + f("123.45e-20") + f("123.45e20") + f("-123.45e+20") + f("-123.45e-20") + f(" - 1 23. 45e - 36 ") + f(" - 1 23. 4Z 5e - 20 ") + f(" - 1 23!. 4Z 5e - 20 ") + f("1.7014118345e+38") ; TODO fix overflow error + f("-1.7014118345e+38") ; TODO fix overflow error + } + + sub f(str string) { + cbm.SETTIM(0,0,0) + repeat 100 + float value1 = floats.parse_f(string) + txt.print("1=") + txt.print_uw(cbm.RDTIM16()) + txt.spc() + + cbm.SETTIM(0,0,0) + repeat 100 + float value2 = parse(string) + txt.print("2=") + txt.print_uw(cbm.RDTIM16()) + txt.nl() + + floats.print_f(value1) + txt.spc() + txt.spc() + floats.print_f(value2) + txt.nl() + } + + sub parse(uword stringptr) -> float { + if @(stringptr)==0 + return 0.0 + + float result + byte exponent + bool negative + + repeat { + cx16.r0L = @(stringptr) + when cx16.r0L { + 0 -> goto done + '-' -> negative=true + '+', ' ' -> { /* skip */ } + else -> { + if string.isdigit(cx16.r0L) { + result *= 10 + result += cx16.r0L - '0' + } else + break + } + } + stringptr++ + } + + if cx16.r0L=='.' { + ; read decimals + repeat { + stringptr++ + cx16.r0L = @(stringptr) + if cx16.r0L==' ' + continue + else if string.isdigit(cx16.r0L) { + exponent-- + result *= 10 + result += cx16.r0L - '0' + } else + break + } + } + + if cx16.r0L=='e' or cx16.r0L=='E' { + ; read exponent + bool neg_exponent + byte exp_value + repeat { + stringptr++ + cx16.r0L = @(stringptr) + when cx16.r0L { + 0 -> break + '+', ' ' -> { /* skip */ } + '-' -> neg_exponent=true + else -> { + if string.isdigit(cx16.r0L) { + exp_value *= 10 + exp_value += cx16.r0L - '0' + } else + break + } + } + } + if neg_exponent + exponent -= exp_value + else + exponent += exp_value + } + +done: + if exponent + result *= floats.pow(10, exponent) + + if negative + result = -result + + return floats.normalize(result) + } +} diff --git a/examples/test.p8 b/examples/test.p8 index d8265574c..12b29ea06 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -1,139 +1,8 @@ -%import floats %import textio -%import string %zeropage basicsafe main { - - ; float parsing prototype - sub start() { - f("") - f("0") - f("-0") - f(".0") - f("-.0") - f("0.0") - f("0.1") - f("+1.1") - f("-1.1") - f("-.1") - f("-.9") - f("-99.9") - f("99.9") - f("123456789.888888") - f("123.456789123456") - f("-123.") - f("-123.456789123456") - f("123.45e20") - f("+123.45e+20") - f("123.45e-20") - f("123.45e20") - f("-123.45e+20") - f("-123.45e-20") - f(" - 1 23. 45e - 36 ") - f(" - 1 23. 4Z 5e - 20 ") - f(" - 1 23!. 4Z 5e - 20 ") - f("1.7014118345e+38") ; TODO fix overflow error - f("-1.7014118345e+38") ; TODO fix overflow error - } - sub f(str string) { - cbm.SETTIM(0,0,0) - repeat 100 - float value1 = floats.parse_f(string) - txt.print("1=") - txt.print_uw(cbm.RDTIM16()) - txt.spc() - - cbm.SETTIM(0,0,0) - repeat 100 - float value2 = parse(string) - txt.print("2=") - txt.print_uw(cbm.RDTIM16()) - txt.nl() - - floats.print_f(value1) - txt.spc() - txt.spc() - floats.print_f(value2) - txt.nl() - } - - sub parse(uword stringptr) -> float { - if @(stringptr)==0 - return 0.0 - - float result - byte exponent - bool negative - - repeat { - cx16.r0L = @(stringptr) - when cx16.r0L { - 0 -> goto done - '-' -> negative=true - '+', ' ' -> { /* skip */ } - else -> { - if string.isdigit(cx16.r0L) { - result *= 10 - result += cx16.r0L - '0' - } else - break - } - } - stringptr++ - } - - if cx16.r0L=='.' { - ; read decimals - repeat { - stringptr++ - cx16.r0L = @(stringptr) - if cx16.r0L==' ' - continue - else if string.isdigit(cx16.r0L) { - exponent-- - result *= 10 - result += cx16.r0L - '0' - } else - break - } - } - - if cx16.r0L=='e' or cx16.r0L=='E' { - ; read exponent - bool neg_exponent - byte exp_value - repeat { - stringptr++ - cx16.r0L = @(stringptr) - when cx16.r0L { - 0 -> break - '+', ' ' -> { /* skip */ } - '-' -> neg_exponent=true - else -> { - if string.isdigit(cx16.r0L) { - exp_value *= 10 - exp_value += cx16.r0L - '0' - } else - break - } - } - } - if neg_exponent - exponent -= exp_value - else - exponent += exp_value - } - -done: - if exponent - result *= floats.pow(10, exponent) - - if negative - result = -result - - return floats.normalize(result) } }