commit f3d450276320e808f473db702356105f7af4c710 Author: dev Date: Thu May 29 02:24:59 2025 +0200 feat: Implement core CValue type system This commit introduces the foundational CValue type system, enabling unified handling and representation of various Go data types. Key features and components: - **`CValue` struct**: Core data structure for holding any Go value. - **`CValueType` and `CValueState`**: Enums for type identification and value state. - **`cValueCreator` interface**: Defines the contract for creating `CValue` instances. - **`creatorCValueFnc[T]`**: Generic function type implementing `cValueCreator`, responsible for converting specific Go types (`T`) to `CValue`. - **`makePointerCreator`, `makeListCreator`, `makeFuncCreator`**: Generic helper functions for creating specialized `cValueCreator`s for pointers (`*T`), slices (`[]T`), and provider functions (`func() T`), respectively. - **`cValueTypeInfo`**: Struct for metadata and associated `cValueCreator`s for each `CValueType`. - **`createCValueTypeInfo[T]`**: Generic factory function to initialize `cValueTypeInfo` entries, including support for custom `cValueCreator` overrides. - **Initial set of `CreateCValue` functions**: Basic implementations for primitive types (int, string, bool, etc.) and specific types like `[]byte`. - **Centralized type registration**: `newCValueTypeInfoMap` for organizing all `cValueTypeInfo` definitions. This foundational layer is designed for extensibility, allowing easy addition of new `CValueType`s and custom handling logic. diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/GO·AT.iml b/.idea/GO·AT.iml new file mode 100644 index 0000000..5e764c4 --- /dev/null +++ b/.idea/GO·AT.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/dictionaries/project.xml b/.idea/dictionaries/project.xml new file mode 100644 index 0000000..a09503b --- /dev/null +++ b/.idea/dictionaries/project.xml @@ -0,0 +1,7 @@ + + + + vtype + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..38e420e --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/core/blrs/baleable.go b/src/core/blrs/baleable.go new file mode 100644 index 0000000..83c9f73 --- /dev/null +++ b/src/core/blrs/baleable.go @@ -0,0 +1,33 @@ +// ============================================================================= +// 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 28/05/2025 +// ============================================================================= + +package blrs + +type Baleable interface { + Bale(baler Baler) error +} diff --git a/src/core/blrs/baler.go b/src/core/blrs/baler.go new file mode 100644 index 0000000..2097751 --- /dev/null +++ b/src/core/blrs/baler.go @@ -0,0 +1,35 @@ +// ============================================================================= +// 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 28/05/2025 +// ============================================================================= + +package blrs + +type Baler interface { + Map(mapBaler MapBaler) error + List(listBaler ListBaler) error + Object(objBaler ObjectBaler) error +} diff --git a/src/core/blrs/list_baler.go b/src/core/blrs/list_baler.go new file mode 100644 index 0000000..c06e433 --- /dev/null +++ b/src/core/blrs/list_baler.go @@ -0,0 +1,33 @@ +// ============================================================================= +// 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 28/05/2025 +// ============================================================================= + +package blrs + +type ListBaler interface { + Add() Baler +} diff --git a/src/core/blrs/map_baler.go b/src/core/blrs/map_baler.go new file mode 100644 index 0000000..1b1f8f9 --- /dev/null +++ b/src/core/blrs/map_baler.go @@ -0,0 +1,33 @@ +// ============================================================================= +// 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 28/05/2025 +// ============================================================================= + +package blrs + +type MapBaler interface { + Key(key any) Baler +} diff --git a/src/core/blrs/object_baler.go b/src/core/blrs/object_baler.go new file mode 100644 index 0000000..ddb9b89 --- /dev/null +++ b/src/core/blrs/object_baler.go @@ -0,0 +1,33 @@ +// ============================================================================= +// 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 28/05/2025 +// ============================================================================= + +package blrs + +type ObjectBaler interface { + Field(name string) Baler +} diff --git a/src/core/go.mod b/src/core/go.mod new file mode 100644 index 0000000..e15d98f --- /dev/null +++ b/src/core/go.mod @@ -0,0 +1,3 @@ +module core + +go 1.24 diff --git a/src/core/vals/cvalue.go b/src/core/vals/cvalue.go new file mode 100644 index 0000000..abd70a7 --- /dev/null +++ b/src/core/vals/cvalue.go @@ -0,0 +1,84 @@ +// ============================================================================= +// 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 28/05/2025 +// ============================================================================= + +package vals + +import ( + "core/blrs" + "time" +) + +type ( + CValue struct { + mType CValueType + mState CValueState + vInt int64 + vStr string + vAny 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 time.Duration) CValue { return CValue{} } +func CreateCValueDate(value time.Time) CValue { return CValue{} } + +func CreateCValueString(value string) CValue { return CValue{} } +func CreateCValueBytes(value []byte) CValue { return CValue{} } +func CreateCValueStack(value []string) CValue { return CValue{} } + +func CreateCValueBaleable(value blrs.Baleable) CValue { return CValue{} } +func CreateCValueError(value error) CValue { return CValue{} } + +func CreateCValueNil(value any) CValue { return CValue{} } +func CreateCValueMap(value any) CValue { return CValue{} } +func CreateCValueList(value any) CValue { return CValue{} } + +func createCValueInvalid(value any) CValue { return CValue{} } diff --git a/src/core/vals/cvalue_creator.go b/src/core/vals/cvalue_creator.go new file mode 100644 index 0000000..6b56767 --- /dev/null +++ b/src/core/vals/cvalue_creator.go @@ -0,0 +1,76 @@ +// ============================================================================= +// 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 28/05/2025 +// ============================================================================= + +package vals + +type ( + cValueCreator interface { + createCValue(value any) CValue + } + creatorCValueFnc[T any] func(T) CValue + + genericProvider[T any] func() T +) + +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 { + return CValue{mType: vtype, mState: CValueStateNil} + } + return fnc(caller()) + }) +} + +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 { + // Si el puntero es nil, creamos un CValue que representa un valor nil del tipo T. + // Para obtener el CValueType de T, usamos una función auxiliar. + return CValue{mType: vtype, mState: CValueStateNil} + } + + // Si el puntero no es nil, lo desreferenciamos y llamamos a la función original (fnc). + return fnc(*value) + }) +} + +func makeListCreator[T any](vtype CValueType) cValueCreator { + return creatorCValueFnc[[]T](func(value []T) CValue { + if value == nil { + return CValue{mType: vtype, mState: CValueStateNil} + } + if len(value) == 0 { + return CValue{mType: vtype, mState: CValueStateZero} + } + return CValue{mType: vtype, vAny: value} // Asegúrate de usar 'anyVal' para el campo de valor + }) +} diff --git a/src/core/vals/cvalue_state.go b/src/core/vals/cvalue_state.go new file mode 100644 index 0000000..0b19130 --- /dev/null +++ b/src/core/vals/cvalue_state.go @@ -0,0 +1,63 @@ +// ============================================================================= +// 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 28/05/2025 +// ============================================================================= + +package vals + +const ( + CValueStateInvalid CValueState = 1 << iota + CValueStateNil + CValueStateZero + cValueStateVersion + CValueStateSensitive + CValueStateUnpackable + + CValueStateNone CValueState = 0 + + cValueStateNilOrZero = CValueStateZero | CValueStateNil + cValueStateOptions = CValueStateSensitive | CValueStateUnpackable +) + +type CValueState uint8 + +func (f CValueState) IsInvalid() bool { return f&CValueStateInvalid != 0 } + +func (f CValueState) IsNil() bool { return f&CValueStateNil != 0 } + +func (f CValueState) IsZero() bool { return f&CValueStateZero != 0 } + +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) isVersion() bool { return f&cValueStateVersion != 0 } + +func (f CValueState) setOption(option CValueState) CValueState { + return f | (cValueStateOptions & option) +} diff --git a/src/core/vals/cvalue_type.go b/src/core/vals/cvalue_type.go new file mode 100644 index 0000000..d0eb794 --- /dev/null +++ b/src/core/vals/cvalue_type.go @@ -0,0 +1,78 @@ +// ============================================================================= +// 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 28/05/2025 +// ============================================================================= + +package vals + +const ( + maxCValueTypes int = 32 + + // Tipos definidos de CValue + + 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 + + CValueTypeMap CValueType = 1 << 30 + CValueTypeList CValueType = 1 << 31 +) + +type CValueType uint32 diff --git a/src/core/vals/cvalue_type_info.go b/src/core/vals/cvalue_type_info.go new file mode 100644 index 0000000..4d6efaa --- /dev/null +++ b/src/core/vals/cvalue_type_info.go @@ -0,0 +1,155 @@ +// ============================================================================= +// 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 28/05/2025 +// ============================================================================= + +package vals + +import ( + "core/blrs" + "time" +) + +const ( + idxCValueTypeInvalid = iota + idxCValueTypeAny + + idxCValueTypeBool + + idxCValueTypeInt + idxCValueTypeInt8 + idxCValueTypeInt16 + idxCValueTypeInt32 + idxCValueTypeInt64 + + idxCValueTypeUint + idxCValueTypeUint8 + idxCValueTypeUint16 + idxCValueTypeUint32 + idxCValueTypeUint64 + + idxCValueTypeUintptr + + idxCValueTypeFloat32 + idxCValueTypeFloat64 + idxCValueTypeComplex64 + idxCValueTypeComplex128 + + idxCValueTypeDuration + idxCValueTypeDate + + idxCValueTypeString + idxCValueTypeBytes + idxCValueTypeStack + + idxCValueTypeBaleable + + idxCValueTypeError + + idxCValueTypeNil + _ + _ + _ + _ + idxCValueTypeMap + idxCValueTypeList +) + +type ( + cValueTypeInfo struct { + vType CValueType + name string + + vCreator, + lCreator, + pCreator, + fCreator cValueCreator + } +) + +func createCValueTypeInfo[T any](vtype CValueType, name string, creatorFnc creatorCValueFnc[T]) cValueTypeInfo { + + return cValueTypeInfo{ + vType: vtype, + name: name, + vCreator: creatorFnc, + lCreator: makeListCreator[T](vtype | CValueTypeList), + fCreator: makeFuncCreator[T](vtype, creatorFnc), + pCreator: makePointerCreator[T](vtype, creatorFnc), + } +} + +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), + /* 9 CValueTypeUint8 */ createCValueTypeInfo[uint8](CValueTypeUint8, "uint8", CreateCValueUint8), + /* 10 CValueTypeUint16 */ createCValueTypeInfo[uint16](CValueTypeUint8, "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[[]string](CValueTypeStack, "stack", CreateCValueStack), + + /* 23 CValueTypePackable*/ createCValueTypeInfo[blrs.Baleable](CValueTypeBaleable, "packable", CreateCValueBaleable), + /* 24 CValueTypeError */ createCValueTypeInfo[error](CValueTypeError, "error", CreateCValueError), + + /* 25 CValueTypeInvalid */ createCValueTypeInfo[any](CValueTypeInvalid, "invalid", createCValueInvalid), + /* 26 CValueTypeInvalid */ createCValueTypeInfo[any](CValueTypeInvalid, "invalid", createCValueInvalid), + /* 27 CValueTypeInvalid */ createCValueTypeInfo[any](CValueTypeInvalid, "invalid", createCValueInvalid), + /* 28 CValueTypeInvalid */ createCValueTypeInfo[any](CValueTypeInvalid, "invalid", createCValueInvalid), + /* 29 CValueTypeInvalid */ createCValueTypeInfo[any](CValueTypeInvalid, "invalid", createCValueInvalid), + + /* 30 CValueTypeMap */ createCValueTypeInfo[any](CValueTypeMap, "map", CreateCValueMap), + /* 31 CValueTypeList */ createCValueTypeInfo[any](CValueTypeList, "list", CreateCValueList), + } + + // excepcion de []uint8 debe de ser tratado como bytes + types[idxCValueTypeUint8].lCreator = creatorCValueFnc[[]uint8](CreateCValueBytes) + + return types +} diff --git a/src/go.work b/src/go.work new file mode 100644 index 0000000..a97f4a1 --- /dev/null +++ b/src/go.work @@ -0,0 +1,3 @@ +go 1.24 + +use core \ No newline at end of file