@@ -13,8 +13,8 @@ mod runtime {
1313
1414 const SZ : usize = 1 << 20 ;
1515 static mut SRC : [ u8 ; SZ ] = [ 0 ; SZ ] ;
16- static mut OUT : [ u8 ; SZ ] = [ 0 ; SZ ] ;
17- static mut INP : [ u8 ; SZ ] = [ 0 ; SZ ] ;
16+ static mut OUT : [ u8 ; SZ ] = [ 0 ; SZ ] ;
17+ static mut INP : [ u8 ; SZ ] = [ 0 ; SZ ] ;
1818 static mut INP_LEN : usize = 0 ;
1919
2020 #[ unsafe( no_mangle) ]
@@ -50,15 +50,15 @@ mod runtime {
5050 s
5151 } else {
5252 crate :: modules:: vm:: optimizer:: constant_fold ( & mut chunk) ;
53- let mut vm = VM :: with_limits ( & chunk, Limits :: sandbox ( ) ) ;
54- // Feed input buffer from host
55- let inp_len = unsafe { INP_LEN } ;
56- if inp_len > 0 {
57- let inp = unsafe { core:: str:: from_utf8_unchecked (
58- core:: slice:: from_raw_parts ( core:: ptr:: addr_of!( INP ) as * const u8 , inp_len)
59- ) } ;
60- vm. input_buffer = inp. split ( '\n' ) . map ( |s| alloc:: string:: String :: from ( s ) ) . collect ( ) ;
61- unsafe { INP_LEN = 0 ; }
53+ let mut vm = VM :: with_limits ( & chunk, Limits :: sandbox ( ) ) ;
54+ // Feed input buffer from host
55+ let inp_len = unsafe { INP_LEN } ;
56+ if inp_len > 0 {
57+ let inp = unsafe { core:: str:: from_utf8_unchecked (
58+ core:: slice:: from_raw_parts ( core:: ptr:: addr_of!( INP ) as * const u8 , inp_len)
59+ ) } ;
60+ vm. input_buffer = inp. split ( '\n' ) . map ( alloc:: string:: String :: from) . collect ( ) ;
61+ unsafe { INP_LEN = 0 ; }
6262 }
6363 match vm. run ( ) {
6464 Ok ( _) => vm. output . join ( "\n " ) ,
@@ -106,8 +106,8 @@ mod tests {
106106 include_str ! ( "../tests/cases/vm.json" )
107107 ) . expect ( "invalid JSON" ) ;
108108
109- for case in cases {
110- // WASM: input tests should produce a RuntimeError
109+ for case in cases {
110+ // WASM: input tests should produce a RuntimeError
111111 let expect_input_error = case. input . len ( ) > 0 && cfg ! ( target_arch = "wasm32" ) ;
112112 let ( chunk, errs) = Parser :: new ( & case. src , lexer ( & case. src ) ) . parse ( ) ;
113113 assert ! ( errs. is_empty( ) , "parse error on {:?}: {:?}" , case. src, errs. iter( ) . map( |e| & e. msg) . collect:: <Vec <_>>( ) ) ;
0 commit comments