Skip to content

Commit

Permalink
Merge pull request #71 from kaeluka/new-ponyrt
Browse files Browse the repository at this point in the history
Generate structs for messages conforming to the new PonyRT
  • Loading branch information
TobiasWrigstad committed Feb 4, 2015
2 parents ec48ce1 + bf853ae commit f41b8a8
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 @@ -72,7 +72,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 @@ -29,6 +29,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 @@ -127,4 +129,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 @@ -53,24 +53,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 f41b8a8

Please sign in to comment.