From 5743c6c3a7227fbca9858bc1ae4cc20d3cd25857 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Facundo=20Dom=C3=ADnguez?= Date: Wed, 26 Apr 2023 09:47:44 -0300 Subject: [PATCH] Make Parse.hsc a regular module Parse.hs Liquid Haskell can't collect specs in .hsc files. See https://github.com/ucsd-progsys/liquidhaskell/issues/2132 --- .../src/Foreign/R/{Parse.hsc => Parse.hs} | 30 ++----------------- inline-r/src/Foreign/R/Type.hsc | 26 ++++++++++++++++ 2 files changed, 28 insertions(+), 28 deletions(-) rename inline-r/src/Foreign/R/{Parse.hsc => Parse.hs} (53%) diff --git a/inline-r/src/Foreign/R/Parse.hsc b/inline-r/src/Foreign/R/Parse.hs similarity index 53% rename from inline-r/src/Foreign/R/Parse.hsc rename to inline-r/src/Foreign/R/Parse.hs index 192c3560..262c5a24 100644 --- a/inline-r/src/Foreign/R/Parse.hsc +++ b/inline-r/src/Foreign/R/Parse.hs @@ -3,49 +3,23 @@ -- -- Bindings for @@. -{-# LANGUAGE CPP #-} {-# LANGUAGE CApiFFI #-} {-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE ViewPatterns #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE ForeignFunctionInterface #-} -#include -#include module Foreign.R.Parse ( parseVector , ParseStatus(..) ) where +import Foreign.R.Type (ParseStatus(..)) import qualified Foreign.R as R import Foreign import Foreign.C --- | The return code of a call to 'parseVector', indicating whether the parser --- failed or succeeded. -data ParseStatus - = PARSE_NULL - | PARSE_OK - | PARSE_INCOMPLETE - | PARSE_ERROR - | PARSE_EOF - deriving (Eq, Show) - -instance Enum ParseStatus where - fromEnum PARSE_NULL = #const PARSE_NULL - fromEnum PARSE_OK = #const PARSE_OK - fromEnum PARSE_INCOMPLETE = #const PARSE_INCOMPLETE - fromEnum PARSE_ERROR = #const PARSE_ERROR - fromEnum PARSE_EOF = #const PARSE_EOF - toEnum i = case i of - (#const PARSE_NULL) -> PARSE_NULL - (#const PARSE_OK) -> PARSE_OK - (#const PARSE_INCOMPLETE) -> PARSE_INCOMPLETE - (#const PARSE_ERROR) -> PARSE_ERROR - (#const PARSE_EOF) -> PARSE_EOF - _ -> error "ParseStatus.fromEnum: can't mach value" - -- | @parseVector text num status source@ parses the input string into an AST. -- @source@, if provided, names the origin of @text@ (e.g. a filename). @num@ -- limits the number of expressions to parse, or @-1@ if no limit. @@ -59,6 +33,6 @@ parseVector -> IO (R.SEXP s) parseVector (R.unsexp -> s) (fromIntegral -> cnt) reti (R.unsexp -> input) = R.sexp <$> c_parseVector s cnt reti input - + foreign import ccall "R_ext/Parse.h R_ParseVector" c_parseVector :: R.SEXP0 -> CInt -> Ptr CInt -> R.SEXP0 -> IO R.SEXP0 diff --git a/inline-r/src/Foreign/R/Type.hsc b/inline-r/src/Foreign/R/Type.hsc index 7b23d586..00d98fef 100644 --- a/inline-r/src/Foreign/R/Type.hsc +++ b/inline-r/src/Foreign/R/Type.hsc @@ -38,6 +38,7 @@ module Foreign.R.Type , Sing , Logical(..) , PairList + , ParseStatus(..) , IsVector , IsGenericVector , IsList @@ -46,6 +47,7 @@ module Foreign.R.Type ) where #include +#include import Foreign.R.Constraints import Internal.Error @@ -162,6 +164,30 @@ instance Enum SEXPTYPE where instance NFData SEXPTYPE where rnf = (`seq` ()) +-- | The return code of a call to 'parseVector', indicating whether the parser +-- failed or succeeded. +data ParseStatus + = PARSE_NULL + | PARSE_OK + | PARSE_INCOMPLETE + | PARSE_ERROR + | PARSE_EOF + deriving (Eq, Show) + +instance Enum ParseStatus where + fromEnum PARSE_NULL = #const PARSE_NULL + fromEnum PARSE_OK = #const PARSE_OK + fromEnum PARSE_INCOMPLETE = #const PARSE_INCOMPLETE + fromEnum PARSE_ERROR = #const PARSE_ERROR + fromEnum PARSE_EOF = #const PARSE_EOF + toEnum i = case i of + (#const PARSE_NULL) -> PARSE_NULL + (#const PARSE_OK) -> PARSE_OK + (#const PARSE_INCOMPLETE) -> PARSE_INCOMPLETE + (#const PARSE_ERROR) -> PARSE_ERROR + (#const PARSE_EOF) -> PARSE_EOF + _ -> error "ParseStatus.fromEnum: can't mach value" + genSingletons [''SEXPTYPE] -- | Used where the R documentation speaks of "pairlists", which are really just