77 lines
1.5 KiB
Go
77 lines
1.5 KiB
Go
package main
|
|
|
|
import (
|
|
"strconv"
|
|
)
|
|
|
|
type Lang_I8 int8
|
|
type Lang_I16 int16
|
|
type Lang_I32 int32
|
|
type Lang_I64 int64
|
|
|
|
type Lang_U8 uint8
|
|
type Lang_U16 uint16
|
|
type Lang_U32 uint32
|
|
type Lang_U64 uint64
|
|
|
|
var NumberTypeNames = [...]string{"i8", "i16", "i32", "i64", "u8", "u16", "u32", "u64", "f32", "f64"}
|
|
|
|
type PrimitiveType uint32
|
|
|
|
const (
|
|
Primitive_I8 PrimitiveType = iota
|
|
Primitive_I16
|
|
Primitive_I32
|
|
Primitive_I64
|
|
Primitive_U8
|
|
Primitive_U16
|
|
Primitive_U32
|
|
Primitive_U64
|
|
Primitive_F32
|
|
Primitive_F64
|
|
)
|
|
|
|
const InvalidValue = 0xEEEEEE // Magic value
|
|
|
|
func isSignedInt(primitiveType PrimitiveType) bool {
|
|
switch primitiveType {
|
|
case Primitive_I8, Primitive_I16, Primitive_I32, Primitive_I64:
|
|
return true
|
|
default:
|
|
return false
|
|
}
|
|
}
|
|
|
|
func isUnsignedInt(primitiveType PrimitiveType) bool {
|
|
switch primitiveType {
|
|
case Primitive_U8, Primitive_U16, Primitive_U32, Primitive_U64:
|
|
return true
|
|
default:
|
|
return false
|
|
}
|
|
}
|
|
|
|
func isFloatingPoint(primitiveType PrimitiveType) bool {
|
|
switch primitiveType {
|
|
case Primitive_F32, Primitive_F64:
|
|
return true
|
|
default:
|
|
return false
|
|
}
|
|
}
|
|
|
|
func getBits(primitiveType PrimitiveType) int {
|
|
switch primitiveType {
|
|
case Primitive_I8, Primitive_U8:
|
|
return 8
|
|
case Primitive_I16, Primitive_U16:
|
|
return 16
|
|
case Primitive_I32, Primitive_U32, Primitive_F32:
|
|
return 32
|
|
case Primitive_I64, Primitive_U64, Primitive_F64:
|
|
return 64
|
|
default:
|
|
panic("Passed an invalid type (" + strconv.FormatUint(uint64(primitiveType), 10) + ") to getBits()")
|
|
}
|
|
}
|