mirror of
https://github.com/CatalaLang/catala.git
synced 2024-09-19 00:15:39 +03:00
Support closure calls across modules
First I was disappointed that we couldn't convert closure environment properly because of their opaque nature (native/interpreted conversion is based on the Catala types) ; but after more thought it's actually unnecessary to convert them at all since we are guaranteed that they can't be consumed outside of their realm.
This commit is contained in:
parent
d871b95447
commit
712fc1e279
@ -566,7 +566,11 @@ let rec runtime_to_val :
|
|||||||
let e = runtime_to_val eval_expr ctx m ty (Obj.field o 0) in
|
let e = runtime_to_val eval_expr ctx m ty (Obj.field o 0) in
|
||||||
EInj { name = Expr.option_enum; cons = Expr.some_constr; e }, m
|
EInj { name = Expr.option_enum; cons = Expr.some_constr; e }, m
|
||||||
| _ -> assert false)
|
| _ -> assert false)
|
||||||
| TClosureEnv -> assert false
|
| TClosureEnv ->
|
||||||
|
(* By construction, a closure environment can only be consumed from the same
|
||||||
|
scope where it was built (compiled or not) ; for this reason, we can
|
||||||
|
safely avoid converting in depth here *)
|
||||||
|
Obj.obj o, m
|
||||||
| TArray ty ->
|
| TArray ty ->
|
||||||
( EArray
|
( EArray
|
||||||
(List.map
|
(List.map
|
||||||
@ -656,6 +660,11 @@ and val_to_runtime :
|
|||||||
in
|
in
|
||||||
curry [] targs
|
curry [] targs
|
||||||
| TDefault ty, _ -> val_to_runtime eval_expr ctx ty v
|
| TDefault ty, _ -> val_to_runtime eval_expr ctx ty v
|
||||||
|
| TClosureEnv, v ->
|
||||||
|
(* By construction, a closure environment can only be consumed from the same
|
||||||
|
scope where it was built (compiled or not) ; for this reason, we can
|
||||||
|
safely avoid converting in depth here *)
|
||||||
|
Obj.repr v
|
||||||
| _ ->
|
| _ ->
|
||||||
Message.error ~internal:true
|
Message.error ~internal:true
|
||||||
"Could not convert value of type %a@ to@ runtime:@ %a" (Print.typ ctx) ty
|
"Could not convert value of type %a@ to@ runtime:@ %a" (Print.typ ctx) ty
|
||||||
|
Loading…
Reference in New Issue
Block a user