From 2546d6d16b6d75137bd9956217e6f082823fcc63 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Mon, 6 Nov 2023 20:55:37 +0100 Subject: [PATCH] apply --- flap/src/hopix/hopixInterpreter.ml | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/flap/src/hopix/hopixInterpreter.ml b/flap/src/hopix/hopixInterpreter.ml index 0e8341e..3814997 100644 --- a/flap/src/hopix/hopixInterpreter.ml +++ b/flap/src/hopix/hopixInterpreter.ml @@ -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