gisele-vm 0.6.0
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.
- data/CHANGELOG.md +5 -0
- data/Gemfile +18 -0
- data/Gemfile.lock +46 -0
- data/LICENCE.md +22 -0
- data/Manifest.txt +15 -0
- data/README.md +10 -0
- data/Rakefile +11 -0
- data/bin/gvm +9 -0
- data/gisele-vm.gemspec +191 -0
- data/gisele-vm.noespec +31 -0
- data/lib/gisele-vm.rb +4 -0
- data/lib/gisele-vm/loader.rb +5 -0
- data/lib/gisele-vm/version.rb +16 -0
- data/lib/gisele/compiling.rb +3 -0
- data/lib/gisele/compiling/gisele2gts.rb +143 -0
- data/lib/gisele/compiling/gts.rb +74 -0
- data/lib/gisele/compiling/gts2bytecode.rb +127 -0
- data/lib/gisele/vm.rb +87 -0
- data/lib/gisele/vm/bytecode.rb +84 -0
- data/lib/gisele/vm/bytecode/builder.rb +77 -0
- data/lib/gisele/vm/bytecode/grammar.citrus +116 -0
- data/lib/gisele/vm/bytecode/grammar.rb +19 -0
- data/lib/gisele/vm/bytecode/grammar.sexp.yml +113 -0
- data/lib/gisele/vm/bytecode/printer.rb +35 -0
- data/lib/gisele/vm/command.rb +140 -0
- data/lib/gisele/vm/component.rb +91 -0
- data/lib/gisele/vm/console.rb +58 -0
- data/lib/gisele/vm/enacter.rb +29 -0
- data/lib/gisele/vm/errors.rb +26 -0
- data/lib/gisele/vm/event.rb +11 -0
- data/lib/gisele/vm/event_manager.rb +65 -0
- data/lib/gisele/vm/kernel.rb +58 -0
- data/lib/gisele/vm/kernel/macros.gvm +214 -0
- data/lib/gisele/vm/kernel/opcodes.rb +212 -0
- data/lib/gisele/vm/kernel/runner.rb +63 -0
- data/lib/gisele/vm/lifecycle.rb +72 -0
- data/lib/gisele/vm/logging.rb +18 -0
- data/lib/gisele/vm/null_object.rb +19 -0
- data/lib/gisele/vm/prog.rb +63 -0
- data/lib/gisele/vm/prog_list.rb +55 -0
- data/lib/gisele/vm/prog_list/memory.rb +74 -0
- data/lib/gisele/vm/prog_list/sqldb.rb +123 -0
- data/lib/gisele/vm/prog_list/storage.rb +31 -0
- data/lib/gisele/vm/proxy.rb +14 -0
- data/lib/gisele/vm/proxy/client.rb +64 -0
- data/lib/gisele/vm/proxy/server.rb +29 -0
- data/lib/gisele/vm/registry.rb +57 -0
- data/lib/gisele/vm/robustness.rb +31 -0
- data/lib/gisele/vm/simulator/resumer.rb +32 -0
- data/spec/command/gvm_compile.cmd +1 -0
- data/spec/command/gvm_compile.stdout +111 -0
- data/spec/command/gvm_gts.cmd +1 -0
- data/spec/command/gvm_gts.stdout +101 -0
- data/spec/command/gvm_help.cmd +1 -0
- data/spec/command/gvm_help.stdout +30 -0
- data/spec/command/gvm_version.cmd +1 -0
- data/spec/command/gvm_version.stdout +2 -0
- data/spec/command/test_command.rb +29 -0
- data/spec/fixtures/complete.gis +13 -0
- data/spec/fixtures/fake_component.rb +24 -0
- data/spec/fixtures/kernel.rb +39 -0
- data/spec/fixtures/ts.adl +11 -0
- data/spec/fixtures/ts.gts +20 -0
- data/spec/fixtures/ts.gvm +19 -0
- data/spec/spec_helper.rb +86 -0
- data/spec/test_examples.rb +29 -0
- data/spec/test_gisele-vm.rb +8 -0
- data/spec/unit/bytecode/builder/test_at.rb +56 -0
- data/spec/unit/bytecode/builder/test_helpers.rb +36 -0
- data/spec/unit/bytecode/builder/test_instruction.rb +35 -0
- data/spec/unit/bytecode/builder/test_to_a.rb +53 -0
- data/spec/unit/bytecode/bytecode.gvm +1 -0
- data/spec/unit/bytecode/grammar/fixtures/comments.gvm +16 -0
- data/spec/unit/bytecode/grammar/fixtures/every.gvm +46 -0
- data/spec/unit/bytecode/grammar/fixtures/singleblock.gvm +2 -0
- data/spec/unit/bytecode/grammar/fixtures/twoblocks.gvm +4 -0
- data/spec/unit/bytecode/grammar/fixtures/with_end.gvm +5 -0
- data/spec/unit/bytecode/grammar/test_array.rb +24 -0
- data/spec/unit/bytecode/grammar/test_block.rb +35 -0
- data/spec/unit/bytecode/grammar/test_boolean.rb +20 -0
- data/spec/unit/bytecode/grammar/test_constant.rb +20 -0
- data/spec/unit/bytecode/grammar/test_eol.rb +20 -0
- data/spec/unit/bytecode/grammar/test_eol_comment.rb +36 -0
- data/spec/unit/bytecode/grammar/test_file.rb +38 -0
- data/spec/unit/bytecode/grammar/test_hash.rb +33 -0
- data/spec/unit/bytecode/grammar/test_instruction.rb +32 -0
- data/spec/unit/bytecode/grammar/test_int.rb +24 -0
- data/spec/unit/bytecode/grammar/test_label.rb +24 -0
- data/spec/unit/bytecode/grammar/test_opcode.rb +23 -0
- data/spec/unit/bytecode/grammar/test_string.rb +25 -0
- data/spec/unit/bytecode/grammar/test_symbol.rb +30 -0
- data/spec/unit/bytecode/test_build.rb +36 -0
- data/spec/unit/bytecode/test_coerce.rb +41 -0
- data/spec/unit/bytecode/test_fetch.rb +20 -0
- data/spec/unit/bytecode/test_grammar.rb +30 -0
- data/spec/unit/bytecode/test_parse.rb +22 -0
- data/spec/unit/bytecode/test_plus.rb +27 -0
- data/spec/unit/bytecode/test_to_a.rb +19 -0
- data/spec/unit/bytecode/test_to_s.rb +32 -0
- data/spec/unit/command/code.gis +3 -0
- data/spec/unit/command/test_vm.rb +51 -0
- data/spec/unit/compiling/gisele2gts/test_on_par_st.rb +51 -0
- data/spec/unit/compiling/gisele2gts/test_on_seq_st.rb +46 -0
- data/spec/unit/compiling/gisele2gts/test_on_task_call_st.rb +37 -0
- data/spec/unit/compiling/gisele2gts/test_on_task_def.rb +49 -0
- data/spec/unit/compiling/gisele2gts/test_on_unit_def.rb +35 -0
- data/spec/unit/compiling/gts2bytecode/test_on_end.rb +31 -0
- data/spec/unit/compiling/gts2bytecode/test_on_event.rb +37 -0
- data/spec/unit/compiling/gts2bytecode/test_on_fork.rb +41 -0
- data/spec/unit/compiling/gts2bytecode/test_on_join.rb +42 -0
- data/spec/unit/compiling/gts2bytecode/test_on_listen.rb +36 -0
- data/spec/unit/compiling/gts2bytecode/test_on_nop.rb +30 -0
- data/spec/unit/component/test_component_name.rb +16 -0
- data/spec/unit/component/test_logging.rb +36 -0
- data/spec/unit/enacter/test_component.rb +11 -0
- data/spec/unit/event/test_to_s.rb +12 -0
- data/spec/unit/event_manager/test_component.rb +9 -0
- data/spec/unit/event_manager/test_subscribe.rb +40 -0
- data/spec/unit/event_manager/test_unsubscribe.rb +39 -0
- data/spec/unit/kernel/macros/test_fork.rb +37 -0
- data/spec/unit/kernel/macros/test_join.rb +43 -0
- data/spec/unit/kernel/macros/test_listen.rb +37 -0
- data/spec/unit/kernel/macros/test_notify.rb +57 -0
- data/spec/unit/kernel/macros/test_react.rb +47 -0
- data/spec/unit/kernel/macros/test_schedule_at.rb +30 -0
- data/spec/unit/kernel/opcodes/test_op_del.rb +42 -0
- data/spec/unit/kernel/opcodes/test_op_event.rb +25 -0
- data/spec/unit/kernel/opcodes/test_op_fetch.rb +27 -0
- data/spec/unit/kernel/opcodes/test_op_flip.rb +17 -0
- data/spec/unit/kernel/opcodes/test_op_fold.rb +29 -0
- data/spec/unit/kernel/opcodes/test_op_fork.rb +63 -0
- data/spec/unit/kernel/opcodes/test_op_forka.rb +51 -0
- data/spec/unit/kernel/opcodes/test_op_get.rb +62 -0
- data/spec/unit/kernel/opcodes/test_op_getr.rb +48 -0
- data/spec/unit/kernel/opcodes/test_op_ifenil.rb +41 -0
- data/spec/unit/kernel/opcodes/test_op_ifezero.rb +32 -0
- data/spec/unit/kernel/opcodes/test_op_invoke.rb +34 -0
- data/spec/unit/kernel/opcodes/test_op_nop.rb +18 -0
- data/spec/unit/kernel/opcodes/test_op_parent.rb +39 -0
- data/spec/unit/kernel/opcodes/test_op_pop.rb +22 -0
- data/spec/unit/kernel/opcodes/test_op_push.rb +17 -0
- data/spec/unit/kernel/opcodes/test_op_save.rb +32 -0
- data/spec/unit/kernel/opcodes/test_op_savea.rb +34 -0
- data/spec/unit/kernel/opcodes/test_op_self.rb +20 -0
- data/spec/unit/kernel/opcodes/test_op_send.rb +20 -0
- data/spec/unit/kernel/opcodes/test_op_set.rb +61 -0
- data/spec/unit/kernel/opcodes/test_op_then.rb +50 -0
- data/spec/unit/kernel/opcodes/test_op_unfold.rb +22 -0
- data/spec/unit/kernel/opcodes/test_op_uuid.rb +16 -0
- data/spec/unit/kernel/runner/test_pop.rb +26 -0
- data/spec/unit/kernel/runner/test_stack.rb +28 -0
- data/spec/unit/kernel/test_progress.rb +47 -0
- data/spec/unit/kernel/test_resume.rb +53 -0
- data/spec/unit/kernel/test_start.rb +36 -0
- data/spec/unit/prog/test_to_hash.rb +29 -0
- data/spec/unit/prog/test_waitlist_eq.rb +20 -0
- data/spec/unit/prog_list/memory/test_component.rb +9 -0
- data/spec/unit/prog_list/memory/test_fetch.rb +40 -0
- data/spec/unit/prog_list/memory/test_pick.rb +39 -0
- data/spec/unit/prog_list/memory/test_save.rb +91 -0
- data/spec/unit/prog_list/memory/test_to_relation.rb +17 -0
- data/spec/unit/prog_list/sqldb/test_component.rb +11 -0
- data/spec/unit/prog_list/sqldb/test_connect.rb +46 -0
- data/spec/unit/prog_list/test_memory.rb +9 -0
- data/spec/unit/prog_list/test_sqldb.rb +13 -0
- data/spec/unit/prog_list/test_storage.rb +51 -0
- data/spec/unit/registry/test_component.rb +9 -0
- data/spec/unit/registry/test_connect.rb +53 -0
- data/spec/unit/registry/test_disconnect.rb +51 -0
- data/spec/unit/registry/test_registration.rb +44 -0
- data/spec/unit/shared/a_component.rb +49 -0
- data/spec/unit/shared/a_storage.rb +114 -0
- data/spec/unit/test_logging.rb +46 -0
- data/spec/unit/test_prog.rb +57 -0
- data/spec/unit/test_prog_list.rb +22 -0
- data/spec/unit/vm/test_event_facace.rb +11 -0
- data/spec/unit/vm/test_initialize.rb +59 -0
- data/spec/unit/vm/test_proglist_facade.rb +21 -0
- data/tasks/debug_mail.rake +75 -0
- data/tasks/debug_mail.txt +13 -0
- data/tasks/gem.rake +73 -0
- data/tasks/spec_test.rake +71 -0
- data/tasks/unit_test.rake +76 -0
- data/tasks/yard.rake +51 -0
- metadata +493 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
module Gisele
|
|
3
|
+
class VM
|
|
4
|
+
describe Bytecode, 'fetch' do
|
|
5
|
+
|
|
6
|
+
let(:bytecode){
|
|
7
|
+
Bytecode.new([:gvm, [:block, :s0, [:push, 12]]])
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
it 'returns the set of instructions at that label' do
|
|
11
|
+
bytecode[:s0].should eq([ [:push, 12] ])
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it 'returns nil if no such label' do
|
|
15
|
+
bytecode[:s10].should be_nil
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
module Gisele
|
|
3
|
+
class VM
|
|
4
|
+
describe Bytecode::Grammar do
|
|
5
|
+
|
|
6
|
+
it 'recognizes bad instructions' do
|
|
7
|
+
(Bytecode::Grammar[:instruction] === [:push, 12]).should be_true
|
|
8
|
+
(Bytecode::Grammar[:instruction] === [:push]).should be_false
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it 'recognizes bad blocks' do
|
|
12
|
+
(Bytecode::Grammar[:block] === [:block]).should be_false
|
|
13
|
+
(Bytecode::Grammar[:block] === [:block, 0]).should be_false
|
|
14
|
+
(Bytecode::Grammar[:block] === [:block, 0, [:push]]).should be_false
|
|
15
|
+
(Bytecode::Grammar[:block] === [:block, 0, [:push, 12]]).should be_true
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it 'recognize bad files' do
|
|
19
|
+
(Bytecode::Grammar === [:gvm, [:block, 0, [:push]]]).should be_false
|
|
20
|
+
(Bytecode::Grammar === [:gvm, [:block, 0, [:push, 12]]]).should be_true
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it 'provides the list of instruction names' do
|
|
24
|
+
Bytecode::Grammar.instructions.should be_a(Array)
|
|
25
|
+
Bytecode::Grammar.instructions.include?(:push).should be_true
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
module Gisele
|
|
3
|
+
class VM
|
|
4
|
+
describe Bytecode, '.parse' do
|
|
5
|
+
|
|
6
|
+
let(:file){ Path.dir/'bytecode.gvm' }
|
|
7
|
+
|
|
8
|
+
subject{
|
|
9
|
+
Bytecode.parse(file)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
it 'returns a Bytecode instance' do
|
|
13
|
+
subject.should be_a(Bytecode)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it 'has the expected bytecode' do
|
|
17
|
+
subject[:s0].should eq([ [:push, 12] ])
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
module Gisele
|
|
3
|
+
class VM
|
|
4
|
+
describe Bytecode, '+' do
|
|
5
|
+
|
|
6
|
+
subject{
|
|
7
|
+
left + right
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
let(:left) { Bytecode.coerce('s0: push 12') }
|
|
11
|
+
let(:right){ 's1: push 14' }
|
|
12
|
+
|
|
13
|
+
it 'returns a Bytecode' do
|
|
14
|
+
subject.should be_a(Bytecode)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it 'denotes the concatenation of bytecodes' do
|
|
18
|
+
expected = [:gvm,
|
|
19
|
+
[:block, :s0, [ :push, 12 ]],
|
|
20
|
+
[:block, :s1, [ :push, 14 ]]
|
|
21
|
+
]
|
|
22
|
+
subject.to_a.should eq(expected)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
module Gisele
|
|
3
|
+
class VM
|
|
4
|
+
describe Bytecode, 'to_a' do
|
|
5
|
+
|
|
6
|
+
let(:gvm){
|
|
7
|
+
[:gvm, [:block, :s0, [:push, 12]]]
|
|
8
|
+
}
|
|
9
|
+
let(:bytecode){
|
|
10
|
+
Bytecode.new(gvm)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
it 'returns the gvm array' do
|
|
14
|
+
bytecode.to_a.should eq(gvm)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
module Gisele
|
|
3
|
+
class VM
|
|
4
|
+
describe Bytecode, 'to_a' do
|
|
5
|
+
|
|
6
|
+
let(:bytecode){
|
|
7
|
+
Bytecode.coerce <<-BC.gsub(/^\s+/, '')
|
|
8
|
+
s0: push 12
|
|
9
|
+
pop
|
|
10
|
+
a_long_label: push [12, "hello"]
|
|
11
|
+
push {:hello => :s1}
|
|
12
|
+
BC
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
subject{ bytecode.to_s.strip }
|
|
16
|
+
|
|
17
|
+
it 'should indent friendly' do
|
|
18
|
+
subject.should eq(<<-STR.gsub(/^\s+\| /, '').strip)
|
|
19
|
+
| s0: push 12
|
|
20
|
+
| pop
|
|
21
|
+
| a_long_label: push [12, "hello"]
|
|
22
|
+
| push {:hello=>:s1}
|
|
23
|
+
STR
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it 'should print equivalent bytecode' do
|
|
27
|
+
Bytecode.parse(bytecode.to_s).to_a.should eq(bytecode.to_a)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
module Gisele
|
|
3
|
+
class VM
|
|
4
|
+
describe Command, "vm" do
|
|
5
|
+
|
|
6
|
+
subject do
|
|
7
|
+
c = Command.new
|
|
8
|
+
c.parse_options argv
|
|
9
|
+
c.vm(Path.dir/'code.gis')
|
|
10
|
+
end
|
|
11
|
+
let(:components){ subject.components }
|
|
12
|
+
|
|
13
|
+
after do
|
|
14
|
+
components.any?{|c| c.is_a?(ProgList)}.should be_true
|
|
15
|
+
components.any?{|c| c.is_a?(EventManager)}.should be_true
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
context 'without options' do
|
|
19
|
+
let(:argv){ [] }
|
|
20
|
+
it 'should have an Enacter' do
|
|
21
|
+
components.any?{|c| c.is_a?(Enacter)}.should be_true
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
context 'with --simulate' do
|
|
26
|
+
let(:argv){ ["--simulate"] }
|
|
27
|
+
it 'should have Simulator agents' do
|
|
28
|
+
pending{
|
|
29
|
+
components.any?{|c| c.is_a?(Simulator::Resumer)}.should be_true
|
|
30
|
+
components.any?{|c| c.is_a?(Simulator::Starter)}.should be_true
|
|
31
|
+
}
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
context 'with --interactive' do
|
|
36
|
+
let(:argv){ ["--interactive"] }
|
|
37
|
+
it 'should have a Console agent' do
|
|
38
|
+
components.any?{|c| c.is_a?(Console)}.should be_true
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
context 'with --storage' do
|
|
43
|
+
let(:argv){ ["--storage=postgres://localhost/gvm"] }
|
|
44
|
+
it 'sets the options on ProgList correctly' do
|
|
45
|
+
subject.proglist.options[:uri].should eq("postgres://localhost/gvm")
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
module Gisele
|
|
3
|
+
module Compiling
|
|
4
|
+
describe Gisele2Gts, "on_par_st" do
|
|
5
|
+
|
|
6
|
+
before do
|
|
7
|
+
subject.ith_state(0).initial!
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
subject do
|
|
11
|
+
code = <<-GIS.strip
|
|
12
|
+
par
|
|
13
|
+
Ping
|
|
14
|
+
Pong
|
|
15
|
+
end
|
|
16
|
+
GIS
|
|
17
|
+
Gisele2Gts.compile code.strip, :root => :par_st
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
let :expected do
|
|
21
|
+
ping = Gisele2Gts.compile("Ping", :root => :task_call_st)
|
|
22
|
+
pong = Gisele2Gts.compile("Pong", :root => :task_call_st)
|
|
23
|
+
Gts.new do
|
|
24
|
+
s0 = add_state :kind => :fork, :initial => true
|
|
25
|
+
s1 = add_state :kind => :end, :accepting => true
|
|
26
|
+
s2 = add_state :kind => :end, :accepting => true
|
|
27
|
+
s3 = add_state :kind => :join, :accepting => true
|
|
28
|
+
connect(s0, s3, :symbol => :"(wait)")
|
|
29
|
+
|
|
30
|
+
ping.dup(self) do |source,target|
|
|
31
|
+
connect(s0, target, :symbol => :"(forked#0)") if source.in_edges.empty?
|
|
32
|
+
connect(target, s1, :symbol => :"(joined)") if source.out_edges.empty?
|
|
33
|
+
end
|
|
34
|
+
pong.dup(self) do |source,target|
|
|
35
|
+
connect(s0, target, :symbol => :"(forked#1)") if source.in_edges.empty?
|
|
36
|
+
connect(target, s2, :symbol => :"(joined)") if source.out_edges.empty?
|
|
37
|
+
end
|
|
38
|
+
connect(s1, s3, :symbol => :"(notify)")
|
|
39
|
+
connect(s2, s3, :symbol => :"(notify)")
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it 'generates an equivalent transition system' do
|
|
44
|
+
# (Path.pwd/'examples/gts.dot').write subject.to_dot
|
|
45
|
+
# (Path.pwd/'examples/expected.dot').write expected.to_dot
|
|
46
|
+
subject.bytecode_equivalent!(expected).should be_true
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
module Gisele
|
|
3
|
+
module Compiling
|
|
4
|
+
describe Gisele2Gts, "on_seq_def" do
|
|
5
|
+
|
|
6
|
+
before do
|
|
7
|
+
subject.ith_state(0).initial!
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
subject do
|
|
11
|
+
code = <<-GIS.strip
|
|
12
|
+
seq
|
|
13
|
+
Ping
|
|
14
|
+
Pong
|
|
15
|
+
end
|
|
16
|
+
GIS
|
|
17
|
+
Gisele2Gts.compile code.strip, :root => :seq_st
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
let :expected do
|
|
21
|
+
ping = Gisele2Gts.compile("Ping", :root => :task_call_st)
|
|
22
|
+
pong = Gisele2Gts.compile("Pong", :root => :task_call_st)
|
|
23
|
+
Gts.new do
|
|
24
|
+
s0 = add_state :kind => :nop, :initial => true
|
|
25
|
+
s1 = add_state :kind => :nop
|
|
26
|
+
ping_end = nil
|
|
27
|
+
ping.dup(self) do |source,target|
|
|
28
|
+
connect(s0, target, :symbol => nil) if source.in_edges.empty?
|
|
29
|
+
ping_end = target if source.out_edges.empty?
|
|
30
|
+
end
|
|
31
|
+
pong.dup(self) do |source,target|
|
|
32
|
+
connect(ping_end, target, :symbol => nil) if source.in_edges.empty?
|
|
33
|
+
connect(target, s1, :symbol => nil) if source.out_edges.empty?
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it 'generates an equivalent transition system' do
|
|
39
|
+
# (Path.pwd/'examples/gts.dot').write subject.to_dot
|
|
40
|
+
# (Path.pwd/'examples/expected.dot').write expected.to_dot
|
|
41
|
+
subject.bytecode_equivalent!(expected).should be_true
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
module Gisele
|
|
3
|
+
module Compiling
|
|
4
|
+
describe Gisele2Gts, "on_task_call_st" do
|
|
5
|
+
|
|
6
|
+
before do
|
|
7
|
+
subject.ith_state(0).initial!
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
subject do
|
|
11
|
+
Gisele2Gts.compile "Hello", :root => :task_call_st
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
let :expected do
|
|
15
|
+
Gts.new do
|
|
16
|
+
add_state :kind => :fork, :initial => true
|
|
17
|
+
add_state :kind => :event
|
|
18
|
+
add_state :kind => :listen, :accepting => true
|
|
19
|
+
add_state :kind => :event
|
|
20
|
+
add_state :kind => :end, :accepting => true
|
|
21
|
+
add_state :kind => :join, :accepting => true
|
|
22
|
+
connect 0, 1, :symbol => :"(forked)"
|
|
23
|
+
connect 1, 2, :symbol => :start, :event_args => [ "Hello" ]
|
|
24
|
+
connect 2, 3, :symbol => :ended
|
|
25
|
+
connect 3, 4, :symbol => :end, :event_args => [ "Hello" ]
|
|
26
|
+
connect 4, 5, :symbol => :"(notify)"
|
|
27
|
+
connect 0, 5, :symbol => :"(wait)"
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it 'generates an equivalent transition system' do
|
|
32
|
+
subject.bytecode_equivalent!(expected).should be_true
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
module Gisele
|
|
3
|
+
module Compiling
|
|
4
|
+
describe Gisele2Gts, "on_task_def" do
|
|
5
|
+
|
|
6
|
+
before do
|
|
7
|
+
subject
|
|
8
|
+
subject.ith_state(0).initial!
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
subject do
|
|
12
|
+
code = <<-GIS.strip
|
|
13
|
+
task Main
|
|
14
|
+
Hello
|
|
15
|
+
end
|
|
16
|
+
GIS
|
|
17
|
+
Gisele2Gts.compile(code, :root => :task_def)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
let :expected do
|
|
21
|
+
Gts.new do
|
|
22
|
+
add_state :kind =>:event, :initial => true
|
|
23
|
+
add_state :kind => :fork
|
|
24
|
+
add_state :kind => :event
|
|
25
|
+
add_state :kind => :listen, :accepting => true
|
|
26
|
+
add_state :kind => :event
|
|
27
|
+
add_state :kind => :end, :accepting => true
|
|
28
|
+
add_state :kind => :join, :accepting => true
|
|
29
|
+
add_state :kind => :event
|
|
30
|
+
add_state :kind => :end, :accepting => true
|
|
31
|
+
connect 0, 1, :symbol => :start, :event_args => [ "Main" ]
|
|
32
|
+
connect 1, 2, :symbol => :"(forked)"
|
|
33
|
+
connect 2, 3, :symbol => :start, :event_args => [ "Hello" ]
|
|
34
|
+
connect 3, 4, :symbol => :ended
|
|
35
|
+
connect 4, 5, :symbol => :end, :event_args => [ "Hello" ]
|
|
36
|
+
connect 5, 6, :symbol => :"(notify)"
|
|
37
|
+
connect 1, 6, :symbol => :"(wait)"
|
|
38
|
+
connect 6, 7, :symbol => nil
|
|
39
|
+
connect 7, 8, :symbol => :end, :event_args => [ "Main" ]
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it 'generates an equivalent transition system' do
|
|
44
|
+
subject.bytecode_equivalent!(expected).should be_true
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
module Gisele
|
|
3
|
+
module Compiling
|
|
4
|
+
describe Gisele2Gts, "on_unit_def" do
|
|
5
|
+
|
|
6
|
+
subject do
|
|
7
|
+
code = <<-GIS.strip
|
|
8
|
+
task Ping
|
|
9
|
+
Helli
|
|
10
|
+
end
|
|
11
|
+
GIS
|
|
12
|
+
Gisele2Gts.compile code.strip
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
let :expected do
|
|
16
|
+
ping = Gisele2Gts.compile("task Ping Helli end", :root => :task_def)
|
|
17
|
+
Gts.new do
|
|
18
|
+
s0 = add_state :kind => :launch, :initial => true
|
|
19
|
+
s1 = add_state :kind => :end, :accepting => true
|
|
20
|
+
ping.dup(self) do |source,target|
|
|
21
|
+
connect(s0, target, :symbol => :Ping) if source.in_edges.empty?
|
|
22
|
+
connect(target, s1, :symbol => nil) if source.out_edges.empty?
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it 'generates an equivalent transition system' do
|
|
28
|
+
# (Path.pwd/'examples/gts.dot').write gts.to_dot
|
|
29
|
+
# (Path.pwd/'examples/expected.dot').write expected.to_dot
|
|
30
|
+
subject.bytecode_equivalent!(expected).should be_true
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
module Gisele
|
|
3
|
+
module Compiling
|
|
4
|
+
describe Gts2Bytecode, "on_end" do
|
|
5
|
+
|
|
6
|
+
let(:gts) do
|
|
7
|
+
Gts.new do
|
|
8
|
+
add_state :kind => :end
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
let(:compiler){ Gts2Bytecode.new }
|
|
12
|
+
let(:bytecode){ compiler.builder.to_a }
|
|
13
|
+
|
|
14
|
+
before do
|
|
15
|
+
subject
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
subject do
|
|
19
|
+
compiler.on_end(gts.ith_state(0))
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it 'should generate the expected bytecode' do
|
|
23
|
+
bytecode.should eq([:gvm,
|
|
24
|
+
[:block, :s0,
|
|
25
|
+
[:then, :notify] ]
|
|
26
|
+
])
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|