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'
|
||||
|
||||
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
|
||||
| Variable (id, _) ->
|
||||
(* On cherche l'id dans l'environnement *)
|
||||
|
@ -403,7 +403,7 @@ and expression _pos environment _memory = function
|
|||
(* Cas pour le Tuple vide
|
||||
* Un tuple vide ne contient rien (logique), donc on utilise un 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 _ ->
|
||||
(* TODO *)
|
||||
failwith "Students! This is your job (Sequence)!"
|
||||
|
@ -413,12 +413,10 @@ and expression _pos environment _memory = function
|
|||
| Fun (FunctionDefinition _) ->
|
||||
(* TODO *)
|
||||
failwith "Students! This is your job (Fun)!"
|
||||
| Apply _ ->
|
||||
(* TODO *)
|
||||
failwith "Students! This is your job (Apply)!"
|
||||
| Apply (f, x) -> apply_expression f x environment memory
|
||||
| Ref ref ->
|
||||
let dref = expression' environment _memory ref in
|
||||
VLocation (Memory.allocate _memory Mint.one dref)
|
||||
let dref = expression' environment memory ref in
|
||||
VLocation (Memory.allocate memory Mint.one dref)
|
||||
| Assign _ ->
|
||||
(* TODO *)
|
||||
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 *)
|
||||
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
|
||||
| LInt n -> VInt n
|
||||
| LChar c -> VChar c
|
||||
|
|
Reference in a new issue