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
@@ -1,151 +0,0 @@
1
- require 'irb'
2
- require 'irb/completion'
3
-
4
- class Object
5
- include IRB::ExtendCommandBundle
6
- # so that Marshal.dump still works, even when doing ">> irb obj"
7
- end
8
-
9
- def IRB.parse_opts
10
- # Don't touch ARGV, which belongs to the app which called this module.
11
- end
12
-
13
- class RedShift::IRBShell
14
- @@irb_setup_done = false
15
-
16
- # +args+ are binding, self (both optional)
17
- def initialize(*args)
18
- ## maybe set some opts here, as in parse_opts in irb/init.rb?
19
-
20
- unless @@irb_setup_done
21
- @@irb_setup_done = true
22
-
23
- conf = IRB.conf
24
-
25
- if File.directory?("tmp")
26
- conf[:HISTORY_FILE] = "tmp/.redshift_irb_shell_history"
27
- else
28
- conf[:HISTORY_FILE] = ".redshift_irb_shell_history"
29
- end
30
-
31
- IRB.setup nil
32
-
33
- at_exit do
34
- IRB.irb_at_exit
35
- end
36
- end
37
-
38
- workspace = IRB::WorkSpace.new(*args)
39
-
40
- if conf[:SCRIPT] ## normally, set by parse_opts
41
- @irb = IRB::Irb.new(workspace, conf[:SCRIPT])
42
- else
43
- @irb = IRB::Irb.new(workspace)
44
- end
45
-
46
- conf[:IRB_RC].call(@irb.context) if conf[:IRB_RC]
47
- conf[:MAIN_CONTEXT] = @irb.context
48
- end
49
-
50
- def run
51
- @interrupt_requests = nil
52
-
53
- trap("INT") do
54
- @irb.signal_handle
55
- end
56
-
57
- begin
58
- catch(:IRB_EXIT) do
59
- @irb.eval_input
60
- end
61
- ensure
62
- install_interrupt_handler
63
- end
64
- end
65
-
66
- def install_interrupt_handler
67
- unless @interrupt_requests
68
- @interrupt_requests = 0
69
- trap("INT") do
70
- @interrupt_requests += 1
71
- if @interrupt_requests == 2
72
- puts "\nType one more ^C to abort, or wait for RedShift shell."
73
- elsif @interrupt_requests >= 3
74
- exit!
75
- end
76
- end
77
- end
78
- end
79
-
80
- def handle_interrupt after = nil
81
- if @interrupt_requests && @interrupt_requests > 0
82
- yield if block_given?
83
- run
84
- true
85
- else
86
- false
87
- end
88
- end
89
- end
90
-
91
- # extend a World instance with this (or include in a World subclass)
92
- module RedShift::Shellable
93
- def shell
94
- @shell ||= RedShift::IRBShell.new(binding, self)
95
- end
96
-
97
- def run(*)
98
- shell.install_interrupt_handler
99
- super
100
- end
101
-
102
- def step(*)
103
- super do
104
- yield self if block_given?
105
- if shell.handle_interrupt {before_shell}
106
- after_shell
107
- return
108
- end
109
- end
110
- end
111
-
112
- # Override to complete some action before dropping into shell.
113
- def before_shell
114
- end
115
-
116
- # Override to complete some action after leaving shell.
117
- def after_shell
118
- end
119
-
120
- # Typically, call this in a rescue clause, if you to let the user
121
- # examine state and possibly continue:
122
- #
123
- # rescue ... => e
124
- # require 'redshift/mixins/irb-shell'
125
- # world.extend RedShift::IRBShell
126
- # world.recoverable_error e, "Assertion failure", e.backtrace
127
- #
128
- def recoverable_error e, msg = "Error", bt = []
129
- puts "#{msg} at time #{clock}"
130
- puts "From " + bt[0..2].join("\n ") unless bt.empty
131
- puts " ..." if bt.length > 3
132
- shell.run
133
- end
134
-
135
- private
136
- def q
137
- exit
138
- end
139
-
140
- ## commands:
141
- ## step [n] {block}
142
- ## step_until/while
143
- ## continue -- safer than ^D, does step_discrete in case of changes
144
- ## step_continuous
145
- ## step_discrete [n]
146
- ## break [class/component/transition/comp.event/condition]
147
- ## until step_until, stops inside step_discrete
148
- ## clear
149
- ##
150
- ## customize prompt
151
- end