ruff 1.3.1 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,7 +6,7 @@
6
6
  <title>
7
7
  Top Level Namespace
8
8
 
9
- &mdash; Ruff 1.3.0 Documentation
9
+ &mdash; Ruff 1.3.1 Documentation
10
10
 
11
11
  </title>
12
12
 
@@ -100,7 +100,7 @@
100
100
  </div>
101
101
 
102
102
  <div id="footer">
103
- Generated on Mon Oct 7 02:29:28 2019 by
103
+ Generated on Wed Oct 30 01:51:52 2019 by
104
104
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
105
105
  0.9.20 (ruby-2.6.5).
106
106
  </div>
data/lib/ruff/standard.rb CHANGED
@@ -24,3 +24,4 @@ require 'ruff/standard/measure_time'
24
24
  require 'ruff/standard/defer'
25
25
  require 'ruff/standard/state'
26
26
  require 'ruff/standard/async'
27
+ require 'ruff/standard/call1cc'
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # `Async` provides effects `Async.async`, `Async.yield` and `Async.await`, and the implementation async/await.
3
+ # `Async` provides effects `Async.async`, `Async.yield` and `Async.await`,
4
+ # and the implementation async/await.
4
5
  # This implementation is based on the tutorial for Multicore OCaml.
5
6
  # @see https://github.com/ocamllabs/ocaml-effects-tutorial/blob/master/sources/solved/async_await.ml
6
7
  #
@@ -47,8 +48,8 @@ module Ruff::Standard::Async
47
48
  # type 'a promise =
48
49
  # | Waiting of ('a, unit) continuation list
49
50
  # | Done of 'a
50
- _Waiting = Util::ADT.create
51
- _Done = Util::ADT.create
51
+ Waiting = Util::ADT.create
52
+ Done = Util::ADT.create
52
53
 
53
54
  # makes a new instance.
54
55
  def initialize
@@ -95,7 +96,7 @@ module Ruff::Standard::Async
95
96
  # @return [()!{e}]
96
97
  # returns unit but still has the possibility to invoke effects `e` .
97
98
  define_method :with do |&th|
98
- fork(Util::Ref.new(_Waiting.new([])), th)
99
+ fork(Util::Ref.new(Waiting.new([])), th)
99
100
  end
100
101
 
101
102
  # You can reimplement the handler using these effect instances
@@ -104,26 +105,26 @@ module Ruff::Standard::Async
104
105
 
105
106
  private
106
107
 
108
+ # rubocop:disable Metrics/AbcSize
109
+ # rubocop:disable Metrics/BlockLength
107
110
  define_method :fork do |pr, th|
108
111
  Ruff.handler
109
112
  .to do |v|
110
113
  pp = pr.get
111
114
  l = case pp
112
- when _Waiting
113
- pp.get
114
- else
115
- raise 'impossible'
115
+ when Waiting then pp.get
116
+ else raise 'impossible'
116
117
  end
117
118
 
118
119
  l.each do |k|
119
120
  @q.enqueue(-> { k[v] })
120
121
  end
121
122
 
122
- pr.set(_Done.new(v))
123
+ pr.set(Done.new(v))
123
124
  @q.dequeue
124
125
  end
125
126
  .on(@eff.async) do |k, f|
126
- pr_ = Util::Ref.new(_Waiting.new([]))
127
+ pr_ = Util::Ref.new(Waiting.new([]))
127
128
  @q.enqueue(-> { k[pr_] })
128
129
  fork(pr_, f)
129
130
  end
@@ -131,19 +132,20 @@ module Ruff::Standard::Async
131
132
  @q.enqueue(-> { k[] })
132
133
  @q.dequeue.call
133
134
  end
134
- .on(@eff.await) do |k, pr|
135
- pp = pr.get
135
+ .on(@eff.await) do |k, ppr|
136
+ pp = ppr.get
136
137
 
137
138
  return case pp
138
- when _Done
139
- k[pp.get]
140
- when _Waiting
141
- pr.set(_Waiting.new(@q.cons(k)))
139
+ when Done then k[pp.get]
140
+ when Waiting
141
+ pr.set(Waiting.new(@q.cons(k)))
142
142
  @q.dequeue.call
143
143
  end
144
144
  end
145
145
  .run { th[] }
146
146
  end
147
+ # rubocop:enable Metrics/BlockLength
148
+ # rubocop:enable Metrics/AbcSize
147
149
  end
148
150
 
149
151
  # ---
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ # `Call1cc` provides call-with-oneshot-continuation.
4
+ # The continuation can be run in the `context`.
5
+ #
6
+ # @example
7
+ # Call1cc.context do
8
+ # divfail = lambda { |l, default|
9
+ # Call1cc.run {|k|
10
+ # l.map{|e|
11
+ # if e.zero?
12
+ # k.call(default)
13
+ # else
14
+ # e / 2
15
+ # end
16
+ # }
17
+ # }
18
+ # }
19
+ #
20
+ # pp divfail.call([1, 3, 5], [1])
21
+ # # ==> [0, 1, 2]
22
+ # puts '---'
23
+ # pp divfail.call([1, 0, 5], [1])
24
+ # # ==> [1]
25
+ # end
26
+
27
+ module Ruff::Standard::Call1cc
28
+ # call stack
29
+ @stack = []
30
+
31
+ def context(&prc)
32
+ p = Ruff.instance
33
+ @stack.push p
34
+
35
+ ret = Ruff.handler
36
+ .on(p) do |k, v|
37
+ k.call(v)
38
+ end
39
+ .run(&prc)
40
+
41
+ @stack.pop
42
+ ret
43
+ end
44
+
45
+ def run(&f)
46
+ top = @stack.first
47
+ Ruff.handler
48
+ .on(top) do |_, v|
49
+ # abort the rest of computation from calling the continuation
50
+ top.perform(v)
51
+ end.run do
52
+ f.call(->(v) { top.perform(v) })
53
+ end
54
+ end
55
+
56
+ module_function :context, :run
57
+ end
data/lib/ruff/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ruff
4
- VERSION = '1.3.1'
4
+ VERSION = '1.4.0'
5
5
  end
data/version CHANGED
@@ -1 +1 @@
1
- 1.3.1
1
+ 1.4.0
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruff
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - nymphium
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-06 00:00:00.000000000 Z
11
+ date: 2019-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -60,6 +60,7 @@ files:
60
60
  - docs/Ruff/Standard.html
61
61
  - docs/Ruff/Standard/Async.html
62
62
  - docs/Ruff/Standard/Async/Instance.html
63
+ - docs/Ruff/Standard/Call1cc.html
63
64
  - docs/Ruff/Standard/CurrentTime.html
64
65
  - docs/Ruff/Standard/CurrentTime/Instance.html
65
66
  - docs/Ruff/Standard/Defer.html
@@ -95,6 +96,7 @@ files:
95
96
  - lib/ruff/objects.rb
96
97
  - lib/ruff/standard.rb
97
98
  - lib/ruff/standard/async.rb
99
+ - lib/ruff/standard/call1cc.rb
98
100
  - lib/ruff/standard/current_time.rb
99
101
  - lib/ruff/standard/defer.rb
100
102
  - lib/ruff/standard/measure_time.rb