Skip to content

Commit

Permalink
Generate new structs for messages.
Browse files Browse the repository at this point in the history
There's one struct for oneway msgs and one struct for future-msgs
each.

This encore method in class `Foo`

    def bar(x:int, y:string) {...}

will generate:

    struct ___encore_Foo_bar_fut_msg
    {
      encore_fut_msg_t msg;
      int64_t x;
      char* y;
    };

    struct ___encore_Foo_bar_oneway_msg
    {
      encore_msg_t msg;
      int64_t x;
      char* y;
    };
  • Loading branch information
Stephan Brandauer committed Feb 4, 2015
1 parent 6660676 commit bf853ae
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/back/CCode/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/back/CodeGen/CCodeNames.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
closure_type_rec_name = Nam $ "closure_type"
27 changes: 10 additions & 17 deletions src/back/CodeGen/ClassDecl.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down

0 comments on commit bf853ae

Please sign in to comment.