Skip to content

Commit

Permalink
7/N Add primitives4 for Haskell
Browse files Browse the repository at this point in the history
Summary:
Don't know what I'm doing here...

Followed the pattern in `common/hs/util/cpp/HsStruct.cpp` and `common/hs/util/cpp/HsStruct.cpp` in order to get past compiler errors.

Reviewed By: ahilger

Differential Revision: D66151816

fbshipit-source-id: f1360ac13ca8cdb1e665554da4bc49854ae9b29a
  • Loading branch information
Dan Deng authored and facebook-github-bot committed Nov 19, 2024
1 parent 967ac21 commit f5dd370
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
12 changes: 12 additions & 0 deletions common/util/Foreign/CPP/HsStruct/Types.hsc
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,8 @@ $(deriveMarshallableUnsafe "HsArrayInt64" [t| HsArray CLong |])
$(deriveMarshallableUnsafe "HsArrayUInt8" [t| HsArray CBool |])
$(deriveMarshallableUnsafe "HsArrayUInt8" [t| HsArray Word8 |])
$(deriveMarshallableUnsafe "HsArrayUInt8" [t| HsArray CSChar |])
$(deriveMarshallableUnsafe "HsArrayUInt8" [t| HsArray CUChar |])
$(deriveMarshallableUnsafe "HsArrayUInt16" [t| HsArray CUShort |])
$(deriveMarshallableUnsafe "HsArrayUInt32" [t| HsArray CUInt |])
$(deriveMarshallableUnsafe "HsArrayUInt32" [t| HsArray Word32 |])
$(deriveMarshallableUnsafe "HsArrayUInt64" [t| HsArray CULong |])
Expand All @@ -809,6 +811,8 @@ $(deriveMarshallableUnsafe "HsArrayString" [t| HsArray HsLenientText |])
$(deriveMarshallableUnsafe "HsArrayStringPiece" [t| HsArray HsStringPiece |])
$(deriveMarshallableUnsafe "HsArrayJSON" [t| HsArray HsJSON |])

$(deriveMarshallableUnsafe "HsSetUInt8" [t| HsHashSet CUChar |])
$(deriveMarshallableUnsafe "HsSetUInt16" [t| HsHashSet CUShort |])
$(deriveMarshallableUnsafe "HsSetInt32" [t| HsHashSet CInt |])
$(deriveMarshallableUnsafe "HsSetInt32" [t| HsHashSet Int32 |])
$(deriveMarshallableUnsafe "HsSetInt64" [t| HsHashSet Int |])
Expand All @@ -829,6 +833,8 @@ $(deriveMarshallableUnsafe "HsSetString" [t| HsHashSet HsLenientText |])
$(deriveMarshallableUnsafe "HsSetJSON" [t| HsHashSet HsJSON |])

$(deriveMarshallableUnsafe "HsMapIntInt" [t| HsIntMap Int |])
$(deriveMarshallableUnsafe "HsMapUInt8UInt8" [t| HsHashMap CUChar CUChar |])
$(deriveMarshallableUnsafe "HsMapUInt16UInt16" [t| HsHashMap CUShort CUShort |])
$(deriveMarshallableUnsafe "HsMapIntDouble" [t| HsIntMap Double |])
$(deriveMarshallableUnsafe "HsMapIntString" [t| HsIntMap HsByteString |])
$(deriveMarshallableUnsafe "HsMapIntString" [t| HsIntMap HsText |])
Expand Down Expand Up @@ -930,7 +936,9 @@ $(deriveHsArrayUnsafe "Int64" [t| CLong |])
$(deriveHsArrayUnsafe "Int64" [t| Int64 |])
$(deriveHsArrayUnsafe "UInt8" [t| CBool |])
$(deriveHsArrayUnsafe "UInt8" [t| Word8 |])
$(deriveHsArrayUnsafe "UInt8" [t| CUChar |])
$(deriveHsArrayUnsafe "UInt8" [t| CSChar |])
$(deriveHsArrayUnsafe "UInt16" [t| CUShort |])
$(deriveHsArrayUnsafe "UInt32" [t| CUInt |])
$(deriveHsArrayUnsafe "UInt32" [t| Word32 |])
$(deriveHsArrayUnsafe "UInt64" [t| CULong |])
Expand All @@ -953,6 +961,8 @@ $(deriveHsHashSetUnsafe "Int64" [t| CLong |])
$(deriveHsHashSetUnsafe "UInt8" [t| CBool |])
$(deriveHsHashSetUnsafe "UInt8" [t| Word8 |])
$(deriveHsHashSetUnsafe "UInt8" [t| CSChar |])
$(deriveHsHashSetUnsafe "UInt8" [t| CUChar |])
$(deriveHsHashSetUnsafe "UInt16" [t| CUShort |])
$(deriveHsHashSetUnsafe "UInt32" [t| CUInt |])
$(deriveHsHashSetUnsafe "UInt32" [t| Word32 |])
$(deriveHsHashSetUnsafe "UInt64" [t| CULong |])
Expand All @@ -966,6 +976,8 @@ $(deriveHsHashSetUnsafe "HsJSON" [t| HsJSON |])

-- O(n^2) derivations, try to derive just what you need
$(deriveHsHashMapUnsafe "IntInt" [t| Int |] [t| Int |])
$(deriveHsHashMapUnsafe "UInt8UInt8" [t| CUChar |] [t| CUChar |])
$(deriveHsHashMapUnsafe "UInt16UInt16" [t| CUShort |] [t| CUShort |])
$(deriveHsHashMapUnsafe "Int32Int32" [t| Int32 |] [t| Int32 |])
$(deriveHsHashMapUnsafe "Int32Double" [t| Int32 |] [t| Double |])
$(deriveHsHashMapUnsafe "Int32String" [t| Int32 |] [t| HsByteString |])
Expand Down
8 changes: 8 additions & 0 deletions common/util/cpp/HsStruct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ HS_DEFINE_MARSHALLABLE(HsArrayInt16, HsArray<int16_t>);
HS_DEFINE_MARSHALLABLE(HsArrayInt32, HsArray<int32_t>);
HS_DEFINE_MARSHALLABLE(HsArrayInt64, HsArray<int64_t>);
HS_DEFINE_MARSHALLABLE(HsArrayUInt8, HsArray<uint8_t>);
HS_DEFINE_MARSHALLABLE(HsArrayUInt16, HsArray<uint16_t>);
HS_DEFINE_MARSHALLABLE(HsArrayUInt32, HsArray<uint32_t>);
HS_DEFINE_MARSHALLABLE(HsArrayUInt64, HsArray<uint64_t>);
HS_DEFINE_MARSHALLABLE(HsArrayFloat, HsArray<float>);
Expand All @@ -251,6 +252,7 @@ HS_DEFINE_MARSHALLABLE(HsSetInt16, HsSet<int16_t>);
HS_DEFINE_MARSHALLABLE(HsSetInt32, HsSet<int32_t>);
HS_DEFINE_MARSHALLABLE(HsSetInt64, HsSet<int64_t>);
HS_DEFINE_MARSHALLABLE(HsSetUInt8, HsSet<uint8_t>);
HS_DEFINE_MARSHALLABLE(HsSetUInt16, HsSet<uint16_t>);
HS_DEFINE_MARSHALLABLE(HsSetUInt32, HsSet<uint32_t>);
HS_DEFINE_MARSHALLABLE(HsSetUInt64, HsSet<uint64_t>);
HS_DEFINE_MARSHALLABLE(HsSetFloat, HsSet<float>);
Expand All @@ -259,6 +261,8 @@ HS_DEFINE_MARSHALLABLE(HsSetString, HsSet<HsString>);
HS_DEFINE_MARSHALLABLE(HsSetJSON, HsSet<HsJSON>);

HS_DEFINE_MARSHALLABLE(HsMapIntInt, HsMap<int64_t, int64_t>);
HS_DEFINE_MARSHALLABLE(HsMapUInt8UInt8, HsMap<uint8_t, uint8_t>);
HS_DEFINE_MARSHALLABLE(HsMapUInt16UInt16, HsMap<uint16_t, uint16_t>);
HS_DEFINE_MARSHALLABLE(HsMapInt32Int32, HsMap<int32_t, int32_t>);
HS_DEFINE_MARSHALLABLE(HsMapInt32Double, HsMap<int32_t, double>);
HS_DEFINE_MARSHALLABLE(HsMapIntDouble, HsMap<int64_t, double>);
Expand Down Expand Up @@ -292,6 +296,7 @@ HS_DEFINE_ARRAY_CONSTRUCTIBLE(Int64, int64_t);
// std::vector<bool> doesn't guarantee contiguous memory layout,
// so use HsArray<uint8_t> to store one bool per byte
HS_DEFINE_ARRAY_CONSTRUCTIBLE(UInt8, uint8_t);
HS_DEFINE_ARRAY_CONSTRUCTIBLE(UInt16, uint16_t);
HS_DEFINE_ARRAY_CONSTRUCTIBLE(UInt32, uint32_t);
HS_DEFINE_ARRAY_CONSTRUCTIBLE(UInt64, uint64_t);
HS_DEFINE_ARRAY_CONSTRUCTIBLE(Float, float);
Expand All @@ -301,6 +306,8 @@ HS_DEFINE_ARRAY_CONSTRUCTIBLE(StringView, HsStringPiece);
HS_DEFINE_ARRAY_CONSTRUCTIBLE(HsJSON, HsJSON);

HS_DEFINE_MAP_CONSTRUCTIBLE(IntInt, int64_t, int64_t);
HS_DEFINE_MAP_CONSTRUCTIBLE(UInt8UInt8, uint8_t, uint8_t);
HS_DEFINE_MAP_CONSTRUCTIBLE(UInt16UInt16, uint16_t, uint16_t);
HS_DEFINE_MAP_CONSTRUCTIBLE(Int32Int32, int32_t, int32_t);
HS_DEFINE_MAP_CONSTRUCTIBLE(Int32Double, int32_t, double);
HS_DEFINE_MAP_CONSTRUCTIBLE(Int32String, int32_t, HsString);
Expand All @@ -313,6 +320,7 @@ HS_DEFINE_SET_CONSTRUCTIBLE(Int16, int16_t);
HS_DEFINE_SET_CONSTRUCTIBLE(Int32, int32_t);
HS_DEFINE_SET_CONSTRUCTIBLE(Int64, int64_t);
HS_DEFINE_SET_CONSTRUCTIBLE(UInt8, uint8_t);
HS_DEFINE_SET_CONSTRUCTIBLE(UInt16, uint16_t);
HS_DEFINE_SET_CONSTRUCTIBLE(UInt32, uint32_t);
HS_DEFINE_SET_CONSTRUCTIBLE(UInt64, uint64_t);
HS_DEFINE_SET_CONSTRUCTIBLE(Float, float);
Expand Down

0 comments on commit f5dd370

Please sign in to comment.