Skip to content
Snippets Groups Projects
Commit 6e082ac0 authored by Augustin Jaujay's avatar Augustin Jaujay
Browse files

Instruction Get fonctionnelle

parent ba7dc02c
No related branches found
No related tags found
No related merge requests found
......@@ -12,3 +12,5 @@ let rec eval env = function
| _, v -> (BinOp.eval op) (eval env e1) v
end
| Uminus e -> - (eval env e)
| App(_, _) -> failwith "Not yet supported" (* TODO *)
| Fun(_, _) -> failwith "Not yet supported"
......@@ -10,5 +10,7 @@ let rec generate = function
| Binop(Bmul,a,b) -> (generate b) @ (generate a) @ [Mul]
| Binop(Bdiv,a,b) -> (generate b) @ (generate a) @ [Div]
| Binop(Bmod,a,b) -> (generate b) @ (generate a) @ [Rem]
| App(_, _) -> failwith "Not yet supported" (* TODO *)
| Fun(_, _) -> failwith "Not yet supported"
| Uminus x -> (generate x) @ [Push 0] @ [Sub]
| Var _ -> failwith "Not yet supported"
......@@ -14,6 +14,8 @@ let string_of_command = function
| Mul -> "Mul"
| Div -> "Div"
| Rem -> "Rem"
| Exec -> "Exec"
| Get -> "Get"
let string_of_commands cmds = String.concat " " (List.map string_of_command cmds)
......
......@@ -30,7 +30,9 @@ let step state =
| Rem::_, [] -> Error("Nothing to divide",state)
| Rem::_, _::0::_ -> Error("Forbidden operation",state)
| Get::_, i::stack when (List.length stack) < i -> Error("Invalid get operation", state)
| Get::_, i::_ when i < O -> Error("Cannot get negative index", state)
| Get::_, i::_ when i < 0 -> Error("Cannot get negative index", state)
| Get::_, [] -> Error("Nothing to get", state)
| Exec::_, _ -> Error("Not yet supported", state) (* TODO *)
(* Valid configurations *)
| (Push x)::q, stack -> Ok (q, x::stack)
| Pop::q, _::stack -> Ok (q, stack)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment