Class: Metal::Generator::Meta
- Inherits:
-
Object
- Object
- Metal::Generator::Meta
- Defined in:
- lib/metal/generator.rb
Instance Attribute Summary collapse
-
#grammar ⇒ Object
Returns the value of attribute grammar.
-
#meta ⇒ Object
Returns the value of attribute meta.
-
#rule ⇒ Object
Returns the value of attribute rule.
Instance Method Summary collapse
- #generate(fname, source = '', header = '', rbcode = '') ⇒ Object
-
#initialize(codes) ⇒ Meta
constructor
A new instance of Meta.
- #register_var(name) ⇒ Object
Constructor Details
Instance Attribute Details
#grammar ⇒ Object
Returns the value of attribute grammar.
89 90 91 |
# File 'lib/metal/generator.rb', line 89 def grammar @grammar end |
#meta ⇒ Object
Returns the value of attribute meta.
89 90 91 |
# File 'lib/metal/generator.rb', line 89 def @meta end |
#rule ⇒ Object
Returns the value of attribute rule.
89 90 91 |
# File 'lib/metal/generator.rb', line 89 def rule @rule end |
Instance Method Details
#generate(fname, source = '', header = '', rbcode = '') ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/metal/generator.rb', line 42 def generate(fname, source = '', header = '', rbcode = '') @grammars.each {|grammar| grammar.preprocess(self) } header << "#import \"metal/runtime.h\"\n" source << "#import \"#{fname}.h\"\n" source << "using namespace Metal;\n" @vars.sort! @vars.uniq! @vars.each {|var| source << "static param_t const PARAM_#{var} = param_lookup(\"#{var}\");\n" } rbcode << <<END #import "ruby.h" #import "metal/rbcode.h" #import "#{fname}.h" #ifdef __cplusplus extern "C" { #endif void Init_#{fname}() { VALUE mMetal = rb_define_module("Metal"); VALUE cBase = rb_define_class_under(mMetal, "ParserBase", rb_cObject); VALUE code; END @precodes.each {|precode| code, code_len = Generator.escape_quoated_string(precode.code) rbcode << "rb_eval_string(\"#{code}\");\n" } @grammars.each {|grammar| grammar.generate(self, source, header, rbcode) } rbcode << <<END } #ifdef __cplusplus } #endif END return [source, header, rbcode] end |
#register_var(name) ⇒ Object
91 92 93 |
# File 'lib/metal/generator.rb', line 91 def register_var(name) @vars.push name end |