9. 실행 / 툴 개요
본 블록에서는 rok 의 컴파일러 rokc, front-end rok, 그리고 실행 환경 (REPL / Jupyter 커널) 사양을 정의합니다. 실행 엔진과 사용자 표면 에서 정의한 두 엔진 (JIT / AOT) 과 세 사용자 표면 (REPL / Jupyter / AOT 산출물 직접 실행) 을 어떻게 구현하는지 다루고 있습니다.
목차
- 9.1.
rokcCLI 인터페이스 - 9.2. AOT 빌드 파이프라인
- 9.3. 패키지 아카이브 (.a) 포맷
- 9.4. ROKHIR 포맷
- 9.5. 심볼 맹글링 스킴
- 9.6. JIT 엔진 (RokJitSession)
- 9.7. JIT 셀 실행 흐름과 상태 관리
- 9.8. Jupyter 커널 통합
- 9.9. 디버그 / 진단 도구
- 9.10.
rok- 패키지 / 빌드 front-end
도구 표면
도구 표면은 다음과 같이 구성됩니다.
rok (front-end, cargo-like)
│ new / init, add / remove / update / deps (rok.rokon, rok.lock), env, toolchain
│ build / check / run / test / bench / emit / fmt / lint / doc / clean / repl / lsp / demangle
│ └── resolve deps, then call rokc ... --extern <dep roots>
▼
rokc (compiler)
│
├── build / run
│ ├── rokc build : AOT compile - .rok source to .a / executable
│ ├── rokc run : AOT compile then run immediately
│ ├── rokc test : collect + build the #[test] harness (rok test runs it)
│ ├── rokc bench : collect + build the #[bench] harness (rok bench runs it)
│ ├── rokc check : type / diagnostics only (no native build)
│ └── rokc clean : remove build artifacts
│
├── tools
│ ├── rokc fmt : formatter
│ ├── rokc lint : linter
│ ├── rokc doc : API documentation
│ └── rokc lsp : LSP server (IDE integration)
│
├── interactive
│ ├── rokc repl : terminal REPL (each cell runs once)
│ └── rokc jupyter : Jupyter kernel (REPL cell session + ZMQ)
│
├── debug / diagnostic
│ ├── rokc demangle : symbol demangle
│ ├── rokc rokhir-text : ROKHIR interface text dump
│ └── rokc inspect : package inspect
│
└── rokc version / help
rokls (= rok lsp, for editors)
librokr.a (runtime, rokr)
toolchain 은 컴파일러 rokc (rustc 에 해당), cargo 식 front-end rok, 편집기용 LSP 실행 파일 rokls, 런타임 librokr.a 로 이루어집니다. rok 는 매니페스트 rok.rokon / rok.lock, 의존성, 환경, toolchain 고정을 맡고, 빌드와 도구 명령은 해소한 의존 패키지를 --extern 으로 붙여 rokc 에 위임합니다 (9.10). 별도 도구 (rok-fmt 등) 는 두지 않습니다.
두 엔진의 구현
실행 엔진과 사용자 표면 에서 정한 두 엔진은 다음과 같이 구분됩니다.
JIT engine ── used by rokc repl / jupyter
AOT engine ── used by rokc build / run / test
두 엔진은 같은 컴파일 파이프라인 (rok-hir → rok-mir → 표준 MLIR) 을 거치고 있으며, 마지막 중간 표현 이후에만 갈라지고 있습니다. 자세한 내용은 실행 엔진과 사용자 표면 과 컴파일 파이프라인 에서 다루고 있습니다.
세 사용자 표면의 구현
세 사용자 표면과 그 구현 명령은 다음과 같이 정리됩니다.
surface command
──────── ──────
REPL rokc repl
Jupyter rokc jupyter (invoked by Jupyter, not directly)
AOT direct exec rokc build → run artifact
각 표면의 구현은 후속 문서에서 다루고 있습니다.
패키지 빌드 산출물
소스 단위 의 라이브러리 패키지는 libfoo.a 와 인터페이스 foo.rokhir 로 컴파일됩니다.
foo/
├── src/
│ ├── lib.rok <- input
│ └── ...
v rokc build
foo/target/debug/
├── libfoo.a <- artifact (static archive)
├── foo.rokhir <- interface (ROKHIR)
├── build/ <- intermediates (foo.o, ...)
└── ...
profile 별 레이아웃은 9.2.15, archive 의 형식은 패키지 아카이브 가 정의합니다.
ROKHIR: 제네릭 함수의 휴대용 IR
제네릭 함수는 호출 지점에서 단형화 해야 하므로 바이너리 코드만으로는 부족합니다. 따라서 라이브러리 옆에 인터페이스 파일 ROKHIR 을 둡니다. ROKHIR 은 구체 함수 본문을 잘라 낸 패키지 소스를 담습니다 (단형화가 AST 를 입력으로 쓰므로).
자세한 형식은 ROKHIR 포맷 에서 정의합니다.
단일 의존성: librokr.a
빌드 산출물은 사용자 패키지의 libfoo.a, 런타임 librokr.a, 표준 라이브러리 librok_*.a 로 구성됩니다. 외부 OS 라이브러리 외에는 추가 의존성이 없습니다.
자세한 빌드 흐름은 AOT 빌드 파이프라인 에서 정의합니다.