rien 0.0.1 → 0.0.2

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
  SHA256:
3
- metadata.gz: d2eee9c5dd1bca6d442257c46bcd9c105c580609ce7235d9871a8885dc308199
4
- data.tar.gz: 283fe64abdeb6932f6baf30d84e79ea7a1a6b41054f9acd4df9d44399363898b
3
+ metadata.gz: 98c91f699f5e7d0919d39495d34bd70f89251f88c049442c3b3ffa75268d0b71
4
+ data.tar.gz: 5172a96c5292175a2165b9f9f7e49646e3adee03eae1b5fe865e9cd9d72eef07
5
5
  SHA512:
6
- metadata.gz: e3b64e266d8dd41c29407f4cacc601bcf4ae9935df546d6b6fd988cff1c659e7c7bef2f61e6a8f91a1b2e0f6873b406357cb719ee4f5313ce26bc19053e61f50
7
- data.tar.gz: 79ffb9c8d90418f54b4c423d2abe2dfabe11d34c2b09dd6d0a7fda776eba45c88a5879824845666ea184dac27e7f11a18ca57b7c8e31246f903714a82276b4b7
6
+ metadata.gz: a9cdd05af22e562479fde38e856514072825422671f21c65444bf8652cb66d70ebba43401ab9d5f72826201d5f269f1f51c9eec75e9a8b2ced3dd2032ca9d91f
7
+ data.tar.gz: 6ba6743a3dba672fcbee2feb4065819b7442207f3c8be93436146a8d66689d406ea7b3d0983c5437760b2e03c2bbf525263e605dd0faf1588c628838e91d0a06
data/bin/rien CHANGED
@@ -1,3 +1,43 @@
1
- # !/bin/ruby
1
+ #!/bin/ruby
2
2
 
3
- puts 'Hello World'
3
+ require 'optparse'
4
+ require 'rien'
5
+
6
+ options = {
7
+ mode: :help
8
+ }
9
+
10
+ parser = OptionParser.new do |opts|
11
+ opts.banner = 'Usage: rien [options]'
12
+ opts.on('-e', '--encode [FILE]', 'Encode specific ruby file', String) do |v|
13
+ options[:mode] = :encode
14
+ options[:file] = v
15
+ end
16
+
17
+ # opts.on('-p', '--pack [FILE]', 'Pack ruby file and all relative requirements into a single executable', String) do |v|
18
+ # options[:mode] = :pack
19
+ # options[:file] = v
20
+ # end
21
+ end
22
+
23
+ parser.parse!
24
+
25
+ case options[:mode]
26
+ when :encode
27
+ encoder = Rien::Encoder.new
28
+ bytes = encoder.encode_file(options[:file])
29
+ generated_name = "#{options[:file]}.encoded.rb"
30
+ bootstrap = encoder.bootstrap(generated_name)
31
+
32
+ File.open(generated_name, 'w') do |f|
33
+ f.write bootstrap
34
+ end
35
+
36
+ File.open("#{generated_name}.rien", 'wb') do |f|
37
+ f.write bytes
38
+ end
39
+ when :help
40
+ puts parser
41
+ else
42
+ puts parser
43
+ end
data/lib/rien/const.rb ADDED
@@ -0,0 +1,12 @@
1
+ module Rien::Const
2
+ COMPILE_OPTION = {
3
+ inline_const_cache: true,
4
+ instructions_unification: true,
5
+ operands_unification: true,
6
+ peephole_optimization: true,
7
+ specialized_instruction: true,
8
+ stack_caching: true,
9
+ tailcall_optimization: true,
10
+ trace_instruction: false,
11
+ }.freeze
12
+ end
@@ -0,0 +1,12 @@
1
+ class Rien::Decoder
2
+ def self.check_version(version)
3
+ version == RUBY_VERSION
4
+ end
5
+
6
+ def self.eval(filename)
7
+ file = File.read(filename)
8
+ ir_bin = Zlib::Inflate.inflate(file)
9
+ ir = RubyVM::InstructionSequence.load_from_binary(ir_bin)
10
+ ir.eval
11
+ end
12
+ end
@@ -0,0 +1,24 @@
1
+ class Rien::Encoder
2
+ def initialize(version=RUBY_VERSION)
3
+ @version = version
4
+ end
5
+
6
+ def encode(str)
7
+ bytecode = RubyVM::InstructionSequence.compile(str, options: Rien::Const::COMPILE_OPTION)
8
+ Zlib::Deflate.deflate(bytecode.to_binary)
9
+ end
10
+
11
+ def bootstrap(path)
12
+ <<-EOL
13
+ require 'rien'
14
+
15
+ Rien::Decoder.check_version('#{RUBY_VERSION}')
16
+ Rien::Decoder.eval('#{path}.rien')
17
+ EOL
18
+ end
19
+
20
+ def encode_file(filepath)
21
+ src = File.read(filepath)
22
+ self.encode(src)
23
+ end
24
+ end
data/lib/rien/pipe.rb ADDED
File without changes
@@ -0,0 +1,3 @@
1
+ module Rien
2
+ VERSION = '0.0.2'
3
+ end
data/lib/rien.rb ADDED
@@ -0,0 +1,8 @@
1
+ require 'zlib'
2
+
3
+ require_relative 'rien/version'
4
+ require_relative 'rien/const'
5
+
6
+ require_relative 'rien/decoder'
7
+ require_relative 'rien/encoder'
8
+ require_relative 'rien/pipe'
data/rien.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ require './lib/rien'
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'rien'
5
+ s.version = Rien::VERSION
6
+ s.required_ruby_version = '>=2.4.5'
7
+ s.date = Time.now.strftime('%Y-%m-%d')
8
+ s.summary = 'Ruby IR Encoding'
9
+ s.description = 'Encode your Ruby code for distribution'
10
+ s.authors = ['CodeRemixer']
11
+ s.email = ['dsh0416@gmail.com']
12
+ s.require_paths = ['lib']
13
+ s.bindir = ['bin']
14
+ s.executables = ['rien']
15
+ s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec|.resources)/}) } \
16
+ - %w(README.md CODE_OF_CONDUCT.md CONTRIBUTING.md Gemfile Rakefile my_general.gemspec .gitignore .rspec .codeclimate.yml .rubocop.yml .travis.yml logo.png Rakefile Gemfile)
17
+ s.homepage = 'https://github.com/coderemixer/rien'
18
+ s.metadata = { 'issue_tracker' => 'https://github.com/coderemixer/rien/issues' }
19
+ s.license = 'Apache-2.0'
20
+ s.add_runtime_dependency 'ruby-progressbar', '~> 1.9'
21
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rien
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - CodeRemixer
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir:
10
10
  - bin
11
11
  cert_chain: []
12
- date: 2018-12-15 00:00:00.000000000 Z
12
+ date: 2018-12-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ruby-progressbar
@@ -35,9 +35,16 @@ extra_rdoc_files: []
35
35
  files:
36
36
  - LICENSE
37
37
  - bin/rien
38
+ - lib/rien.rb
39
+ - lib/rien/const.rb
40
+ - lib/rien/decoder.rb
41
+ - lib/rien/encoder.rb
42
+ - lib/rien/pipe.rb
43
+ - lib/rien/version.rb
44
+ - rien.gemspec
38
45
  homepage: https://github.com/coderemixer/rien
39
46
  licenses:
40
- - Apache 2.0
47
+ - Apache-2.0
41
48
  metadata:
42
49
  issue_tracker: https://github.com/coderemixer/rien/issues
43
50
  post_install_message:
@@ -48,7 +55,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
48
55
  requirements:
49
56
  - - ">="
50
57
  - !ruby/object:Gem::Version
51
- version: 2.2.6
58
+ version: 2.4.5
52
59
  required_rubygems_version: !ruby/object:Gem::Requirement
53
60
  requirements:
54
61
  - - ">="