changed set/clear carry and irqd somewhat

This commit is contained in:
Irmen de Jong 2018-09-24 23:38:33 +02:00
parent cef0aae927
commit 70e5a38aa2
11 changed files with 37 additions and 34 deletions

View File

@ -8,8 +8,11 @@ sub start() -> () {
float f float f
word ww = $55aa word ww = $55aa
; P_carry(1) @todo function -> assignment set_carry()
; P_irqd(1) @todo function -> assignment clear_carry()
set_irqd()
clear_irqd()
f=flt(i) f=flt(i)
i = msb(ww) i = msb(ww)
i = lsb(ww) i = lsb(ww)

View File

@ -1137,7 +1137,7 @@ class FunctionCall(override var target: IdentifierReference,
"all" -> builtinAll(arglist, position, namespace) "all" -> builtinAll(arglist, position, namespace)
"floor" -> builtinFloor(arglist, position, namespace) "floor" -> builtinFloor(arglist, position, namespace)
"ceil" -> builtinCeil(arglist, position, namespace) "ceil" -> builtinCeil(arglist, position, namespace)
"lsl", "lsr", "rol", "rol2", "ror", "ror2", "P_carry", "P_irqd" -> "lsl", "lsr", "rol", "rol2", "ror", "ror2", "set_carry", "clear_carry", "set_irqd", "clear_irqd" ->
throw ExpressionError("builtin function ${target.nameInSource[0]} can't be used in expressions because it doesn't return a value", position) throw ExpressionError("builtin function ${target.nameInSource[0]} can't be used in expressions because it doesn't return a value", position)
else -> null else -> null
} }
@ -1169,7 +1169,8 @@ class FunctionCall(override var target: IdentifierReference,
return constVal.resultingDatatype(namespace) return constVal.resultingDatatype(namespace)
val stmt = target.targetStatement(namespace) ?: return null val stmt = target.targetStatement(namespace) ?: return null
if(stmt is BuiltinFunctionStatementPlaceholder) { if(stmt is BuiltinFunctionStatementPlaceholder) {
if(target.nameInSource[0] == "P_carry" || target.nameInSource[0]=="P_irqd") { if(target.nameInSource[0] == "set_carry" || target.nameInSource[0]=="set_irqd" ||
target.nameInSource[0] == "clear_carry" || target.nameInSource[0]=="clear_irqd") {
return null // these have no return value return null // these have no return value
} }
return builtinFunctionReturnType(target.nameInSource[0], this.arglist, namespace) return builtinFunctionReturnType(target.nameInSource[0], this.arglist, namespace)

View File

@ -506,16 +506,10 @@ class AstChecker(private val namespace: INameScope, private val compilerOptions:
private fun checkBuiltinFunctionCall(call: IFunctionCall, position: Position) { private fun checkBuiltinFunctionCall(call: IFunctionCall, position: Position) {
if(call.target.nameInSource.size==1 && BuiltinFunctionNames.contains(call.target.nameInSource[0])) { if(call.target.nameInSource.size==1 && BuiltinFunctionNames.contains(call.target.nameInSource[0])) {
val functionName = call.target.nameInSource[0] val functionName = call.target.nameInSource[0]
if(functionName=="P_carry" || functionName=="P_irqd") { if(functionName=="set_carry" || functionName=="set_irqd" || functionName=="clear_carry" || functionName=="clear_irqd") {
// these functions allow only 0 or 1 as argument // these functions have zero arguments
if(call.arglist.size!=1 || call.arglist[0] !is LiteralValue) { if(call.arglist.isNotEmpty())
checkResult.add(SyntaxError("$functionName requires one argument, 0 or 1", position)) checkResult.add(SyntaxError("$functionName has zero arguments", position))
} else {
val value = call.arglist[0] as LiteralValue
if(value.asIntegerValue==null || value.asIntegerValue < 0 || value.asIntegerValue > 1) {
checkResult.add(SyntaxError("$functionName requires one argument, 0 or 1", position))
}
}
} }
} }
} }

View File

@ -365,6 +365,10 @@ private class StatementTranslator(private val stackvmProg: StackVmProgram, priva
"ror" -> stackvmProg.instr(Opcode.ROR) "ror" -> stackvmProg.instr(Opcode.ROR)
"rol2" -> stackvmProg.instr(Opcode.ROL2) "rol2" -> stackvmProg.instr(Opcode.ROL2)
"ror2" -> stackvmProg.instr(Opcode.ROR2) "ror2" -> stackvmProg.instr(Opcode.ROR2)
"set_carry" -> stackvmProg.instr(Opcode.SEC)
"clear_carry" -> stackvmProg.instr(Opcode.CLC)
"set_irqd" -> stackvmProg.instr(Opcode.SEI)
"clear_irqd" -> stackvmProg.instr(Opcode.CLI)
else -> createSyscall(funcname) // call builtin function else -> createSyscall(funcname) // call builtin function
} }
} }

View File

@ -5,7 +5,7 @@ import kotlin.math.log2
val BuiltinFunctionNames = setOf( val BuiltinFunctionNames = setOf(
"P_carry", "P_irqd", "rol", "ror", "rol2", "ror2", "lsl", "lsr", "set_carry", "clear_carry", "set_irqd", "clear_irqd", "rol", "ror", "rol2", "ror2", "lsl", "lsr",
"sin", "cos", "abs", "acos", "asin", "tan", "atan", "rnd", "rndw", "rndf", "sin", "cos", "abs", "acos", "asin", "tan", "atan", "rnd", "rndw", "rndf",
"ln", "log2", "log10", "sqrt", "rad", "deg", "round", "floor", "ceil", "ln", "log2", "log10", "sqrt", "rad", "deg", "round", "floor", "ceil",
"max", "min", "avg", "sum", "len", "any", "all", "lsb", "msb", "flt", "max", "min", "avg", "sum", "len", "any", "all", "lsb", "msb", "flt",
@ -13,12 +13,12 @@ val BuiltinFunctionNames = setOf(
"_vm_write_str", "_vm_input_str", "_vm_gfx_clearscr", "_vm_gfx_pixel", "_vm_gfx_text" "_vm_write_str", "_vm_input_str", "_vm_gfx_clearscr", "_vm_gfx_pixel", "_vm_gfx_text"
) )
val BuiltinFunctionsWithoutSideEffects = BuiltinFunctionNames - setOf( val BuiltinFunctionsWithoutSideEffects = BuiltinFunctionNames - setOf(
"P_carry", "P_irqd", "lsl", "lsr", "rol", "ror", "rol2", "ror2", "set_carry", "clear_carry", "set_irqd", "clear_irqd", "lsl", "lsr", "rol", "ror", "rol2", "ror2",
"_vm_write_memchr", "_vm_write_memstr", "_vm_write_num", "_vm_write_char", "_vm_write_memchr", "_vm_write_memstr", "_vm_write_num", "_vm_write_char",
"_vm_write_str", "_vm_gfx_clearscr", "_vm_gfx_pixel", "_vm_gfx_text") "_vm_write_str", "_vm_gfx_clearscr", "_vm_gfx_pixel", "_vm_gfx_text")
fun builtinFunctionReturnType(function: String, args: List<IExpression>, namespace: INameScope): DataType? { fun builtinFunctionReturnType(function: String, args: List<IExpression>, namespace: INameScope): DataType? {
fun integerDatatypeFromArg(arg: IExpression): DataType { fun integerDatatypeFromArg(arg: IExpression): DataType {
val dt = arg.resultingDatatype(namespace) val dt = arg.resultingDatatype(namespace)
@ -50,10 +50,10 @@ fun builtinFunctionReturnType(function: String, args: List<IExpression>, namespa
"sqrt", "rad", "deg", "avg", "rndf", "flt" -> DataType.FLOAT "sqrt", "rad", "deg", "avg", "rndf", "flt" -> DataType.FLOAT
"lsb", "msb", "any", "all", "rnd" -> DataType.BYTE "lsb", "msb", "any", "all", "rnd" -> DataType.BYTE
"rndw" -> DataType.WORD "rndw" -> DataType.WORD
"rol", "rol2", "ror", "ror2", "P_carry", "P_irqd" -> null // no return value so no datatype "rol", "rol2", "ror", "ror2", "lsl", "lsr", "set_carry", "clear_carry", "set_irqd", "clear_irqd" -> null // no return value so no datatype
"abs" -> args.single().resultingDatatype(namespace) "abs" -> args.single().resultingDatatype(namespace)
"max", "min" -> datatypeFromListArg(args.single()) "max", "min" -> datatypeFromListArg(args.single())
"round", "floor", "ceil", "lsl", "lsr" -> integerDatatypeFromArg(args.single()) "round", "floor", "ceil" -> integerDatatypeFromArg(args.single())
"sum" -> { "sum" -> {
val dt=datatypeFromListArg(args.single()) val dt=datatypeFromListArg(args.single())
when(dt) { when(dt) {

View File

@ -1,8 +1,8 @@
package prog8.stackvm package prog8.stackvm
import prog8.ast.DataType import prog8.ast.DataType
import prog8.compiler.target.c64.Petscii
import prog8.compiler.target.c64.Mflpt5 import prog8.compiler.target.c64.Mflpt5
import prog8.compiler.target.c64.Petscii
import java.io.File import java.io.File
import java.io.PrintStream import java.io.PrintStream
import java.util.* import java.util.*

View File

@ -1,12 +1,12 @@
package prog8tests package prog8tests
import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers.* import org.hamcrest.Matchers.empty
import org.hamcrest.Matchers.equalTo
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance import org.junit.jupiter.api.TestInstance
import prog8.ast.* import prog8.ast.DataType
import prog8.stackvm.* import prog8.stackvm.*
import kotlin.math.floor
import kotlin.test.* import kotlin.test.*

View File

@ -1,13 +1,13 @@
package prog8tests package prog8tests
import prog8.compiler.*
import prog8.compiler.target.c64.*
import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers.closeTo import org.hamcrest.Matchers.closeTo
import org.hamcrest.Matchers.equalTo import org.hamcrest.Matchers.equalTo
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance import org.junit.jupiter.api.TestInstance
import prog8.ast.* import prog8.ast.*
import prog8.compiler.*
import prog8.compiler.target.c64.*
import prog8.stackvm.Value import prog8.stackvm.Value
import kotlin.test.assertEquals import kotlin.test.assertEquals
import kotlin.test.assertFailsWith import kotlin.test.assertFailsWith

View File

@ -2,8 +2,12 @@ package prog8tests
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance import org.junit.jupiter.api.TestInstance
import prog8.ast.* import prog8.ast.DataType
import prog8.stackvm.* import prog8.ast.ExpressionError
import prog8.ast.LiteralValue
import prog8.ast.Position
import prog8.stackvm.Value
import prog8.stackvm.VmExecutionException
import kotlin.test.* import kotlin.test.*

View File

@ -587,13 +587,10 @@ ror2(x)
It uses some extra logic to not consider the carry flag as extra rotation bit. It uses some extra logic to not consider the carry flag as extra rotation bit.
Modifies in-place, doesn't return a value (so can't be used in an expression). Modifies in-place, doesn't return a value (so can't be used in an expression).
P_carry(bit) set_carry() / clear_carry()
Set (or clear) the CPU status register Carry flag. No result value. Set (or clear) the CPU status register Carry flag. No result value.
(translated into ``SEC`` or ``CLC`` cpu instruction) (translated into ``SEC`` or ``CLC`` cpu instruction)
P_irqd(bit) set_irqd() / clear_irqd()
Set (or clear) the CPU status register Interrupt Disable flag. No result value. Set (or clear) the CPU status register Interrupt Disable flag. No result value.
(translated into ``SEI`` or ``CLI`` cpu instruction) (translated into ``SEI`` or ``CLI`` cpu instruction)
@todo remove P_carry and P_irqd as functions and turn them into assignments instead (allowing only 0 or 1 as value)

View File

@ -121,9 +121,9 @@ The following 6502 CPU hardware registers are directly usable in program code (a
- ``A``, ``X``, ``Y`` the three main cpu registers (8 bits) - ``A``, ``X``, ``Y`` the three main cpu registers (8 bits)
- ``AX``, ``AY``, ``XY`` surrogate 16-bit registers: LSB-order (lo/hi) combined register pairs - ``AX``, ``AY``, ``XY`` surrogate 16-bit registers: LSB-order (lo/hi) combined register pairs
- the status register (P) carry flag and interrupt disable flag can be written via the ``P_carry`` and ``P_irqd`` builtin functions. - the status register (P) carry flag and interrupt disable flag can be written via a couple of special
builtin functions (``set_carry()``, ``clear_carry()``, ``set_irqd()``, ``clear_irqd()``)
@todo remove P_carry and P_irqd as functions and turn them into assignments instead (allowing only 0 or 1 as value)
Subroutine Calling Conventions Subroutine Calling Conventions