koi-vm 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
data/koi-vm.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{koi-vm}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Aaron Gough"]
|
@@ -34,6 +34,7 @@ Gem::Specification.new do |s|
|
|
34
34
|
"lib/koi-vm/opcodes/_value_constants.rb",
|
35
35
|
"lib/koi-vm/opcodes/comparative_operations/equal.rb",
|
36
36
|
"lib/koi-vm/opcodes/comparative_operations/greater_than.rb",
|
37
|
+
"lib/koi-vm/opcodes/comparative_operations/invert.rb",
|
37
38
|
"lib/koi-vm/opcodes/comparative_operations/less_than.rb",
|
38
39
|
"lib/koi-vm/opcodes/control_operations/exit.rb",
|
39
40
|
"lib/koi-vm/opcodes/control_operations/no_op.rb",
|
@@ -75,6 +76,7 @@ Gem::Specification.new do |s|
|
|
75
76
|
"test/test_helper.rb",
|
76
77
|
"test/unit/opcodes/comparative_operations/equal_test.rb",
|
77
78
|
"test/unit/opcodes/comparative_operations/greater_than_test.rb",
|
79
|
+
"test/unit/opcodes/comparative_operations/invert_test.rb",
|
78
80
|
"test/unit/opcodes/comparative_operations/less_than_test.rb",
|
79
81
|
"test/unit/opcodes/control_operations/exit_test.rb",
|
80
82
|
"test/unit/opcodes/control_operations/no_op_test.rb",
|
@@ -122,6 +124,7 @@ Gem::Specification.new do |s|
|
|
122
124
|
"test/test_helper.rb",
|
123
125
|
"test/unit/opcodes/comparative_operations/equal_test.rb",
|
124
126
|
"test/unit/opcodes/comparative_operations/greater_than_test.rb",
|
127
|
+
"test/unit/opcodes/comparative_operations/invert_test.rb",
|
125
128
|
"test/unit/opcodes/comparative_operations/less_than_test.rb",
|
126
129
|
"test/unit/opcodes/control_operations/exit_test.rb",
|
127
130
|
"test/unit/opcodes/control_operations/no_op_test.rb",
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module KoiVM
|
2
|
+
class VM
|
3
|
+
|
4
|
+
@@instruction[INVERT] = Proc.new() do |vm|
|
5
|
+
raise StackError, "Expecting at least one item on the data stack" unless(vm.data_stack.length > 0)
|
6
|
+
raise StackError, "Expecting boolean value" unless(vm.data_stack[-1][0] == BOOL_)
|
7
|
+
vm.data_stack[-1][1] = !vm.data_stack[-1][1]
|
8
|
+
vm.instruction_pointer = vm.instruction_pointer + 1
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'test_helper.rb'))
|
2
|
+
|
3
|
+
class InvertTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
include KoiVM
|
6
|
+
|
7
|
+
test "should invert boolean value true -> false" do
|
8
|
+
vm = VM.new
|
9
|
+
vm.data_stack = [[BOOL_, true]]
|
10
|
+
vm.run [
|
11
|
+
INVERT
|
12
|
+
]
|
13
|
+
assert_equal [[BOOL_, false]], vm.data_stack
|
14
|
+
end
|
15
|
+
|
16
|
+
test "should invert boolean value false -> true" do
|
17
|
+
vm = VM.new
|
18
|
+
vm.data_stack = [[BOOL_, false]]
|
19
|
+
vm.run [
|
20
|
+
INVERT
|
21
|
+
]
|
22
|
+
assert_equal [[BOOL_, true]], vm.data_stack
|
23
|
+
end
|
24
|
+
|
25
|
+
test "should raise StackError topmost stack value is not a bool" do
|
26
|
+
assert_raises StackError do
|
27
|
+
vm = VM.new
|
28
|
+
vm.data_stack = [[INTEGER_, 1]]
|
29
|
+
vm.run [
|
30
|
+
INVERT
|
31
|
+
]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
test "should raise StackError if there are no items on the stack" do
|
36
|
+
assert_raises StackError do
|
37
|
+
vm = VM.new
|
38
|
+
vm.run [
|
39
|
+
INVERT
|
40
|
+
]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 2
|
9
|
+
version: 0.0.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Aaron Gough
|
@@ -45,6 +45,7 @@ files:
|
|
45
45
|
- lib/koi-vm/opcodes/_value_constants.rb
|
46
46
|
- lib/koi-vm/opcodes/comparative_operations/equal.rb
|
47
47
|
- lib/koi-vm/opcodes/comparative_operations/greater_than.rb
|
48
|
+
- lib/koi-vm/opcodes/comparative_operations/invert.rb
|
48
49
|
- lib/koi-vm/opcodes/comparative_operations/less_than.rb
|
49
50
|
- lib/koi-vm/opcodes/control_operations/exit.rb
|
50
51
|
- lib/koi-vm/opcodes/control_operations/no_op.rb
|
@@ -86,6 +87,7 @@ files:
|
|
86
87
|
- test/test_helper.rb
|
87
88
|
- test/unit/opcodes/comparative_operations/equal_test.rb
|
88
89
|
- test/unit/opcodes/comparative_operations/greater_than_test.rb
|
90
|
+
- test/unit/opcodes/comparative_operations/invert_test.rb
|
89
91
|
- test/unit/opcodes/comparative_operations/less_than_test.rb
|
90
92
|
- test/unit/opcodes/control_operations/exit_test.rb
|
91
93
|
- test/unit/opcodes/control_operations/no_op_test.rb
|
@@ -161,6 +163,7 @@ test_files:
|
|
161
163
|
- test/test_helper.rb
|
162
164
|
- test/unit/opcodes/comparative_operations/equal_test.rb
|
163
165
|
- test/unit/opcodes/comparative_operations/greater_than_test.rb
|
166
|
+
- test/unit/opcodes/comparative_operations/invert_test.rb
|
164
167
|
- test/unit/opcodes/comparative_operations/less_than_test.rb
|
165
168
|
- test/unit/opcodes/control_operations/exit_test.rb
|
166
169
|
- test/unit/opcodes/control_operations/no_op_test.rb
|