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

fix wrong expansion of @ in nested EXCEPT #79

Merged
merged 1 commit into from
Jun 11, 2024
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
8 changes: 3 additions & 5 deletions src/expr/e_anon.ml
Original file line number Diff line number Diff line change
Expand Up @@ -297,11 +297,9 @@ class anon_sg = object (self: 'self)
end


class anon = object
inherit anon_sg as super

method expr scx e =
Elab.desugar (super#expr scx e)
class anon = object (self : 'self)
inherit anon_sg as super
method expr scx e = Elab.desugar self#expr super#expr scx e
end


Expand Down
70 changes: 32 additions & 38 deletions src/expr/e_elab.ml
Original file line number Diff line number Diff line change
Expand Up @@ -14,45 +14,39 @@ module Constness = E_constness
module Fmt = E_fmt


let desugar =
let current_at = ref None in
let at_expand = object (self : 'self)
inherit [unit] Visit.map as super
let current_at = ref None

method expr scx e = match e.core with
| At true -> begin
match !current_at with
| Some (e, dep) ->
let shf = Deque.size (snd scx) - dep in
if shf = 0 then e else app_expr (shift shf) e
| None ->
e
end
| Except (f, xs) ->
let at_save = !current_at in
let f = self#expr scx f in
let f = List.fold_left begin
fun f (trail, bod) ->
let (trail, at) = List.fold_left begin
fun (trail, f) -> function
| Except_dot x -> (Except_dot x :: trail, { f with core = Dot (f, x) })
| Except_apply k ->
let k = self#expr scx k in
(Except_apply k :: trail, { f with core = FcnApp (f, [k]) })
end ([], f) trail in
let trail = List.rev trail in
let () = current_at := Some (at, Deque.size (snd scx)) in
let bod = self#expr scx bod in
let () = current_at := at_save in
{e with core = Except (f, [(trail, bod)])}
end f xs in
f
| _ ->
super#expr scx e
end in
fun e ->
current_at := None ;
at_expand#expr ((), Deque.empty) e
let desugar self_expr super_expr scx e =
match e.core with
| At true ->
begin match !current_at with
| Some (e, dep) ->
let shf = Deque.size (snd scx) - dep in
if shf = 0 then e else app_expr (shift shf) e
| None -> e
end
| Except (f, xs) ->
let f = self_expr scx f in
List.fold_left begin
fun f (trail, bod) ->
let (trail, at) =
List.fold_left begin
fun (trail, f) ex ->
match ex with
| Except_dot x ->
(Except_dot x :: trail, {f with core = Dot (f, x)})
| Except_apply k ->
let k = self_expr scx k in
(Except_apply k :: trail, {f with core = FcnApp (f, [k])})
end ([], f) trail
in
let at_save = !current_at in
current_at := Some (at, Deque.size (snd scx));
let bod = self_expr scx bod in
current_at := at_save;
{e with core = Except (f, [(List.rev trail, bod)])}
end f xs
| _ -> super_expr scx e

let non_temporal =
let visitor = object (self : 'self)
Expand Down
4 changes: 3 additions & 1 deletion src/expr/e_elab.mli
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ Copyright (C) 2008-2010 INRIA and Microsoft Corporation
open Deque
open E_t

val desugar : (string list E_visit.scx -> expr -> expr) ->
(string list E_visit.scx -> expr -> expr) ->
string list E_visit.scx -> expr -> expr

val desugar : expr -> expr
(* moved to action frontend *)
(* val prime_normalize : hyp Deque.dq -> expr -> expr *)
val normalize : hyp Deque.dq -> expr -> expr
Expand Down