brainclusterfuck 0.0.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. data/.travis.yml +6 -0
  2. data/Gemfile +1 -1
  3. data/README.md +4 -0
  4. data/lib/brainclusterfuck/compile_error.rb +10 -0
  5. data/lib/brainclusterfuck/compiler.rb +57 -35
  6. data/lib/brainclusterfuck/error.rb +5 -0
  7. data/lib/brainclusterfuck/interpreter.rb +84 -0
  8. data/lib/brainclusterfuck/interpreter_error.rb +4 -0
  9. data/lib/brainclusterfuck/lexer.rb +2 -2
  10. data/lib/brainclusterfuck/loop_error.rb +6 -0
  11. data/lib/brainclusterfuck/memory.rb +33 -0
  12. data/lib/brainclusterfuck/memory_error.rb +6 -0
  13. data/lib/brainclusterfuck/opcodes.rb +5 -0
  14. data/lib/brainclusterfuck/opcodes/base.rb +19 -0
  15. data/lib/brainclusterfuck/opcodes/loop_base.rb +27 -0
  16. data/lib/brainclusterfuck/opcodes/loop_end.rb +10 -0
  17. data/lib/brainclusterfuck/opcodes/loop_end_placeholder.rb +6 -0
  18. data/lib/brainclusterfuck/opcodes/loop_placeholder.rb +20 -0
  19. data/lib/brainclusterfuck/opcodes/loop_start.rb +10 -0
  20. data/lib/brainclusterfuck/opcodes/loop_start_placeholder.rb +6 -0
  21. data/lib/brainclusterfuck/opcodes/modify_pointer.rb +9 -0
  22. data/lib/brainclusterfuck/opcodes/modify_value.rb +6 -0
  23. data/lib/brainclusterfuck/opcodes/modifying_base.rb +27 -0
  24. data/lib/brainclusterfuck/opcodes/print.rb +13 -0
  25. data/lib/brainclusterfuck/terminal.rb +4 -0
  26. data/lib/brainclusterfuck/version.rb +1 -1
  27. data/spec/compiler_spec.rb +82 -16
  28. data/spec/integration/basic_loops_spec.rb +55 -0
  29. data/spec/integration/basic_print_spec.rb +65 -0
  30. data/spec/integration/boundary_conditions_spec.rb +81 -0
  31. data/spec/interpreter_spec.rb +154 -0
  32. data/spec/lexer_spec.rb +2 -2
  33. data/spec/memory_spec.rb +33 -0
  34. data/spec/opcodes/base_spec.rb +26 -0
  35. data/spec/opcodes/loop_end_placeholder_spec.rb +5 -0
  36. data/spec/opcodes/loop_end_spec.rb +7 -0
  37. data/spec/opcodes/loop_start_placeholder_spec.rb +5 -0
  38. data/spec/opcodes/loop_start_spec.rb +7 -0
  39. data/spec/opcodes/modify_pointer_spec.rb +6 -0
  40. data/spec/opcodes/modify_value_spec.rb +6 -0
  41. data/spec/{opcode → opcodes}/print_spec.rb +3 -3
  42. data/spec/spec_helper.rb +2 -0
  43. data/spec/support/loop_opcode_shared_behavior.rb +22 -0
  44. data/spec/support/loop_placeholder_shared_behavior.rb +12 -0
  45. data/spec/{opcode/modify_value_spec.rb → support/modifying_opcode_shared_behavior.rb} +4 -7
  46. data/spec/terminal_spec.rb +11 -0
  47. metadata +60 -20
  48. data/lib/brainclusterfuck/cells.rb +0 -9
  49. data/lib/brainclusterfuck/opcode.rb +0 -11
  50. data/lib/brainclusterfuck/opcode/modify_pointer.rb +0 -27
  51. data/lib/brainclusterfuck/opcode/modify_value.rb +0 -27
  52. data/lib/brainclusterfuck/opcode/print.rb +0 -13
  53. data/lib/brainclusterfuck/vm.rb +0 -11
  54. data/spec/cells_spec.rb +0 -8
  55. data/spec/opcode/modify_pointer_spec.rb +0 -37
  56. data/spec/opcode_spec.rb +0 -10
  57. data/spec/vm_spec.rb +0 -22
@@ -1,13 +0,0 @@
1
- module Brainclusterfuck
2
- class Opcode
3
- class Print < Opcode
4
- def initialize
5
- @cycles = 1
6
- end
7
-
8
- def ==(other)
9
- other.is_a?(Print)
10
- end
11
- end
12
- end
13
- end
@@ -1,11 +0,0 @@
1
- module Brainclusterfuck
2
- class VM
3
- attr_reader :instructions, :cells, :terminal
4
-
5
- def initialize(opts)
6
- @instructions = opts.fetch(:instructions)
7
- @cells = opts.fetch(:cells)
8
- @terminal = opts.fetch(:terminal)
9
- end
10
- end
11
- end
data/spec/cells_spec.rb DELETED
@@ -1,8 +0,0 @@
1
- require 'spec_helper'
2
- require 'brainclusterfuck/cells'
3
-
4
- describe Brainclusterfuck::Cells do
5
- it 'initializes with a size' do
6
- expect(Brainclusterfuck::Cells.new(5).size).to eq(5)
7
- end
8
- end
@@ -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
@@ -1,10 +0,0 @@
1
- require 'spec_helper'
2
- require 'brainclusterfuck/opcode'
3
-
4
- describe Brainclusterfuck::Opcode do
5
- describe '#can_squeeze_with?' do
6
- it 'is false' do
7
- expect(described_class.new.can_squeeze_with?(described_class.new)).to eq(false)
8
- end
9
- end
10
- end
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