From 0309ef98b3a86bd4beb6bfa9a5130fdff6dafb17 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Fri, 18 Oct 2024 18:19:01 +0200 Subject: [PATCH 1/2] WIP: use promises --- src/mo_interpreter/interpret.ml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/mo_interpreter/interpret.ml b/src/mo_interpreter/interpret.ml index ec3a30736cb..11149479c91 100644 --- a/src/mo_interpreter/interpret.ml +++ b/src/mo_interpreter/interpret.ml @@ -17,7 +17,7 @@ type lib_env = V.value V.Env.t type lab_env = V.value V.cont V.Env.t type ret_env = V.value V.cont option type throw_env = V.value V.cont option -type actor_env = V.value V.Env.t ref (* indexed by actor ids *) +type actor_env = V.def V.Env.t ref (* indexed by actor ids *) (* The actor heap. NB: A cut-down ManagementCanister with id "" is added later, to enjoy access to logging facilities. @@ -70,6 +70,8 @@ let env_of_scope flags ae scope = let context env = V.Blob env.self +let defined f d = f (Lib.Promise.value d) + (* Error handling *) exception Trap of Source.region * string @@ -87,7 +89,7 @@ let lookup_actor env at aid id = match V.Env.find_opt aid !(env.actor_env) with | None -> trap at "Unknown actor \"%s\"" aid | Some actor_value -> - let fs = V.as_obj actor_value in + let fs = defined V.as_obj actor_value in match V.Env.find_opt id fs with | None -> trap at "Actor \"%s\" has no method \"%s\"" aid id | Some field_value -> field_value @@ -907,7 +909,7 @@ and interpret_obj env obj_sort self_id dec_fields (k : V.value V.cont) = let env'' = adjoin_vals { env' with self } ve_in in interpret_dec_fields env'' dec_fields ve_ex (fun obj -> - (env.actor_env := V.Env.add self obj !(env.actor_env); + (env.actor_env := V.Env.add self (Lib.Promise.make_fulfilled obj) !(env.actor_env); k self')) | _ -> let ve_ex, ve_in = declare_dec_fields dec_fields V.Env.empty V.Env.empty in @@ -1047,7 +1049,7 @@ let ensure_management_canister env = Source.no_region (fun k' r -> k' (V.Blob (V.Blob.rand32 ()))) - k)))) + k))) |> Lib.Promise.make_fulfilled) !(env.actor_env) let interpret_prog flags scope p : (V.value * scope) option = From aa92388ecda4048ffd3cd1852564ae1392507263 Mon Sep 17 00:00:00 2001 From: Gabor Greif Date: Mon, 21 Oct 2024 12:03:50 +0200 Subject: [PATCH 2/2] tweak --- src/mo_interpreter/interpret.ml | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/mo_interpreter/interpret.ml b/src/mo_interpreter/interpret.ml index 11149479c91..ae315383c49 100644 --- a/src/mo_interpreter/interpret.ml +++ b/src/mo_interpreter/interpret.ml @@ -1041,15 +1041,14 @@ let ensure_management_canister env = V.Env.add (* ManagementCanister with raw_rand (only) *) "" - (V.Obj - (V.Env.singleton "raw_rand" - (V.async_func (T.Write) 0 1 - (fun c v k -> - async env - Source.no_region - (fun k' r -> - k' (V.Blob (V.Blob.rand32 ()))) - k))) |> Lib.Promise.make_fulfilled) + V.(Obj + (Env.singleton "raw_rand" + (async_func T.Write 0 1 + (fun c v k -> + async env + Source.no_region + (fun k' r -> k' (Blob (Blob.rand32 ()))) + k))) |> Lib.Promise.make_fulfilled) !(env.actor_env) let interpret_prog flags scope p : (V.value * scope) option =