Skip to content

Commit

Permalink
Interpret CompE
Browse files Browse the repository at this point in the history
  • Loading branch information
702fbtngus committed Aug 27, 2024
1 parent 61dcf0a commit 127610a
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions spectec/src/backend-interpreter/interpreter.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 127610a

Please sign in to comment.