Renamed enter/leave

This commit is contained in:
Dmitry Boulytchev 2018-04-02 06:09:30 +03:00
parent 47080c50cd
commit 0ab54cddbc
2 changed files with 6 additions and 6 deletions

View file

@ -30,10 +30,10 @@ module State =
let eval s x = (if List.mem x s.scope then s.l else s.g) x
(* Creates a new scope, based on a given state *)
let push_scope st xs = {empty with g = st.g; scope = xs}
let enter st xs = {empty with g = st.g; scope = xs}
(* Drops a scope *)
let drop_scope st st' = {st' with g = st.g}
let leave st st' = {st' with g = st.g}
end
@ -163,9 +163,9 @@ module Stmt =
| Repeat (s, e) -> let (st, _, _) as conf' = eval env conf s in if Expr.eval st e = 0 then eval env conf' stmt else conf'
| Call (f, args) -> let args = List.map (Expr.eval st) args in
let xs, locs, s = env#definition f in
let st' = List.fold_left (fun st (x, a) -> State.update x a st) (State.push_scope st (xs @ locs)) (List.combine xs args) in
let st' = List.fold_left (fun st (x, a) -> State.update x a st) (State.enter st (xs @ locs)) (List.combine xs args) in
let st'', i', o' = eval env (st', i, o) s in
(State.drop_scope st'' st, i', o')
(State.leave st'' st, i', o')
(* Statement parser *)
ostap (

View file

@ -51,9 +51,9 @@ let rec eval env ((cstack, stack, ((st, i, o) as c)) as conf) = function
| a::args', s::stack' -> combine ((a, s)::acc) args' stack'
in
let state', stack' = combine [] args stack in
eval env (cstack, stack', (List.fold_left (fun s (x, v) -> State.update x v s) (State.push_scope st (args @ locals)) state', i, o)) prg'
eval env (cstack, stack', (List.fold_left (fun s (x, v) -> State.update x v s) (State.enter st (args @ locals)) state', i, o)) prg'
| END -> (match cstack with
| (prg', st')::cstack' -> eval env (cstack', stack, (State.drop_scope st st', i, o)) prg'
| (prg', st')::cstack' -> eval env (cstack', stack, (State.leave st st', i, o)) prg'
| [] -> conf
)
)