zig言語学習帳。 しばらく zig してなかったのだが、また触り始める。 2周め。 `v0.11 dev~` 軌道に乗るまでに手間取りました。 他の言語と違うところ、初見でわかりにくいところのメモなど。 ~`v0.10`
Zig is a new, independently developed low-level programming language. It’s a modern reimagining of C that attempts to retain C’s performance while embracing improvements from the last 30 years of tooling and language design. Zig makes calling into C code easier than any other language I’ve used. Zig also treats unit testing as a first-class feature, which the C language certainly does not. These t
Languages are often judged initially on their "Hello, world!" program. How easy is it to write? To run? How easy is it to understand? It's a very simple program, of course, one of the simplest, even... just produce a little text, and display it, what could be simpler? It's really not fair to judge a language by such a cursory impression, but it can give you an idea of what a language values and ho
See also the followup post: https://zig.news/kristoff/building-sqlite-with-cgo-for-every-os-4cic For the last couple of months I worked on a redesign of https://ziglang.org. Among other things, the site was ported to Hugo, a popular static site generator written in Go. Everything went smoothly, but I did encounter a snag when setting up the deploy pipeline: I could not build Hugo for x86_64 Linux
Jun 19, 2024 Why I am not yet ready to switch to Zig from Rust I am not going to lie: I love programming in C. I know it’s a little bit irrational, but programming in C just feels right. Perhaps that’s because I did spend a lot of time programming with C as I contributed to the Linux kernel. Those were good times because I had the opportunity to learn from some of the best C programmers in the wor
In this article we will be exploring what parser combinators are, what runtime parser generation is - why they’re useful, and then walking through a Zig implementation of them. What are parser combinators?Why are parser combinators useful?Going deeper: runtime parser generationA note about traditional regex enginesImplementing the Parser interfaceCompile-time vs. run-timeThe parser interfaceZig ge
While not yet at version 1.0, Zig is about to reach a new level of maturity and stability. In the early days, Zig was but a thin frontend in front of LLVM. This was instrumental for getting started quickly and filling in gaps of Andrew’s knowledge as a compiler developer. Now, the training wheels of the bicycle are coming off, and LLVM is transitioning into an optional component. The work to repla
Welcome Welcome! This is the initial page for the “Open Access” HTML version of the book “Introduction to Zig: a project-based book”, written by Pedro Duarte Faria. This is an open book that provides an introduction to the Zig programming language, which is a new general-purpose, and low-level language for building robust and optimal software. About this book This an open book, meaning that, it is
If you look at the HackerNews headlines and comments - you may notice that every now and then people praise Zig, a relatively young programming language for low-level programming. Maybe not as low-level as assembler, but definitely as low-level as C or C++. I’m usually very skeptical about new languages, so naturally I wanted to give Zig a try. But after playing around and building a few toy proje
イントロ さあ、やって参りました。 第2回 Zig探訪 のお時間です。 今回担当するのは、ここ最近冷房が寒くてエアコンを消すと、今度は内部洗浄で湧き出てくる熱気のせいでまた部屋が暑くなることに悩まされている、社会人歴マイナス2年のsmallkirbyです。昨日Ubuntuを24.04にしました。まだ22.04使ってる人は反省してください。もう22.04からアップグレードできます。Ubuntuは最初のポイントリリースまでアップグレードできない印象あったんだけど、どういうこと? Zig探訪では、Zigの機能や特徴の中で面白いんじゃないかと思うものをピックアップして紹介していきます。 紹介しないこともあります。 第2回のテーマは、Zigを取り囲むエコシステムについてです。 実際にコーディングをする上で開発体験に大きく影響を与える部分ですね。 最近の言語だと、ただ言語仕様自体が優れているだけでは不
In many ways my whole programming career feels like a long wait for a replacement to C. 20 years ago I though that was C++. Over time I learned C++ was a complex monster that could never be tamed no matter how many thick best practices books I read. I think Yossi Kreinin with his C++ Frequently Questioned Answers does a pretty good job of summarizing everything I have come to hate about C++. So wh
Zig の標準ライブラリではコレクション型が提供されていますが、ドキュメント整備が途上ということもあり、どのようなコレクションが提供されているのかを把握するのが難しいと感じています。 提供されているコレクションを簡単にまとめ、適切な場面で適切なコレクション型を利用することができるようになることを狙いとした記事です。 なお、対象のZigバージョンは 0.10.0-dev.3513+e218b7ea0 です。 また、掲載しているサンプルコードは以下のgistにまとめてあります。 ArrayList 全要素がメモリ上で連続した領域に配置され、実行時に動的に長さを変えることができるコレクションです。 C++のstd::vector, Rustのstd::vec::Vec に相当します。 添字によるランダムアクセス、末尾への要素追加、順方向・逆方向のイテレーションをしたいユースケースで役立ちます。
I keep seeing discussions that equate zig's level of memory safety with c (or occasionally with rust!). Neither is particularly accurate. This is an attempt at a more detailed breakdown. This article is limited to memory safety. See Assorted thoughts on zig and rust for a more general comparison. I'm concerned mostly with security. In practice, it doesn't seem that any level of testing is sufficie
Zig に関する自分なりのメモを残しています。 学ぶモチベーション C++ や Rust を学ぶには難しそう Erlang VM の NIF 経由で Zig で書かれたライブラリを呼び出したい Zig で HWA を利用したエンコーダーとか作ってみたい macOS もしくは Linux で動けば良い Wasm に出力してブラウザで利用したい Zig の良いところ zig build は C のビルドツールとしても有用そう allocator の概念がわかりやすい std.crypto が充実している zig test がよくできている switch が好み 利用目的 WebTransport HTTP/3 QUIC HTTP/2 MLS (C++ / Wasm) Signal Protocol (C++ / Wasm) AV1 / VPX / Opus / Lyra 翻訳 自分向けに Zi
この記事で書くこと 最近、低レイヤー周りの技術を学習しているなかでブートローダーを実装したので、頭の整理もかねて記事を書くことにしました。 ブートローダーで実行するカーネルは Hello World を出力するだけの自作カーネルで、メモリ管理やシステムコールなどの実装はしません。そのためブートローダーも自作カーネルを実行するのに必要な範囲の実装になっています。 ブートローダー、カーネルともに Zig で実装します。プログラムのビルドにも Zig が使えるので他にビルドツールを揃えなくてもいいところが嬉しいです。 Zig Language Reference ブートローダーを実行する リポジトリをクローンしてブートローダーを実行することができます。
Zig-style generics are not well-suited for most languages Too long; didn’t read: Zig’s compilation scheme for generics shares a lot of similarities with C++, and hence the pitfalls too. Such a compilation scheme is not well-suited to all languages, so armchair suggestions about how other languages should embrace Zig-style generics are misguided. Ain’t nobody handing out free lunches in Generics La
This issue is to fully eliminate LLVM, Clang, and LLD libraries from the Zig project. The remaining ties to these projects are as follows: completely eliminate dependency on LLD #8726 eliminate dependency on LLD for Mach-O #8727 eliminate dependency on LLD for ELF #17749 eliminate dependency on LLD for COFF/PE #17751 eliminate dependency on LLD for WebAssembly #17750 LLVM directly output LLVM bitc
This is the text format of a talk I did for Zig Showtime. If you'd rather watch the video, you can find it on YouTube: Zig Showtime: Ghostty. The video also includes a Q&A session at the end which I did not include in this post. Hello! I'm excited to talk today about Ghostty. Ghostty is a brand new terminal emulator written from scratch in Zig. Note: at the time of writing this, Ghostty is still n
ブログに書いていたものを引っ越してきて一部手直ししました。元の記事公開日は 2021-01-07 です。 かんたんな自作言語のコンパイラをいろんな言語で書いてみるシリーズ 11回目は Zig です。 ライフゲームのコンパイルが通ったのでヨシ、という程度の雑なものです。 Zig言語(ziglang)を触り始めて1週間くらいの人が、理解は後回しにしてとにかく動くものを作るぞ、という方向性で書いたもの(その程度のノリでかんたんに書けるコンパイラです)。 Zig のバージョンは 0.6.0。 (追記 2022-07-17: 0.9.1 に上げました) できたもの サイズはこんな感じ: $ wc -l {lexer,parser,codegen}.zig lib/{types,utils,json}.zig 189 lexer.zig 630 parser.zig 552 codegen.zig 2
You've surely read plenty about how simple is good, but what's wrong with easy? The Zig project has a non-profit foundation that needs to be managed, a community to shape, and the actual language to develop. These are all big, complex problems that don't default to a positive outcome without active care. Andrew did an amazing job laying the foundations, from deliberately choosing a non-profit corp
While I've written a lot about Zig, I've avoided talking about Zig's meta programming capabilities which, in Zig, generally falls under the "comptime" umbrella. The idea behind "comptime" is to allow Zig code to be run at compile time in order to generate code. It's often said that an advantage of Zig's comptime is that it's just Zig code, as opposed to a separate, often limited, language as seen
Zig is a programming language that’s attempting to become “the new C” - the language of choice for low-level systems programming and embedded hardware. Going into that space not only puts it in competition with C and C++, but also other newcomers like Rust and Go. So what makes Zig special? Joining us to discuss it is Loris Cro from the Zig Foundation. We talk through Zig’s reasons to exist, its
As we’ve been building Mach engine, we’ve been using a neat little pattern in Zig that enables writing flag sets more nicely in Zig than in other languages. What is a flag set?We’ve been rewriting mach/gpu (WebGPU bindings for Zig) from scratch recently, so let’s take a flag set from the WebGPU C API:
前回の記事はこちら。 前回JavaScriptとWasmでデータを受け渡す概念的なことを説明しました。今回は、実際にDenoとZigのコードを書いていきます。 Denoで書いていますが、これまでの記事で説明したようにブラウザのJavaScriptでも少し書き換えるだけで利用できます。 今回説明する方法はあくまで、私が考えた1つの方法にすぎないことをご了承ください。前記事を踏まえて自身で学んで書くか、ライブラリを探すのも一つの手だと思います。 なお、私はZigにあまり詳しくなく、データ受け渡しのための最低限のことしか勉強していません。そのため、Zigのコードについては稚拙なものになっているかもしれませんがご了承ください。 何を作るか 今回の目標は、Zigの標準ライブラリのBase64エンコードをWasm化することです。 これは実際に計測して確かめたことなのですが、Base64エンコード程度の
Fore-forwarning: This post describes std.http efforts pre-0.11 zig. After the 0.11 release new features have been introduced, and some names have been changed, this post does not describe those changes. To attempt to keep this post as a useful guide: if you're using zig 0.12 (or a development version thereof, as 0.12 has not been released as of this edit), apply the following changes: Client.reque
I'm working on an application that needs the ability to schedule tasks. Many applications have a similar need, but requirements can vary greatly. Advanced cases might require persistence and distribution, typically depending on external systems (like a database or queue) to do much of the heavy lifting. My needs are simpler: I don't have a huge variety of tasks or a high number of them. Thread-Per
Zig defer Patterns Mar 21, 2024 A short note about some unexpected usages of Zig’s defer statement. This post assumes that you already know the basics about RAII, defer and errdefer. While discussing the differences between them is not the point, I will allow myself one high level comment. I don’t like defer as a replacement for RAII: after writing Zig for some time, I am relatively confident that
Building a native GUI for a cross-platform application is a decades old problem. Nowadays, most people just don't and fallback to using a non-native experience such as Electron instead. One approach to building a native GUI for a cross-platform application is to write all of the business logic in a cross-platform language (C, Rust, Zig, etc.) and then write the platform-specific GUI code. This is
Why FastlyProductsServicesSolutionsDevelopersPartnersResourcesPricing Creating an Efficient Language with Zig | FastlyBuilding a programming language from scratch is no easy feat. In addition to creating the compiler, defining the standard library, and supporting tools like editors and build systems, you need to design the language — will it be imperative or functional? What systems will the langu
I decided to bootstrap Zig without using binaries that are checked in the repository and answer if the resulting zig1.wasm in the latest Zig release (0.13.0) is the same the one bootstrapped without using those binaries. TLDR: yes, they are the same: $ sha256sum code/zig{,2}/stage1/zig1.wasm 127909fb8c9610ce3f296d8a48014546c0f85055115002fb3aba4d865dcdbb27 code/zig/stage1/zig1.wasm 127909fb8c9610ce
We’ve just finished a complete rewrite of mach/gpu (WebGPU/Dawn bindings for Zig), with 700+ commits, ~7.4k LOC, and 100% API coverage. WebGPU (not to be confused with WebGL) is a modern graphics API, acting as a unified API to the underlying Vulkan/Metal/DirectX APIs. Despite it’s name, it is also designed for use in native applications via its C API. Dawn is the C++ implementation of WebGPU by G
index.md これは Zig ドキュメント 0.10.1 を DeepL Pro と ChatGPT を利用して翻訳したものです。 一部 master なモノもあります、ごちゃ混ぜです 自分用に翻訳しています zig_doc_0.10.1.md Zig 言語リファレンス はじめに Zig は、堅牢で最適かつ再利用可能なソフトウェアを維持するための汎用プログラミング言語およびツールチェインです。 ロバスト メモリ不足などのエッジケースでも正しく動作する。 最適化 プログラムが最適に動作・実行されるように記述する。 再利用可能 同じコードが、制約の異なる多くの環境で動作します。 保守性 コンパイラや他のプログラマに意図を正確に伝えることができる。コードを読むためのオーバーヘッドが少なく、要件や環境の変化に強い言語です。 新しいことを学ぶのに一番効率的な方法は例を見ることであることが多いので
Why self-host Zig? For great justice, of course… and also a few more reasons actually. With the upcoming 0.10.0 release of Zig on November 1st, we are going to ship the new self-hosted compiler. This is the result of a huge amount of work that brings a lot of benefits, some obvious, some others less so. Even though the self-hosted compiler is now shipped, there's still more work to do on it but, a
This page collects my writing about the 🦎 Zig programming language. Compiler Internals An introduction to the internals of the Zig compiler. The articles currently cover an introduction of most of the compiler "frontend" -- the process from source code to just prior to machine code generation. Note: These are the internals for the self-hosted compiler, also known as the "stage2" compiler. At the
まあ、当たり前のことなんですけどね。 前回の記事のプログラムを書き直した 前回の記事のMJPEGからJPEGを切り出すプログラムにはバグがありました。脚注にも書きましたが、それは読み込んだバッファの最後のバイトが0xffで、次のバッファの先頭が0xd9のときに、JPEGの終わりを見逃してしまうというものです。 なので、ちゃんと4つの状態を遷移するように書き直しました。 const std = @import("std"); const fs = std.fs; const io = std.io; const os = std.os; const BUF_SIZE = 64 * 1024; const OUTPUT_FILENAME_PATTERN = "out{d:0>4}.jpg"; const JPEG_START0 = 0xff; const JPEG_START1 = 0xd8;
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く