Class: RedShift::Component::ContState

Inherits:
Object
  • Object
show all
Includes:
CShadow
Defined in:
lib/redshift/target/c/component-gen.rb

Overview

One subclass per component subclass; one instance per component. Must have only ContVars in the shadow struct.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.add_var(var_name, kind) ⇒ Object

yields to block only if var was added



248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
# File 'lib/redshift/target/c/component-gen.rb', line 248

def add_var var_name, kind
  var = vars[var_name]
  if var
    unless kind == :permissive or var.kind == kind
      raise StrictnessError,
        "\nVariable #{var_name} redefined with different strictness."
    end
  else
    var = vars[var_name] =
      ContVarDescriptor.new(var_name, vars.own.size, self, kind)
    shadow_attr var_name => "ContVar #{var_name}"
    yield if block_given?
  end
  var
end

.cumulative_var_countObject



272
273
274
275
276
277
278
279
280
281
# File 'lib/redshift/target/c/component-gen.rb', line 272

def cumulative_var_count
  unless @cumulative_var_count
    raise Library::CommitError unless committed?
    @cumulative_var_count = vars.size
    if @cumulative_var_count > 32767
      raise "overflow in cumulative_var_count: #{@cumulative_var_count}"
    end
  end
  @cumulative_var_count
end

.inherited_var_countObject



264
265
266
267
268
269
270
# File 'lib/redshift/target/c/component-gen.rb', line 264

def inherited_var_count
  unless @inherited_var_count
    raise Library::CommitError unless committed?
    @inherited_var_count = superclass.vars.size
  end
  @inherited_var_count
end

.make_subclass_for(component_class) ⇒ Object



228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
# File 'lib/redshift/target/c/component-gen.rb', line 228

def make_subclass_for component_class
  if component_class == Component
    cl = ContState
  else
    sup = component_class.superclass.cont_state_class
    cl = component_class.const_set("ContState", Class.new(sup))
  end
  cl.instance_eval do
    @component_class = component_class
    file_name =
      component_class.shadow_library_source_file.name[/.*(?=\.c$)/] +
      "_ContState"     ## a bit hacky
    shadow_library_file file_name
    component_class.shadow_library_include_file.include(
      shadow_library_include_file)
  end
  cl
end

.strict_var_indexesObject



288
289
290
291
292
293
294
295
296
# File 'lib/redshift/target/c/component-gen.rb', line 288

def strict_var_indexes
  unless @strict_var_indexes
    raise Library::CommitError unless committed?
    @strict_var_indexes = vars.
      select {|name, var| var.strict?}.
      map {|name, var| var.index}
  end
  @strict_var_indexes
end

.var_at_index(idx) ⇒ Object



283
284
285
286
# File 'lib/redshift/target/c/component-gen.rb', line 283

def var_at_index(idx)
  @var_at_index ||= {}
  @var_at_index[idx] ||= vars.values.find {|var| var.index == idx}
end

Instance Method Details

#first_cont_varObject

wasted



199
200
201
# File 'lib/redshift/target/c/component-gen.rb', line 199

Component.shadow_library_include_file.declare :first_cont_var => '
  #define FIRST_CONT_VAR(shadow) ((shadow)->cont_state->begin_vars[1])
'

#strict_var_indexesObject



223
224
225
# File 'lib/redshift/target/c/component-gen.rb', line 223

def strict_var_indexes
  self.class.strict_var_indexes
end

#var_at_index(idx) ⇒ Object



219
220
221
# File 'lib/redshift/target/c/component-gen.rb', line 219

def var_at_index(idx)
  self.class.var_at_index(idx)
end

#varsObject



215
216
217
# File 'lib/redshift/target/c/component-gen.rb', line 215

def vars
  self.class.vars
end