はじめに
Hewをインストールして最初のプログラムを書く。
クイックインストール
Hewを最速でインストールする方法はインストーラースクリプトを使うことです:
v0.9.3 · リリース
curl -fsSL https://hew.sh/install | bash -s -- --version 0.9.3curl -fsSL https://hew.sh/install | bash -s -- --version 0.9.3Invoke-WebRequest https://hew.sh/install.ps1 -OutFile install.ps1
.\install.ps1 -Version 0.9.3インストーラーは、コンパイラとパッケージマネージャーを含む hew をインストールします。
このターミナルで標準のインストール先を PATH に追加してください。今後のターミナルでも使うには、インストーラーが表示したシェル用の永続設定コマンドを実行します。別の場所を指定した場合は、その PATH コマンドを使ってください。
export PATH="$HOME/.hew/bin:$PATH"インストール後に新しいターミナルを開き、更新された PATH を読み込んでください。
これらのコマンドはレッスンと同じコンパイラのバージョンを選択します。hew version で確認してください。
hew versionこんにちは世界
hello.hewというファイルを作成します:
fn main() {
println("Hello, world!");
}コンパイルと実行
hew buildでコンパイルして結果のバイナリを実行します:
ネイティブビルドには C コンパイラとシステムの開発ツールが必要です。macOS では Xcode Command Line Tools、Linux では Clang または GCC、Windows では LLVM と Visual Studio C++ Build Tools を使います。チェックに成功してもリンクに失敗する場合は、トラブルシューティング(英語)を参照してください。
hew check hello.hew
hew build hello.hew -o hello
./helloHello, world!hew check hello.hew
hew build hello.hew -o hello.exe
.\hello.exeHello, world!hew buildはRustフロントエンドを実行し、検査済みプログラムをHIRとMIRへ下げ、LLVMでネイティブバイナリを生成します。
エディターの設定
VS Code の拡張機能から Hew Language(hew-lang.hew-lang)をインストールしてください。code が PATH にある場合は、次のコマンドも使えます:
code --install-extension hew-lang.hew-langhello.hew を開いてください。言語モードが Hew になり、構文ハイライトと言語サーバーの診断が表示されます。公開済みの拡張機能には、対応プラットフォーム用の hew-lsp が含まれています。
特定のインストールを使うには、VS Code の設定で hew.lsp.serverPath と hew.formatterPath に hew-lsp と hew の完全なパスを指定してください。~ や変数を含まない絶対パスを使います。PATH を変更したら VS Code を再起動してください。
クイックリファレンス
印刷用の両面チャートに、日常的な構文、アクター、並行処理、ワイヤー型、ステートマシンをまとめています。
その他のインストール方法
実行前にインストーラーを確認するには、ローカルファイルにダウンロードして読んでください。
curl -fsSLo hew-install.sh https://hew.sh/install
less hew-install.sh
bash hew-install.sh --version 0.9.3Invoke-WebRequest https://hew.sh/install.ps1 -OutFile install.ps1
Get-Content .\install.ps1
.\install.ps1 -Version 0.9.3上記のリリースをダウンロードし、対応する SHA-256 チェックサムファイルでプラットフォームのアーカイブを検証してください。
tag=v0.9.3
asset=hew-v0.9.3-darwin-aarch64.tar.gz # choose the asset for your Mac
base="https://github.com/hew-lang/hew/releases/download/$tag"
curl -fLO "$base/$asset"
curl -fLO "$base/hew-$tag-checksums.txt"
grep " $asset$" "hew-$tag-checksums.txt" | shasum -a 256 -c -tag=v0.9.3
asset=hew-v0.9.3-linux-x86_64.tar.gz # choose the asset for your Linux host
base="https://github.com/hew-lang/hew/releases/download/$tag"
curl -fLO "$base/$asset"
curl -fLO "$base/hew-$tag-checksums.txt"
grep " $asset$" "hew-$tag-checksums.txt" | sha256sum -c -$tag = "v0.9.3"
$asset = "hew-v0.9.3-windows-x86_64.zip"
$base = "https://github.com/hew-lang/hew/releases/download/$tag"
Invoke-WebRequest "$base/$asset" -OutFile $asset
Invoke-WebRequest "$base/hew-$tag-checksums.txt" -OutFile checksums.txt
$expected = (Select-String -Path checksums.txt -Pattern " $asset$").Line.Split(" ")[0]
$actual = (Get-FileHash -Algorithm SHA256 $asset).Hash.ToLower()
if ($actual -ne $expected) { throw "checksum mismatch" }以下の前提条件を用意すると、指定したリリースをソースからビルドすることもできます。
Using the mobile apps? Follow the illustrated iPhone/iPad guide or Android beta guide for examples, editing, running and saving code. These guides are in English.
前提条件
ソースからのビルドには GNU Make と Python 3.12 以降も必要です。 すべてのビルド要件(英語)
macOSでソースからビルドするにはLLVM 22とRust toolchainが必要です。HomebrewでLLVMをインストール:
brew install llvm cmake ninjaHewコンパイラをソースからビルドするにはLLVM 22とRust toolchainが必要です。Ubuntu/Debianの場合:
# Install LLVM 22 (required by Inkwell)
wget https://apt.llvm.org/llvm.sh && chmod +x llvm.sh && sudo ./llvm.sh 22
# Install build tools
sudo apt install cmake ninja-buildWindowsでソースからビルドするにはRust toolchain、VS Build Tools 2022(C++デスクトップ開発)、cmake、Ninja、llvm.orgからのLLVM 22が必要です。
ソースからビルド
リポジトリをクローンしてコンパイラをビルドします:
git clone --branch v0.9.3 https://github.com/hew-lang/hew.git
cd hew
make hew-nativeコンパイラドライバーはtarget/debug/hewにあります。PATHに追加:
export PATH="$PWD/target/debug:$PATH"コンパイラドライバーはtarget\debug\hew.exeにあります。PowerShellでPATHに追加:
$env:PATH = "$PWD\target\debug;$env:PATH"