Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: SLEEP's argument should be in seconds, not milliseconds #79

Merged
merged 1 commit into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/src/main/java/io/atha/bababasic/ActivityMain.kt
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ NEXT I%
40 PRINT C
50 LET A = B
60 LET B = C
65 SLEEP 500
65 SLEEP 0.5
70 GOTO 30
""",
"INKEY.bas" to """PRINT "PRESS w,a,s,d TO MOVE THE STAR. PRESS q to QUIT."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,22 @@ import java.util.Arrays
import java.util.Random
import java.util.concurrent.TimeUnit
import java.util.concurrent.locks.LockSupport
import kotlin.math.roundToLong

object Statements {
@JvmStatic
fun sleep(
symbolTable: SymbolTable,
instruction: IR.Instruction
) {
val millis = symbolTable[instruction.op1]!!.value!!.int32
if (millis < 0) {
val sleepArg = symbolTable[instruction.op1]!!.value!!.float64
if (sleepArg < 0) {
throw RuntimeError(
RuntimeError.ErrorCode.DATA_OUT_OF_RANGE,
"Sleep time millis cannot be less than 0."
"Sleep time seconds cannot be less than 0."
)
}
LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(millis.toLong()))
LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos((sleepArg * 1000L).roundToLong()))
}

@JvmStatic
Expand Down
Loading