Class: Ruby2CExtension::Plugins::ConstCache

Inherits:
Ruby2CExtension::Plugin show all
Defined in:
lib/ruby2cext/plugins/const_cache.rb

Instance Attribute Summary

Attributes inherited from Ruby2CExtension::Plugin

#compiler

Instance Method Summary collapse

Methods inherited from Ruby2CExtension::Plugin

#global_c_code, #init_c_code

Constructor Details

#initialize(compiler) ⇒ ConstCache

Returns a new instance of ConstCache.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/ruby2cext/plugins/const_cache.rb', line 7

def initialize(compiler)
	super
	compiler.add_preprocessor(:const) { |cfun, node|
		cfun.instance_eval {
			c_static_once {
				comp_const(node.last)
			}
		}
	}
	compiler.add_preprocessor(:colon2) { |cfun, node|
		mid = node.last[:mid]
		if mid.to_s[0,1].downcase != mid.to_s[0,1] # then it is a constant
			cfun.instance_eval {
				c_static_once {
					comp_colon2(node.last)
				}
			}
		else
			node
		end
	}
	compiler.add_preprocessor(:colon3) { |cfun, node|
		cfun.instance_eval {
			c_static_once {
				comp_colon3(node.last)
			}
		}
	}
end