vernacular 0.0.2 → 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9508b52673e0c49694898de05274d5fd1a9b0ca9
4
- data.tar.gz: 166c7ab5082b86422fcfce27522b6cfe4e08b2e9
3
+ metadata.gz: be3b65d96dd405422c5d5723be0aea18e1aca5c8
4
+ data.tar.gz: 3f70cac82ad0ce35054d2b3289b4dc612b0da9a7
5
5
  SHA512:
6
- metadata.gz: ec927a7f7f7afa393b0a196b5f5aa10771fbb18a9384b290bdc3d49e2730c2feb5d638fa2aea769f564b92117def186faf69c6a2e856ffc0f2cf108b32593c30
7
- data.tar.gz: abe8027ee48689dc06e0d20b509ea32cd0759009c062b269909c5b8e79c6909985c7593a374d336753a57ba2d3b2f4b91048dbfcdc08799be446107f6c583cfd
6
+ metadata.gz: a640f138ed4496de8f88f13a2c9e7820c6a92ce2ebbc7e5a1e153a17fbe302c841e934bd6cc2969b3c3a9a577b74aa5e3cfd1881fbe1a94c951f40a3e8f37132
7
+ data.tar.gz: 7f66305aabfacb753d8b79fc20d9a07647546063964aa330c02fa2653b56c008214f284588c70d58ba7d93b65b07409c94a7e358600b67de97025538d7cb0a02
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # Vernacular
2
2
 
3
3
  [![Build Status](https://travis-ci.org/kddeisz/vernacular.svg?branch=master)](https://travis-ci.org/kddeisz/vernacular)
4
+ [![Gem Version](https://img.shields.io/gem/v/vernacular.svg)](https://rubygems.org/gems/vernacular)
4
5
 
5
6
  Allows extending ruby's syntax and compilation process.
6
7
 
@@ -16,16 +16,32 @@ end
16
16
 
17
17
  # Allows extending ruby's syntax and compilation process
18
18
  module Vernacular
19
+ PARSER_PATH = File.expand_path('vernacular/parser.rb', __dir__).freeze
20
+
19
21
  # Module that gets included into `RubyVM::InstructionSequence` in order to
20
22
  # hook into the require process.
21
23
  module InstructionSequenceMixin
22
- PARSER_PATH = File.expand_path('vernacular/parser.rb', __dir__).freeze
23
-
24
24
  def load_iseq(filepath)
25
25
  ::Vernacular::SourceFile.load_iseq(filepath) if filepath != PARSER_PATH
26
26
  end
27
27
  end
28
28
 
29
+ # Module that gets included into `Bootsnap::CompileCache::ISeq` in order to
30
+ # hook into the bootsnap compilation process.
31
+ module BootsnapMixin
32
+ def input_to_storage(contents, filepath)
33
+ if filepath == PARSER_PATH
34
+ raise ::Bootsnap::CompileCache::Uncompilable, "can't compile parser"
35
+ end
36
+
37
+ contents = ::Vernacular.modify(contents)
38
+ iseq = RubyVM::InstructionSequence.compile(contents, filepath, filepath)
39
+ iseq.to_binary
40
+ rescue SyntaxError
41
+ raise ::Bootsnap::CompileCache::Uncompilable, 'syntax error'
42
+ end
43
+ end
44
+
29
45
  class << self
30
46
  attr_reader :iseq_dir, :modifiers
31
47
 
@@ -45,9 +61,7 @@ module Vernacular
45
61
  @iseq_dir = File.expand_path(File.join('../.iseq', hash), __dir__)
46
62
  FileUtils.mkdir_p(iseq_dir) unless File.directory?(iseq_dir)
47
63
 
48
- class << RubyVM::InstructionSequence
49
- prepend ::Vernacular::InstructionSequenceMixin
50
- end
64
+ install
51
65
  end
52
66
 
53
67
  # Use every available pre-configured modifier
@@ -56,9 +70,31 @@ module Vernacular
56
70
  Modifiers.constants.map { |constant| Modifiers.const_get(constant).new }
57
71
  end
58
72
 
73
+ def modify(source)
74
+ modifiers.each do |modifier|
75
+ source = modifier.modify(source)
76
+ end
77
+ source
78
+ end
79
+
59
80
  def iseq_path_for(source_path)
60
81
  source_path.gsub(/[^A-Za-z0-9\._-]/) { |c| '%02x' % c.ord }
61
82
  .gsub('.rb', '.yarb')
62
83
  end
84
+
85
+ private
86
+
87
+ def install
88
+ @installed ||=
89
+ if defined?(Bootsnap)
90
+ class << Bootsnap::CompileCache::ISeq
91
+ prepend ::Vernacular::BootsnapMixin
92
+ end
93
+ else
94
+ class << RubyVM::InstructionSequence
95
+ prepend ::Vernacular::InstructionSequenceMixin
96
+ end
97
+ end
98
+ end
63
99
  end
64
100
  end
@@ -10,12 +10,9 @@ module Vernacular
10
10
  end
11
11
 
12
12
  def dump
13
- source = File.read(source_path)
14
- Vernacular.modifiers.each do |modifier|
15
- source = modifier.modify(source)
16
- end
17
-
18
- iseq = RubyVM::InstructionSequence.compile(source)
13
+ source = Vernacular.modify(File.read(source_path))
14
+ iseq = RubyVM::InstructionSequence.compile(source, source_path,
15
+ source_path)
19
16
  digest = ::Digest::MD5.file(source_path).digest
20
17
  File.binwrite(iseq_path, iseq.to_binary("MD5:#{digest}"))
21
18
  iseq
@@ -1,3 +1,3 @@
1
1
  module Vernacular
2
- VERSION = '0.0.2'.freeze
2
+ VERSION = '0.1.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vernacular
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Deisz
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-09-10 00:00:00.000000000 Z
11
+ date: 2017-09-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser