From ba4191b64a294e3790fdb9539122f1b1338e8cb8 Mon Sep 17 00:00:00 2001 From: ProgramSnail Date: Sat, 10 Jan 2026 07:40:46 +0300 Subject: [PATCH 1/2] +rel types def --- lib/relational_semantic_interpreter.ml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/relational_semantic_interpreter.ml b/lib/relational_semantic_interpreter.ml index 651eec1..c7a64f3 100644 --- a/lib/relational_semantic_interpreter.ml +++ b/lib/relational_semantic_interpreter.ml @@ -40,5 +40,14 @@ struct @type value_logic = value_ground logic with show, gmap type value_injected = value_ground ilogic + @type list_map_ground = (data_ground * data_ground) List.ground with show, gmap + @type list_map_logic = (data_logic * data_logic) List.logic with show, gmap + type list_map_injected = (data_injected * data_injected) List.injected ilogic + + @type ('env, 'mem, 'last_mem, 'assignments) state_abs = 'env * 'mem * 'last_mem * 'assignments with show, gmap + @type state_ground = (list_map_ground, value_ground List.ground, data_ground, data_ground List.ground) state_abs with show, gmap + @type state_logic = (list_map_logic, value_logic List.logic, data_logic, data_logic List.logic) state_abs logic with show, gmap + type state_injected = (list_map_injected, value_injected List.injected, data_injected, data_injected List.injected) state_abs ilogic + (* ocanren type 'a lst = Nil | Cons of 'a * 'a lst *) end From 909dad66940e9cf94a8dbca6adf12a472d96287d Mon Sep 17 00:00:00 2001 From: ProgramSnail Date: Sun, 11 Jan 2026 15:12:33 +0300 Subject: [PATCH 2/2] replace map with loist of associations --- lib/semantic_interpreter.ml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/semantic_interpreter.ml b/lib/semantic_interpreter.ml index 539f98c..2952dd8 100644 --- a/lib/semantic_interpreter.ml +++ b/lib/semantic_interpreter.ml @@ -23,7 +23,7 @@ struct (* --- static interpreter (no rec) --- *) - module M = Map.Make (Int);; + type env = (int * data) list (* TODO: allow data (rvalue) in calls ?? *) type arg = RValue | LValue of data @@ -31,7 +31,7 @@ struct (* TODO: replace env map with pairs *) (* env * memory * last unused memory * assignments *) - type state = data M.t * value list * int * data list + type state = env * value list * int * data list (* TODO: replace with pairs *) let rec list_replace xs id value = match (xs, id) with @@ -41,10 +41,10 @@ struct let env_get state id = match state with - (env, _mem, _mem_len, _assignments) -> M.find id env + (env, _mem, _mem_len, _assignments) -> List.assoc id env let env_add state id mem_id = match state with - (env, mem, mem_len, assignments) -> let env = M.add id mem_id env in + (env, mem, mem_len, assignments) -> let env = (id, mem_id) :: env in (env, mem, mem_len, assignments) let inv_id mem_len id = mem_len - id - 1 @@ -93,7 +93,7 @@ struct and eval_fun state prog decl args = match decl with (arg_tags, body) -> match state with (env_before, mem_before, len_before, assignments_before) as state_before -> - let state = (M.empty, mem_before, len_before, []) in + let state = ([], mem_before, len_before, []) in let (state, _) = List.fold_left2 (fun (state, id) arg_tag arg -> (st_add_arg state state_before id arg_tag arg, id + 1)) (state, 0) arg_tags args in let state = eval_body state prog body in let state = st_spoil_assignments state in @@ -105,7 +105,7 @@ struct let args = List.map (fun _ -> RValue) arg_tags in eval_fun state prog decl args - let empty_state = (M.empty, [], 0, []) + let empty_state = ([], [], 0, []) let eval_prog (prog, main_decl) = ignore @@ eval_fun_empty_args empty_state prog main_decl