@@ -9,6 +9,7 @@ use crate::runtime::context::SyncTable;
99use crate :: runtime:: vm_operation:: * ;
1010use crate :: runtime:: vm_table_opt:: * ;
1111use crate :: runtime:: { MetadataUnit , RuntimeError , SharedGlobals , SharedSync } ;
12+ use crate :: runtime:: RuntimeError :: NoSuchFunctionException ;
1213
1314pub struct StackFrame < ' a > {
1415 pc : usize ,
@@ -388,10 +389,9 @@ fn print_and_return(executor: &Executor, failed_status: Option<RuntimeError>) ->
388389 Value :: Null
389390}
390391
391- fn print_error ( executor : & Executor , path : SmolStr ) {
392+ fn print_error ( executor : & Executor , error : RuntimeError ) {
392393 eprintln ! (
393- "RuntimeError: {:?}" ,
394- RuntimeError :: NoSuchFunctionException ( path)
394+ "RuntimeError: {error:?}" ,
395395 ) ;
396396 for frame in & executor. call_stack {
397397 let name = frame. get_frame_name ( ) ;
@@ -456,24 +456,33 @@ pub fn call_function(
456456 argument. push ( stack_frame. pop_op_stack ( ) ) ;
457457 }
458458
459- if let Ok ( lib ) = find_library ( file, |f| {
459+ match find_library ( file, |f| {
460460 if let Some ( lib) = f
461461 && let Some ( func) = lib. find_func ( & SmolStr :: new ( func) )
462462 {
463- ( func. func ) ( & argument) . map_or ( Err ( ParserError :: Empty ) , Ok )
463+ match ( func. func ) ( & argument) {
464+ Err ( error) => Err ( ParserError :: RuntimeError ( error) ) ,
465+ Ok ( ok ) => Ok ( ok) ,
466+ }
464467 } else {
465- Err ( ParserError :: Empty )
468+ Err ( ParserError :: RuntimeError ( NoSuchFunctionException ( path . clone ( ) ) ) )
466469 }
467470 } ) {
468- let mut frame = executor. call_stack . pop ( ) . unwrap ( ) ;
469- if let Some ( ( unit_index, func_index) ) = frame. take_sync_lock ( ) {
470- sync_table. unlock ( unit_index, func_index) ;
471+ Ok ( lib) => {
472+ let mut frame = executor. call_stack . pop ( ) . unwrap ( ) ;
473+ if let Some ( ( unit_index, func_index) ) = frame. take_sync_lock ( ) {
474+ sync_table. unlock ( unit_index, func_index) ;
475+ }
476+ executor. call_stack . last_mut ( ) . unwrap ( ) . push_op_stack ( lib) ;
477+ executor. frame_index -= 1 ;
478+ } ,
479+ Err ( error) => {
480+ let ParserError :: RuntimeError ( error) = error else {
481+ unreachable ! ( )
482+ } ;
483+ print_error ( & executor, error) ;
484+ break ;
471485 }
472- executor. call_stack . last_mut ( ) . unwrap ( ) . push_op_stack ( lib) ;
473- executor. frame_index -= 1 ;
474- } else {
475- print_error ( & executor, path) ;
476- break ;
477486 }
478487 } else {
479488 match run_code ( units, stack_frame, & globals, & call_cache, & sync_table) {
0 commit comments