Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pointer to runtime type in each object #160

Merged
merged 1 commit into from
May 8, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/back/CodeGen/CCodeNames.hs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ array = Ptr $ Typ "array_t"
unit :: CCode Lval
unit = Embed "UNIT"

self_type_field :: CCode Name
self_type_field = Nam "_enc__self_type"

-- | each method is implemented as a function with a `this`
-- pointer. This is the name of that function
method_impl_name :: Ty.Type -> ID.Name -> CCode Name
Expand Down
13 changes: 7 additions & 6 deletions src/back/CodeGen/Expr.hs
Original file line number Diff line number Diff line change
Expand Up @@ -232,15 +232,16 @@ instance Translatable A.Expr (State Ctx.Context (CCode Lval, CCode Stat)) where

translate (A.New {A.ty})
| Ty.isActiveRefType ty =
named_tmp_var "new" ty $
Cast (Ptr . AsType $ class_type_name ty)
(Call (Nam "encore_create")
[Amp $ runtime_type_name ty])
named_tmp_var "new" ty $ Cast (Ptr . AsType $ class_type_name ty)
(Call (Nam "encore_create")
[Amp $ runtime_type_name ty])
| otherwise =
do na <- Ctx.gen_named_sym "new"
let size = Sizeof . AsType $ class_type_name ty
return $ (Var na, Assign (Decl (translate ty, Var na))
(Call (Nam "encore_alloc") [size]))
the_new = Assign (Decl (translate ty, Var na))
(Call (Nam "encore_alloc") [size])
init = Assign (Var na `Arrow` self_type_field) (Amp $ runtime_type_name ty)
return $ (Var na, Seq [the_new, init])

translate (A.Peer {A.ty})
| Ty.isActiveRefType ty =
Expand Down
5 changes: 3 additions & 2 deletions src/back/CodeGen/Header.hs
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,9 @@ generate_header p =
passive_types = map passive_type $ filter (not . A.isActive) allclasses
where
passive_type A.Class{A.cname, A.fields} =
StructDecl (AsType $ class_type_name cname)
(zip
StructDecl (AsType $ class_type_name cname)
((Ptr pony_type_t, AsLval $ self_type_field) :
zip
(map (translate . A.ftype) fields)
(map (Var . show . A.fname) fields))

Expand Down
8 changes: 6 additions & 2 deletions src/runtime/encore/encore.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,14 +297,18 @@ bool gc_disabled()

encore_actor_t *encore_create(pony_type_t *type)
{
return (encore_actor_t *)pony_create(type);
encore_actor_t *new = (encore_actor_t *)pony_create(type);
new->_enc__self_type = type;
return new;
}

encore_actor_t *encore_peer_create(pony_type_t *type)
{
//todo: this should create an actor in another work pool
// printf("warning: creating peer not implemented by runtime\n");
return (encore_actor_t *)pony_create(type);
encore_actor_t *new = (encore_actor_t *)pony_create(type);
new->_enc__self_type = type;
return new;
}

/// Allocate s bytes of memory, zeroed out
Expand Down
1 change: 1 addition & 0 deletions src/runtime/encore/encore.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ struct encore_actor
#else
ucontext_t *saved;
#endif
pony_type_t *_enc__self_type;
};

/// Create a new Encore actor
Expand Down