Skip to content

Commit

Permalink
vm: fix comparison datatype error; primes.p8 works again
Browse files Browse the repository at this point in the history
  • Loading branch information
irmen committed May 24, 2022
1 parent 3f5877d commit b459b09
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 21 deletions.
2 changes: 1 addition & 1 deletion codeGenVirtual/src/prog8/codegen/virtual/CodeGen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ class CodeGen(internal val program: PtProgram,
throw AssemblyError("if condition should only be a binary comparison expression")

val signed = ifElse.condition.left.type in arrayOf(DataType.BYTE, DataType.WORD, DataType.FLOAT)
val vmDt = vmType(ifElse.condition.type)
val vmDt = vmType(ifElse.condition.left.type)
val code = VmCodeChunk()

fun translateNonZeroComparison(): VmCodeChunk {
Expand Down
1 change: 0 additions & 1 deletion docs/source/todo.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ TODO

For next release
^^^^^^^^^^^^^^^^
- vm: fix primes.p8 calculating wrong primes
...


Expand Down
12 changes: 0 additions & 12 deletions examples/primes.p8
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,15 @@ main {
return 0 ; we wrapped; no more primes available in the sieve
}

txt.print("candidate: ")
txt.print_ub(candidate_prime)
txt.nl()

; found next one, mark the multiples and return it.
sieve[candidate_prime] = true
uword multiple = candidate_prime


while multiple < len(sieve) {
sieve[lsb(multiple)] = true
multiple += candidate_prime
}

ubyte xx
for xx in sieve {
txt.print_ub(xx)
txt.spc()
}
txt.nl()

return candidate_prime
}
}
22 changes: 15 additions & 7 deletions examples/test.p8
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,24 @@ main {

ubyte[20] sieve
uword count=0
ubyte xx
for xx in sieve {
txt.print_ub(xx)
if count < 256
txt.print("<256 ok! 1\n")
if count > 256
txt.print(">256 nok! 2\n")
count=257
if count < 256
txt.print("<256 nok! 3\n")
if count > 256
txt.print(">256 ok! 4\n")
count=256

count=0
while count < 256 { ; TODO fix this while loop
txt.print_uw(count)
txt.spc()
count++
count += 10
}
txt.nl()
txt.print_uw(count)
txt.nl()


; ; a "pixelshader":
; sys.gfx_enable(0) ; enable lo res screen
Expand Down

0 comments on commit b459b09

Please sign in to comment.