I’m writing a bytecode virtual machine. I have a Select statement that selects a UInt8 variable called opcode. I want to compare this with various constant values to see which opcode I’m dealing with. In the IDE when you create a “Number” constant, what type is it exactly? I’m assuming it’s an Int64 or Int32 depending on the platform. Is there a way to create a UInt8 constant in a module or class?
Select Case opcode // This is a UInt8
Case kOP_RETURN
// Handle return opcode
Else
// Unknown opcode
End Select
I can’t use an Enumeration because they seem to be Integers and there is overhead converting them. I’m thinking the only option is to create properties of type UInt8 and just hope I don’t accidentally modify them by mistake (if they were constants then the compiler would prevent that and would probably optimise their storage too as they are known at compile time).
[quote=429906:@Garry Pettet]I’m writing a bytecode virtual machine. I have a Select statement that selects a UInt8 variable called opcode. I want to compare this with various constant values to see which opcode I’m dealing with. In the IDE when you create a “Number” constant, what type is it exactly? I’m assuming it’s an Int64 or Int32 depending on the platform. Is there a way to create a UInt8 constant in a module or class?
Select Case opcode // This is a UInt8
Case kOP_RETURN
// Handle return opcode
Else
// Unknown opcode
End Select
I can’t use an Enumeration because they seem to be Integers and there is overhead converting them. I’m thinking the only option is to create properties of type UInt8 and just hope I don’t accidentally modify them by mistake (if they were constants then the compiler would prevent that and would probably optimise their storage too as they are known at compile time).[/quote]
You may be able to use CType(TheNumberConst, UInt8) so it will convert it to UINt8
Numeric constants don’t have a “type”… 123 could be used as an Integer, Single or Double… it would depend on the context where it was USED, not where it was created. The Xojo compiler takes the constants defined value and replaces it in all appropriate code locations prior to the compile step.