bel 0.3.2-x64-mingw32 → 0.3.3-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +39 -0
  3. data/README.md +1 -1
  4. data/bel.gemspec +4 -4
  5. data/ext/mri/extconf.rb +20 -6
  6. data/lib/bel.rb +4 -3
  7. data/lib/bel/libbel.rb +141 -177
  8. data/lib/bel/libbel/bel_ast_structs.rb +150 -148
  9. data/lib/bel/libbel/bel_token.rb +29 -27
  10. data/lib/bel/libbel/bel_token_list.rb +28 -26
  11. data/lib/bel/{2.0 → libbel/ext/2.0}/libbel.so +0 -0
  12. data/lib/bel/{2.1 → libbel/ext/2.1}/libbel.so +0 -0
  13. data/lib/bel/{2.2 → libbel/ext/2.2}/libbel.so +0 -0
  14. data/lib/bel/libbel/ext/java/darwin/x86_64/libbel.bundle +0 -0
  15. data/lib/bel/libbel/ext/java/linux/x86_64/libbel.so +0 -0
  16. data/lib/bel/libbel/ext/java/mswin/i686/2.0/libbel.so +0 -0
  17. data/lib/bel/libbel/ext/java/mswin/i686/2.1/libbel.so +0 -0
  18. data/lib/bel/libbel/ext/java/mswin/i686/2.2/libbel.so +0 -0
  19. data/lib/bel/libbel/ext/java/mswin/x86_64/2.0/libbel.so +0 -0
  20. data/lib/bel/libbel/ext/java/mswin/x86_64/2.1/libbel.so +0 -0
  21. data/lib/bel/libbel/ext/java/mswin/x86_64/2.2/libbel.so +0 -0
  22. data/lib/bel/libbel/ext/mingw/i686/2.0/libbel.so +0 -0
  23. data/lib/bel/libbel/ext/mingw/i686/2.1/libbel.so +0 -0
  24. data/lib/bel/libbel/ext/mingw/i686/2.2/libbel.so +0 -0
  25. data/lib/bel/libbel/ext/mingw/x86_64/2.0/libbel.so +0 -0
  26. data/lib/bel/libbel/ext/mingw/x86_64/2.1/libbel.so +0 -0
  27. data/lib/bel/libbel/ext/mingw/x86_64/2.2/libbel.so +0 -0
  28. data/lib/bel/libbel/library_load_error.rb +30 -0
  29. data/lib/bel/libbel/library_resolver.rb +103 -0
  30. data/lib/bel/libbel/node_test.rb +29 -27
  31. data/lib/bel/libbel/node_transformation.rb +24 -22
  32. data/lib/bel/libbel/node_traversal.rb +79 -77
  33. data/lib/bel/libbel/platform_support_error.rb +23 -0
  34. data/lib/bel/version.rb +1 -1
  35. metadata +23 -33
@@ -0,0 +1,30 @@
1
+ module BEL
2
+ module LibBEL
3
+
4
+ class LibraryLoadError < StandardError
5
+
6
+ ERROR_MSG = %Q{
7
+ The C extension library could not be loaded for your platform.
8
+
9
+ Host information:
10
+
11
+ RUBY_PLATFORM: #{RUBY_PLATFORM},
12
+ RbConfig::CONFIG['host_os']: #{RbConfig::CONFIG['host_os']},
13
+ RbConfig::CONFIG['host_cpu']: #{RbConfig::CONFIG['host_cpu']},
14
+ library: %s
15
+
16
+ Original error:
17
+
18
+ Name: %s,
19
+ Message: %s
20
+ }.gsub(/^\s+/, '')
21
+
22
+ attr_reader :cause
23
+
24
+ def initialize(library_name, cause=$!)
25
+ super(ERROR_MSG % [library_name, cause.class, cause.message])
26
+ @cause = cause;
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,103 @@
1
+ require_relative 'platform_support_error'
2
+
3
+ module BEL
4
+ module LibBEL
5
+
6
+ module LibraryResolver
7
+
8
+ EXT_BASE_PATH = File.join(File.expand_path('..', __FILE__), 'ext')
9
+
10
+ def resolve_library(lib_name)
11
+ case library_type(lib_name)
12
+ when :compiled
13
+ compiled_library(lib_name)
14
+ when :windows
15
+ windows_library(lib_name)
16
+ when :java
17
+ java_library(lib_name)
18
+ when :unknown
19
+ raise BEL::LibBEL::PlatformSupportError.new
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ def library_type(lib_name)
26
+ exist = File.method(:exist?)
27
+ if compiled_library_paths(lib_name).any?(&exist)
28
+ :compiled
29
+ else
30
+ case RUBY_PLATFORM
31
+ when /mingw/i
32
+ :windows
33
+ when /java/i
34
+ :java
35
+ else
36
+ :unsupported
37
+ end
38
+ end
39
+ end
40
+
41
+ def compiled_library(lib_name)
42
+ exist = File.method(:exist?)
43
+ compiled_library_paths(lib_name).select(&exist).first
44
+ end
45
+
46
+ def compiled_library_paths(lib_name)
47
+ base_path = "#{EXT_BASE_PATH}"
48
+ extensions = ['so', 'bundle', 'dylib']
49
+
50
+ extensions.map { |ext|
51
+ "%s/%s.%s" % [base_path, lib_name, ext]
52
+ }
53
+ end
54
+
55
+ def windows_library(lib_name)
56
+ unless RUBY_VERSION =~ /^2/
57
+ raise BEL::LibBEL::PlatformSupportError.new
58
+ end
59
+
60
+ base_path = "#{EXT_BASE_PATH}/mingw"
61
+ host_cpu = RbConfig::CONFIG['host_cpu']
62
+ File.join(base_path, host_cpu, ruby_version, 'libbel.so')
63
+ end
64
+
65
+ def java_library(lib_name)
66
+ # extra check to make sure jruby supports Ruby 2 (e.g. JRuby 9.0.0.0)
67
+ unless RUBY_VERSION =~ /^2/
68
+ raise BEL::LibBEL::PlatformSupportError.new
69
+ end
70
+
71
+ base_path = "#{EXT_BASE_PATH}/java"
72
+ host_os = RbConfig::CONFIG['host_os']
73
+ host_cpu = RbConfig::CONFIG['host_cpu']
74
+
75
+ case host_os
76
+ when /darwin/i
77
+ File.join(base_path, 'darwin', host_cpu, 'libbel.bundle')
78
+ when /mswin/i
79
+ File.join(base_path, 'mswin', host_cpu, ruby_version, 'libbel.so')
80
+ when /linux/i
81
+ File.join(base_path, 'linux', host_cpu, 'libbel.so')
82
+ else
83
+ raise BEL::LibBEL::PlatformSupportError.new
84
+ end
85
+ end
86
+
87
+ def host_cpu
88
+ RbConfig::CONFIG['host_cpu']
89
+ end
90
+
91
+ def host_os
92
+ RbConfig::CONFIG['host_os']
93
+ end
94
+
95
+ def ruby_version
96
+ major = RbConfig::CONFIG['MAJOR']
97
+ minor = RbConfig::CONFIG['MINOR']
98
+
99
+ "%s.%s" % [major, minor]
100
+ end
101
+ end
102
+ end
103
+ end
@@ -1,44 +1,46 @@
1
- module LibBEL
2
- module NodeTest
1
+ module BEL
2
+ module LibBEL
3
+ module NodeTest
3
4
 
4
- def any?(predicates)
5
- predicates.each do |predicate|
6
- if predicate.call(self)
7
- return true
5
+ def any?(predicates)
6
+ predicates.each do |predicate|
7
+ if predicate.call(self)
8
+ return true
9
+ end
8
10
  end
11
+ return false
9
12
  end
10
- return false
11
- end
12
13
 
13
- def any_in_tree?(predicates)
14
- predicates.each do |predicate|
15
- self.traversal_method(self, :depth_first).call do |ast_node|
16
- if predicate.call(ast_node)
17
- return true
14
+ def any_in_tree?(predicates)
15
+ predicates.each do |predicate|
16
+ self.traversal_method(self, :depth_first).call do |ast_node|
17
+ if predicate.call(ast_node)
18
+ return true
19
+ end
18
20
  end
19
21
  end
22
+ return false
20
23
  end
21
- return false
22
- end
23
24
 
24
- def all?(predicates)
25
- predicates.each do |predicate|
26
- if !predicate.call(self)
27
- return false
25
+ def all?(predicates)
26
+ predicates.each do |predicate|
27
+ if !predicate.call(self)
28
+ return false
29
+ end
28
30
  end
31
+ return true
29
32
  end
30
- return true
31
- end
32
33
 
33
- def all_in_tree?(predicates)
34
- predicates.each do |predicate|
35
- self.traversal_method(self, :depth_first).call do |ast_node|
36
- if !predicate.call(ast_node)
37
- return false
34
+ def all_in_tree?(predicates)
35
+ predicates.each do |predicate|
36
+ self.traversal_method(self, :depth_first).call do |ast_node|
37
+ if !predicate.call(ast_node)
38
+ return false
39
+ end
38
40
  end
39
41
  end
42
+ return true
40
43
  end
41
- return true
42
44
  end
43
45
  end
44
46
  end
@@ -1,31 +1,33 @@
1
- module LibBEL
2
- module NodeTransformation
1
+ module BEL
2
+ module LibBEL
3
+ module NodeTransformation
3
4
 
4
- def transform(transforms, options = {})
5
- if options[:mutate] == true
6
- ast_node = self
7
- else
8
- ast_node = LibBEL::copy_ast_node(self)
9
- end
5
+ def transform(transforms, options = {})
6
+ if options[:mutate] == true
7
+ ast_node = self
8
+ else
9
+ ast_node = LibBEL::copy_ast_node(self)
10
+ end
10
11
 
11
- transforms.each do |transform|
12
- transform.call(ast_node)
12
+ transforms.each do |transform|
13
+ transform.call(ast_node)
14
+ end
15
+ ast_node
13
16
  end
14
- ast_node
15
- end
16
17
 
17
- def transform_tree(transforms, traversal = :depth_first, options = {})
18
- if options[:mutate] == true
19
- ast_node = self
20
- else
21
- ast_node = LibBEL::copy_ast_node(self)
22
- end
18
+ def transform_tree(transforms, traversal = :depth_first, options = {})
19
+ if options[:mutate] == true
20
+ ast_node = self
21
+ else
22
+ ast_node = LibBEL::copy_ast_node(self)
23
+ end
23
24
 
24
- transforms.each do |transform|
25
- self.traversal_method(ast_node, traversal).call(transform)
26
- end
25
+ transforms.each do |transform|
26
+ self.traversal_method(ast_node, traversal).call(transform)
27
+ end
27
28
 
28
- ast_node
29
+ ast_node
30
+ end
29
31
  end
30
32
  end
31
33
  end
@@ -1,97 +1,99 @@
1
- module LibBEL
2
- module NodeTraversal
3
- include Enumerable
1
+ module BEL
2
+ module LibBEL
3
+ module NodeTraversal
4
+ include Enumerable
4
5
 
5
- def each(traversal = :depth_first, callable = nil, &block)
6
- func = if block_given?
7
- block
8
- else
9
- callable
10
- end
11
- if !func
12
- if traversal == :depth_first
13
- enum_for(:each_depth_first)
14
- elsif traversal == :breadth_first
15
- enum_for(:each_breadth_first)
16
- end
17
- else
18
- if traversal == :depth_first
19
- each_depth_first(callable, &block)
20
- elsif traversal == :breadth_first
21
- each_breadth_first(callable, &block)
6
+ def each(traversal = :depth_first, callable = nil, &block)
7
+ func = if block_given?
8
+ block
9
+ else
10
+ callable
11
+ end
12
+ if !func
13
+ if traversal == :depth_first
14
+ enum_for(:each_depth_first)
15
+ elsif traversal == :breadth_first
16
+ enum_for(:each_breadth_first)
17
+ end
18
+ else
19
+ if traversal == :depth_first
20
+ each_depth_first(callable, &block)
21
+ elsif traversal == :breadth_first
22
+ each_breadth_first(callable, &block)
23
+ end
22
24
  end
23
25
  end
24
- end
25
26
 
26
- def each_depth_first(callable = nil, &block)
27
- func = if block_given?
28
- block
29
- else
30
- callable
31
- end
32
- if !func
33
- enum_for(:each_depth_first)
34
- else
35
- typed_node = self.to_typed_node
36
- func.call(typed_node)
27
+ def each_depth_first(callable = nil, &block)
28
+ func = if block_given?
29
+ block
30
+ else
31
+ callable
32
+ end
33
+ if !func
34
+ enum_for(:each_depth_first)
35
+ else
36
+ typed_node = self.to_typed_node
37
+ func.call(typed_node)
37
38
 
38
- if typed_node.is_a? (LibBEL::BelAstNodeToken)
39
- if !typed_node.left.pointer.null?
40
- typed_node.left.each_depth_first(func)
41
- end
42
- if func.respond_to?(:between)
43
- func.between(typed_node)
44
- end
45
- if !typed_node.right.pointer.null?
46
- typed_node.right.each_depth_first(func)
39
+ if typed_node.is_a? (LibBEL::BelAstNodeToken)
40
+ if !typed_node.left.pointer.null?
41
+ typed_node.left.each_depth_first(func)
42
+ end
43
+ if func.respond_to?(:between)
44
+ func.between(typed_node)
45
+ end
46
+ if !typed_node.right.pointer.null?
47
+ typed_node.right.each_depth_first(func)
48
+ end
47
49
  end
48
- end
49
50
 
50
- if func.respond_to?(:after)
51
- func.after(typed_node)
51
+ if func.respond_to?(:after)
52
+ func.after(typed_node)
53
+ end
52
54
  end
53
55
  end
54
- end
55
56
 
56
- def each_breadth_first(callable = nil, queue = [], &block)
57
- func = if block_given?
58
- block
59
- else
60
- callable
61
- end
62
- if !func
63
- enum_for(:each_breadth_first)
64
- else
65
- typed_node = (queue.shift || self).to_typed_node
66
- func.call(typed_node)
57
+ def each_breadth_first(callable = nil, queue = [], &block)
58
+ func = if block_given?
59
+ block
60
+ else
61
+ callable
62
+ end
63
+ if !func
64
+ enum_for(:each_breadth_first)
65
+ else
66
+ typed_node = (queue.shift || self).to_typed_node
67
+ func.call(typed_node)
67
68
 
68
- if typed_node.is_a? (LibBEL::BelAstNodeToken)
69
- if !typed_node.left.pointer.null?
70
- queue << typed_node.left
71
- end
72
- if func.respond_to?(:between)
73
- func.between(typed_node)
69
+ if typed_node.is_a? (LibBEL::BelAstNodeToken)
70
+ if !typed_node.left.pointer.null?
71
+ queue << typed_node.left
72
+ end
73
+ if func.respond_to?(:between)
74
+ func.between(typed_node)
75
+ end
76
+ if !typed_node.right.pointer.null?
77
+ queue << typed_node.right
78
+ end
74
79
  end
75
- if !typed_node.right.pointer.null?
76
- queue << typed_node.right
77
- end
78
- end
79
80
 
80
- if func.respond_to?(:after)
81
- func.after(typed_node)
82
- end
81
+ if func.respond_to?(:after)
82
+ func.after(typed_node)
83
+ end
83
84
 
84
- if !queue.empty?
85
- queue.first.each_breadth_first(queue, &block)
85
+ if !queue.empty?
86
+ queue.first.each_breadth_first(queue, &block)
87
+ end
86
88
  end
87
89
  end
88
- end
89
90
 
90
- def traversal_method(obj, traversal)
91
- if traversal == :breadth_first
92
- obj.method(:each_breadth_first)
93
- else
94
- obj.method(:each_depth_first)
91
+ def traversal_method(obj, traversal)
92
+ if traversal == :breadth_first
93
+ obj.method(:each_breadth_first)
94
+ else
95
+ obj.method(:each_depth_first)
96
+ end
95
97
  end
96
98
  end
97
99
  end