avoid multiple change events in watch mode

added bsieve example
This commit is contained in:
Irmen de Jong 2022-07-31 11:58:27 +02:00
parent f6b03d5a78
commit 90ddec2ad8
6 changed files with 76 additions and 14 deletions

View File

@ -129,7 +129,7 @@ _startloop dey
asmsub find(uword string @R0, ubyte character @A) -> ubyte @A, ubyte @Pc {
; 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.
; returns Carry set if found + index in A, or A=0 + Carry clear if not found.
%asm {{
; need to copy the the cx16 virtual registers to zeropage to make this run on C64...
sta P8ZP_SCRATCH_B1
@ -144,7 +144,8 @@ _startloop dey
beq _found
iny
bne -
_notfound clc
_notfound lda #0
clc
rts
_found tya
sec

View File

@ -10,10 +10,7 @@ import prog8.compiler.CompilationResult
import prog8.compiler.CompilerArguments
import prog8.compiler.compileProgram
import java.io.File
import java.nio.file.FileSystems
import java.nio.file.Path
import java.nio.file.Paths
import java.nio.file.StandardWatchEventKinds
import java.nio.file.*
import java.time.LocalDateTime
import kotlin.system.exitProcess
@ -148,16 +145,26 @@ private fun compileMain(args: Array<String>): Boolean {
}
println("[${LocalDateTime.now().withNano(0)}] Waiting for file changes.")
fun determineRecompilationNeeded(event: WatchKey): Boolean {
if(event.isValid) {
for (changed in event.pollEvents()) {
if (changed.kind() == StandardWatchEventKinds.ENTRY_MODIFY) {
val changedPath = changed.context() as Path
if (allImportedFiles.any { it.fileName == changedPath.fileName }) {
println(" change detected: $changedPath")
return true
}
}
}
}
return false
}
var recompile=false
while(!recompile) {
val event = watchservice.take()
for (changed in event.pollEvents()) {
val changedPath = changed.context() as Path
if(allImportedFiles.any { it.fileName == changedPath.fileName }) {
println(" change detected: $changedPath")
recompile = true
}
}
Thread.sleep(50) // avoid multiple events on same file
recompile = determineRecompilationNeeded(event)
event.reset()
}

View File

@ -127,6 +127,7 @@ class TestCompilerOnExamplesBothC64andCx16: FunSpec({
listOf(
"animals",
"balls",
"bsieve",
"cube3d",
"cube3d-float",
"cube3d-gfx",

View File

@ -172,7 +172,7 @@ Provides string manipulation routines.
``find(string, char) -> ubyte index + carry bit``
Locates the first position of the given character in the string, returns carry bit set if found
and the index in the string. Or carry bit clear if the character was not found.
and the index in the string. Or 0+carry bit clear if the character was not found.
``compare(string1, string2) -> ubyte result``
Returns -1, 0 or 1 depeding on wether string1 sorts before, equal or after string2.

View File

@ -3,6 +3,8 @@ TODO
For next release
^^^^^^^^^^^^^^^^
- can we optimize logical expresions such as if input_size and command_line[0]!=159 to not use stack eval anymore?
...

51
examples/bsieve.p8 Normal file
View File

@ -0,0 +1,51 @@
%import textio
%import floats
%zeropage basicsafe
%option no_sysinit
; The "Byte Sieve" test. https://en.wikipedia.org/wiki/Byte_Sieve
; Note: this program is compatible with C64 and CX16.
main {
sub start() {
c64.SETTIM(0, 0, 0)
const ubyte ITERS = 10
uword count
uword i
uword prime
uword k
const uword SIZEPL = 8191
uword flags_ptr = memory("flags", SIZEPL, $100)
txt.print("calculating...\n")
repeat ITERS {
sys.memset(flags_ptr, SIZEPL, 1)
count = 0
for i in 0 to SIZEPL-1 {
if @(flags_ptr+i) {
prime = i + i + 3
k = i + prime
while k <= SIZEPL-1 {
@(flags_ptr + k) = false
k += prime
}
; txt.print_uw(prime)
; txt.spc()
count++
}
}
}
txt.print_uw(count)
txt.print(" primes\n")
float time = c64.RDTIM16() / 60.0
floats.print_f(time)
txt.print(" sec total = ")
floats.print_f(time/ITERS)
txt.print(" sec per iteration\n")
}
}