let usage = {|coollang toolchain 사용법: cool check ... 타입/effect/capability 검사 (fast path) cool run typed IR 인터프리터로 실행 cool tokens 토큰 덤프 (렉서 디버깅) cool ast 구문 트리 덤프 (파서 디버깅) cool version 버전 출력 |} let report_errors errors = List.iter (fun e -> prerr_endline (Coollang.Driver.string_of_error e)) errors; 1 let report = function Ok () -> 0 | Error errors -> report_errors errors let dump_tokens file = match Coollang.Driver.tokens file with | Error errors -> report_errors errors | Ok tokens -> List.iter (fun t -> print_endline (Coollang.Token.show t)) tokens; 0 let dump_ast file = match Coollang.Driver.ast file with | Error errors -> report_errors errors | Ok m -> List.iter (fun it -> print_endline (Coollang.Ast.show_item it)) m.Coollang.Ast.items; 0 let () = let argv = Array.to_list Sys.argv in let code = match List.tl argv with | "check" :: files -> report (Coollang.Driver.check files) | [ "run"; file ] -> report (Coollang.Driver.run file) | [ "tokens"; file ] -> dump_tokens file | [ "ast"; file ] -> dump_ast file | [ "version" ] -> print_endline Coollang.Version.string; 0 | [] | [ "help" ] | [ "--help" ] | [ "-h" ] -> print_string usage; 0 | cmd :: _ -> Printf.eprintf "알 수 없는 명령: %s\n\n%s" cmd usage; 2 in exit code