11use std:: env;
22use std:: fs;
3+ use std:: path:: Path ;
34use std:: process:: ExitCode ;
45
56fn main ( ) -> ExitCode {
@@ -64,8 +65,16 @@ fn main() -> ExitCode {
6465 } )
6566 } ) {
6667 Ok ( program) => {
68+ let output_path = match axiom_native:: vm:: write_artifact_file ( Path :: new ( & path) , & program) {
69+ Ok ( path) => path,
70+ Err ( error) => {
71+ eprintln ! ( "error: {}" , error. message) ;
72+ return ExitCode :: from ( 1 ) ;
73+ }
74+ } ;
6775 let artifact = axiom_native:: vm:: build_artifact ( & program) ;
6876 println ! ( "build ok: {path}" ) ;
77+ println ! ( "artifact file: {}" , output_path. display( ) ) ;
6978 println ! ( "artifact bytes: {}" , artifact. len( ) ) ;
7079 ExitCode :: SUCCESS
7180 }
@@ -77,33 +86,60 @@ fn main() -> ExitCode {
7786 ExitCode :: from ( 1 )
7887 }
7988 } ,
80- "run" => match axiom_native:: parser:: parse ( & source) . and_then ( |program| {
81- axiom_native:: semantic:: analyze ( & program)
82- . map ( |_| program)
83- . map_err ( |error| axiom_native:: parser:: ParseError {
84- message : error. message ,
85- line : 0 ,
86- column : 0 ,
87- } )
88- } ) {
89- Ok ( program) => match axiom_native:: vm:: execute_program ( & program) {
90- Ok ( output) => {
91- print ! ( "{output}" ) ;
92- ExitCode :: SUCCESS
89+ "run" => {
90+ if Path :: new ( & path) . extension ( ) . and_then ( |ext| ext. to_str ( ) ) == Some ( "axm" ) {
91+ match fs:: read_to_string ( & path) {
92+ Ok ( encoded) => match axiom_native:: vm:: Artifact :: deserialize ( & encoded) {
93+ Ok ( artifact) => match axiom_native:: vm:: execute_artifact ( & artifact) {
94+ Ok ( output) => {
95+ print ! ( "{output}" ) ;
96+ ExitCode :: SUCCESS
97+ }
98+ Err ( error) => {
99+ eprintln ! ( "error: {}" , error. message) ;
100+ ExitCode :: from ( 1 )
101+ }
102+ } ,
103+ Err ( error) => {
104+ eprintln ! ( "error: {}" , error. message) ;
105+ ExitCode :: from ( 1 )
106+ }
107+ } ,
108+ Err ( error) => {
109+ eprintln ! ( "error: cannot read {path}: {error}" ) ;
110+ ExitCode :: from ( 1 )
111+ }
93112 }
94- Err ( error) => {
95- eprintln ! ( "error: {}" , error. message) ;
96- ExitCode :: from ( 1 )
113+ } else {
114+ match axiom_native:: parser:: parse ( & source) . and_then ( |program| {
115+ axiom_native:: semantic:: analyze ( & program)
116+ . map ( |_| program)
117+ . map_err ( |error| axiom_native:: parser:: ParseError {
118+ message : error. message ,
119+ line : 0 ,
120+ column : 0 ,
121+ } )
122+ } ) {
123+ Ok ( program) => match axiom_native:: vm:: execute_program ( & program) {
124+ Ok ( output) => {
125+ print ! ( "{output}" ) ;
126+ ExitCode :: SUCCESS
127+ }
128+ Err ( error) => {
129+ eprintln ! ( "error: {}" , error. message) ;
130+ ExitCode :: from ( 1 )
131+ }
132+ } ,
133+ Err ( error) => {
134+ eprintln ! (
135+ "error: {} at {}:{}" ,
136+ error. message, error. line, error. column
137+ ) ;
138+ ExitCode :: from ( 1 )
139+ }
97140 }
98- } ,
99- Err ( error) => {
100- eprintln ! (
101- "error: {} at {}:{}" ,
102- error. message, error. line, error. column
103- ) ;
104- ExitCode :: from ( 1 )
105141 }
106- } ,
142+ }
107143 _ => {
108144 eprintln ! ( "error: unknown command '{command}'" ) ;
109145 print_help ( ) ;
0 commit comments