improve KotlinJavaRuntime library ref

This commit is contained in:
Irmen de Jong 2023-12-06 22:17:08 +01:00
parent cce08d95db
commit 5a776dd690
5 changed files with 168 additions and 149 deletions

View File

@ -1,19 +1,26 @@
<component name="libraryTable">
<library name="KotlinJavaRuntime">
<CLASSES>
<root url="jar://$KOTLIN_BUNDLED$/lib/kotlin-stdlib.jar!/" />
<root url="jar://$KOTLIN_BUNDLED$/lib/kotlin-reflect.jar!/" />
<root url="jar://$KOTLIN_BUNDLED$/lib/kotlin-test.jar!/" />
<root url="jar://$KOTLIN_BUNDLED$/lib/kotlin-stdlib-jdk7.jar!/" />
<root url="jar://$KOTLIN_BUNDLED$/lib/kotlin-stdlib-jdk8.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$KOTLIN_BUNDLED$/lib/kotlin-stdlib-sources.jar!/" />
<root url="jar://$KOTLIN_BUNDLED$/lib/kotlin-reflect-sources.jar!/" />
<root url="jar://$KOTLIN_BUNDLED$/lib/kotlin-test-sources.jar!/" />
<root url="jar://$KOTLIN_BUNDLED$/lib/kotlin-stdlib-jdk7-sources.jar!/" />
<root url="jar://$KOTLIN_BUNDLED$/lib/kotlin-stdlib-jdk8-sources.jar!/" />
</SOURCES>
</library>
<library name="KotlinJavaRuntime" type="repository">
<properties maven-id="org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.9.0" />
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib-jdk8/1.9.0/kotlin-stdlib-jdk8-1.9.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib/1.9.0/kotlin-stdlib-1.9.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib-common/1.9.0/kotlin-stdlib-common-1.9.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/annotations/13.0/annotations-13.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib-jdk7/1.9.0/kotlin-stdlib-jdk7-1.9.0.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib-jdk8/1.9.0/kotlin-stdlib-jdk8-1.9.0-javadoc.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib/1.9.0/kotlin-stdlib-1.9.0-javadoc.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib-common/1.9.0/kotlin-stdlib-common-1.9.0-javadoc.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/annotations/13.0/annotations-13.0-javadoc.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib-jdk7/1.9.0/kotlin-stdlib-jdk7-1.9.0-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib-jdk8/1.9.0/kotlin-stdlib-jdk8-1.9.0-sources.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib/1.9.0/kotlin-stdlib-1.9.0-sources.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib-common/1.9.0/kotlin-stdlib-common-1.9.0-sources.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/annotations/13.0/annotations-13.0-sources.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib-jdk7/1.9.0/kotlin-stdlib-jdk7-1.9.0-sources.jar!/" />
</SOURCES>
</library>
</component>

View File

@ -408,6 +408,9 @@ class IRPeepholeOptimizer(private val irprog: IRProgram) {
}
private fun removeDoubleLoadsAndStores(chunk: IRCodeChunk, indexedInstructions: List<IndexedValue<IRInstruction>>): Boolean {
return false
/*
var changed = false
indexedInstructions.forEach { (idx, ins) ->
@ -421,5 +424,6 @@ class IRPeepholeOptimizer(private val irprog: IRProgram) {
// ...
}
return changed
*/
}
}

View File

@ -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)?

139
examples/cx16/floatparse.p8 Normal file
View File

@ -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)
}
}

View File

@ -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)
}
}