Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Rustの手続きマクロで黒魔術入門
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
lemolatoon
March 11, 2023
Programming
1.4k
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Rustの手続きマクロで黒魔術入門
Rustの手続きマクロについて紹介します。そして、自作関数手続きマクロである direct_c_lang についても紹介します。
lemolatoon
March 11, 2023
More Decks by lemolatoon
See All by lemolatoon
スマホから Youtube Shortsを見られないようにする
lemolatoon
29
39k
お家miniPCを使ってミリしらでkubernetes clusterたててみる
lemolatoon
1
360
【Rust × C++】 夢の共演を試した話
lemolatoon
1
1.8k
no_stdでもasyncしたい
lemolatoon
0
280
Other Decks in Programming
See All in Programming
Web Framework Benchmark Battle 2026, Any%
a_matsuda
2
2.7k
Kotlinの15年とServer-Side Kotlin
n_takehata
1
160
Jetpack Compose Mechanisms
skydoves
3
840
Seven New Principles of Software Engineering
yegor256
0
170
【加筆修正版】Laravel のアプリケーションをどこにデプロイするか #phpcon_ehime
akase244
0
160
ChromeでローカルLLM
ryu1013
0
160
GemmaをJevのように使ってみる / Use Gemma like Jev
kishida
5
820
AI-Powered Domain-Driven Design
ziobrando
0
200
AWSに止められる覚悟してますか?
morizo_1984
2
540
最近”作らせてる” ローカルAIアプリの話
akit37
0
490
3回つくってわかった、 定期実行ジョブ基盤の本質情報
takai
0
600
IBM Bob でAI駆動開発『QC-Playbook』
ichirokano2
0
120
Featured
See All Featured
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.9k
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
630
VelocityConf: Rendering Performance Case Studies
addyosmani
331
25k
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
720
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
203
77k
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
530
The Curse of the Amulet
leimatthew05
3
16k
The browser strikes back
jonoalderson
0
1.8k
Chasing Engaging Ingredients in Design
codingconduct
0
370
Navigating Team Friction
lara
192
16k
AI Search: Where Are We & What Can We Do About It?
aleyda
0
8.1k
Transcript
Rustの手続きマクロで黒魔術入門 lemolatoon
自己紹介 慶應義塾大学 理工学部1年 セキュリティ・キャンプ2022 Cコンパイラゼミ修了生 Twitter (@lemolatoon1)
(このスライドは上記アカウントでツイートしています) 2
“Rustの手続きマクロ”って? Rustを書くときによく見る手続きマクロの例 1) deriveマクロ 2) attributeマクロ 3 ソースコードを受け取って、ソースコードを返すようなプログラミング言語Rustの特殊な関数
3) 関数マクロ
自由度の高い関数手続きマクロ 4 * カッコの対応などは入力時点で正しい必要がある 関数手続きマクロは正しいRustのコードを出力すれば、 どんな入力*でも受け付ける。
自作関数手続きマクロ direct_c_lang の紹介 5 https://github.com/lemolatoon/direct_c_lang_rs.git C言語のコードを受け取り、Rustから呼べるインターフェースを提供する。 (下記は実際に使っている例 ) Rust側からマクロ内で定義されたC言語
で書かれた関数を呼び出している。 (4~10行) C言語のソースコードをマクロに渡し ている。 (12~25行)
自作関数手続きマクロ direct_c_lang の紹介(マクロの展開) 6 ◼マクロの入力を global_asmマクロ+C言語側の関数 の宣言へ変換 ◼マクロ内部で自作Cコンパイラを使っている ◼マクロ展開前 ◼マクロ展開後
実際の手続きマクロの中身 7 * https://github.com/lemolatoon/direct_c_lang_rs.git マクロの変換前から、マクロの変換後の処理自体をRustでかける。 中略(Cの関数をRustの宣言に変換) マクロの入力として与えられ たC言語のソースコードを アセンブリに変換
マクロの出力(展開先)を関 数の戻り値として返す
まとめ Rustの手続きマクロは自由度が高い上に、マクロ処理自体をRustでかけるため、 C/C++のような複雑性が生じにくい 自由度を生かして自分の独自のマクロを作ると楽しい 「書けばいいことは明確になったけど、これ全部手で書かなきゃいけないのか ……」といったときに便利 8
ありがとうございました 9