@@ -136,12 +136,13 @@ where
136136 trace ! ( "Invoking AML method: {}" , path) ;
137137
138138 let object = self . namespace . lock ( ) . get ( path. clone ( ) ) ?. clone ( ) ;
139- match object. typ ( ) {
140- ObjectType :: Method => {
139+ match & * object {
140+ Object :: Method { .. } => {
141141 self . namespace . lock ( ) . add_level ( path. clone ( ) , NamespaceLevelKind :: MethodLocals ) ?;
142142 let context = MethodContext :: new_from_method ( object, args, path) ?;
143143 self . do_execute_method ( context)
144144 }
145+ Object :: NativeMethod ( f) => f ( & args) ,
145146 _ => Ok ( object) ,
146147 }
147148 }
@@ -644,13 +645,22 @@ where
644645 } )
645646 . collect ( ) ;
646647
647- self . namespace . lock ( ) . add_level ( method_scope. clone ( ) , NamespaceLevelKind :: MethodLocals ) ?;
648+ if let Object :: Method { .. } = * * method {
649+ self . namespace
650+ . lock ( )
651+ . add_level ( method_scope. clone ( ) , NamespaceLevelKind :: MethodLocals ) ?;
648652
649- let new_context =
650- MethodContext :: new_from_method ( method. clone ( ) , args, method_scope. clone ( ) ) ?;
651- let old_context = mem:: replace ( & mut context, new_context) ;
652- self . context_stack . lock ( ) . push ( old_context) ;
653- context. retire_op ( op) ;
653+ let new_context =
654+ MethodContext :: new_from_method ( method. clone ( ) , args, method_scope. clone ( ) ) ?;
655+ let old_context = mem:: replace ( & mut context, new_context) ;
656+ self . context_stack . lock ( ) . push ( old_context) ;
657+ context. retire_op ( op) ;
658+ } else if let Object :: NativeMethod { ref f, .. } = * * method {
659+ let result = f ( & args) ?;
660+ context. contribute_arg ( Argument :: Object ( result) ) ;
661+ } else {
662+ panic ! ( ) ;
663+ }
654664 }
655665 Opcode :: Return => {
656666 let [ Argument :: Object ( object) ] = & op. arguments [ ..] else { panic ! ( ) } ;
@@ -1207,7 +1217,8 @@ where
12071217 let object = self . namespace . lock ( ) . search ( & name, & context. current_scope ) ;
12081218 match object {
12091219 Ok ( ( resolved_name, object) ) => {
1210- if let Object :: Method { flags, .. } = * object {
1220+ if let Object :: Method { flags, .. } | Object :: NativeMethod { flags, .. } = * object
1221+ {
12111222 context. start_in_flight_op ( OpInFlight :: new_with (
12121223 Opcode :: InternalMethodCall ,
12131224 vec ! [ Argument :: Object ( object) , Argument :: Namestring ( resolved_name) ] ,
@@ -1762,7 +1773,7 @@ where
17621773 Object :: Event => "[Event]" . to_string ( ) ,
17631774 Object :: FieldUnit ( _) => "[Field]" . to_string ( ) ,
17641775 Object :: Integer ( value) => value. to_string ( ) ,
1765- Object :: Method { .. } => "[Control Method]" . to_string ( ) ,
1776+ Object :: Method { .. } | Object :: NativeMethod ( _ ) => "[Control Method]" . to_string ( ) ,
17661777 Object :: Mutex { .. } => "[Mutex]" . to_string ( ) ,
17671778 Object :: Reference { inner, .. } => resolve_as_string ( & * ( inner. clone ( ) . unwrap_reference ( ) ) ) ,
17681779 Object :: OpRegion ( _) => "[Operation Region]" . to_string ( ) ,
0 commit comments