@@ -74,54 +74,33 @@ fn main() -> hyperlight_host::Result<()> {
7474#![no_main]
7575extern crate alloc;
7676
77- use alloc :: string :: ToString ;
7877use alloc :: vec :: Vec ;
78+ use alloc :: string :: String ;
7979use hyperlight_common :: flatbuffer_wrappers :: function_call :: FunctionCall ;
80- use hyperlight_common :: flatbuffer_wrappers :: function_types :: {
81- ParameterType , ParameterValue , ReturnType ,
82- };
8380use hyperlight_common :: flatbuffer_wrappers :: guest_error :: ErrorCode ;
84- use hyperlight_common :: flatbuffer_wrappers :: util :: get_flatbuffer_result;
85-
86- use hyperlight_guest :: error :: {HyperlightGuestError , Result };
87- use hyperlight_guest_bin :: guest_function :: definition :: GuestFunctionDefinition ;
88- use hyperlight_guest_bin :: guest_function :: register :: register_function;
89- use hyperlight_guest_bin :: host_comm :: call_host_function;
90-
91- fn print_output (function_call : & FunctionCall ) -> Result <Vec <u8 >> {
92- if let ParameterValue :: String (message ) = function_call . parameters. clone (). unwrap ()[0 ]. clone () {
93- let result = call_host_function :: <i32 >(
94- " HostPrint" ,
95- Some (Vec :: from (& [ParameterValue :: String (message . to_string ())])),
96- ReturnType :: Int ,
97- )? ;
98- Ok (get_flatbuffer_result (result ))
99- } else {
100- Err (HyperlightGuestError :: new (
101- ErrorCode :: GuestFunctionParameterTypeMismatch ,
102- " Invalid parameters passed to simple_print_output" . to_string (),
103- ))
104- }
81+
82+ use hyperlight_guest :: bail;
83+ use hyperlight_guest :: error :: Result ;
84+ use hyperlight_guest_bin :: {guest_function, host_function};
85+
86+ #[host_function(" HostPrint" )]
87+ fn host_print (message : String ) -> Result <i32 >;
88+
89+ #[guest_function(" PrintOutput" )]
90+ fn print_output (message : String ) -> Result <i32 > {
91+ let result = host_print (message )? ;
92+ Ok (result )
10593}
10694
10795#[no_mangle]
10896pub extern " C" fn hyperlight_main () {
109- let print_output_def = GuestFunctionDefinition :: new (
110- " PrintOutput" . to_string (),
111- Vec :: from (& [ParameterType :: String ]),
112- ReturnType :: Int ,
113- print_output as usize ,
114- );
115- register_function (print_output_def );
97+ // any initialization code goes here
11698}
11799
118100#[no_mangle]
119101pub fn guest_dispatch_function (function_call : FunctionCall ) -> Result <Vec <u8 >> {
120- let function_name = function_call . function_name. clone ();
121- return Err (HyperlightGuestError :: new (
122- ErrorCode :: GuestFunctionNotFound ,
123- function_name ,
124- ));
102+ let function_name = function_call . function_name;
103+ bail! (ErrorCode :: GuestFunctionNotFound => " {function_name}" );
125104}
126105```
127106
0 commit comments