From 408753bc9ff73c6e7c2d73918e59242b9d1ea042 Mon Sep 17 00:00:00 2001 From: dev Date: Thu, 5 Jun 2025 01:06:29 +0200 Subject: [PATCH] definicion de CField --- src/core/cfls/a.go | 9 +- src/core/cfls/cfields.go | 34 +++ src/core/cfls/cval.go | 444 +++++++--------------------- src/core/cfls/cval_creators.go | 14 +- src/core/cfls/cval_type.go | 63 +--- src/core/cfls/cval_type_cache.go | 200 +++++++++++++ src/core/cfls/cval_type_infos.go | 311 +++++++++++++++++++ src/core/cflss/a.go | 29 ++ src/core/cflss/cfield.go | 43 +++ src/core/cflss/cvalue.go | 80 +++++ src/core/cflss/cvalue_state.go | 66 +++++ src/core/cflss/cvalue_type.go | 175 +++++++++++ src/core/cflss/cvalue_type_infos.go | 335 +++++++++++++++++++++ src/core/cflss/types.go | 49 +++ 14 files changed, 1453 insertions(+), 399 deletions(-) create mode 100644 src/core/cfls/cfields.go create mode 100644 src/core/cfls/cval_type_cache.go create mode 100644 src/core/cfls/cval_type_infos.go create mode 100644 src/core/cflss/a.go create mode 100644 src/core/cflss/cfield.go create mode 100644 src/core/cflss/cvalue.go create mode 100644 src/core/cflss/cvalue_state.go create mode 100644 src/core/cflss/cvalue_type.go create mode 100644 src/core/cflss/cvalue_type_infos.go create mode 100644 src/core/cflss/types.go diff --git a/src/core/cfls/a.go b/src/core/cfls/a.go index 89edad7..54aca1f 100644 --- a/src/core/cfls/a.go +++ b/src/core/cfls/a.go @@ -31,14 +31,19 @@ package cfls import ( "core/blrs" "core/excs" + "reflect" "time" ) + + + var ( G = struct { CValTypeNames [maxCValTypes+1]string cValTypeCreators [maxCValTypes+1]cValTypeCreators + typeToCValTypes map[reflect.Type]cValTypeCacheEntry }{ CValTypeNames: [maxCValTypes+1]string { /* 0: */ "invalid", @@ -113,13 +118,15 @@ var ( /* 24:*/ createGValTypeCreators[error](CValTypeError, CreateCValError), /* 25:*/ createGValTypeCreators[any](CValTypeNil, CreateCValNil), /* 26:*/ createGValTypeCreators[CVal](CValTypeCVal, CreateCValCVal), - /* 27:*/ createGValTypeCreators[any](CValTypeFields, CreateCValFields), + /* 27:*/ createGValTypeCreators[any](CValTypeCFields, CreateCValFields), /* 28:*/ createGValTypeCreators[any](CValTypeObject, CreateCValObject), /* 29:*/ createGValTypeCreators[any](CValTypeDefer, CreateCValDefer), /* 30:*/ createGValTypeCreators[any](CValTypeList, CreateCValList), /* 31:*/ createGValTypeCreators[any](CValTypeMap, CreateCValMap), /* 32:*/ createGValTypeCreators[any](CValTypeObject, createCValInvalid), }, + + typeToCValTypes: makeCacheCValTypes(), } diff --git a/src/core/cfls/cfields.go b/src/core/cfls/cfields.go new file mode 100644 index 0000000..5a7a63e --- /dev/null +++ b/src/core/cfls/cfields.go @@ -0,0 +1,34 @@ +// ============================================================================= +// 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 04/06/2025 +// ============================================================================= + +package cfls + + + + +type CFields = map[string]CVal diff --git a/src/core/cfls/cval.go b/src/core/cfls/cval.go index 7a1e6a9..0aa2d5b 100644 --- a/src/core/cfls/cval.go +++ b/src/core/cfls/cval.go @@ -51,142 +51,66 @@ func CreateCVal (value any) CVal { var f cValTypeCreateFunc switch value.(type) { - case any : f = G.cValTypeCreators[ 1/* CValTypeAny.Index() */].valueCreator - // case *any : f = G.cValTypeCreators[ 1/* CValTypeAny.Index() */].pointerCreator - // case []any : f = G.cValTypeCreators[ 1/* CValTypeAny.Index() */].listCreator - // case func()any : f = G.cValTypeCreators[ 1/* CValTypeAny.Index() */].deferCreator - case bool : f = G.cValTypeCreators[ 2/* CValTypeBool.Index() */].valueCreator - // case *bool : f = G.cValTypeCreators[ 2/* CValTypeBool.Index() */].pointerCreator + /* Valores simples */ + case any : f = G.cValTypeCreators[ 1/* CValTypeAny.Index() */].valueCreator + case bool : f = G.cValTypeCreators[ 2/* CValTypeBool.Index() */].valueCreator + case int : f = G.cValTypeCreators[ 3/* CValTypeInt.Index() */].valueCreator + case int8 : f = G.cValTypeCreators[ 4/* CValTypeInt8.Index() */].valueCreator + case int16 : f = G.cValTypeCreators[ 5/* CValTypeInt16.Index() */].valueCreator + case int32 : f = G.cValTypeCreators[ 6/* CValTypeInt32.Index() */].valueCreator + case int64 : f = G.cValTypeCreators[ 7/* CValTypeInt64.Index() */].valueCreator + case uint : f = G.cValTypeCreators[ 8/* CValTypeUint.Index() */].valueCreator + case uint8 : f = G.cValTypeCreators[ 9/* CValTypeUint8.Index() */].valueCreator + case uint16 : f = G.cValTypeCreators[10/* CValTypeUint16.Index() */].valueCreator + case uint32 : f = G.cValTypeCreators[11/* CValTypeUint32.Index() */].valueCreator + case uint64 : f = G.cValTypeCreators[12/* CValTypeUint64.Index() */].valueCreator + case uintptr : f = G.cValTypeCreators[13/* CValTypeUintptr.Index() */].valueCreator + case float32 : f = G.cValTypeCreators[14/* CValTypeFloat32.Index() */].valueCreator + case float64 : f = G.cValTypeCreators[15/* CValTypeFloat64.Index() */].valueCreator + case complex64 : f = G.cValTypeCreators[16/* CValTypeComplex64.Index() */].valueCreator + case complex128 : f = G.cValTypeCreators[17/* CValTypeComplex128.Index()*/].valueCreator + case time.Duration : f = G.cValTypeCreators[18/* CValTypeTime.Duration.Index() */].valueCreator + case time.Time : f = G.cValTypeCreators[19/* CValTypeTime.Time.Index() */].valueCreator + case string : f = G.cValTypeCreators[20/* CValTypeString.Index() */].valueCreator + case []uint8 : f = G.cValTypeCreators[21/* CValTypeBytes.Index() */].valueCreator + case excs.Stack : f = G.cValTypeCreators[22/* CValTypeStack.Index() */].valueCreator + case blrs.Baleable : f = G.cValTypeCreators[23/* CValTypeBaleable.Index() */].valueCreator + case error : f = G.cValTypeCreators[24/* CValTypeError.Index() */].valueCreator + case CVal : f = G.cValTypeCreators[26/* CValTypeCVal.Index() */].valueCreator + case map[string]CVal: f = G.cValTypeCreators[27/* CValTypeCVal.Index() */].valueCreator + + /* Valores Listas */ + // case []any : f = G.cValTypeCreators[ 1/* CValTypeAny.Index() */].listCreator // case []bool : f = G.cValTypeCreators[ 2/* CValTypeBool.Index() */].listCreator - // case func()bool : f = G.cValTypeCreators[ 2/* CValTypeBool.Index() */].deferCreator - - /* Int's */ - case int : f = G.cValTypeCreators[ 3/* CValTypeInt.Index() */].valueCreator - // case *int : f = G.cValTypeCreators[ 3/* CValTypeInt.Index() */].pointerCreator // case []int : f = G.cValTypeCreators[ 3/* CValTypeInt.Index() */].listCreator - // case func()int : f = G.cValTypeCreators[ 3/* CValTypeInt.Index() */].deferCreator - - case int8 : f = G.cValTypeCreators[ 4/* CValTypeInt8.Index() */].valueCreator - // case *int8 : f = G.cValTypeCreators[ 4/* CValTypeInt8.Index() */].pointerCreator // case []int8 : f = G.cValTypeCreators[ 4/* CValTypeInt8.Index() */].listCreator - // case func()int8 : f = G.cValTypeCreators[ 4/* CValTypeInt8.Index() */].deferCreator - - case int16 : f = G.cValTypeCreators[ 5/* CValTypeInt16.Index() */].valueCreator - // case *int16 : f = G.cValTypeCreators[ 5/* CValTypeInt16.Index() */].pointerCreator // case []int16 : f = G.cValTypeCreators[ 5/* CValTypeInt16.Index() */].listCreator - // case func()int16 : f = G.cValTypeCreators[ 5/* CValTypeInt16.Index() */].deferCreator - - case int32 : f = G.cValTypeCreators[ 6/* CValTypeInt32.Index() */].valueCreator - // case *int32 : f = G.cValTypeCreators[ 6/* CValTypeInt32.Index() */].pointerCreator // case []int32 : f = G.cValTypeCreators[ 6/* CValTypeInt32.Index() */].listCreator - // case func()int32 : f = G.cValTypeCreators[ 6/* CValTypeInt32.Index() */].deferCreator - - case int64 : f = G.cValTypeCreators[ 7/* CValTypeInt64.Index() */].valueCreator - // case *int64 : f = G.cValTypeCreators[ 7/* CValTypeInt64.Index() */].pointerCreator // case []int64 : f = G.cValTypeCreators[ 7/* CValTypeInt64.Index() */].listCreator - // case func()int64 : f = G.cValTypeCreators[ 7/* CValTypeInt64.Index() */].deferCreator - - /* Uint's */ - case uint : f = G.cValTypeCreators[ 8/* CValTypeUint.Index() */].valueCreator - // case *uint : f = G.cValTypeCreators[ 8/* CValTypeUint.Index() */].pointerCreator // case []uint : f = G.cValTypeCreators[ 8/* CValTypeUint.Index() */].listCreator - // case func()uint : f = G.cValTypeCreators[ 8/* CValTypeUint.Index() */].deferCreator - - case uint8 : f = G.cValTypeCreators[ 9/* CValTypeUint8.Index() */].valueCreator - // case *uint8 : f = G.cValTypeCreators[ 9/* CValTypeUint8.Index() */].pointerCreator // case []uint8 : f = G.cValTypeCreators[ 9/* CValTypeUint8.Index() */].listCreator - // case func()uint8 : f = G.cValTypeCreators[ 9/* CValTypeUint8.Index() */].deferCreator - - case uint16 : f = G.cValTypeCreators[10/* CValTypeUint16.Index() */].valueCreator - // case *uint16 : f = G.cValTypeCreators[10/* CValTypeUint16.Index() */].pointerCreator // case []uint16 : f = G.cValTypeCreators[10/* CValTypeUint16.Index() */].listCreator - // case func()uint16: f = G.cValTypeCreators[10/* CValTypeUint16.Index() */].deferCreator - - case uint32 : f = G.cValTypeCreators[11/* CValTypeUint32.Index() */].valueCreator - // case *uint32 : f = G.cValTypeCreators[11/* CValTypeUint32.Index() */].pointerCreator // case []uint32 : f = G.cValTypeCreators[11/* CValTypeUint32.Index() */].listCreator - // case func()uint32: f = G.cValTypeCreators[11/* CValTypeUint32.Index() */].deferCreator - - case uint64 : f = G.cValTypeCreators[12/* CValTypeUint64.Index() */].valueCreator - // case *uint64 : f = G.cValTypeCreators[12/* CValTypeUint64.Index() */].pointerCreator // case []uint64 : f = G.cValTypeCreators[12/* CValTypeUint64.Index() */].listCreator // case func()uint64: f = G.cValTypeCreators[12/* CValTypeUint64.Index() */].deferCreator - - case uintptr : f = G.cValTypeCreators[13/* CValTypeUintptr.Index() */].valueCreator - // case *uintptr : f = G.cValTypeCreators[13/* CValTypeUintptr.Index() */].pointerCreator // case []uintptr : f = G.cValTypeCreators[13/* CValTypeUintptr.Index() */].listCreator - // case func()uintptr: f = G.cValTypeCreators[13/* CValTypeUintptr.Index() */].deferCreator - - /* Float's */ - case float32 : f = G.cValTypeCreators[14/* CValTypeFloat32.Index() */].valueCreator - // case *float32 : f = G.cValTypeCreators[14/* CValTypeFloat32.Index() */].pointerCreator // case []float32 : f = G.cValTypeCreators[14/* CValTypeFloat32.Index() */].listCreator - // case func()float32: f = G.cValTypeCreators[14/* CValTypeFloat32.Index() */].deferCreator - - case float64 : f = G.cValTypeCreators[15/* CValTypeFloat64.Index() */].valueCreator - // case *float64 : f = G.cValTypeCreators[15/* CValTypeFloat64.Index() */].pointerCreator // case []float64 : f = G.cValTypeCreators[15/* CValTypeFloat64.Index() */].listCreator - // case func()float64: f = G.cValTypeCreators[15/* CValTypeFloat64.Index() */].deferCreator - - case complex64 : f = G.cValTypeCreators[16/* CValTypeComplex64.Index() */].valueCreator - // case *complex64 : f = G.cValTypeCreators[16/* CValTypeComplex64.Index() */].pointerCreator // case []complex64 : f = G.cValTypeCreators[16/* CValTypeComplex64.Index() */].listCreator - // case func()complex64: f = G.cValTypeCreators[16/* CValTypeComplex64.Index() */].deferCreator - - case complex128 : f = G.cValTypeCreators[17/* CValTypeComplex128.Index() */].valueCreator - // case *complex128 : f = G.cValTypeCreators[17/* CValTypeComplex128.Index() */].pointerCreator // case []complex128: f = G.cValTypeCreators[17/* CValTypeComplex128.Index() */].listCreator - // case func()complex128:f = G.cValTypeCreators[17/* CValTypeComplex128.Index() */].deferCreator - - /* time's */ - - case time.Duration : f = G.cValTypeCreators[18/* CValTypeTime.Duration.Index() */].valueCreator - // case *time.Duration : f = G.cValTypeCreators[18/* CValTypeTime.Duration.Index() */].pointerCreator // case []time.Duration : f = G.cValTypeCreators[18/* CValTypeTime.Duration.Index() */].listCreator - // case func()time.Duration: f = G.cValTypeCreators[18/* CValTypeTime.Duration.Index() */].deferCreator - - case time.Time : f = G.cValTypeCreators[19/* CValTypeTime.Time.Index() */].valueCreator - // case *time.Time : f = G.cValTypeCreators[19/* CValTypeTime.Time.Index() */].pointerCreator - // case []time.Time : f = G.cValTypeCreators[19/* CValTypeTime.Time.Index() */].listCreator - // case func()time.Time : f = G.cValTypeCreators[19/* CValTypeTime.Time.Index() */].deferCreator - - /* Strings, Bytes, Stack */ - case string : f = G.cValTypeCreators[20/* CValTypeString.Index() */].valueCreator - // case *string : f = G.cValTypeCreators[20/* CValTypeString.Index() */].pointerCreator + // case []time.Time : f = G.cValTypeCreators[19/* CValTypeTime.Time.Index() */].listCreator // case []string : f = G.cValTypeCreators[20/* CValTypeString.Index() */].listCreator - // case func()string: f = G.cValTypeCreators[20/* CValTypeString.Index() */].deferCreator - - case []uint8 : f = G.cValTypeCreators[21/* CValTypeBytes.Index() */].valueCreator - // case *[]uint8 : f = G.cValTypeCreators[21/* CValTypeBytes.Index() */].pointerCreator - // case [][]uint8 : f = G.cValTypeCreators[21/* CValTypeBytes.Index() */].listCreator - // case func()[]uint8: f = G.cValTypeCreators[21/* CValTypeBytes.Index() */].deferCreator - - case excs.Stack : f = G.cValTypeCreators[22/* CValTypeStack.Index() */].valueCreator - // case *excs.Stack : f = G.cValTypeCreators[22/* CValTypeStack.Index() */].pointerCreator - // case []excs.Stack : f = G.cValTypeCreators[22/* CValTypeStack.Index() */].listCreator - // case func()excs.Stack: f = G.cValTypeCreators[22/* CValTypeStack.Index() */].deferCreator - - case blrs.Baleable : f = G.cValTypeCreators[23/* CValTypeBaleable.Index() */].valueCreator - // case *blrs.Baleable : f = G.cValTypeCreators[23/* CValTypeBaleable.Index() */].pointerCreator + // case []excs.Stack: f = G.cValTypeCreators[22/* CValTypeStack.Index() */].listCreator // case []blrs.Baleable : f = G.cValTypeCreators[23/* CValTypeBaleable.Index() */].listCreator - // case func()blrs.Baleable: f = G.cValTypeCreators[23/* CValTypeBaleable.Index() */].deferCreator - - case error : f = G.cValTypeCreators[24/* CValTypeError.Index() */].valueCreator - // case *error : f = G.cValTypeCreators[24/* CValTypeError.Index() */].pointerCreator // case []error : f = G.cValTypeCreators[24/* CValTypeError.Index() */].listCreator - // case func()error : f = G.cValTypeCreators[24/* CValTypeError.Index() */].deferCreator - - case CVal : f = G.cValTypeCreators[26/* CValTypeCVal.Index() */].valueCreator - // case *CVal : f = G.cValTypeCreators[26/* CValTypeCVal.Index() */].pointerCreator // case []CVal : f = G.cValTypeCreators[26/* CValTypeCVal.Index() */].listCreator - // case func()CVal : f = G.cValTypeCreators[26/* CValTypeCVal.Index() */].deferCreator + // case []map[string]CVal : f = G.cValTypeCreators[27]/* CValTypeCVal.Index() */].listCreator + + - case map[string]CVal: f = G.cValTypeCreators[27/* CValTypeCVal.Index() */].valueCreator - // case *CVal : f = G.cValTypeCreators[27/* CValTypeCVal.Index() */].pointerCreator - // case []CVal : f = G.cValTypeCreators[27/* CValTypeCVal.Index() */].listCreator - // case func()CVal : f = G.cValTypeCreators[27/* CValTypeCVal.Index() */].deferCreator default: rv := reflect.ValueOf(value) @@ -194,94 +118,35 @@ func CreateCVal (value any) CVal { return createCValInvalid(value) } - switch rv.Kind() { - case reflect.Ptr : f = getCreatorForCValPointer(rv) - case reflect.Slice, - reflect.Array: return createCValByList (rv) - case reflect.Func : return createCValByDefer (rv) - case reflect.Map : return createCValByMap (rv) + rt := rv.Type() + ti,ok := G.typeToCValTypes[rt] + if ok { + f = G.cValTypeCreators[ti.i].creatorByIndex(ti.c) + } else { + // --- Fallback para tipos NO mapeados explícitamente en typeToCValInfoMap --- + switch rt.Kind() { + case reflect.Ptr: + return createCValPointerByReflected(rv) + case reflect.Struct: + return createCValObjectByReflected(rv) + case reflect.Map: + return createCValMapByReflected(rv) + case reflect.Slice, + reflect.Array: + return createCValListByReflected(rv) + case reflect.Func: + return createCValDeferByReflected(rv) + default: + // Cualquier otro tipo que no se pudo identificar + return CreateCValAny(value) + } } - return createCValAny(value) } return f(value) } -func getCreatorForCValPointer(value any) cValTypeCreateFunc { - buildType := CValTypeAny - switch value.(type) { - case *any : buildType = CValTypeAny - case *bool : buildType = CValTypeBool - case *int : - buildType = CValTypeInt - case *int8 : - buildType = CValTypeInt8 - case *int16 : - buildType = CValTypeInt16 - case *int32 : - buildType = CValTypeInt32 - case *int64 : - buildType = CValTypeInt64 - case *uint : - buildType = CValTypeUint - case *uint8 : buildType = CValTypeUint8 - case *uint16 : buildType = CValTypeUint16 - case *uint32 : buildType = CValTypeUint32 - case *uint64 : buildType = CValTypeUint64 - case *uintptr : - buildType = CValTypeUintptr - case *float32 : - buildType = CValTypeFloat32 - case *float64 : - buildType = CValTypeFloat64 - case *complex64 : - buildType = CValTypeComplex64 - case *complex128: - buildType = CValTypeComplex128 - case *time.Duration : - buildType = CValTypeDuration - case *time.Time : buildType = CValTypeDate - case *string : - buildType = CValTypeString - case *[]uint8 : - buildType = CValTypeBytes - case *excs.Stack: - buildType = CValTypeStack - case *blrs.Baleable: - buildType = CValTypeBaleable - case *error : - buildType = CValTypeError - case *CVal : - buildType = CValTypeCVal - case *map[string]CVal : - buildType = CValTypeFields - default: - buildType = CValTypeAny - } - return G.cValTypeCreators[buildType.Index()].pointerCreator -} - - -func createCValByList (value reflect.Value) CVal { - return CVal{} -} - - -func createCValByDefer (value reflect.Value) CVal { - return CVal{} -} - -func createCValByMap (value reflect.Value) CVal { - return CVal{} -} - - - - -func createCValAny (value any) CVal { - return CVal{} -} func CreateCValAny (value any ) CVal { return CVal{ } } @@ -323,177 +188,78 @@ func createCValInvalid (value any) CVal { return CVal{} } -func createCValByReflect (value any) CVal { - rv := reflect.ValueOf(value) - if !rv.IsValid() { - return createCValInvalid(value) - } - rt := rv.Type() - - switch rt.Kind() { - case reflect.Ptr: - et := rt.Elem() - bt := reflectTypeToCValType(et) - ti := bt.Index() - if ti == 0 || G.cValTypeCreators[ti].pointerCreator == nil { - return createCValInvalid(value) - } - return G.cValTypeCreators[ti].pointerCreator(value) - - case reflect.Slice,reflect.Array: - et := rt.Elem() - bt := reflectTypeToCValType(et) - if bt == CValTypeUint8 { - return CreateCValBytes(value.([]uint8)) - } - ti := bt.Index() - if ti == 0 || G.cValTypeCreators[ti].listCreator == nil { - return createCValInvalid(value) - } - return G.cValTypeCreators[ti].listCreator(value) - +func createCValPointerByReflected (value reflect.Value) CVal { + ti,ok := G.typeToCValTypes[value.Elem().Type()] + if !ok { + // } - + return G.cValTypeCreators[bt.Index()].pointerCreator(value) } - - - -func createCValListByReflected (value any, rvalue reflect.Value) CVal { +func createCValListByReflected (rvalue reflect.Value) CVal { // asumimos que rvalue es valido y que es una slice ya que la llamada // se ha hecho o bien a traves de CreateCVal o CreateCValList - - eleType := rvalue.Type().Elem() - zeroEle := reflect.Zero(eleType) - baseEleType := reflectToCValType(zeroEle, eleType) - finalListCType := CValTypeList | baseEleType - - var vState CValState + if bt,ok := G.typeToCValTypes[rvalue.Type()]; ok { + return G.cValTypeCreators[bt.i]. bt.c(rvalue.Interface()) + } + if bt == CValTypeInvalid { + return createCValInvalid(rvalue) + } + bt|=CValTypeList + var cState CValState if rvalue.IsNil() { // Aunque Kind sea Slice, el slice subyacente puede ser nil - vState = cValStateNil - return CVal{cType: finalListCType, cState: vState} + cState = cValStateNil + return CVal{cType: bt, cState: cState} } - vState = cValStateReflected + cState = cValStateReflected if rvalue.Len() == 0 { - vState |= cValStateZero + cState |= cValStateZero } - return CVal{cType: finalListCType, cState: vState, anyVal: rvalue} + return CVal{cType: bt, cState: cState, anyVal: rvalue} } -func createCValMapByReflected (value any, rvalue reflect.Value) CVal { - // asumimos que rvalue es valido y que es un map ya que la llamada - // se ha hecho o bien a traves de CreateCVal o CreateCValMap - - tv := rvalue.Type() - kType := tv.Key() - vType := tv.Elem() - - zeroKey := reflect.Zero(kType) - zeroValue := reflect.Zero(vType) - - cType := BuildMapType(reflectToCValType(zeroKey, kType), reflectToCValType(zeroValue, vType)) +func createCValMapByReflected (rvalue reflect.Value) CVal { + kt := reflectTypeToCValType(rvalue.Type().Key()) + if kt == CValTypeInvalid { + return createCValInvalid(rvalue) + } + vt := reflectTypeToCValType(rvalue.Type().Elem()) + if vt == CValTypeInvalid { + return createCValInvalid(rvalue) + } - var vState CValState + if kt == CValTypeString && vt == CValTypeCVal { + // Es un fields // debemos llamar a create fields + return CreateCValFields(rvalue.Interface().(map[string]CVal)) + } + bt := BuildMapType(kt,vt) + var cState CValState if rvalue.IsNil() { - vState = cValStateNil - return CVal{cType: cType, cState: vState} + cState = cValStateNil + return CVal{cType: bt, cState: cState} } - vState = cValStateReflected + cState = cValStateReflected if rvalue.Len() == 0 { - vState |= cValStateZero + cState |= cValStateZero } - return CVal{cType: cType, cState: vState, anyVal: rvalue} + return CVal{cType: bt, cState: cState, anyVal: rvalue} } -func createCValObjectByReflected (value any, rvalue reflect.Value) CVal { - // asumimos que rvalue es valido y que es un struct ya que la llamada - // se ha hecho o bien a traves de CreateCVal o CreateCValMap +func createCValObjectByReflected (rvalue reflect.Value) CVal { return CVal{cType: CValTypeObject, cState: cValStateReflected, anyVal: rvalue} } - - -// reflectToCValType determina el CValType base para un reflect.Value y reflect.Type dados. -func reflectToCValType(rv reflect.Value, tp reflect.Type) CValType { - // 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 CValTypeDate - case time.Duration : return CValTypeDuration - case CValType : return CValTypeCVal - case excs.Stack : return CValTypeStack - case []byte : return CValTypeBytes - case blrs.Baleable : return CValTypeBaleable - case error : return CValTypeError - case map[string]any : return CValTypeFields - } +func createCValDeferByReflected (rvalue reflect.Value) CVal { + rt := rvalue.Type() + if rt.NumIn() != 0 || rt.NumOut() != 1 { + return CVal{ cType: CValTypeAny, cState: cValStateReflected, anyVal: rvalue } } - - // Si tp es nil, no hay información de tipo para determinar. - if tp == nil { - return CValTypeInvalid - } - - // Identificar tipos que implementan interfaces específicas. - if tp.Implements(reflect.TypeOf((*error)(nil)).Elem()) { - return CValTypeError - } - if tp.Implements(reflect.TypeOf((*blrs.Baleable)(nil)).Elem()) { - return CValTypeBaleable - } - - // Como último recurso, mapear el Kind del tipo a un CValType. - // kindToCValType debe ser robusto y manejar correctamente - // todos los reflect.Kind relevantes (ej., Struct -> Object, Slice/Array -> List). - return kindToCValType(tp.Kind(), false) -} - - -func kindToCValType(kind reflect.Kind, base bool) CValType { - switch kind { - case reflect.Bool: return CValTypeBool - case reflect.Int: return CValTypeInt - case reflect.Int8: return CValTypeInt8 - case reflect.Int16: return CValTypeInt16 - case reflect.Int32: return CValTypeInt32 - case reflect.Int64: return CValTypeInt64 - case reflect.Uint: return CValTypeUint - case reflect.Uint8: return CValTypeUint8 - case reflect.Uint16: return CValTypeUint16 - case reflect.Uint32: return CValTypeUint32 - case reflect.Uint64: return CValTypeUint64 - case reflect.Uintptr: return CValTypeUintptr - case reflect.Float32: return CValTypeFloat32 - case reflect.Float64: return CValTypeFloat64 - case reflect.Complex64: return CValTypeComplex64 - case reflect.Complex128:return CValTypeComplex128 - case reflect.String: return CValTypeString - - case reflect.Array, - reflect.Slice: - if base { - return CValTypeList - } - return CValTypeAny - case reflect.Map: - if base { - return CValTypeMap - } - return CValTypeAny - - case reflect.Struct: - if base { - return CValTypeObject - } - return CValTypeAny - - default: - return CValTypeAny + bt := reflectTypeToCValType(rt.Out(0)) + if bt == CValTypeInvalid { + return createCValInvalid(rvalue) } + return G.cValTypeCreators[bt.Index()].deferCreator(rvalue.Interface()) } - - - diff --git a/src/core/cfls/cval_creators.go b/src/core/cfls/cval_creators.go index 7cc6b20..6e2e271 100644 --- a/src/core/cfls/cval_creators.go +++ b/src/core/cfls/cval_creators.go @@ -30,7 +30,6 @@ package cfls - type ( cValTypeCreators struct { @@ -52,6 +51,19 @@ func createGValTypeCreators [T any] (valType CValType, createFnc func(value T) C } } + +func (c cValTypeCreators) creatorByIndex (idx int) cValTypeCreateFunc { + switch idx { + case cvalCreatorByValue : return c.valueCreator + case cvalCreatorByPointer : return c.pointerCreator + case cvalCreatorByList : return c.listCreator + case cvalCreatorByDefer : return c.deferCreator + default: + return createCValInvalid + } +} + + func createGValTypeList [T any](vType CValType, value []T) CVal { if value == nil { return CVal{cType : vType, cState: cValStateNil} diff --git a/src/core/cfls/cval_type.go b/src/core/cfls/cval_type.go index ce69dd8..bc2dccb 100644 --- a/src/core/cfls/cval_type.go +++ b/src/core/cfls/cval_type.go @@ -30,8 +30,6 @@ package cfls import ( "math/bits" - "reflect" - "time" ) @@ -80,9 +78,9 @@ const ( CValTypeError CValType = 1 << 23 CValTypeNil CValType = 1 << 24 - CValTypeCVal CValType = 1 << 25 - CValTypeFields CValType = 1 << 26 - CValTypeObject CValType = 1 << 27 + CValTypeCVal CValType = 1 << 25 + CValTypeCFields CValType = 1 << 26 + CValTypeObject CValType = 1 << 27 CValTypeDefer CValType = 1 << 28 CValTypeList CValType = 1 << 29 @@ -124,7 +122,7 @@ func (t CValType) ListType () CValType { } func (t CValType) FieldsType() CValType { - if t&CValTypeFields == 0 { + if t&CValTypeCFields == 0 { return CValTypeInvalid } return t &maskCValTypeBase @@ -175,7 +173,7 @@ func (t CValType) IsTypeBaleable () bool { return t&maskCValTypeBase == CValT func (t CValType) IsTypeError () bool { return t&maskCValTypeBase == CValTypeError } func (t CValType) IsTypeNil () bool { return t&maskCValTypeBase == CValTypeNil } func (t CValType) IsTypeCVal () bool { return t&maskCValTypeBase == CValTypeCVal } -func (t CValType) IsFields () bool { return t&CValTypeFields != 0 } +func (t CValType) IsFields () bool { return t&CValTypeCFields != 0 } func (t CValType) IsTypeObject () bool { return t&maskCValTypeBase == CValTypeObject } func (t CValType) IsDefer () bool { return t&CValTypeDefer != 0 } @@ -227,54 +225,3 @@ func BuildMapType(keyType, valType CValType) CValType { } - - -func reflectTypeToCValType (t reflect.Type) CValType { - switch t.Kind() { - case reflect.Bool: - return CValTypeBool - case reflect.Int: - return CValTypeInt - case reflect.Int8: - return CValTypeInt8 - case reflect.Int16: - return CValTypeInt16 - case reflect.Int32: - return CValTypeInt32 - case reflect.Int64: - return CValTypeInt64 - case reflect.Uint: - return CValTypeUint - case reflect.Uint8: - return CValTypeUint8 - case reflect.Uint16: - return CValTypeUint16 - case reflect.Uint32: - return CValTypeUint32 - case reflect.Uint64: - return CValTypeUint64 - case reflect.Uintptr: - return CValTypeUintptr - case reflect.Float32: - return CValTypeFloat32 - case reflect.Float64: - return CValTypeFloat64 - case reflect.Complex64: - return CValTypeComplex64 - case reflect.Complex128: - return CValTypeComplex128 - case reflect.String: - return CValTypeString - - case reflect.Interface: - - case reflect.Struct: - if t == reflect.TypeOf(time.Time{}) { - return CValTypeDate - } - - case reflect.Slice, reflect.Array: - } - - return CValTypeAny -} \ No newline at end of file diff --git a/src/core/cfls/cval_type_cache.go b/src/core/cfls/cval_type_cache.go new file mode 100644 index 0000000..f639210 --- /dev/null +++ b/src/core/cfls/cval_type_cache.go @@ -0,0 +1,200 @@ +// ============================================================================= +// 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. +// / +// ============================================================================ +// ate Create 03/06/2025 +// ============================================================================ + +package cfls + +import ( + "core/blrs" + "core/excs" + "reflect" + "time" +) + +type cValTypeCacheEntry struct { + t CValType + i int + c int + } + +func makeCacheCValTypes () map[reflect.Type]cValTypeCacheEntry { + return map[reflect.Type]cValTypeCacheEntry { + // Any + reflect.TypeOf(any(nil)): {i: 1, t: CValTypeAny, c: 0}, + reflect.TypeOf((*any)(nil)): {i: 1, t: CValTypeAny, c: 1}, + reflect.TypeOf([]any(nil)): {i: 1, t: CValTypeAny|CValTypeList , c: 2}, + reflect.TypeOf((*func()any)(nil)).Elem(): {i: 1, t: CValTypeAny|CValTypeDefer, c: 3}, + + // Bool + reflect.TypeOf(true): {i: 2, t: CValTypeBool, c: 0}, + reflect.TypeOf(new(bool)): {i: 2, t: CValTypeBool, c: 1}, + reflect.TypeOf([]bool(nil)): {i: 2, t: CValTypeBool|CValTypeList , c: 2}, + reflect.TypeOf((*func() bool)(nil)).Elem(): {i: 2, t: CValTypeBool|CValTypeDefer, c: 3}, + + // Int + reflect.TypeOf(int(0)): {i: 3, t: CValTypeInt, c: 0}, + reflect.TypeOf(new(int)): {i: 3, t: CValTypeInt, c: 1}, + reflect.TypeOf([]int(nil)): {i: 3, t: CValTypeInt|CValTypeList , c: 2}, + reflect.TypeOf((*func() int)(nil)).Elem(): {i: 3, t: CValTypeInt|CValTypeDefer, c: 3}, + + // Int8 + reflect.TypeOf(int8(0)): {i: 4, t: CValTypeInt8, c: 0}, + reflect.TypeOf(new(int8)): {i: 4, t: CValTypeInt8, c: 1}, + reflect.TypeOf([]int8(nil)): {i: 4, t: CValTypeInt8|CValTypeList , c: 2}, + reflect.TypeOf((*func() int8)(nil)).Elem(): {i: 4, t: CValTypeInt8|CValTypeDefer, c: 3}, + + // Int16 + reflect.TypeOf(int16(0)): {i: 5, t: CValTypeInt16, c: 0}, + reflect.TypeOf(new(int16)): {i: 5, t: CValTypeInt16, c: 1}, + reflect.TypeOf([]int16(nil)): {i: 5, t: CValTypeInt16|CValTypeList , c: 2}, + reflect.TypeOf((*func() int16)(nil)).Elem(): {i: 5, t: CValTypeInt16|CValTypeDefer, c: 3}, + + // Int32 + reflect.TypeOf(int32(0)): {i: 6, t: CValTypeInt32, c: 0}, + reflect.TypeOf(new(int32)): {i: 6, t: CValTypeInt32, c: 1}, + reflect.TypeOf([]int32(nil)): {i: 6, t: CValTypeInt32|CValTypeList , c: 2}, + reflect.TypeOf((*func() int32)(nil)).Elem(): {i: 6, t: CValTypeInt32|CValTypeDefer, c: 3}, + + // Int64 + reflect.TypeOf(int64(0)): {i: 7, t: CValTypeInt64, c: 0}, + reflect.TypeOf(new(int64)): {i: 7, t: CValTypeInt64, c: 1}, + reflect.TypeOf([]int64(nil)): {i: 7, t: CValTypeInt64|CValTypeList , c: 2}, + reflect.TypeOf((*func() int64)(nil)).Elem(): {i: 7, t: CValTypeInt64|CValTypeDefer, c: 3}, + + // Uint + reflect.TypeOf(uint(0)): {i: 8, t: CValTypeUint, c: 0}, + reflect.TypeOf(new(uint)): {i: 8, t: CValTypeUint, c: 1}, + reflect.TypeOf([]uint(nil)): {i: 8, t: CValTypeUint|CValTypeList , c: 2}, + reflect.TypeOf((*func() uint )(nil)).Elem(): {i: 8, t: CValTypeUint|CValTypeDefer, c: 3}, + + // Uint8 + // Corregimos para que []uint8 sea bytes, un tipo basico + reflect.TypeOf(uint8(0)): {i: 9, t: CValTypeUint8, c: 0}, + reflect.TypeOf(new(uint8)): {i: 9, t: CValTypeUint8, c: 1}, + reflect.TypeOf([]uint8(nil)): {i:21, t: CValTypeUint8, c: 0}, + reflect.TypeOf((*func() uint8 )(nil)).Elem(): {i: 9, t: CValTypeUint8|CValTypeDefer, c: 3}, + + // Uint16 + reflect.TypeOf(uint16(0)): {i: 10, t: CValTypeUint16, c: 0}, + reflect.TypeOf(new(uint16)): {i: 10, t: CValTypeUint16, c: 1}, + reflect.TypeOf([]uint16(nil)): {i: 10, t: CValTypeUint16|CValTypeList , c: 2}, + reflect.TypeOf((*func() uint16 )(nil)).Elem():{i: 10, t: CValTypeUint16|CValTypeDefer, c: 3}, + + // Uint32 + reflect.TypeOf(uint32(0)): {i: 11, t: CValTypeUint32, c: 0}, + reflect.TypeOf(new(uint32)): {i: 11, t: CValTypeUint32, c: 1}, + reflect.TypeOf([]uint32(nil)): {i: 11, t: CValTypeUint32|CValTypeList , c: 2}, + reflect.TypeOf((*func() uint32 )(nil)).Elem():{i: 11, t: CValTypeUint32|CValTypeDefer, c: 3}, + + // Uint64 + reflect.TypeOf(uint64(0)): {i: 12, t: CValTypeUint64, c: 0}, + reflect.TypeOf(new(uint64)): {i: 12, t: CValTypeUint64, c: 1}, + reflect.TypeOf([]uint64(nil)): {i: 12, t: CValTypeUint64|CValTypeList , c: 2}, + reflect.TypeOf((*func() uint64 )(nil)).Elem():{i: 12, t: CValTypeUint64|CValTypeDefer, c: 3}, + + // Uintptr + reflect.TypeOf(uintptr(0)): {i: 13, t: CValTypeUintptr, c: 0}, + reflect.TypeOf(new(uintptr)): {i: 13, t: CValTypeUintptr, c: 1}, + reflect.TypeOf([]uintptr(nil)): {i: 13, t: CValTypeUintptr|CValTypeList , c: 2}, + reflect.TypeOf((*func() uintptr)(nil)).Elem():{i: 13, t: CValTypeUintptr|CValTypeDefer, c: 3}, + + // Float32 + reflect.TypeOf(float32(0)): {i: 14, t: CValTypeFloat32, c: 0}, + reflect.TypeOf(new(float32)): {i: 14, t: CValTypeFloat32, c: 1}, + reflect.TypeOf([]float32(nil)): {i: 14, t: CValTypeFloat32|CValTypeList , c: 2}, + reflect.TypeOf((*func() float32)(nil)).Elem():{i: 14, t: CValTypeFloat32|CValTypeDefer, c: 3}, + + // Float64 + reflect.TypeOf(float64(0)): {i: 15, t: CValTypeFloat64, c: 0}, + reflect.TypeOf(new(float64)): {i: 15, t: CValTypeFloat64, c: 1}, + reflect.TypeOf([]float64(nil)): {i: 15, t: CValTypeFloat64|CValTypeList , c: 2}, + reflect.TypeOf((*func() float64)(nil)).Elem():{i: 15, t: CValTypeFloat64|CValTypeDefer, c: 3}, + + // Complex64 + reflect.TypeOf(complex64(0)): {i: 16, t: CValTypeComplex64, c: 0}, + reflect.TypeOf(new(complex64)): {i: 16, t: CValTypeComplex64, c: 1}, + reflect.TypeOf([]complex64(nil)): {i: 16, t: CValTypeComplex64|CValTypeList , c: 2}, + reflect.TypeOf((*func()complex64)(nil)).Elem():{i: 16, t: CValTypeComplex64|CValTypeDefer, c: 3}, + + // Complex128 + reflect.TypeOf(complex128(0)): {i: 17, t: CValTypeComplex128, c: 0}, + reflect.TypeOf(new(complex128)): {i: 17, t: CValTypeComplex128, c: 1}, + reflect.TypeOf([]complex128(nil)): {i: 17, t: CValTypeComplex128|CValTypeList , c: 2}, + reflect.TypeOf((*func()complex128)(nil)).Elem():{i: 17, t: CValTypeComplex128|CValTypeDefer, c: 3}, + + /* time's */ + + reflect.TypeOf(time.Duration(0)): { i: 18, t:CValTypeDuration, c:0 }, + reflect.TypeOf(new(time.Duration)): { i: 18, t:CValTypeDuration, c:1 }, + reflect.TypeOf([]time.Duration(nil)): { i: 18, t:CValTypeDuration, c:2 }, + reflect.TypeOf((*func ()time.Duration)(nil)).Elem():{ i : 18, t:CValTypeDuration, c:3 }, + + reflect.TypeOf(time.Time{}): { i: 19, t:CValTypeDate, c:0 }, + reflect.TypeOf(new (time.Time)): { i: 19, t:CValTypeDate, c:1 }, + reflect.TypeOf([]time.Time(nil)): { i: 19, t:CValTypeDate, c:2 }, + reflect.TypeOf((*func ()time.Time)(nil)).Elem():{ i: 19, t:CValTypeDate, c:3 }, + + /* Strings, Bytes, Stack */ + reflect.TypeOf(""): { i: 20, t:CValTypeString, c:0 }, + reflect.TypeOf(new (string)): { i: 20, t:CValTypeString, c:1 }, + reflect.TypeOf([]string(nil)): { i: 20, t:CValTypeString, c:2 }, + reflect.TypeOf((*func ()string)(nil)).Elem(): { i: 20, t:CValTypeString, c:3 }, + + reflect.TypeOf([]uint8(nil)): { i: 21, t:CValTypeBytes, c:0 }, + reflect.TypeOf((*[]uint8)(nil)): { i: 21, t:CValTypeBytes, c:1 }, + reflect.TypeOf([][]uint8(nil)): { i: 21, t:CValTypeBytes, c:2 }, + reflect.TypeOf((*func ()[]uint8)(nil)).Elem(): { i: 21, t:CValTypeBytes, c:3 }, + + reflect.TypeOf(excs.Stack(nil)): { i: 22, t:CValTypeStack, c:0 }, + reflect.TypeOf((*excs.Stack)(nil)): { i: 22, t:CValTypeStack, c:1 }, + reflect.TypeOf([]excs.Stack(nil)): { i: 22, t:CValTypeStack, c:2 }, + reflect.TypeOf((*func ()excs.Stack)(nil)).Elem():{i: 22, t:CValTypeStack, c:3 }, + + reflect.TypeOf(blrs.Baleable(nil)): { i: 23, t:CValTypeBaleable, c:0 }, + reflect.TypeOf((*blrs.Baleable)(nil)): { i: 23, t:CValTypeBaleable, c:1 }, + reflect.TypeOf([]blrs.Baleable(nil)): { i: 23, t:CValTypeBaleable, c:2 }, + reflect.TypeOf((*func ()blrs.Baleable)(nil)).Elem(): { i : 23 , t:CValTypeBaleable, c:3 }, + + + reflect.TypeOf(error(nil)): { i: 24, t:CValTypeError, c:0 }, + reflect.TypeOf((*error)(nil)): { i: 24, t:CValTypeError, c:1 }, + reflect.TypeOf([]error(nil)): { i: 24, t:CValTypeError, c:2 }, + reflect.TypeOf((*func ()error)(nil)).Elem():{ i: 24, t:CValTypeError, c:3 }, + + reflect.TypeOf(CVal{}): { i: 26, t:CValTypeCVal, c:0 }, + reflect.TypeOf((*CVal)(nil)): { i: 26, t:CValTypeCVal, c:1 }, + reflect.TypeOf([]CVal(nil)): { i: 26, t:CValTypeCVal, c:2 }, + reflect.TypeOf((*func ()CVal)(nil)): { i: 26, t:CValTypeCVal, c:3 }, + + + reflect.TypeOf(map[string]CVal(nil)): { i: 27, t:CValTypeCVal, c:0 }, + reflect.TypeOf((*CVal)(nil)): { i: 27, t:CValTypeCVal, c:1 }, + reflect.TypeOf([]CVal(nil)): { i: 27, t:CValTypeCVal, c:2 }, + reflect.TypeOf((*func ()CVal)(nil)).Elem(): { i: 27 , t:CValTypeCVal, c:3 }, + + } +} \ No newline at end of file diff --git a/src/core/cfls/cval_type_infos.go b/src/core/cfls/cval_type_infos.go new file mode 100644 index 0000000..9c3c4ea --- /dev/null +++ b/src/core/cfls/cval_type_infos.go @@ -0,0 +1,311 @@ +// ============================================================================= +// 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 04/06/2025 +// ============================================================================= + +package cfls + +import ( + "core/blrs" + "core/excs" + "math/bits" + "reflect" + "time" +) + +const( + cvalCreatorByValue = iota + cvalCreatorByPointer + cvalCreatorByList + cvalCreatorByDefer + + cValNumCreators = 4 +) + + +type ( + + cValTypeInfos struct { + names [maxCValTypes+1]string + creators [maxCValTypes+1][cValNumCreators]func(any)CVal + } +) + + +func createCValTypeInfos () cValTypeInfos { + is := cValTypeInfos{ + names: [maxCValTypes+1]string{ + /* 0: */ "invalid", + /* 1: */ "any", + /* 2: */ "bool", + /* 3: */ "int", + /* 4: */ "int8", + /* 5: */ "int16", + /* 6: */ "int32", + /* 7: */ "int64", + /* 8: */ "uint", + /* 9: */ "uint8", + /* 10: */ "uint16", + /* 11: */ "uint32", + /* 12: */ "uint64", + /* 13: */ "uintptr", + /* 14: */ "float32", + /* 15: */ "float64", + /* 16: */ "complex64", + /* 17: */ "complex128", + /* 18: */ "duration", + /* 19: */ "date", + /* 20: */ "string", + /* 21: */ "bytes", + /* 22: */ "stack", + /* 23: */ "baleable", + /* 24: */ "error", + /* 25: */ "nil", + /* 26: */ "cval", + /* 27: */ "fields", + /* 28: */ "object", + /* 29: */ "defer", + /* 30: */ "list", + /* 31: */ "map", + /* 32: */ "flag", + }, + creators: [maxCValTypes+1][cValNumCreators]func(any)CVal{ + /* 0: */ createGValCreators[any ](CValTypeInvalid, createCValInvalid), + /* 1: */ createGValCreators[any ](CValTypeAny, CreateCValAny), + /* 2: */ createGValCreators[bool ](CValTypeBool, CreateCValBool), + /* 3: */ createGValCreators[int ](CValTypeInt, CreateCValInt), + /* 4: */ createGValCreators[int8 ](CValTypeInt8, CreateCValInt8), + /* 5: */ createGValCreators[int16 ](CValTypeInt16, CreateCValInt16), + /* 6: */ createGValCreators[int32 ](CValTypeInt32, CreateCValInt32), + /* 7: */ createGValCreators[int64 ](CValTypeInt64, CreateCValInt64), + /* 8: */ createGValCreators[uint ](CValTypeUint, CreateCValUint), + /* + caso en el que []uint debe de establecerse como bytes procedemos a construirlo manualmente + */ + /* 9 :*/ { + func(v any) CVal { return CreateCValUint8 (v.(uint8)) }, + func(v any) CVal { return createGValTypePointer (CValTypeUint8, CreateCValUint8, v.(*uint8)) }, + func(v any) CVal { return createGValTypeList (CValTypeBytes, v.([]uint8)) }, + func(v any) CVal { return createGValTypeDefer (CValTypeDefer|CValTypeUint8, v.(func() uint8))}, + }, + + /* 10:*/ createGValCreators[uint16 ](CValTypeUint16, CreateCValUint16), + /* 11:*/ createGValCreators[uint32 ](CValTypeUint32, CreateCValUint32), + /* 12:*/ createGValCreators[uint64 ](CValTypeUint64, CreateCValUint64), + /* 13:*/ createGValCreators[uintptr ](CValTypeUintptr, CreateCValUintptr), + + /* 14:*/ createGValCreators[float32 ](CValTypeFloat32, CreateCValFloat32), + /* 15:*/ createGValCreators[float64 ](CValTypeFloat64, CreateCValFloat64), + /* 16:*/ createGValCreators[complex64 ](CValTypeComplex64,CreateCValComplex64), + /* 17:*/ createGValCreators[complex128 ](CValTypeComplex128,CreateCValComplex128), + + /* 18:*/ createGValCreators[time.Duration](CValTypeDuration,CreateCValDuration), + /* 19:*/ createGValCreators[time.Time ](CValTypeDate, CreateCValDate), + + /* 20:*/ createGValCreators[string ](CValTypeString, CreateCValString), + /* 21:*/ createGValCreators[[]uint8 ](CValTypeBytes, CreateCValBytes), + /* 22:*/ createGValCreators[excs.Stack ](CValTypeStack, CreateCValStack), + /* 23:*/ createGValCreators[blrs.Baleable](CValTypeBaleable,CreateCValBaleable), + /* 24:*/ createGValCreators[error ](CValTypeError, CreateCValError), + /* 25:*/ createGValCreators[any ](CValTypeNil, CreateCValNil), + /* 26:*/ createGValCreators[CVal ](CValTypeCVal, CreateCValCVal), + /* 27:*/ createGValCreators[any ](CValTypeCFields, CreateCValFields), + /* 28:*/ createGValCreators[any ](CValTypeObject, CreateCValObject), + /* 29:*/ createGValCreators[any ](CValTypeDefer, CreateCValDefer), + /* 30:*/ createGValCreators[any ](CValTypeList, CreateCValList), + /* 31:*/ createGValCreators[any ](CValTypeMap, CreateCValMap), + /* 32:*/ createGValCreators[any ](CValTypeObject, createCValInvalid), + }, + } + + + + return is +} + +func (i cValTypeInfos) getCValTypeName (cvalType CValType) string { + if cvalType.IsComposite() { + if cvalType.IsDefer () { + return "defer|" + cvalType.BaseType().String() + } + if cvalType.IsList () { + return "list|" + cvalType.BaseType().String() + } + if cvalType.IsFields() { + return "fields|"+ cvalType.BaseType().String() + } + if cvalType.IsMap () { + k, v := cvalType.MapType() + return "map@" + k.String() + "|" + v.String() + } + } + return i.names[i.getCValTypeIndex(cvalType)] +} + + +func (_ cValTypeInfos) getCValTypeIndex(cvalType CValType) int { + if cvalType == 0 { + return 0 + } + return bits.TrailingZeros32(uint32(cvalType))+1 +} + +func (i cValTypeInfos) getCreator (value any) (f func(v any) CVal) { + switch value.(type) { + /* Valores simples */ + case any : f = i.creators[ 1/* CValTypeAny.Index() */][cvalCreatorByValue] + case bool : f = i.creators[ 2/* CValTypeBool.Index() */][cvalCreatorByValue] + case int : f = i.creators[ 3/* CValTypeInt.Index() */][cvalCreatorByValue] + case int8 : f = i.creators[ 4/* CValTypeInt8.Index() */][cvalCreatorByValue] + case int16 : f = i.creators[ 5/* CValTypeInt16.Index() */][cvalCreatorByValue] + case int32 : f = i.creators[ 6/* CValTypeInt32.Index() */][cvalCreatorByValue] + case int64 : f = i.creators[ 7/* CValTypeInt64.Index() */][cvalCreatorByValue] + case uint : f = i.creators[ 8/* CValTypeUint.Index() */][cvalCreatorByValue] + case uint8 : f = i.creators[ 9/* CValTypeUint8.Index() */][cvalCreatorByValue] + case uint16 : f = i.creators[10/* CValTypeUint16.Index() */][cvalCreatorByValue] + case uint32 : f = i.creators[11/* CValTypeUint32.Index() */][cvalCreatorByValue] + case uint64 : f = i.creators[12/* CValTypeUint64.Index() */][cvalCreatorByValue] + case uintptr : f = i.creators[13/* CValTypeUintptr.Index() */][cvalCreatorByValue] + case float32 : f = i.creators[14/* CValTypeFloat32.Index() */][cvalCreatorByValue] + case float64 : f = i.creators[15/* CValTypeFloat64.Index() */][cvalCreatorByValue] + case complex64 : f = i.creators[16/* CValTypeComplex64.Index() */][cvalCreatorByValue] + case complex128 : f = i.creators[17/* CValTypeComplex128.Index()*/][cvalCreatorByValue] + case time.Duration : f = i.creators[18/* CValTypeDuration.Index() */][cvalCreatorByValue] + case time.Time : f = i.creators[19/* CValTypeDate.Index() */][cvalCreatorByValue] + case string : f = i.creators[20/* CValTypeString.Index() */][cvalCreatorByValue] + case []uint8 : f = i.creators[21/* CValTypeBytes.Index() */][cvalCreatorByValue] + case excs.Stack : f = i.creators[22/* CValTypeStack.Index() */][cvalCreatorByValue] + case blrs.Baleable : f = i.creators[23/* CValTypeBaleable.Index() */][cvalCreatorByValue] + case error : f = i.creators[24/* CValTypeError.Index() */][cvalCreatorByValue] + case CVal : f = i.creators[26/* CValTypeCVal.Index() */][cvalCreatorByValue] + case CFields : f = i.creators[27 /* CValTypeCFields.Index() */][cvalCreatorByValue] + + /* Valores Listas */ + case []any : f = i.creators[ 1/* CValTypeAny.Index() */][cvalCreatorByList] + case []bool : f = i.creators[ 2/* CValTypeBool.Index() */][cvalCreatorByList] + case []int : f = i.creators[ 3/* CValTypeInt.Index() */][cvalCreatorByList] + case []int8 : f = i.creators[ 4/* CValTypeInt8.Index() */][cvalCreatorByList] + case []int16 : f = i.creators[ 5/* CValTypeInt16.Index() */][cvalCreatorByList] + case []int32 : f = i.creators[ 6/* CValTypeInt32.Index() */][cvalCreatorByList] + case []int64 : f = i.creators[ 7/* CValTypeInt64.Index() */][cvalCreatorByList] + case []uint : f = i.creators[ 8/* CValTypeUint.Index() */][cvalCreatorByList] + // ya establecido como tipo base + //case []uint8 : f = i.creators[ 9/* CValTypeUint8.Index() */].listCreator + // + case []uint16 : f = i.creators[10/* CValTypeUint16.Index() */][cvalCreatorByList] + case []uint32 : f = i.creators[11/* CValTypeUint32.Index() */][cvalCreatorByList] + case []uint64 : f = i.creators[12/* CValTypeUint64.Index() */][cvalCreatorByList] + case []uintptr : f = i.creators[13/* CValTypeUintptr.Index() */][cvalCreatorByList] + case []float32 : f = i.creators[14/* CValTypeFloat32.Index() */][cvalCreatorByList] + case []float64 : f = i.creators[15/* CValTypeFloat64.Index() */][cvalCreatorByList] + case []complex64 : f = i.creators[16/* CValTypeComplex64.Index() */][cvalCreatorByList] + case []complex128 : f = i.creators[17/* CValTypeComplex128.Index()*/][cvalCreatorByList] + case []time.Duration: f = i.creators[18/* CValTypeDuration.Index() */][cvalCreatorByList] + case []time.Time : f = i.creators[19/* CValTypeDate.Index() */][cvalCreatorByList] + case []string : f = i.creators[20/* CValTypeString.Index() */][cvalCreatorByList] + case []excs.Stack : f = i.creators[22/* CValTypeStack.Index() */][cvalCreatorByList] + case []blrs.Baleable: f = i.creators[23/* CValTypeBaleable.Index() */][cvalCreatorByList] + case []error : f = i.creators[24/* CValTypeError.Index() */][cvalCreatorByList] + case []CVal : f = i.creators[26/* CValTypeCVal.Index() */][cvalCreatorByList] + case []CFields : f = i.creators[27 /* CValTypeCFields.Index() */][cvalCreatorByList] + + /* Valores pasados por punteros */ + case *any : f = i.creators[ 1/* CValTypeAny.Index() */][cvalCreatorByPointer] + case *bool : f = i.creators[ 2/* CValTypeBool.Index() */][cvalCreatorByPointer] + case *int : f = i.creators[ 3/* CValTypeInt.Index() */][cvalCreatorByPointer] + case *int8 : f = i.creators[ 4/* CValTypeInt8.Index() */][cvalCreatorByPointer] + case *int16 : f = i.creators[ 5/* CValTypeInt16.Index() */][cvalCreatorByPointer] + case *int32 : f = i.creators[ 6/* CValTypeInt32.Index() */][cvalCreatorByPointer] + case *int64 : f = i.creators[ 7/* CValTypeInt64.Index() */][cvalCreatorByPointer] + case *uint : f = i.creators[ 8/* CValTypeUint.Index() */][cvalCreatorByPointer] + case *uint8 : f = i.creators[ 9/* CValTypeUint8.Index() */][cvalCreatorByPointer] + case *uint16 : f = i.creators[10/* CValTypeUint16.Index() */][cvalCreatorByPointer] + case *uint32 : f = i.creators[11/* CValTypeUint32.Index() */][cvalCreatorByPointer] + case *uint64 : f = i.creators[12/* CValTypeUint64.Index() */][cvalCreatorByPointer] + case *uintptr : f = i.creators[13/* CValTypeUintptr.Index() */][cvalCreatorByPointer] + case *float32 : f = i.creators[14/* CValTypeFloat32.Index() */][cvalCreatorByPointer] + case *float64 : f = i.creators[15/* CValTypeFloat64.Index() */][cvalCreatorByPointer] + case *complex64 : f = i.creators[16/* CValTypeComplex64.Index() */][cvalCreatorByPointer] + case *complex128 : f = i.creators[17/* CValTypeComplex128.Index()*/][cvalCreatorByPointer] + case *time.Duration : f = i.creators[18/* CValTypeDuration.Index() */][cvalCreatorByPointer] + case *time.Time : f = i.creators[19/* CValTypeDate.Index() */][cvalCreatorByPointer] + case *string : f = i.creators[20/* CValTypeString.Index() */][cvalCreatorByPointer] + case *[]uint8 : f = i.creators[21/* CValTypeBytes.Index() */][cvalCreatorByPointer] + case *excs.Stack : f = i.creators[22/* CValTypeStack.Index() */][cvalCreatorByPointer] + case *blrs.Baleable : f = i.creators[23/* CValTypeBaleable.Index() */][cvalCreatorByPointer] + case *error : f = i.creators[24/* CValTypeError.Index() */][cvalCreatorByPointer] + case *CVal : f = i.creators[26/* CValTypeCVal.Index() */][cvalCreatorByPointer] + case *CFields : f = i.creators[27 /* CValTypeCFields.Index() */][cvalCreatorByPointer] + + /* Valores pasados por functions defers */ + case func()any : f = i.creators[ 1/* CValTypeAny.Index() */][cvalCreatorByDefer] + case func()bool : f = i.creators[ 2/* CValTypeBool.Index() */][cvalCreatorByDefer] + case func()int : f = i.creators[ 3/* CValTypeInt.Index() */][cvalCreatorByDefer] + case func()int8 : f = i.creators[ 4/* CValTypeInt8.Index() */][cvalCreatorByDefer] + case func()int16 : f = i.creators[ 5/* CValTypeInt16.Index() */][cvalCreatorByDefer] + case func()int32 : f = i.creators[ 6/* CValTypeInt32.Index() */][cvalCreatorByDefer] + case func()int64 : f = i.creators[ 7/* CValTypeInt64.Index() */][cvalCreatorByDefer] + case func()uint : f = i.creators[ 8/* CValTypeUint.Index() */][cvalCreatorByDefer] + case func()uint8 : f = i.creators[ 9/* CValTypeUint8.Index() */][cvalCreatorByDefer] + case func()uint16 : f = i.creators[10/* CValTypeUint16.Index() */][cvalCreatorByDefer] + case func()uint32 : f = i.creators[11/* CValTypeUint32.Index() */][cvalCreatorByDefer] + case func()uint64 : f = i.creators[12/* CValTypeUint64.Index() */][cvalCreatorByDefer] + case func()uintptr : f = i.creators[13/* CValTypeUintptr.Index() */][cvalCreatorByDefer] + case func()float32 : f = i.creators[14/* CValTypeFloat32.Index() */][cvalCreatorByDefer] + case func()float64 : f = i.creators[15/* CValTypeFloat64.Index() */][cvalCreatorByDefer] + case func()complex64 : f = i.creators[16/* CValTypeComplex64.Index() */][cvalCreatorByDefer] + case func()complex128 : f = i.creators[17/* CValTypeComplex128.Index()*/][cvalCreatorByDefer] + case func()time.Duration: f = i.creators[18/* CValTypeDuration.Index() */][cvalCreatorByDefer] + case func()time.Time : f = i.creators[19/* CValTypeDate.Index() */][cvalCreatorByDefer] + case func()string : f = i.creators[20/* CValTypeString.Index() */][cvalCreatorByDefer] + case func()[]uint8 : f = i.creators[21/* CValTypeBytes.Index() */][cvalCreatorByDefer] + case func()excs.Stack : f = i.creators[22/* CValTypeStack.Index() */][cvalCreatorByDefer] + case func()blrs.Baleable: f = i.creators[23/* CValTypeBaleable.Index() */][cvalCreatorByDefer] + case func()error : f = i.creators[24/* CValTypeError.Index() */][cvalCreatorByDefer] + case func()CVal : f = i.creators[26/* CValTypeCVal.Index() */][cvalCreatorByDefer] + case func()CFields : f = i.creators[27/* CValTypeCFields.Index() */][cvalCreatorByDefer] + + default: + + rv := reflect.ValueOf(value) + + + } + + return +} + + + + +func createGValCreators [T any] (valType CValType, createFnc func(value T) CVal) [cValNumCreators]func(any)CVal { + return [cValNumCreators]func(any)CVal { + func(v any) CVal { return createFnc(v.(T)) }, + func(v any) CVal { return createGValTypePointer(valType,createFnc,v.(*T))}, + func(v any) CVal { return createGValTypeList (CValTypeList |valType,v.([]T)) }, + func(v any) CVal { return createGValTypeDefer(CValTypeDefer|valType,v.(func() T)) }, + } +} \ No newline at end of file diff --git a/src/core/cflss/a.go b/src/core/cflss/a.go new file mode 100644 index 0000000..fbb60c0 --- /dev/null +++ b/src/core/cflss/a.go @@ -0,0 +1,29 @@ +// ============================================================================= +// 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 05/06/2025 +// ============================================================================= + +package cflss diff --git a/src/core/cflss/cfield.go b/src/core/cflss/cfield.go new file mode 100644 index 0000000..db3ce6d --- /dev/null +++ b/src/core/cflss/cfield.go @@ -0,0 +1,43 @@ +// ============================================================================= +// 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 04/06/2025 +// ============================================================================= + +package cflss + + + + +type ( + + CField struct { + Name string + Value CValue + } + +) + + diff --git a/src/core/cflss/cvalue.go b/src/core/cflss/cvalue.go new file mode 100644 index 0000000..b214096 --- /dev/null +++ b/src/core/cflss/cvalue.go @@ -0,0 +1,80 @@ +// ============================================================================= +// 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 04/06/2025 +// ============================================================================= + +package cflss + +type CValue struct { + vType CValueType + vState CValueState + intVal int64 + strVal string + anyVal any +} + + + + + +func CreateCValueAny (value any ) CValue { return CValue{ } } +func CreateCValueBool (value bool ) CValue { return CValue{ } } +func CreateCValueInt (value int ) CValue { return CValue{ } } +func CreateCValueInt8 (value int8 ) CValue { return CValue{ } } +func CreateCValueInt16 (value int16 ) CValue { return CValue{ } } +func CreateCValueInt32 (value int32 ) CValue { return CValue{ } } +func CreateCValueInt64 (value int64 ) CValue { return CValue{ } } +func CreateCValueUint (value uint ) CValue { return CValue{ } } +func CreateCValueUint8 (value uint8 ) CValue { return CValue{ } } +func CreateCValueUint16 (value uint16 ) CValue { return CValue{ } } +func CreateCValueUint32 (value uint32 ) CValue { return CValue{ } } +func CreateCValueUint64 (value uint64 ) CValue { return CValue{ } } +func CreateCValueUintptr (value uintptr ) CValue { return CValue{ } } +func CreateCValueFloat32 (value float32 ) CValue { return CValue{ } } +func CreateCValueFloat64 (value float64 ) CValue { return CValue{ } } +func CreateCValueComplex64 (value complex64 ) CValue { return CValue{ } } +func CreateCValueComplex128 (value complex128) CValue { return CValue{ } } +func CreateCValueDuration (value Duration ) CValue { return CValue{ } } +func CreateCValueDate (value Date ) CValue { return CValue{ } } +func CreateCValueString (value string ) CValue { return CValue{ } } +func CreateCValueBytes (value []uint8 ) CValue { return CValue{ } } +func CreateCValueStack (value Stack ) CValue { return CValue{ } } +func CreateCValueBaleable (value Baleable ) CValue { return CValue{ } } +func CreateCValueError (value error ) CValue { return CValue{ } } +func CreateCValueNil (value any ) CValue { return CValue{ } } +func CreateCValue (value CValue ) CValue { return CValue{ } } +func CreateCValueCField (value CField ) CValue { return CValue{ } } +func CreateCValueObject (value any ) CValue { return CValue{ } } + + +func CreateCValueDefer (value any) CValue { return CValue{ } } +func CreateCValueList (value any) CValue { return CValue{ } } +func CreateCValueMap (value any) CValue { return CValue{ } } + + +func createCValueInvalid (value any) CValue { + return CValue{} +} diff --git a/src/core/cflss/cvalue_state.go b/src/core/cflss/cvalue_state.go new file mode 100644 index 0000000..1d53a2d --- /dev/null +++ b/src/core/cflss/cvalue_state.go @@ -0,0 +1,66 @@ +// ============================================================================= +// 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 04/06/2025 +// ============================================================================= + +package cflss + + + + + +const ( + + cValueStateInvalid CValueState = 1 << iota // El valor almacenado es un valor invalido + cValueStateNil // Indica que el valor es nulo + cValueStateZero // Indica que el valor tiene valor 0 + cValueStateReflected // Indica que el valor guardado es un value.reflect + cValueStateShort // Indica que el valor es la versión corta del valor, por ejemplo: los dates + cValueStateSensitive // Indica que el valor es delicado, por ejemplo no mostrar o no serializar + cValueStateEncoded // Indica que el valor está codificado + cValueStateError // Indica que el valor no ha podido ser establecido por un error que esta representado en el + // valor + + cValueStateNone CValueState = 0 + + cValueStateOps CValueState = cValueStateEncoded|cValueStateSensitive +) + + +type CValueState uint8 + + +func (s CValueState) HasValueInvalid () bool { return s&cValueStateInvalid != 0 } +func (s CValueState) HasValueNil () bool { return s&cValueStateNil != 0 } +func (s CValueState) HasValueZero () bool { return s&cValueStateZero != 0 } +func (s CValueState) HasValueReflected() bool { return s&cValueStateReflected != 0 } +func (s CValueState) HasValueShort () bool { return s&cValueStateShort != 0 } +func (s CValueState) HasValueSensitive() bool { return s&cValueStateSensitive != 0 } +func (s CValueState) HasValueEncoded () bool { return s&cValueStateEncoded != 0 } +func (s CValueState) HasValueError () bool { return s&cValueStateError != 0 } + + +func (s CValueState) setOption (options CValueState) CValueState { return s|(options&cValueStateOps) } diff --git a/src/core/cflss/cvalue_type.go b/src/core/cflss/cvalue_type.go new file mode 100644 index 0000000..643cde2 --- /dev/null +++ b/src/core/cflss/cvalue_type.go @@ -0,0 +1,175 @@ +// ============================================================================= +// 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 04/06/2025 +// ============================================================================= + +package cflss + +import ( + "math/bits" +) + + +const ( + + maxCValueTypes int = 32 + + // CValueType's definidos + CValueTypeInvalid CValueType = 0 + + CValueTypeAny CValueType = 1 << 0 + CValueTypeBool CValueType = 1 << 1 + + CValueTypeInt CValueType = 1 << 2 + CValueTypeInt8 CValueType = 1 << 3 + CValueTypeInt16 CValueType = 1 << 4 + CValueTypeInt32 CValueType = 1 << 5 + CValueTypeInt64 CValueType = 1 << 6 + + CValueTypeUint CValueType = 1 << 7 + CValueTypeUint8 CValueType = 1 << 8 + CValueTypeUint16 CValueType = 1 << 9 + CValueTypeUint32 CValueType = 1 << 10 + CValueTypeUint64 CValueType = 1 << 11 + + CValueTypeUintptr CValueType = 1 << 12 + + CValueTypeFloat32 CValueType = 1 << 13 + CValueTypeFloat64 CValueType = 1 << 14 + + CValueTypeComplex64 CValueType = 1 << 15 + CValueTypeComplex128 CValueType = 1 << 16 + + CValueTypeDuration CValueType = 1 << 17 + CValueTypeDate CValueType = 1 << 18 + + CValueTypeString CValueType = 1 << 19 + CValueTypeBytes CValueType = 1 << 20 + CValueTypeStack CValueType = 1 << 21 + + CValueTypeBaleable CValueType = 1 << 22 + CValueTypeError CValueType = 1 << 23 + + CValueTypeNil CValueType = 1 << 24 + + CValueTypeCValue CValueType = 1 << 25 + CValueTypeCField CValueType = 1 << 26 + CValueTypeObject CValueType = 1 << 27 + + CValueTypeDefer CValueType = 1 << 28 + CValueTypeList CValueType = 1 << 29 + CValueTypeMap CValueType = 1 << 30 + CValueTypeMapKey CValueType = 1 << 31 + + + maskCValueTypeComposite= CValueTypeDefer|CValueTypeList|CValueTypeMap + maskCValueTypeBase = ^(maskCValueTypeComposite | CValueTypeMapKey) +) + + +type ( + CValueType uint32 + + +) + +func (t CValueType) IsComposite() bool { return t&maskCValueTypeComposite != 0 } + +func (t CValueType) BaseType () CValueType { + if t&CValueTypeMap == 0 { + return t &maskCValueTypeBase + } + _,vt := t.MapType() + return vt +} + +func (t CValueType) MapType () (CValueType,CValueType) { + if t&CValueTypeMap == 0 { + return CValueTypeInvalid, CValueTypeInvalid + } + bs := t &maskCValueTypeBase + switch bits.OnesCount32(uint32(bs)) { + case 1: return bs,bs + case 2: + if t&CValueTypeMapKey == 0 { + return bs&-bs,bs&^(bs&-bs) + } + return bs&^(bs&-bs),bs&-bs + default: + return CValueTypeInvalid,CValueTypeInvalid + } +} + + +func (t CValueType) IsTypeInvalid () bool { return t&maskCValueTypeBase == CValueTypeInvalid } +func (t CValueType) IsTypeAny () bool { return t&maskCValueTypeBase == CValueTypeAny } +func (t CValueType) IsTypeBool () bool { return t&maskCValueTypeBase == CValueTypeBool } +func (t CValueType) IsTypeInt () bool { return t&maskCValueTypeBase == CValueTypeInt } +func (t CValueType) IsTypeInt8 () bool { return t&maskCValueTypeBase == CValueTypeInt8 } +func (t CValueType) IsTypeInt16 () bool { return t&maskCValueTypeBase == CValueTypeInt16 } +func (t CValueType) IsTypeInt32 () bool { return t&maskCValueTypeBase == CValueTypeInt32 } +func (t CValueType) IsTypeInt64 () bool { return t&maskCValueTypeBase == CValueTypeInt64 } +func (t CValueType) IsTypeUint () bool { return t&maskCValueTypeBase == CValueTypeUint } +func (t CValueType) IsTypeUint8 () bool { return t&maskCValueTypeBase == CValueTypeUint8 } +func (t CValueType) IsTypeUint16 () bool { return t&maskCValueTypeBase == CValueTypeUint16 } +func (t CValueType) IsTypeUint32 () bool { return t&maskCValueTypeBase == CValueTypeUint32 } +func (t CValueType) IsTypeUint64 () bool { return t&maskCValueTypeBase == CValueTypeUint64 } +func (t CValueType) IsTypeUintptr () bool { return t&maskCValueTypeBase == CValueTypeUintptr } +func (t CValueType) IsTypeFloat32 () bool { return t&maskCValueTypeBase == CValueTypeFloat32 } +func (t CValueType) IsTypeFloat64 () bool { return t&maskCValueTypeBase == CValueTypeFloat64 } +func (t CValueType) IsTypeComplex64 () bool { return t&maskCValueTypeBase == CValueTypeComplex64} +func (t CValueType) IsTypeComplex128 () bool { return t&maskCValueTypeBase == CValueTypeComplex128} +func (t CValueType) IsTypeDuration () bool { return t&maskCValueTypeBase == CValueTypeDuration } +func (t CValueType) IsTypeDate () bool { return t&maskCValueTypeBase == CValueTypeDate } +func (t CValueType) IsTypeString () bool { return t&maskCValueTypeBase == CValueTypeString } +func (t CValueType) IsTypeBytes () bool { return t&maskCValueTypeBase == CValueTypeBytes } +func (t CValueType) IsTypeStack () bool { return t&maskCValueTypeBase == CValueTypeStack } +func (t CValueType) IsTypeBaleable () bool { return t&maskCValueTypeBase == CValueTypeBaleable } +func (t CValueType) IsTypeError () bool { return t&maskCValueTypeBase == CValueTypeError } +func (t CValueType) IsTypeNil () bool { return t&maskCValueTypeBase == CValueTypeNil } +func (t CValueType) IsTypeCVal () bool { return t&maskCValueTypeBase == CValueTypeCValue } +func (t CValueType) IsTypeCField () bool { return t&CValueTypeCField == CValueTypeCField } +func (t CValueType) IsTypeObject () bool { return t&maskCValueTypeBase == CValueTypeObject } + +func (t CValueType) IsDefer () bool { return t&CValueTypeDefer != 0 } +func (t CValueType) IsList () bool { return t&CValueTypeList != 0 } +func (t CValueType) IsMap () bool { return t&CValueTypeMap != 0 } + + +func buildMapType(keyType, valType CValueType) CValueType { + if keyType == CValueTypeInvalid || valType == CValueTypeInvalid { + return CValueTypeInvalid + } + if keyType == valType { + return CValueTypeMap|keyType + } + if keyType < valType { + return CValueTypeMap|keyType|valType + } + return CValueTypeMap|valType|keyType|CValueTypeMapKey +} + + diff --git a/src/core/cflss/cvalue_type_infos.go b/src/core/cflss/cvalue_type_infos.go new file mode 100644 index 0000000..de82e11 --- /dev/null +++ b/src/core/cflss/cvalue_type_infos.go @@ -0,0 +1,335 @@ +// ============================================================================= +// 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 05/06/2025 +// ============================================================================= + +package cflss + +import ( +"math/bits" +"reflect" + +) + +const( + cValueByVal = iota + cValueByPtr + cValueByLst + cValueByDfr + + cValueNumCreators = 4 +) + + +type ( + + CValueTypeInfos struct { + names [maxCValueTypes+1]string + creators [maxCValueTypes+1][cValueNumCreators]func(any)CValue + } +) + + +func createCValueTypeInfos () CValueTypeInfos { + is := CValueTypeInfos{ + names: [maxCValueTypes+1]string{ + /* 0: */ "invalid", + /* 1: */ "any", + /* 2: */ "bool", + /* 3: */ "int", + /* 4: */ "int8", + /* 5: */ "int16", + /* 6: */ "int32", + /* 7: */ "int64", + /* 8: */ "uint", + /* 9: */ "uint8", + /* 10: */ "uint16", + /* 11: */ "uint32", + /* 12: */ "uint64", + /* 13: */ "uintptr", + /* 14: */ "float32", + /* 15: */ "float64", + /* 16: */ "complex64", + /* 17: */ "complex128", + /* 18: */ "duration", + /* 19: */ "date", + /* 20: */ "string", + /* 21: */ "bytes", + /* 22: */ "stack", + /* 23: */ "baleable", + /* 24: */ "error", + /* 25: */ "nil", + /* 26: */ "CValue", + /* 27: */ "CField", + /* 28: */ "object", + /* 29: */ "defer", + /* 30: */ "list", + /* 31: */ "map", + /* 32: */ "flag", + }, + creators: [maxCValueTypes+1][cValueNumCreators]func(any)CValue{ + /* 0: */ createGValCreators[any ](CValueTypeInvalid,createCValueInvalid), + /* 1: */ createGValCreators[any ](CValueTypeAny, CreateCValueAny), + /* 2: */ createGValCreators[bool ](CValueTypeBool, CreateCValueBool), + /* 3: */ createGValCreators[int ](CValueTypeInt, CreateCValueInt), + /* 4: */ createGValCreators[int8 ](CValueTypeInt8, CreateCValueInt8), + /* 5: */ createGValCreators[int16 ](CValueTypeInt16, CreateCValueInt16), + /* 6: */ createGValCreators[int32 ](CValueTypeInt32, CreateCValueInt32), + /* 7: */ createGValCreators[int64 ](CValueTypeInt64, CreateCValueInt64), + /* 8: */ createGValCreators[uint ](CValueTypeUint, CreateCValueUint), + /* + caso en el que []uint debe de establecerse como bytes procedemos a construirlo manualmente + */ + /* 9 :*/ { + func(v any) CValue { return CreateCValueUint8 (v.(uint8)) }, + func(v any) CValue { return createGValTypePointer(CValueTypeUint8, CreateCValueUint8, v.(*uint8)) }, + func(v any) CValue { return createGValTypeList (CValueTypeBytes, v.([]uint8)) }, + func(v any) CValue { return createGValTypeDefer (CValueTypeDefer|CValueTypeUint8, v.(func() uint8))}, + }, + + /* 10:*/ createGValCreators[uint16 ](CValueTypeUint16, CreateCValueUint16), + /* 11:*/ createGValCreators[uint32 ](CValueTypeUint32, CreateCValueUint32), + /* 12:*/ createGValCreators[uint64 ](CValueTypeUint64, CreateCValueUint64), + /* 13:*/ createGValCreators[uintptr ](CValueTypeUintptr, CreateCValueUintptr), + + /* 14:*/ createGValCreators[float32 ](CValueTypeFloat32, CreateCValueFloat32), + /* 15:*/ createGValCreators[float64 ](CValueTypeFloat64, CreateCValueFloat64), + /* 16:*/ createGValCreators[complex64 ](CValueTypeComplex64, CreateCValueComplex64), + /* 17:*/ createGValCreators[complex128 ](CValueTypeComplex128, CreateCValueComplex128), + + /* 18:*/ createGValCreators[Duration ](CValueTypeDuration, CreateCValueDuration), + /* 19:*/ createGValCreators[Date ](CValueTypeDate, CreateCValueDate), + + /* 20:*/ createGValCreators[string ](CValueTypeString, CreateCValueString), + /* 21:*/ createGValCreators[Bytes ](CValueTypeBytes, CreateCValueBytes), + /* 22:*/ createGValCreators[Stack ](CValueTypeStack, CreateCValueStack), + /* 23:*/ createGValCreators[Baleable ](CValueTypeBaleable, CreateCValueBaleable), + /* 24:*/ createGValCreators[error ](CValueTypeError, CreateCValueError), + /* 25:*/ createGValCreators[any ](CValueTypeNil, CreateCValueNil), + /* 26:*/ createGValCreators[CValue ](CValueTypeCValue, CreateCValue), + /* 27:*/ createGValCreators[CField ](CValueTypeCField, CreateCValueCField), + /* 28:*/ createGValCreators[any ](CValueTypeObject, CreateCValueObject), + /* 29:*/ createGValCreators[any ](CValueTypeDefer, CreateCValueDefer), + /* 30:*/ createGValCreators[any ](CValueTypeList, CreateCValueList), + /* 31:*/ createGValCreators[any ](CValueTypeMap, CreateCValueMap), + /* 32:*/ createGValCreators[any ](CValueTypeObject, createCValueInvalid), + }, + } + + + + return is +} + +func (i CValueTypeInfos) getName(CValueType CValueType) string { + if CValueType.IsComposite() { + if CValueType.IsDefer () { + return "defer|" + i.getName(CValueType.BaseType()) + } + if CValueType.IsList () { + return "list|" + i.getName(CValueType.BaseType()) + } + if CValueType.IsMap () { + k, v := CValueType.MapType() + return "map@" + i.getName(k) + "|" + i.getName(v) + } + } + return i.names[i.getIndex(CValueType)] +} + +func (_ CValueTypeInfos) getIndex(CValueType CValueType) int { + if CValueType == 0 { + return 0 + } + return bits.TrailingZeros32(uint32(CValueType))+1 +} + +func (i CValueTypeInfos) getCreator (value any) (f func(v any) CValue) { + switch value.(type) { + /* Valores simples */ + case any : f = i.creators[ 1/* Any */][cValueByVal] + case bool : f = i.creators[ 2/* Bool */][cValueByVal] + case int : f = i.creators[ 3/* Int */][cValueByVal] + case int8 : f = i.creators[ 4/* Int8 */][cValueByVal] + case int16 : f = i.creators[ 5/* Int16 */][cValueByVal] + case int32 : f = i.creators[ 6/* Int32 */][cValueByVal] + case int64 : f = i.creators[ 7/* Int64 */][cValueByVal] + case uint : f = i.creators[ 8/* Uint */][cValueByVal] + case uint8 : f = i.creators[ 9/* Uint8 */][cValueByVal] + case uint16 : f = i.creators[10/* Uint16 */][cValueByVal] + case uint32 : f = i.creators[11/* Uint32 */][cValueByVal] + case uint64 : f = i.creators[12/* Uint64 */][cValueByVal] + case uintptr : f = i.creators[13/* Uintptr */][cValueByVal] + case float32 : f = i.creators[14/* Float32 */][cValueByVal] + case float64 : f = i.creators[15/* Float64 */][cValueByVal] + case complex64 : f = i.creators[16/* Complex64 */][cValueByVal] + case complex128 : f = i.creators[17/* Complex128*/][cValueByVal] + case Duration : f = i.creators[18/* Duration */][cValueByVal] + case Date : f = i.creators[19/* Date */][cValueByVal] + case string : f = i.creators[20/* String */][cValueByVal] + case Bytes : f = i.creators[21/* Bytes */][cValueByVal] + case Stack : f = i.creators[22/* Stack */][cValueByVal] + case Baleable : f = i.creators[23/* Baleable */][cValueByVal] + case error : f = i.creators[24/* Error */][cValueByVal] + case CValue : f = i.creators[26/* CVal */][cValueByVal] + case CField : f = i.creators[27/* CCField */][cValueByVal] + + /* Valores Listas */ + case []any : f = i.creators[ 1/* Any */][cValueByLst] + case []bool : f = i.creators[ 2/* Bool */][cValueByLst] + case []int : f = i.creators[ 3/* Int */][cValueByLst] + case []int8 : f = i.creators[ 4/* Int8 */][cValueByLst] + case []int16 : f = i.creators[ 5/* Int16 */][cValueByLst] + case []int32 : f = i.creators[ 6/* Int32 */][cValueByLst] + case []int64 : f = i.creators[ 7/* Int64 */][cValueByLst] + case []uint : f = i.creators[ 8/* Uint */][cValueByLst] + // ya establecido como tipo base Bytes + //case []uint8 : f = i.creators[ 9/* CValueTypeUint8 */].listCreator + // + case []uint16 : f = i.creators[10/* Uint16 */][cValueByLst] + case []uint32 : f = i.creators[11/* Uint32 */][cValueByLst] + case []uint64 : f = i.creators[12/* Uint64 */][cValueByLst] + case []uintptr : f = i.creators[13/* Uintptr */][cValueByLst] + case []float32 : f = i.creators[14/* Float32 */][cValueByLst] + case []float64 : f = i.creators[15/* Float64 */][cValueByLst] + case []complex64 : f = i.creators[16/* Complex64 */][cValueByLst] + case []complex128 : f = i.creators[17/* Complex128*/][cValueByLst] + case []Duration : f = i.creators[18/* Duration */][cValueByLst] + case []Date : f = i.creators[19/* Date */][cValueByLst] + case []string : f = i.creators[20/* String */][cValueByLst] + case []Bytes : f = i.creators[21/* String */][cValueByLst] + case []Stack : f = i.creators[22/* Stack */][cValueByLst] + case []Baleable : f = i.creators[23/* Baleable */][cValueByLst] + case []error : f = i.creators[24/* Error */][cValueByLst] + case []CValue : f = i.creators[26/* CValue */][cValueByLst] + case []CField : f = i.creators[27/* CField */][cValueByLst] + + /* Valores pasados por punteros */ + case *any : f = i.creators[ 1/* Any */][cValueByPtr] + case *bool : f = i.creators[ 2/* Bool */][cValueByPtr] + case *int : f = i.creators[ 3/* Int */][cValueByPtr] + case *int8 : f = i.creators[ 4/* Int8 */][cValueByPtr] + case *int16 : f = i.creators[ 5/* Int16 */][cValueByPtr] + case *int32 : f = i.creators[ 6/* Int32 */][cValueByPtr] + case *int64 : f = i.creators[ 7/* Int64 */][cValueByPtr] + case *uint : f = i.creators[ 8/* Uint */][cValueByPtr] + case *uint8 : f = i.creators[ 9/* Uint8 */][cValueByPtr] + case *uint16 : f = i.creators[10/* Uint16 */][cValueByPtr] + case *uint32 : f = i.creators[11/* Uint32 */][cValueByPtr] + case *uint64 : f = i.creators[12/* Uint64 */][cValueByPtr] + case *uintptr : f = i.creators[13/* Uintptr */][cValueByPtr] + case *float32 : f = i.creators[14/* Float32 */][cValueByPtr] + case *float64 : f = i.creators[15/* Float64 */][cValueByPtr] + case *complex64 : f = i.creators[16/* Complex64 */][cValueByPtr] + case *complex128: f = i.creators[17/* Complex128*/][cValueByPtr] + case *Duration : f = i.creators[18/* Duration */][cValueByPtr] + case *Date : f = i.creators[19/* Date */][cValueByPtr] + case *string : f = i.creators[20/* String */][cValueByPtr] + case *Bytes : f = i.creators[21/* Bytes */][cValueByPtr] + case *Stack : f = i.creators[22/* Stack */][cValueByPtr] + case *Baleable : f = i.creators[23/* Baleable */][cValueByPtr] + case *error : f = i.creators[24/* Error */][cValueByPtr] + case *CValue : f = i.creators[26/* CValue */][cValueByPtr] + case *CField : f = i.creators[27/* CField */][cValueByPtr] + + /* Valores pasados por functions defers */ + case func()any : f = i.creators[ 1/* Any */][cValueByDfr] + case func()bool : f = i.creators[ 2/* Bool */][cValueByDfr] + case func()int : f = i.creators[ 3/* Int */][cValueByDfr] + case func()int8 : f = i.creators[ 4/* Int8 */][cValueByDfr] + case func()int16 : f = i.creators[ 5/* Int16 */][cValueByDfr] + case func()int32 : f = i.creators[ 6/* Int32 */][cValueByDfr] + case func()int64 : f = i.creators[ 7/* Int64 */][cValueByDfr] + case func()uint : f = i.creators[ 8/* Uint */][cValueByDfr] + case func()uint8 : f = i.creators[ 9/* Uint8 */][cValueByDfr] + case func()uint16 : f = i.creators[10/* Uint16 */][cValueByDfr] + case func()uint32 : f = i.creators[11/* Uint32 */][cValueByDfr] + case func()uint64 : f = i.creators[12/* Uint64 */][cValueByDfr] + case func()uintptr : f = i.creators[13/* Uintptr */][cValueByDfr] + case func()float32 : f = i.creators[14/* Float32 */][cValueByDfr] + case func()float64 : f = i.creators[15/* Float64 */][cValueByDfr] + case func()complex64 : f = i.creators[16/* Complex64 */][cValueByDfr] + case func()complex128 : f = i.creators[17/* Complex128*/][cValueByDfr] + case func()Duration : f = i.creators[18/* Duration */][cValueByDfr] + case func()Date : f = i.creators[19/* Date */][cValueByDfr] + case func()string : f = i.creators[20/* String */][cValueByDfr] + case func()Bytes : f = i.creators[21/* Bytes */][cValueByDfr] + case func()Stack : f = i.creators[22/* Stack */][cValueByDfr] + case func()Baleable : f = i.creators[23/* Baleable */][cValueByDfr] + case func()error : f = i.creators[24/* Error */][cValueByDfr] + case func()CValue : f = i.creators[26/* CVal */][cValueByDfr] + case func()CField : f = i.creators[27/* CField */][cValueByDfr] + + default: + + rv := reflect.ValueOf(value) + if !rv.IsValid() { + f = createCValueInvalid + } + + } + + return +} + + + + + + +func createGValCreators [T any] (valType CValueType, createFnc func(value T) CValue) [cValueNumCreators]func(any)CValue { + return [cValueNumCreators]func(any)CValue { + func(v any) CValue { return createFnc(v.(T)) }, + func(v any) CValue { return createGValTypePointer(valType,createFnc,v.(*T))}, + func(v any) CValue { return createGValTypeList (CValueTypeList |valType,v.([]T)) }, + func(v any) CValue { return createGValTypeDefer(CValueTypeDefer|valType,v.(func() T)) }, + } +} + +func createGValTypeList [T any](vType CValueType, value []T) CValue { + if value == nil { + return CValue{vType: vType, vState: cValueStateNil} + } + var state CValueState + if len(value) == 0 { + state = cValueStateZero + } + return CValue{vType: vType, vState: state,anyVal: value} +} + +func createGValTypePointer[T any](vType CValueType, createFnc func(value T) CValue, value *T) CValue { + if value == nil { + return CValue{vType: vType, vState: cValueStateNil} + } + return createFnc(*value) +} + +func createGValTypeDefer[T any](vType CValueType,value func()T) CValue { + if value == nil { + return CValue{vType: vType, vState: cValueStateInvalid|cValueStateNil|cValueStateError} + } + return CValue{vType: vType,anyVal: value} +} diff --git a/src/core/cflss/types.go b/src/core/cflss/types.go new file mode 100644 index 0000000..626c54d --- /dev/null +++ b/src/core/cflss/types.go @@ -0,0 +1,49 @@ +// ============================================================================= +// 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 05/06/2025 +// ============================================================================= + +package cflss + +import ( + "core/blrs" + "core/excs" + "time" +) + +type ( + /* Tipos alias */ + + Bytes = []uint8 + Date = time.Time + Duration = time.Duration + Stack = excs.Stack + Baleable = blrs.Baleable + +) + + +