brainclusterfuck 0.0.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +6 -0
- data/Gemfile +1 -1
- data/README.md +4 -0
- data/lib/brainclusterfuck/compile_error.rb +10 -0
- data/lib/brainclusterfuck/compiler.rb +57 -35
- data/lib/brainclusterfuck/error.rb +5 -0
- data/lib/brainclusterfuck/interpreter.rb +84 -0
- data/lib/brainclusterfuck/interpreter_error.rb +4 -0
- data/lib/brainclusterfuck/lexer.rb +2 -2
- data/lib/brainclusterfuck/loop_error.rb +6 -0
- data/lib/brainclusterfuck/memory.rb +33 -0
- data/lib/brainclusterfuck/memory_error.rb +6 -0
- data/lib/brainclusterfuck/opcodes.rb +5 -0
- data/lib/brainclusterfuck/opcodes/base.rb +19 -0
- data/lib/brainclusterfuck/opcodes/loop_base.rb +27 -0
- data/lib/brainclusterfuck/opcodes/loop_end.rb +10 -0
- data/lib/brainclusterfuck/opcodes/loop_end_placeholder.rb +6 -0
- data/lib/brainclusterfuck/opcodes/loop_placeholder.rb +20 -0
- data/lib/brainclusterfuck/opcodes/loop_start.rb +10 -0
- data/lib/brainclusterfuck/opcodes/loop_start_placeholder.rb +6 -0
- data/lib/brainclusterfuck/opcodes/modify_pointer.rb +9 -0
- data/lib/brainclusterfuck/opcodes/modify_value.rb +6 -0
- data/lib/brainclusterfuck/opcodes/modifying_base.rb +27 -0
- data/lib/brainclusterfuck/opcodes/print.rb +13 -0
- data/lib/brainclusterfuck/terminal.rb +4 -0
- data/lib/brainclusterfuck/version.rb +1 -1
- data/spec/compiler_spec.rb +82 -16
- data/spec/integration/basic_loops_spec.rb +55 -0
- data/spec/integration/basic_print_spec.rb +65 -0
- data/spec/integration/boundary_conditions_spec.rb +81 -0
- data/spec/interpreter_spec.rb +154 -0
- data/spec/lexer_spec.rb +2 -2
- data/spec/memory_spec.rb +33 -0
- data/spec/opcodes/base_spec.rb +26 -0
- data/spec/opcodes/loop_end_placeholder_spec.rb +5 -0
- data/spec/opcodes/loop_end_spec.rb +7 -0
- data/spec/opcodes/loop_start_placeholder_spec.rb +5 -0
- data/spec/opcodes/loop_start_spec.rb +7 -0
- data/spec/opcodes/modify_pointer_spec.rb +6 -0
- data/spec/opcodes/modify_value_spec.rb +6 -0
- data/spec/{opcode → opcodes}/print_spec.rb +3 -3
- data/spec/spec_helper.rb +2 -0
- data/spec/support/loop_opcode_shared_behavior.rb +22 -0
- data/spec/support/loop_placeholder_shared_behavior.rb +12 -0
- data/spec/{opcode/modify_value_spec.rb → support/modifying_opcode_shared_behavior.rb} +4 -7
- data/spec/terminal_spec.rb +11 -0
- metadata +60 -20
- data/lib/brainclusterfuck/cells.rb +0 -9
- data/lib/brainclusterfuck/opcode.rb +0 -11
- data/lib/brainclusterfuck/opcode/modify_pointer.rb +0 -27
- data/lib/brainclusterfuck/opcode/modify_value.rb +0 -27
- data/lib/brainclusterfuck/opcode/print.rb +0 -13
- data/lib/brainclusterfuck/vm.rb +0 -11
- data/spec/cells_spec.rb +0 -8
- data/spec/opcode/modify_pointer_spec.rb +0 -37
- data/spec/opcode_spec.rb +0 -10
- data/spec/vm_spec.rb +0 -22
data/lib/brainclusterfuck/vm.rb
DELETED
data/spec/cells_spec.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'brainclusterfuck/opcode/modify_pointer'
|
3
|
-
|
4
|
-
describe Brainclusterfuck::Opcode::ModifyPointer do
|
5
|
-
it 'stores the modify by and cycle count' do
|
6
|
-
op = described_class.new(5, 8)
|
7
|
-
|
8
|
-
expect(op.modify_by).to eq(5)
|
9
|
-
expect(op.cycles).to eq(8)
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'has correct equality behavior' do
|
13
|
-
expect(described_class.new(1, 2)).to eq(described_class.new(1, 2))
|
14
|
-
expect(described_class.new(1, 2)).not_to eq(described_class.new(1, 3))
|
15
|
-
end
|
16
|
-
|
17
|
-
describe 'squeezing' do
|
18
|
-
it 'can squeeze with another ModifyPointer' do
|
19
|
-
op1 = described_class.new(1, 1)
|
20
|
-
op2 = described_class.new(1, 1)
|
21
|
-
|
22
|
-
expect(op1.can_squeeze_with?(op2)).to eq(true)
|
23
|
-
expect(op1.squeeze_with(op2)).to eq(described_class.new(2, 2))
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'cannot squeeze with a generic opcode' do
|
27
|
-
op = described_class.new(1, 1)
|
28
|
-
expect(op.can_squeeze_with?(Brainclusterfuck::Opcode.new)).to eq(false)
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'raises if trying to squeeze with an incompatible object' do
|
32
|
-
op = described_class.new(1, 1)
|
33
|
-
|
34
|
-
expect { op.squeeze_with(Brainclusterfuck::Opcode.new) }.to raise_error
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
data/spec/opcode_spec.rb
DELETED
data/spec/vm_spec.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'brainclusterfuck/vm'
|
3
|
-
|
4
|
-
describe Brainclusterfuck::VM do
|
5
|
-
let(:instructions) { double(:instructions) }
|
6
|
-
let(:cells) { double(:cells) }
|
7
|
-
let(:terminal) { double(:terminal) }
|
8
|
-
|
9
|
-
let(:vm) do
|
10
|
-
Brainclusterfuck::VM.new(
|
11
|
-
instructions: instructions,
|
12
|
-
cells: cells,
|
13
|
-
terminal: terminal
|
14
|
-
)
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'correctly reads from its option hash' do
|
18
|
-
expect(vm.instructions).to eq(instructions)
|
19
|
-
expect(vm.cells).to eq(cells)
|
20
|
-
expect(vm.terminal).to eq(terminal)
|
21
|
-
end
|
22
|
-
end
|