Class: RedShift::CexprGuard

Inherits:
Flow show all
Defined in:
lib/redshift/component.rb,
lib/redshift/target/c/flow/expr.rb

Overview

Kinda funny…

Constant Summary collapse

@@serial =
0

Constants inherited from Flow

Flow::CT_STRUCT_NAME

Instance Attribute Summary

Attributes inherited from Flow

#formula, #strict, #var

Instance Method Summary collapse

Methods inherited from Flow

#external_constant?, #make_ct_struct, #translate, #translate_link

Constructor Details

#initialize(f) ⇒ CexprGuard

Returns a new instance of CexprGuard.



3
4
5
# File 'lib/redshift/target/c/flow/expr.rb', line 3

def initialize f
  super nil, f
end

Instance Method Details

#guard_wrapper(cl) ⇒ Object

cl is the component class maybe all these methods should just be called wrapper?



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
54
55
56
# File 'lib/redshift/target/c/flow/expr.rb', line 11

def guard_wrapper cl
  guard = self
  cl_cname = CGenerator.make_c_name cl.name
  g_cname = "Guard_#{@@serial}"; @@serial += 1
  guard_name = "guard_#{cl_cname}_#{g_cname}"
  
  Component::GuardWrapper.make_subclass guard_name do
    @inspect_str = "#{cl.name}: #{guard.formula}"
 
    ssn = cl.shadow_struct.name
    cont_state_ssn = cl.cont_state_class.shadow_struct.name
    
    # We need the struct
    shadow_library_source_file.include(cl.shadow_library_include_file)
    
    strict = false
    
    shadow_library_source_file.define(guard_name).instance_eval do
      arguments "ComponentShadow *comp_shdw"
      return_type "int"
      declare :shadow => %{
        struct #{ssn} *shadow;
        struct #{cont_state_ssn} *cont_state;
        ContVar  *var;
      }
      setup :shadow => %{
        shadow = (#{ssn} *)comp_shdw;
        cont_state = (#{cont_state_ssn} *)shadow->cont_state;
      }
      declare :result => "int result"
      translation = guard.translate(self, "result", 0, cl) {|s| strict = s}
      body %{
        #{translation.join("
        ")};
        return result;
      }
    end
    
    @strict = strict
    ## should set guard.strict = strict too?
    
    define_c_method :calc_function_pointer do
      body "shadow->guard = &#{guard_name}"
    end
  end
end