mirror of
https://github.com/irmen/prog8.git
synced 2025-02-20 03:29:01 +00:00
some type conversion opcodes added
This commit is contained in:
parent
70fe43a6ac
commit
6da048ba4c
@ -367,9 +367,9 @@ Defining a subroutine
|
|||||||
|
|
||||||
Subroutines are parts of the code that can be repeatedly invoked using a subroutine call from elsewhere.
|
Subroutines are parts of the code that can be repeatedly invoked using a subroutine call from elsewhere.
|
||||||
Their definition, using the sub statement, includes the specification of the required input- and output parameters.
|
Their definition, using the sub statement, includes the specification of the required input- and output parameters.
|
||||||
For now, only register based parameters are supported (A, X, Y and paired registers,
|
For now, only register based parameters are supported (A, X, Y and paired registers AX, AY and XY,
|
||||||
the carry status bit SC and the interrupt disable bit SI as specials).
|
and various flags of the status register P: Pc (carry), Pz (zero), Pn (negative), Pv (overflow).
|
||||||
For subroutine return values, the special SZ register is also available, it means the zero status bit.
|
For subroutine return values, it is the same (registers, status flags).
|
||||||
|
|
||||||
Subroutines can be defined in a Block, but also nested inside another subroutine. Everything is scoped accordingly.
|
Subroutines can be defined in a Block, but also nested inside another subroutine. Everything is scoped accordingly.
|
||||||
|
|
||||||
|
@ -11,19 +11,18 @@ import kotlin.system.exitProcess
|
|||||||
|
|
||||||
|
|
||||||
fun main(args: Array<String>) {
|
fun main(args: Array<String>) {
|
||||||
try {
|
|
||||||
println("\nIL65 compiler by Irmen de Jong (irmen@razorvine.net)")
|
println("\nIL65 compiler by Irmen de Jong (irmen@razorvine.net)")
|
||||||
println("This software is licensed under the GNU GPL 3.0, see https://www.gnu.org/licenses/gpl.html\n")
|
println("This software is licensed under the GNU GPL 3.0, see https://www.gnu.org/licenses/gpl.html\n")
|
||||||
|
|
||||||
// import main module and process additional imports
|
|
||||||
|
|
||||||
if(args.size != 1) {
|
if(args.size != 1) {
|
||||||
System.err.println("module filename argument missing")
|
System.err.println("requires one argument: name of module file")
|
||||||
exitProcess(1)
|
exitProcess(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
val startTime = System.currentTimeMillis()
|
val startTime = System.currentTimeMillis()
|
||||||
val filepath = Paths.get(args[0]).normalize()
|
val filepath = Paths.get(args[0]).normalize()
|
||||||
|
|
||||||
|
try {
|
||||||
|
// import main module and process additional imports
|
||||||
val moduleAst = importModule(filepath)
|
val moduleAst = importModule(filepath)
|
||||||
moduleAst.linkParents()
|
moduleAst.linkParents()
|
||||||
val globalNameSpaceBeforeOptimization = moduleAst.definingScope()
|
val globalNameSpaceBeforeOptimization = moduleAst.definingScope()
|
||||||
|
@ -11,6 +11,7 @@ import java.util.regex.Pattern
|
|||||||
import javax.swing.Timer
|
import javax.swing.Timer
|
||||||
import kotlin.math.max
|
import kotlin.math.max
|
||||||
import kotlin.math.pow
|
import kotlin.math.pow
|
||||||
|
import kotlin.system.exitProcess
|
||||||
|
|
||||||
enum class Opcode {
|
enum class Opcode {
|
||||||
|
|
||||||
@ -66,6 +67,12 @@ enum class Opcode {
|
|||||||
LSB,
|
LSB,
|
||||||
MSB,
|
MSB,
|
||||||
|
|
||||||
|
// numeric type conversions not covered by other opcodes
|
||||||
|
B2WORD, // convert a byte into a word where it is the lower eight bits $00xx
|
||||||
|
MSB2WORD, // convert a byte into a word where it is the upper eight bits $xx00
|
||||||
|
B2FLOAT, // convert byte into floating point
|
||||||
|
W2FLOAT, // convert word into floating point
|
||||||
|
|
||||||
// logical operations
|
// logical operations
|
||||||
AND,
|
AND,
|
||||||
OR,
|
OR,
|
||||||
@ -1221,6 +1228,38 @@ class StackVm(val traceOutputFile: String?) {
|
|||||||
val (top, second) = evalstack.pop2()
|
val (top, second) = evalstack.pop2()
|
||||||
evalstack.push(second.compareNotEqual(top))
|
evalstack.push(second.compareNotEqual(top))
|
||||||
}
|
}
|
||||||
|
Opcode.B2WORD -> {
|
||||||
|
val byte = evalstack.pop()
|
||||||
|
if(byte.type==DataType.BYTE) {
|
||||||
|
evalstack.push(Value(DataType.WORD, byte.integerValue()))
|
||||||
|
} else {
|
||||||
|
throw VmExecutionException("attempt to make a word from a non-byte value $byte")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Opcode.MSB2WORD -> {
|
||||||
|
val byte = evalstack.pop()
|
||||||
|
if(byte.type==DataType.BYTE) {
|
||||||
|
evalstack.push(Value(DataType.WORD, byte.integerValue() * 256))
|
||||||
|
} else {
|
||||||
|
throw VmExecutionException("attempt to make a word from a non-byte value $byte")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Opcode.B2FLOAT -> {
|
||||||
|
val byte = evalstack.pop()
|
||||||
|
if(byte.type==DataType.BYTE) {
|
||||||
|
evalstack.push(Value(DataType.FLOAT, byte.integerValue()))
|
||||||
|
} else {
|
||||||
|
throw VmExecutionException("attempt to make a float from a non-byte value $byte")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Opcode.W2FLOAT -> {
|
||||||
|
val byte = evalstack.pop()
|
||||||
|
if(byte.type==DataType.WORD) {
|
||||||
|
evalstack.push(Value(DataType.FLOAT, byte.integerValue()))
|
||||||
|
} else {
|
||||||
|
throw VmExecutionException("attempt to make a float from a non-word value $byte")
|
||||||
|
}
|
||||||
|
}
|
||||||
else -> throw VmExecutionException("unimplemented opcode: ${ins.opcode}")
|
else -> throw VmExecutionException("unimplemented opcode: ${ins.opcode}")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1235,6 +1274,13 @@ class StackVm(val traceOutputFile: String?) {
|
|||||||
|
|
||||||
|
|
||||||
fun main(args: Array<String>) {
|
fun main(args: Array<String>) {
|
||||||
|
println("\nStackVM by Irmen de Jong (irmen@razorvine.net)")
|
||||||
|
println("This software is licensed under the GNU GPL 3.0, see https://www.gnu.org/licenses/gpl.html\n")
|
||||||
|
if(args.size != 1) {
|
||||||
|
System.err.println("requires one argument: name of stackvm sourcecode file")
|
||||||
|
exitProcess(1)
|
||||||
|
}
|
||||||
|
|
||||||
val program = Program.load(args.first())
|
val program = Program.load(args.first())
|
||||||
val vm = StackVm(traceOutputFile = null)
|
val vm = StackVm(traceOutputFile = null)
|
||||||
val dialog = ScreenDialog()
|
val dialog = ScreenDialog()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user