Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
torque in V8
Search
Taketoshi Aono(青野健利 a.k.a brn)
May 22, 2018
Programming
1
3.5k
torque in V8
V8 javascript eingineのdslであるtorqueの話
Taketoshi Aono(青野健利 a.k.a brn)
May 22, 2018
Tweet
Share
More Decks by Taketoshi Aono(青野健利 a.k.a brn)
See All by Taketoshi Aono(青野健利 a.k.a brn)
document.write再考
brn
6
3k
Parsing Javascript
brn
14
9.2k
JSON & Object Tips
brn
1
490
CA 1Day Youth Bootcamp for Frontend LT
brn
0
940
Modern TypeScript
brn
2
800
javascript - behind the scene
brn
3
740
tc39 proposals
brn
0
870
プロダクト開発とTypeScript
brn
8
2.9k
React-Springでリッチなアニメーション
brn
1
690
Other Decks in Programming
See All in Programming
無関心の谷
kanayannet
0
180
Passkeys for Java Developers
ynojima
3
870
F#で自在につくる静的ブログサイト - 関数型まつり2025
pizzacat83
0
310
Cursor AI Agentと伴走する アプリケーションの高速リプレイス
daisuketakeda
1
120
AIネイティブなプロダクトをGolangで挑む取り組み
nmatsumoto4
0
120
「ElixirでIoT!!」のこれまでとこれから
takasehideki
0
370
ASP.NETアプリケーションのモダナイズ インフラ編
tomokusaba
1
380
LINEヤフー データグループ紹介
lycorp_recruit_jp
0
760
赤裸々に公開。 TSKaigiのオフシーズン
takezoux2
0
140
Haskell でアルゴリズムを抽象化する / 関数型言語で競技プログラミング
naoya
17
4.8k
GoのGenericsによるslice操作との付き合い方
syumai
2
660
今ならAmazon ECSのサービス間通信をどう選ぶか / Selection of ECS Interservice Communication 2025
tkikuc
11
2.5k
Featured
See All Featured
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.4k
The Invisible Side of Design
smashingmag
299
51k
Thoughts on Productivity
jonyablonski
69
4.7k
Writing Fast Ruby
sferik
628
61k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
32
5.9k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
29
9.5k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
A designer walks into a library…
pauljervisheath
206
24k
Agile that works and the tools we love
rasmusluckow
329
21k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
35
2.3k
Bash Introduction
62gerente
614
210k
How to Think Like a Performance Engineer
csswizardry
24
1.7k
Transcript
V8 torque
Name @brn (ꫬꅿ⨳ⵃ) Occupation ؿٗٝزؒٝسؒٝآص،٥ط؎ذ؍ـؒٝآص، Company Cyberagent ،سذؙأةآؔ AI Messenger
OSS Contributor of V8 About http://info.b6n.ch
What is torque? V8ⰻ鿇דⵃ欽ׅח⡲DSL TypeScript괏ז俑岀ד葿ղ邌植ׅ
How does it works? torqueכ؝ٝػ؎ׁٕהCSA(CodeStubAssembler)ח㢌䳔ׁ կ CSAכفٓحزؿؓ٦يꬊ⣛㶷זIRד剑穄涸ח،إٝـٓח؝ٝػ ؎ׁٕկ
Why V8 need torque? CSAכ剅ְגהַָ穠圓הְֲַַז׃וְ - ✲佦װְׅ - 僓כ㘗ָⰋגNode㘗חꟼ׆ⰻ鿇涸חכSmiהַ IntPtrהַ㘗ָאְגְגծ♶侭さؒٓ٦ָ⳿װַׅկ
- ⵖ䖴圓俑ָ铣חְֻ
function add100() {! let value = 0;! for (let i
= 0; i < 100; i++) {! value += 1;! }! return value;! }!
TNode<IntPtrT> Add100(TNode<Context> context) {! TVARIABLE(var_value, MachineType::PointerRepresentation(), IntPtrConstant(0));! TVARIABLE(var_index, MachineType::PointerRepresentation(), IntPtrConstant(0));!
! Label loop(this), after_loop(this);! ! Branch(IntPtrGreaterThan(IntPtrConstant(100), var_index), &loop, &after_loop);! BIND(&loop);! {! var_a.Bind(IntPtrAdd(var_a, IntPtrConstant(1)));! Increment(&var_index, 1);! Branch(IntPtrGreaterThan(IntPtrConstant(100), var_index),! &loop, &after_loop);! }! BIND(&after_loop);! return var_value.value;! }!
macro Add100(): Smi {! let value: Smi = 0;! let
len: Smi = 100;! ! for (let i: Smi = 0; k < len; i = i + 1) {! value = value + 1;! }! return value;! }!
torque grammars 㛇劤涸חכ♧菙涸ז䩛竲ֹ㘗鎉铂הずׄ״ֲז俑岀 TypeScriptך㘗،ظذ٦ءّٝ罋ח׃גְ ָծDSLזךד׳ה暴婊ז俑岀㢳ְ
Type Definition TypeScriptך䕎ؒ؎ٔ،أה⡂גְָծֿכC++ך㘗ה torqueⰻ鿇ך䕎ׇ֮湡涸
type Object generates 'TNode<Object>';! type int32 generates 'TNode<Int32T>';!
External functions V8ⰻ鿇חכׅדח㣐ꆀךِ٦ذ؍ٔذ؍ꟼ侧ָ㹀纏ׁגֶծ ⵃ欽ׅחextern䭷㹀㶨ָ㹀纏ׁגְ - macro CSAⰻ鿇ד㹀纏ׁגְِ٦ذ؍ٔذ؍وؙٗ - builtin V8ךbuiltins⟃♴ח֮ꟼ侧纇
- runtime C++ד鎸鶢ׁًاحس
extern macro Print(Object);! ! extern builtin ToObject(Context, Number): Object;! !
extern runtime CreateDataProperty(! Context, Object, String, Object);!
Operators torqueכoperatorꟼ侧ה׃ג㹀纏ֿׅהָדֹ
extern operator "+" macro SmiAdd(Smi, Smi): Smi;! extern operator "-"
macro SmiSub(Smi, Smi): Smi;!
Cast CastכCSAךCastⵃ欽ָׅծ㣟侁׃㜥さחכGotoדٓكٕפ 굲ע
cast<Smi>(a) otherwise CastError!
Labels CSAכההַז⡚ٖكٕז邌植זךדծ if俑װfor俑瘝ךⵖ䖴圓俑גְזְկ ֿ邌植ׅךכׅץגLabelהGotoד֮կ
Branch(var_a, label1, label2)! ! BIND(&label1);! Print("A");! ! BIND(&label2);! Print("B");!
macro Foo(context: Context): Smi labels Bailout, CastError {! Goto Bailout;!
}!
compiler::TNode<Smi> FooFromDSLAssembler::Foo(! TNode<Context> p_context,! Label* label_Bailout_1,! Label* label_CastError_1) {! Goto(label_Bailout_1);!
}!
WriteBarrier V8כ؝ٖٝؕٝز٥؎ًؙٝٔٝةٕGC琎דְךדծ ؔـآؙؑزפך،ؙإأךꥷחכWriteBarrierָ䗳갭ָ ֿCSAך㜥さחכ荈ⴓדWriteBarrier⢪ֲַNoBarrierד遤ֻ ַ鼅䫛׃זֽלזזְկ torqueדכ㼛勻涸חֿֿ荈⹛⻉ׅ✮㹀׃ְ
Compilation 植㖈ךהֿػ٦؟٦כAntlrד剅ַגְ 俑岀涸חכLL(1)דػ٦أ〳腉 㼛勻涸חכ䩛剅ֹךػ٦؟ח׃ְ׃ְ
Compilation V8ךؽٕسفٗإأ⚥ח.tqؿ؋؎ٕךؽٕسָ饥ծ ך穠卓 <ر؍ؙٖزٔせ>-<ؿ؋؎ٕせ>-from-dsl-gen.h/cc הְֲC++ؿ؋؎ָٕ欰䧭ׁ ׁחךؿ؋؎ָٕؽٕسׁغ؎شٔך♧鿇חז
.tq ~-from-dsl-gen.h/cc V8
SourceMaps 植㖈ךהֿفٗزة؎فָծ--gdbjit-fullؔفءّٝדا٦أ⡘ 縧ךوحؾؚٝ׃גְ׃ְ
Summary ؝ٝػ؎ٓך⚥חDSLאֻךכ״ֻ֮鑧ָծ ֿֿתדֹ׃鎉铂כ穠圓棆׃ְ
Reference - https://docs.google.com/presentation/d/ 1PlQEjS5xyJA-0GY8mjB4wr-pLyzFtdMRfhXczJJ2wic/ edit#slide=id.g388aa7220e_2_348 - https://github.com/v8/v8/blob/master/src/builtins/typed- array.tq