diff --git a/src/back/CCode/Main.hs b/src/back/CCode/Main.hs index 9e1964cf8..ea79db666 100644 --- a/src/back/CCode/Main.hs +++ b/src/back/CCode/Main.hs @@ -71,7 +71,7 @@ data CCode a where Deref :: UsableAs e Expr => CCode e -> CCode Expr Cast :: UsableAs e Expr => CCode Ty -> CCode e -> CCode Expr ArrAcc :: Int -> CCode Lval -> CCode Lval - Amp :: (UsableAs e Expr) => CCode e -> CCode Expr + Amp :: (UsableAs e Expr) => CCode e -> CCode Expr -- | Ampersand Ptr :: CCode Ty -> CCode Ty FunctionDecl :: CCode Ty -> CCode Name -> [CCode Ty] -> CCode Toplevel Function :: CCode Ty -> CCode Name -> [CVarSpec] -> CCode Stat -> CCode Toplevel diff --git a/src/back/CodeGen/CCodeNames.hs b/src/back/CodeGen/CCodeNames.hs index b291a48a2..b89a3eb11 100644 --- a/src/back/CodeGen/CCodeNames.hs +++ b/src/back/CodeGen/CCodeNames.hs @@ -28,6 +28,8 @@ pony_actor_t = Typ "pony_actor_t" pony_actor_type_t = Typ "pony_actor_type_t" pony_arg_t = Typ "pony_arg_t" pony_msg_t = Typ "pony_msg_t" +enc_msg_t = Typ "encore_fut_msg_t" +enc_oneway_msg_t = Typ "encore_oneway_msg_t" closure = Ptr $ Typ "closure_t" future = Ptr $ Typ "future_t" stream = Ptr $ Typ "stream_t" @@ -108,4 +110,4 @@ future_type_rec_name :: CCode Name future_type_rec_name = Nam $ "future_type" closure_type_rec_name :: CCode Name -closure_type_rec_name = Nam $ "closure_type" \ No newline at end of file +closure_type_rec_name = Nam $ "closure_type" diff --git a/src/back/CodeGen/ClassDecl.hs b/src/back/CodeGen/ClassDecl.hs index d8700dc30..69921ec8e 100644 --- a/src/back/CodeGen/ClassDecl.hs +++ b/src/back/CodeGen/ClassDecl.hs @@ -77,24 +77,17 @@ translateActiveClass cdecl@(A.Class{A.cname, A.fields, A.methods}) = pony_msg_t_impls :: [CCode Toplevel] pony_msg_t_impls = map pony_msg_t_impl methods where + pony_msg_t_impl :: A.MethodDecl -> CCode Toplevel pony_msg_t_impl mdecl = - Concat - [AssignTL - (Decl (Static (Typ "pony_msg_t"), - (method_message_type_name cname (A.mname mdecl)))) - (if (A.isMainClass cdecl) && (A.mname mdecl == ID.Name "main") then - (Record - [Int $ length (A.mparams mdecl), - Record $ map (runtime_type . A.getType) (A.mparams mdecl)]) - else - (Record - [Int $ length (A.mparams mdecl) + 1, -- plus 1 for future argument - Record $ Amp future_type_rec_name : map (runtime_type . A.getType) (A.mparams mdecl)])), - AssignTL - (Decl (Static (Typ "pony_msg_t"), - one_way_message_type_name cname (A.mname mdecl))) - (Record [Int $ length (A.mparams mdecl), - Record $ map (runtime_type . A.getType) (A.mparams mdecl)])] + let argrttys = map (translate . A.getType) (A.mparams mdecl) + argnames = map (Var . show . A.pname) (A.mparams mdecl) + argspecs = zip argrttys argnames :: [CVarSpec] + encoremsgtspec = (enc_msg_t, Var "msg") + encoremsgtspec_oneway = (enc_oneway_msg_t, Var "msg") + nameprefix = "encore_"++ (show (A.cname cdecl)) + ++ "_" ++ (show (A.mname mdecl)) + in Concat [StructDecl (Typ $ nameprefix ++ "_fut_msg") (encoremsgtspec : argspecs) + ,StructDecl (Typ $ nameprefix ++ "_oneway_msg") (encoremsgtspec_oneway : argspecs)] message_type_decl :: CCode Toplevel message_type_decl =