English

Cm言語コンパイラ - クイックスタート

🚀 ビルド方法

サポート環境

OS アーキテクチャ ステータス
macOS 14+ ARM64 (Apple Silicon)
macOS 14+ x86_64 (Intel)
Ubuntu 22.04 x86_64

必要環境

📖 詳細な環境構築手順は 環境構築チュートリアル を参照してください。

ビルド

git clone https://github.com/shadowlink0122/Cm.git
cd Cm

# makeでビルド(推奨)
make all      # コンパイラ + ランタイムライブラリ

# アーキテクチャ指定ビルド
make build ARCH=arm64     # Apple Silicon
make build ARCH=x86_64    # Intel / Linux

./cmbuild/bin/cm へのシンボリックリンクです。
Docker環境では docker compose run --rm test でビルド・テストが実行できます。

CMakeの直接実行や詳細なオプションについては 環境構築 を参照。

📝 基本的な使い方

JITで実行

./cm run hello.cm

# デバッグモード
./cm run hello.cm -d

コンパイル

# ネイティブ実行ファイル
./cm compile hello.cm -o hello
./hello

# WebAssembly(wasmtime必要)
./cm compile hello.cm --target=wasm -o hello.wasm
wasmtime hello.wasm

# JavaScript(Node.js必要)
./cm compile --target=js hello.cm -o hello.js
node hello.js

構文チェック・品質ツール

# 構文・型チェック(コンパイルなし)
./cm check hello.cm

# 静的解析(コード品質チェック)
./cm lint hello.cm

# コードフォーマット
./cm fmt -w hello.cm

📖 各ツールの詳細は Linter / Formatter を参照。

📊 サンプルプログラム

Hello World

int main() {
    println("Hello, World!");
    return 0;
}

変数と文字列補間

int main() {
    int x = 10;
    int y = 20;
    println("x + y = {x + y}");
    return 0;
}

構造体とwith自動実装

struct Point with Eq {
    int x;
    int y;
}

int main() {
    Point p1 = {x: 10, y: 20};
    Point p2 = {x: 10, y: 20};
    
    if (p1 == p2) {
        println("Points are equal!");
    }
    return 0;
}

Enumとパターンマッチ

enum Color {
    Red,
    Green,
    Blue,
    Custom(int, int, int)
}

int main() {
    Color c = Color::Custom(255, 128, 0);
    match (c) {
        Color::Red => println("Red");
        Color::Custom(r, g, b) => println("RGB: {r}, {g}, {b}");
        _ => println("Other");
    }
    return 0;
}

インラインユニオン型とnull型

typedef MaybeInt = int | null;

int main() {
    // typedefユニオン型
    MaybeInt x = null;
    MaybeInt y = 42 as MaybeInt;
    
    // インラインユニオン型(typedef不要)
    int | null a = null;
    int | string | null b = null;
    return 0;
}

🧪 テスト実行

# C++ユニットテスト(GTest必須)
make test

# JITテスト(並列)
make tip

# LLVMテスト(並列)
make tlp

# WASMテスト(並列・wasmtime必要)
make twp

# JSテスト(並列・Node.js必要)
make tjp

# Dockerでテスト
docker compose run --rm test

📖 makeコマンドの全一覧は 環境構築 を参照。

📖 ドキュメント

ドキュメント 内容
チュートリアル 40+ファイルの段階的な学習ガイド
環境構築 依存関係・makeコマンド一覧
コンパイラの使い方 コマンド・オプション
JSバックエンド JavaScript出力ガイド
VSCode拡張機能 構文ハイライト・アイコン・開発ガイド
機能リファレンス 実装済み機能一覧
言語仕様 完全な言語仕様
リリースノート バージョン履歴

✅ 実装済み機能(v0.14.0)


最終更新: 2026-02-14