@@ -61,6 +61,12 @@ MC_DLLEXPORT_DEF MCTypeInfoRef kMCSIntPtrTypeInfo;
6161 * provide an element of safety against nullptr vs non-nullptr. */
6262MC_DLLEXPORT_DEF MCTypeInfoRef kMCPointerTypeInfo ;
6363
64+ /* The natural int and float types are 32-bit wide on 32-bit processors and
65+ * 64-bit wide on 64-bit processors. */
66+ MC_DLLEXPORT_DEF MCTypeInfoRef kMCNaturalUIntTypeInfo ;
67+ MC_DLLEXPORT_DEF MCTypeInfoRef kMCNaturalSIntTypeInfo ;
68+ MC_DLLEXPORT_DEF MCTypeInfoRef kMCNaturalFloatTypeInfo ;
69+
6470/* C Types
6571 *
6672 * These types represent the C types which are relative to the compiler,
@@ -109,6 +115,10 @@ MC_DLLEXPORT_DEF MCTypeInfoRef MCForeignSIntSizeTypeInfo() { return kMCSIntSizeT
109115MC_DLLEXPORT_DEF MCTypeInfoRef MCForeignUIntPtrTypeInfo () { return kMCUIntPtrTypeInfo ; }
110116MC_DLLEXPORT_DEF MCTypeInfoRef MCForeignSIntPtrTypeInfo () { return kMCSIntPtrTypeInfo ; }
111117
118+ MC_DLLEXPORT_DEF MCTypeInfoRef MCForeignNaturalUIntTypeInfo () { return kMCNaturalUIntTypeInfo ; }
119+ MC_DLLEXPORT_DEF MCTypeInfoRef MCForeignNaturalSIntTypeInfo () { return kMCNaturalSIntTypeInfo ; }
120+ MC_DLLEXPORT_DEF MCTypeInfoRef MCForeignNaturalFloatTypeInfo () { return kMCNaturalFloatTypeInfo ; }
121+
112122/* */
113123
114124MC_DLLEXPORT_DEF MCTypeInfoRef MCForeignCBoolTypeInfo () { return kMCCBoolTypeInfo ; }
@@ -131,12 +141,30 @@ MC_DLLEXPORT_DEF MCTypeInfoRef MCForeignSIntTypeInfo() { return kMCSIntTypeInfo;
131141
132142// //////////////////////////////////////////////////////////////////////////////
133143
144+ #if defined(__32_BIT__)
145+ typedef uint32_t natural_uint_t ;
146+ typedef int32_t natural_sint_t ;
147+ typedef float natural_float_t ;
148+ #elif defined(__64_BIT__)
149+ typedef uint64_t natural_uint_t ;
150+ typedef int64_t natural_sint_t ;
151+ typedef float natural_float_t ;
152+ #else
153+ #error Bitness of target not defined
154+ #endif
155+
134156static_assert (sizeof (int ) == 4 ,
135157 " Assumption that int is 4 bytes in size not valid" );
136158
137159static_assert (sizeof (bool ) == 1 ,
138160 " Assumption that bool is 1 byte in size not valid" );
139161
162+ static_assert (sizeof (uintptr_t ) == sizeof (natural_uint_t ),
163+ " Assumption that natural_uint_t is the same width as uintptr_t not valid" );
164+
165+ static_assert (sizeof (intptr_t ) == sizeof (natural_sint_t ),
166+ " Assumption that natural_uint_t is the same width as uintptr_t not valid" );
167+
140168template <typename CType, typename Enable = void >
141169struct compute_primitive_type
142170{
@@ -318,6 +346,33 @@ struct sintptr_type_desc_t: public integral_type_desc_t<intptr_t> {
318346 static constexpr auto is_promotable = false ;
319347};
320348
349+ /* */
350+
351+ struct naturaluint_type_desc_t : public integral_type_desc_t <natural_uint_t > {
352+ static constexpr MCTypeInfoRef& type_info () { return kMCNaturalUIntTypeInfo ; }
353+ static constexpr auto describe_format = " <foreign natural unsigned integer %zu>" ;
354+ static constexpr auto is_promotable = false ;
355+ };
356+
357+ struct naturalsint_type_desc_t : public integral_type_desc_t <natural_sint_t > {
358+ static constexpr MCTypeInfoRef& type_info () { return kMCNaturalSIntTypeInfo ; }
359+ static constexpr auto describe_format = " <foreign natural signed integer %zd>" ;
360+ static constexpr auto is_promotable = false ;
361+ };
362+
363+ #if defined(__32_BIT__)
364+ struct naturalfloat_type_desc_t : public float_type_desc_t {
365+ static constexpr MCTypeInfoRef& type_info () { return kMCNaturalFloatTypeInfo ; }
366+ static constexpr auto describe_format = " <foreign natural float %lg>" ;
367+ };
368+ #elif defined(__64_BIT__)
369+ struct naturalfloat_type_desc_t : public double_type_desc_t {
370+ static constexpr MCTypeInfoRef& type_info () { return kMCNaturalFloatTypeInfo ; }
371+ static constexpr auto describe_format = " <foreign natural float %lg>" ;
372+ };
373+ #endif
374+
375+
321376/* */
322377
323378struct cbool_type_desc_t : public bool_type_desc_t
@@ -1044,6 +1099,9 @@ bool __MCForeignValueInitialize(void)
10441099 DescriptorBuilder<uintptr_type_desc_t >::create (" __builtin__.uintptr" ) &&
10451100 DescriptorBuilder<sintptr_type_desc_t >::create (" __builtin__.sintptr" ) &&
10461101 DescriptorBuilder<pointer_type_desc_t >::create (" __builtin__.pointer" ) &&
1102+ DescriptorBuilder<naturaluint_type_desc_t >::create (" __builtin__.naturaluint" ) &&
1103+ DescriptorBuilder<naturalsint_type_desc_t >::create (" __builtin__.naturalsint" ) &&
1104+ DescriptorBuilder<naturalfloat_type_desc_t >::create (" __builtin__.naturalfloat" ) &&
10471105 DescriptorBuilder<cbool_type_desc_t >::create (" __builtin__.cbool" ) &&
10481106 DescriptorBuilder<cuchar_type_desc_t >::create (" __builtin__.cuchar" ) &&
10491107 DescriptorBuilder<cschar_type_desc_t >::create (" __builtin__.cschar" ) &&
@@ -1088,6 +1146,9 @@ void __MCForeignValueFinalize(void)
10881146 MCValueRelease (kMCUIntPtrTypeInfo );
10891147 MCValueRelease (kMCSIntPtrTypeInfo );
10901148 MCValueRelease (kMCPointerTypeInfo );
1149+ MCValueRelease (kMCNaturalUIntTypeInfo );
1150+ MCValueRelease (kMCNaturalSIntTypeInfo );
1151+ MCValueRelease (kMCNaturalFloatTypeInfo );
10911152
10921153 MCValueRelease (kMCCCharTypeInfo );
10931154 MCValueRelease (kMCCUCharTypeInfo );
0 commit comments