Compare commits

...

5 Commits

Author SHA1 Message Date
Irmen de Jong
c719e274d5 java version tweaks 2024-05-18 20:25:44 +02:00
Irmen de Jong
e4990f8ec5 Revert "update to Java 17 LTS"
This reverts commit 3ef5bdfeda.
2024-05-18 18:59:32 +02:00
Irmen de Jong
62afd3342e void syntax check, fixes #135 2024-05-18 17:15:31 +02:00
Irmen de Jong
6e8a89e6f1 optimize const word repeat setup 2024-05-18 16:30:27 +02:00
Irmen de Jong
aa2437cfb8 fix invalid repeat loop when iterations is already in register Y 2024-05-18 15:09:56 +02:00
20 changed files with 74 additions and 57 deletions

View File

@ -1,13 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Kotlin2JvmCompilerArguments">
<option name="jvmTarget" value="17" />
</component>
<component name="KotlinCommonCompilerArguments">
<option name="apiVersion" value="1.9" />
<option name="languageVersion" value="1.9" />
<option name="jvmTarget" value="11" />
</component>
<component name="KotlinJpsPluginSettings">
<option name="version" value="1.9.24" />
</component>
</project>
</project>

View File

@ -6,9 +6,8 @@ plugins {
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(javaVersion)
}
targetCompatibility = JavaLanguageVersion.of(javaVersion)
sourceCompatibility = JavaLanguageVersion.of(javaVersion)
}
compileKotlin {

View File

@ -5,9 +5,8 @@ plugins {
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(javaVersion)
}
targetCompatibility = JavaLanguageVersion.of(javaVersion)
sourceCompatibility = JavaLanguageVersion.of(javaVersion)
}
compileKotlin {

View File

@ -819,17 +819,15 @@ class AsmGen6502Internal (
loopEndLabels.pop()
}
private fun repeatWordCount(count: Int, stmt: PtRepeatLoop) {
require(count in 257..65535) { "invalid repeat count ${stmt.position}" }
private fun repeatWordCount(iterations: Int, stmt: PtRepeatLoop) {
require(iterations in 257..65535) { "invalid repeat count ${stmt.position}" }
val repeatLabel = makeLabel("repeat")
val counterVar = createRepeatCounterVar(DataType.UWORD, isTargetCpu(CpuType.CPU65c02), stmt)
// the iny + double dec is microoptimization of the 16 bit loop
val loopcount = if(iterations and 0x00ff == 0) iterations else iterations + 0x0100 // so that the loop can simply use a double-dec
out("""
ldy #>$count
lda #<$count
beq +
iny
+ sta $counterVar
ldy #>$loopcount
lda #<$loopcount
sta $counterVar
sty $counterVar+1
$repeatLabel""")
translate(stmt.statements)
@ -882,8 +880,8 @@ $repeatLabel""")
}
private fun repeatCountInY(stmt: PtRepeatLoop, endLabel: String) {
// note: Y must just have been loaded with the (variable) number of loops to be performed!
val repeatLabel = makeLabel("repeat")
out(" cpy #0")
if(isTargetCpu(CpuType.CPU65c02)) {
val counterVar = createRepeatCounterVar(DataType.UBYTE, true, stmt)
out(" beq $endLabel | sty $counterVar")

View File

@ -6,9 +6,8 @@ plugins {
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(javaVersion)
}
targetCompatibility = JavaLanguageVersion.of(javaVersion)
sourceCompatibility = JavaLanguageVersion.of(javaVersion)
}
compileKotlin {

View File

@ -6,9 +6,8 @@ plugins {
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(javaVersion)
}
targetCompatibility = JavaLanguageVersion.of(javaVersion)
sourceCompatibility = JavaLanguageVersion.of(javaVersion)
}
compileKotlin {

View File

@ -6,9 +6,8 @@ plugins {
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(javaVersion)
}
targetCompatibility = JavaLanguageVersion.of(javaVersion)
sourceCompatibility = JavaLanguageVersion.of(javaVersion)
}
compileKotlin {

View File

@ -7,9 +7,8 @@ plugins {
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(javaVersion)
}
targetCompatibility = JavaLanguageVersion.of(javaVersion)
sourceCompatibility = JavaLanguageVersion.of(javaVersion)
}
compileKotlin {

View File

@ -56,6 +56,7 @@ string {
sub find(str st, ubyte character) -> ubyte {
; Locates the first position of the given character in the string,
; returns Carry set if found + index in A, or Carry clear if not found (and A will be 255, an invalid index).
; NOTE: because this isn't an asmsub, there's only a SINGLE return value here. On the c64/cx16 targets etc there are 2 return values.
ubyte ix
for ix in 0 to length(st)-1 {
if st[ix]==character {

View File

@ -570,6 +570,13 @@ internal class AstChecker(private val program: Program,
checkType(assignment.target, assignment.value, assignment.isAugmentable)
}
if(assignment.target.void && assignment.target.multi?.isNotEmpty()!=true) {
if(assignment.value is IFunctionCall)
errors.err("cannot assign to 'void', perhaps a void function call was intended", assignment.position)
else
errors.err("cannot assign to 'void'", assignment.position)
return
}
val fcall = assignment.value as? IFunctionCall
val fcallTarget = fcall?.target?.targetSubroutine(program)

View File

@ -4,6 +4,7 @@ import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe
import io.kotest.matchers.shouldNotBe
import io.kotest.matchers.string.shouldContain
import io.kotest.matchers.string.shouldEndWith
import io.kotest.matchers.types.instanceOf
import prog8.ast.IFunctionCall
import prog8.ast.expressions.*
@ -612,5 +613,30 @@ main {
}"""
compileText(Cx16Target(), false, src) shouldNotBe null
}
test("void assignment is invalid") {
val src="""
main {
romsub $2000 = multi() -> ubyte @A, ubyte @Y
romsub $3000 = single() -> ubyte @A
sub start() {
void, void = multi() ; ok
cx16.r0L, void = multi() ; ok
void, cx16.r0L = multi() ; ok
void multi() ; ok
void single() ; ok
void = 3333 ; fail!
void = single() ; fail!
void = multi() ; fail!
}
}"""
val errors = ErrorReporterForTests()
compileText(C64Target(), optimize=false, src, writeAssembly=true, errors = errors) shouldBe null
errors.errors.size shouldBe 3
errors.errors[0] shouldEndWith "cannot assign to 'void'"
errors.errors[1] shouldEndWith "cannot assign to 'void', perhaps a void function call was intended"
errors.errors[2] shouldEndWith "cannot assign to 'void', perhaps a void function call was intended"
}
})

View File

@ -4,9 +4,8 @@ plugins {
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(javaVersion)
}
targetCompatibility = JavaLanguageVersion.of(javaVersion)
sourceCompatibility = JavaLanguageVersion.of(javaVersion)
}
compileKotlin {

View File

@ -5,7 +5,7 @@
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/build" />
</content>
<orderEntry type="jdk" jdkName="Python 3.11" jdkType="Python SDK" />
<orderEntry type="jdk" jdkName="Python 3.12" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -62,7 +62,7 @@ For normal use, the ``installDist`` task should suffice and after succesful comp
.. hint::
Development and testing is done on Linux using the IntelliJ IDEA IDE,
but the actual prog8 compiler should run on all operating systems that provide a java runtime (version 17 or newer).
but the actual prog8 compiler should run on all operating systems that provide a java runtime (version 11 or newer).
If you do have trouble building or running the compiler on your operating system, please let me know!
To successfully build and debug in IDEA, you have to manually generate the Antlr-parser classes first.
@ -325,7 +325,7 @@ Troubleshooting
Compiler doesn't run, complains about "UnsupportedClassVersionError"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
You need to install and use JDK version 17 or newer to run the prog8 compiler. Check this with "java -version".
You need to install and use JDK version 11 or newer to run the prog8 compiler. Check this with "java -version".
See :ref:`requirements`.
The computer just resets (at the end of the program)

View File

@ -193,9 +193,9 @@ It's easy to compile yourself, but a recent precompiled .exe (only for Windows)
*You need at least version 1.58.0 of this assembler.*
If you are on Linux, there's probably a "64tass" package in the repositories, but check if it is a recent enough version.
A **Java runtime (jre or jdk), version 17 or newer** is required to run the prog8 compiler itself.
A **Java runtime (jre or jdk), version 11 or newer** is required to run the prog8 compiler itself.
If you're scared of Oracle's licensing terms, get one of the versions of another vendor. Even Microsoft provides their own version.
Other OpenJDK builds can be found at `Adoptium <https://adoptium.net/temurin/releases/?version=17>`_ .
Other OpenJDK builds can be found at `Adoptium <https://adoptium.net/temurin/releases/?version=11>`_ .
For MacOS you can also use the Homebrew system to install a recent version of OpenJDK.
Finally: an **emulator** (or a real machine of course) to test and run your programs on.

View File

@ -1,10 +1,9 @@
%import textio
%zeropage basicsafe
main {
sub start() {
uword workFunc=$2000
void = call(workFunc)
}
sub start() {
repeat cx16.r0 {
cx16.r1L++
}
}
}

View File

@ -3,6 +3,6 @@ org.gradle.console=rich
org.gradle.parallel=true
org.gradle.daemon=true
kotlin.code.style=official
javaVersion=17
javaVersion=11
kotlinVersion=1.9.24
version=10.3.1-SNAPSHOT

View File

@ -6,9 +6,8 @@ plugins {
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(javaVersion)
}
targetCompatibility = JavaLanguageVersion.of(javaVersion)
sourceCompatibility = JavaLanguageVersion.of(javaVersion)
}
compileKotlin {

View File

@ -4,9 +4,8 @@ plugins {
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(javaVersion)
}
targetCompatibility = JavaLanguageVersion.of(javaVersion)
sourceCompatibility = JavaLanguageVersion.of(javaVersion)
}
dependencies {

View File

@ -6,9 +6,8 @@ plugins {
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(javaVersion)
}
targetCompatibility = JavaLanguageVersion.of(javaVersion)
sourceCompatibility = JavaLanguageVersion.of(javaVersion)
}
compileKotlin {