Skip to content
Snippets Groups Projects
Commit aedd4f0a authored by Jens Nolte's avatar Jens Nolte
Browse files

Document and clean up code generator

parent 74c92172
No related branches found
No related tags found
No related merge requests found
...@@ -103,20 +103,34 @@ tellQs = tell <=< lift ...@@ -103,20 +103,34 @@ tellQs = tell <=< lift
interfaceDecs :: InterfaceSpec -> Q ([Dec], [Dec]) interfaceDecs :: InterfaceSpec -> Q ([Dec], [Dec])
interfaceDecs interface = do interfaceDecs interface = do
public <- execWriterT do public <- execWriterT do
-- Main interface type
let iCtorDec = (normalC iName [], Nothing, []) let iCtorDec = (normalC iName [], Nothing, [])
tellQ $ dataD_doc (pure []) iName [] Nothing [iCtorDec] [] (toDoc interface.description) tellQ $ dataD_doc (pure []) iName [] Nothing [iCtorDec] [] (toDoc interface.description)
tellQ $ instanceD (pure []) [t|IsInterface $iT|] instanceDecs -- IsInterface instance
tellQ $ instanceD (pure []) [t|IsInterface $iT|] [
tySynInstD (tySynEqn Nothing [t|$(conT ''Requests) $sT $iT|] (orUnit (requestsT interface sT))),
tySynInstD (tySynEqn Nothing [t|$(conT ''Events) $sT $iT|] (orUnit (eventsT interface sT))),
tySynInstD (tySynEqn Nothing (appT (conT ''WireRequest) iT) wireRequestT),
tySynInstD (tySynEqn Nothing (appT (conT ''WireEvent) iT) eT),
tySynInstD (tySynEqn Nothing (appT (conT ''InterfaceName) iT) (litT (strTyLit interface.name)))
]
-- | IsInterfaceSide instance
tellQs interfaceSideInstanceDs tellQs interfaceSideInstanceDs
-- | Requests record
when (length interface.requests > 0) do when (length interface.requests > 0) do
tellQ requestRecordD tellQ requestRecordD
-- | Events record
when (length interface.events > 0) do when (length interface.events > 0) do
tellQ eventRecordD tellQ eventRecordD
internals <- execWriterT do internals <- execWriterT do
-- | Request wire type
when (length interface.requests > 0) do when (length interface.requests > 0) do
tellQs $ messageTypeDecs rTypeName requestContexts tellQs $ messageTypeDecs rTypeName requestContexts
-- | Event wire type
when (length interface.events > 0) do when (length interface.events > 0) do
tellQs $ messageTypeDecs eTypeName eventContexts tellQs $ messageTypeDecs eTypeName eventContexts
...@@ -126,13 +140,6 @@ interfaceDecs interface = do ...@@ -126,13 +140,6 @@ interfaceDecs interface = do
iName = interfaceN interface iName = interfaceN interface
iT = interfaceT interface iT = interfaceT interface
sT = sideTVar sT = sideTVar
instanceDecs = [
tySynInstD (tySynEqn Nothing [t|$(conT ''Requests) $sT $iT|] (orUnit (requestsT interface sT))),
tySynInstD (tySynEqn Nothing [t|$(conT ''Events) $sT $iT|] (orUnit (eventsT interface sT))),
tySynInstD (tySynEqn Nothing (appT (conT ''WireRequest) iT) wireRequestT),
tySynInstD (tySynEqn Nothing (appT (conT ''WireEvent) iT) eT),
tySynInstD (tySynEqn Nothing (appT (conT ''InterfaceName) iT) (litT (strTyLit interface.name)))
]
wireRequestT :: Q Type wireRequestT :: Q Type
wireRequestT = if length interface.requests > 0 then conT rTypeName else [t|Void|] wireRequestT = if length interface.requests > 0 then conT rTypeName else [t|Void|]
rTypeName :: Name rTypeName :: Name
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment