Fix: self is no longer considered free var

For recursive functions, the self-reference was considered a free
variable wrt. defunctionalization
This commit is contained in:
Théophile Bastian 2018-02-16 01:13:06 +01:00
parent 6f75134474
commit 29a2ef43a1

View file

@ -65,7 +65,7 @@ let rec walk_term fs t =
| S.LetVal (var, value, next) ->
let fs, nNext = walk_term fs next in
fs, T.LetVal(var, value, nNext)
| S.LetBlo (var, S.Lam(_, vars, body), next) ->
| S.LetBlo (var, S.Lam(self, vars, body), next) ->
(* FIXME is handling of recursive functions correct? *)
let fs, nNext = walk_term fs next in
let fs, nBody = walk_term fs body in
@ -77,10 +77,13 @@ let rec walk_term fs t =
vars
(S.vvars (List.tl args)) in
let thisTag = freshTag () in
let selfVars = (match self with
| S.Self self -> Atom.Set.singleton self
| S.NoSelf -> Atom.Set.empty) in
let freeVars = Atom.Set.elements @@
Atom.Set.diff
(S.fv_term body)
(Atom.Set.of_list vars)
(Atom.Set.union (Atom.Set.of_list vars) selfVars)
in
let thisFunc =
T.Branch(thisTag, freeVars, nBody) in