Implement compilation from files
This commit is contained in:
parent
655832e672
commit
e2f3ab756d
13
compiler.kt
13
compiler.kt
@ -271,8 +271,15 @@ fun parseInstructions(fileData: String): ShortArray {
|
|||||||
val commentIndex = lines[index].indexOf("#")
|
val commentIndex = lines[index].indexOf("#")
|
||||||
if(commentIndex > 0)
|
if(commentIndex > 0)
|
||||||
lines[index] = lines[index].substring(0, commentIndex)
|
lines[index] = lines[index].substring(0, commentIndex)
|
||||||
val insn = parseInstruction(lines[index], unit)
|
try{
|
||||||
if(insn != null) unit.registerInstruction(insn)
|
val insn = parseInstruction(lines[index], unit)
|
||||||
|
if(insn != null) unit.registerInstruction(insn)
|
||||||
|
}catch(e: Exception){
|
||||||
|
print("An error occurred when compiling (line $index)")
|
||||||
|
val message = e.message
|
||||||
|
if(message != null) print(":\n\t$message")
|
||||||
|
println()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return unit.compile()
|
return unit.compile()
|
||||||
}
|
}
|
||||||
@ -291,7 +298,7 @@ fun main(args: Array<String>){
|
|||||||
System.err.println("Given file doesn't exist!")
|
System.err.println("Given file doesn't exist!")
|
||||||
System.exit(-2)
|
System.exit(-2)
|
||||||
}
|
}
|
||||||
for(insn in parseInstructions("LOAD GR0,0xFF"))
|
for(insn in parseInstructions(file.readText()))
|
||||||
println(insn.toUHex())
|
println(insn.toUHex())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user