thats_it 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 63eaa5162389d62c233ed38e177c7741d846a1d5413b8264faea625f9ba3ecfc
4
- data.tar.gz: c03840066dc5eef3566d761eb75dbcbfa9a315a3453729c041fd4df032faeb46
3
+ metadata.gz: e568a9eb40ea7c11b2d7158cfa2e1f1383defcfab7f316b3ab3062c7ba51e7d4
4
+ data.tar.gz: d9834ded0bb6a34046139a940df50bee058dabb6e5afd202b76d5a8cd0baa7f2
5
5
  SHA512:
6
- metadata.gz: ca1ee5f6ae6ec838b53eca1e15ea8816255457b8c9595bbc7e8a504bf3f63bddf9c5b257a7fe62f9d45833ca30d08cfaf01ccca0ac5b12bdf566fa5d1a460a9e
7
- data.tar.gz: 1615a793fb21fc157bd16442030b16c42f728de548cacb0ba975f0356ad64eb7ed9595f7a49da0b2c4bde4e8666bc63228fe7ec5cdd743eb9d3d8fd221de9c7a
6
+ metadata.gz: 0b397715151e041a35676ec031ce9b57ebf96848059f06cc9c666aae965fb8bc15ac9ed4c7fb38d29f0d595cadf00def873e19d825bc234f6788472ca8d3084e
7
+ data.tar.gz: 2ec78c399a9fa59b82a9b51e3f4eeb504906598d95c894a8977f0281bf93847db16f5dbe19064cb09be0ad79e9ef3ed391b7524999610b9469801809bf44c03b
Binary file
data.tar.gz.sig CHANGED
Binary file
data/README.md CHANGED
@@ -26,6 +26,8 @@ You can use `it` method in a block to get a single parameter of the block like K
26
26
  [^1]: https://kotlinlang.org/docs/reference/lambdas.html#it-implicit-name-of-a-single-parameter
27
27
 
28
28
 
29
+ require "thats_it"
30
+
29
31
  2.yield_self { it * it }
30
32
  # => 4
31
33
 
@@ -106,9 +106,30 @@ static VALUE rb_setup_it_block_c_call() {
106
106
  return Qnil;
107
107
  }
108
108
 
109
+ static int env_local_p(VALUE *ep) {
110
+ VALUE flags = ep[VM_ENV_DATA_INDEX_FLAGS];
111
+ return flags & VM_ENV_FLAG_LOCAL ? 1 : 0;
112
+ }
113
+
114
+ static VALUE *prev_ep(VALUE *ep) {
115
+ return VM_TAGGED_PTR_REF(ep[VM_ENV_DATA_INDEX_SPECVAL], 0x03);
116
+ }
117
+
118
+ static VALUE *get_lep(VALUE *ep) {
119
+ while (!env_local_p(ep)) {
120
+ ep = prev_ep(ep);
121
+ }
122
+ return ep;
123
+ }
124
+
125
+ static VALUE get_block_handler(rb_control_frame_t *cfp) {
126
+ VALUE *ep = get_lep(cfp->ep);
127
+ return ep[VM_ENV_DATA_INDEX_SPECVAL];
128
+ }
129
+
109
130
  static VALUE rb_setup_it_block_call() {
110
131
  rb_control_frame_t *cfp = ruby_current_execution_context_ptr->cfp;
111
- VALUE block_handler = (cfp + 2)->ep[VM_ENV_DATA_INDEX_SPECVAL];
132
+ VALUE block_handler = get_block_handler(cfp + 2);
112
133
  rb_iseq_t *iseq;
113
134
 
114
135
  if (!block_handler) { return Qnil; }
@@ -3,6 +3,8 @@
3
3
  https://github.com/ruby/ruby/blob/trunk/COPYING.ja
4
4
  */
5
5
 
6
+ #define VM_ENV_FLAG_LOCAL 0x0002
7
+ #define VM_ENV_DATA_INDEX_FLAGS ( 0) /* ep[ 0] */
6
8
  #define VM_ENV_DATA_INDEX_SPECVAL (-1) /* ep[-1] */
7
9
 
8
10
  /* for setup_it_block */
@@ -3,6 +3,8 @@
3
3
  https://github.com/ruby/ruby/blob/trunk/COPYING.ja
4
4
  */
5
5
 
6
+ #define VM_ENV_FLAG_LOCAL 0x0002
7
+ #define VM_ENV_DATA_INDEX_FLAGS ( 0) /* ep[ 0] */
6
8
  #define VM_ENV_DATA_INDEX_SPECVAL (-1) /* ep[-1] */
7
9
 
8
10
  /* for setup_it_block */
@@ -1,3 +1,3 @@
1
1
  module ThatsIt
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thats_it
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seiei Miyagi
metadata.gz.sig CHANGED
Binary file