File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ use std::process::ExitCode;
33use crate :: cli:: logging:: dump_failure;
44
55pub mod run;
6+ pub mod expression;
67pub mod check;
78pub mod transpile;
89pub mod logging;
@@ -14,6 +15,7 @@ pub fn make_command() -> Command {
1415 . arg_required_else_help ( true )
1516 . allow_external_subcommands ( true )
1617 . subcommand ( run:: make_command ( ) )
18+ . subcommand ( expression:: make_command ( ) )
1719 . subcommand ( check:: make_command ( ) )
1820 . subcommand ( transpile:: make_command ( ) )
1921}
@@ -23,6 +25,7 @@ pub fn run_command() -> ExitCode {
2325
2426 let result = match matches. subcommand ( ) {
2527 Some ( ( "run" , sub_matches) ) => run:: run ( sub_matches) ,
28+ Some ( ( "expression" , sub_matches) ) => expression:: run ( sub_matches) ,
2629 Some ( ( "check" , sub_matches) ) => check:: run ( sub_matches) ,
2730 Some ( ( "transpile" , sub_matches) ) => transpile:: run ( sub_matches) ,
2831 _ => panic ! ( "Unsupported action." ) ,
Original file line number Diff line number Diff line change 1+ use std:: path:: PathBuf ;
2+ use std:: process:: ExitCode ;
3+
4+ use clap:: { arg, ArgMatches , Command } ;
5+
6+ use crate :: error:: RResult ;
7+ use crate :: { interpreter, parser} ;
8+ use crate :: interpreter:: runtime:: Runtime ;
9+ use crate :: program:: functions:: FunctionInterface ;
10+ use crate :: program:: module:: { module_name, ModuleName } ;
11+ use crate :: program:: types:: TypeProto ;
12+
13+ pub fn make_command ( ) -> Command {
14+ Command :: new ( "expression" )
15+ . about ( "Run an expression using the interpreter." )
16+ . arg_required_else_help ( true )
17+ . arg ( arg ! ( <EXPRESSION > "expression to run" ) . value_parser ( clap:: value_parser!( String ) ) )
18+ }
19+
20+ pub fn run ( args : & ArgMatches ) -> RResult < ExitCode > {
21+ let expression = args. get_one :: < String > ( "EXPRESSION" ) . unwrap ( ) ;
22+ let full_expression = format ! ( "use!(module!(\" common\" )); def main! :: write_line({});" , expression) ;
23+
24+ let mut runtime = Runtime :: new ( ) ?;
25+ runtime. add_common_repository ( ) ;
26+
27+ let module = runtime. load_text_as_module ( & full_expression, vec ! [ "dynamic" . to_string( ) ] ) ?;
28+
29+ interpreter:: run:: main ( & module, & mut runtime) ?;
30+
31+ Ok ( ExitCode :: SUCCESS )
32+ }
You can’t perform that action at this time.
0 commit comments