1717
1818use anyhow:: { Result , anyhow} ;
1919use async_channel:: Sender ;
20- use endbasic_core:: exec:: Signal ;
21- use endbasic_std:: console:: { Console , ConsoleSpec } ;
22- use endbasic_std:: gpio;
23- use endbasic_std:: storage:: Storage ;
20+ #[ cfg( not( feature = "crossterm" ) ) ]
21+ use async_channel:: Sender ;
22+ use endbasic_client:: CloudService ;
23+ use endbasic_core2:: { Compiler , StopReason , Vm } ;
24+ use endbasic_repl:: demos:: DemoDriveFactory ;
25+ #[ cfg( not( feature = "crossterm" ) ) ]
26+ use endbasic_std:: Signal ;
27+ use endbasic_std:: console:: Console ;
28+ #[ cfg( feature = "rpi" ) ]
29+ use endbasic_std:: console:: ConsoleSpec ;
30+ #[ cfg( not( feature = "sdl" ) ) ]
31+ use endbasic_std:: console:: ConsoleSpec ;
32+ use endbasic_std:: storage:: { DirectoryDriveFactory , Storage } ;
33+ use endbasic_std:: { InteractiveMachineBuilder , Machine , MachineBuilder , Signal , gpio} ;
2434use getoptsargs:: prelude:: * ;
2535use std:: cell:: RefCell ;
36+ use std:: collections:: HashMap ;
2637use std:: fs:: File ;
2738use std:: io;
2839use std:: path:: Path ;
@@ -100,20 +111,20 @@ fn setup_gpio_pins(spec: Option<&str>) -> Result<Rc<RefCell<dyn gpio::Pins>>> {
100111fn new_machine_builder (
101112 console_spec : Option < & str > ,
102113 gpio_pins_spec : Option < & str > ,
103- ) -> Result < endbasic_std :: MachineBuilder > {
114+ ) -> Result < MachineBuilder > {
104115 let signals_chan = async_channel:: unbounded ( ) ;
105- let mut builder = endbasic_std :: MachineBuilder :: default ( ) ;
116+ let mut builder = MachineBuilder :: default ( ) ;
106117 builder = builder. with_console ( setup_console ( console_spec, signals_chan. 0 . clone ( ) ) ?) ;
118+ /*
107119 builder = builder.with_signals_chan(signals_chan);
108120 builder = builder.with_gpio_pins(setup_gpio_pins(gpio_pins_spec)?);
121+ */
109122 Ok ( builder)
110123}
111124
112125/// Turns a regular machine builder into an interactive builder ensuring common features for all
113126/// callers.
114- fn make_interactive (
115- builder : endbasic_std:: MachineBuilder ,
116- ) -> endbasic_std:: InteractiveMachineBuilder {
127+ fn make_interactive ( builder : MachineBuilder ) -> InteractiveMachineBuilder {
117128 builder
118129 . make_interactive ( )
119130 . with_program ( Rc :: from ( RefCell :: from ( endbasic_repl:: editor:: Editor :: default ( ) ) ) )
@@ -124,16 +135,16 @@ fn make_interactive(
124135///
125136/// `service_url` is the base URL of the cloud service.
126137fn finish_interactive_build (
127- mut builder : endbasic_std :: InteractiveMachineBuilder ,
138+ mut builder : InteractiveMachineBuilder ,
128139 service_url : & str ,
129- ) -> Result < endbasic_core :: exec :: Machine > {
140+ ) -> Result < Machine > {
130141 let console = builder. get_console ( ) ;
131142 let storage = builder. get_storage ( ) ;
132143
133- let mut machine = builder. build ( ) ? ;
144+ let mut machine = builder. build ( ) ;
134145
135- let service = Rc :: from ( RefCell :: from ( endbasic_client :: CloudService :: new ( service_url) ?) ) ;
136- endbasic_client:: add_all ( & mut machine, service, console, storage, "https://repl.endbasic.dev/" ) ;
146+ let service = Rc :: from ( RefCell :: from ( CloudService :: new ( service_url) ?) ) ;
147+ // endbasic_client::add_all(&mut machine, service, console, storage, "https://repl.endbasic.dev/");
137148
138149 Ok ( machine)
139150}
@@ -244,12 +255,9 @@ fn setup_console(
244255/// This instantiates non-optional drives, such as `MEMORY:` and `DEMOS:`, maps `LOCAL` the
245256/// location given in `local_drive_spec`.
246257pub fn setup_storage ( storage : & mut Storage , local_drive_spec : & str ) -> io:: Result < ( ) > {
247- storage. register_scheme ( "demos" , Box :: from ( endbasic_repl :: demos :: DemoDriveFactory :: default ( ) ) ) ;
258+ storage. register_scheme ( "demos" , Box :: from ( DemoDriveFactory :: default ( ) ) ) ;
248259 storage. mount ( "demos" , "demos://" ) . expect ( "Demos drive shouldn't fail to mount" ) ;
249- storage. register_scheme (
250- "file" ,
251- Box :: from ( endbasic_std:: storage:: DirectoryDriveFactory :: default ( ) ) ,
252- ) ;
260+ storage. register_scheme ( "file" , Box :: from ( DirectoryDriveFactory :: default ( ) ) ) ;
253261 storage. mount ( "local" , local_drive_spec) ?;
254262 storage. cd ( "local:" ) . expect ( "Local drive was just registered" ) ;
255263 Ok ( ( ) )
@@ -286,9 +294,12 @@ async fn run_script<P: AsRef<Path>>(
286294 gpio_pins_spec : Option < & str > ,
287295) -> Result < i32 > {
288296 let builder = new_machine_builder ( console_spec, gpio_pins_spec) ?;
289- let mut machine = builder. build ( ) ? ;
297+ let mut machine = builder. build ( ) ;
290298 let mut input = File :: open ( path) ?;
291- Ok ( machine. exec ( & mut input) . await ?. as_exit_code ( ) )
299+
300+ machine. compile ( & mut input) ?;
301+ machine. exec ( ) . await ?;
302+ Ok ( 0 )
292303}
293304
294305/// Executes the `path` program in a fresh machine allowing any interactive-only calls.
@@ -331,7 +342,8 @@ async fn run_interactive(
331342 }
332343 None => {
333344 let mut input = File :: open ( path) ?;
334- Ok ( machine. exec ( & mut input) . await ?. as_exit_code ( ) )
345+ machine. compile ( & mut input) ?;
346+ Ok ( machine. exec ( ) . await ?. unwrap_or ( 0 ) )
335347 }
336348 }
337349}
0 commit comments