cdts creado, refinando ctype y cvalue

master
dev 1 year ago
parent 6ac5c4a6f5
commit 775d64b147

@ -66,4 +66,6 @@ func main() {
e := cdts.CreateCValue(an)
fmt.Printf("%v+ --> tipo : %s estado :%s \n",e,e.Type().String(),e.State().String())
}

@ -29,9 +29,34 @@
package cdts
import (
"context"
"math"
"time"
)
type (
// Alias para tipos usados provenientes de otros modulos
Date = time.Time
Duration = time.Duration
Bytes = []uint8
Stack = []interface { m () int }
Context = context.Context
Packable = interface { a()}
MapPackable = interface { p()}
ObjectPackable = interface {}
ListPackable = interface {}
ints interface { int | int8 | int16 | int32 | int64 }
uints interface { uint | uint8 | uint16 | uint32 | uint64 }
numsEnt interface { ints | uints }
)
var (

@ -105,7 +105,7 @@ const (
const (
// Mascaras de bits
maskCTypeComposite = CTypeList | CTypeMap | CTypePackable
maskCTypeComposite = CTypeList | CTypeMap | CTypeLazy
maskCTypeBase = ^(maskCTypeComposite|CTypeMapKey)
maskCTypeInt = CTypeInt | CTypeInt8 | CTypeInt16 | CTypeInt32 | CTypeInt64
@ -137,6 +137,8 @@ func (t CType) BaseType () CType {
return vt
}
func (t CType) CompositeType() CType { return t&maskCTypeComposite }
func (t CType) IsLazy () bool { return t&CTypeLazy != 0 }
func (t CType) IsList () bool { return t&CTypeList != 0 }
func (t CType) IsMap () bool { return t&CTypeMap != 0 }

@ -50,59 +50,49 @@ func newCTypeInfos() *cTypeInfos {
mux : sync.RWMutex{},
cache: make(map[reflect.Type]func(value reflect.Value)CValue),
types: [maxCTypes+1]cTypeInfo{
/* 0 */ createCTypeInfo[any ](CTypeInvalid,"invalid" ,createCValueInvalid,
func(i *cTypeInfo) {
i.creators[createByPtr] = createCValueInvalid
i.creators[createByList] = createCValueInvalid
i.creators[createByLazy] = createCValueInvalid
}),
/* 1 */createCTypeInfo [any ](CTypeAny ,"any" ,CreateCValueAny),
/* 2 */createCTypeInfo [bool ](CTypeBool ,"bool" ,CreateCValueBool),
/* 3 */createCTypeInfo [int ](CTypeInt ,"int" ,CreateCValueInt),
/* 4 */createCTypeInfo [int8 ](CTypeInt8 ,"int8" ,CreateCValueInt8),
/* 5 */createCTypeInfo [int16 ](CTypeInt16 ,"int16" ,CreateCValueInt16),
/* 6 */createCTypeInfo [int32 ](CTypeInt32 ,"int32" ,CreateCValueInt32),
/* 7 */createCTypeInfo [int64 ](CTypeInt64 ,"int64" ,CreateCValueInt64),
/* 8 */createCTypeInfo [uint ](CTypeUint ,"uint" ,CreateCValueUint),
/* 9 */createCTypeInfo [uint8 ](CTypeUint8 ,"uint8" ,CreateCValueUint8,
/* 0 */createCTypeInfo[any ](CTypeInvalid ,"invalid" ,createCValueInvalid),
/* 1 */createCTypeInfo [any ](CTypeAny ,"any" ,CreateCValueAny),
/* 2 */createCTypeInfo [bool ](CTypeBool ,"bool" ,CreateCValueBool),
/* 3 */createCTypeInfo [int ](CTypeInt ,"int" ,CreateCValueInt),
/* 4 */createCTypeInfo [int8 ](CTypeInt8 ,"int8" ,CreateCValueInt8),
/* 5 */createCTypeInfo [int16 ](CTypeInt16 ,"int16" ,CreateCValueInt16),
/* 6 */createCTypeInfo [int32 ](CTypeInt32 ,"int32" ,CreateCValueInt32),
/* 7 */createCTypeInfo [int64 ](CTypeInt64 ,"int64" ,CreateCValueInt64),
/* 8 */createCTypeInfo [uint ](CTypeUint ,"uint" ,CreateCValueUint),
/* 9 */createCTypeInfo [uint8 ](CTypeUint8 ,"uint8" ,CreateCValueUint8,
// El []uint8 debe de ser considerado como de tipo bytes
func(i *cTypeInfo) {
i.creators[createByList] = func(v any) CValue { return CreateCValueBytes(v.([]uint8)) }
}),
/* 10 */createCTypeInfo [uint16 ](CTypeUint16 ,"uint16" ,CreateCValueUint16),
/* 11 */createCTypeInfo [uint32 ](CTypeUint32 ,"uint32" ,CreateCValueUint32),
/* 12 */createCTypeInfo [uint64 ](CTypeUint64 ,"uint64" ,CreateCValueUint64),
/* 13 */createCTypeInfo [uintptr ](CTypeUintptr ,"uintptr" ,CreateCValueUintptr),
/* 14 */createCTypeInfo [float32 ](CTypeFloat32 ,"float32" ,CreateCValueFloat32),
/* 15 */createCTypeInfo [float64 ](CTypeFloat64 ,"float64" ,CreateCValueFloat64),
/* 16 */createCTypeInfo [complex64 ](CTypeComplex64,"complex64" ,CreateCValueComplex64),
/* 17 */createCTypeInfo [complex128 ](CTypeComplex128,"complex128" ,CreateCValueComplex128),
/* 18 */createCTypeInfo [Date ](CTypeDate ,"date" ,CreateCValueDate),
/* 19 */createCTypeInfo [Duration ](CTypeDuration ,"duration" ,CreateCValueDuration),
/* 20 */createCTypeInfo [string ](CTypeString ,"string" ,CreateCValueString),
/* 21 */createCTypeInfo [Bytes ](CTypeBytes ,"bytes" ,CreateCValueBytes),
/* 22 */createCTypeInfo [Stack ](CTypeStack ,"stack" ,CreateCValueStack),
/* 23 */createCTypeInfo [CValue ](CTypeCValue ,"cvalue" ,createCValueCValue),
/* 24 */createCTypeInfo [Packable ](CTypePackable ,"packable" ,CreateCValuePackable),
/* 25 */createCTypeInfo [Context ](CTypeContext ,"context" ,CreateCValueContext),
/* 26 */createCTypeInfo [error ](CTypeError ,"error" ,CreateCValueError),
/* 27 */createCTypeInfo [any ](CTypeNil ,"nil" ,CreateCValueNil),
/* 10 */createCTypeInfo [uint16 ](CTypeUint16 ,"uint16" ,CreateCValueUint16),
/* 11 */createCTypeInfo [uint32 ](CTypeUint32 ,"uint32" ,CreateCValueUint32),
/* 12 */createCTypeInfo [uint64 ](CTypeUint64 ,"uint64" ,CreateCValueUint64),
/* 13 */createCTypeInfo [uintptr ](CTypeUintptr ,"uintptr" ,CreateCValueUintptr),
/* 14 */createCTypeInfo [float32 ](CTypeFloat32 ,"float32" ,CreateCValueFloat32),
/* 15 */createCTypeInfo [float64 ](CTypeFloat64 ,"float64" ,CreateCValueFloat64),
/* 16 */createCTypeInfo [complex64 ](CTypeComplex64,"complex64" ,CreateCValueComplex64),
/* 17 */createCTypeInfo [complex128 ](CTypeComplex128,"complex128",CreateCValueComplex128),
/* 18 */createCTypeInfo [Date ](CTypeDate ,"date" ,CreateCValueDate),
/* 19 */createCTypeInfo [Duration ](CTypeDuration ,"duration" ,CreateCValueDuration),
/* 20 */createCTypeInfo [string ](CTypeString ,"string" ,CreateCValueString),
/* 21 */createCTypeInfo [Bytes ](CTypeBytes ,"bytes" ,CreateCValueBytes),
/* 22 */createCTypeInfo [Stack ](CTypeStack ,"stack" ,CreateCValueStack),
/* 23 */createCTypeInfo [CValue ](CTypeCValue ,"cvalue" ,createCValueCValue),
/* 24 */createCTypeInfo [Packable ](CTypePackable ,"packable" ,CreateCValuePackable),
/* 25 */createCTypeInfo [Context ](CTypeContext ,"context" ,CreateCValueContext),
/* 26 */createCTypeInfo [error ](CTypeError ,"error" ,CreateCValueError),
/* 27 */createCTypeInfo [any ](CTypeNil ,"nil" ,CreateCValueNil),
// Los tipos compuestos, solo pueden crearse por reflexion, las listas de los tipos claves ya estan
// definidas en el switch .(Type)
/* 28 */createCTypeInfo [any ](CTypeObject ,"object" ,createCValueInvalid),
/* 29 */createCTypeInfo [any ](CTypeLazy ,"lazy" ,createCValueInvalid),
/* 30 */createCTypeInfo [any ](CTypeList ,"list" ,createCValueInvalid),
/* 31 */createCTypeInfo [any ](CTypeMap ,"map" ,createCValueInvalid),
// Corresponde con el bit del flag del tipo de mapa, por lo que no puede generar un cvalue valido
/* 32 */createCTypeInfo [any ](CTypeInvalid,"invalid" ,createCValueInvalid),
/* 28 */createCTypeInfo [any ](CTypeObject ,"object" ,createCValueInvalid),
/* 29 */createCTypeInfo [any ](CTypeLazy ,"lazy" ,createCValueInvalid),
/* 30 */createCTypeInfo [any ](CTypeList ,"list" ,createCValueInvalid),
/* 31 */createCTypeInfo [any ](CTypeMap ,"map" ,createCValueInvalid),
//corresponde con el bit del flag del tipo de mapa, por lo que no puede generar un cvalue valido
/* 32 */createCTypeInfo [any ](CTypeInvalid ,"invalid" ,createCValueInvalid),
},
}
@ -124,7 +114,7 @@ func (i *cTypeInfos) getName(cType CType) string {
return "map@" + i.getName(k) + "|" + i.getName(v)
}
}
return i.types[getPos(cType)].name
return i.types[GetPos(cType)].name
}
@ -138,119 +128,119 @@ func (i *cTypeInfos) createCValue (value any) CValue {
switch value.(type) {
/* Valores simples */
//case any : f = i.types[getPos(CTypeAny )].creators[createByValue]
case bool : f = i.types[getPos(CTypeBool )].creators[createByValue]
case int : f = i.types[getPos(CTypeInt )].creators[createByValue]
case int8 : f = i.types[getPos(CTypeInt8 )].creators[createByValue]
case int16 : f = i.types[getPos(CTypeInt16 )].creators[createByValue]
case int32 : f = i.types[getPos(CTypeInt32 )].creators[createByValue]
case int64 : f = i.types[getPos(CTypeInt64 )].creators[createByValue]
case uint : f = i.types[getPos(CTypeUint )].creators[createByValue]
case uint8 : f = i.types[getPos(CTypeUint8 )].creators[createByValue]
case uint16 : f = i.types[getPos(CTypeUint16 )].creators[createByValue]
case uint32 : f = i.types[getPos(CTypeUint32 )].creators[createByValue]
case uint64 : f = i.types[getPos(CTypeUint64 )].creators[createByValue]
case uintptr : f = i.types[getPos(CTypeUintptr )].creators[createByValue]
case float32 : f = i.types[getPos(CTypeFloat32 )].creators[createByValue]
case float64 : f = i.types[getPos(CTypeFloat64 )].creators[createByValue]
case complex64 : f = i.types[getPos(CTypeComplex64 )].creators[createByValue]
case complex128 : f = i.types[getPos(CTypeComplex128)].creators[createByValue]
case Date : f = i.types[getPos(CTypeDate )].creators[createByValue]
case Duration : f = i.types[getPos(CTypeDuration )].creators[createByValue]
case string : f = i.types[getPos(CTypeString )].creators[createByValue]
case Bytes : f = i.types[getPos(CTypeBytes )].creators[createByValue]
case Stack : f = i.types[getPos(CTypeStack )].creators[createByValue]
case CValue : f = i.types[getPos(CTypeCValue )].creators[createByValue]
case Packable : f = i.types[getPos(CTypePackable )].creators[createByValue]
case Context : f = i.types[getPos(CTypeContext )].creators[createByValue]
case error : f = i.types[getPos(CTypeError )].creators[createByValue]
//case any : f = i.types[GetPos(CTypeAny )].creators[createByValue]
case bool : f = i.types[GetPos(CTypeBool )].creators[createByValue]
case int : f = i.types[GetPos(CTypeInt )].creators[createByValue]
case int8 : f = i.types[GetPos(CTypeInt8 )].creators[createByValue]
case int16 : f = i.types[GetPos(CTypeInt16 )].creators[createByValue]
case int32 : f = i.types[GetPos(CTypeInt32 )].creators[createByValue]
case int64 : f = i.types[GetPos(CTypeInt64 )].creators[createByValue]
case uint : f = i.types[GetPos(CTypeUint )].creators[createByValue]
case uint8 : f = i.types[GetPos(CTypeUint8 )].creators[createByValue]
case uint16 : f = i.types[GetPos(CTypeUint16 )].creators[createByValue]
case uint32 : f = i.types[GetPos(CTypeUint32 )].creators[createByValue]
case uint64 : f = i.types[GetPos(CTypeUint64 )].creators[createByValue]
case uintptr : f = i.types[GetPos(CTypeUintptr )].creators[createByValue]
case float32 : f = i.types[GetPos(CTypeFloat32 )].creators[createByValue]
case float64 : f = i.types[GetPos(CTypeFloat64 )].creators[createByValue]
case complex64 : f = i.types[GetPos(CTypeComplex64 )].creators[createByValue]
case complex128 : f = i.types[GetPos(CTypeComplex128)].creators[createByValue]
case Date : f = i.types[GetPos(CTypeDate )].creators[createByValue]
case Duration : f = i.types[GetPos(CTypeDuration )].creators[createByValue]
case string : f = i.types[GetPos(CTypeString )].creators[createByValue]
case Bytes : f = i.types[GetPos(CTypeBytes )].creators[createByValue]
case Stack : f = i.types[GetPos(CTypeStack )].creators[createByValue]
case CValue : f = i.types[GetPos(CTypeCValue )].creators[createByValue]
case Packable : f = i.types[GetPos(CTypePackable )].creators[createByValue]
case Context : f = i.types[GetPos(CTypeContext )].creators[createByValue]
case error : f = i.types[GetPos(CTypeError )].creators[createByValue]
/* Valores Listas */
case []any : f = i.types[getPos(CTypeAny )].creators[createByList]
case []bool : f = i.types[getPos(CTypeBool )].creators[createByList]
case []int : f = i.types[getPos(CTypeInt )].creators[createByList]
case []int8 : f = i.types[getPos(CTypeInt8 )].creators[createByList]
case []int16 : f = i.types[getPos(CTypeInt16 )].creators[createByList]
case []int32 : f = i.types[getPos(CTypeInt32 )].creators[createByList]
case []int64 : f = i.types[getPos(CTypeInt64 )].creators[createByList]
case []uint : f = i.types[getPos(CTypeUint )].creators[createByList]
case []any : f = i.types[GetPos(CTypeAny )].creators[createByList]
case []bool : f = i.types[GetPos(CTypeBool )].creators[createByList]
case []int : f = i.types[GetPos(CTypeInt )].creators[createByList]
case []int8 : f = i.types[GetPos(CTypeInt8 )].creators[createByList]
case []int16 : f = i.types[GetPos(CTypeInt16 )].creators[createByList]
case []int32 : f = i.types[GetPos(CTypeInt32 )].creators[createByList]
case []int64 : f = i.types[GetPos(CTypeInt64 )].creators[createByList]
case []uint : f = i.types[GetPos(CTypeUint )].creators[createByList]
// ya establecido como tipo base Bytes
//case []uint8 :
//
case []uint16 : f = i.types[getPos(CTypeUint16 )].creators[createByList]
case []uint32 : f = i.types[getPos(CTypeUint32 )].creators[createByList]
case []uint64 : f = i.types[getPos(CTypeUint64 )].creators[createByList]
case []uintptr : f = i.types[getPos(CTypeUintptr )].creators[createByList]
case []float32 : f = i.types[getPos(CTypeFloat32 )].creators[createByList]
case []float64 : f = i.types[getPos(CTypeFloat64 )].creators[createByList]
case []complex64: f = i.types[getPos(CTypeComplex64 )].creators[createByList]
case []complex128:f = i.types[getPos(CTypeComplex128)].creators[createByList]
case []Duration : f = i.types[getPos(CTypeDate )].creators[createByList]
case []Date : f = i.types[getPos(CTypeDuration )].creators[createByList]
case []string : f = i.types[getPos(CTypeString )].creators[createByList]
case []Bytes : f = i.types[getPos(CTypeBytes )].creators[createByList]
case []Stack : f = i.types[getPos(CTypeStack )].creators[createByList]
case []CValue : f = i.types[getPos(CTypeCValue )].creators[createByList]
case []Packable : f = i.types[getPos(CTypePackable )].creators[createByList]
case []Context : f = i.types[getPos(CTypeContext )].creators[createByList]
case []error : f = i.types[getPos(CTypeError )].creators[createByList]
case []uint16 : f = i.types[GetPos(CTypeUint16 )].creators[createByList]
case []uint32 : f = i.types[GetPos(CTypeUint32 )].creators[createByList]
case []uint64 : f = i.types[GetPos(CTypeUint64 )].creators[createByList]
case []uintptr : f = i.types[GetPos(CTypeUintptr )].creators[createByList]
case []float32 : f = i.types[GetPos(CTypeFloat32 )].creators[createByList]
case []float64 : f = i.types[GetPos(CTypeFloat64 )].creators[createByList]
case []complex64: f = i.types[GetPos(CTypeComplex64 )].creators[createByList]
case []complex128:f = i.types[GetPos(CTypeComplex128)].creators[createByList]
case []Duration : f = i.types[GetPos(CTypeDate )].creators[createByList]
case []Date : f = i.types[GetPos(CTypeDuration )].creators[createByList]
case []string : f = i.types[GetPos(CTypeString )].creators[createByList]
case []Bytes : f = i.types[GetPos(CTypeBytes )].creators[createByList]
case []Stack : f = i.types[GetPos(CTypeStack )].creators[createByList]
case []CValue : f = i.types[GetPos(CTypeCValue )].creators[createByList]
case []Packable : f = i.types[GetPos(CTypePackable )].creators[createByList]
case []Context : f = i.types[GetPos(CTypeContext )].creators[createByList]
case []error : f = i.types[GetPos(CTypeError )].creators[createByList]
/* Valores pasados por punteros */
//case *any : f = i.types[ 1/* Any */].creators[createByPtr]
case *bool : f = i.types[getPos(CTypeBool )].creators[createByPtr]
case *int : f = i.types[getPos(CTypeInt )].creators[createByPtr]
case *int8 : f = i.types[getPos(CTypeInt8 )].creators[createByPtr]
case *int16 : f = i.types[getPos(CTypeInt16 )].creators[createByPtr]
case *int32 : f = i.types[getPos(CTypeInt32 )].creators[createByPtr]
case *int64 : f = i.types[getPos(CTypeInt64 )].creators[createByPtr]
case *uint : f = i.types[getPos(CTypeUint )].creators[createByPtr]
case *uint8 : f = i.types[getPos(CTypeUint8 )].creators[createByPtr]
case *uint16 : f = i.types[getPos(CTypeUint16 )].creators[createByPtr]
case *uint32 : f = i.types[getPos(CTypeUint32 )].creators[createByPtr]
case *uint64 : f = i.types[getPos(CTypeUint64 )].creators[createByPtr]
case *uintptr : f = i.types[getPos(CTypeUintptr )].creators[createByPtr]
case *float32 : f = i.types[getPos(CTypeFloat32 )].creators[createByPtr]
case *float64 : f = i.types[getPos(CTypeFloat64 )].creators[createByPtr]
case *complex64 : f = i.types[getPos(CTypeComplex64 )].creators[createByPtr]
case *complex128: f = i.types[getPos(CTypeComplex128)].creators[createByPtr]
case *Duration : f = i.types[getPos(CTypeDate )].creators[createByPtr]
case *Date : f = i.types[getPos(CTypeDuration )].creators[createByPtr]
case *string : f = i.types[getPos(CTypeString )].creators[createByPtr]
case *Bytes : f = i.types[getPos(CTypeBytes )].creators[createByPtr]
case *Stack : f = i.types[getPos(CTypeStack )].creators[createByPtr]
case *CValue : f = i.types[getPos(CTypeCValue )].creators[createByPtr]
case *Packable : f = i.types[getPos(CTypePackable )].creators[createByPtr]
case *Context : f = i.types[getPos(CTypeContext )].creators[createByPtr]
case *error : f = i.types[getPos(CTypeError )].creators[createByPtr]
case *bool : f = i.types[GetPos(CTypeBool )].creators[createByPtr]
case *int : f = i.types[GetPos(CTypeInt )].creators[createByPtr]
case *int8 : f = i.types[GetPos(CTypeInt8 )].creators[createByPtr]
case *int16 : f = i.types[GetPos(CTypeInt16 )].creators[createByPtr]
case *int32 : f = i.types[GetPos(CTypeInt32 )].creators[createByPtr]
case *int64 : f = i.types[GetPos(CTypeInt64 )].creators[createByPtr]
case *uint : f = i.types[GetPos(CTypeUint )].creators[createByPtr]
case *uint8 : f = i.types[GetPos(CTypeUint8 )].creators[createByPtr]
case *uint16 : f = i.types[GetPos(CTypeUint16 )].creators[createByPtr]
case *uint32 : f = i.types[GetPos(CTypeUint32 )].creators[createByPtr]
case *uint64 : f = i.types[GetPos(CTypeUint64 )].creators[createByPtr]
case *uintptr : f = i.types[GetPos(CTypeUintptr )].creators[createByPtr]
case *float32 : f = i.types[GetPos(CTypeFloat32 )].creators[createByPtr]
case *float64 : f = i.types[GetPos(CTypeFloat64 )].creators[createByPtr]
case *complex64 : f = i.types[GetPos(CTypeComplex64 )].creators[createByPtr]
case *complex128: f = i.types[GetPos(CTypeComplex128)].creators[createByPtr]
case *Duration : f = i.types[GetPos(CTypeDate )].creators[createByPtr]
case *Date : f = i.types[GetPos(CTypeDuration )].creators[createByPtr]
case *string : f = i.types[GetPos(CTypeString )].creators[createByPtr]
case *Bytes : f = i.types[GetPos(CTypeBytes )].creators[createByPtr]
case *Stack : f = i.types[GetPos(CTypeStack )].creators[createByPtr]
case *CValue : f = i.types[GetPos(CTypeCValue )].creators[createByPtr]
case *Packable : f = i.types[GetPos(CTypePackable )].creators[createByPtr]
case *Context : f = i.types[GetPos(CTypeContext )].creators[createByPtr]
case *error : f = i.types[GetPos(CTypeError )].creators[createByPtr]
/* Valores pasados por functions Lazys */
case func()any : f = i.types[getPos(CTypeAny )].creators[createByLazy]
case func()bool : f = i.types[getPos(CTypeBool )].creators[createByLazy]
case func()int : f = i.types[getPos(CTypeInt )].creators[createByLazy]
case func()int8 : f = i.types[getPos(CTypeInt8 )].creators[createByLazy]
case func()int16 : f = i.types[getPos(CTypeInt16 )].creators[createByLazy]
case func()int32 : f = i.types[getPos(CTypeInt32 )].creators[createByLazy]
case func()int64 : f = i.types[getPos(CTypeInt64 )].creators[createByLazy]
case func()uint : f = i.types[getPos(CTypeUint )].creators[createByLazy]
case func()uint8 : f = i.types[getPos(CTypeUint8 )].creators[createByLazy]
case func()uint16 : f = i.types[getPos(CTypeUint16 )].creators[createByLazy]
case func()uint32 : f = i.types[getPos(CTypeUint32 )].creators[createByLazy]
case func()uint64 : f = i.types[getPos(CTypeUint64 )].creators[createByLazy]
case func()uintptr : f = i.types[getPos(CTypeUintptr )].creators[createByLazy]
case func()float32 : f = i.types[getPos(CTypeFloat32 )].creators[createByLazy]
case func()float64 : f = i.types[getPos(CTypeFloat64 )].creators[createByLazy]
case func()complex64: f = i.types[getPos(CTypeComplex64 )].creators[createByLazy]
case func()complex128:f = i.types[getPos(CTypeComplex128)].creators[createByLazy]
case func()Duration : f = i.types[getPos(CTypeDate )].creators[createByLazy]
case func()Date : f = i.types[getPos(CTypeDuration )].creators[createByLazy]
case func()string : f = i.types[getPos(CTypeString )].creators[createByLazy]
case func()Bytes : f = i.types[getPos(CTypeBytes )].creators[createByLazy]
case func()Stack : f = i.types[getPos(CTypeStack )].creators[createByLazy]
case func()CValue : f = i.types[getPos(CTypeCValue )].creators[createByLazy]
case func()Packable : f = i.types[getPos(CTypePackable )].creators[createByLazy]
case func()Context : f = i.types[getPos(CTypeContext )].creators[createByLazy]
case func()error : f = i.types[getPos(CTypeError )].creators[createByLazy]
case func()any : f = i.types[GetPos(CTypeAny )].creators[createByLazy]
case func()bool : f = i.types[GetPos(CTypeBool )].creators[createByLazy]
case func()int : f = i.types[GetPos(CTypeInt )].creators[createByLazy]
case func()int8 : f = i.types[GetPos(CTypeInt8 )].creators[createByLazy]
case func()int16 : f = i.types[GetPos(CTypeInt16 )].creators[createByLazy]
case func()int32 : f = i.types[GetPos(CTypeInt32 )].creators[createByLazy]
case func()int64 : f = i.types[GetPos(CTypeInt64 )].creators[createByLazy]
case func()uint : f = i.types[GetPos(CTypeUint )].creators[createByLazy]
case func()uint8 : f = i.types[GetPos(CTypeUint8 )].creators[createByLazy]
case func()uint16 : f = i.types[GetPos(CTypeUint16 )].creators[createByLazy]
case func()uint32 : f = i.types[GetPos(CTypeUint32 )].creators[createByLazy]
case func()uint64 : f = i.types[GetPos(CTypeUint64 )].creators[createByLazy]
case func()uintptr : f = i.types[GetPos(CTypeUintptr )].creators[createByLazy]
case func()float32 : f = i.types[GetPos(CTypeFloat32 )].creators[createByLazy]
case func()float64 : f = i.types[GetPos(CTypeFloat64 )].creators[createByLazy]
case func()complex64: f = i.types[GetPos(CTypeComplex64 )].creators[createByLazy]
case func()complex128:f = i.types[GetPos(CTypeComplex128)].creators[createByLazy]
case func()Duration : f = i.types[GetPos(CTypeDate )].creators[createByLazy]
case func()Date : f = i.types[GetPos(CTypeDuration )].creators[createByLazy]
case func()string : f = i.types[GetPos(CTypeString )].creators[createByLazy]
case func()Bytes : f = i.types[GetPos(CTypeBytes )].creators[createByLazy]
case func()Stack : f = i.types[GetPos(CTypeStack )].creators[createByLazy]
case func()CValue : f = i.types[GetPos(CTypeCValue )].creators[createByLazy]
case func()Packable : f = i.types[GetPos(CTypePackable )].creators[createByLazy]
case func()Context : f = i.types[GetPos(CTypeContext )].creators[createByLazy]
case func()error : f = i.types[GetPos(CTypeError )].creators[createByLazy]
}
if f != nil {
@ -433,7 +423,7 @@ func createCValueRAny (tname string) func(reflect.Value) CValue {
func getPos (t CType) int {
func GetPos(t CType) int {
if t == 0 {
// Si 't' es CType(0) (que corresponde a CTypeInvalid),
// se le asigna el índice 0. Esto es consistente con 'cTypeInfos[0]'
@ -455,12 +445,15 @@ func getPos (t CType) int {
// - El CType correspondiente al bit 1 (valor 2) mapea a 'cTypeInfos[2]'.
// - ... y así sucesivamente, hasta el CType para el bit 31 (valor 1 << 31)
// que mapearía al índice 32, el último índice válido en el array de 33 posiciones.
//
// si es un tipo compuesto debemos aplicar la mascara
if t.IsComposite() {
return bits.TrailingZeros32(uint32(t & maskCTypeComposite))+1
}
return bits.TrailingZeros32(uint32(t))+1
}
func reflectKindToCType (kind reflect.Kind, base bool) CType {
switch kind {
case reflect.Invalid: return CTypeInvalid

@ -28,7 +28,10 @@
package cdts
import "math"
import (
"math"
"reflect"
)
type (
@ -70,21 +73,21 @@ func CreateCValueBool (value bool) CValue {
// Int's
func CreateCValueInt (value int) CValue {
func CreateCValueInt (value int) CValue {
if value == 0 {
return CValue{ vType: CTypeInt, vState: CStateZero }
}
return CValue{vType: CTypeInt, intVal: int64(value) }
}
func CreateCValueInt8 (value int8) CValue {
func CreateCValueInt8 (value int8) CValue {
if value == 0 {
return CValue{ vType: CTypeInt8, vState: CStateZero }
}
return CValue{vType: CTypeInt8, intVal: int64(value)}
}
func CreateCValueInt16(value int16) CValue {
func CreateCValueInt16 (value int16) CValue {
if value == 0 {
return CValue{ vType: CTypeInt16, vState: CStateZero }
}
@ -98,7 +101,7 @@ func CreateCValueInt32 (value int32) CValue {
return CValue{vType: CTypeInt32, intVal: int64(value)}
}
func CreateCValueInt64 (value int64 ) CValue {
func CreateCValueInt64 (value int64 ) CValue {
if value == 0 { return CValue{ vType: CTypeInt64, vState: CStateZero } }
return CValue{ vType: CTypeInt64, intVal: value }
}
@ -107,33 +110,33 @@ func CreateCValueInt64 (value int64 ) CValue {
// Uint's
func CreateCValueUint (value uint) CValue {
func CreateCValueUint (value uint) CValue {
if value == 0 { return CValue{ vType: CTypeUint, vState: CStateZero } }
return CValue{ vType: CTypeUint, intVal: int64(value) }
}
func CreateCValueUint8 (value uint8) CValue {
func CreateCValueUint8 (value uint8) CValue {
if value == 0 { return CValue{ vType: CTypeUint8, vState: CStateZero } }
return CValue{ vType: CTypeUint8, intVal: int64(value) }
}
func CreateCValueUint16 (value uint16) CValue {
func CreateCValueUint16 (value uint16) CValue {
if value == 0 { return CValue{ vType: CTypeUint16, vState: CStateZero } }
return CValue{ vType: CTypeUint16, intVal: int64(value) }
}
func CreateCValueUint32 (value uint32) CValue {
func CreateCValueUint32 (value uint32) CValue {
if value == 0 { return CValue{ vType: CTypeUint32, vState: CStateZero } }
return CValue{ vType: CTypeUint32, intVal: int64(value) }
}
func CreateCValueUint64 (value uint64) CValue {
func CreateCValueUint64 (value uint64) CValue {
if value == 0 { return CValue{ vType: CTypeUint64, vState: CStateZero } }
return CValue{ vType: CTypeUint64, intVal: int64(value) }
}
func CreateCValueUintptr (value uintptr) CValue {
func CreateCValueUintptr (value uintptr) CValue {
if value == 0 { return CValue{ vType: CTypeUintptr, vState: CStateZero } }
return CValue{ vType: CTypeUintptr, intVal: int64(value) }
}
@ -141,14 +144,14 @@ func CreateCValueUintptr (value uintptr) CValue {
// Floats
func CreateCValueFloat32 (value float32) CValue {
func CreateCValueFloat32 (value float32) CValue {
if value == 0.0 { // Comprobación directa para el valor cero
return CValue{vType: CTypeFloat32, vState: CStateZero}
}
return CValue{vType: CTypeFloat32, intVal: int64(math.Float32bits(value))}
}
func CreateCValueFloat64 (value float64) CValue {
func CreateCValueFloat64 (value float64) CValue {
if value == 0.0 { // Comprobación directa para el valor cero
return CValue{vType: CTypeFloat64, vState: CStateZero}
}
@ -271,4 +274,82 @@ func createCValueWithError (value any, vtype CType, vstate CState, er string) CV
func (v CValue) Type () CType { return v.vType }
func (v CValue) State() CState { return v.vState }
func (v CValue) State() CState { return v.vState }
func (v CValue) Value() (any,bool) {
// debemos de devolver el valor
// dependiendo donde se ha almacenado
// si es valido o no, si esta reflectado
// si es un valor lazy, etc
if v.vState.HasInvalid() {
return nil, false
}
if v.vState.HasNil() {
return nil, true
}
if v.vState.HasReflected() {
return v.anyVal.(reflect.Value), true
}
// todo: resto probalidades
return v.anyVal, true
}
func (v CValue) AsBool () (bool,bool) {
if v.vType != CTypeBool {
return false, false
}
if v.vState.HasNilOrZero() {
return false,true
}
if v.vType.IsLazy() {
return v.anyVal.(func()bool)(), true
}
return v.intVal > 0,true
}
func asNumEnt[T numsEnt] (ctype CType, cvalue CValue) (T, bool) {
if cvalue.vType != ctype {
return T(0), false
}
if cvalue.vState.HasNilOrZero() {
return T(0), true
}
if cvalue.vType.IsLazy() {
return cvalue.anyVal.(func()T)(),true
}
return T(cvalue.intVal), true
}
func (v CValue) AsInt () (int ,bool) { return asNumEnt[int ](CTypeInt,v) }
func (v CValue) AsInt8 () (int8 ,bool) { return asNumEnt[int8](CTypeInt8,v) }
func (v CValue) AsInt16() (int16,bool) { return asNumEnt[int16](CTypeInt16, v) }
func (v CValue) AsInt32() (int32,bool) { return asNumEnt[int32](CTypeInt32, v) }
func (v CValue) AsInt64() (int64,bool) { return asNumEnt[int64](CTypeInt64, v) }
func (v CValue) AsUint () (uint ,bool) { return asNumEnt[uint ](CTypeUint,v) }
func (v CValue) AsUint8 () (uint8 ,bool) { return asNumEnt[uint8](CTypeUint8,v) }
func (v CValue) AsUint16() (uint16,bool) { return asNumEnt[uint16](CTypeUint16, v) }
func (v CValue) AsUint32() (uint32,bool) { return asNumEnt[uint32](CTypeUint32, v) }
func (v CValue) AsUint64() (uint64,bool) { return asNumEnt[uint64](CTypeUint64, v) }

@ -1,50 +0,0 @@
// =============================================================================
// GO·AT Framework
// Copyright (c) 2025 ActiveThing (https://activething.com)
// Author: Juan V. Navarro juanvnl@activething.com
// =============================================================================
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
// =============================================================================
// Date Create 10/06/2025
// =============================================================================
package cdts
import (
"context"
"time"
)
type (
Date = time.Time
Duration = time.Duration
Bytes = []uint8
Stack = []interface { m () int }
Context = context.Context
Packable = interface { a()}
MapPackable = interface { p()}
ObjectPackable = interface {}
ListPackable = interface {}
)
Loading…
Cancel
Save

Powered by TurnKey Linux.