reli 0.2.0 → 0.3.0
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 +4 -4
- data/README.md +21 -1
- data/lib/reli.rb +2 -0
- data/lib/reli/abstract.rb +1 -1
- data/lib/reli/braincrash.rb +37 -0
- data/lib/reli/hq9plus.rb +43 -0
- data/lib/reli/malbolge.rb +33 -26
- data/lib/reli/version.rb +1 -1
- data/spec/fixtures/hello_world/braincrash +1 -0
- data/spec/fixtures/hello_world/hq9plus +1 -0
- data/spec/reli_spec.rb +11 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5070708babce9a5075a328a47581c185481a9778
|
4
|
+
data.tar.gz: 49991946d44cb2bdf5c0afc6642bcc5a746318d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 `:
|
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
|
data/lib/reli.rb
CHANGED
data/lib/reli/abstract.rb
CHANGED
@@ -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
|
data/lib/reli/hq9plus.rb
ADDED
@@ -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
|
data/lib/reli/malbolge.rb
CHANGED
@@ -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
|
28
|
+
case crypt1 char
|
17
29
|
when 42, 47, 60, 105, 106, 111, 112, 118
|
18
|
-
@
|
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
|
34
|
-
case crypt1
|
40
|
+
while (crypt1 [@c]) != 118
|
41
|
+
case crypt1 [@c]
|
35
42
|
when 106
|
36
|
-
@d =
|
43
|
+
@d = get [@d]
|
37
44
|
when 104
|
38
|
-
@c =
|
45
|
+
@c = get [@d]
|
39
46
|
when 42
|
40
47
|
rotr
|
41
|
-
@a =
|
48
|
+
@a = get [@d]
|
42
49
|
when 112
|
43
|
-
@a = @memory[@d] = crz(
|
50
|
+
@a = @memory[@d] = crz([@d], @a)
|
44
51
|
when 60
|
45
|
-
@buffer[@buffer.length] =
|
52
|
+
@buffer[@buffer.length] = @a
|
46
53
|
when 47
|
47
54
|
@a = $stdin.getc.ord
|
48
55
|
end
|
49
|
-
@memory[@c] = crypt2
|
50
|
-
@c = inc
|
51
|
-
@d = inc
|
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
|
-
|
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@"
|
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] += (
|
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
|
data/lib/reli/version.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
>>>>>>^<<[-]>[[<+>-]>]<<<<<<<<<<<<<
|
@@ -0,0 +1 @@
|
|
1
|
+
H
|
data/spec/reli_spec.rb
CHANGED
@@ -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.
|
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-
|
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
|