redshift 1.3.17 → 1.3.18

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. data/.bnsignore +23 -0
  2. data/.gitignore +7 -6
  3. data/README +22 -4
  4. data/RELEASE-NOTES +16 -0
  5. data/examples/lotka-volterra.rb +1 -1
  6. data/examples/modular-component-def.rb +49 -0
  7. data/examples/robots/README +49 -0
  8. data/examples/robots/lib/base.rb +38 -0
  9. data/examples/robots/lib/explosion.rb +48 -0
  10. data/examples/robots/lib/missile.rb +75 -0
  11. data/examples/robots/lib/radar.rb +56 -0
  12. data/examples/robots/lib/robot.rb +105 -0
  13. data/examples/robots/lib/shell-world.rb +167 -0
  14. data/examples/robots/lib/tracker.rb +16 -0
  15. data/examples/robots/robots.rb +53 -0
  16. data/examples/shell.rb +1 -2
  17. data/ext/redshift/buffer/buffer.c +102 -0
  18. data/ext/redshift/buffer/buffer.h +17 -0
  19. data/ext/redshift/buffer/dir.rb +1 -0
  20. data/ext/redshift/buffer/extconf.rb +2 -0
  21. data/ext/redshift/util/isaac/extconf.rb +2 -0
  22. data/ext/redshift/util/isaac/isaac.c +129 -0
  23. data/ext/redshift/util/isaac/rand.c +140 -0
  24. data/ext/redshift/util/isaac/rand.h +61 -0
  25. data/lib/redshift/mixins/shell.rb +72 -0
  26. data/lib/redshift/redshift.rb +1 -1
  27. data/lib/redshift/syntax.rb +12 -5
  28. data/lib/redshift/target/c/component-gen.rb +11 -8
  29. data/lib/redshift/target/c/flow/buffer.rb +17 -126
  30. data/lib/redshift/target/c/flow/delay.rb +5 -5
  31. data/lib/redshift/target/c/library.rb +12 -1
  32. data/lib/redshift/util/histogram.rb +1 -1
  33. data/lib/redshift/util/irb-shell.rb +81 -0
  34. data/lib/redshift/util/isaac.rb +22 -0
  35. data/lib/redshift/util/modular.rb +48 -0
  36. data/lib/redshift/util/tkar-driver.rb +1 -2
  37. data/lib/redshift/util/tracer/var.rb +1 -1
  38. data/lib/redshift/world.rb +9 -3
  39. data/rakefile +9 -1
  40. data/test/test.rb +23 -9
  41. data/test/test_buffer.rb +1 -1
  42. data/test/test_flow_trans.rb +3 -20
  43. metadata +50 -46
  44. data/lib/redshift/mixins/irb-shell.rb +0 -151
@@ -21,10 +21,10 @@ module RedShift; class DelayFlow
21
21
  tsname = "#{var_name}_time_step"
22
22
 
23
23
  cl.class_eval do
24
- shadow_attr_accessor bufname => "Buffer #{bufname}"
25
- shadow_attr_accessor delayname => "double #{delayname}"
24
+ shadow_attr_accessor bufname => "RSBuffer #{bufname}"
25
+ shadow_attr_accessor delayname => "double #{delayname}"
26
26
  # delay should be set only using the expr designated in :by => "expr"
27
- shadow_attr tsname => "double #{tsname}"
27
+ shadow_attr tsname => "double #{tsname}"
28
28
 
29
29
  after_commit do
30
30
  alias_method "__#{bufname}=", "#{bufname}="
@@ -104,10 +104,10 @@ module RedShift; class DelayFlow
104
104
  #{flow.translate(self, "fill", 0, cl).join("
105
105
  ")};
106
106
 
107
- buffer_init(&shadow->#{bufname}, len, fill);
107
+ rs_buffer_init(&shadow->#{bufname}, len, fill);
108
108
  }
109
109
  else { // # delay != shadow->#{delayname}
110
- buffer_resize(&shadow->#{bufname}, len);
110
+ rs_buffer_resize(&shadow->#{bufname}, len);
111
111
  }
112
112
 
113
113
  shadow->#{delayname} = delay;
@@ -12,7 +12,14 @@ module RedShift
12
12
  super
13
13
 
14
14
  self.purge_source_dir = :delete
15
- self.show_times_flag = $REDSHIFT_BUILD_TIMES
15
+
16
+ self.show_times_flag =
17
+ case $REDSHIFT_BUILD_TIMES
18
+ when nil, false, /\A(false|0*)\z/i
19
+ false
20
+ else
21
+ true
22
+ end
16
23
 
17
24
  if $REDSHIFT_DEBUG
18
25
  include_file.include "<assert.h>"
@@ -49,6 +56,10 @@ module RedShift
49
56
  end
50
57
  end
51
58
 
59
+ def make arg=nil
60
+ super [$REDSHIFT_MAKE_ARGS, arg].join(" ")
61
+ end
62
+
52
63
  def commit
53
64
  return if committed?
54
65
  precommit
@@ -137,7 +137,7 @@ if __FILE__ == $0
137
137
  end
138
138
 
139
139
  if opts["plot"]
140
- require 'sci/plot'
140
+ require 'redshift/util/plot'
141
141
  extend Plot::PlotUtils
142
142
 
143
143
  gnuplot do |plot|
@@ -0,0 +1,81 @@
1
+ require 'irb'
2
+ require 'irb/completion'
3
+
4
+ # A shell that runs when the user interrupts the main process.
5
+ class IRBShell
6
+ @@irb_setup_done = false
7
+
8
+ # +args+ are binding, self (both optional)
9
+ def initialize(*args)
10
+ ## maybe set some opts here, as in parse_opts in irb/init.rb?
11
+
12
+ unless @@irb_setup_done
13
+ @@irb_setup_done = true
14
+
15
+ conf = IRB.conf
16
+
17
+ if File.directory?("tmp")
18
+ conf[:HISTORY_FILE] = "tmp/.irb_shell_history"
19
+ else
20
+ conf[:HISTORY_FILE] = ".irb_shell_history"
21
+ end
22
+
23
+ IRB.setup nil
24
+
25
+ at_exit do
26
+ IRB.irb_at_exit
27
+ end
28
+ end
29
+
30
+ workspace = IRB::WorkSpace.new(*args)
31
+
32
+ if conf[:SCRIPT] ## normally, set by parse_opts
33
+ @irb = IRB::Irb.new(workspace, conf[:SCRIPT])
34
+ else
35
+ @irb = IRB::Irb.new(workspace)
36
+ end
37
+
38
+ conf[:IRB_RC].call(@irb.context) if conf[:IRB_RC]
39
+ conf[:MAIN_CONTEXT] = @irb.context
40
+ end
41
+
42
+ def run
43
+ @interrupt_requests = nil
44
+
45
+ trap("INT") do
46
+ @irb.signal_handle
47
+ end
48
+
49
+ begin
50
+ catch(:IRB_EXIT) do
51
+ @irb.eval_input
52
+ end
53
+ ensure
54
+ install_interrupt_handler
55
+ end
56
+ end
57
+
58
+ def install_interrupt_handler
59
+ unless @interrupt_requests
60
+ @interrupt_requests = 0
61
+ trap("INT") do
62
+ @interrupt_requests += 1
63
+ if @interrupt_requests == 2
64
+ puts "\nType one more ^C to abort, or wait for shell."
65
+ elsif @interrupt_requests >= 3
66
+ exit!
67
+ end
68
+ end
69
+ end
70
+ end
71
+
72
+ def handle_interrupt after = nil
73
+ if @interrupt_requests && @interrupt_requests > 0
74
+ yield if block_given?
75
+ run
76
+ true
77
+ else
78
+ false
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,22 @@
1
+ require 'redshift/util/isaac/isaac.so'
2
+
3
+ # Adaptor class to use ISAAC with redshift/util/random distributions.
4
+ # See test/test_flow_trans.rb for an example.
5
+ class ISAACGenerator < ISAAC
6
+ def initialize(*seeds)
7
+ super()
8
+ if seeds.compact.empty?
9
+ if defined?(Random::Sequence.random_seed)
10
+ seeds = [Random::Sequence.random_seed]
11
+ else
12
+ seeds = [rand]
13
+ end
14
+ end
15
+ @seeds = seeds
16
+ srand(seeds)
17
+ end
18
+
19
+ attr_reader :seeds
20
+
21
+ alias next rand
22
+ end
@@ -0,0 +1,48 @@
1
+ # A way to use a class-method-based DSL, like redshift, from within a module.
2
+ # Extend a module M with Modular. Then, use the DSL freely in M, even though M
3
+ # doesn't have the DSL methods. When you include M in some class, it "replays"
4
+ # the class methods. See examples/modular-component-def.rb.
5
+ module Modular
6
+ def method_missing(meth, *args, &block)
7
+ (@_modular_saved ||= []) << [meth, args, block, caller]
8
+ end
9
+
10
+ # this would allow unquoted constants, such as state names, but it's a bit
11
+ # too much magic:
12
+ # def const_missing(c)
13
+ # c
14
+ # end
15
+
16
+ def included(m)
17
+ @_modular_saved && @_modular_saved.each do |meth, args, block, where|
18
+ begin
19
+ m.send(meth, *args, &block)
20
+ rescue => ex
21
+ ex.set_backtrace where
22
+ ex.message << " while applying methods from #{self}"
23
+ raise ex
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ if __FILE__ == $0
30
+
31
+ class C # think: Component
32
+ def self.foo x # think #state, #flow, or #transition
33
+ p x
34
+ yield if block_given?
35
+ end
36
+ end
37
+
38
+ module M
39
+ extend Modular
40
+ foo 2 do puts "hi" end # using the DSL
41
+ end
42
+
43
+ class D < C
44
+ include M
45
+ foo 3
46
+ end
47
+
48
+ end
@@ -51,8 +51,7 @@ class TkarDriver
51
51
  end
52
52
  end
53
53
 
54
- # :yields: pipe
55
- def update
54
+ def update # :yields: pipe
56
55
  return unless @pipe
57
56
 
58
57
  yield @pipe if block_given?
@@ -1,4 +1,4 @@
1
- require 'sci/tracer/trace'
1
+ require 'redshift/util/tracer/trace'
2
2
 
3
3
  class Tracer
4
4
  # Represents the various options and controls associated with a variable
@@ -12,7 +12,8 @@ class World
12
12
 
13
13
  {
14
14
  :Debugger => "debugger",
15
- :ZenoDebugger => "zeno-debugger"
15
+ :ZenoDebugger => "zeno-debugger",
16
+ :Shell => "shell"
16
17
  }.each {|m,f| autoload(m, "redshift/mixins/#{f}")}
17
18
 
18
19
  class ComponentList
@@ -38,8 +39,13 @@ class World
38
39
  end
39
40
 
40
41
  def [](idx)
41
- warn "#{self.class}#[] is deprecated"
42
- to_a[idx] ## very inefficient
42
+ n = nil
43
+ summands.each do |enum|
44
+ n = enum.size
45
+ return enum[idx] if idx < n
46
+ idx - n
47
+ end
48
+ nil
43
49
  end
44
50
 
45
51
  def clear
data/rakefile CHANGED
@@ -26,11 +26,19 @@ END
26
26
  history_file 'RELEASE-NOTES'
27
27
  changes File.read(history_file)[/^\w.*?(?=^\w)/m]
28
28
  rdoc.dir "rdoc" ## Note: doc dir has original content files
29
+ rdoc.include ["README", "RELEASE-NOTES", "ext", "lib"]
30
+ rdoc.exclude ["examples", "test", "bench"]
29
31
 
30
32
  spec.opts << '--color'
31
- test.files = Dir["test/test_*.rb"]
33
+ test.files = [] ## Dir["test/test_*.rb"]
32
34
  }
33
35
 
36
+ task 'test' do
37
+ Dir.chdir 'test' do
38
+ system "./test.rb"
39
+ end
40
+ end
41
+
34
42
  task 'gem:release' => 'rubyforge:release' # to release to rubyforge as well
35
43
 
36
44
  task :release => ["rubyforge:release", "rubyforge:doc_release"]
data/test/test.rb CHANGED
@@ -21,6 +21,12 @@ $REDSHIFT_DEBUG=3 ## what should this be?
21
21
  ### have to fix the CLIB_NAME problem before can do this
22
22
  ### require 'redshift' ## all the tests will need this anyway
23
23
 
24
+ if ARGV.delete("-j2") ## parse better
25
+ jobs = 2
26
+ else
27
+ jobs = 1
28
+ end
29
+
24
30
  pat = ARGV.join("|")
25
31
  tests = Dir["test_*.rb"].grep(/#{pat}/)
26
32
  tests.sort!
@@ -33,17 +39,25 @@ tests.sort!
33
39
  require 'rbconfig'
34
40
  ruby = Config::CONFIG["RUBY_INSTALL_NAME"]
35
41
 
36
- failed = tests.reject do |file|
37
- puts "_"*50 + "\nStarting #{file}...\n"
38
- system "#{ruby} #{file}"
39
- # pid = fork { ## should use popen3 so we can weed out successful output
40
- # $REDSHIFT_CLIB_NAME = file
41
- # require 'redshift'
42
- # load file
43
- # }
44
- # Process.waitpid(pid)
42
+ pending = tests.dup
43
+ failed = []
44
+
45
+ workers = (0...jobs).map do |i|
46
+ Thread.new do
47
+ loop do
48
+ file = pending.shift
49
+ break unless file
50
+ puts "_"*50 + "\nStarting #{file}...\n"
51
+ if not system "#{ruby} #{file}" ## problem with interleaved outputs
52
+ ## should use popen3 so we can weed out successful output
53
+ failed << file
54
+ end
55
+ end
56
+ end
45
57
  end
46
58
 
59
+ workers.each {|w| w.join}
60
+
47
61
  puts "_"*50
48
62
  if failed.empty?
49
63
  puts "All tests passed."
data/test/test_buffer.rb CHANGED
@@ -13,7 +13,7 @@ class TestBuffer < Test::Unit::TestCase
13
13
 
14
14
  class T < Component
15
15
  RedShift.with_library do
16
- shadow_attr_accessor :b => "Buffer b"
16
+ shadow_attr_accessor :b => "RSBuffer b"
17
17
  end
18
18
  end
19
19
 
@@ -2,24 +2,7 @@
2
2
 
3
3
  require 'redshift'
4
4
  require 'redshift/util/random'
5
- ### TODO: add pure ruby ISAAC to util
6
- #require 'isaac'
7
-
8
- # Adaptor class to use ISAAC with redshift/util/random distributions.
9
- #class ISAACGenerator < ISAAC
10
- # def initialize(*seeds)
11
- # super()
12
- # if seeds.compact.empty?
13
- # seeds = [Random::Sequence.random_seed]
14
- # end
15
- # @seeds = seeds
16
- # srand(seeds)
17
- # end
18
- #
19
- # attr_reader :seeds
20
- #
21
- # alias next rand
22
- #end
5
+ require 'redshift/util/isaac'
23
6
 
24
7
  include RedShift
25
8
 
@@ -71,12 +54,12 @@ class Flow_Transition < FlowTestComponent
71
54
  self.x = 0
72
55
  @alarm_time = 0
73
56
  @alarm_seq = Random::Exponential.new(
74
- #:generator => ISAACGenerator,
57
+ :generator => ISAACGenerator,
75
58
  :seed => 614822716,
76
59
  :mean => 0.5
77
60
  )
78
61
  @state_seq = Random::Discrete.new(
79
- #:generator => ISAACGenerator,
62
+ :generator => ISAACGenerator,
80
63
  :seed => 3871653669, ## doesn't make sense to re-seed the same global gen
81
64
  :distrib =>
82
65
  {
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redshift
3
3
  version: !ruby/object:Gem::Version
4
- hash: 57
4
+ hash: 63
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 3
9
- - 17
10
- version: 1.3.17
9
+ - 18
10
+ version: 1.3.18
11
11
  platform: ruby
12
12
  authors:
13
13
  - Joel VanderWerf
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-06-13 00:00:00 -07:00
18
+ date: 2010-06-26 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -26,10 +26,12 @@ dependencies:
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- hash: 3
29
+ hash: 87
30
30
  segments:
31
31
  - 0
32
- version: "0"
32
+ - 16
33
+ - 4
34
+ version: 0.16.4
33
35
  type: :runtime
34
36
  version_requirements: *id001
35
37
  - !ruby/object:Gem::Dependency
@@ -40,12 +42,12 @@ dependencies:
40
42
  requirements:
41
43
  - - ">="
42
44
  - !ruby/object:Gem::Version
43
- hash: 27
45
+ hash: 25
44
46
  segments:
45
47
  - 3
46
48
  - 4
47
- - 6
48
- version: 3.4.6
49
+ - 7
50
+ version: 3.4.7
49
51
  type: :development
50
52
  version_requirements: *id002
51
53
  description: |
@@ -54,11 +56,14 @@ description: |
54
56
  email: vjoel@users.sourceforge.net
55
57
  executables: []
56
58
 
57
- extensions: []
58
-
59
- extra_rdoc_files: []
60
-
59
+ extensions:
60
+ - ext/redshift/buffer/extconf.rb
61
+ - ext/redshift/util/isaac/extconf.rb
62
+ extra_rdoc_files:
63
+ - README
64
+ - RELEASE-NOTES
61
65
  files:
66
+ - .bnsignore
62
67
  - .gitignore
63
68
  - README
64
69
  - RELEASE-NOTES
@@ -89,11 +94,21 @@ files:
89
94
  - examples/external-lib.rb
90
95
  - examples/guard-debugger.rb
91
96
  - examples/lotka-volterra.rb
97
+ - examples/modular-component-def.rb
92
98
  - examples/pid.rb
93
99
  - examples/ports.rb
94
100
  - examples/queue.rb
95
101
  - examples/queue2.rb
96
102
  - examples/reset-with-event-val.rb
103
+ - examples/robots/README
104
+ - examples/robots/lib/base.rb
105
+ - examples/robots/lib/explosion.rb
106
+ - examples/robots/lib/missile.rb
107
+ - examples/robots/lib/radar.rb
108
+ - examples/robots/lib/robot.rb
109
+ - examples/robots/lib/shell-world.rb
110
+ - examples/robots/lib/tracker.rb
111
+ - examples/robots/robots.rb
97
112
  - examples/scheduler.rb
98
113
  - examples/set-dest.rb
99
114
  - examples/shell.rb
@@ -108,10 +123,25 @@ files:
108
123
  - examples/sync.rb
109
124
  - examples/thermostat.rb
110
125
  - examples/zeno.rb
126
+ - ext/redshift/buffer/Makefile
127
+ - ext/redshift/buffer/buffer.c
128
+ - ext/redshift/buffer/buffer.h
129
+ - ext/redshift/buffer/buffer.o
130
+ - ext/redshift/buffer/buffer.so
131
+ - ext/redshift/buffer/dir.rb
132
+ - ext/redshift/buffer/extconf.rb
133
+ - ext/redshift/util/isaac/Makefile
134
+ - ext/redshift/util/isaac/extconf.rb
135
+ - ext/redshift/util/isaac/isaac.c
136
+ - ext/redshift/util/isaac/isaac.o
137
+ - ext/redshift/util/isaac/isaac.so
138
+ - ext/redshift/util/isaac/rand.c
139
+ - ext/redshift/util/isaac/rand.h
140
+ - ext/redshift/util/isaac/rand.o
111
141
  - lib/redshift.rb
112
142
  - lib/redshift/component.rb
113
143
  - lib/redshift/meta.rb
114
- - lib/redshift/mixins/irb-shell.rb
144
+ - lib/redshift/mixins/shell.rb
115
145
  - lib/redshift/mixins/zeno-debugger.rb
116
146
  - lib/redshift/port.rb
117
147
  - lib/redshift/queue.rb
@@ -134,6 +164,9 @@ files:
134
164
  - lib/redshift/util/accessible-index.rb
135
165
  - lib/redshift/util/argos.rb
136
166
  - lib/redshift/util/histogram.rb
167
+ - lib/redshift/util/irb-shell.rb
168
+ - lib/redshift/util/isaac.rb
169
+ - lib/redshift/util/modular.rb
137
170
  - lib/redshift/util/object-diff.rb
138
171
  - lib/redshift/util/plot.rb
139
172
  - lib/redshift/util/random.rb
@@ -186,6 +219,7 @@ rdoc_options:
186
219
  - README
187
220
  require_paths:
188
221
  - lib
222
+ - ext
189
223
  required_ruby_version: !ruby/object:Gem::Requirement
190
224
  none: false
191
225
  requirements:
@@ -211,35 +245,5 @@ rubygems_version: 1.3.7
211
245
  signing_key:
212
246
  specification_version: 3
213
247
  summary: Simulation of hybrid automata
214
- test_files:
215
- - test/test_setup.rb
216
- - test/test_inherit_link.rb
217
- - test/test_discrete_isolated.rb
218
- - test/test_connect_strict.rb
219
- - test/test_buffer.rb
220
- - test/test_world.rb
221
- - test/test_flow_link.rb
222
- - test/test_reset.rb
223
- - test/test_inherit_flow.rb
224
- - test/test_connect.rb
225
- - test/test_inherit_state.rb
226
- - test/test_flow_trans.rb
227
- - test/test_delay.rb
228
- - test/test_strict_reset_error.rb
229
- - test/test_flow.rb
230
- - test/test_derivative.rb
231
- - test/test_inherit.rb
232
- - test/test_inherit_transition.rb
233
- - test/test_connect_parallel.rb
234
- - test/test_queue_alone.rb
235
- - test/test_exit.rb
236
- - test/test_discrete.rb
237
- - test/test_strictness_error.rb
238
- - test/test_sync.rb
239
- - test/test_queue.rb
240
- - test/test_flow_sub.rb
241
- - test/test_inherit_setup.rb
242
- - test/test_numerics.rb
243
- - test/test_strict_continuity.rb
244
- - test/test_constant.rb
245
- - test/test_inherit_event.rb
248
+ test_files: []
249
+