apply
This commit is contained in:
parent
d461396636
commit
2546d6d16b
1 changed files with 16 additions and 7 deletions
|
@ -385,7 +385,7 @@ and expression' environment memory e =
|
||||||
E, M ⊢ e ⇓ v, M'
|
E, M ⊢ e ⇓ v, M'
|
||||||
|
|
||||||
and E = [runtime.environment], M = [runtime.memory]. *)
|
and E = [runtime.environment], M = [runtime.memory]. *)
|
||||||
and expression _pos environment _memory = function
|
and expression _pos environment memory = function
|
||||||
| Literal l -> literal_expression l.value
|
| Literal l -> literal_expression l.value
|
||||||
| Variable (id, _) ->
|
| Variable (id, _) ->
|
||||||
(* On cherche l'id dans l'environnement *)
|
(* On cherche l'id dans l'environnement *)
|
||||||
|
@ -403,7 +403,7 @@ and expression _pos environment _memory = function
|
||||||
(* Cas pour le Tuple vide
|
(* Cas pour le Tuple vide
|
||||||
* Un tuple vide ne contient rien (logique), donc on utilise un VUnit*)
|
* Un tuple vide ne contient rien (logique), donc on utilise un VUnit*)
|
||||||
VUnit
|
VUnit
|
||||||
| Tuple list_exp -> VTuple (List.map (expression' environment _memory) list_exp)
|
| Tuple list_exp -> VTuple (List.map (expression' environment memory) list_exp)
|
||||||
| Sequence _ ->
|
| Sequence _ ->
|
||||||
(* TODO *)
|
(* TODO *)
|
||||||
failwith "Students! This is your job (Sequence)!"
|
failwith "Students! This is your job (Sequence)!"
|
||||||
|
@ -413,12 +413,10 @@ and expression _pos environment _memory = function
|
||||||
| Fun (FunctionDefinition _) ->
|
| Fun (FunctionDefinition _) ->
|
||||||
(* TODO *)
|
(* TODO *)
|
||||||
failwith "Students! This is your job (Fun)!"
|
failwith "Students! This is your job (Fun)!"
|
||||||
| Apply _ ->
|
| Apply (f, x) -> apply_expression f x environment memory
|
||||||
(* TODO *)
|
|
||||||
failwith "Students! This is your job (Apply)!"
|
|
||||||
| Ref ref ->
|
| Ref ref ->
|
||||||
let dref = expression' environment _memory ref in
|
let dref = expression' environment memory ref in
|
||||||
VLocation (Memory.allocate _memory Mint.one dref)
|
VLocation (Memory.allocate memory Mint.one dref)
|
||||||
| Assign _ ->
|
| Assign _ ->
|
||||||
(* TODO *)
|
(* TODO *)
|
||||||
failwith "Students! This is your job (Assign)!"
|
failwith "Students! This is your job (Assign)!"
|
||||||
|
@ -441,6 +439,17 @@ and expression _pos environment _memory = function
|
||||||
(* On ignore le type car on interprète *)
|
(* On ignore le type car on interprète *)
|
||||||
VUnit
|
VUnit
|
||||||
|
|
||||||
|
and apply_expression f x environment memory =
|
||||||
|
let x_val = expression' environment memory x in
|
||||||
|
match expression' environment memory f with
|
||||||
|
| VPrimitive (_, f) ->
|
||||||
|
(* Fonction "primitive" *)
|
||||||
|
f memory x_val
|
||||||
|
| VClosure (env_fn, pattern, expr) ->
|
||||||
|
(* Fonction *)
|
||||||
|
failwith "Students! This is your job (Apply)!"
|
||||||
|
| _ -> assert false (* By typing *)
|
||||||
|
|
||||||
and literal_expression = function
|
and literal_expression = function
|
||||||
| LInt n -> VInt n
|
| LInt n -> VInt n
|
||||||
| LChar c -> VChar c
|
| LChar c -> VChar c
|
||||||
|
|
Reference in a new issue