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
How is magic formed
Search
Rin Raeuber
July 03, 2014
Programming
910
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
How is magic formed
Short excursion into Ruby Internals, Ruby Usergroup Berlin, June 3rd 2014
Rin Raeuber
July 03, 2014
More Decks by Rin Raeuber
See All by Rin Raeuber
Das Internet of Things mit dem ESP2866
rin
0
190
Let's create a game with Ruby
rin
1
120
Hallo, wir sind die Cyborgs: Implantate, Body-Hacks und Rock ‘n Roll
rin
1
110
Let's go to Mars #rp14
rin
0
280
Angular Directives For The Rest Of Us
rin
1
350
Other Decks in Programming
See All in Programming
VibeCodingからAgenticWorkflowへ
starfish719
0
230
PHP Application における Kubernetes 内 gRPC 通信
ganchiku
0
580
使用 Meilisearch 建立新聞搜尋工具
johnroyer
0
220
PostgreSQL 18で考えるUUID主キー
kazuhiro1982
0
460
Detecting Compromised CI with eBPF and Cilium Tetragon
lizrice
0
130
Lean は証明の正しさを確認するためだけのツールって思ってませんか?
inoueasei
1
140
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
520
メールのエイリアス機能を履き違えない
isshinfunada
0
220
komatsuna「分散システムにおけるバグ分析手法」
komatsunaqa
0
230
なぜ関数型プログラミングで「型」と「証明」が語られるのか #fp_matsuri
kajitack
3
1.1k
php-fpmのプロセスが枯渇した日-調査・対処・そして本当にやるべきだったこと-
shibuchaaaan
0
210
React本体のコードリーディング
high_g_engineer
1
130
Featured
See All Featured
Bash Introduction
62gerente
615
220k
Building Adaptive Systems
keathley
44
3.2k
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
190
First, design no harm
axbom
PRO
2
1.2k
A Tale of Four Properties
chriscoyier
163
24k
From π to Pie charts
rasagy
0
250
Faster Mobile Websites
deanohume
310
32k
Designing for Performance
lara
611
70k
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
160
WENDY [Excerpt]
tessaabrams
11
39k
Become a Pro
speakerdeck
PRO
31
6.1k
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
890
Transcript
How is ! magic ! formed
Rin! @rinpaku @bitcrowd
None
WHY?
TIL: There’s bacon in! the Ruby source code
What happens when Ruby runs my code?! ! What is
an Object?
What happens ! when Ruby ! runs my code?
Ruby code 9.times do puts "Ente" end
Tokens 9 . t i m e s …
9 . times do puts "" Tokens 9 . t
i m e s … integer identifier identifier period keyword strin
Syntax Tree do_block period method_add_block integer! 9 identifier! times call
command identifier! puts …
YARV instructions “Yet Another Ruby Virtual Machine” == catch table
| catch type: break st: 0002 ed: 0006 sp: 0000 cont: 0006 |-------------------------------------------------------------- 0000 trace 1 0002 putobject 9 0004 send <callinfo!mid:times, argc:0, block:block 0006 leave == disasm: <RubyVM::InstructionSequence:block in <compiled>@<co == catch table | catch type: redo st: 0000 ed: 0009 sp: 0000 cont: 0000 | catch type: next st: 0000 ed: 0009 sp: 0000 cont: 0009 |-------------------------------------------------------------- 0000 trace 256 0002 trace 1 0004 putself 0005 putstring "Ente"
I MIGHT! HAVE MADE THIS ALL UP
Tokenizing Ripper.lex(your_code)
parse.c
with Ripper: Ripper.sexp(your_code) ! Parsing
with Ripper: Ripper.sexp(your_code) parser debug information: ruby -y example.rb Parsing
RubyVM::InstructionSequence. compile(code).disasm Compiling
What ! is an! Object?
struct meetup { char title[120]; time_t starts_at; bool has_talks; };
Structs
union location { char address[120]; struct position { int latitude;
int longitude; } }; Union
struct meetup { char title[120]; time_t starts_at; bool has_talks; union
{ char address[120]; struct position { int latitude; int longitude; } } };
Let’s look at some source code
RObject struct RObject { struct RBasic basic; … };
RBasic struct RBasic { VALUE flags; const VALUE klass; };
RObject struct RObject { struct RBasic basic; struct { long
numiv; VALUE *ivptr; struct st_table *iv_index_tbl; } heap; }; simplified
RObject struct RObject { struct RBasic basic; union { struct
{ long numiv; VALUE *ivptr; struct st_table *iv_index_tbl; } heap; VALUE ary[ROBJECT_EMBED_LEN_MAX]; } as; };
RFloat struct RFloat { struct RBasic basic; double float_value; };
- Reading C is not that bad.* *(If you
hate it, you can still look at the Standard Library or Rubinius.)! ! - Check out the Ruby source code and give a talk about it. ;) Things to take home
WAIT! Where’s the bacon?
Never create Ruby Strings longer than 23 characters ! Ruby
under a microscope (the book) ! The Ruby Hacking Guide (Warning: Ruby 1.7.3!) ! A Tour of the Ruby MRI Source Code with Pat Shaughnessy Some Links