use more modern java date/time api

This commit is contained in:
Irmen de Jong 2019-09-10 01:29:33 +02:00
parent c493c3e5c6
commit 9dedbbf47c
12 changed files with 39 additions and 54 deletions

View File

@ -16,7 +16,6 @@ import prog8.vm.RuntimeValue
import prog8.vm.stackvm.Syscall
import java.io.File
import java.nio.file.Path
import java.util.*
import kotlin.math.abs

View File

@ -17,7 +17,6 @@ import prog8.compiler.target.c64.MachineDefinition
import prog8.compiler.target.c64.Petscii
import prog8.vm.RuntimeValue
import java.io.File
import java.util.*
import kotlin.math.abs

View File

@ -12,9 +12,9 @@ import prog8.compiler.intermediate.Opcode
import prog8.compiler.intermediate.opcodesWithVarArgument
import prog8.vm.RuntimeValue
import java.io.File
import java.util.*
import java.util.regex.Pattern
class Program (val name: String,
val program: MutableList<Instruction>,
val variables: Map<String, RuntimeValue>,

View File

@ -12,7 +12,6 @@ import prog8.vm.astvm.BitmapScreenPanel
import prog8.vm.astvm.Memory
import java.io.File
import java.io.PrintStream
import java.util.*
import kotlin.math.*

View File

@ -9,7 +9,7 @@ import prog8.vm.astvm.AstVm
import java.nio.file.FileSystems
import java.nio.file.Path
import java.nio.file.StandardWatchEventKinds
import java.util.*
import java.time.LocalDateTime
import kotlin.system.exitProcess
@ -67,7 +67,7 @@ private fun compileMain(args: Array<String>) {
println(importedFile)
importedFile.parent.register(watchservice, StandardWatchEventKinds.ENTRY_MODIFY)
}
println("${Date()}: Waiting for file changes.")
println("[${LocalDateTime.now().withNano(0)}] Waiting for file changes.")
val event = watchservice.take()
for(changed in event.pollEvents()) {
val changedPath = changed.context() as Path

View File

@ -13,7 +13,7 @@ import prog8.compiler.target.c64.Petscii
import prog8.functions.BuiltinFunctions
import prog8.functions.NotConstArgumentException
import prog8.functions.builtinFunctionReturnType
import java.util.*
import java.util.Objects
import kotlin.math.abs

View File

@ -1,7 +1,8 @@
package prog8.ast.expressions
import java.util.Objects
import prog8.ast.base.DataType
import java.util.*
object InferredTypes {
class InferredType private constructor(val isUnknown: Boolean, val isVoid: Boolean, private var datatype: DataType?) {

View File

@ -16,7 +16,9 @@ import prog8.functions.BuiltinFunctions
import prog8.functions.FunctionSignature
import java.math.RoundingMode
import java.nio.file.Path
import java.util.*
import java.time.LocalDate
import java.time.LocalDateTime
import java.util.ArrayDeque
import kotlin.math.absoluteValue
@ -38,8 +40,8 @@ internal class AsmGen(val program: Program,
private val functioncallAsmGen = FunctionCallAsmGen(program, this)
private val assignmentAsmGen = AssignmentAsmGen(program, this)
private val expressionsAsmGen = ExpressionsAsmGen(program, this)
internal val loopEndLabels = Stack<String>()
internal val loopContinueLabels = Stack<String>()
internal val loopEndLabels = ArrayDeque<String>()
internal val loopContinueLabels = ArrayDeque<String>()
internal fun compileToAssembly(optimize: Boolean): AssemblyProgram {
assemblyLines.clear()
@ -74,7 +76,7 @@ internal class AsmGen(val program: Program,
private fun header() {
val ourName = this.javaClass.name
out("; 6502 assembly code for '${program.name}'")
out("; generated by $ourName on ${Date()}")
out("; generated by $ourName on ${LocalDateTime.now().withNano(0)}")
out("; assembler syntax is for the 64tasm cross-assembler")
out("; output options: output=${options.output} launcher=${options.launcher} zp=${options.zeropage}")
out("\n.cpu '6502'\n.enc 'none'\n")
@ -90,7 +92,7 @@ internal class AsmGen(val program: Program,
throw AssemblyError("BASIC output must have load address $0801")
out("; ---- basic program with sys call ----")
out("* = ${program.actualLoadAddress.toHex()}")
val year = Calendar.getInstance().get(Calendar.YEAR)
val year = LocalDate.now().year
out(" .word (+), $year")
out(" .null $9e, format(' %d ', _prog8_entrypoint), $3a, $8f, ' prog8 by idj'")
out("+\t.word 0")

View File

@ -8,7 +8,7 @@ import prog8.ast.expressions.NumericLiteralValue
import prog8.ast.expressions.StringLiteralValue
import prog8.compiler.target.c64.Petscii
import prog8.vm.astvm.VmExecutionException
import java.util.*
import java.util.Objects
import kotlin.math.abs
import kotlin.math.pow

View File

@ -12,7 +12,7 @@ import prog8.compiler.target.c64.Petscii
import prog8.vm.*
import java.awt.EventQueue
import java.io.CharConversionException
import java.util.*
import java.util.ArrayDeque
import kotlin.NoSuchElementException
import kotlin.concurrent.fixedRateTimer
import kotlin.math.*
@ -140,10 +140,10 @@ class AstVm(val program: Program) {
var rtcOffset = bootTime
private val rnd = Random(0)
private val statusFlagsSave = Stack<StatusFlags>()
private val registerXsave = Stack<RuntimeValueNumeric>()
private val registerYsave = Stack<RuntimeValueNumeric>()
private val registerAsave = Stack<RuntimeValueNumeric>()
private val statusFlagsSave = ArrayDeque<StatusFlags>()
private val registerXsave = ArrayDeque<RuntimeValueNumeric>()
private val registerYsave = ArrayDeque<RuntimeValueNumeric>()
private val registerAsave = ArrayDeque<RuntimeValueNumeric>()
init {

View File

@ -6,7 +6,7 @@ import java.awt.*
import java.awt.event.KeyEvent
import java.awt.event.KeyListener
import java.awt.image.BufferedImage
import java.util.*
import java.util.ArrayDeque
import javax.swing.JFrame
import javax.swing.JPanel
import javax.swing.Timer
@ -18,7 +18,7 @@ class BitmapScreenPanel : KeyListener, JPanel() {
private val g2d = image.graphics as Graphics2D
private var cursorX: Int=0
private var cursorY: Int=0
val keyboardBuffer: Deque<Char> = LinkedList()
val keyboardBuffer = ArrayDeque<Char>()
init {
val size = Dimension(image.width * SCALING, image.height * SCALING)

View File

@ -1,6 +1,8 @@
package sim65.components
import java.util.*
import java.time.LocalDate
import java.time.LocalTime
/**
* A real-time clock (time of day clock).
@ -17,8 +19,6 @@ import java.util.*
*/
class RealTimeClock(startAddress: Address, endAddress: Address) : MemMappedComponent(startAddress, endAddress) {
val calendar = Calendar.getInstance()
init {
require(endAddress - startAddress + 1 == 9) { "rtc needs exactly 9 memory bytes" }
}
@ -32,44 +32,29 @@ class RealTimeClock(startAddress: Address, endAddress: Address) : MemMappedCompo
}
override operator fun get(address: Address): UByte {
when (address - startAddress) {
return when (address - startAddress) {
0 -> {
val year = calendar.get(Calendar.YEAR)
return (year and 255).toShort()
val year = LocalDate.now().year
(year and 255).toShort()
}
1 -> {
val year = calendar.get(Calendar.YEAR)
return (year ushr 8).toShort()
}
2 -> {
val month = calendar.get(Calendar.MONTH) + 1
return month.toShort()
}
3 -> {
val day = calendar.get(Calendar.DAY_OF_MONTH)
return day.toShort()
}
4 -> {
val hour = calendar.get(Calendar.HOUR_OF_DAY)
return hour.toShort()
}
5 -> {
val minute = calendar.get(Calendar.MINUTE)
return minute.toShort()
}
6 -> {
val second = calendar.get(Calendar.SECOND)
return second.toShort()
val year = LocalDate.now().year
(year ushr 8).toShort()
}
2 -> LocalDate.now().monthValue.toShort()
3 -> LocalDate.now().dayOfMonth.toShort()
4 -> LocalTime.now().hour.toShort()
5 -> LocalTime.now().minute.toShort()
6 -> LocalTime.now().second.toShort()
7 -> {
val ms = calendar.get(Calendar.MILLISECOND)
return (ms and 255).toShort()
val ms = LocalTime.now().nano / 1000
(ms and 255).toShort()
}
8 -> {
val ms = calendar.get(Calendar.MILLISECOND)
return (ms ushr 8).toShort()
val ms = LocalTime.now().nano / 1000
(ms ushr 8).toShort()
}
else -> return 0
else -> 0
}
}