Class: RedShift::CexprGuard
- Defined in:
- lib/redshift/component.rb,
lib/redshift/target/c/flow/expr.rb
Overview
Kinda funny…
Constant Summary collapse
- @@serial =
Hash.new(0)
Constants inherited from Flow
Instance Attribute Summary
Attributes inherited from Flow
#fname, #formula, #generator, #inspect_str, #strict, #var
Instance Method Summary collapse
-
#initialize(f) ⇒ CexprGuard
constructor
A new instance of CexprGuard.
- #make_generator(cl) ⇒ Object
Methods inherited from Flow
#become_generatable, #external_constant?, #generate, #inspect, #make_ct_struct, #translate, #translate_link, #wrapper
Constructor Details
#initialize(f) ⇒ CexprGuard
Returns a new instance of CexprGuard.
2 3 4 |
# File 'lib/redshift/target/c/flow/expr.rb', line 2 def initialize f super nil, f end |
Instance Method Details
#make_generator(cl) ⇒ Object
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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/redshift/target/c/flow/expr.rb', line 8 def make_generator cl @fname = "guard_#{CGenerator.make_c_name cl.name}_#{@@serial[cl]}" @@serial[cl] += 1 @inspect_str = "#{cl.name}: #{formula}" @generator = proc do sl = cl.shadow_library ssn = cl.shadow_struct_name cont_state_ssn = cl.cont_state_class.shadow_struct_name include_file, source_file = sl.add_file fname # We need the struct source_file.include(cl.shadow_library_include_file) strict = false guard = self source_file.define(fname).instance_eval do arguments "ComponentShadow *comp_shdw" scope:extern return_type "int" declare :shadow => %{ struct #{ssn} *shadow; struct #{cont_state_ssn} *cont_state; ContVar *var; } setup :shadow => %{ shadow = (#{ssn} *)comp_shdw; cont_state = (struct #{cont_state_ssn} *)shadow->cont_state; } declare :result => "int result" translation = guard.translate(self, "result", cl, 0) {|s| strict = s} body %{ #{translation.join(" ")}; return result; } end s = strict ? "STRICT" : "NONSTRICT" sl.init_library_function.body \ "s_init_guard(#{fname}, #{fname.inspect}, #{inspect_str.inspect}, #{s});" @strict = strict end end |