ruff 0.0.7 → 0.0.8

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.
@@ -6,7 +6,7 @@
6
6
  <title>
7
7
  Top Level Namespace
8
8
 
9
- &mdash; Ruff 0.0.6 Documentation
9
+ &mdash; Ruff 0.0.8 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 Thu Oct 3 00:38:48 2019 by
103
+ Generated on Thu Oct 3 03:25:53 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.4).
106
106
  </div>
@@ -4,8 +4,6 @@ require 'securerandom'
4
4
  class Ruff::Handler
5
5
  include Ruff::Throws
6
6
 
7
- @valh_id = SecureRandom.uuid
8
-
9
7
  # makes a new handler, internally having fresh empty hash.
10
8
  #
11
9
  # This is a effect-handler store and when handliong it is looked up.
@@ -16,6 +14,7 @@ class Ruff::Handler
16
14
 
17
15
  def initialize
18
16
  @handlers = Hash.new
17
+ @valh_id = SecureRandom.uuid
19
18
  @handlers[@valh_id] = ->(x) { x }
20
19
  end
21
20
 
@@ -115,13 +114,16 @@ class Ruff::Handler
115
114
  if effh = @handlers[r.id]
116
115
  effh[continue, *r.args]
117
116
  else
118
- Fiber.yield (Resend.new r, continue)
117
+ Fiber.yield Resend.new(r, continue)
119
118
  end
120
119
  elsif r.is_a? Resend
121
- if effh = @handlers[r.eff.id]
122
- effh[rehandles[r.k], *r.eff.args]
120
+ eff = r.eff
121
+ next_k = rehandles.(r.k)
122
+
123
+ if effh = @handlers[eff.id]
124
+ effh.(next_k, *eff.args)
123
125
  else
124
- Fiber.yield (Resend.new r, rehandles[r.k])
126
+ Fiber.yield Resend.new(eff, next_k)
125
127
  end
126
128
  else
127
129
  @handlers[@valh_id].(r)
@@ -145,16 +147,16 @@ class Ruff::Handler
145
147
  ->(*args) {
146
148
  continue[
147
149
  newh.run {
148
- k[*args]
150
+ k.(*args)
149
151
  }
150
152
  ]
151
153
  }
152
154
  }
153
155
 
154
156
  continue = ->(*arg) {
155
- handle[co.resume(*arg)]
157
+ handle.(co.resume(*arg))
156
158
  }
157
159
 
158
- continue[nil]
160
+ continue.(nil)
159
161
  end
160
162
  end
@@ -0,0 +1,6 @@
1
+ module Ruff::Standard end
2
+
3
+ require "ruff/standard/current_time"
4
+ require "ruff/standard/defer"
5
+ require "ruff/standard/state"
6
+
@@ -0,0 +1,29 @@
1
+ module Ruff::Standard::CurrentTime
2
+ class Instance
3
+ def initialize
4
+ @eff = Ruff.instance
5
+ end
6
+
7
+ def get
8
+ @eff.perform
9
+ end
10
+
11
+ def with &th
12
+ Ruff.handler.on(@eff){|k| k[Time.now]}.run &th
13
+ end
14
+ end
15
+
16
+ # ---
17
+ @inst = Instance.new
18
+
19
+ def get
20
+ @inst.get
21
+ end
22
+
23
+ def with &th
24
+ @inst.with &th
25
+ end
26
+
27
+ module_function :get, :with
28
+ end
29
+
@@ -0,0 +1,40 @@
1
+ module Ruff::Standard::Defer
2
+ class Instance
3
+ def initialize
4
+ @eff = Ruff.instance
5
+ end
6
+
7
+ def register &prc
8
+ @eff.perform prc
9
+ end
10
+
11
+ def with &th
12
+ procs = []
13
+
14
+ Ruff.handler
15
+ .on(@eff){|k, prc|
16
+ procs << prc
17
+ k[]
18
+ }
19
+ .to {|_|
20
+ procs.reverse_each{|prc|
21
+ prc[]
22
+ }
23
+ }
24
+ .run &th
25
+ end
26
+ end
27
+
28
+ # ---
29
+ @inst = Instance.new
30
+
31
+ def register &prc
32
+ @inst.register &prc
33
+ end
34
+
35
+ def with &th
36
+ @inst.with &th
37
+ end
38
+
39
+ module_function :register, :with
40
+ end
@@ -0,0 +1,64 @@
1
+ module Ruff::Standard::State
2
+ class Instance
3
+ def initialize
4
+ @get = Ruff.instance
5
+ @modify = Ruff.instance
6
+ end
7
+
8
+ def get
9
+ @get.perform
10
+ end
11
+
12
+ def modify &fn
13
+ @modify.perform fn
14
+ end
15
+
16
+ def put s
17
+ @modify.perform ->(_) { s }
18
+ end
19
+
20
+ def with_init init, &task
21
+ state = init
22
+
23
+ Ruff.handler
24
+ .on(@modify){|k, fn|
25
+ state = fn[state]
26
+ k[nil]
27
+ }
28
+ .on(@get){|k|
29
+ k[state]
30
+ }
31
+ .run &task
32
+ end
33
+
34
+ def with &task
35
+ with_init(nil, &task)
36
+ end
37
+ end
38
+
39
+ # ---
40
+ @inst = Instance.new
41
+
42
+ def get
43
+ @inst.get
44
+ end
45
+
46
+ def modify &fn
47
+ @inst.modify &fn
48
+ end
49
+
50
+ def put s
51
+ @inst.put s
52
+ end
53
+
54
+ def with_init init, &task
55
+ @inst.with_init init, &task
56
+ end
57
+
58
+ def with &task
59
+ @inst.with &task
60
+ end
61
+
62
+ module_function :get, :put, :modify, :with, :with_init
63
+ end
64
+
@@ -1,3 +1,3 @@
1
1
  module Ruff
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
data/version.h CHANGED
@@ -1 +1 @@
1
- #define RUFF_VERSION "0.0.7"
1
+ #define RUFF_VERSION "0.0.8"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruff
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - nymphium
@@ -54,6 +54,13 @@ files:
54
54
  - docs/Ruff.html
55
55
  - docs/Ruff/Effect.html
56
56
  - docs/Ruff/Handler.html
57
+ - docs/Ruff/Standard.html
58
+ - docs/Ruff/Standard/CurrentTime.html
59
+ - docs/Ruff/Standard/CurrentTime/Instance.html
60
+ - docs/Ruff/Standard/Defer.html
61
+ - docs/Ruff/Standard/Defer/Instance.html
62
+ - docs/Ruff/Standard/State.html
63
+ - docs/Ruff/Standard/State/Instance.html
57
64
  - docs/Ruff/Throws.html
58
65
  - docs/Ruff/Throws/Eff.html
59
66
  - docs/Ruff/Throws/Resend.html
@@ -75,6 +82,10 @@ files:
75
82
  - lib/ruff/effect.rb
76
83
  - lib/ruff/handler.rb
77
84
  - lib/ruff/objects.rb
85
+ - lib/ruff/standard.rb
86
+ - lib/ruff/standard/current_time.rb
87
+ - lib/ruff/standard/defer.rb
88
+ - lib/ruff/standard/state.rb
78
89
  - lib/ruff/version.cpp.rb
79
90
  - lib/ruff/version.rb
80
91
  - ruff.gemspec