Skip to content

Standard Library and C API

james-yusuke edited this page Jul 16, 2026 · 1 revision

標準ライブラリとC API

YCPLは高水準APIとraw foreign APIをdirectoryで分離します。

stl/
├─ std/  YCPL言語レベルの標準API
└─ c/    C、POSIX、runtime、LLVMのraw ABI宣言

std

主なmodule:

  • std/fmt: print、println、printf
  • std/array: 旧slice container互換API
  • std/bytes: binary buffer
  • std/text: string builderと検索
  • std/json: JSON view/parser
  • std/map: Map<string,T> helper
  • std/fs: file操作
  • std/os: process/environment
  • std/hexstd/base32std/base64std/hash
  • std/mem: runtime-managed低水準互換API
  • std/unsafe/mem: 明示的unsafe raw allocation wrapper
  • std/llvm: 既存コード向けLLVM互換wrapper

新しい可変長containerにはstd/arrayではなく、言語組み込みのVec<T>を 推奨します。

c

c/
├─ stdlib
├─ string
├─ stdio
├─ math
├─ unistd
├─ fcntl
├─ sys/stat
├─ llvm
└─ yc_runtime
import "c/string" as cstr

fn main() i32 {
    return cstr.strcmp("YCPL", "YCPL")
}

c/*はraw pointerやforeign lifetimeを扱うため、安全なownershipを自動付与しません。 新しいraw C/LLVM bindingはstl/cへ追加し、stl/stdには高水準wrapperを置きます。

c/llvmはLLVM APIが要求する連続したreference列をVec<i64>から渡す専用bridgeを 持ちますが、一般のYCPLプログラムへVecのraw pointer変換を公開しません。

runtime

ycc buildはmanaged C runtimeをnative binaryへstatic linkします。runtimeの探索順:

  1. YCPL_RUNTIME_LIB
  2. compiler executable隣接のlibyc_runtime.a
  3. YCPL_RUNTIME_SRCが示すdevelopment runtime source

標準ライブラリrootはYCPL_STL_ROOTでoverrideできます。

Clone this wiki locally