1단계 최소 IO: File(읽기), Args capability. 권한의 출처는 여전히 런타임 하나이고, IO 오류는 Result[a, String]이다 — 런타임이 사용자 정의 enum을 만들 수 없고, 만들 수 있게 하면 런타임이 프로그램의 타입을 알아야 한다. 2단계 std 확장: fold, filter, push, concat, reverse, is_empty, String.split/trim/starts_with/contains, Int.parse. 3단계 samples/app: 설정 파서 + 리포트 도구, 2모듈 304줄. 검사기를 시험 하려고 쓴 것이 아니라 일을 하려고 쓴 첫 프로그램이다. 산출물은 프로그램이 아니라 docs/friction.md다. 요약: - 되돌리기 비싼 결정은 하나도 후회되지 않았다. capability 전달, effect 명시, 실패를 버릴 수 없음, 소진적 match — 300줄 내내 거추장스럽지 않았고 소진성은 실제로 실수를 잡았다(Value에 경우 하나 추가하니 고칠 자리 넷을 정확히 짚었다). - 불편은 전부 되돌리기 싼 것들이었다. 리스트 n번째 접근이 없어 fold로 우회(40줄), else if가 없어 3~4단 중첩, String.concat이 2항이라 중첩 지옥. 304줄 중 70줄쯤이 이 셋 때문에 존재한다. v0의 질문은 "되돌리기 비싼 결정이 옳은가"였고 답은 그렇다이다. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019ZVDeU6KLuUVL3gs18Hm3E
102 lines
3.3 KiB
OCaml
102 lines
3.3 KiB
OCaml
let usage =
|
|
{|coollang toolchain
|
|
|
|
사용법:
|
|
coolc check <file.cool>... 타입/effect/capability 검사 (import를 따라 모듈 그래프 전체)
|
|
coolc iface <file.cool> interface 표면과 해시 출력
|
|
coolc run <file.cool> [인자...] typed IR 인터프리터로 실행
|
|
coolc tokens <file.cool> 토큰 덤프 (렉서 디버깅)
|
|
coolc ast <file.cool> 구문 트리 덤프 (파서 디버깅)
|
|
coolc deps <file.cool> 외부 참조 목록 (모듈의 의존 표면)
|
|
coolc 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
|
|
|
|
(* import를 따라 모듈 그래프를 로드하고 전부 검사한다. root는 첫 파일의 디렉터리다. *)
|
|
let check_graph files =
|
|
match files with
|
|
| [] ->
|
|
prerr_endline "검사할 파일이 없습니다";
|
|
2
|
|
| first :: _ ->
|
|
let st = Coollang.Session.create ~root:(Filename.dirname first) () in
|
|
List.iter (fun f -> Coollang.Session.load st f) files;
|
|
let errors = Coollang.Session.errors st in
|
|
List.iter
|
|
(fun e -> prerr_endline (Coollang.Session.string_of_error e))
|
|
errors;
|
|
if errors = [] then 0 else 1
|
|
|
|
let dump_iface file =
|
|
let st = Coollang.Session.create ~root:(Filename.dirname file) () in
|
|
Coollang.Session.load st file;
|
|
match Coollang.Session.find st file with
|
|
| None -> 1
|
|
| Some e ->
|
|
Printf.printf "hash %s\n" e.iface.Coollang.Iface.hash;
|
|
List.iter
|
|
(fun it -> print_endline (Coollang.Ast.show_item it))
|
|
e.iface.Coollang.Iface.items;
|
|
0
|
|
|
|
let dump_deps file =
|
|
match Coollang.Driver.resolve file with
|
|
| Error errors -> report_errors errors
|
|
| Ok info ->
|
|
List.iter
|
|
(fun (name, (p : Coollang.Token.pos)) ->
|
|
Printf.printf "%d:%d %s\n" p.line p.col name)
|
|
info.Coollang.Resolve.externals;
|
|
0
|
|
|
|
let () =
|
|
let argv = Array.to_list Sys.argv in
|
|
let code =
|
|
match List.tl argv with
|
|
| "check" :: files -> check_graph files
|
|
| [ "iface"; file ] -> dump_iface file
|
|
| "run" :: file :: args -> (
|
|
let st = Coollang.Session.create ~root:(Filename.dirname file) () in
|
|
match Coollang.Session.run ~args st file with
|
|
| Ok out ->
|
|
print_string out;
|
|
0
|
|
| Error e ->
|
|
prerr_endline (Coollang.Session.string_of_error e);
|
|
1)
|
|
| [ "tokens"; file ] -> dump_tokens file
|
|
| [ "ast"; file ] -> dump_ast file
|
|
| [ "deps"; file ] -> dump_deps 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
|