interp: 실패해도 그때까지의 출력을 보여준다

0으로 나누는 프로그램을 돌려보니 실패 전에 출력한 것이 통째로 사라졌다.
Interp.run이 출력을 버퍼에 모았다가 성공했을 때만 돌려주고 실패하면 버렸다.

print는 실제로 일어난 effect다. 일어난 일을 안 보여주면 "어디까지 갔나"를
알 수 없고, 그게 실패했을 때 가장 먼저 보고 싶은 것이다.

Interp.run과 Session.run이 이제 (출력, 실패 여부)를 함께 돌려준다.
result가 아니라 짝인 이유는 둘이 배타가 아니기 때문이다 — 실패했어도
출력은 있다.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019ZVDeU6KLuUVL3gs18Hm3E
This commit is contained in:
2026-08-30 17:21:34 +09:00
co-authored by Claude Opus 5
parent bb19a39e04
commit 8ff35c5d9b
4 changed files with 53 additions and 25 deletions
+5 -2
View File
@@ -79,10 +79,13 @@ let () =
| "run" :: file :: args -> (
let st = Coollang.Session.create ~root:(Filename.dirname file) () in
match Coollang.Session.run ~args st file with
| Ok out ->
| out, None ->
print_string out;
0
| Error e ->
| out, Some e ->
(* 실패해도 그때까지의 출력을 먼저 보여준다 *)
print_string out;
flush stdout;
prerr_endline (Coollang.Session.string_of_error e);
1)
| [ "tokens"; file ] -> dump_tokens file