순서가 요점이다. 문법에 test_decl과 panic_expr을 넣고 파서는 안 고친 채로
대조 장치를 돌렸더니 즉시 잡혔다:
문장 300개 중 파서가 거부한 것 140개
[1] 선언 (fn, struct, enum, capability, const)이(가) 필요합니다 — test 발견
파서를 따라가게 하니 다시 0건. 문법과 구현이 어긋나는 상태가 관측 가능한
것이 되었다는 뜻이다.
panic:
- 키워드다. prelude가 없어 함수로 두면 쓸 때마다 import해야 한다
- effect가 아니다. 경계 검사 하나에 {Panic}이 호출자 전부로 전염되면
effect 절은 신호가 아니라 잡음이 된다
- Never는 어떤 타입 자리에도 놓인다. 없으면 panic을 match 팔에서 못 쓴다
- 언어 수준 recover 없음. 되감기 없음. 자원 해제 여부는 열어둔다
- 0으로 나누기, assert 실패가 이 하나로 모인다
test:
- 파라미터가 없어 capability를 받을 수 없고, 만들 문법도 없다. 그래서
effect-free임이 증명된다 — 관례가 아니라 검사다. 시험해 보니 실제로
"테스트는 effect를 수행할 수 없습니다"로 거부한다
- 일반 코드와 같은 타입/effect/move 검사를 받는다
- interface hash에서 제외 — 테스트를 고쳤다고 downstream이 재검사되면 안 된다
- 격리는 런타임의 일이다. 하나가 죽어도 나머지는 돈다
assert는 std/test.cool에 coollang으로 쓰였다 — panic 위의 설탕임이 코드로
보이고, std에서 본문이 있는 첫 함수가 됐다. 그 바람에 std/런타임 양방향
테스트가 걸렸고(본문 있는 함수에 런타임 구현을 요구했다), 그 구분을 넣었다.
samples/app/config.cool에 첫 테스트 넷.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019ZVDeU6KLuUVL3gs18Hm3E
135 lines
4.6 KiB
OCaml
135 lines
4.6 KiB
OCaml
let usage =
|
|
{|coollang toolchain
|
|
|
|
사용법:
|
|
coolc check <file.cool>... 타입/effect/capability 검사 (import를 따라 모듈 그래프 전체)
|
|
coolc test <file.cool> [필터] 모듈 그래프의 test 블록 실행
|
|
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
|
|
| "test" :: file :: rest -> (
|
|
let filter = match rest with f :: _ -> f | [] -> "" in
|
|
let st = Coollang.Session.create ~root:(Filename.dirname file) () in
|
|
match Coollang.Session.test ~filter st file with
|
|
| Error errors ->
|
|
List.iter
|
|
(fun e -> prerr_endline (Coollang.Session.string_of_error e))
|
|
errors;
|
|
1
|
|
| Ok results ->
|
|
let failed =
|
|
List.filter
|
|
(fun (r : Coollang.Interp.test_result) -> r.t_failure <> None)
|
|
results
|
|
in
|
|
List.iter
|
|
(fun (r : Coollang.Interp.test_result) ->
|
|
match r.t_failure with
|
|
| None -> ()
|
|
| Some (p, msg) ->
|
|
Printf.printf "FAIL %s:%d %s\n %s\n" r.t_module
|
|
r.t_pos.line r.t_name msg;
|
|
ignore p)
|
|
results;
|
|
Printf.printf "%s 테스트 %d개 중 %d개 통과\n"
|
|
(if failed = [] then "ok " else "실패")
|
|
(List.length results)
|
|
(List.length results - List.length failed);
|
|
if failed = [] then 0 else 1)
|
|
| "run" :: file :: args -> (
|
|
let st = Coollang.Session.create ~root:(Filename.dirname file) () in
|
|
match Coollang.Session.run ~args st file with
|
|
| out, None ->
|
|
print_string out;
|
|
0
|
|
| out, Some e ->
|
|
(* 실패해도 그때까지의 출력을 먼저 보여준다 *)
|
|
print_string out;
|
|
flush stdout;
|
|
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
|