From 1ef9d745ff24a4c2ac06bc49c16f637b2e2179ed Mon Sep 17 00:00:00 2001 From: subkey <2822448396@qq.com> Date: Sun, 31 Mar 2024 01:58:35 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E--ast=E5=8F=82?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index dfbe426..9201338 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,6 +13,15 @@ mod utils; mod c; mod native; +/// 全局选项 +struct GlobalOptions { + /// --ast + print_ast: bool +} +static mut GLOBAL_OPTIONS:GlobalOptions = GlobalOptions { + print_ast: false +}; + /// 标志目前走到的行号 static mut LINE:usize = 1; /// 用于标记报错文件 @@ -50,6 +59,7 @@ fn main()-> ExitCode { // linux macos支持 // 脚本打包exe + intern::init(); // 获取路径 @@ -61,6 +71,13 @@ fn main()-> ExitCode { panic!("Key暂时不支持REPL, 请先传入一个文件路径运行") }; // let path = "D:\\code\\rs\\key-lang\\samples\\helloworld.ks"; + while let Some(n) = args.next() { + let opts = unsafe {&mut GLOBAL_OPTIONS}; + match &*n { + "--ast"=> opts.print_ast = true, + _=>() + } + } // 自定义报错 unsafe {PLACE = path.clone()} @@ -79,7 +96,8 @@ fn main()-> ExitCode { // 运行并返回 let scanned = scan::scan(&fs::read(&path).unwrap_or_else(|e| panic!("无法读取'{}': {}", path, e))); - println!("{scanned:?}"); + if unsafe{GLOBAL_OPTIONS.print_ast} {println!("{scanned:?}")} + let exit = runtime::run(&scanned); if let primitive::litr::Litr::Int(code) = exit.returned { return ExitCode::from(code as u8);