reli 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 86c2aa64f8ac2610503fc3da8449f1b1574b023e
4
- data.tar.gz: 9e409081e0c9efeb720e4f6fca58212a0507d58f
3
+ metadata.gz: 5070708babce9a5075a328a47581c185481a9778
4
+ data.tar.gz: 49991946d44cb2bdf5c0afc6642bcc5a746318d2
5
5
  SHA512:
6
- metadata.gz: da0b624c4dd332e08f66ef818ec300a608785a543f6d2b211b8bff5962386f66d74a0efdf2528cc60e6ef3f74410d02dd9d6de904ec2b9733bb20b210694345b
7
- data.tar.gz: 54cd93702344a79a9a944f8895b33b8332a7ae737b0f6626bd94b0aea5e216c86ab09a3185d4ee17843095f9c8ee35eb40fbaf5bb31a5eba9857f8caa3431ae7
6
+ metadata.gz: 5008791d68627875efd547aa504b59d21de4e074c3dc65ca58c85e0a2116fbde6a6c13896f9cc5cbfa14c337b95e193653d8a28110be7dc9fc7bdcc150c9ccc9
7
+ data.tar.gz: 3ef76c4a5eb89b6759904eb96c508e4487ef934b8880a6929364022c5f8f732bf4acf74b8bf16ea57744609874c4ce5a1aabd6f0e7594d64759199789ce37620
data/README.md CHANGED
@@ -22,7 +22,7 @@ Or execute this.
22
22
 
23
23
  ### Basic
24
24
 
25
- `type:` support `:brainfuck`, `:ook`, and `:monamona`.
25
+ `type:` support `:brainfuck`, `:braincrash`, `:ook`, `:monamona`, and `:malbolge`, `:hq9plus`
26
26
 
27
27
  ```ruby
28
28
  require 'reli'
@@ -42,6 +42,16 @@ source = "+++++++++[>++++++++<-]>.<++++[>+++++++<-]>+.+++++++..+++.<++++++++[
42
42
  brainfuck.run(source) #=> Hello World!
43
43
  ```
44
44
 
45
+ ### Braincrash
46
+
47
+ ```ruby
48
+ require 'reli/braincrash'
49
+
50
+ braincrash = RELI::Braincrash.new
51
+ source = ">>>>>>^<<[-]>[[<+>-]>]<<<<<<<<<<<<<"
52
+ braincrash.run(source) #=> Hello World!
53
+ ```
54
+
45
55
  ### Ook!
46
56
 
47
57
  ```ruby
@@ -92,6 +102,16 @@ source = "(=<`#9]~6ZY32V6/S3,Pq)M'&Jk#Gh~De{z@>`v*;yKw%ut4Uqp0/ml>jibgIedFFaZB
92
102
  malbolge.run(source) #=> Hello World!
93
103
  ```
94
104
 
105
+ ### HQ9+
106
+
107
+ ```ruby
108
+ require 'reli/hq9plus'
109
+
110
+ hq9plus = RELI::Hq9plus.new
111
+ source = "H"
112
+ hq9plus.run(source) #=> Hello, world!
113
+ ```
114
+
95
115
  ## TODO
96
116
 
97
117
  * support other esoteric languages
@@ -1,7 +1,9 @@
1
1
  require 'reli/brainfuck'
2
+ require 'reli/braincrash'
2
3
  require 'reli/ook'
3
4
  require 'reli/monamona'
4
5
  require 'reli/malbolge'
6
+ require 'reli/hq9plus'
5
7
 
6
8
  module RELI
7
9
  def self.new(options = {})
@@ -4,7 +4,7 @@ module RELI
4
4
  def initialize(options = {})
5
5
  @memory = []
6
6
  @buffer = []
7
- @pointer = 0; @memory[0] = 0
7
+ @pointer = @memory[0] = 0
8
8
  @size = 1
9
9
  @break = 0
10
10
  end
@@ -0,0 +1,37 @@
1
+ require 'reli/brainfuck'
2
+
3
+ module RELI
4
+ class Braincrash < Brainfuck
5
+ on(?|) do
6
+ @memory[@pointer + 1] |= @memory[@pointer]
7
+ @pointer += 1
8
+ @index += @size
9
+ end
10
+
11
+ on(?&) do
12
+ @memory[@pointer + 1] &= @memory[@pointer]
13
+ @pointer += 1
14
+ @index += @size
15
+ end
16
+
17
+ on(?~) do
18
+ @memory[@pointer] = ~@memory[@pointer]
19
+ @index += @size
20
+ end
21
+
22
+ on(?^) do
23
+ @memory[@pointer + 1] ^= @memory[@pointer]
24
+ @pointer += 1
25
+ @index += @size
26
+ end
27
+
28
+ def initialize(options = {})
29
+ super
30
+ @memory = [72, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100, 33]
31
+ end
32
+
33
+ def run(code)
34
+ super code + "[.>]"
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,43 @@
1
+ require 'reli/abstract'
2
+
3
+ module RELI
4
+ class Hq9plus < Abstract
5
+ def initialize(options = {})
6
+ super
7
+ @a = 0
8
+ end
9
+
10
+ on(?H) do
11
+ @buffer << "Hello, world!"
12
+ @index += @size
13
+ end
14
+
15
+ on(?Q) do
16
+ @buffer += @code
17
+ @index += @size
18
+ end
19
+
20
+ on(?9) do
21
+ 99.downto(1) { |i|
22
+ @buffer << <<-EOS.gsub(/^ */, "")
23
+ #{bottles i} of beer on the wall, #{bottles i} of beer.
24
+ Take one down and pass it around, #{bottles i - 1} of beer on the wall.
25
+ EOS
26
+ }
27
+ @buffer << <<-EOS.gsub(/^ */, "")
28
+ No more bottles of beer on the wall, no more bottles of beer.
29
+ Go to the store and buy some more, 99 bottles of beer on the wall.
30
+ EOS
31
+ @index += @size
32
+ end
33
+
34
+ on(?+) do
35
+ @a += 1
36
+ @index += @size
37
+ end
38
+
39
+ def bottles(i)
40
+ [i == 0? "no more" : i.to_s, " bottle", i == 1? "": "s"].join
41
+ end
42
+ end
43
+ end
@@ -3,6 +3,18 @@ module RELI
3
3
  def initialize(options = {})
4
4
  end
5
5
 
6
+ # lazy evaluation
7
+ def get_orid(a)
8
+ @oridinal_memory[a] = crz get_orid(a - 2), get_orid(a - 1) if a >= @oridinal_memory.length
9
+ return @oridinal_memory[a]
10
+ end
11
+
12
+ def get(addr)
13
+ a = addr[0]
14
+ @memory[a] = get_orid a if a >= @memory.length
15
+ return @memory[a]
16
+ end
17
+
6
18
  def run(code_)
7
19
  code = code_.split(//u).map(&:ord)
8
20
  @a = 0
@@ -11,11 +23,11 @@ module RELI
11
23
 
12
24
  # load step
13
25
  @buffer = []
14
- @memory = []
26
+ @oridinal_memory = @memory = []
15
27
  for char in code
16
- case crypt1 op char
28
+ case crypt1 char
17
29
  when 42, 47, 60, 105, 106, 111, 112, 118
18
- @memory[@c] = char
30
+ @oridinal_memory[@c] = char
19
31
  else
20
32
  # error
21
33
  next
@@ -23,46 +35,45 @@ module RELI
23
35
  @c += 1
24
36
  end
25
37
 
26
- while @c < 3**10
27
- @memory[@c] = crz @memory[@c - 2], @memory[@c - 1]
28
- @c += 1
29
- end
30
-
31
38
  # run
32
39
  @c = 0
33
- while (crypt1 op @memory[@c]) != 118
34
- case crypt1 op @memory[@c]
40
+ while (crypt1 [@c]) != 118
41
+ case crypt1 [@c]
35
42
  when 106
36
- @d = @memory[@d]
43
+ @d = get [@d]
37
44
  when 104
38
- @c = @memory[@d]
45
+ @c = get [@d]
39
46
  when 42
40
47
  rotr
41
- @a = @memory[@d]
48
+ @a = get [@d]
42
49
  when 112
43
- @a = @memory[@d] = crz(@memory[@d], @a)
50
+ @a = @memory[@d] = crz([@d], @a)
44
51
  when 60
45
- @buffer[@buffer.length] = (@a.modulo 256).chr
52
+ @buffer[@buffer.length] = @a
46
53
  when 47
47
54
  @a = $stdin.getc.ord
48
55
  end
49
- @memory[@c] = crypt2 (@memory[@c] - 33).modulo 94
50
- @c = inc(@c)
51
- @d = inc(@d)
56
+ @memory[@c] = crypt2 [@c]
57
+ @c = inc @c
58
+ @d = inc @d
52
59
  end
53
60
 
54
- @buffer.join
61
+ @buffer.map { |a| (a.modulo 256).chr}.join
55
62
  end
56
63
 
57
64
  def crypt1(m)
58
- "+b(29e*j1VMEKLyC})8&m#~W>qxdRp0wkrUo[D7,XTcA\"lI.v%{gJh4G\\-=O@5`_3i<?Z';FNQuY]szf$!BS/|t:Pn6^Ha".split(//)[m].ord
65
+ m = get m if m.class == Array
66
+ "+b(29e*j1VMEKLyC})8&m#~W>qxdRp0wkrUo[D7,XTcA\"lI.v%{gJh4G\\-=O@5`_3i<?Z';FNQuY]szf$!BS/|t:Pn6^Ha"
67
+ .split(//)[(m - 33 + @c).modulo 94].ord
59
68
  end
60
69
 
61
70
  def crypt2(m)
62
- "5z]&gqtyfr$(we4{WP)H-Zn,[%\\3dL+Q;>U!pJS72FhOA1CB6v^=I_0/8|jsb9m<.TVac`uY*MK'X~xDl}REokN:#?G\"i@".split(//)[m].ord
71
+ "5z]&gqtyfr$(we4{WP)H-Zn,[%\\3dL+Q;>U!pJS72FhOA1CB6v^=I_0/8|jsb9m<.TVac`uY*MK'X~xDl}REokN:#?G\"i@"
72
+ .split(//)[((get m) - 33).modulo 94].ord
63
73
  end
64
74
 
65
75
  def crz(a, b)
76
+ a = get a if a.class == Array
66
77
  [a, b].map { |item|
67
78
  sprintf("%010d", item.to_s(3).to_i).split(//).map { |char| char.ord - 0x30 }
68
79
  }.transpose.map { |items|
@@ -71,14 +82,10 @@ module RELI
71
82
  end
72
83
 
73
84
  def rotr()
74
- @memory[@d] += (@memory[@d].modulo 3) * (3 ** 10)
85
+ @memory[@d] += ((get [@d]).modulo 3) * 3 ** 10
75
86
  @memory[@d] /= 3
76
87
  end
77
88
 
78
- def op(c)
79
- (c - 33 + @c).modulo 94
80
- end
81
-
82
89
  def inc(n)
83
90
  n += 1
84
91
  n = 0 if n == 3**10
@@ -1,4 +1,4 @@
1
1
 
2
2
  module RELI
3
- VERSION = '0.2.0'
3
+ VERSION = '0.3.0'
4
4
  end
@@ -0,0 +1 @@
1
+ >>>>>>^<<[-]>[[<+>-]>]<<<<<<<<<<<<<
@@ -8,6 +8,11 @@ module RELI
8
8
  expect(bf.run(hello_world(:brainfuck))).to eq("Hello World!")
9
9
  end
10
10
 
11
+ it "support braincrash" do
12
+ bf = RELI.new(:type => :braincrash)
13
+ expect(bf.run(hello_world(:braincrash))).to eq("Hello World!")
14
+ end
15
+
11
16
  it "support ook" do
12
17
  bf = RELI.new(:type => :ook)
13
18
  expect(bf.run(hello_world(:ook))).to eq("Hello World!")
@@ -22,5 +27,11 @@ module RELI
22
27
  bf = RELI.new(:type => :malbolge)
23
28
  expect(bf.run(hello_world(:malbolge))).to eq("Hello World!")
24
29
  end
30
+
31
+ # HQ9+ never say "Hello World!", instead of "Hello, world!"
32
+ it "support HQ9+" do
33
+ bf = RELI.new(:type => :hq9plus)
34
+ expect(bf.run(hello_world(:hq9plus))).to eq("Hello, world!")
35
+ end
25
36
  end
26
37
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - namusyaka
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-10-06 00:00:00.000000000 Z
12
+ date: 2013-10-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -52,13 +52,17 @@ files:
52
52
  - Rakefile
53
53
  - lib/reli.rb
54
54
  - lib/reli/abstract.rb
55
+ - lib/reli/braincrash.rb
55
56
  - lib/reli/brainfuck.rb
57
+ - lib/reli/hq9plus.rb
56
58
  - lib/reli/malbolge.rb
57
59
  - lib/reli/monamona.rb
58
60
  - lib/reli/ook.rb
59
61
  - lib/reli/version.rb
60
62
  - reli.gemspec
63
+ - spec/fixtures/hello_world/braincrash
61
64
  - spec/fixtures/hello_world/brainfuck
65
+ - spec/fixtures/hello_world/hq9plus
62
66
  - spec/fixtures/hello_world/malbolge
63
67
  - spec/fixtures/hello_world/monamona
64
68
  - spec/fixtures/hello_world/ook