generated from rnentjes/kotlin-server-web-undertow
Remove legacy JVM-specific file system, shell, and related implementations; migrate to platform-agnostic and common main modules.
This commit is contained in:
46
src/commonMain/kotlin/mtmc/os/shell/builtins/LoadCommand.kt
Normal file
46
src/commonMain/kotlin/mtmc/os/shell/builtins/LoadCommand.kt
Normal file
@@ -0,0 +1,46 @@
|
||||
package mtmc.os.shell.builtins
|
||||
|
||||
import mtmc.emulator.MonTanaMiniComputer
|
||||
import mtmc.os.exec.Executable.Companion.load
|
||||
import mtmc.os.fs.FileSystem
|
||||
import mtmc.os.fs.Path
|
||||
import mtmc.os.shell.ShellCommand
|
||||
import mtmc.tokenizer.MTMCTokenizer
|
||||
|
||||
class LoadCommand : ShellCommand() {
|
||||
@Throws(Exception::class)
|
||||
override fun exec(tokens: MTMCTokenizer, computer: MonTanaMiniComputer) {
|
||||
val fs = computer.fileSystem
|
||||
val program = tokens.collapseTokensAsString()
|
||||
require(!(program == null || program.isBlank())) { "missing or required argument 'src'" }
|
||||
val srcPath: Path = getDiskPath(program, fs)
|
||||
|
||||
val exec = load(srcPath)
|
||||
computer.load(exec!!.code, exec.data, exec.graphics, exec.debugInfo)
|
||||
val source = tokens.source
|
||||
|
||||
// set up an argument if given
|
||||
if (tokens.more()) {
|
||||
val firstArgToken = tokens.consume()
|
||||
val startChar: Int = firstArgToken.start
|
||||
val arg = source.substring(startChar)
|
||||
val strippedArg = arg.trim()
|
||||
if (!strippedArg.isEmpty()) {
|
||||
computer.setArg(strippedArg)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override val help: String
|
||||
get() = """
|
||||
load <exec>
|
||||
- exec : path to an executable file
|
||||
""".trimIndent()
|
||||
|
||||
companion object {
|
||||
fun getDiskPath(pathString: String, fs: FileSystem): Path {
|
||||
val path = Path.of("disk" + fs.resolve(pathString))
|
||||
return path.toAbsolutePath()
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user