@@ -176,6 +176,12 @@ pub enum FunctionBody {
176176 cache : RefCell < HashMap < u64 , Value > > ,
177177 function : Box < FunctionBody > ,
178178 } ,
179+ /// Opaque foreign function that cannot be called by the interpreter.
180+ /// Used to round-trip VM functions through interpreter values.
181+ Opaque {
182+ data : Rc < dyn std:: any:: Any > ,
183+ static_type : StaticType ,
184+ } ,
179185}
180186
181187impl FunctionBody {
@@ -186,6 +192,7 @@ impl FunctionBody {
186192 Self :: NumericBinaryOp { .. } => Some ( 2 ) ,
187193 Self :: GenericFunction { type_signature, .. } => type_signature. arity ( ) ,
188194 Self :: Memoized { function, .. } => function. arity ( ) ,
195+ Self :: Opaque { .. } => None ,
189196 }
190197 }
191198
@@ -213,6 +220,7 @@ impl FunctionBody {
213220 Parameter :: new( "right" , StaticType :: Number ) ,
214221 ] ) ,
215222 Self :: GenericFunction { type_signature, .. } => type_signature. clone ( ) ,
223+ Self :: Opaque { .. } => TypeSignature :: Variadic ,
216224 }
217225 }
218226
@@ -223,6 +231,7 @@ impl FunctionBody {
223231 }
224232 Self :: NumericUnaryOp { .. } | Self :: NumericBinaryOp { .. } => & StaticType :: Number ,
225233 Self :: Memoized { function, .. } => function. return_type ( ) ,
234+ Self :: Opaque { static_type, .. } => static_type,
226235 }
227236 }
228237 pub fn call ( & self , args : & mut [ Value ] , env : & Rc < RefCell < Environment > > ) -> EvaluationResult {
@@ -277,6 +286,13 @@ impl FunctionBody {
277286 . into ( ) ) ,
278287 } ,
279288 Self :: GenericFunction { function, .. } => function ( args, env) ,
289+ Self :: Opaque { .. } => {
290+ Err ( FunctionCallError :: ArgumentCountError {
291+ expected : 0 ,
292+ actual : args. len ( ) ,
293+ }
294+ . into ( ) )
295+ }
280296 Self :: Memoized { cache, function } => {
281297 let mut hasher = DefaultHasher :: default ( ) ;
282298 for arg in & * args {
0 commit comments