flor 0.0.1 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. data/CHANGELOG.md +13 -0
  2. data/LICENSE.txt +1 -1
  3. data/Makefile +66 -0
  4. data/README.md +57 -0
  5. data/fail.txt +7 -0
  6. data/flor.gemspec +12 -9
  7. data/intercepted.txt +123 -0
  8. data/lib/flor/colours.rb +140 -0
  9. data/lib/flor/conf.rb +88 -0
  10. data/lib/flor/core/executor.rb +473 -0
  11. data/lib/flor/core/node.rb +397 -0
  12. data/lib/flor/core/procedure.rb +600 -0
  13. data/lib/flor/core/texecutor.rb +209 -0
  14. data/lib/flor/core.rb +93 -0
  15. data/lib/flor/dollar.rb +248 -0
  16. data/lib/flor/errors.rb +36 -0
  17. data/lib/flor/flor.rb +556 -0
  18. data/lib/flor/log.rb +336 -0
  19. data/lib/flor/migrations/0001_tables.rb +122 -0
  20. data/lib/flor/parser.rb +414 -0
  21. data/lib/flor/pcore/_arr.rb +49 -0
  22. data/lib/flor/pcore/_atom.rb +43 -0
  23. data/lib/flor/pcore/_att.rb +160 -0
  24. data/lib/flor/pcore/_dump.rb +60 -0
  25. data/lib/flor/pcore/_err.rb +30 -0
  26. data/lib/flor/pcore/_happly.rb +73 -0
  27. data/lib/flor/pcore/_obj.rb +65 -0
  28. data/lib/flor/pcore/_skip.rb +63 -0
  29. data/lib/flor/pcore/apply.rb +60 -0
  30. data/lib/flor/pcore/arith.rb +46 -0
  31. data/lib/flor/pcore/break.rb +71 -0
  32. data/lib/flor/pcore/cmp.rb +72 -0
  33. data/lib/flor/pcore/cond.rb +57 -0
  34. data/lib/flor/pcore/cursor.rb +223 -0
  35. data/lib/flor/pcore/define.rb +96 -0
  36. data/lib/flor/pcore/fail.rb +45 -0
  37. data/lib/flor/pcore/ife.rb +56 -0
  38. data/lib/flor/pcore/loop.rb +53 -0
  39. data/lib/flor/pcore/map.rb +75 -0
  40. data/lib/flor/pcore/match.rb +70 -0
  41. data/lib/flor/pcore/move.rb +65 -0
  42. data/lib/flor/pcore/noeval.rb +46 -0
  43. data/lib/flor/pcore/noret.rb +47 -0
  44. data/lib/flor/pcore/push.rb +69 -0
  45. data/lib/flor/pcore/sequence.rb +39 -0
  46. data/lib/flor/pcore/set.rb +76 -0
  47. data/lib/flor/pcore/stall.rb +35 -0
  48. data/lib/flor/pcore/until.rb +122 -0
  49. data/lib/flor/pcore/val.rb +40 -0
  50. data/lib/flor/punit/cancel.rb +69 -0
  51. data/lib/flor/punit/cmap.rb +76 -0
  52. data/lib/flor/punit/concurrence.rb +149 -0
  53. data/lib/flor/punit/every.rb +46 -0
  54. data/lib/flor/punit/on.rb +81 -0
  55. data/lib/flor/punit/schedule.rb +68 -0
  56. data/lib/flor/punit/signal.rb +47 -0
  57. data/lib/flor/punit/sleep.rb +53 -0
  58. data/lib/flor/punit/task.rb +109 -0
  59. data/lib/flor/punit/trace.rb +51 -0
  60. data/lib/flor/punit/trap.rb +100 -0
  61. data/lib/flor/to_string.rb +81 -0
  62. data/lib/flor/tools/env.rb +103 -0
  63. data/lib/flor/tools/repl.rb +231 -0
  64. data/lib/flor/unit/executor.rb +260 -0
  65. data/lib/flor/unit/hooker.rb +186 -0
  66. data/lib/flor/unit/journal.rb +52 -0
  67. data/lib/flor/unit/loader.rb +181 -0
  68. data/lib/flor/unit/logger.rb +181 -0
  69. data/lib/flor/unit/models/execution.rb +105 -0
  70. data/lib/flor/unit/models/pointer.rb +31 -0
  71. data/lib/flor/unit/models/timer.rb +52 -0
  72. data/lib/flor/unit/models/trace.rb +31 -0
  73. data/lib/flor/unit/models/trap.rb +130 -0
  74. data/lib/flor/unit/models.rb +106 -0
  75. data/lib/flor/unit/scheduler.rb +419 -0
  76. data/lib/flor/unit/storage.rb +633 -0
  77. data/lib/flor/unit/tasker.rb +191 -0
  78. data/lib/flor/unit/waiter.rb +146 -0
  79. data/lib/flor/unit/wlist.rb +77 -0
  80. data/lib/flor/unit.rb +50 -0
  81. data/lib/flor.rb +40 -3
  82. metadata +152 -22
  83. checksums.yaml +0 -7
  84. data/Rakefile +0 -52
@@ -0,0 +1,31 @@
1
+ #--
2
+ # Copyright (c) 2015-2017, John Mettraux, jmettraux+flor@gmail.com
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ # of this software and associated documentation files (the "Software"), to deal
6
+ # in the Software without restriction, including without limitation the rights
7
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ # copies of the Software, and to permit persons to whom the Software is
9
+ # furnished to do so, subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in
12
+ # all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ # THE SOFTWARE.
21
+ #
22
+ # Made in Japan.
23
+ #++
24
+
25
+
26
+ module Flor
27
+
28
+ class Pointer < FlorModel
29
+ end
30
+ end
31
+
@@ -0,0 +1,52 @@
1
+ #--
2
+ # Copyright (c) 2015-2017, John Mettraux, jmettraux+flor@gmail.com
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ # of this software and associated documentation files (the "Software"), to deal
6
+ # in the Software without restriction, including without limitation the rights
7
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ # copies of the Software, and to permit persons to whom the Software is
9
+ # furnished to do so, subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in
12
+ # all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ # THE SOFTWARE.
21
+ #
22
+ # Made in Japan.
23
+ #++
24
+
25
+
26
+ module Flor
27
+
28
+ class Timer < FlorModel
29
+
30
+ def to_trigger_message
31
+
32
+ m = self.data(false)['message']
33
+ m['timer_id'] = self.id
34
+
35
+ {
36
+ 'point' => 'trigger',
37
+ 'exid' => self.exid,
38
+ 'nid' => self.nid,
39
+ 'type' => self.type,
40
+ 'schedule' => self.schedule,
41
+ 'timer_id' => self.id,
42
+ 'message' => m
43
+ }
44
+ end
45
+
46
+ def ntime_t
47
+
48
+ @ntime_t ||= Time.parse(ntime)
49
+ end
50
+ end
51
+ end
52
+
@@ -0,0 +1,31 @@
1
+ #--
2
+ # Copyright (c) 2015-2017, John Mettraux, jmettraux+flor@gmail.com
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ # of this software and associated documentation files (the "Software"), to deal
6
+ # in the Software without restriction, including without limitation the rights
7
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ # copies of the Software, and to permit persons to whom the Software is
9
+ # furnished to do so, subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in
12
+ # all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ # THE SOFTWARE.
21
+ #
22
+ # Made in Japan.
23
+ #++
24
+
25
+
26
+ module Flor
27
+
28
+ class Trace < FlorModel
29
+ end
30
+ end
31
+
@@ -0,0 +1,130 @@
1
+ #--
2
+ # Copyright (c) 2015-2017, John Mettraux, jmettraux+flor@gmail.com
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ # of this software and associated documentation files (the "Software"), to deal
6
+ # in the Software without restriction, including without limitation the rights
7
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ # copies of the Software, and to permit persons to whom the Software is
9
+ # furnished to do so, subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in
12
+ # all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ # THE SOFTWARE.
21
+ #
22
+ # Made in Japan.
23
+ #++
24
+
25
+
26
+ module Flor
27
+
28
+ class Trap < FlorModel
29
+
30
+ def to_hook
31
+
32
+ @hook ||=
33
+ begin
34
+
35
+ opts = {}
36
+
37
+ opts[:consumed] = tconsumed
38
+
39
+ opts[:point] = tpoints.split(',') if tpoints
40
+ opts[:heap] = theaps.split(',') if theaps
41
+ opts[:heat] = theats.split(',') if theats
42
+
43
+ opts[:name] = data['names']
44
+
45
+ case trange
46
+ when 'execution'
47
+ opts[:exid] = exid
48
+ when 'subdomain'
49
+ opts[:subdomain] = Flor.domain(exid)
50
+ when 'domain'
51
+ opts[:domain] = Flor.domain(exid)
52
+ else #'subnid' # default
53
+ opts[:exid] = exid
54
+ opts[:subnid] = true
55
+ end
56
+
57
+ [ "trap#{id}", opts, self, nil ]
58
+ end
59
+ end
60
+
61
+ def trigger(executor, message)
62
+
63
+ [ decrement, [ to_trigger_message(executor, message) ] ]
64
+ end
65
+
66
+ def within_itself?(executor, message)
67
+
68
+ return false if message['exid'] != exid
69
+
70
+ n = executor.node(message['from'] || message['nid'], true)
71
+ return false if n == nil
72
+
73
+ n.descendant_of?(onid)
74
+ end
75
+
76
+ protected
77
+
78
+ # returns true if the trap should be removed from the execution's list
79
+ # of traps
80
+ #
81
+ def decrement
82
+
83
+ c = data['count']
84
+ return false unless c
85
+
86
+ c = c - 1
87
+ data['count'] = c
88
+ self[:status] = c > 0 ? 'active' : 'consumed'
89
+
90
+ self.update(content: Flor::Storage.to_blob(@data), status: self[:status])
91
+
92
+ c < 1
93
+ end
94
+
95
+ def to_trigger_message(executor, message)
96
+
97
+ dat = self.data(false)
98
+ msg = dat['message']
99
+
100
+ msg['trap_id'] = self.id
101
+
102
+ if vs = msg['vars']
103
+ k = vs.keys.find { |k| k != 'arguments' } || 'msg'
104
+ vs[k] = message
105
+ end
106
+
107
+ if dat['pl'] == 'event'
108
+ (msg['vars'] ||= {})['payload'] = msg['payload']
109
+ msg['payload'] = Flor.dup(message['payload'])
110
+ end
111
+
112
+ {
113
+ 'point' => 'trigger',
114
+ 'exid' => self.exid,
115
+ 'nid' => self.nid,
116
+ 'type' => 'trap',
117
+ 'trap' => to_hash,
118
+ 'trap_id' => self.id,
119
+ 'message' => msg,
120
+ #'dbg' => xx
121
+ }#.tap { |m| pp m }
122
+ end
123
+
124
+ def to_hash
125
+
126
+ values.inject({}) { |h, (k, v)| h[k.to_s ] = v if k != :content; h }
127
+ end
128
+ end
129
+ end
130
+
@@ -0,0 +1,106 @@
1
+ #--
2
+ # Copyright (c) 2015-2017, John Mettraux, jmettraux+flor@gmail.com
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ # of this software and associated documentation files (the "Software"), to deal
6
+ # in the Software without restriction, including without limitation the rights
7
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ # copies of the Software, and to permit persons to whom the Software is
9
+ # furnished to do so, subject to the following conditions:
10
+ #
11
+ # The above copyright notice and this permission notice shall be included in
12
+ # all copies or substantial portions of the Software.
13
+ #
14
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ # THE SOFTWARE.
21
+ #
22
+ # Made in Japan.
23
+ #++
24
+
25
+
26
+ module Flor
27
+
28
+ class DummySequelAdapter < Sequel::Dataset
29
+
30
+ class Db
31
+ def supports_schema_parsing?; false; end
32
+ def transaction(opts={}); yield; end
33
+ end
34
+
35
+ def initialize(opts)
36
+ @opts = opts
37
+ @db = Db.new
38
+ @cache = {} # necessary for Sequel >= 4.42.0
39
+ end
40
+
41
+ def fetch_rows(sql); yield([]); end
42
+
43
+ DB = Sequel.connect(:adapter => Flor::DummySequelAdapter)
44
+ end
45
+
46
+ class FlorModel < Sequel::Model(DummySequelAdapter::DB)
47
+
48
+ def _data
49
+
50
+ d = Flor::Storage.from_blob(content)
51
+ d['id'] = id
52
+
53
+ d
54
+ end
55
+
56
+ def data(cache=true)
57
+
58
+ cache ? (@data = _data) : _data
59
+ end
60
+
61
+ def to_h
62
+
63
+ values.inject({}) do |h, (k, v)|
64
+ if k == :content
65
+ h[:data] = data
66
+ else
67
+ h[k] = v
68
+ end
69
+ h
70
+ end
71
+ end
72
+ end
73
+
74
+ MODELS = [ :executions, :timers, :traces, :traps, :pointers ]
75
+
76
+ dir = File.dirname(__FILE__)
77
+ MODELS.each { |m| require File.join(dir, 'models', "#{m.to_s[0..-2]}.rb") }
78
+
79
+ class Storage
80
+
81
+ MODELS.each do |k|
82
+
83
+ define_method(k) do
84
+
85
+ s = self
86
+ c = k.to_s[0..-2].capitalize
87
+
88
+ @models[k] ||=
89
+ Flor.const_set(
90
+ "#{c}#{@db.object_id.to_s.gsub('-', 'M')}",
91
+ Class.new(Flor.const_get(c)) do
92
+ self.dataset = s.db["flor_#{k}".to_sym]
93
+ end)
94
+ end
95
+ end
96
+ end
97
+
98
+ class Scheduler
99
+
100
+ MODELS.each do |k|
101
+
102
+ define_method(k) { @storage.send(k) }
103
+ end
104
+ end
105
+ end
106
+