@@ -11,31 +11,32 @@ use std::io;
11
11
pub enum InterpreterError {
12
12
Io ( io:: Error ) ,
13
13
Unmarshal ( marshal:: decode:: UnmarshalError ) ,
14
+ Processor ( processor:: ProcessorError ) ,
14
15
}
15
16
16
17
impl fmt:: Display for InterpreterError {
17
18
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
18
19
match * self {
19
- InterpreterError :: Io ( ref e) => write ! ( f, "I/O error:" ) . and_then ( |_| e. fmt ( f) ) ,
20
- InterpreterError :: Unmarshal ( ref e) => write ! ( f, "Unmarshal error:" ) . and_then ( |_| e. fmt ( f) ) ,
20
+ InterpreterError :: Io ( ref e) => write ! ( f, "I/O error: " ) . and_then ( |_| e. fmt ( f) ) ,
21
+ InterpreterError :: Unmarshal ( ref e) => write ! ( f, "Unmarshal error: " ) . and_then ( |_| e. fmt ( f) ) ,
22
+ InterpreterError :: Processor ( ref e) => write ! ( f, "Processor error: " ) . and_then ( |_| e. fmt ( f) ) ,
21
23
}
22
24
}
23
25
}
24
26
25
- pub fn run_module < R : io:: Read , EP : sandbox:: EnvProxy > ( reader : & mut R , envproxy : & mut EP ) -> Result < ( ) , InterpreterError > {
27
+ pub fn run_module < R : io:: Read , EP : sandbox:: EnvProxy > ( reader : & mut R , envproxy : & mut EP ) -> Result < objects :: ObjectRef , InterpreterError > {
26
28
let mut buf = [ 0 ; 12 ] ;
27
29
try!( reader. read_exact ( & mut buf) . map_err ( InterpreterError :: Io ) ) ;
28
30
// TODO: do something with the content of the buffer
29
31
let mut store = objects:: ObjectStore :: new ( ) ;
30
32
let module = try!( marshal:: read_object ( reader, & mut store) . map_err ( InterpreterError :: Unmarshal ) ) ;
31
- processor:: run_code_object ( envproxy, & mut store, module) ;
32
- Ok ( ( ) )
33
+ processor:: run_code_object ( envproxy, & mut store, module) . map_err ( InterpreterError :: Processor )
33
34
}
34
35
35
36
#[ test]
36
37
fn test_hello_world ( ) {
37
38
let mut reader: & [ u8 ] = b"\xee \x0c \r \n \x15 j\n W\x15 \x00 \x00 \x00 \xe3 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x02 \x00 \x00 \x00 @\x00 \x00 \x00 s\x0e \x00 \x00 \x00 e\x00 \x00 d\x00 \x00 \x83 \x01 \x00 \x01 d\x01 \x00 S)\x02 z\x0b Hello worldN)\x01 \xda \x05 print\xa9 \x00 r\x02 \x00 \x00 \x00 r\x02 \x00 \x00 \x00 \xfa \x0b /tmp/foo.py\xda \x08 <module>\x01 \x00 \x00 \x00 s\x00 \x00 \x00 \x00 " ;
38
39
let mut envproxy = sandbox:: MockEnvProxy :: new ( ) ;
39
- run_module ( & mut reader, & mut envproxy) . unwrap ( ) ;
40
+ println ! ( "{:?}" , run_module( & mut reader, & mut envproxy) . unwrap( ) ) ;
40
41
assert_eq ! ( * envproxy. stdout_content. lock( ) . unwrap( ) , b"Hello world\n " ) ;
41
42
}
0 commit comments