{-# LINE 1 "src/Quickjs/Types.hsc" #-}
{-# LANGUAGE QuasiQuotes, TemplateHaskell, OverloadedStrings, MultiParamTypeClasses, FlexibleInstances, GeneralizedNewtypeDeriving #-}
module Quickjs.Types where
import qualified Data.Map as Map
import Data.Bits (Bits)
import Foreign.C.Types
import Foreign.Ptr (plusPtr)
import Foreign.Storable (Storable(..))
import Language.C.Inline
import Language.C.Inline.Context (Context(..), TypesTable)
import qualified Language.C.Types as C
data JSValue = JSValue
{ JSValue -> CDouble
u :: {-# UNPACK #-} !CDouble
, JSValue -> CLong
tag :: {-# UNPACK #-} !CLong
} deriving (Int -> JSValue -> ShowS
[JSValue] -> ShowS
JSValue -> String
(Int -> JSValue -> ShowS)
-> (JSValue -> String) -> ([JSValue] -> ShowS) -> Show JSValue
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [JSValue] -> ShowS
$cshowList :: [JSValue] -> ShowS
show :: JSValue -> String
$cshow :: JSValue -> String
showsPrec :: Int -> JSValue -> ShowS
$cshowsPrec :: Int -> JSValue -> ShowS
Show, JSValue -> JSValue -> Bool
(JSValue -> JSValue -> Bool)
-> (JSValue -> JSValue -> Bool) -> Eq JSValue
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: JSValue -> JSValue -> Bool
$c/= :: JSValue -> JSValue -> Bool
== :: JSValue -> JSValue -> Bool
$c== :: JSValue -> JSValue -> Bool
Eq)
instance Storable JSValue where
sizeOf :: JSValue -> Int
sizeOf JSValue
_ = (Int
16)
{-# LINE 23 "src/Quickjs/Types.hsc" #-}
alignment _ = 8
{-# LINE 24 "src/Quickjs/Types.hsc" #-}
peek ptr = do
u <- peek ((\hsc_ptr -> hsc_ptr `plusPtr` 0) ptr)
{-# LINE 26 "src/Quickjs/Types.hsc" #-}
tag <- peek ((\hsc_ptr -> hsc_ptr `plusPtr` 8) ptr)
{-# LINE 27 "src/Quickjs/Types.hsc" #-}
Prelude.pure (JSValue u tag)
poke :: Ptr JSValue -> JSValue -> IO ()
poke Ptr JSValue
ptr (JSValue CDouble
u CLong
tag) = do
Ptr CDouble -> CDouble -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke ((\Ptr JSValue
hsc_ptr -> Ptr JSValue
hsc_ptr Ptr JSValue -> Int -> Ptr CDouble
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
0) Ptr JSValue
ptr) CDouble
u
{-# LINE 30 "src/Quickjs/Types.hsc" #-}
poke ((\hsc_ptr -> hsc_ptr `plusPtr` 8) ptr) tag
{-# LINE 31 "src/Quickjs/Types.hsc" #-}
type JSValueConst = JSValue
newtype JSRuntime = JSRuntime { JSRuntime -> CUChar
_unusedRuntime :: CUChar }
newtype JSContext = JSContext { JSContext -> CUChar
_unusedContext :: CUChar }
type JSBool = CInt
type JSAtom = CUInt
data JSPropertyEnum = JSPropertyEnum
{ JSPropertyEnum -> JSBool
is_enumerable :: {-# UNPACK #-} !JSBool
, JSPropertyEnum -> JSAtom
atom :: {-# UNPACK #-} !JSAtom
} deriving (Int -> JSPropertyEnum -> ShowS
[JSPropertyEnum] -> ShowS
JSPropertyEnum -> String
(Int -> JSPropertyEnum -> ShowS)
-> (JSPropertyEnum -> String)
-> ([JSPropertyEnum] -> ShowS)
-> Show JSPropertyEnum
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [JSPropertyEnum] -> ShowS
$cshowList :: [JSPropertyEnum] -> ShowS
show :: JSPropertyEnum -> String
$cshow :: JSPropertyEnum -> String
showsPrec :: Int -> JSPropertyEnum -> ShowS
$cshowsPrec :: Int -> JSPropertyEnum -> ShowS
Show, JSPropertyEnum -> JSPropertyEnum -> Bool
(JSPropertyEnum -> JSPropertyEnum -> Bool)
-> (JSPropertyEnum -> JSPropertyEnum -> Bool) -> Eq JSPropertyEnum
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: JSPropertyEnum -> JSPropertyEnum -> Bool
$c/= :: JSPropertyEnum -> JSPropertyEnum -> Bool
== :: JSPropertyEnum -> JSPropertyEnum -> Bool
$c== :: JSPropertyEnum -> JSPropertyEnum -> Bool
Eq)
instance Storable JSPropertyEnum where
sizeOf :: JSPropertyEnum -> Int
sizeOf JSPropertyEnum
_ = (Int
8)
{-# LINE 51 "src/Quickjs/Types.hsc" #-}
alignment _ = 4
{-# LINE 52 "src/Quickjs/Types.hsc" #-}
peek ptr = do
is_enumerable <- peek ((\hsc_ptr -> hsc_ptr `plusPtr` 0) ptr)
{-# LINE 54 "src/Quickjs/Types.hsc" #-}
atom <- peek ((\hsc_ptr -> hsc_ptr `plusPtr` 4) ptr)
{-# LINE 55 "src/Quickjs/Types.hsc" #-}
Prelude.pure (JSPropertyEnum is_enumerable atom)
poke :: Ptr JSPropertyEnum -> JSPropertyEnum -> IO ()
poke Ptr JSPropertyEnum
ptr (JSPropertyEnum JSBool
is_enumerable JSAtom
atom) = do
Ptr JSBool -> JSBool -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke ((\Ptr JSPropertyEnum
hsc_ptr -> Ptr JSPropertyEnum
hsc_ptr Ptr JSPropertyEnum -> Int -> Ptr JSBool
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
0) Ptr JSPropertyEnum
ptr) JSBool
is_enumerable
{-# LINE 58 "src/Quickjs/Types.hsc" #-}
poke ((\hsc_ptr -> hsc_ptr `plusPtr` 4) ptr) atom
{-# LINE 59 "src/Quickjs/Types.hsc" #-}
data =
{ JSRefCountHeader -> JSBool
ref_count :: {-# UNPACK #-} !CInt
} deriving (Int -> JSRefCountHeader -> ShowS
[JSRefCountHeader] -> ShowS
JSRefCountHeader -> String
(Int -> JSRefCountHeader -> ShowS)
-> (JSRefCountHeader -> String)
-> ([JSRefCountHeader] -> ShowS)
-> Show JSRefCountHeader
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [JSRefCountHeader] -> ShowS
$cshowList :: [JSRefCountHeader] -> ShowS
show :: JSRefCountHeader -> String
$cshow :: JSRefCountHeader -> String
showsPrec :: Int -> JSRefCountHeader -> ShowS
$cshowsPrec :: Int -> JSRefCountHeader -> ShowS
Show, JSRefCountHeader -> JSRefCountHeader -> Bool
(JSRefCountHeader -> JSRefCountHeader -> Bool)
-> (JSRefCountHeader -> JSRefCountHeader -> Bool)
-> Eq JSRefCountHeader
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: JSRefCountHeader -> JSRefCountHeader -> Bool
$c/= :: JSRefCountHeader -> JSRefCountHeader -> Bool
== :: JSRefCountHeader -> JSRefCountHeader -> Bool
$c== :: JSRefCountHeader -> JSRefCountHeader -> Bool
Eq)
instance Storable JSRefCountHeader where
sizeOf :: JSRefCountHeader -> Int
sizeOf JSRefCountHeader
_ = (Int
4)
{-# LINE 68 "src/Quickjs/Types.hsc" #-}
alignment _ = 4
{-# LINE 69 "src/Quickjs/Types.hsc" #-}
peek ptr = do
ref_count <- peek ((\hsc_ptr -> hsc_ptr `plusPtr` 0) ptr)
{-# LINE 71 "src/Quickjs/Types.hsc" #-}
Prelude.pure (JSRefCountHeader ref_count)
poke :: Ptr JSRefCountHeader -> JSRefCountHeader -> IO ()
poke Ptr JSRefCountHeader
ptr (JSRefCountHeader JSBool
ref_count) = do
Ptr JSBool -> JSBool -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke ((\Ptr JSRefCountHeader
hsc_ptr -> Ptr JSRefCountHeader
hsc_ptr Ptr JSRefCountHeader -> Int -> Ptr JSBool
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
0) Ptr JSRefCountHeader
ptr) JSBool
ref_count
{-# LINE 74 "src/Quickjs/Types.hsc" #-}
class ToCType ty cty where
toCType :: ty -> cty
class FromCType ty cty where
fromCType :: cty -> Maybe ty
data JSTagEnum = JSTagFirst
| JSTagBigDecimal
| JSTagBigInt
| JSTagBigFloat
| JSTagSymbol
| JSTagString
| JSTagModule
| JSTagFunctionBytecode
| JSTagObject
| JSTagInt
| JSTagBool
| JSTagNull
| JSTagUndefined
| JSTagUninitialized
| JSTagCatchOffset
| JSTagException
| JSTagFloat64
deriving (Int -> JSTagEnum -> ShowS
[JSTagEnum] -> ShowS
JSTagEnum -> String
(Int -> JSTagEnum -> ShowS)
-> (JSTagEnum -> String)
-> ([JSTagEnum] -> ShowS)
-> Show JSTagEnum
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [JSTagEnum] -> ShowS
$cshowList :: [JSTagEnum] -> ShowS
show :: JSTagEnum -> String
$cshow :: JSTagEnum -> String
showsPrec :: Int -> JSTagEnum -> ShowS
$cshowsPrec :: Int -> JSTagEnum -> ShowS
Show, JSTagEnum -> JSTagEnum -> Bool
(JSTagEnum -> JSTagEnum -> Bool)
-> (JSTagEnum -> JSTagEnum -> Bool) -> Eq JSTagEnum
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: JSTagEnum -> JSTagEnum -> Bool
$c/= :: JSTagEnum -> JSTagEnum -> Bool
== :: JSTagEnum -> JSTagEnum -> Bool
$c== :: JSTagEnum -> JSTagEnum -> Bool
Eq)
instance Num a => ToCType JSTagEnum a where
toCType :: JSTagEnum -> a
toCType JSTagEnum
JSTagFirst = -a
11
{-# LINE 106 "src/Quickjs/Types.hsc" #-}
toCType JSTagBigDecimal = -11
{-# LINE 107 "src/Quickjs/Types.hsc" #-}
toCType JSTagBigInt = -10
{-# LINE 108 "src/Quickjs/Types.hsc" #-}
toCType JSTagBigFloat = -9
{-# LINE 109 "src/Quickjs/Types.hsc" #-}
toCType JSTagSymbol = -8
{-# LINE 110 "src/Quickjs/Types.hsc" #-}
toCType JSTagString = -7
{-# LINE 111 "src/Quickjs/Types.hsc" #-}
toCType JSTagModule = -3
{-# LINE 112 "src/Quickjs/Types.hsc" #-}
toCType JSTagFunctionBytecode = -2
{-# LINE 113 "src/Quickjs/Types.hsc" #-}
toCType JSTagObject = -1
{-# LINE 114 "src/Quickjs/Types.hsc" #-}
toCType JSTagInt = 0
{-# LINE 115 "src/Quickjs/Types.hsc" #-}
toCType JSTagBool = 1
{-# LINE 116 "src/Quickjs/Types.hsc" #-}
toCType JSTagNull = 2
{-# LINE 117 "src/Quickjs/Types.hsc" #-}
toCType JSTagUndefined = 3
{-# LINE 118 "src/Quickjs/Types.hsc" #-}
toCType JSTagUninitialized = 4
{-# LINE 119 "src/Quickjs/Types.hsc" #-}
toCType JSTagCatchOffset = 5
{-# LINE 120 "src/Quickjs/Types.hsc" #-}
toCType JSTagException = 6
{-# LINE 121 "src/Quickjs/Types.hsc" #-}
toCType JSTagFloat64 = 7
{-# LINE 122 "src/Quickjs/Types.hsc" #-}
instance (Eq a, Num a) => FromCType JSTagEnum a where
fromCType :: a -> Maybe JSTagEnum
fromCType (-11) = JSTagEnum -> Maybe JSTagEnum
forall a. a -> Maybe a
Just JSTagEnum
JSTagBigDecimal
{-# LINE 126 "src/Quickjs/Types.hsc" #-}
fromCType (-10) = Just JSTagBigInt
{-# LINE 127 "src/Quickjs/Types.hsc" #-}
fromCType (-9) = Just JSTagBigFloat
{-# LINE 128 "src/Quickjs/Types.hsc" #-}
fromCType (-8) = Just JSTagSymbol
{-# LINE 129 "src/Quickjs/Types.hsc" #-}
fromCType (-7) = Just JSTagString
{-# LINE 130 "src/Quickjs/Types.hsc" #-}
fromCType (-3) = Just JSTagModule
{-# LINE 131 "src/Quickjs/Types.hsc" #-}
fromCType (-2) = Just JSTagFunctionBytecode
{-# LINE 132 "src/Quickjs/Types.hsc" #-}
fromCType (-1) = Just JSTagObject
{-# LINE 133 "src/Quickjs/Types.hsc" #-}
fromCType (0) = Just JSTagInt
{-# LINE 134 "src/Quickjs/Types.hsc" #-}
fromCType (1) = Just JSTagBool
{-# LINE 135 "src/Quickjs/Types.hsc" #-}
fromCType (2) = Just JSTagNull
{-# LINE 136 "src/Quickjs/Types.hsc" #-}
fromCType (3) = Just JSTagUndefined
{-# LINE 137 "src/Quickjs/Types.hsc" #-}
fromCType (4) = Just JSTagUninitialized
{-# LINE 138 "src/Quickjs/Types.hsc" #-}
fromCType (5) = Just JSTagCatchOffset
{-# LINE 139 "src/Quickjs/Types.hsc" #-}
fromCType (6) = Just JSTagException
{-# LINE 140 "src/Quickjs/Types.hsc" #-}
fromCType (7) = Just JSTagFloat64
{-# LINE 141 "src/Quickjs/Types.hsc" #-}
fromCType _ = Nothing
data JSTypeEnum = JSTypeFromTag JSTagEnum
| JSIsNumber
| JSIsArray
| JSIsDate
| JSIsError
deriving Int -> JSTypeEnum -> ShowS
[JSTypeEnum] -> ShowS
JSTypeEnum -> String
(Int -> JSTypeEnum -> ShowS)
-> (JSTypeEnum -> String)
-> ([JSTypeEnum] -> ShowS)
-> Show JSTypeEnum
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [JSTypeEnum] -> ShowS
$cshowList :: [JSTypeEnum] -> ShowS
show :: JSTypeEnum -> String
$cshow :: JSTypeEnum -> String
showsPrec :: Int -> JSTypeEnum -> ShowS
$cshowsPrec :: Int -> JSTypeEnum -> ShowS
Show
data JSEvalType = Global | Module
instance Num a => ToCType JSEvalType a where
toCType :: JSEvalType -> a
toCType JSEvalType
Global = a
0
{-# LINE 155 "src/Quickjs/Types.hsc" #-}
toCType Module = 1
{-# LINE 156 "src/Quickjs/Types.hsc" #-}
newtype JSGPNMask = JSGPNMask { JSGPNMask -> JSBool
unJSGPNMask :: CInt }
deriving (JSGPNMask -> JSGPNMask -> Bool
(JSGPNMask -> JSGPNMask -> Bool)
-> (JSGPNMask -> JSGPNMask -> Bool) -> Eq JSGPNMask
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: JSGPNMask -> JSGPNMask -> Bool
$c/= :: JSGPNMask -> JSGPNMask -> Bool
== :: JSGPNMask -> JSGPNMask -> Bool
$c== :: JSGPNMask -> JSGPNMask -> Bool
Eq, Eq JSGPNMask
JSGPNMask
Eq JSGPNMask
-> (JSGPNMask -> JSGPNMask -> JSGPNMask)
-> (JSGPNMask -> JSGPNMask -> JSGPNMask)
-> (JSGPNMask -> JSGPNMask -> JSGPNMask)
-> (JSGPNMask -> JSGPNMask)
-> (JSGPNMask -> Int -> JSGPNMask)
-> (JSGPNMask -> Int -> JSGPNMask)
-> JSGPNMask
-> (Int -> JSGPNMask)
-> (JSGPNMask -> Int -> JSGPNMask)
-> (JSGPNMask -> Int -> JSGPNMask)
-> (JSGPNMask -> Int -> JSGPNMask)
-> (JSGPNMask -> Int -> Bool)
-> (JSGPNMask -> Maybe Int)
-> (JSGPNMask -> Int)
-> (JSGPNMask -> Bool)
-> (JSGPNMask -> Int -> JSGPNMask)
-> (JSGPNMask -> Int -> JSGPNMask)
-> (JSGPNMask -> Int -> JSGPNMask)
-> (JSGPNMask -> Int -> JSGPNMask)
-> (JSGPNMask -> Int -> JSGPNMask)
-> (JSGPNMask -> Int -> JSGPNMask)
-> (JSGPNMask -> Int)
-> Bits JSGPNMask
Int -> JSGPNMask
JSGPNMask -> Bool
JSGPNMask -> Int
JSGPNMask -> Maybe Int
JSGPNMask -> JSGPNMask
JSGPNMask -> Int -> Bool
JSGPNMask -> Int -> JSGPNMask
JSGPNMask -> JSGPNMask -> JSGPNMask
forall a.
Eq a
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> a
-> (Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> Bool)
-> (a -> Maybe Int)
-> (a -> Int)
-> (a -> Bool)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int)
-> Bits a
popCount :: JSGPNMask -> Int
$cpopCount :: JSGPNMask -> Int
rotateR :: JSGPNMask -> Int -> JSGPNMask
$crotateR :: JSGPNMask -> Int -> JSGPNMask
rotateL :: JSGPNMask -> Int -> JSGPNMask
$crotateL :: JSGPNMask -> Int -> JSGPNMask
unsafeShiftR :: JSGPNMask -> Int -> JSGPNMask
$cunsafeShiftR :: JSGPNMask -> Int -> JSGPNMask
shiftR :: JSGPNMask -> Int -> JSGPNMask
$cshiftR :: JSGPNMask -> Int -> JSGPNMask
unsafeShiftL :: JSGPNMask -> Int -> JSGPNMask
$cunsafeShiftL :: JSGPNMask -> Int -> JSGPNMask
shiftL :: JSGPNMask -> Int -> JSGPNMask
$cshiftL :: JSGPNMask -> Int -> JSGPNMask
isSigned :: JSGPNMask -> Bool
$cisSigned :: JSGPNMask -> Bool
bitSize :: JSGPNMask -> Int
$cbitSize :: JSGPNMask -> Int
bitSizeMaybe :: JSGPNMask -> Maybe Int
$cbitSizeMaybe :: JSGPNMask -> Maybe Int
testBit :: JSGPNMask -> Int -> Bool
$ctestBit :: JSGPNMask -> Int -> Bool
complementBit :: JSGPNMask -> Int -> JSGPNMask
$ccomplementBit :: JSGPNMask -> Int -> JSGPNMask
clearBit :: JSGPNMask -> Int -> JSGPNMask
$cclearBit :: JSGPNMask -> Int -> JSGPNMask
setBit :: JSGPNMask -> Int -> JSGPNMask
$csetBit :: JSGPNMask -> Int -> JSGPNMask
bit :: Int -> JSGPNMask
$cbit :: Int -> JSGPNMask
zeroBits :: JSGPNMask
$czeroBits :: JSGPNMask
rotate :: JSGPNMask -> Int -> JSGPNMask
$crotate :: JSGPNMask -> Int -> JSGPNMask
shift :: JSGPNMask -> Int -> JSGPNMask
$cshift :: JSGPNMask -> Int -> JSGPNMask
complement :: JSGPNMask -> JSGPNMask
$ccomplement :: JSGPNMask -> JSGPNMask
xor :: JSGPNMask -> JSGPNMask -> JSGPNMask
$cxor :: JSGPNMask -> JSGPNMask -> JSGPNMask
.|. :: JSGPNMask -> JSGPNMask -> JSGPNMask
$c.|. :: JSGPNMask -> JSGPNMask -> JSGPNMask
.&. :: JSGPNMask -> JSGPNMask -> JSGPNMask
$c.&. :: JSGPNMask -> JSGPNMask -> JSGPNMask
$cp1Bits :: Eq JSGPNMask
Bits)
jsGPNStringMask :: JSGPNMask
jsGPNStringMask :: JSGPNMask
jsGPNStringMask = JSBool -> JSGPNMask
JSGPNMask JSBool
1
jsGPNSymbolMask :: JSGPNMask
jsGPNSymbolMask :: JSGPNMask
jsGPNSymbolMask = JSBool -> JSGPNMask
JSGPNMask JSBool
2
jsGPNPrivateMask :: JSGPNMask
jsGPNPrivateMask :: JSGPNMask
jsGPNPrivateMask = JSBool -> JSGPNMask
JSGPNMask JSBool
4
jsGPNEnumOnly :: JSGPNMask
jsGPNEnumOnly :: JSGPNMask
jsGPNEnumOnly = JSBool -> JSGPNMask
JSGPNMask JSBool
16
jsGPNSetEnum :: JSGPNMask
jsGPNSetEnum :: JSGPNMask
jsGPNSetEnum = JSBool -> JSGPNMask
JSGPNMask JSBool
32
{-# LINE 168 "src/Quickjs/Types.hsc" #-}
quickjsCtx :: Context
quickjsCtx = baseCtx <> fptrCtx <> ctx
where
ctx = mempty
{ ctxTypesTable = quickjsTypesTable
}
quickjsTypesTable :: TypesTable
quickjsTypesTable :: TypesTable
quickjsTypesTable = [(TypeSpecifier, TypeQ)] -> TypesTable
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList
[
(CIdentifier -> TypeSpecifier
C.TypeName CIdentifier
"JSValue", [t| JSValue |])
, (CIdentifier -> TypeSpecifier
C.TypeName CIdentifier
"JSValueConst", [t| JSValueConst |])
, (CIdentifier -> TypeSpecifier
C.TypeName CIdentifier
"JSRuntime", [t| JSRuntime |])
, (CIdentifier -> TypeSpecifier
C.TypeName CIdentifier
"JSContext", [t| JSContext |])
, (CIdentifier -> TypeSpecifier
C.TypeName CIdentifier
"JSBool", [t| JSBool |])
, (CIdentifier -> TypeSpecifier
C.TypeName CIdentifier
"JSAtom", [t| JSAtom |])
, (CIdentifier -> TypeSpecifier
C.TypeName CIdentifier
"JSPropertyEnum", [t| JSPropertyEnum |])
]