añadidos las funciones getter de CValue AsXXX

master
dev 1 year ago
parent 66db3529f2
commit 1622783b38

@ -0,0 +1,3 @@
module app
go 1.24

@ -0,0 +1,61 @@
// =============================================================================
// 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 31/05/2025
// =============================================================================
package main
import (
"core/blrs"
"core/vals"
"fmt"
)
func main() {
//list := func() int{ return 9 }
ls := []vals.CValue {
/*
vals.CreateCValue(map[int]string{}),
vals.CreateCValue([]any{}),
vals.CreateCValue(map[string]string(nil)),
vals.CreateCValue([]int{2,2,2,2,2}),
vals.CreateCValue(func()float64{ return 3.14 }),
vals.CreateCValue(time.Now()),
*/
vals.CreateCValue(blrs.Baleable(nil)),
}
for i,v := range ls {
fmt.Printf("%d Type %s isNIl=%t isZero=%t -> %v\n",i,v.Type().String(),v.State().IsNil(),v.State().IsZero(),v)
}
}

@ -33,9 +33,9 @@ import (
"time"
)
var (
g = struct {
var (
g = struct {
minTime,
maxTime time.Time
@ -43,7 +43,11 @@ var (
}{
minTime: time.Unix(0, math.MinInt64),
maxTime: time.Unix(0, math.MaxInt64),
cValueTypeInfos: createCValueTypeInfos(),
}
)
func init() {
// Initialize cValueTypeInfos as an empty array here.
// It will be populated in the init() function below.
g.cValueTypeInfos = createCValueTypeInfos()
}

@ -55,122 +55,6 @@ func CreateCValue (value any) CValue {
var idxT,idxC int
switch value.(type) {
/*
case string : idxT,idxC = idxCValueTypeString,0
case *string : idxT,idxC = idxCValueTypeString,1
case []string : idxT,idxC = idxCValueTypeString,2
case func()string : idxT,idxC = idxCValueTypeString,3
case bool : idxT,idxC = idxCValueTypeBool,0
case *bool : idxT,idxC = idxCValueTypeBool,1
case []bool : idxT,idxC = idxCValueTypeBool,2
case func()bool : idxT,idxC = idxCValueTypeBool,3
case int : idxT,idxC = idxCValueTypeInt,0
case *int : idxT,idxC = idxCValueTypeInt,1
case []int : idxT,idxC = idxCValueTypeInt,2
case func()int : idxT,idxC = idxCValueTypeInt,3
case int8 : idxT,idxC = idxCValueTypeInt8,0
case *int8 : idxT,idxC = idxCValueTypeInt8,1
case []int8 : idxT,idxC = idxCValueTypeInt8,2
case func()int8 : idxT,idxC = idxCValueTypeInt8,3
case int16 : idxT,idxC = idxCValueTypeInt16,0
case *int16 : idxT,idxC = idxCValueTypeInt16,1
case []int16 : idxT,idxC = idxCValueTypeInt16,2
case func()int16 : idxT,idxC = idxCValueTypeInt16,3
case int32 : idxT,idxC = idxCValueTypeInt32,0
case *int32 : idxT,idxC = idxCValueTypeInt32,1
case []int32 : idxT,idxC = idxCValueTypeInt32,2
case func()int32 : idxT,idxC = idxCValueTypeInt32,3
case int64 : idxT,idxC = idxCValueTypeInt64,0
case *int64 : idxT,idxC = idxCValueTypeInt64,1
case []int64 : idxT,idxC = idxCValueTypeInt64,2
case func()int64 : idxT,idxC = idxCValueTypeInt64,3
case uint : idxT,idxC = idxCValueTypeUint,0
case *uint : idxT,idxC = idxCValueTypeUint,1
case []uint : idxT,idxC = idxCValueTypeUint,2
case func()uint : idxT,idxC = idxCValueTypeUint,3
case uint8 : idxT,idxC = idxCValueTypeUint8,0
case *uint8 : idxT,idxC = idxCValueTypeUint8,1
// ya esta contemplado en el array de constructores
// que este tipo se convierta en CValueTypes
case []uint8 : idxT,idxC = idxCValueTypeUint8,2
case func()uint8 : idxT,idxC = idxCValueTypeUint8,3
case uint16 : idxT,idxC = idxCValueTypeUint16,0
case *uint16 : idxT,idxC = idxCValueTypeUint16,1
case []uint16 : idxT,idxC = idxCValueTypeUint16,2
case func()uint16 : idxT,idxC = idxCValueTypeUint16,3
case uint32 : idxT,idxC = idxCValueTypeUint32,0
case *uint32 : idxT,idxC = idxCValueTypeUint32,1
case []uint32 : idxT,idxC = idxCValueTypeUint32,2
case func()uint32 : idxT,idxC = idxCValueTypeUint32,3
case uint64 : idxT,idxC = idxCValueTypeUint64,0
case *uint64 : idxT,idxC = idxCValueTypeUint64,1
case []uint64 : idxT,idxC = idxCValueTypeUint64,2
case func()uint64 : idxT,idxC = idxCValueTypeUint64,3
case float32 : idxT,idxC = idxCValueTypeFloat32,0
case *float32 : idxT,idxC = idxCValueTypeFloat32,1
case []float32 : idxT,idxC = idxCValueTypeFloat32,2
case func()float32 : idxT,idxC = idxCValueTypeFloat32,3
case float64 : idxT,idxC = idxCValueTypeFloat64,0
case *float64 : idxT,idxC = idxCValueTypeFloat64,1
case []float64 : idxT,idxC = idxCValueTypeFloat64,2
case func()float64 : idxT,idxC = idxCValueTypeFloat64,3
case complex64 : idxT,idxC = idxCValueTypeComplex64,0
case *complex64 : idxT,idxC = idxCValueTypeComplex64,1
case []complex64 : idxT,idxC = idxCValueTypeComplex64,2
case func()complex64: idxT,idxC = idxCValueTypeComplex64,3
case complex128 : idxT,idxC = idxCValueTypeComplex128,0
case *complex128 : idxT,idxC = idxCValueTypeComplex128,1
case []complex128 : idxT,idxC = idxCValueTypeComplex128,2
case func()complex128:idxT,idxC = idxCValueTypeComplex128,3
case time.Duration : idxT,idxC = idxCValueTypeDuration,0
case *time.Duration : idxT,idxC = idxCValueTypeDuration,1
case []time.Duration : idxT,idxC = idxCValueTypeDuration,2
case func()time.Duration: idxT,idxC = idxCValueTypeDuration,3
case time.Time : idxT,idxC = idxCValueTypeDate,0
case *time.Time : idxT,idxC = idxCValueTypeDate,1
case []time.Time : idxT,idxC = idxCValueTypeDate,2
case func()time.Time : idxT,idxC = idxCValueTypeDate,3
//
//case []uint8 : idxT,idxC = idxCValueTypeBytes,0
case *[]uint8 : idxT,idxC = idxCValueTypeBytes,1
case [][]uint8 : idxT,idxC = idxCValueTypeBytes,2
case func()[]uint8 : idxT,idxC = idxCValueTypeBytes,3
case excs.Stack : idxT,idxC = idxCValueTypeStack,0
case *excs.Stack : idxT,idxC = idxCValueTypeStack,1
case []excs.Stack : idxT,idxC = idxCValueTypeStack,2
case func()excs.Stack: idxT,idxC = idxCValueTypeStack,3
case blrs.Baleable : idxT,idxC = idxCValueTypeBaleable,0
case *blrs.Baleable : idxT,idxC = idxCValueTypeBaleable,1
case []blrs.Baleable: idxT,idxC = idxCValueTypeBaleable,2
case func()blrs.Baleable : idxT,idxC = idxCValueTypeBaleable,3
case error : idxT,idxC = idxCValueTypeError,0
case *error : idxT,idxC = idxCValueTypeError,1
case []error : idxT,idxC = idxCValueTypeError,2
case func()error : idxT,idxC = idxCValueTypeError,3
*/
// --- CATEGORÍA 0: VALORES DIRECTOS (idxC = 0) ---
// Ordenados por frecuencia: string, int, bool, int64, float64, otros numéricos, tiempo, complejos, custom
case string : idxT, idxC = idxCValueTypeString, 0
@ -237,80 +121,57 @@ func CreateCValue (value any) CValue {
case []int16 : idxT, idxC = idxCValueTypeInt16, 2
case []int32 : idxT, idxC = idxCValueTypeInt32, 2
case []uint : idxT, idxC = idxCValueTypeUint, 2
case []uint16 :
idxT, idxC = idxCValueTypeUint16, 2
case []uint32 :
idxT, idxC = idxCValueTypeUint32, 2
case []uint64 :
idxT, idxC = idxCValueTypeUint64, 2
case []float32 :
idxT, idxC = idxCValueTypeFloat32, 2
case []time.Time :
idxT, idxC = idxCValueTypeDate, 2
case []time.Duration:
idxT, idxC = idxCValueTypeDuration, 2
case []complex64 :
idxT, idxC = idxCValueTypeComplex64, 2
case []complex128 :
idxT, idxC = idxCValueTypeComplex128, 2
case []excs.Stack :
idxT, idxC = idxCValueTypeStack, 2
case []blrs.Baleable:
idxT, idxC = idxCValueTypeBaleable, 2
case []error :
idxT, idxC = idxCValueTypeError, 2
case []uint16 : idxT, idxC = idxCValueTypeUint16, 2
case []uint32 : idxT, idxC = idxCValueTypeUint32, 2
case []uint64 : idxT, idxC = idxCValueTypeUint64, 2
case []float32 : idxT, idxC = idxCValueTypeFloat32, 2
case []time.Time: idxT, idxC = idxCValueTypeDate, 2
case []time.Duration: idxT, idxC = idxCValueTypeDuration, 2
case []complex64 : idxT, idxC = idxCValueTypeComplex64, 2
case []complex128 : idxT, idxC = idxCValueTypeComplex128, 2
case []excs.Stack : idxT, idxC = idxCValueTypeStack, 2
case []blrs.Baleable: idxT, idxC = idxCValueTypeBaleable, 2
case []error : idxT, idxC = idxCValueTypeError, 2
// --- CATEGORÍA 3: FUNCIONES (idxC = 3) ---
// Ordenados por frecuencia de su tipo de retorno: func()string, func()int, func()bool, etc.
case func() string :
idxT, idxC = idxCValueTypeString, 3
case func() int :
idxT, idxC = idxCValueTypeInt, 3
case func() bool :
idxT, idxC = idxCValueTypeBool, 3
case func() []uint8 : // func() []byte
idxT, idxC = idxCValueTypeBytes, 3
case func() int64 :
idxT, idxC = idxCValueTypeInt64, 3
case func() float64 :
idxT, idxC = idxCValueTypeFloat64, 3
case func() int8 :
idxT, idxC = idxCValueTypeInt8, 3
case func() int16 :
idxT, idxC = idxCValueTypeInt16, 3
case func() int32 :
idxT, idxC = idxCValueTypeInt32, 3
case func() uint :
idxT, idxC = idxCValueTypeUint, 3
case func() uint8 :
idxT, idxC = idxCValueTypeUint8, 3
case func() uint16 :
idxT, idxC = idxCValueTypeUint16, 3
case func() uint32 :
idxT, idxC = idxCValueTypeUint32, 3
case func() uint64 :
idxT, idxC = idxCValueTypeUint64, 3
case func() float32 :
idxT, idxC = idxCValueTypeFloat32, 3
case func() time.Duration:
idxT, idxC = idxCValueTypeDuration, 3
case func() time.Time :
idxT, idxC = idxCValueTypeDate, 3
case func() complex64 :
idxT, idxC = idxCValueTypeComplex64, 3
case func() complex128 :
idxT, idxC = idxCValueTypeComplex128, 3
case func() excs.Stack :
idxT, idxC = idxCValueTypeStack, 3
case func() blrs.Baleable:
idxT, idxC = idxCValueTypeBaleable, 3
case func() error :
idxT, idxC = idxCValueTypeError, 3
case func() string : idxT, idxC = idxCValueTypeString, 3
case func() int : idxT, idxC = idxCValueTypeInt, 3
case func() bool : idxT, idxC = idxCValueTypeBool, 3
case func() []uint8 : idxT, idxC = idxCValueTypeBytes, 3
case func() int64 : idxT, idxC = idxCValueTypeInt64, 3
case func() float64 : idxT, idxC = idxCValueTypeFloat64, 3
case func() int8 : idxT, idxC = idxCValueTypeInt8, 3
case func() int16 : idxT, idxC = idxCValueTypeInt16, 3
case func() int32 : idxT, idxC = idxCValueTypeInt32, 3
case func() uint : idxT, idxC = idxCValueTypeUint, 3
case func() uint8 : idxT, idxC = idxCValueTypeUint8, 3
case func() uint16 : idxT, idxC = idxCValueTypeUint16, 3
case func() uint32 : idxT, idxC = idxCValueTypeUint32, 3
case func() uint64 : idxT, idxC = idxCValueTypeUint64, 3
case func() float32 : idxT, idxC = idxCValueTypeFloat32, 3
case func() time.Duration: idxT, idxC = idxCValueTypeDuration, 3
case func() time.Time : idxT, idxC = idxCValueTypeDate, 3
case func() complex64 : idxT, idxC = idxCValueTypeComplex64, 3
case func() complex128 : idxT, idxC = idxCValueTypeComplex128, 3
case func() excs.Stack : idxT, idxC = idxCValueTypeStack, 3
case func() blrs.Baleable: idxT, idxC = idxCValueTypeBaleable, 3
case func() error : idxT, idxC = idxCValueTypeError, 3
default:
return createCValueByReflect(value,cValueTypeCompositeMask|cValueTypeBaseMask)
rvalue := reflect.ValueOf(value)
if !rvalue.IsValid() {
return CValue{mType: CValueTypeInvalid, mState: cValueStateError | cValueStateNil } // O createCValueInvalid(nil) si nil no es aceptable
}
switch rvalue.Kind() {
case reflect.Slice,reflect.Array: return createCValueListByReflected(value,rvalue)
case reflect.Map: return createCValueMapByReflected(value,rvalue)
case reflect.Struct: return createCValueObjectByReflected(value,rvalue)
default:
return CValue{ mType: CValueTypeAny, mState: cValueStateReflected, anyVal: rvalue}
}
}
switch idxC {
@ -460,7 +321,7 @@ func CreateCValueDate(value time.Time) CValue {
return CValue{mType: valType, mState: cValueStateZero}
}
if value.After(g.minTime) && value.Before(g.maxTime) {
return CValue{mType: valType, mState: cValueStateVersion,intVal: int64(value.UnixNano()), anyVal: value.Location()}
return CValue{mType: valType, mState: cValueStateVersion,intVal: value.UnixNano(), anyVal: value.Location()}
}
return CValue{mType: valType, anyVal: value}
}
@ -514,141 +375,482 @@ func CreateCValueError(value error) CValue {
}
func CreateCValueNil (value any) CValue {
func CreateCValueNil (_ any) CValue {
return CValue{mType: CValueTypeNil, mState: cValueStateNil }
}
func CreateCValueObject(value any) CValue { return createCValueByReflect(value,CValueTypeObject)}
func CreateCValueObject(value any) CValue {
rvalue := reflect.ValueOf(value)
if !rvalue.IsValid() {
return CValue{mType: CValueTypeInvalid, mState: cValueStateError | cValueStateNil } // O createCValueInvalid(nil) si nil no es aceptable
}
if rvalue.Kind() != reflect.Struct {
return createCValueInvalid(value) // No es el tipo de mapa esperado
}
return createCValueObjectByReflected(value,reflect.ValueOf(value))
}
func CreateCValueMap (value any) CValue {
return createCValueByReflect(value,CValueTypeMap)
rvalue := reflect.ValueOf(value)
if !rvalue.IsValid() {
return CValue{mType: CValueTypeInvalid, mState: cValueStateError | cValueStateNil } // O createCValueInvalid(nil) si nil no es aceptable
}
if rvalue.Kind() != reflect.Map {
return createCValueInvalid(value) // No es el tipo de lista esperado
}
return createCValueMapByReflected(value,rvalue)
}
func CreateCValueList(value any) CValue {
return createCValueByReflect(value,CValueTypeList)
rvalue := reflect.ValueOf(value)
if !rvalue.IsValid() {
return CValue{mType: CValueTypeInvalid, mState: cValueStateError | cValueStateNil }
}
if rvalue.Kind() != reflect.Slice && rvalue.Kind() != reflect.Array {
return createCValueInvalid(value) // No es el tipo de lista esperado
}
return createCValueListByReflected(value,rvalue)
}
func createCValueInvalid(value any) CValue {
return CValue{ mType: CValueTypeInvalid, anyVal: value }
}
func createCValueByReflect(value any, expected CValueType) CValue {
rv := reflect.ValueOf(value)
if !rv.IsValid() {
return CValue{mType: CValueTypeInvalid, mState: cValueStateError | cValueStateNil } // O createCValueInvalid(nil) si nil no es aceptable
func (v CValue) Type () CValueType { return v.mType }
func (v CValue) State() CValueState { return v.mState }
func (v CValue) Value() (any,bool) {
if v.mType == CValueTypeInvalid {
return nil,false
}
tv := rv.Type()
switch v.mType.BaseType() {
case CValueTypeAny : return v.AsAny ()
case CValueTypeBool : return v.AsBool ()
case CValueTypeInt : return v.AsInt ()
case CValueTypeInt8 : return v.AsInt8 ()
case CValueTypeInt16 : return v.AsInt16 ()
case CValueTypeInt32 : return v.AsInt32 ()
case CValueTypeInt64 : return v.AsInt64 ()
case CValueTypeUint : return v.AsUint ()
case CValueTypeUint8 : return v.AsUint8 ()
case CValueTypeUint16 : return v.AsUint16 ()
case CValueTypeUint32 : return v.AsUint32 ()
case CValueTypeUint64 : return v.AsUint64 ()
case CValueTypeUintptr : return v.AsUintptr ()
case CValueTypeFloat32 : return v.AsFloat32 ()
case CValueTypeFloat64 : return v.AsFloat64 ()
case CValueTypeComplex64 : return v.AsComplex64 ()
case CValueTypeComplex128: return v.AsComplex128 ()
case CValueTypeDuration : return v.AsDuration ()
case CValueTypeDate : return v.AsDate ()
case CValueTypeString : return v.AsString ()
case CValueTypeBytes : return v.AsBytes ()
case CValueTypeStack : return v.AsStack ()
case CValueTypeBaleable : return v.AsBaleable ()
case CValueTypeError : return v.AsError ()
case CValueTypeNil : return nil,true
case CValueTypeObject : return v.AsObject ()
switch rv.Kind() {
case reflect.Slice,
reflect.Array:
if !expected.IsList() {
return createCValueInvalid(value) // No es el tipo de lista esperado
}
eleType := tv.Elem()
zeroEle := reflect.Zero(eleType)
baseEleType := reflectToCValueType(zeroEle, eleType)
finalListCType := CValueTypeList | baseEleType
var vState CValueState
if rv.IsNil() { // Aunque Kind sea Slice, el slice subyacente puede ser nil
vState = cValueStateNil
return CValue{mType: finalListCType, mState: vState}
default:
if v.mType.IsList() {
return v.AsList()
}
if rv.Len() == 0 {
vState = cValueStateZero
return CValue{mType: finalListCType, mState: vState, anyVal: value} // Guardamos el slice vacío
if v.mType.IsMap() {
return v.AsMap()
}
vState = cValueStateReflected
return CValue{mType: finalListCType, mState: vState, anyVal: value}
return nil, false
}
}
case reflect.Map:
if !expected.IsMap() {
return createCValueInvalid(value) // No es el tipo de mapa esperado
}
keyType := tv.Key()
valueType := tv.Elem()
zeroKey := reflect.Zero(keyType)
zeroValue := reflect.Zero(valueType)
func (v CValue) AsAny () (any,bool){
if v.mType != CValueTypeAny {
return nil, false
}
return v.anyVal, true
}
func (v CValue) AsBool () (bool,bool){
if v.mType != CValueTypeBool {
return false,false
}
if v.State().IsNilOrZero() {
return false,true
}
return v.intVal != 0,true
}
mapType := buildMapType(reflectToCValueType(zeroKey, keyType), reflectToCValueType(zeroValue, valueType))
func (v CValue) AsInt () (int,bool){
if v.mType != CValueTypeInt {
return 0,false
}
if v.State().IsNilOrZero() {
return 0,true
}
return int(v.intVal),true
}
var vState CValueState
if rv.IsNil() {
vState = cValueStateNil
return CValue{mType: mapType, mState: vState}
}
if rv.Len() == 0 {
vState = cValueStateZero
return CValue{mType: mapType, mState: vState, anyVal: value}
}
vState = cValueStateReflected
return CValue{mType: mapType, mState: vState, anyVal: rv}
func (v CValue) AsInt8 () (int8,bool){
if v.mType != CValueTypeInt8 {
return 0,false
}
if v.State().IsNilOrZero() {
return 0,true
}
return int8(v.intVal),true
}
case reflect.Struct:
if CValueTypeObject & expected == 0 {
return createCValueInvalid(value) // No es el tipo de mapa esperado
}
return CValue{mType: CValueTypeObject, mState: cValueStateReflected, anyVal: rv}
func (v CValue) AsInt16 () (int16,bool){
if v.mType != CValueTypeInt16 {
return 0,false
}
if v.State().IsNilOrZero() {
return 0,true
}
return int16(v.intVal),true
}
default:
// Si el Kind no es Slice, Array, Object, o Map, y no se espera que esta función
// maneje otros tipos que no sean Slice, Array, Object y Map debera devolver CValueObjectAny
// con el estado reflejado
return CValue{ mType: CValueTypeAny, mState: cValueStateReflected,anyVal: rv}
func (v CValue) AsInt32 () (int32,bool){
if v.mType != CValueTypeInt32 {
return 0,false
}
if v.State().IsNilOrZero() {
return 0,true
}
return int32(v.intVal),true
}
func (v CValue) AsInt64 () (any,bool){
if v.mType != CValueTypeInt64 {
return 0,false
}
if v.State().IsNilOrZero() {
return 0,true
}
return v.intVal,true
}
func (v CValue) AsUint () (uint,bool){
if v.mType != CValueTypeUint {
return 0,false
}
if v.State().IsNilOrZero() {
return 0,true
}
return uint(v.intVal),true
}
func (v CValue) AsUint8 () (uint8,bool){
if v.mType != CValueTypeUint8 {
return 0,false
}
if v.State().IsNilOrZero() {
return 0,true
}
return uint8(v.intVal),true
}
func (v CValue) AsUint16 () (uint16,bool){
if v.mType != CValueTypeUint16 {
return 0,false
}
if v.State().IsNilOrZero() {
return 0,true
}
return uint16(v.intVal),true
}
func (v CValue) AsUint32 () (uint32,bool){
if v.mType != CValueTypeUint32 {
return 0,false
}
if v.State().IsNilOrZero() {
return 0,true
}
return uint32(v.intVal),true
}
func (v CValue) AsUint64 () (uint64,bool){
if v.mType != CValueTypeUint64 {
return 0,false
}
if v.State().IsNilOrZero() {
return 0,true
}
return uint64(v.intVal),true
}
func (v CValue) AsUintptr() (uintptr,bool){
if v.mType != CValueTypeUintptr {
return 0,false
}
if v.State().IsNilOrZero() {
return 0,true
}
return uintptr(v.intVal),true
}
func (v CValue) AsFloat32() (float32,bool){
if v.mType != CValueTypeFloat32 {
return 0,false
}
if v.State().IsNilOrZero() {
return 0,true
}
return math.Float32frombits(uint32(v.intVal)), true
}
func (v CValue) AsFloat64() (float64,bool){
if v.mType != CValueTypeFloat64 {
return 0,false
}
if v.State().IsNilOrZero() {
return 0,true
}
return math.Float64frombits(uint64(v.intVal)), true
}
func (v CValue) AsComplex64 () (complex64,bool){
if v.mType != CValueTypeComplex64 {
return 0,false
}
if v.State().IsNilOrZero() {
return 0,true
}
return v.anyVal.(complex64),true
}
func (v CValue) AsComplex128() (complex128,bool){
if v.mType != CValueTypeComplex128 {
return 0,false
}
if v.State().IsNilOrZero() {
return 0,true
}
return v.anyVal.(complex128),true
}
func (v CValue) AsDuration() (time.Duration,bool){
if v.mType != CValueTypeDuration {
return 0,false
}
if v.State().IsNilOrZero() {
return 0,true
}
return time.Duration(v.intVal),true
}
func (v CValue) AsDate () (time.Time,bool){
if v.mType != CValueTypeDate {
return time.Time{},false
}
if v.State().IsNilOrZero() {
return time.Time{}, true
}
if v.State().isVersion() {
// version corta del date
return time.Unix(0, v.intVal).In(v.anyVal.(*time.Location)), true
}
return v.anyVal.(time.Time),true
}
func (v CValue) AsString () (string,bool){
if v.mType != CValueTypeString {
return "", false
}
if v.State().IsNilOrZero() {
return "", true
}
return v.strVal,true
}
func (v CValue) AsBytes () ([]byte,bool){
if v.mType != CValueTypeBytes {
return nil, false
}
if v.State().IsNil() {
return []byte(nil),true
}
if v.State().IsZero() {
return []byte{}, true
}
return v.anyVal.([]byte),true
}
func (v CValue) AsStack () (excs.Stack,bool){
if v.mType != CValueTypeStack {
return nil, false
}
if v.State().IsNil() {
return excs.Stack(nil),true
}
if v.State().IsZero() {
return excs.Stack{}, true
}
return v.anyVal.(excs.Stack),true
}
func (v CValue) AsBaleable() (blrs.Baleable,bool){
if v.mType != CValueTypeBaleable {
return nil, false
}
if v.State().IsNil() {
return blrs.Baleable(nil),true
}
return v.anyVal.(blrs.Baleable),true
}
func (v CValue) AsError () (error,bool){
if v.mType != CValueTypeError {
return nil, false
}
if v.State().IsNil() {
return error(nil),true
}
return v.anyVal.(error),true
}
func (v CValue) AsObject () (any,bool) {
if v.mType != CValueTypeObject {
return nil, false
}
return v.anyVal,true
}
func (v CValue) AsList () (any,bool) {
if v.mType != CValueTypeList {
return nil, false
}
if v.State().IsNil() {
return any(nil),true
}
return v.anyVal,true
}
func (v CValue) AsMap () (any,bool) {
if v.mType != CValueTypeMap {
return nil, false
}
if v.State().IsNil() {
return nil,true
}
return v.anyVal,true
}
func (v CValue) AsReflected () (reflect.Value,bool) {
if !v.State().IsNil() {
return reflect.Value{},false
}
return v.anyVal.(reflect.Value),true
}
func createCValueListByReflected (value any, rvalue reflect.Value) CValue {
// asumimos que rvalue es valido y que es una slice ya que la llamada
// se ha hecho o bien a traves de CreateCValue o CreateCValueList
eleType := rvalue.Type().Elem()
zeroEle := reflect.Zero(eleType)
baseEleType := reflectToCValueType(zeroEle, eleType)
finalListCType := CValueTypeList | baseEleType
var vState CValueState
if rvalue.IsNil() { // Aunque Kind sea Slice, el slice subyacente puede ser nil
vState = cValueStateNil
return CValue{mType: finalListCType, mState: vState}
}
vState = cValueStateReflected
if rvalue.Len() == 0 {
vState |= cValueStateZero
}
return CValue{mType: finalListCType, mState: vState, anyVal: rvalue}
}
func createCValueMapByReflected (value any, rvalue reflect.Value) CValue {
// asumimos que rvalue es valido y que es un map ya que la llamada
// se ha hecho o bien a traves de CreateCValue o CreateCValueMap
tv := rvalue.Type()
kType := tv.Key()
vType := tv.Elem()
zeroKey := reflect.Zero(kType)
zeroValue := reflect.Zero(vType)
mType := buildMapType(reflectToCValueType(zeroKey, kType), reflectToCValueType(zeroValue, vType))
var vState CValueState
if rvalue.IsNil() {
vState = cValueStateNil
return CValue{mType: mType, mState: vState}
}
vState = cValueStateReflected
if rvalue.Len() == 0 {
vState |= cValueStateZero
}
return CValue{mType: mType, mState: vState, anyVal: rvalue}
}
func createCValueObjectByReflected (value any, rvalue reflect.Value) CValue {
// asumimos que rvalue es valido y que es un struct ya que la llamada
// se ha hecho o bien a traves de CreateCValue o CreateCValueMap
return CValue{mType: CValueTypeObject, mState: cValueStateReflected, anyVal: rvalue}
}
// reflectToCValueType determina el CValueType base para un reflect.Value y reflect.Type dados.
func reflectToCValueType(rv reflect.Value, tp reflect.Type) CValueType {
// Primero, intentar identificar por el valor concreto usando un type switch.
// Esto es más eficiente para tipos conocidos que no son interfaces puras.
// rv.Interface() puede causar pánico si rv es un valor cero de un tipo no exportado
// o si rv no es válido. Asegurarse de que rv sea válido antes de llamar a Interface().
if rv.IsValid() { // Añadir chequeo de validez
// Priorizar la identificación por el valor concreto para tipos conocidos y válidos.
if rv.IsValid() {
switch rv.Interface().(type) {
case time.Time: return CValueTypeDate
case time.Duration: return CValueTypeDuration
case excs.Stack: return CValueTypeStack
case []byte: return CValueTypeBytes
case blrs.Baleable: return CValueTypeBaleable
case error: return CValueTypeError
case time.Time: return CValueTypeDate
case time.Duration: return CValueTypeDuration
case excs.Stack: return CValueTypeStack
case []byte: return CValueTypeBytes
case blrs.Baleable: return CValueTypeBaleable
case error: return CValueTypeError
}
}
if tp != nil {
typeError := reflect.TypeOf((*error)(nil)).Elem()
typeBaleable := reflect.TypeOf((*blrs.Baleable)(nil)).Elem()
if tp.Implements(typeError) {
return CValueTypeError
}
if tp.Implements(typeBaleable) {
return CValueTypeBaleable
}
// Si tp es nil, no hay información de tipo para determinar.
if tp == nil {
return CValueTypeInvalid
}
// Comprobación para tipos concretos especiales por reflect.Type
if tp == reflect.TypeOf(time.Time{}) {
return CValueTypeDate
}
if tp == reflect.TypeOf(time.Duration(0)) {
return CValueTypeDuration
}
if tp == reflect.TypeOf([]byte{}) {
return CValueTypeBytes
}
if tp == reflect.TypeOf(excs.Stack{}) { // Si Stack es un tipo específico
return CValueTypeStack
}
return kindToCValueType(tp.Kind(),false)
// Identificar tipos que implementan interfaces específicas.
if tp.Implements(reflect.TypeOf((*error)(nil)).Elem()) {
return CValueTypeError
}
return CValueTypeInvalid // Si tp es nil
if tp.Implements(reflect.TypeOf((*blrs.Baleable)(nil)).Elem()) {
return CValueTypeBaleable
}
// Como último recurso, mapear el Kind del tipo a un CValueType.
// kindToCValueType debe ser robusto y manejar correctamente
// todos los reflect.Kind relevantes (ej., Struct -> Object, Slice/Array -> List).
return kindToCValueType(tp.Kind(), false)
}
@ -694,3 +896,12 @@ func kindToCValueType(kind reflect.Kind, base bool) CValueType {
return CValueTypeAny
}
}

@ -41,15 +41,23 @@ func (f creatorCValueFnc[T]) createCValue(value any) CValue {
return f(value.(T))
}
func makeFuncCreator[T any](vtype CValueType, fnc creatorCValueFnc[T]) cValueCreator {
return creatorCValueFnc[genericProvider[T]](func(caller genericProvider[T]) CValue {
if caller == nil {
// The returned creatorCValueFnc expects 'value' to be of type 'func() T'.
// So, the generic parameter for creatorCValueFnc should be 'func() T'.
return creatorCValueFnc[func() T](func(callerFunc func() T) CValue {
if callerFunc == nil {
return CValue{mType: vtype, mState: cValueStateNil}
}
return fnc(caller())
// Call the original function to get the actual value of type T,
// then pass it to the provided 'fnc' (which is creatorCValueFnc[T]).
return fnc(callerFunc())
})
}
func makePointerCreator[T any](vtype CValueType, fnc creatorCValueFnc[T]) cValueCreator {
return creatorCValueFnc[*T](func(value *T) CValue { // La entrada es explícitamente *T
if value == nil {
@ -69,7 +77,7 @@ func makeListCreator[T any](vtype CValueType) cValueCreator {
return CValue{mType: vtype, mState: cValueStateNil}
}
if len(value) == 0 {
return CValue{mType: vtype, mState: cValueStateZero}
return CValue{mType: vtype, mState: cValueStateZero, anyVal: value}
}
return CValue{mType: vtype, anyVal: value} // Asegúrate de usar 'anyVal' para el campo de valor
})

@ -34,21 +34,21 @@ const (
cValueStateZero
cValueStateVersion
cValueStateSensitive
cValueStateUnpackable
cValueStateReflected
cValueStateError
cValueStateNone CValueState = 0
cValueStateNilOrZero = cValueStateZero | cValueStateNil
cValueStateOptions = cValueStateSensitive | cValueStateUnpackable
cValueStateOptions = cValueStateSensitive
)
type CValueState uint8
func (f CValueState) IsInvalid() bool { return f&cValueStateInvalid != 0 }
func (f CValueState) IsNil () bool { return f&cValueStateNil != 0 }
func (f CValueState) IsNil() bool { return f&cValueStateNil != 0 }
func (f CValueState) IsZero() bool { return f&cValueStateZero != 0 }
@ -56,8 +56,6 @@ func (f CValueState) IsNilOrZero() bool { return f&cValueStateNilOrZero != 0 }
func (f CValueState) IsSensitive() bool { return f&cValueStateSensitive != 0 }
func (f CValueState) IsUnpackable() bool { return f&cValueStateUnpackable != 0 }
func (f CValueState) IsReflected() bool { return f&cValueStateReflected != 0 }
func (f CValueState) IsError() bool { return f&cValueStateError != 0 }

@ -28,7 +28,10 @@
package vals
import "math/bits"
import (
"math/bits"
"strings"
)
const (
maxCValueTypes int = 32
@ -91,109 +94,144 @@ const (
// el de menos valor
// se recomienda usar buildMapType para evitar posibles errores
//
cValueTypeMKey CValueType = 1 << 29
CValueTypeMap CValueType = 1 << 30
CValueTypeList CValueType = 1 << 31
CValueTypeList CValueType = 1 << 29
CValueTypeMap CValueType = 1 << 30
cValueTypeMKey CValueType = 1 << 31
cValueTypeCompositeMask = CValueTypeMap | CValueTypeList
cValueTypeBaseMask = ^(cValueTypeCompositeMask | cValueTypeMKey)
)
cValueTypeCompositeMask = cValueTypeMKey | CValueTypeMap | CValueTypeList
cValueTypeBaseMask = ^cValueTypeCompositeMask
const (
cValueTypeSep = "|"
)
type CValueType uint32
func (v CValueType) IsComposite () bool { return v&cValueTypeCompositeMask != 0 }
func (v CValueType) IsCompositeType() bool { return v&cValueTypeCompositeMask != 0 }
func (v CValueType) CompositeType () CValueType { return v &cValueTypeBaseMask }
func (v CValueType) BaseType () CValueType {
bs := v & cValueTypeBaseMask
if v&CValueTypeMap == 0 {
return bs
if !v.IsMap() {
// For lists or non-composite types
return v & cValueTypeBaseMask
}
// For Maps
bs := v & cValueTypeBaseMask
nb := bits.OnesCount32(uint32(bs))
if nb == 0 || nb > 2 {
if nb == 0 || nb > 2 { // Should not happen if buildMapType is used
return CValueTypeInvalid
}
if nb == 1 {
return bs
return bs // Value type is the same as key type
}
lsb := bs & -bs
if v&cValueTypeMKey != 0 {
// clave está en MSB → valor está en LSB
return lsb
type1 := bs & -bs // The CValueType with the smallest bit value
type2 := bs &^ type1 // The CValueType with the largest bit value
if (v & cValueTypeMKey) != 0 {
// MKey is active: value is type1 (smaller bit value)
return type1
}
// clave está en LSB → valor está en MSB
return bs &^ lsb
// MKey is not active: value is type2 (larger bit value)
return type2
}
func (v CValueType) KeyType () CValueType {
if v&cValueTypeCompositeMask != CValueTypeMap {
return CValueTypeInvalid
}
bs := v &cValueTypeBaseMask
nb := bits.OnesCount32(uint32(bs))
if nb == 0 || nb > 2 {
return CValueTypeInvalid
}
if nb == 1 {
return bs
}
// obtenemos el bit menos significativo para la key
// y el más significativo para el valor de los
// elementos del map
lsb := bs & -bs
if v&cValueTypeCompositeMask != cValueTypeMKey {
//si no esta activado el bit de key indica que la key
//esta representada por el bit menos significativa
return lsb
}
return bs &^ lsb
func (v CValueType) IsList () bool { return v&cValueTypeCompositeMask == CValueTypeList }
func (v CValueType) IsListOf (baseType CValueType) bool {
return v&cValueTypeCompositeMask == CValueTypeList && v&cValueTypeBaseMask == baseType
}
func (v CValueType) IsMap () bool { return v&cValueTypeCompositeMask == CValueTypeMap }
func (v CValueType) MapType () (CValueType, CValueType) {
if !v.IsMap() {
return CValueTypeInvalid,CValueTypeInvalid
return CValueTypeInvalid, CValueTypeInvalid
}
bs := v &cValueTypeBaseMask
bs := v & cValueTypeBaseMask
nb := bits.OnesCount32(uint32(bs))
if nb == 0 || nb > 2 {
return CValueTypeInvalid,CValueTypeInvalid
if nb == 0 || nb > 2 { // Should not happen
return CValueTypeInvalid, CValueTypeInvalid
}
if nb == 1 {
return bs,bs
}
// obtenemos el bit menos significativo para la key
// y el más significativo para el valor de los
// elementos del map
lsb := bs & -bs
if v&cValueTypeCompositeMask != cValueTypeMKey {
//si no esta activado el bit de key indica que la key
//esta representada por el bit menos significativa
return lsb,bs &^ lsb
return bs, bs // Key and value types are the same
}
return bs &^ lsb, lsb
}
func (v CValueType) IsMap () bool { return v&cValueTypeCompositeMask == CValueTypeMap }
type1 := bs & -bs // The CValueType with the smallest bit value
type2 := bs &^ type1 // The CValueType with the largest bit value
func (v CValueType) IsList () bool { return v&cValueTypeCompositeMask == CValueTypeList }
if (v & cValueTypeMKey) != 0 {
// MKey is active: key is type2 (larger bit value), value is type1 (smaller bit value)
return type2, type1
}
// MKey is not active: key is type1 (smaller bit value), value is type2 (larger bit value)
return type1, type2
}
func (v CValueType) IsListOf (baseType CValueType) bool {
return v&cValueTypeCompositeMask == CValueTypeList && v&cValueTypeBaseMask == baseType
func (v CValueType) IsMapKeyOf (keyType CValueType) bool {
kt,_ := v.MapType()
return kt == keyType
}
func (v CValueType) IsMapValueOf (baseType CValueType) bool {
func (v CValueType) IsMapValueOf (baseType CValueType) bool {
_,tv := v.MapType()
return tv == baseType
}
func (v CValueType) IsTypeInvalid () bool { return v&cValueTypeBaseMask==CValueTypeInvalid}
func (v CValueType) IsTypeAny () bool {return v&cValueTypeBaseMask==CValueTypeAny }
func (v CValueType) IsTypeBool () bool {return v&cValueTypeBaseMask==CValueTypeBool}
func (v CValueType) IsTypeInt () bool {return v&cValueTypeBaseMask==CValueTypeInt}
func (v CValueType) IsTypeInt8 () bool {return v&cValueTypeBaseMask==CValueTypeInt8}
func (v CValueType) IsTypeInt16 () bool {return v&cValueTypeBaseMask==CValueTypeInt16}
func (v CValueType) IsTypeInt32 () bool {return v&cValueTypeBaseMask==CValueTypeInt32}
func (v CValueType) IsTypeInt64 () bool {return v&cValueTypeBaseMask==CValueTypeInt64}
func (v CValueType) IsTypeUint () bool {return v&cValueTypeBaseMask==CValueTypeUint}
func (v CValueType) IsTypeUint8 () bool {return v&cValueTypeBaseMask==CValueTypeUint8}
func (v CValueType) IsTypeUint16 () bool {return v&cValueTypeBaseMask==CValueTypeUint16}
func (v CValueType) IsTypeUint32 () bool {return v&cValueTypeBaseMask==CValueTypeUint32}
func (v CValueType) IsTypeUint64 () bool {return v&cValueTypeBaseMask==CValueTypeUint64}
func (v CValueType) IsTypeUintptr () bool {return v&cValueTypeBaseMask==CValueTypeUintptr}
func (v CValueType) IsTypeFloat32 () bool {return v&cValueTypeBaseMask==CValueTypeFloat32}
func (v CValueType) IsTypeFloat64 () bool {return v&cValueTypeBaseMask==CValueTypeFloat64}
func (v CValueType) IsTypeComplex64 () bool {return v&cValueTypeBaseMask==CValueTypeComplex64}
func (v CValueType) IsTypeComplex128 () bool {return v&cValueTypeBaseMask==CValueTypeComplex128}
func (v CValueType) IsTypeDuration () bool {return v&cValueTypeBaseMask==CValueTypeDuration}
func (v CValueType) IsTypeDate () bool {return v&cValueTypeBaseMask==CValueTypeDate}
func (v CValueType) IsTypeString () bool {return v&cValueTypeBaseMask==CValueTypeString}
func (v CValueType) IsTypeBytes () bool {return v&cValueTypeBaseMask==CValueTypeBytes}
func (v CValueType) IsTypeStack () bool {return v&cValueTypeBaseMask==CValueTypeStack}
func (v CValueType) IsTypeBaleable () bool {return v&cValueTypeBaseMask==CValueTypeBaleable}
func (v CValueType) IsTypeError () bool {return v&cValueTypeBaseMask==CValueTypeError}
func (v CValueType) IsTypeNil () bool {return v&cValueTypeBaseMask==CValueTypeNil}
func (v CValueType) IsTypeObject () bool {return v&cValueTypeBaseMask==CValueTypeObject}
func (v CValueType) String () string {
// IsList ?
if v&cValueTypeCompositeMask == CValueTypeList {
return strings.Join(append([]string{g.cValueTypeInfos[idxCValueTypeList].name},v.BaseType().String()),cValueTypeSep)
}
if v&cValueTypeCompositeMask == CValueTypeMap {
t1,t2 := v.MapType()
return strings.Join(append([]string{g.cValueTypeInfos[idxCValueTypeMap].name},
g.cValueTypeInfos[getCValueTypeIdx(t1)].name,
g.cValueTypeInfos[getCValueTypeIdx(t2)].name),cValueTypeSep)
}
return g.cValueTypeInfos[getCValueTypeIdx(v)].name
}
func buildMapType (keyType, valueType CValueType) CValueType {
if keyType == CValueTypeInvalid || valueType == CValueTypeInvalid {
return CValueTypeInvalid
@ -206,3 +244,7 @@ func buildMapType (keyType, valueType CValueType) CValueType {
}
return keyType|valueType|CValueTypeMap| cValueTypeMKey
}

@ -69,21 +69,22 @@ const (
idxCValueTypeBaleable
idxCValueTypeError
idxCValueTypeNil
_
_
idxCValueTypeObject
_
idxCValueTypeMap
idxCValueTypeList
idxCValueTypeMap
)
type (
cValueTypeInfo struct {
vType CValueType
name string
vType CValueType
name string
getter func() any
vCreator,
lCreator,
@ -105,65 +106,94 @@ func createCValueTypeInfo[T any](vtype CValueType, name string, creatorFnc creat
}
func createCValueTypeInfos() [maxCValueTypes]cValueTypeInfo {
types := [maxCValueTypes]cValueTypeInfo{
/* 1 CValueTypeAny */ createCValueTypeInfo[any](CValueTypeAny, "any", CreateCValueAny),
/* 2 CValueTypeBool */ createCValueTypeInfo[bool](CValueTypeBool, "bool", CreateCValueBool),
/* 3 CValueTypeInt */ createCValueTypeInfo[int](CValueTypeInt, "int", CreateCValueInt),
/* 4 CValueTypeInt8 */ createCValueTypeInfo[int8](CValueTypeInt8, "int8", CreateCValueInt8),
/* 5 CValueTypeInt16 */ createCValueTypeInfo[int16](CValueTypeInt16, "int16", CreateCValueInt16),
/* 6 CValueTypeInt32 */ createCValueTypeInfo[int32](CValueTypeInt32, "int32", CreateCValueInt32),
/* 7 CValueTypeInt64 */ createCValueTypeInfo[int64](CValueTypeInt64, "int64", CreateCValueInt64),
/* 8 CValueTypeUint */ createCValueTypeInfo[uint](CValueTypeUint, "uint", CreateCValueUint),
/* -- Exception
/* 9 CValueTypeUint8 createCValueTypeInfo[uint8](CValueTypeUint8, "uint8", CreateCValueUint8), */
/* --
/* 10 CValueTypeUint16 */ createCValueTypeInfo[uint16](CValueTypeUint16, "uint16", CreateCValueUint16),
/* 11 CValueTypeUint32 */ createCValueTypeInfo[uint32](CValueTypeUint32, "uint32", CreateCValueUint32),
/* 12 CValueTypeUint64 */ createCValueTypeInfo[uint64](CValueTypeUint64, "uint64", CreateCValueUint64),
/* 13 CValueTypeUintptr */ createCValueTypeInfo[uintptr](CValueTypeUintptr, "uintptr", CreateCValueUintptr),
/* 14 CValueTypeFloat32 */ createCValueTypeInfo[float32](CValueTypeFloat32, "float32", CreateCValueFloat32),
/* 15 CValueTypeFloat64 */ createCValueTypeInfo[float64](CValueTypeFloat64, "float64", CreateCValueFloat64),
/* 16 CValueTypeComplex64 */ createCValueTypeInfo[complex64](CValueTypeComplex64, "complex64", CreateCValueComplex64),
/* 17 CValueTypeComplex128*/ createCValueTypeInfo[complex128](CValueTypeComplex128, "complex128", CreateCValueComplex128),
/* 18 CValueTypeDuration*/ createCValueTypeInfo[time.Duration](CValueTypeDuration, "duration", CreateCValueDuration),
/* 19 CValueTypeDate */ createCValueTypeInfo[time.Time](CValueTypeDate, "date", CreateCValueDate),
/* 20 CValueTypeString */ createCValueTypeInfo[string](CValueTypeString, "string", CreateCValueString),
/* 21 CValueTypeBytes */ createCValueTypeInfo[[]uint8](CValueTypeBytes, "bytes", CreateCValueBytes),
/* 22 CValueTypeStack */ createCValueTypeInfo[excs.Stack](CValueTypeStack, "stack", CreateCValueStack),
/* 23 CValueTypePackable*/ createCValueTypeInfo[blrs.Baleable](CValueTypeBaleable, "packable", CreateCValueBaleable),
/* 24 CValueTypeError */ createCValueTypeInfo[error](CValueTypeError, "error", CreateCValueError),
return [maxCValueTypes]cValueTypeInfo{
idxCValueTypeInvalid: createCValueTypeInfo[any ](CValueTypeInvalid, "invalid", createCValueInvalid),
idxCValueTypeAny : createCValueTypeInfo[any ](CValueTypeAny, "any", CreateCValueAny),
idxCValueTypeBool : createCValueTypeInfo[bool ](CValueTypeBool, "bool", CreateCValueBool),
idxCValueTypeInt : createCValueTypeInfo[int ](CValueTypeInt, "int", CreateCValueInt),
idxCValueTypeInt8 : createCValueTypeInfo[int8 ](CValueTypeInt8, "int8", CreateCValueInt8),
idxCValueTypeInt16 : createCValueTypeInfo[int16](CValueTypeInt16, "int16", CreateCValueInt16),
idxCValueTypeInt32 : createCValueTypeInfo[int32](CValueTypeInt32, "int32", CreateCValueInt32),
idxCValueTypeInt64 : createCValueTypeInfo[int64](CValueTypeInt64, "int64", CreateCValueInt64),
idxCValueTypeUint : createCValueTypeInfo[uint ](CValueTypeUint, "uint", CreateCValueUint),
// Manejo especial para uint8: su creador de listas es para bytes
idxCValueTypeUint8: {
vType: CValueTypeUint8,
name: "uint8",
vCreator: creatorCValueFnc[uint8](CreateCValueUint8),
lCreator: creatorCValueFnc[[]uint8](CreateCValueBytes), // Lista de uint8 es bytes ([]uint8)
fCreator: makeFuncCreator[uint8](CValueTypeUint8, creatorCValueFnc[uint8](CreateCValueUint8)),
pCreator: makePointerCreator[uint8](CValueTypeUint8, creatorCValueFnc[uint8](CreateCValueUint8)),
},
idxCValueTypeUint16 : createCValueTypeInfo[uint16](CValueTypeUint16, "uint16", CreateCValueUint16),
idxCValueTypeUint32 : createCValueTypeInfo[uint32](CValueTypeUint32, "uint32", CreateCValueUint32),
idxCValueTypeUint64 : createCValueTypeInfo[uint64](CValueTypeUint64, "uint64", CreateCValueUint64),
idxCValueTypeUintptr: createCValueTypeInfo[uintptr](CValueTypeUintptr, "uintptr", CreateCValueUintptr),
idxCValueTypeFloat32: createCValueTypeInfo[float32](CValueTypeFloat32, "float32", CreateCValueFloat32),
idxCValueTypeFloat64: createCValueTypeInfo[float64](CValueTypeFloat64, "float64", CreateCValueFloat64),
idxCValueTypeComplex64 : createCValueTypeInfo[complex64](CValueTypeComplex64, "complex64", CreateCValueComplex64),
idxCValueTypeComplex128 : createCValueTypeInfo[complex128](CValueTypeComplex128, "complex128", CreateCValueComplex128),
idxCValueTypeDuration : createCValueTypeInfo[time.Duration](CValueTypeDuration, "duration", CreateCValueDuration),
idxCValueTypeDate : createCValueTypeInfo[time.Time](CValueTypeDate, "date", CreateCValueDate),
idxCValueTypeString : createCValueTypeInfo[string](CValueTypeString, "string", CreateCValueString),
idxCValueTypeBytes : createCValueTypeInfo[[]uint8](CValueTypeBytes, "bytes", CreateCValueBytes),
idxCValueTypeStack : createCValueTypeInfo[excs.Stack](CValueTypeStack, "stack", CreateCValueStack),
idxCValueTypeBaleable: createCValueTypeInfo[blrs.Baleable](CValueTypeBaleable, "packable", CreateCValueBaleable),
idxCValueTypeError : createCValueTypeInfo[error](CValueTypeError, "error", CreateCValueError),
idxCValueTypeNil : createCValueTypeInfo[any](CValueTypeNil, "nil", CreateCValueNil),
// Tipos no definidos
26 : createCValueTypeInfo[any](CValueTypeInvalid, "invalid", createCValueInvalid),
27 : createCValueTypeInfo[any](CValueTypeInvalid, "invalid", createCValueInvalid),
//---------------------
idxCValueTypeObject : createCValueTypeInfo[any](CValueTypeObject, "object", CreateCValueObject),
idxCValueTypeList : createCValueTypeInfo[any](CValueTypeList, "list", CreateCValueList),
idxCValueTypeMap : createCValueTypeInfo[any](CValueTypeMap, "map", CreateCValueMap),
// Flag del mama
31 : createCValueTypeInfo[any](CValueTypeInvalid, "invalid", createCValueInvalid),
}
}
/* 25 CValueTypeInvalid */ createCValueTypeInfo[any](CValueTypeInvalid, "invalid", createCValueInvalid),
/* 26 CValueTypeInvalid */ createCValueTypeInfo[any](CValueTypeInvalid, "invalid", createCValueInvalid),
/* 27 CValueTypeInvalid */ createCValueTypeInfo[any](CValueTypeInvalid, "invalid", createCValueInvalid),
/* 28 CValueTypeObject */ createCValueTypeInfo[any](CValueTypeObject, "object", CreateCValueObject),
// Reservad for map key
/* 29 CValueTypeMKey */ createCValueTypeInfo[any](CValueTypeInvalid, "invalid", createCValueInvalid),
/* 30 CValueTypeMap */ createCValueTypeInfo[any](CValueTypeMap, "map", CreateCValueMap),
/* 31 CValueTypeList */ createCValueTypeInfo[any](CValueTypeList, "list", CreateCValueList),
}
// exception de []uint8 debe de ser tratado como bytes
types[idxCValueTypeUint8] = cValueTypeInfo{
vType: CValueTypeUint8,
name: "uint8",
vCreator: creatorCValueFnc[uint8](CreateCValueUint8),
lCreator: creatorCValueFnc[[]uint8](CreateCValueBytes),
fCreator: makeFuncCreator[uint8](CValueTypeUint8, CreateCValueUint8),
pCreator: makePointerCreator[uint8](CValueTypeUint8, CreateCValueUint8),
func getCValueTypeIdx (vtype CValueType) int {
switch vtype {
case CValueTypeInvalid : return idxCValueTypeInvalid
case CValueTypeAny : return idxCValueTypeAny
case CValueTypeBool : return idxCValueTypeBool
case CValueTypeInt : return idxCValueTypeInt
case CValueTypeInt8 : return idxCValueTypeInt8
case CValueTypeInt16 : return idxCValueTypeInt16
case CValueTypeInt32 : return idxCValueTypeInt32
case CValueTypeInt64 : return idxCValueTypeInt64
case CValueTypeUint : return idxCValueTypeUint
case CValueTypeUint8 : return idxCValueTypeUint8
case CValueTypeUint16 : return idxCValueTypeUint16
case CValueTypeUint32 : return idxCValueTypeUint32
case CValueTypeUint64 : return idxCValueTypeUint64
case CValueTypeUintptr : return idxCValueTypeUintptr
case CValueTypeFloat32 : return idxCValueTypeFloat32
case CValueTypeFloat64 : return idxCValueTypeFloat64
case CValueTypeComplex64: return idxCValueTypeComplex64
case CValueTypeComplex128: return idxCValueTypeComplex128
case CValueTypeDuration: return idxCValueTypeDuration
case CValueTypeDate : return idxCValueTypeDate
case CValueTypeString : return idxCValueTypeString
case CValueTypeBytes : return idxCValueTypeBytes
case CValueTypeStack : return idxCValueTypeStack
case CValueTypeBaleable: return idxCValueTypeBaleable
case CValueTypeError : return idxCValueTypeError
case CValueTypeNil : return idxCValueTypeNil
case CValueTypeObject : return idxCValueTypeObject
case CValueTypeList : return idxCValueTypeList
case CValueTypeMap : return idxCValueTypeMap
default:
// Se mapea a 0 (CValueTypeInvalid) como un valor por defecto.
// Manejar tipos que no están directamente mapeados, si es necesario.
// Podrías devolver -1 o un valor de error específico.
return 0 // Opcional: devolver 0 (Invalid) para tipos no mapeados explícitamente.
}
return types
}
}

@ -1,3 +1,7 @@
go 1.24
use core
use (
app
core
)
Loading…
Cancel
Save

Powered by TurnKey Linux.