rubyfuu 0.0.1 → 0.0.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 46c420fbf375a8c940ab1320624261406b4e4c4b
4
- data.tar.gz: ab32f7c015e7b6734da321785776309be268cc41
3
+ metadata.gz: c418e179367ca564d0d4b89e42030eeebe639b36
4
+ data.tar.gz: c3baf4b6da362162ff006ebb1855df57597e5bea
5
5
  SHA512:
6
- metadata.gz: 51dbd5bd556434445004cad960c6c93fb091e6a9382257ea0498733250f445c80813c3a9e6a801467fd4a74757afd43967f673e8afdc72206c33502057a70a59
7
- data.tar.gz: c862853ae7e61277fb6b6b78a7ccccc8ab598bc365d9046870063e0c397d79beac64c5a075d749d6de912e8d29b67f98bd1f200c9b0c47f7422b8a51f1ab14cd
6
+ metadata.gz: 0fcc3e33137ad2a01029b56e67c19186aed6ff8ad5222ffe2472a1f88e4abc5e143604800f66ec4be375c15368c9abe39995ac21ae42404bd62384b45bb7bfa0
7
+ data.tar.gz: dfe97c38c558b74756b77862eb99e4b16c213c81d674cdbae6d17e233d1461ea784f651a3fd9111ad6f81a9468a2849d946e6cb4893a7b014b98b4732695d2ca
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Rubyfuu
2
2
 
3
3
  Ruby compiler for Brainfuck programming language. Currently implemented only to
4
- generate 32bit OSX binaries.
4
+ generate 32bit Linux / OSX binaries.
5
5
 
6
6
  ## Installation
7
7
 
@@ -21,6 +21,7 @@ generate 32bit OSX binaries.
21
21
  - Support for other platforms
22
22
  - More options
23
23
  - Cleanup
24
+ - TESTS
24
25
 
25
26
  ## FAQ
26
27
 
data/bin/rubyfuu CHANGED
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ $LOAD_PATH.unshift File.expand_path(File.join(File.dirname(__FILE__), "..", "lib"))
3
4
  require 'rubyfuu/cli'
4
5
 
5
6
  Rubyfuu::CLI.start
@@ -6,60 +6,5 @@ module Rubyfuu
6
6
  @loop_counter = 0
7
7
  @stack = []
8
8
  end
9
-
10
- def >
11
- write 'inc %edi'
12
- end
13
-
14
- def <
15
- write 'dec %edi'
16
- end
17
-
18
- def +
19
- write 'incb (%edi)'
20
- end
21
-
22
- def -
23
- write 'decb (%edi)'
24
- end
25
-
26
- def comma
27
- write 'push $0x1'
28
- write 'push %edi'
29
- write 'push $0x1'
30
-
31
- write 'mov $0x3, %eax'
32
- write 'subl $0x4, %esp'
33
- write 'int $0x80'
34
- write 'addl $16, %esp'
35
- end
36
-
37
- def period
38
- write 'push $0x1'
39
- write 'push %edi'
40
- write 'push $0x1'
41
-
42
- write 'mov $0x4, %eax'
43
- write 'subl $0x4, %esp'
44
- write 'int $0x80'
45
- write 'addl $16, %esp'
46
- end
47
-
48
- def left_bracket
49
- loop = @loop_counter+=1
50
- @stack << loop
51
-
52
- write 'cmpb $0, (%edi)'
53
- write "jz .LE#{loop}"
54
- write ".LS#{loop}:", false
55
- end
56
-
57
- def right_bracket
58
- loop = @stack.pop
59
-
60
- write 'cmpb $0, (%edi)'
61
- write "jnz .LS#{loop}"
62
- write ".LE#{loop}:", false
63
- end
64
9
  end
65
10
  end
@@ -0,0 +1,46 @@
1
+ module Rubyfuu
2
+ class Assembly32 < Assembly
3
+ def header
4
+ write <<EOF
5
+ .lcomm buffer1, 10000
6
+
7
+ .globl _main
8
+ _main:
9
+ \tmov $buffer1, %edi
10
+ EOF
11
+ end
12
+
13
+ def left_bracket
14
+ loop = @loop_counter+=1
15
+ @stack << loop
16
+
17
+ write 'cmpb $0, (%edi)'
18
+ write "jz .LE#{loop}"
19
+ write ".LS#{loop}:", false
20
+ end
21
+
22
+ def right_bracket
23
+ loop = @stack.pop
24
+
25
+ write 'cmpb $0, (%edi)'
26
+ write "jnz .LS#{loop}"
27
+ write ".LE#{loop}:", false
28
+ end
29
+
30
+ def >
31
+ write 'inc %edi'
32
+ end
33
+
34
+ def <
35
+ write 'dec %edi'
36
+ end
37
+
38
+ def +
39
+ write 'incb (%edi)'
40
+ end
41
+
42
+ def -
43
+ write 'decb (%edi)'
44
+ end
45
+ end
46
+ end
data/lib/rubyfuu/cli.rb CHANGED
@@ -15,6 +15,11 @@ module Rubyfuu
15
15
  with_rescue { builder.run(path) }
16
16
  end
17
17
 
18
+ desc "version", "Show Rubyfuu version"
19
+ def version
20
+ puts "Rubyfuu #{VERSION}"
21
+ end
22
+
18
23
  private
19
24
  def with_rescue(&block)
20
25
  yield
@@ -24,13 +24,10 @@ module Rubyfuu
24
24
  link(compile, outfile)
25
25
  end
26
26
 
27
- def link
28
- raise Error::NotImplemented
29
- end
30
-
31
27
  def compile
32
28
  header
33
29
  while c = @readable.getc
30
+ c = c.chr
34
31
  if OPERATORS.has_key?(c)
35
32
  parse(c)
36
33
  end
@@ -41,14 +38,11 @@ module Rubyfuu
41
38
  end
42
39
 
43
40
  def parse(char)
44
- public_send method_name(char)
41
+ send method_name(char)
45
42
  end
46
43
 
47
44
  def method_name(char)
48
- OPERATORS.each do |from,to|
49
- char.gsub!(from, to) if to
50
- end
51
- char
45
+ OPERATORS[char] || char
52
46
  end
53
47
  end
54
48
  end
@@ -0,0 +1,35 @@
1
+ module Rubyfuu
2
+ class LinuxAssembly32 < Assembly32
3
+ def footer
4
+ write <<EOF
5
+ \tmov $0, %ebx
6
+ \tmov $1, %eax
7
+ \tint $0x80
8
+ EOF
9
+ end
10
+
11
+ def period
12
+ write 'mov $1, %edx'
13
+ write 'mov %edi, %ecx'
14
+ write 'mov $1, %ebx'
15
+ write 'mov $4, %eax'
16
+ write 'int $0x80'
17
+ end
18
+
19
+ def comma
20
+ write 'mov $1, %edx'
21
+ write 'mov %edi, %ecx'
22
+ write 'mov $1, %ebx'
23
+ write 'mov $3, %eax'
24
+ write 'int $0x80'
25
+ end
26
+
27
+ def link(source_path, outfile)
28
+ tempfile = Tempfile.new(["out", ".o"])
29
+ tempfile.close
30
+
31
+ system "as --32 -o #{tempfile.path} #{source_path} && ld -e _main -o #{outfile} #{tempfile.path}"
32
+ tempfile.unlink
33
+ end
34
+ end
35
+ end
data/lib/rubyfuu/os.rb ADDED
@@ -0,0 +1,17 @@
1
+ require 'rbconfig'
2
+
3
+ module Rubyfuu
4
+ class OS
5
+ def self.host_os
6
+ RbConfig::CONFIG['host_os']
7
+ end
8
+
9
+ def self.osx?
10
+ host_os =~ /darwin/
11
+ end
12
+
13
+ def self.linux?
14
+ host_os =~ /linux/
15
+ end
16
+ end
17
+ end
@@ -1,15 +1,5 @@
1
1
  module Rubyfuu
2
- class OSXAssembly32 < Assembly
3
- def header
4
- write <<EOF
5
- .lcomm buffer1, 10000
6
-
7
- .globl _main
8
- _main:
9
- \tmov $buffer1, %edi
10
- EOF
11
- end
12
-
2
+ class OSXAssembly32 < Assembly32
13
3
  def footer
14
4
  write <<EOF
15
5
  \tpush $0
@@ -19,6 +9,28 @@ EOF
19
9
  EOF
20
10
  end
21
11
 
12
+ def comma
13
+ write 'push $0x1'
14
+ write 'push %edi'
15
+ write 'push $0x1'
16
+
17
+ write 'mov $3, %eax'
18
+ write 'subl $4, %esp'
19
+ write 'int $0x80'
20
+ write 'addl $16, %esp'
21
+ end
22
+
23
+ def period
24
+ write 'push $1'
25
+ write 'push %edi'
26
+ write 'push $1'
27
+
28
+ write 'mov $4, %eax'
29
+ write 'subl $4, %esp'
30
+ write 'int $0x80'
31
+ write 'addl $16, %esp'
32
+ end
33
+
22
34
  def link(source_path, outfile)
23
35
  tempfile = Tempfile.new(["out", ".o"])
24
36
  tempfile.close
@@ -1,3 +1,3 @@
1
1
  module Rubyfuu
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/rubyfuu.rb CHANGED
@@ -1,17 +1,23 @@
1
1
  require 'rubyfuu/version'
2
+ require 'rubyfuu/os'
2
3
 
3
4
  require 'rubyfuu/file_writer'
4
5
 
5
6
  require 'rubyfuu/compiler'
6
7
  require 'rubyfuu/assembly'
7
- require 'rubyfuu/osx_assembly'
8
+ require 'rubyfuu/assembly32'
8
9
  require 'rubyfuu/osx_assembly32'
10
+ require 'rubyfuu/linux_assembly32'
9
11
 
10
12
  require 'tempfile'
11
13
 
12
14
  module Rubyfuu
13
15
  class Builder
14
- def initialize(compiler = OSXAssembly32)
16
+ def initialize(compiler = nil)
17
+ unless compiler
18
+ compiler = OS.osx? ? OSXAssembly32 : LinuxAssembly32
19
+ end
20
+
15
21
  @compiler = compiler
16
22
  end
17
23
 
data/rubyfuu.gemspec CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["Jan Votava"]
10
10
  spec.email = ["votava@deployment.cz"]
11
11
  spec.summary = %q{Brainfuck compiler written in Ruby}
12
- spec.description = %q{Brainfuck compiler written in Ruby - highly experimental and for fun}
12
+ spec.description = %q{Brainfuck compiler written in Ruby - highly serious project}
13
13
  spec.homepage = "http://github.com/cyner/rubyfuu"
14
14
  spec.license = "MIT"
15
15
 
@@ -21,5 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.add_runtime_dependency 'thor', '~> 0.19', '>= 0.19.1'
22
22
 
23
23
  spec.add_development_dependency "bundler", "~> 1.6"
24
+ spec.add_development_dependency "rspec", '~> 2.14'
25
+
24
26
  spec.add_development_dependency "rake"
25
27
  end
@@ -0,0 +1,6 @@
1
+ require 'spec_helper'
2
+
3
+
4
+ describe Rubyfuu::LinuxAssembly32 do
5
+ it_should_behave_like "a compile interface"
6
+ end
@@ -0,0 +1,6 @@
1
+ require 'spec_helper'
2
+
3
+
4
+ describe Rubyfuu::OSXAssembly32 do
5
+ it_should_behave_like "a compile interface"
6
+ end
@@ -0,0 +1,16 @@
1
+ $LOAD_PATH.unshift File.expand_path(File.join(File.dirname(__FILE__), "support"))
2
+ require 'rubyfuu'
3
+
4
+ require 'shared_examples/compile_interface'
5
+
6
+ RSpec.configure do |config|
7
+ config.treat_symbols_as_metadata_keys_with_true_values = true
8
+ config.run_all_when_everything_filtered = true
9
+ config.filter_run :focus
10
+
11
+ # Run specs in random order to surface order dependencies. If you find an
12
+ # order dependency and want to debug it, you can fix the order by providing
13
+ # the seed, which is printed after each run.
14
+ # --seed 1234
15
+ config.order = 'random'
16
+ end
@@ -0,0 +1,17 @@
1
+ shared_examples_for "a compile interface" do
2
+ context "with instance" do
3
+ subject(:instance) { described_class.new(nil,nil) }
4
+
5
+ it { should respond_to(:header) }
6
+ it { should respond_to(:footer) }
7
+ it { should respond_to(:+) }
8
+ it { should respond_to(:-) }
9
+ it { should respond_to(:<) }
10
+ it { should respond_to(:>) }
11
+ it { should respond_to(:period) }
12
+ it { should respond_to(:comma) }
13
+ it { should respond_to(:left_bracket) }
14
+ it { should respond_to(:right_bracket) }
15
+ it { should respond_to(:link) }
16
+ end
17
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubyfuu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Votava
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-19 00:00:00.000000000 Z
11
+ date: 2014-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -44,6 +44,20 @@ dependencies:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
46
  version: '1.6'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rspec
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '2.14'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '2.14'
47
61
  - !ruby/object:Gem::Dependency
48
62
  name: rake
49
63
  requirement: !ruby/object:Gem::Requirement
@@ -58,7 +72,7 @@ dependencies:
58
72
  - - ">="
59
73
  - !ruby/object:Gem::Version
60
74
  version: '0'
61
- description: Brainfuck compiler written in Ruby - highly experimental and for fun
75
+ description: Brainfuck compiler written in Ruby - highly serious project
62
76
  email:
63
77
  - votava@deployment.cz
64
78
  executables:
@@ -67,6 +81,7 @@ extensions: []
67
81
  extra_rdoc_files: []
68
82
  files:
69
83
  - ".gitignore"
84
+ - ".rspec"
70
85
  - Gemfile
71
86
  - LICENSE.txt
72
87
  - README.md
@@ -74,13 +89,19 @@ files:
74
89
  - bin/rubyfuu
75
90
  - lib/rubyfuu.rb
76
91
  - lib/rubyfuu/assembly.rb
92
+ - lib/rubyfuu/assembly32.rb
77
93
  - lib/rubyfuu/cli.rb
78
94
  - lib/rubyfuu/compiler.rb
79
95
  - lib/rubyfuu/file_writer.rb
80
- - lib/rubyfuu/osx_assembly.rb
96
+ - lib/rubyfuu/linux_assembly32.rb
97
+ - lib/rubyfuu/os.rb
81
98
  - lib/rubyfuu/osx_assembly32.rb
82
99
  - lib/rubyfuu/version.rb
83
100
  - rubyfuu.gemspec
101
+ - spec/lib/linux_assembly32_spec.rb
102
+ - spec/lib/osx_assembly32_spec.rb
103
+ - spec/spec_helper.rb
104
+ - spec/support/shared_examples/compile_interface.rb
84
105
  homepage: http://github.com/cyner/rubyfuu
85
106
  licenses:
86
107
  - MIT
@@ -105,4 +126,8 @@ rubygems_version: 2.2.2
105
126
  signing_key:
106
127
  specification_version: 4
107
128
  summary: Brainfuck compiler written in Ruby
108
- test_files: []
129
+ test_files:
130
+ - spec/lib/linux_assembly32_spec.rb
131
+ - spec/lib/osx_assembly32_spec.rb
132
+ - spec/spec_helper.rb
133
+ - spec/support/shared_examples/compile_interface.rb
@@ -1,4 +0,0 @@
1
- module Rubyfuu
2
- class OSXAssembly < Assembly
3
- end
4
- end