Skip to content

feat(builtin): path_exists 추가 + file_exists fopen→S_ISREG 백엔드 통일#2160

Merged
dancinlife merged 1 commit into
mainfrom
feat/path-exists
May 29, 2026
Merged

feat(builtin): path_exists 추가 + file_exists fopen→S_ISREG 백엔드 통일#2160
dancinlife merged 1 commit into
mainfrom
feat/path-exists

Conversation

@dancinlife
Copy link
Copy Markdown
Contributor

요약

hexa 파일존재 빌트인을 canonical(Go/Rust) 3분법에 맞춘다.

  • path_exists(path) -> bool 신규 추가 — stat 기반, 경로가 존재하면 정규파일·디렉터리·그외 무관 true. Rust Path::exists() / Go os.Stat+!IsNotExist 의미. C impl = struct stat st; return (stat(path,&st)==0)?1:0;
  • file_exists 백엔드 불일치 버그 수정self/build_c.hexahexa_file_existsfopen(path,"rb") 로 구현돼 Linux서 디렉터리에 true 를 반환했다. stat+S_ISREG 로 교체해 self/runtime_core_emit.hexa 의 기존 S_ISREG 구현과 일치(정규파일 전용 = is_file).

결과 canonical 매핑: path_exists=exists(any) · file_exists=is_file(정규파일만) · dir_exists=is_dir(디렉터리만).

기존 갭(walkie-hexa #292서 발견): hexa엔 generic exists 가 없어 .git(clone=dir, worktree=gitfile) 확인에 shell test -e 우회가 필요했다. path_exists 가 그 갭을 메운다.

등록 전수성 (@l3)

자기호스팅 컴파일러라 빌트인은 모든 백엔드 site 에 등록해야 unknown-builtin 이 안 난다. file_exists 가 등록된 모든 자리에 path_exists 동반 등록:

site 역할
compiler/check/bind.hexa 빌트인 always-in-scope 목록
compiler/codegen/arm64_darwin.hexa name→rt 심볼 (rt_path_exists)
self/build_c.hexa emit dispatch + static C impl + Int 반환타입
self/runtime_core_emit.hexa rt_path_exists C impl + forward decl
self/codegen.hexa gen2 emit + is-builtin
self/codegen/rt_symbols.hexa rt 심볼 인식
self/env.hexa · self/lsp.hexa · tool/hexa_repl.hexa interp/completion/repl 목록
self/rt/io.hexa · self/rt/fs.hexa rt alias
self/runtime/io.hexa interp pub fn (test -e)
tool/native_build.hexa name→sym map
self/runtime.h forward decl (user.c implicit-decl 방지)

compiler/intrinsics/intrinsics.hexa 의 기존 pub fn path_exists(import용 v0)와 충돌 없음 — 빌트인은 always-in-scope, local pub fn 이 shadow (file_exists 와 동일 패턴, 다수 local fn 공존 확인).

검증

  • hexa 자기호스팅 재빌드 (LOCAL_BUILD · Mac arm64) — [0-pre] runtime_core.c regen → [3/5] main 재트랜스파일 → [5/5] smoke OK(--version·parse·build round-trip). 부트스트랩 PASS.
  • 6-case (freshly-built hexat):
    1 path_exists(dir)    = true
    2 path_exists(file)   = true
    3 path_exists(missing)= false
    4 file_exists(dir)    = false   ← @L4 버그 수정 전엔 true
    5 file_exists(file)   = true
    6 file_exists(missing)= false
    
  • 회귀 test/runtime/io_test.hexa 10/10 PASS (file_exists·dir_exists·dir_exists(file)==false 커버).

53 insertions / 5 deletions, 14 files — 단일 PR (<200 LOC, @l6).

🤖 Generated with Claude Code

canonical 파일존재 3분법(Go/Rust)에 맞춤:
  · path_exists(path)->bool 신규 = stat 기반, 존재하면 정규파일·디렉터리 무관 true
    (Rust Path::exists() / Go os.Stat+!IsNotExist). C impl = stat()==0.
  · file_exists 백엔드 불일치 버그 수정 = self/build_c.hexa 의 fopen(path,"rb")
    (Linux서 디렉터리에 true) → stat+S_ISREG 로 교체, runtime_core_emit.hexa 의
    S_ISREG 구현과 일치(정규파일 전용 = is_file).

결과: path_exists=exists(any) · file_exists=is_file(정규파일만) · dir_exists=is_dir.

등록 전수성(@l3) — file_exists 가 등록된 모든 백엔드 site 에 path_exists 동반 등록:
  bind.hexa(빌트인 목록) · arm64_darwin(name→rt) · build_c(emit+C impl+Int반환) ·
  runtime_core_emit(rt_path_exists C impl+decl) · codegen(emit+is-builtin) ·
  rt_symbols · env · lsp · rt/io · rt/fs · runtime/io(pub fn) · native_build ·
  hexa_repl · runtime.h(forward decl). 누락 없음 = unknown-builtin 없음.

검증: hexa 자기호스팅 재빌드(LOCAL_BUILD Mac) 부트스트랩 PASS · 6-case
  (path_exists dir/file=T·missing=F · file_exists dir=F·file=T·missing=F) PASS ·
  test/runtime/io_test 10/10 회귀 PASS.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@dancinlife dancinlife merged commit a5c5c68 into main May 29, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant