rabbit-slide-S_H_-graduating-ruby-literal-object-generation-from-parsey 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ac229630399c80d3bc33c2e27eef2c23d630aa2acb18693f258d44376fa65002
4
+ data.tar.gz: df75e956b8f70cd2efbcfd2727968e54c3e7ba86dc5a959ff610a36cf9c810dd
5
+ SHA512:
6
+ metadata.gz: 746c8612f0b10d2dadbf256aa7bbc385943a96fd24601f64b9ddd7202eb391c5d488f978c0f727b6086b6f1116062b85005ca1fbe13e6b3550e8e36f315a12bb
7
+ data.tar.gz: 1b79dbd7c51d5fe9fd7e54d1ffaad5041281a89ce93b1ca09d1e57fea3809e752ac0776f9d2d7664fff118dcbbacd3ffa194052372e7d5f4bdbcd5bd13afa860
data/.rabbit ADDED
@@ -0,0 +1,2 @@
1
+ --size 1600,900
2
+ graduating-ruby-literal-object-generation-from-parsey.md
data/README.md ADDED
@@ -0,0 +1,24 @@
1
+ # Rubyのリテラルオブジェクト生成をparse.yから卒業させる
2
+
3
+ Fukuoka.rb #333 Ninja Talk 大会で話した「Rubyのリテラルオブジェクト生成をparse.yから卒業させる」のスライドです。
4
+
5
+ ## For author
6
+
7
+ ### Show
8
+
9
+ rake
10
+
11
+ ### Publish
12
+
13
+ rake publish
14
+
15
+ ## For viewers
16
+
17
+ ### Install
18
+
19
+ gem install rabbit-slide-S_H_-wip-graduating-ruby-literal-object-generation-from-parsey
20
+
21
+ ### Show
22
+
23
+ rabbit rabbit-slide-S_H_-wip-graduating-ruby-literal-object-generation-from-parsey.gem
24
+
data/Rakefile ADDED
@@ -0,0 +1,17 @@
1
+ require "rabbit/task/slide"
2
+
3
+ # Edit ./config.yaml to customize meta data
4
+
5
+ spec = nil
6
+ Rabbit::Task::Slide.new do |task|
7
+ spec = task.spec
8
+ # spec.files += Dir.glob("doc/**/*.*")
9
+ # spec.files -= Dir.glob("private/**/*.*")
10
+ # spec.add_runtime_dependency("rabbit-theme-YOUR-THEME")
11
+ end
12
+
13
+ desc "Tag #{spec.version}"
14
+ task :tag do
15
+ sh("git", "tag", "-a", spec.version.to_s, "-m", "Publish #{spec.version}")
16
+ sh("git", "push", "--tags")
17
+ end
data/config.yaml ADDED
@@ -0,0 +1,24 @@
1
+ ---
2
+ id: graduating-ruby-literal-object-generation-from-parsey
3
+ base_name: slide
4
+ tags:
5
+ - rabbit
6
+ presentation_date:
7
+ presentation_start_time:
8
+ presentation_end_time:
9
+ version: 1.0.2
10
+ licenses: []
11
+ slideshare_id:
12
+ speaker_deck_id:
13
+ vimeo_id:
14
+ youtube_id:
15
+ width: 1600
16
+ height: 900
17
+ source_code_uri:
18
+ author:
19
+ markup_language: :markdown
20
+ name: S.H.
21
+ email: gamelinks007@gmail.com
22
+ rubygems_user: S_H_
23
+ slideshare_user:
24
+ speaker_deck_user:
@@ -0,0 +1,169 @@
1
+ # Rubyのリテラルオブジェクト生成をparse.yから卒業させる
2
+
3
+ author
4
+ : S.H.
5
+ theme
6
+ : lightning-simple
7
+ content_source
8
+ : Fukuoka.rb #333 Ninja Talk 大会
9
+
10
+ # 自己紹介
11
+
12
+ * S.H.
13
+ * 永和システムマネジメント
14
+ アジャイル事業部所属 & 構文解析研究部員
15
+ * Hamada.rb
16
+ * 時々Rubyにパッチを投げてます
17
+
18
+ # 話すこと
19
+
20
+ * リテラルオブジェクトの生成をparse.y以外でしたい背景
21
+ * リテラルオブジェクトの生成をparse.y以外でさせる方法
22
+ * 今後の対応
23
+
24
+ # 背景(1)
25
+
26
+ * Numeric などのリテラルが parse.y で Ruby のオブジェクトとして生成されている
27
+ * Ruby のオブジェクトを作っているので GC から離せない
28
+ * parse.y を Universal Parser として扱うためには C API を自前で用意する必要がある
29
+
30
+ # 背景(2)
31
+
32
+ * リテラルの生成を別の場所へ移行できれば
33
+ * GC との切り離しができる
34
+ * Universal Parser の C API への依存を減らすことができる
35
+
36
+ # 背景(3)
37
+
38
+ * より詳しい話は [Ruby Parser開発日誌 (10) - parse.y リファクタリングチャレンジ はじめました](https://yui-knk.hatenablog.com/entry/2023/06/18/162100)
39
+
40
+ # 対応方法(ex: Numeric)
41
+
42
+ * `rubyparser.h`にリテラルの生成に必要な構造体を追加
43
+ * `compile.c`で、その構造体を使ってリテラルを生成する
44
+ * `parse.y`で構造体を使って値をセットする
45
+
46
+ # `rubyparser.h`に構造体を追加
47
+
48
+ ```c
49
+ enum rb_literal_type {
50
+ integer_literal,
51
+ float_literal,
52
+ rational_literal
53
+ };
54
+ ```
55
+
56
+ # `rubyparser.h`に構造体を追加
57
+
58
+ ```c
59
+ typedef struct rb_numeric_literal_info {
60
+ int tminus;
61
+ int base;
62
+ int seen_point;
63
+ int is_imaginary;
64
+ } rb_numeric_literal_info_t;
65
+ ```
66
+
67
+ # `rubyparser.h`に構造体を追加
68
+
69
+ ```c
70
+ typedef struct rb_literal_struct {
71
+ char *val;
72
+ enum rb_literal_type type;
73
+ rb_numeric_literal_info_t numeric_literal_info;
74
+ } rb_literal_t;
75
+ ```
76
+
77
+ # `rubyparser.h`に構造体を追加
78
+
79
+ ```c
80
+ typedef struct RNode_LIT {
81
+ NODE node;
82
+ VALUE nd_lit;
83
+ VALUE not_used;
84
+ VALUE not_used2;
85
+ rb_literal_t *literal;
86
+ } rb_node_lit_t;
87
+ ```
88
+
89
+ # `compile.c`でリテラルを生成
90
+
91
+ ```c
92
+ VALUE
93
+ rb_compile_numeric_literal(rb_literal_t *literal)
94
+ {
95
+ if (literal->type == integer_literal) {
96
+ return rb_compile_integer_literal(literal);
97
+ } else if (literal->type == float_literal) {
98
+ return rb_compile_float_literal(literal);
99
+ } else if (literal->type == rational_literal) {
100
+ return rb_compile_rational_literal(literal);
101
+ }
102
+ return 0;
103
+ }
104
+ ```
105
+
106
+ # `compile.c`でリテラルを生成
107
+
108
+ ```c
109
+ static VALUE
110
+ rb_compile_integer_literal(rb_literal_t *literal)
111
+ {
112
+ VALUE lit = rb_cstr_to_inum(literal->val, literal->numeric_literal_info.base, FALSE);
113
+ return compile_numeric_literal(literal, lit);
114
+ }
115
+ ```
116
+
117
+ # `compile.c`でリテラルを生成
118
+
119
+ ```c
120
+ static VALUE
121
+ compile_numeric_literal(rb_literal_t *literal, VALUE val)
122
+ {
123
+ if (literal->numeric_literal_info.tminus) {
124
+ val = compile_negative_numeric(val);
125
+ }
126
+ if (literal->numeric_literal_info.is_imaginary) {
127
+ val = rb_complex_raw(INT2FIX(0), val);
128
+ }
129
+ return val;
130
+ }
131
+ ```
132
+
133
+
134
+ # `parse.y`で構造体に値をセット
135
+
136
+ ```c
137
+ static enum yytokentype
138
+ set_number_literal(struct parser_params *p, enum yytokentype type, int suffix, int base, int seen_point)
139
+ {
140
+ /* ... */
141
+ rb_literal_t *literal = malloc(sizeof(rb_literal_t));
142
+ literal->val = strdup(tok(p));
143
+ literal->numeric_literal_info.tminus = FALSE;
144
+ literal->numeric_literal_info.base = base;
145
+ literal->numeric_literal_info.seen_point = seen_point;
146
+ literal->numeric_literal_info.is_imaginary = FALSE;
147
+ literal->numeric_literal_info.is_tokenline = FALSE;
148
+ /* ... */
149
+ }
150
+ ```
151
+
152
+ # できたもの
153
+
154
+ * [[WIP] Introduce rb_literal_t struct for purge literal generation in parse.y](https://github.com/S-H-GAMELINKS/ruby/pull/33)
155
+
156
+ ![PR](./img/pr.png)
157
+
158
+ # 対応状況
159
+
160
+ * Numeric(Fixnum, Bignum, Float, Rational, Complex) は対応完了
161
+ * Symbol は一部対応
162
+ * そのほか細々としたものにも対応中
163
+
164
+ # 今後の対応
165
+
166
+ * Ractor 周りでのリテラルオブジェクトの処理
167
+ * NODE_STR などから NODE_LIT へ変換している箇所の対応がまだ
168
+ * とりあえず動くレベルなのでコードの整理をしたい
169
+
data/img/pr.png ADDED
Binary file
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rabbit-slide-S_H_-graduating-ruby-literal-object-generation-from-parsey
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.2
5
+ platform: ruby
6
+ authors:
7
+ - S.H.
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-11-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rabbit
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 2.0.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 2.0.2
27
+ description: 'Fukuoka.rb #333 Ninja Talk 大会で話した「Rubyのリテラルオブジェクト生成をparse.yから卒業させる」のスライドです。'
28
+ email:
29
+ - gamelinks007@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".rabbit"
35
+ - README.md
36
+ - Rakefile
37
+ - config.yaml
38
+ - graduating-ruby-literal-object-generation-from-parsey.md
39
+ - img/pr.png
40
+ - pdf/graduating-ruby-literal-object-generation-from-parsey-slide.pdf
41
+ homepage: https://slide.rabbit-shocker.org/authors/S_H_/graduating-ruby-literal-object-generation-from-parsey/
42
+ licenses: []
43
+ metadata: {}
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubygems_version: 3.5.0.dev
60
+ signing_key:
61
+ specification_version: 4
62
+ summary: Rubyのリテラルオブジェクト生成をparse.yから卒業させる
63
+ test_files: []