Skip to content

Commit

Permalink
Assigning from this turns the alias into a normal active reference
Browse files Browse the repository at this point in the history
Note that getting a future from a method called on the alias will cause
a deadlock!
  • Loading branch information
EliasC committed Dec 10, 2014
1 parent 26130e2 commit 9f917d2
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/back/CodeGen/Expr.hs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ instance Translatable A.Expr (State Ctx.Context (CCode Lval, CCode Stat)) where
return (last nes, Seq tes)

translate (A.Assign {A.lhs, A.rhs}) = do
(nrhs, trhs) <- translate rhs
(nrhs, trhs) <- if A.isThisAccess rhs && (Ty.isActiveRefType $ A.getType rhs)
then return (Deref (Var "this") `Dot` (Nam "aref"), Skip)
else translate rhs
lval <- mk_lval lhs
return (unit, Seq [trhs, Assign lval nrhs])
where
Expand Down Expand Up @@ -170,8 +172,10 @@ instance Translatable A.Expr (State Ctx.Context (CCode Lval, CCode Stat)) where
return (nbody, Seq $ tdecls ++ [tbody])
where
translate_decls [] = return []
translate_decls ((name, expr):decls) =
do (ne, te) <- translate expr
translate_decls ((name, expr):decls) =
do (ne, te) <- if A.isThisAccess expr && (Ty.isActiveRefType $ A.getType expr)
then return (Deref (Var "this") `Dot` (Nam "aref"), Skip)
else translate expr
tmp <- Ctx.gen_sym
substitute_var name (Var tmp)
tdecls <- translate_decls decls
Expand Down Expand Up @@ -391,7 +395,9 @@ instance Translatable A.Expr (State Ctx.Context (CCode Lval, CCode Stat)) where
| Ty.isRealType ty = AsExpr $ e `Dot` Nam "d"
| otherwise = AsExpr $ e `Dot` Nam "p"
translateArgument arg =
do (ntother, tother) <- translate arg
do (ntother, tother) <- if A.isThisAccess arg && (Ty.isActiveRefType $ A.getType arg)
then return (Deref (Var "this") `Dot` (Nam "aref"), Skip)
else translate arg
return $ UnionInst (arg_member $ A.getType arg) (StatAsExpr ntother tother)
where
arg_member ty
Expand Down
33 changes: 33 additions & 0 deletions src/tests/encore/basic/activeThis.enc
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
class Foo
def fr0b() : bool
true

def foo() : Fut bool
let that = this in{
that.fr0b();
}

def bar() : Fut bool
let that = null : Foo in{
that = this;
that.fr0b()
}

def baz() : Fut bool
let id = \ (x : a) -> x
that = id(this)
in
that.fr0b()

class Main
def main() : void
let x = new Foo in{
assertTrue(get get x.foo());
assertTrue(get get x.bar());
assertTrue(get get x.baz());
print "Done!";
-- TODO: Find out why this is needed!
embed void
fflush(NULL);
end
}
1 change: 1 addition & 0 deletions src/tests/encore/basic/activeThis.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Done!

0 comments on commit 9f917d2

Please sign in to comment.