thats_it 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 63eaa5162389d62c233ed38e177c7741d846a1d5413b8264faea625f9ba3ecfc
4
+ data.tar.gz: c03840066dc5eef3566d761eb75dbcbfa9a315a3453729c041fd4df032faeb46
5
+ SHA512:
6
+ metadata.gz: ca1ee5f6ae6ec838b53eca1e15ea8816255457b8c9595bbc7e8a504bf3f63bddf9c5b257a7fe62f9d45833ca30d08cfaf01ccca0ac5b12bdf566fa5d1a460a9e
7
+ data.tar.gz: 1615a793fb21fc157bd16442030b16c42f728de548cacb0ba975f0356ad64eb7ed9595f7a49da0b2c4bde4e8666bc63228fe7ec5cdd743eb9d3d8fd221de9c7a
Binary file
Binary file
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ *.bundle
10
+ *.so
11
+ *.o
12
+ *.a
13
+ mkmf.log
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at hanachin@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in thats_it.gemspec
6
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Seiei Miyagi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,54 @@
1
+ # ThatsIt
2
+
3
+ Provide Kotlin's `it` keyword in Ruby.
4
+
5
+ It's experimental ;) Don't use in production.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'thats_it'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install thats_it
22
+
23
+ ## Usage
24
+
25
+ You can use `it` method in a block to get a single parameter of the block like Kotlin's `it` keyword[^1].
26
+ [^1]: https://kotlinlang.org/docs/reference/lambdas.html#it-implicit-name-of-a-single-parameter
27
+
28
+
29
+ 2.yield_self { it * it }
30
+ # => 4
31
+
32
+ def greeting
33
+ yield "Hello, World!"
34
+ end
35
+ greeting { puts it }
36
+ # Hello, World!
37
+
38
+ ## Development
39
+
40
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
41
+
42
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
43
+
44
+ ## Contributing
45
+
46
+ Bug reports and pull requests are welcome on GitHub at https://github.com/hanachin/thats_it. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
47
+
48
+ ## License
49
+
50
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
51
+
52
+ ## Code of Conduct
53
+
54
+ Everyone interacting in the ThatsIt project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/hanachin/thats_it/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,17 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/extensiontask"
3
+ require "rake/testtask"
4
+
5
+ Rake::TestTask.new(:test) do |t|
6
+ t.libs << "test"
7
+ t.libs << "lib"
8
+ t.test_files = FileList['test/**/*_test.rb']
9
+ end
10
+
11
+ task :build => :compile
12
+
13
+ Rake::ExtensionTask.new("thats_it") do |ext|
14
+ ext.lib_dir = "lib/thats_it"
15
+ end
16
+
17
+ task :default => [:clobber, :compile, :test]
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "thats_it"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,6 @@
1
+ require "mkmf"
2
+
3
+ $optflags="-O0"
4
+ $debugflags="-g3"
5
+
6
+ create_makefile("thats_it/thats_it")
@@ -0,0 +1,136 @@
1
+ #include "thats_it.h"
2
+
3
+ static int thats_it_block_p(const rb_iseq_t *iseq) {
4
+ ID id_it;
5
+ if (!iseq) { return 0; }
6
+ if (iseq->body->param.size) { return 0; }
7
+
8
+ id_it = rb_intern("it");
9
+ for (unsigned int i = 0; i < iseq->body->ci_size; i++) {
10
+ if (id_it == iseq->body->ci_entries[i].mid) {
11
+ return 1;
12
+ }
13
+ }
14
+ return 0;
15
+ }
16
+
17
+ static inline enum rb_block_type block_type(const struct rb_block *block) {
18
+ return block->type;
19
+ }
20
+
21
+ static const struct rb_block *proc_block(VALUE procval) {
22
+ return &((rb_proc_t *)RTYPEDDATA_DATA(procval))->block;
23
+ }
24
+
25
+ static const rb_iseq_t *proc_iseq(VALUE procval);
26
+
27
+ static const rb_iseq_t *block_iseq(const struct rb_block *block) {
28
+ switch (block_type(block)) {
29
+ case block_type_iseq:
30
+ return block->as.captured.code.iseq;
31
+ case block_type_proc:
32
+ return proc_iseq(block->as.proc);
33
+ case block_type_ifunc:
34
+ case block_type_symbol:
35
+ break;
36
+ }
37
+ return NULL;
38
+ }
39
+
40
+ static const rb_iseq_t *proc_iseq(VALUE procval) {
41
+ return block_iseq(proc_block(procval));
42
+ }
43
+
44
+ static int block_handler_type_iseq_p(VALUE block_handler) {
45
+ return (block_handler & 0x03) == 0x01;
46
+ }
47
+
48
+ static int block_handler_type_ifunc_p(VALUE block_handler) {
49
+ return (block_handler & 0x03) == 0x03;
50
+ }
51
+
52
+ static enum rb_block_handler_type block_handler_type(VALUE block_handler) {
53
+ if (block_handler_type_iseq_p(block_handler)) {
54
+ return block_handler_type_iseq;
55
+ } else if (block_handler_type_ifunc_p(block_handler)) {
56
+ return block_handler_type_ifunc;
57
+ } else if (SYMBOL_P(block_handler)) {
58
+ return block_handler_type_symbol;
59
+ } else {
60
+ if (!rb_obj_is_proc(block_handler)) {
61
+ rb_raise(rb_eRuntimeError, "unknown block_handler type");
62
+ }
63
+ return block_handler_type_proc;
64
+ }
65
+ }
66
+
67
+ static const rb_iseq_t *block_handler_iseq(VALUE block_handler) {
68
+ switch (block_handler_type(block_handler)) {
69
+ case block_handler_type_iseq:
70
+ {
71
+ struct rb_captured_block *captured = VM_TAGGED_PTR_REF(block_handler, 0x03);
72
+ return captured->code.iseq;
73
+ }
74
+ case block_handler_type_proc:
75
+ {
76
+ return proc_iseq(block_handler);
77
+ }
78
+ case block_handler_type_ifunc:
79
+ case block_handler_type_symbol:
80
+ break;
81
+ }
82
+ return NULL;
83
+ }
84
+
85
+ static const void rewrite_iseq(const rb_iseq_t *iseq) {
86
+ ID *ids = (ID *)ALLOC_N(ID, 1);
87
+ ids[0] = rb_intern("it");
88
+ iseq->body->param.size = 1;
89
+ iseq->body->param.flags.has_lead = 1;
90
+ iseq->body->param.lead_num = 1;
91
+ iseq->body->param.flags.ambiguous_param0 = 1;
92
+ iseq->body->local_table_size = 1;
93
+ ruby_xfree((void *)iseq->body->local_table);
94
+ iseq->body->local_table = ids;
95
+ }
96
+
97
+ static VALUE rb_setup_it_block_c_call() {
98
+ const rb_control_frame_t *cfp = ruby_current_execution_context_ptr->cfp;
99
+ rb_iseq_t *iseq = (rb_iseq_t *)(cfp + 2)->block_code;
100
+
101
+ if (!iseq) { return Qnil; }
102
+ if (!thats_it_block_p(iseq)) { return Qnil; }
103
+
104
+ rewrite_iseq(iseq);
105
+
106
+ return Qnil;
107
+ }
108
+
109
+ static VALUE rb_setup_it_block_call() {
110
+ rb_control_frame_t *cfp = ruby_current_execution_context_ptr->cfp;
111
+ VALUE block_handler = (cfp + 2)->ep[VM_ENV_DATA_INDEX_SPECVAL];
112
+ rb_iseq_t *iseq;
113
+
114
+ if (!block_handler) { return Qnil; }
115
+
116
+ iseq = block_handler_iseq(block_handler);
117
+
118
+ if (!thats_it_block_p(iseq)) { return Qnil; }
119
+
120
+ rewrite_iseq(iseq);
121
+
122
+ return Qnil;
123
+ }
124
+
125
+ static VALUE rb_it() {
126
+ const rb_control_frame_t *cfp = ruby_current_execution_context_ptr->cfp;
127
+ return *(cfp + 2)->sp;
128
+ }
129
+
130
+ void
131
+ Init_thats_it(void)
132
+ {
133
+ rb_define_global_function("setup_it_block_c_call", rb_setup_it_block_c_call, 0);
134
+ rb_define_global_function("setup_it_block_call", rb_setup_it_block_call, 0);
135
+ rb_define_global_function("it", rb_it, 0);
136
+ }
@@ -0,0 +1,15 @@
1
+ #ifndef THATS_IT_H
2
+ #define THATS_IT_H 1
3
+
4
+ #include "setjmp.h"
5
+ #include "ruby.h"
6
+ #include "ruby/ruby.h"
7
+ #include "ruby/version.h"
8
+
9
+ #endif /* THATS_IT_H */
10
+
11
+ #if RUBY_API_VERSION_CODE >= 20600
12
+ #include "thats_it_20600.h"
13
+ #elif RUBY_API_VERSION_CODE >= 20500
14
+ #include "thats_it_20500.h"
15
+ #endif
@@ -0,0 +1,290 @@
1
+ /*
2
+ copy from ruby source code
3
+ https://github.com/ruby/ruby/blob/trunk/COPYING.ja
4
+ */
5
+
6
+ #define VM_ENV_DATA_INDEX_SPECVAL (-1) /* ep[-1] */
7
+
8
+ /* for setup_it_block */
9
+ #define VM_TAGGED_PTR_REF(v, mask) ((void *)((v) & ~mask))
10
+
11
+ typedef struct rb_code_location_struct {
12
+ int lineno;
13
+ int column;
14
+ } rb_code_location_t;
15
+
16
+ typedef struct rb_code_range_struct {
17
+ rb_code_location_t first_loc;
18
+ rb_code_location_t last_loc;
19
+ } rb_code_range_t;
20
+
21
+ typedef struct rb_iseq_location_struct {
22
+ VALUE pathobj; /* String (path) or Array [path, realpath]. Frozen. */
23
+ VALUE base_label; /* String */
24
+ VALUE label; /* String */
25
+ VALUE first_lineno; /* TODO: may be unsigned short */
26
+ rb_code_range_t code_range;
27
+ } rb_iseq_location_t;
28
+
29
+ struct rb_call_info {
30
+ /* fixed at compile time */
31
+ ID mid;
32
+ unsigned int flag;
33
+ int orig_argc;
34
+ };
35
+
36
+ struct rb_iseq_constant_body {
37
+ enum iseq_type {
38
+ ISEQ_TYPE_TOP,
39
+ ISEQ_TYPE_METHOD,
40
+ ISEQ_TYPE_BLOCK,
41
+ ISEQ_TYPE_CLASS,
42
+ ISEQ_TYPE_RESCUE,
43
+ ISEQ_TYPE_ENSURE,
44
+ ISEQ_TYPE_EVAL,
45
+ ISEQ_TYPE_MAIN,
46
+ ISEQ_TYPE_DEFINED_GUARD
47
+ } type; /* instruction sequence type */
48
+
49
+ unsigned int iseq_size;
50
+ const VALUE *iseq_encoded; /* encoded iseq (insn addr and operands) */
51
+
52
+ /**
53
+ * parameter information
54
+ *
55
+ * def m(a1, a2, ..., aM, # mandatory
56
+ * b1=(...), b2=(...), ..., bN=(...), # optional
57
+ * *c, # rest
58
+ * d1, d2, ..., dO, # post
59
+ * e1:(...), e2:(...), ..., eK:(...), # keyword
60
+ * **f, # keyword_rest
61
+ * &g) # block
62
+ * =>
63
+ *
64
+ * lead_num = M
65
+ * opt_num = N
66
+ * rest_start = M+N
67
+ * post_start = M+N+(*1)
68
+ * post_num = O
69
+ * keyword_num = K
70
+ * block_start = M+N+(*1)+O+K
71
+ * keyword_bits = M+N+(*1)+O+K+(&1)
72
+ * size = M+N+O+(*1)+K+(&1)+(**1) // parameter size.
73
+ */
74
+
75
+ struct {
76
+ struct {
77
+ unsigned int has_lead : 1;
78
+ unsigned int has_opt : 1;
79
+ unsigned int has_rest : 1;
80
+ unsigned int has_post : 1;
81
+ unsigned int has_kw : 1;
82
+ unsigned int has_kwrest : 1;
83
+ unsigned int has_block : 1;
84
+
85
+ unsigned int ambiguous_param0 : 1; /* {|a|} */
86
+ } flags;
87
+
88
+ unsigned int size;
89
+
90
+ int lead_num;
91
+ int opt_num;
92
+ int rest_start;
93
+ int post_start;
94
+ int post_num;
95
+ int block_start;
96
+
97
+ const VALUE *opt_table; /* (opt_num + 1) entries. */
98
+ /* opt_num and opt_table:
99
+ *
100
+ * def foo o1=e1, o2=e2, ..., oN=eN
101
+ * #=>
102
+ * # prologue code
103
+ * A1: e1
104
+ * A2: e2
105
+ * ...
106
+ * AN: eN
107
+ * AL: body
108
+ * opt_num = N
109
+ * opt_table = [A1, A2, ..., AN, AL]
110
+ */
111
+
112
+ const struct rb_iseq_param_keyword {
113
+ int num;
114
+ int required_num;
115
+ int bits_start;
116
+ int rest_start;
117
+ const ID *table;
118
+ const VALUE *default_values;
119
+ } *keyword;
120
+ } param;
121
+
122
+ rb_iseq_location_t location;
123
+
124
+ /* insn info, must be freed */
125
+ const struct iseq_insn_info_entry *insns_info;
126
+
127
+ const ID *local_table; /* must free */
128
+
129
+ /* catch table */
130
+ const struct iseq_catch_table *catch_table;
131
+
132
+ /* for child iseq */
133
+ const struct rb_iseq_struct *parent_iseq;
134
+ struct rb_iseq_struct *local_iseq; /* local_iseq->flip_cnt can be modified */
135
+
136
+ union iseq_inline_storage_entry *is_entries;
137
+ struct rb_call_info *ci_entries; /* struct rb_call_info ci_entries[ci_size];
138
+ * struct rb_call_info_with_kwarg cikw_entries[ci_kw_size];
139
+ * So that:
140
+ * struct rb_call_info_with_kwarg *cikw_entries = &body->ci_entries[ci_size];
141
+ */
142
+ struct rb_call_cache *cc_entries; /* size is ci_size = ci_kw_size */
143
+
144
+ VALUE mark_ary; /* Array: includes operands which should be GC marked */
145
+
146
+ unsigned int local_table_size;
147
+ unsigned int is_size;
148
+ unsigned int ci_size;
149
+ unsigned int ci_kw_size;
150
+ unsigned int insns_info_size;
151
+ unsigned int stack_max; /* for stack overflow check */
152
+ };
153
+
154
+ /* T_IMEMO/iseq */
155
+ /* typedef rb_iseq_t is in method.h */
156
+ struct rb_iseq_struct {
157
+ VALUE flags;
158
+ VALUE reserved1;
159
+ struct rb_iseq_constant_body *body;
160
+
161
+ union { /* 4, 5 words */
162
+ /* struct iseq_compile_data *compile_data; /\* used at compile time *\/ */
163
+ void *compile_data;
164
+
165
+ struct {
166
+ VALUE obj;
167
+ int index;
168
+ } loader;
169
+
170
+ rb_event_flag_t trace_events;
171
+ } aux;
172
+ };
173
+
174
+ typedef struct rb_iseq_struct rb_iseq_t;
175
+
176
+ struct rb_captured_block {
177
+ VALUE self;
178
+ const VALUE *ep;
179
+ union {
180
+ const rb_iseq_t *iseq;
181
+ const struct vm_ifunc *ifunc;
182
+ VALUE val;
183
+ } code;
184
+ };
185
+
186
+ enum rb_block_type {
187
+ block_type_iseq,
188
+ block_type_ifunc,
189
+ block_type_symbol,
190
+ block_type_proc
191
+ };
192
+
193
+ enum rb_block_handler_type {
194
+ block_handler_type_iseq,
195
+ block_handler_type_ifunc,
196
+ block_handler_type_symbol,
197
+ block_handler_type_proc
198
+ };
199
+
200
+ struct rb_block {
201
+ union {
202
+ struct rb_captured_block captured;
203
+ VALUE symbol;
204
+ VALUE proc;
205
+ } as;
206
+ enum rb_block_type type;
207
+ };
208
+
209
+ typedef struct {
210
+ const struct rb_block block;
211
+ unsigned int is_from_method: 1; /* bool */
212
+ unsigned int is_lambda: 1; /* bool */
213
+ } rb_proc_t;
214
+
215
+ /* for it */
216
+ enum method_missing_reason { FOO };
217
+
218
+ typedef struct rb_control_frame_struct {
219
+ const VALUE *pc; /* cfp[0] */
220
+ VALUE *sp; /* cfp[1] */
221
+ const rb_iseq_t *iseq; /* cfp[2] */
222
+ VALUE self; /* cfp[3] / block[0] */
223
+ const VALUE *ep; /* cfp[4] / block[1] */
224
+ const void *block_code; /* cfp[5] / block[2] */ /* iseq or ifunc */
225
+ } rb_control_frame_t;
226
+
227
+ typedef struct rb_execution_context_struct {
228
+ /* execution information */
229
+ VALUE *vm_stack; /* must free, must mark */
230
+ size_t vm_stack_size; /* size in word (byte size / sizeof(VALUE)) */
231
+ rb_control_frame_t *cfp;
232
+
233
+ /* struct rb_vm_tag *tag; */
234
+ /* struct rb_vm_protect_tag *protect_tag; */
235
+ void *tag;
236
+ void *protect_tag;
237
+ int safe_level;
238
+ int raised_flag;
239
+
240
+ /* interrupt flags */
241
+ /* rb_atomic_t interrupt_flag; */
242
+ unsigned long interrupt_flag;
243
+ unsigned long interrupt_mask;
244
+
245
+ /* rb_fiber_t *fiber_ptr; */
246
+ /* struct rb_thread_struct *thread_ptr; */
247
+ void *fiber_ptr;
248
+ void *thread_ptr;
249
+
250
+ /* storage (ec (fiber) local) */
251
+ /* st_table *local_storage; */
252
+ void *local_storage;
253
+ VALUE local_storage_recursive_hash;
254
+ VALUE local_storage_recursive_hash_for_trace;
255
+
256
+ /* eval env */
257
+ const VALUE *root_lep;
258
+ VALUE root_svar;
259
+
260
+ /* ensure & callcc */
261
+ /* rb_ensure_list_t *ensure_list; */
262
+ void *ensure_list;
263
+
264
+ /* trace information */
265
+ /* struct rb_trace_arg_struct *trace_arg; */
266
+ void *trace_arg;
267
+
268
+ /* temporary places */
269
+ VALUE errinfo;
270
+ VALUE passed_block_handler; /* for rb_iterate */
271
+ /* const rb_callable_method_entry_t *passed_bmethod_me; /\* for bmethod *\/ */
272
+ /* enum method_missing_reason method_missing_reason; */
273
+ void *passed_bmethod_me;
274
+ enum method_missing_reason method_missing_reason;
275
+
276
+ /* for GC */
277
+ struct {
278
+ VALUE *stack_start;
279
+ VALUE *stack_end;
280
+ size_t stack_maxsize;
281
+ #ifdef __ia64
282
+ VALUE *register_stack_start;
283
+ VALUE *register_stack_end;
284
+ size_t register_stack_maxsize;
285
+ #endif
286
+ jmp_buf regs;
287
+ } machine;
288
+ } rb_execution_context_t;
289
+
290
+ extern rb_execution_context_t *ruby_current_execution_context_ptr;
@@ -0,0 +1,288 @@
1
+ /*
2
+ copy from ruby source code
3
+ https://github.com/ruby/ruby/blob/trunk/COPYING.ja
4
+ */
5
+
6
+ #define VM_ENV_DATA_INDEX_SPECVAL (-1) /* ep[-1] */
7
+
8
+ /* for setup_it_block */
9
+
10
+ #define VM_TAGGED_PTR_REF(v, mask) ((void *)((v) & ~mask))
11
+
12
+ typedef struct rb_code_position_struct {
13
+ int lineno;
14
+ int column;
15
+ } rb_code_position_t;
16
+
17
+ typedef struct rb_code_location_struct {
18
+ rb_code_position_t beg_pos;
19
+ rb_code_position_t end_pos;
20
+ } rb_code_location_t;
21
+
22
+ typedef struct rb_iseq_location_struct {
23
+ VALUE pathobj; /* String (path) or Array [path, realpath]. Frozen. */
24
+ VALUE base_label; /* String */
25
+ VALUE label; /* String */
26
+ VALUE first_lineno; /* TODO: may be unsigned short */
27
+ rb_code_location_t code_location;
28
+ } rb_iseq_location_t;
29
+
30
+ typedef signed long rb_snum_t;
31
+
32
+ struct rb_call_info {
33
+ /* fixed at compile time */
34
+ ID mid;
35
+ unsigned int flag;
36
+ int orig_argc;
37
+ };
38
+
39
+ struct rb_iseq_constant_body {
40
+ enum iseq_type {
41
+ ISEQ_TYPE_TOP,
42
+ ISEQ_TYPE_METHOD,
43
+ ISEQ_TYPE_BLOCK,
44
+ ISEQ_TYPE_CLASS,
45
+ ISEQ_TYPE_RESCUE,
46
+ ISEQ_TYPE_ENSURE,
47
+ ISEQ_TYPE_EVAL,
48
+ ISEQ_TYPE_MAIN,
49
+ ISEQ_TYPE_PLAIN
50
+ } type; /* instruction sequence type */
51
+
52
+ unsigned int iseq_size;
53
+ const VALUE *iseq_encoded; /* encoded iseq (insn addr and operands) */
54
+
55
+ /**
56
+ * parameter information
57
+ *
58
+ * def m(a1, a2, ..., aM, # mandatory
59
+ * b1=(...), b2=(...), ..., bN=(...), # optional
60
+ * *c, # rest
61
+ * d1, d2, ..., dO, # post
62
+ * e1:(...), e2:(...), ..., eK:(...), # keyword
63
+ * **f, # keyword_rest
64
+ * &g) # block
65
+ * =>
66
+ *
67
+ * lead_num = M
68
+ * opt_num = N
69
+ * rest_start = M+N
70
+ * post_start = M+N+(*1)
71
+ * post_num = O
72
+ * keyword_num = K
73
+ * block_start = M+N+(*1)+O+K
74
+ * keyword_bits = M+N+(*1)+O+K+(&1)
75
+ * size = M+N+O+(*1)+K+(&1)+(**1) // parameter size.
76
+ */
77
+
78
+ struct {
79
+ struct {
80
+ unsigned int has_lead : 1;
81
+ unsigned int has_opt : 1;
82
+ unsigned int has_rest : 1;
83
+ unsigned int has_post : 1;
84
+ unsigned int has_kw : 1;
85
+ unsigned int has_kwrest : 1;
86
+ unsigned int has_block : 1;
87
+
88
+ unsigned int ambiguous_param0 : 1; /* {|a|} */
89
+ } flags;
90
+
91
+ unsigned int size;
92
+
93
+ int lead_num;
94
+ int opt_num;
95
+ int rest_start;
96
+ int post_start;
97
+ int post_num;
98
+ int block_start;
99
+
100
+ const VALUE *opt_table; /* (opt_num + 1) entries. */
101
+ /* opt_num and opt_table:
102
+ *
103
+ * def foo o1=e1, o2=e2, ..., oN=eN
104
+ * #=>
105
+ * # prologue code
106
+ * A1: e1
107
+ * A2: e2
108
+ * ...
109
+ * AN: eN
110
+ * AL: body
111
+ * opt_num = N
112
+ * opt_table = [A1, A2, ..., AN, AL]
113
+ */
114
+
115
+ const struct rb_iseq_param_keyword {
116
+ int num;
117
+ int required_num;
118
+ int bits_start;
119
+ int rest_start;
120
+ const ID *table;
121
+ const VALUE *default_values;
122
+ } *keyword;
123
+ } param;
124
+
125
+ rb_iseq_location_t location;
126
+
127
+ /* insn info, must be freed */
128
+ struct iseq_insn_info {
129
+ const struct iseq_insn_info_entry *body;
130
+ unsigned int *positions;
131
+ unsigned int size;
132
+ struct succ_index_table *succ_index_table;
133
+ } insns_info;
134
+
135
+ ID *local_table; /* must free */
136
+
137
+ /* catch table */
138
+ const struct iseq_catch_table *catch_table;
139
+
140
+ /* for child iseq */
141
+ const struct rb_iseq_struct *parent_iseq;
142
+ struct rb_iseq_struct *local_iseq; /* local_iseq->flip_cnt can be modified */
143
+
144
+ union iseq_inline_storage_entry *is_entries;
145
+ struct rb_call_info *ci_entries; /* struct rb_call_info ci_entries[ci_size];
146
+ * struct rb_call_info_with_kwarg cikw_entries[ci_kw_size];
147
+ * So that:
148
+ * struct rb_call_info_with_kwarg *cikw_entries = &body->ci_entries[ci_size];
149
+ */
150
+ struct rb_call_cache *cc_entries; /* size is ci_size = ci_kw_size */
151
+
152
+ struct {
153
+ rb_snum_t flip_count;
154
+ VALUE coverage;
155
+ VALUE *original_iseq;
156
+ } variable;
157
+
158
+ unsigned int local_table_size;
159
+ unsigned int is_size;
160
+ unsigned int ci_size;
161
+ unsigned int ci_kw_size;
162
+ unsigned int stack_max; /* for stack overflow check */
163
+
164
+ /* The following fields are MJIT related info. */
165
+ VALUE (*jit_func)(struct rb_execution_context_struct *,
166
+ struct rb_control_frame_struct *); /* function pointer for loaded native code */
167
+ long unsigned total_calls; /* number of total calls with `mjit_exec()` */
168
+ struct rb_mjit_unit *jit_unit;
169
+ char catch_except_p; /* If a frame of this ISeq may catch exception, set TRUE */
170
+ };
171
+
172
+ /* T_IMEMO/iseq */
173
+ /* typedef rb_iseq_t is in method.h */
174
+ struct rb_iseq_struct {
175
+ VALUE flags;
176
+ VALUE reserved1;
177
+ struct rb_iseq_constant_body *body;
178
+
179
+ union { /* 4, 5 words */
180
+ /* struct iseq_compile_data *compile_data; /\* used at compile time *\/ */
181
+ void *compile_data; /* used at compile time */
182
+
183
+ struct {
184
+ VALUE obj;
185
+ int index;
186
+ } loader;
187
+
188
+ rb_event_flag_t trace_events;
189
+ } aux;
190
+ };
191
+
192
+ typedef struct rb_iseq_struct rb_iseq_t;
193
+
194
+ struct rb_captured_block {
195
+ VALUE self;
196
+ const VALUE *ep;
197
+ union {
198
+ const rb_iseq_t *iseq;
199
+ const struct vm_ifunc *ifunc;
200
+ VALUE val;
201
+ } code;
202
+ };
203
+
204
+
205
+ enum rb_block_type {
206
+ block_type_iseq,
207
+ block_type_ifunc,
208
+ block_type_symbol,
209
+ block_type_proc
210
+ };
211
+
212
+ enum rb_block_handler_type {
213
+ block_handler_type_iseq,
214
+ block_handler_type_ifunc,
215
+ block_handler_type_symbol,
216
+ block_handler_type_proc
217
+ };
218
+
219
+ struct rb_block {
220
+ union {
221
+ struct rb_captured_block captured;
222
+ VALUE symbol;
223
+ VALUE proc;
224
+ } as;
225
+ enum rb_block_type type;
226
+ };
227
+
228
+ typedef struct {
229
+ const struct rb_block block;
230
+ unsigned int is_from_method: 1; /* bool */
231
+ unsigned int is_lambda: 1; /* bool */
232
+ } rb_proc_t;
233
+
234
+ /* for it */
235
+ enum method_missing_reason { FOO };
236
+
237
+ typedef struct rb_control_frame_struct {
238
+ const VALUE *pc;
239
+ VALUE *sp;
240
+ const rb_iseq_t *iseq;
241
+ VALUE self;
242
+ const VALUE *ep;
243
+ const void *block_code;
244
+ const VALUE *bp;
245
+ } rb_control_frame_t;
246
+
247
+ typedef struct rb_execution_context_struct {
248
+ VALUE *vm_stack;
249
+ size_t vm_stack_size;
250
+ rb_control_frame_t *cfp;
251
+ /* struct rb_vm_tag *tag; */
252
+ /* struct rb_vm_protect_tag *protect_tag; */
253
+ void *tag;
254
+ void *protect_tag;
255
+ int raised_flag;
256
+ /* rb_atomic_t interrupt_flag; */
257
+ /* rb_atomic_t interrupt_mask; */
258
+ unsigned int interrupt_flag;
259
+ unsigned int interrupt_mask;
260
+ /* rb_fiber_t *fiber_ptr; */
261
+ /* struct rb_thread_struct *thread_ptr; */
262
+ /* st_table *local_storage; */
263
+ void *fiber_ptr;
264
+ void *thread_ptr;
265
+ void *local_storage;
266
+ VALUE local_storage_recursive_hash;
267
+ VALUE local_storage_recursive_hash_for_trace;
268
+ const VALUE *root_lep;
269
+ VALUE root_svar;
270
+ /* rb_ensure_list_t *ensure_list; */
271
+ /* struct rb_trace_arg_struct *trace_arg; */
272
+ void *ensure_list;
273
+ void *trace_arg;
274
+ VALUE errinfo;
275
+ VALUE passed_block_handler;
276
+ /* const rb_callable_method_entry_t *passed_bmethod_me; */
277
+ /* enum method_missing_reason method_missing_reason; */
278
+ void *passed_bmethod_me;
279
+ enum method_missing_reason method_missing_reason;
280
+ struct {
281
+ VALUE *stack_start;
282
+ VALUE *stack_end;
283
+ size_t stack_maxsize;
284
+ __attribute__((__aligned__(8))) jmp_buf regs;
285
+ } machine;
286
+ } rb_execution_context_t;
287
+
288
+ extern rb_execution_context_t *ruby_current_execution_context_ptr;
@@ -0,0 +1,7 @@
1
+ require "thats_it/version"
2
+ require "thats_it/thats_it"
3
+
4
+ module ThatsIt
5
+ CALL_TP = TracePoint.trace(:call) { |tp| setup_it_block_call }
6
+ C_CALL_TP = TracePoint.trace(:c_call) { |tp| setup_it_block_c_call }
7
+ end
@@ -0,0 +1,3 @@
1
+ module ThatsIt
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,33 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "thats_it/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "thats_it"
8
+ spec.version = ThatsIt::VERSION
9
+ spec.authors = ["Seiei Miyagi"]
10
+ spec.email = ["hanachin@gmail.com"]
11
+
12
+ spec.summary = %q{Provide Kotlin's `it` keyword in Ruby.}
13
+ spec.description = %q{You can use `it` method in a block to get a single parameter of the block like Kotlin's `it` keyword}
14
+ spec.homepage = "https://github.com/hanachin/thats_it"
15
+ spec.license = "MIT"
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
25
+ spec.extensions = ["ext/thats_it/extconf.rb"]
26
+
27
+ spec.required_ruby_version = '>= 2.5.0'
28
+
29
+ spec.add_development_dependency "bundler", "~> 1.16"
30
+ spec.add_development_dependency "rake", "~> 10.0"
31
+ spec.add_development_dependency "rake-compiler"
32
+ spec.add_development_dependency "test-unit"
33
+ end
metadata ADDED
@@ -0,0 +1,144 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: thats_it
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Seiei Miyagi
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIEODCCAqCgAwIBAgIBATANBgkqhkiG9w0BAQsFADAjMSEwHwYDVQQDDBhoYW5h
14
+ Y2hpbi9EQz1nbWFpbC9EQz1jb20wHhcNMTgwNjAxMTExMDAyWhcNMTkwNjAxMTEx
15
+ MDAyWjAjMSEwHwYDVQQDDBhoYW5hY2hpbi9EQz1nbWFpbC9EQz1jb20wggGiMA0G
16
+ CSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQDsXXR8HJ8E0dujOixOIb9RDFaya8t/
17
+ ehq2rPIdNdtjmsphryZQusm8PW0Ql12Yt8z/hZX6Cl3wOGoDwTv9ru1z55+DSw7I
18
+ ayJPGwKTgS9KFEf1q7koVQeaUSLRHFT8kOZn6YNaHACTNkCOUzpXH8sI2Z7hxwjH
19
+ P2CDmyrQKoT6mLmLzh/YvyFqNdQXLGXwQsOaO0CAB5f42oIy78A+FdVolH/vTx0A
20
+ PKHsuzqZR0ZKv8r8MH7qmK5XA7mmxyNIuifCGqIU3jER1YhJj/hm2bCPQjGnwsEm
21
+ TPPkoo/VdAxPvoOwsRitgXEHEg+7PBEsUD8bacdnCvG0y/Bi7yIwFVQh5GKRiJML
22
+ OVzHX5C1ywES7Aob3VSaIylQHXIQ684FCvt32TxuCx/0Dura9B+5FHYp0CjNiS+9
23
+ rdhKDaAePSmKppIv2fAOYN0xRDjNU/XPIH6WNh3qp0KkGy5BtjK1DTL/FUcKKt+G
24
+ iZHN0VDev+Zia32VNyHncZfUR2GgDcrWKd8CAwEAAaN3MHUwCQYDVR0TBAIwADAL
25
+ BgNVHQ8EBAMCBLAwHQYDVR0OBBYEFFJfQEa1jViT1bAbLKXfbAuUONBUMB0GA1Ud
26
+ EQQWMBSBEmhhbmFjaGluQGdtYWlsLmNvbTAdBgNVHRIEFjAUgRJoYW5hY2hpbkBn
27
+ bWFpbC5jb20wDQYJKoZIhvcNAQELBQADggGBAAOUkk0oc4OnOIyZ/KA2QqJwcyAz
28
+ rpl/Q8125b/3yvyfghN9xGFDL6zZ+pR+pt9YJ+TlBlGvIKw+i5mTe/nHSOr4+NyW
29
+ WHOKA7lTi4rgFT5oCqZrE9yJCUpAex921lXSEZg7f2zFZwgKQkdpASUHfvZsHJt/
30
+ b3hDk/Cw1FwVVBouIvdUFZBSJW71ggkpLYTERD2vqMU/8buIw954rDyaf3WzT4WT
31
+ X+4pVer2L5SN4cuxa1d/OEImJioGP7+tjocen+su3+uL4J0ck+8zEo9gUVEoVFz+
32
+ GcY06QPq9ePmuF04TJJDCJNdLJrD8JFeQpe4yGUiSvAAS4Zo4NKt5F9mGheP/T0f
33
+ 7AtB9OsSwXmofmNtdn1v9oswC64lFvfPThCtvAQsvlds/gZPq4B8W+8Xi/qdGVjS
34
+ OKwDKKYe2ogJ/XrOjTltlugSNvq/NgD53wc4TA0F5KofdIZSJELTCUyyZMPztwI4
35
+ OawPtyIyOegL6pM8fc7IfzLzjkdO3Bis1qFZcg==
36
+ -----END CERTIFICATE-----
37
+ date: 2018-07-06 00:00:00.000000000 Z
38
+ dependencies:
39
+ - !ruby/object:Gem::Dependency
40
+ name: bundler
41
+ requirement: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - "~>"
44
+ - !ruby/object:Gem::Version
45
+ version: '1.16'
46
+ type: :development
47
+ prerelease: false
48
+ version_requirements: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - "~>"
51
+ - !ruby/object:Gem::Version
52
+ version: '1.16'
53
+ - !ruby/object:Gem::Dependency
54
+ name: rake
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '10.0'
60
+ type: :development
61
+ prerelease: false
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - "~>"
65
+ - !ruby/object:Gem::Version
66
+ version: '10.0'
67
+ - !ruby/object:Gem::Dependency
68
+ name: rake-compiler
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ type: :development
75
+ prerelease: false
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ - !ruby/object:Gem::Dependency
82
+ name: test-unit
83
+ requirement: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ description: You can use `it` method in a block to get a single parameter of the block
96
+ like Kotlin's `it` keyword
97
+ email:
98
+ - hanachin@gmail.com
99
+ executables: []
100
+ extensions:
101
+ - ext/thats_it/extconf.rb
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - CODE_OF_CONDUCT.md
106
+ - Gemfile
107
+ - LICENSE.txt
108
+ - README.md
109
+ - Rakefile
110
+ - bin/console
111
+ - bin/setup
112
+ - ext/thats_it/extconf.rb
113
+ - ext/thats_it/thats_it.c
114
+ - ext/thats_it/thats_it.h
115
+ - ext/thats_it/thats_it_20500.h
116
+ - ext/thats_it/thats_it_20600.h
117
+ - lib/thats_it.rb
118
+ - lib/thats_it/version.rb
119
+ - thats_it.gemspec
120
+ homepage: https://github.com/hanachin/thats_it
121
+ licenses:
122
+ - MIT
123
+ metadata: {}
124
+ post_install_message:
125
+ rdoc_options: []
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: 2.5.0
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ requirements: []
139
+ rubyforge_project:
140
+ rubygems_version: 2.7.6
141
+ signing_key:
142
+ specification_version: 4
143
+ summary: Provide Kotlin's `it` keyword in Ruby.
144
+ test_files: []
@@ -0,0 +1,4 @@
1
+ 1������6��,X=������۳���8���=����ѓ�T��P
2
+ �G0�ݏ�B�Ȏ�0^(�6Ͳt�ѡF1�����.�#FP� ��T���g��3&&3lg�Tu����*Ʌ^�b
3
+ ��b�M�o\��.����,8^�$�FD��~�?U�:���>rL 4Kz/���=c���x���
4
+ q��R�a%>�F'�Fz�8�+��Ŀ�j�5��;�t��ʓ��pD� �B�`o�_��ۖ�MGD��}Y��������;���5���6�Dn)�>}�4謅�,Wl�2 Tb~d��D�4��Tm{c7���