mirror of
https://github.com/ProgramSnail/Lama.git
synced 2025-12-07 15:28:49 +00:00
Renamed enter/leave
This commit is contained in:
parent
47080c50cd
commit
0ab54cddbc
2 changed files with 6 additions and 6 deletions
|
|
@ -30,10 +30,10 @@ module State =
|
||||||
let eval s x = (if List.mem x s.scope then s.l else s.g) x
|
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 *)
|
(* 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 *)
|
(* Drops a scope *)
|
||||||
let drop_scope st st' = {st' with g = st.g}
|
let leave st st' = {st' with g = st.g}
|
||||||
|
|
||||||
end
|
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'
|
| 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
|
| Call (f, args) -> let args = List.map (Expr.eval st) args in
|
||||||
let xs, locs, s = env#definition f 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
|
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 *)
|
(* Statement parser *)
|
||||||
ostap (
|
ostap (
|
||||||
|
|
|
||||||
|
|
@ -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'
|
| a::args', s::stack' -> combine ((a, s)::acc) args' stack'
|
||||||
in
|
in
|
||||||
let state', stack' = combine [] 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
|
| 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
|
| [] -> conf
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue