mirror of
https://github.com/irmen/prog8.git
synced 2024-12-24 01:29:28 +00:00
avoid multiple change events in watch mode
added bsieve example
This commit is contained in:
parent
f6b03d5a78
commit
90ddec2ad8
@ -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
|
||||
|
@ -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()
|
||||
}
|
||||
|
||||
|
@ -127,6 +127,7 @@ class TestCompilerOnExamplesBothC64andCx16: FunSpec({
|
||||
listOf(
|
||||
"animals",
|
||||
"balls",
|
||||
"bsieve",
|
||||
"cube3d",
|
||||
"cube3d-float",
|
||||
"cube3d-gfx",
|
||||
|
@ -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.
|
||||
|
@ -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
51
examples/bsieve.p8
Normal 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")
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user