From 127610aed7b52f64b24492032c7a898cb1771c06 Mon Sep 17 00:00:00 2001 From: 702fbtngus <702fbtngus@kaist.ac.kr> Date: Tue, 27 Aug 2024 15:54:54 +0900 Subject: [PATCH] Interpret CompE --- spectec/src/backend-interpreter/interpreter.ml | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/spectec/src/backend-interpreter/interpreter.ml b/spectec/src/backend-interpreter/interpreter.ml index c27c7d454a..454cfca8e0 100644 --- a/spectec/src/backend-interpreter/interpreter.ml +++ b/spectec/src/backend-interpreter/interpreter.ml @@ -244,9 +244,21 @@ and eval_expr env expr = ) (* Data Structure *) | ListE el -> List.map (eval_expr env) el |> listV_of_list - (* | CompE (_, _) -> - (* TODO: interpret CompE *) - raise (Exception.MissingReturnValue "CompE") *) + | CompE (e1, e2) -> + let s1 = eval_expr env e1 |> unwrap_strv in + let s2 = eval_expr env e2 |> unwrap_strv in + List.map + (fun (id, v) -> + let arr1 = match !v with + | ListV arr_ref -> arr_ref + | _ -> failwith (sprintf "`%s` is not a list" (string_of_value !v)) + in + let arr2 = match Record.find id s2 with + | ListV arr_ref -> arr_ref + | v -> failwith (sprintf "`%s` is not a list" (string_of_value v)) + in + (id, Array.append !arr1 !arr2 |> listV |> ref) + ) s1 |> strV | CatE (e1, e2) -> let a1 = eval_expr env e1 |> unwrap_seq_to_array in let a2 = eval_expr env e2 |> unwrap_seq_to_array in