rpxem 0.0.1
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.
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/MIT-LICENSE.txt +22 -0
- data/README.md +61 -0
- data/Rakefile +12 -0
- data/bin/rpxem +14 -0
- data/lib/rpxem/interpreter.rb +232 -0
- data/lib/rpxem/stack.rb +47 -0
- data/lib/rpxem/version.rb +3 -0
- data/lib/rpxem.rb +20 -0
- data/rpxem.gemspec +21 -0
- data/spec/rpxem_helper.rb +13 -0
- data/spec/rpxem_spec.rb +196 -0
- data/spec/world!.fHello,.pxe +1 -0
- metadata +112 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/MIT-LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 wktk
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# RPxem
|
2
|
+
|
3
|
+
[](https://travis-ci.org/wktk/rpxem)
|
4
|
+
|
5
|
+
RPxem is a Ruby implementation of [Pxem], a esoteric programming language that
|
6
|
+
enables you to create programs in 0-byte files.
|
7
|
+
[Pxem]: http://cfs.maxn.jp/neta/pxem.php
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
gem 'rpxem'
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install rpxem
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
### Using in Ruby
|
26
|
+
|
27
|
+
Require `RPxem`:
|
28
|
+
|
29
|
+
require 'rpxem'
|
30
|
+
|
31
|
+
Open and execute your Pxem **file**:
|
32
|
+
|
33
|
+
path_to_pxem_file = '~/Hello, world!.pxe'
|
34
|
+
RPxem.open(path_to_pxem_file) #=> Hello, world!
|
35
|
+
|
36
|
+
Execute your Pxem **code**:
|
37
|
+
|
38
|
+
file_name = 'world!.fHello,.pxe'
|
39
|
+
file_cont = ' Pxem '
|
40
|
+
RPxem.run(file_name, file_cont) #=> Hello, Pxem world!
|
41
|
+
|
42
|
+
### Using from CLI
|
43
|
+
|
44
|
+
This program also runs as a command-line Pxem interpreter called `rpxem`:
|
45
|
+
|
46
|
+
$ touch "Hello, world!.pxe"
|
47
|
+
$ rpxem "Hello, world!.pxe"
|
48
|
+
Hello, world!
|
49
|
+
|
50
|
+
## Contributing
|
51
|
+
|
52
|
+
1. Fork it
|
53
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
54
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
55
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
56
|
+
5. Create new Pull Request
|
57
|
+
|
58
|
+
## License
|
59
|
+
|
60
|
+
Copyright (c) 2012 wktk. This software is distributed under the
|
61
|
+
MIT License. See `MIT-LICENSE.txt` for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
require 'bundler/gem_tasks'
|
3
|
+
|
4
|
+
task :default => [:spec]
|
5
|
+
begin
|
6
|
+
require 'rspec/core/rake_task'
|
7
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
8
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
9
|
+
spec.rspec_opts = ['-cfs']
|
10
|
+
end
|
11
|
+
rescue LoadError => e
|
12
|
+
end
|
data/bin/rpxem
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
if (!ARGV[0] || /^-/ =~ ARGV[0] && !File.exist?(ARGV[0]))
|
4
|
+
require 'rpxem/version'
|
5
|
+
puts "RPxem (#{RPxem::VERSION}) https://github.com/wtkt/rpxem"
|
6
|
+
puts 'Usage: rpxem path-to-pxem-file.pxe'
|
7
|
+
puts 'Report bugs to <https://github.com/wktk/rpxem/issues>.'
|
8
|
+
elsif (!File.exist?(ARGV[0]) || !source = open(ARGV[0]).read)
|
9
|
+
puts "Can't load file: #{ARGV[0]}"
|
10
|
+
puts "Try `rpxem --help' for more infomation."
|
11
|
+
else
|
12
|
+
require 'rpxem'
|
13
|
+
RPxem.run(File::basename(ARGV[0]), source)
|
14
|
+
end
|
@@ -0,0 +1,232 @@
|
|
1
|
+
require 'rpxem/stack'
|
2
|
+
require 'rpxem/version'
|
3
|
+
require 'scanf'
|
4
|
+
|
5
|
+
module RPxem
|
6
|
+
class Interpreter
|
7
|
+
attr_accessor :mapping
|
8
|
+
attr_reader :stack, :temp
|
9
|
+
|
10
|
+
def initialize(mapping={})
|
11
|
+
@mapping = default_mapping().merge(mapping)
|
12
|
+
end
|
13
|
+
|
14
|
+
# Open and execute a Pxem file
|
15
|
+
def open(file, stack=RPxem::Stack.new, temp=nil)
|
16
|
+
run(File.basename(file), File.open(file).read, stack, temp)
|
17
|
+
end
|
18
|
+
|
19
|
+
# Execute a Pxem code
|
20
|
+
def run(filename, source='', stack=RPxem::Stack.new, temp=nil)
|
21
|
+
@filename, @source, @stack, @temp = filename.each_byte.to_a, source, stack, temp
|
22
|
+
buffer, @cursor, length = RPxem::Stack.new, 0, @filename.length
|
23
|
+
|
24
|
+
while (@cursor < length)
|
25
|
+
char = @filename[@cursor]
|
26
|
+
@cursor += 1
|
27
|
+
if (@cursor < length && 46 == char && name = @mapping[@filename[@cursor].chr.downcase])
|
28
|
+
@stack.push(*buffer)
|
29
|
+
buffer = RPxem::Stack.new
|
30
|
+
__send__(name)
|
31
|
+
@cursor += 1
|
32
|
+
else
|
33
|
+
buffer.unshift(char)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
return @stack
|
38
|
+
end
|
39
|
+
|
40
|
+
def default_mapping
|
41
|
+
{
|
42
|
+
# I/O
|
43
|
+
'p' => 'output_all',
|
44
|
+
'o' => 'output',
|
45
|
+
'n' => 'output_num',
|
46
|
+
'i' => 'input',
|
47
|
+
'_' => 'input_num',
|
48
|
+
|
49
|
+
# Stack
|
50
|
+
'c' => 'copy',
|
51
|
+
's' => 'throw_away',
|
52
|
+
'v' => 'reverse',
|
53
|
+
|
54
|
+
# File contents
|
55
|
+
'f' => 'read_file',
|
56
|
+
'e' => 'emurate',
|
57
|
+
|
58
|
+
# Rand
|
59
|
+
'r' => 'rand',
|
60
|
+
|
61
|
+
# Loop
|
62
|
+
'w' => 'w',
|
63
|
+
'x' => 'x',
|
64
|
+
'y' => 'y',
|
65
|
+
'z' => 'z',
|
66
|
+
'a' => 'a',
|
67
|
+
|
68
|
+
# Temporary area
|
69
|
+
't' => 'to_temp',
|
70
|
+
'm' => 'from_temp',
|
71
|
+
|
72
|
+
# Do nothing
|
73
|
+
'd' => 'void',
|
74
|
+
|
75
|
+
# Math
|
76
|
+
'+' => 'addition',
|
77
|
+
'-' => 'subtraction',
|
78
|
+
'!' => 'multiplication',
|
79
|
+
'$' => 'quotient',
|
80
|
+
'%' => 'surplus',
|
81
|
+
}
|
82
|
+
end
|
83
|
+
|
84
|
+
private
|
85
|
+
|
86
|
+
# .p:
|
87
|
+
def output_all
|
88
|
+
while output; end
|
89
|
+
end
|
90
|
+
|
91
|
+
# .o:
|
92
|
+
def output
|
93
|
+
putc @stack.pop unless @stack.empty?
|
94
|
+
end
|
95
|
+
|
96
|
+
# .n:
|
97
|
+
def output_num
|
98
|
+
print @stack.pop
|
99
|
+
end
|
100
|
+
|
101
|
+
# .i:
|
102
|
+
def input
|
103
|
+
@stack.push(*STDIN.getc.ord)
|
104
|
+
end
|
105
|
+
|
106
|
+
# ._:
|
107
|
+
def input_num
|
108
|
+
@stack.push(*scanf('%d'))
|
109
|
+
end
|
110
|
+
|
111
|
+
# .c:
|
112
|
+
def copy
|
113
|
+
@stack.push(@stack.last)
|
114
|
+
end
|
115
|
+
|
116
|
+
# .s:
|
117
|
+
def throw_away
|
118
|
+
@stack.pop
|
119
|
+
end
|
120
|
+
|
121
|
+
# .v:
|
122
|
+
def reverse
|
123
|
+
@stack.reverse!
|
124
|
+
end
|
125
|
+
|
126
|
+
# .f:
|
127
|
+
def read_file
|
128
|
+
@stack.push(*@source.each_byte.to_a.reverse)
|
129
|
+
end
|
130
|
+
|
131
|
+
# .e:
|
132
|
+
def emurate
|
133
|
+
@stack.push(*clone.run(@source, @source, @stack.clone))
|
134
|
+
end
|
135
|
+
|
136
|
+
# .r:
|
137
|
+
def rand
|
138
|
+
@stack.push((super * @stack.pop).to_i)
|
139
|
+
end
|
140
|
+
|
141
|
+
# .w:
|
142
|
+
def w
|
143
|
+
jump if (!@stack.empty? && 0 == @stack.pop)
|
144
|
+
end
|
145
|
+
|
146
|
+
# .x:
|
147
|
+
def x
|
148
|
+
jump if (2 <= @stack.size && @stack.pop >= @stack.pop)
|
149
|
+
end
|
150
|
+
|
151
|
+
# .y:
|
152
|
+
def y
|
153
|
+
jump if (2 <= @stack.size && @stack.pop <= @stack.pop)
|
154
|
+
end
|
155
|
+
|
156
|
+
# .z:
|
157
|
+
def z
|
158
|
+
jump if (2 <= @stack.size && @stack.pop == @stack.pop)
|
159
|
+
end
|
160
|
+
|
161
|
+
# Jump forward to correspondent .a
|
162
|
+
def jump
|
163
|
+
count = 1
|
164
|
+
while (count.nonzero?)
|
165
|
+
@cursor += 1
|
166
|
+
if (46 == @filename[@cursor])
|
167
|
+
if (['w','x','y','z'].include? @filename[@cursor+1].chr.downcase)
|
168
|
+
count += 1
|
169
|
+
elsif ('a' == @filename[@cursor+1].chr.downcase)
|
170
|
+
count -= 1
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
@cursor += 1
|
175
|
+
end
|
176
|
+
|
177
|
+
# .a:
|
178
|
+
def a
|
179
|
+
@cursor -= 2
|
180
|
+
count = -1
|
181
|
+
while (count.nonzero?)
|
182
|
+
if (46 == @filename[@cursor])
|
183
|
+
if (['w','x','y','z'].include? @filename[@cursor+1].chr.downcase)
|
184
|
+
count += 1
|
185
|
+
elsif ('a' == @filename[@cursor+1].chr.downcase)
|
186
|
+
count -= 1
|
187
|
+
end
|
188
|
+
end
|
189
|
+
@cursor -= 1
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
# .t:
|
194
|
+
def to_temp
|
195
|
+
@temp = @stack.pop
|
196
|
+
end
|
197
|
+
|
198
|
+
# .m:
|
199
|
+
def from_temp
|
200
|
+
@stack.push(@temp) if @temp
|
201
|
+
end
|
202
|
+
|
203
|
+
# .d:
|
204
|
+
def void
|
205
|
+
end
|
206
|
+
|
207
|
+
# .+:
|
208
|
+
def addition
|
209
|
+
@stack.push(@stack.pop + @stack.pop) if 2 <= @stack.size
|
210
|
+
end
|
211
|
+
|
212
|
+
# .-:
|
213
|
+
def subtraction
|
214
|
+
@stack.push((@stack.pop - @stack.pop).abs) if 2 <= @stack.size
|
215
|
+
end
|
216
|
+
|
217
|
+
# .!:
|
218
|
+
def multiplication
|
219
|
+
@stack.push(@stack.pop * @stack.pop) if 2 <= @stack.size
|
220
|
+
end
|
221
|
+
|
222
|
+
# .$:
|
223
|
+
def quotient
|
224
|
+
@stack.push((f=@stack.pop)>(s=@stack.pop)? f/s : s/f) if 2 <= @stack.size
|
225
|
+
end
|
226
|
+
|
227
|
+
# .%:
|
228
|
+
def surplus
|
229
|
+
@stack.push((f=@stack.pop)>(s=@stack.pop)? f%s : s%f) if 2 <= @stack.size
|
230
|
+
end
|
231
|
+
end
|
232
|
+
end
|
data/lib/rpxem/stack.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
module RPxem
|
2
|
+
class Stack < Array
|
3
|
+
def initialize(*args, &block)
|
4
|
+
super(*args, &block)
|
5
|
+
simple_check(*self)
|
6
|
+
end
|
7
|
+
|
8
|
+
def push(*args, &block)
|
9
|
+
simple_check(*args)
|
10
|
+
super(*args, &block)
|
11
|
+
end
|
12
|
+
|
13
|
+
def unshift(*args, &block)
|
14
|
+
simple_check(*args)
|
15
|
+
super(*args, &block)
|
16
|
+
end
|
17
|
+
|
18
|
+
def <<(*args, &block)
|
19
|
+
simple_check(*args)
|
20
|
+
super(*args, &block)
|
21
|
+
end
|
22
|
+
|
23
|
+
def []=(*args, &block)
|
24
|
+
super(*args, &block)
|
25
|
+
simple_check(*self)
|
26
|
+
end
|
27
|
+
|
28
|
+
def insert(*args, &block)
|
29
|
+
super(*args, &block)
|
30
|
+
simple_check(*self)
|
31
|
+
end
|
32
|
+
|
33
|
+
def map!(*args, &block)
|
34
|
+
super(*args, &block)
|
35
|
+
simple_check(*self)
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
def simple_check(*args)
|
40
|
+
args.each do |arg|
|
41
|
+
raise ArgumentError.new 'Argument must be Fixnum' if (arg.class != Fixnum)
|
42
|
+
raise ArgumentError.new 'Argument must be positive' if (arg != arg.abs)
|
43
|
+
raise ArgumentError.new 'Argument must be integer' if (!arg.integer?)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/lib/rpxem.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'rpxem/interpreter'
|
2
|
+
require 'rpxem/version'
|
3
|
+
|
4
|
+
module RPxem
|
5
|
+
class << self
|
6
|
+
def new(options={})
|
7
|
+
RPxem::Interpreter.new(options)
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
def method_missing(name, *args, &block)
|
12
|
+
return super unless new.respond_to?(name)
|
13
|
+
new.__send__(name, *args, &block)
|
14
|
+
end
|
15
|
+
|
16
|
+
def respond_to?(name)
|
17
|
+
new.respond_to?(name) || super(name)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/rpxem.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/rpxem/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ['wktk']
|
6
|
+
gem.email = ['wktk@wktk.in']
|
7
|
+
gem.description = %q{RPxem is a Ruby implementation of Pxem, a esoteric programming language that enables you to create programs in 0-byte files.}
|
8
|
+
gem.summary = %q{Pxem implementation in Ruby}
|
9
|
+
gem.homepage = 'https://github.com/wktk/rpxem'
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = 'rpxem'
|
15
|
+
gem.require_paths = ['lib']
|
16
|
+
gem.version = RPxem::VERSION
|
17
|
+
|
18
|
+
gem.add_development_dependency 'rspec'
|
19
|
+
gem.add_development_dependency 'rake'
|
20
|
+
gem.add_development_dependency 'rdoc'
|
21
|
+
end
|
data/spec/rpxem_spec.rb
ADDED
@@ -0,0 +1,196 @@
|
|
1
|
+
require 'rpxem_helper'
|
2
|
+
|
3
|
+
describe RPxem do
|
4
|
+
describe 'delegation' do
|
5
|
+
it 'RPxem.new => RPxem::Interpreter.new' do
|
6
|
+
RPxem.new.class.should == RPxem::Interpreter.new.class
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'RPxem.run => #<RPxem::Interpreter>.run' do
|
10
|
+
RPxem.run('hoge.d').should == RPxem::Interpreter.new.run('hoge.d')
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe RPxem::Stack do
|
15
|
+
before do
|
16
|
+
@stack = RPxem::Stack.new
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should be Fixnum' do
|
20
|
+
expect{ @stack.push('a') }.to raise_error ArgumentError
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should be positive' do
|
24
|
+
expect{ @stack.push(-1) }.to raise_error ArgumentError
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'can be zero' do
|
28
|
+
expect{ @stack.push(0) }.not_to raise_error
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should be integer' do
|
32
|
+
expect{ @stack.unshift(0.1) }.to raise_error ArgumentError
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'can check in #new' do
|
36
|
+
expect{ RPxem::Stack.new([1, 2, 'san']) }.to raise_error ArgumentError
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe RPxem::Interpreter do
|
41
|
+
before do
|
42
|
+
@pxem = RPxem.new
|
43
|
+
end
|
44
|
+
|
45
|
+
describe 'initializing' do
|
46
|
+
it 'can set initial stack' do
|
47
|
+
capture{ @pxem.run('.p', '', RPxem::Stack.new([99, 98, 97])) }.should == 'abc'
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'can open file' do
|
51
|
+
testfile = File.join(File.dirname(__FILE__), 'world!.fHello,.pxe')
|
52
|
+
capture{ @pxem.open(testfile) }.should == 'Hello, Pxem world!'
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'can merge command mapping' do
|
56
|
+
pxem = RPxem.new({'q' => 'output_all', 'c' => 'output_all'})
|
57
|
+
capture{ pxem.run('Hi.q') }.should == 'Hi'
|
58
|
+
capture{ pxem.run('Hi.c') }.should == 'Hi'
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe 'get result' do
|
63
|
+
it 'should return remaining stack' do
|
64
|
+
@pxem.run('Hi.d').should == [105, 72]
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'can read stack' do
|
68
|
+
@pxem.run('a.d')
|
69
|
+
@pxem.stack.should == [97]
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'can read temp area' do
|
73
|
+
@pxem.run('a.t')
|
74
|
+
@pxem.temp.should == 97
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe 'Pxem commands' do
|
79
|
+
describe 'I/O' do
|
80
|
+
it '.p' do
|
81
|
+
capture{ @pxem.run('Hello, world!.p') }.should == 'Hello, world!'
|
82
|
+
end
|
83
|
+
|
84
|
+
it '.o' do
|
85
|
+
capture{ @pxem.run('Hi.o') }.should == 'H'
|
86
|
+
end
|
87
|
+
|
88
|
+
it '.n' do
|
89
|
+
capture{ @pxem.run('Hi.n') }.should == '72'
|
90
|
+
end
|
91
|
+
|
92
|
+
#it '.i' do
|
93
|
+
#end
|
94
|
+
|
95
|
+
#it '._' do
|
96
|
+
#end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe 'Stack' do
|
100
|
+
it '.c' do
|
101
|
+
@pxem.run('Hi.c').should == [105, 72, 72]
|
102
|
+
end
|
103
|
+
|
104
|
+
it '.s' do
|
105
|
+
@pxem.run('Hi.s').should == [105]
|
106
|
+
end
|
107
|
+
|
108
|
+
it '.v' do
|
109
|
+
@pxem.run('Hi.v').should == [72, 105]
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
describe 'File' do
|
114
|
+
it '.f' do
|
115
|
+
@pxem.run('.f', 'File').should == [101, 108, 105, 70]
|
116
|
+
end
|
117
|
+
|
118
|
+
it '.e' do
|
119
|
+
@pxem.run('.e', 'File.d').should == [101, 108, 105, 70]
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
describe 'Rand' do
|
124
|
+
it '.r' do
|
125
|
+
@pxem.run('d.r').first.should be_within(100).of(0)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
describe 'Loop' do
|
130
|
+
it '.w' do
|
131
|
+
capture{ @pxem.run('a.whoge.paa.-.a') }.should == 'hoge'
|
132
|
+
end
|
133
|
+
|
134
|
+
it '.x' do
|
135
|
+
capture{ @pxem.run('e.xhog.pba.a') }.should == 'hoge'
|
136
|
+
end
|
137
|
+
|
138
|
+
it '.y' do
|
139
|
+
capture{ @pxem.run('e.yhog.pab.a') }.should == 'hoge'
|
140
|
+
end
|
141
|
+
|
142
|
+
it '.z' do
|
143
|
+
capture{ @pxem.run('e.zhog.paa.a') }.should == 'hoge'
|
144
|
+
end
|
145
|
+
|
146
|
+
it '.a' do
|
147
|
+
capture{ @pxem.run('e.zhog.pe.zhog.paa.aaa.a') } == 'hogehoge'
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
describe 'Temporary area' do
|
152
|
+
it '.t' do
|
153
|
+
@pxem.run('a.t')
|
154
|
+
@pxem.temp.should == 97
|
155
|
+
end
|
156
|
+
|
157
|
+
it '.m' do
|
158
|
+
@pxem.run('a.t.m.m').should == [97, 97]
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
describe '.d' do
|
163
|
+
it '.d' do
|
164
|
+
@pxem.run('Hi.d').should == [105, 72]
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
describe 'Math' do
|
169
|
+
it '.+' do
|
170
|
+
@pxem.run('ab.+').should == [98 + 97]
|
171
|
+
@pxem.run('ba.+').should == [98 + 97]
|
172
|
+
end
|
173
|
+
|
174
|
+
it '.-' do
|
175
|
+
@pxem.run('ab.-').should == [98 - 97]
|
176
|
+
@pxem.run('ba.-').should == [98 - 97]
|
177
|
+
end
|
178
|
+
|
179
|
+
it '.!' do
|
180
|
+
@pxem.run('ab.!').should == [98 * 97]
|
181
|
+
@pxem.run('ba.!').should == [98 * 97]
|
182
|
+
end
|
183
|
+
|
184
|
+
it '.$' do
|
185
|
+
@pxem.run('ab.$').should == [98 / 97]
|
186
|
+
@pxem.run('ba.$').should == [98 / 97]
|
187
|
+
end
|
188
|
+
|
189
|
+
it '.%' do
|
190
|
+
@pxem.run('ab.%').should == [98 % 97]
|
191
|
+
@pxem.run('ba.%').should == [98 % 97]
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
Pxem
|
metadata
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rpxem
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- wktk
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-12-03 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rdoc
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: RPxem is a Ruby implementation of Pxem, a esoteric programming language
|
63
|
+
that enables you to create programs in 0-byte files.
|
64
|
+
email:
|
65
|
+
- wktk@wktk.in
|
66
|
+
executables:
|
67
|
+
- rpxem
|
68
|
+
extensions: []
|
69
|
+
extra_rdoc_files: []
|
70
|
+
files:
|
71
|
+
- .gitignore
|
72
|
+
- Gemfile
|
73
|
+
- MIT-LICENSE.txt
|
74
|
+
- README.md
|
75
|
+
- Rakefile
|
76
|
+
- bin/rpxem
|
77
|
+
- lib/rpxem.rb
|
78
|
+
- lib/rpxem/interpreter.rb
|
79
|
+
- lib/rpxem/stack.rb
|
80
|
+
- lib/rpxem/version.rb
|
81
|
+
- rpxem.gemspec
|
82
|
+
- spec/rpxem_helper.rb
|
83
|
+
- spec/rpxem_spec.rb
|
84
|
+
- spec/world!.fHello,.pxe
|
85
|
+
homepage: https://github.com/wktk/rpxem
|
86
|
+
licenses: []
|
87
|
+
post_install_message:
|
88
|
+
rdoc_options: []
|
89
|
+
require_paths:
|
90
|
+
- lib
|
91
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
92
|
+
none: false
|
93
|
+
requirements:
|
94
|
+
- - ! '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
99
|
+
requirements:
|
100
|
+
- - ! '>='
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
requirements: []
|
104
|
+
rubyforge_project:
|
105
|
+
rubygems_version: 1.8.23
|
106
|
+
signing_key:
|
107
|
+
specification_version: 3
|
108
|
+
summary: Pxem implementation in Ruby
|
109
|
+
test_files:
|
110
|
+
- spec/rpxem_helper.rb
|
111
|
+
- spec/rpxem_spec.rb
|
112
|
+
- spec/world!.fHello,.pxe
|